00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00030 #ifndef QPIPE_H
00031 #define QPIPE_H
00032
00033 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00034
00035 #ifndef QPIPE_NO_SECURE
00036 # define QPIPE_SECURE
00037 #endif
00038
00039 #ifdef QPIPE_SECURE
00040 # include <QtCrypto>
00041 #else
00042 # define QCA_EXPORT
00043 #endif
00044
00045
00046 #ifdef Q_OS_WIN
00047 #include <windows.h>
00048 typedef HANDLE Q_PIPE_ID;
00049 #define INVALID_Q_PIPE_ID INVALID_HANDLE_VALUE
00050 #else
00051 typedef int Q_PIPE_ID;
00052 #define INVALID_Q_PIPE_ID -1
00053 #endif
00054
00055 #endif
00056
00057
00058
00059
00060
00061 namespace QCA {
00062
00063
00064 class QCA_EXPORT QPipeDevice : public QObject
00065 {
00066 Q_OBJECT
00067 public:
00071 enum Type
00072 {
00073 Read,
00074 Write
00075 };
00076
00077 QPipeDevice(QObject *parent = 0);
00078 ~QPipeDevice();
00079
00080 Type type() const;
00081 bool isValid() const;
00082 Q_PIPE_ID id() const;
00083 int idAsInt() const;
00084
00085 void take(Q_PIPE_ID id, Type t);
00086 void enable();
00087 void close();
00088 void release();
00089 bool setInheritable(bool enabled);
00090
00091 int bytesAvailable() const;
00092 int read(char *data, int maxsize);
00093 int write(const char *data, int size);
00094 int writeResult(int *written) const;
00095
00096 Q_SIGNALS:
00097 void notify();
00098
00099 private:
00100 Q_DISABLE_COPY(QPipeDevice)
00101
00102 class Private;
00103 friend class Private;
00104 Private *d;
00105 };
00106
00116 class QCA_EXPORT QPipeEnd : public QObject
00117 {
00118 Q_OBJECT
00119 public:
00120
00124 enum Error
00125 {
00126 ErrorEOF,
00127 ErrorBroken
00128 };
00129
00133 QPipeEnd(QObject *parent = 0);
00134
00135 ~QPipeEnd();
00136
00140 void reset();
00141
00145 QPipeDevice::Type type() const;
00146
00153 bool isValid() const;
00154
00158 Q_PIPE_ID id() const;
00159
00163 int idAsInt() const;
00164
00171 void take(Q_PIPE_ID id, QPipeDevice::Type t);
00172
00173 #ifdef QPIPE_SECURE
00174
00180 void setSecurityEnabled(bool secure);
00181 #endif
00182
00189 void enable();
00190
00196 void close();
00197
00204 void release();
00205
00212 bool setInheritable(bool enabled);
00213
00217 void finalize();
00218
00222 void finalizeAndRelease();
00223
00232 int bytesAvailable() const;
00233
00242 int bytesToWrite() const;
00243
00254 QByteArray read(int bytes = -1);
00255
00265 void write(const QByteArray &a);
00266
00267 #ifdef QPIPE_SECURE
00268
00278 SecureArray readSecure(int bytes = -1);
00279
00289 void writeSecure(const SecureArray &a);
00290 #endif
00291
00298 QByteArray takeBytesToWrite();
00299
00300 #ifdef QPIPE_SECURE
00301
00307 SecureArray takeBytesToWriteSecure();
00308 #endif
00309
00310 Q_SIGNALS:
00317 void readyRead();
00318
00325 void bytesWritten(int bytes);
00326
00338 void closed();
00339
00346 void error(QCA::QPipeEnd::Error e);
00347
00348 private:
00349 Q_DISABLE_COPY(QPipeEnd)
00350
00351 class Private;
00352 friend class Private;
00353 Private *d;
00354 };
00355
00372 class QCA_EXPORT QPipe
00373 {
00374 public:
00382 QPipe(QObject *parent = 0);
00383
00384 ~QPipe();
00385
00392 void reset();
00393
00394 #ifdef QPIPE_SECURE
00395
00400 bool create(bool secure = false);
00401 #else
00402
00405 bool create();
00406 #endif
00407
00411 QPipeEnd & readEnd() { return i; }
00412
00416 QPipeEnd & writeEnd() { return o; }
00417
00418 private:
00419 Q_DISABLE_COPY(QPipe)
00420
00421 QPipeEnd i, o;
00422 };
00423
00424 }
00425
00426 #endif