File indexing completed on 2024-06-23 05:14:17

0001 /*
0002   SPDX-FileCopyrightText: 2007 Klarälvdalens Datakonsult AB
0003 
0004   SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QIODevice>
0010 
0011 #include <utility>
0012 
0013 class KDPipeIODevice : public QIODevice
0014 {
0015     Q_OBJECT
0016     // KDAB_MAKE_CHECKABLE( KDPipeIODevice )
0017 public:
0018     enum DebugLevel {
0019         NoDebug,
0020         Debug,
0021     };
0022 
0023     static DebugLevel debugLevel();
0024     static void setDebugLevel(DebugLevel level);
0025 
0026     explicit KDPipeIODevice(QObject *parent = nullptr);
0027     explicit KDPipeIODevice(int fd, OpenMode = ReadOnly, QObject *parent = nullptr);
0028     explicit KDPipeIODevice(Qt::HANDLE handle, OpenMode = ReadOnly, QObject *parent = nullptr);
0029     ~KDPipeIODevice() override;
0030 
0031     static std::pair<KDPipeIODevice *, KDPipeIODevice *> makePairOfConnectedPipes();
0032 
0033     bool open(int fd, OpenMode mode = ReadOnly);
0034     bool open(Qt::HANDLE handle, OpenMode mode = ReadOnly);
0035 
0036     Qt::HANDLE handle() const;
0037     int descriptor() const;
0038 
0039     bool readWouldBlock() const;
0040     bool writeWouldBlock() const;
0041 
0042     qint64 bytesAvailable() const override;
0043     qint64 bytesToWrite() const override;
0044     bool canReadLine() const override;
0045     void close() override;
0046     bool isSequential() const override;
0047     bool atEnd() const override;
0048 
0049     bool waitForBytesWritten(int msecs) override;
0050     bool waitForReadyRead(int msecs) override;
0051 
0052 protected:
0053     qint64 readData(char *data, qint64 maxSize) override;
0054     qint64 writeData(const char *data, qint64 maxSize) override;
0055 
0056 private:
0057     using QIODevice::open;
0058 
0059 private:
0060     class Private;
0061     Private *d;
0062 };