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
00074 class QCA_EXPORT QPipeDevice : public QObject
00075 {
00076 Q_OBJECT
00077 public:
00081 enum Type
00082 {
00083 Read,
00084 Write
00085 };
00086
00092 QPipeDevice(QObject *parent = 0);
00093 ~QPipeDevice();
00094
00098 Type type() const;
00099
00103 bool isValid() const;
00104
00114 Q_PIPE_ID id() const;
00115
00123 int idAsInt() const;
00124
00131 void take(Q_PIPE_ID id, Type t);
00132
00136 void enable();
00137
00141 void close();
00142
00146 void release();
00147
00155 bool setInheritable(bool enabled);
00156
00160 int bytesAvailable() const;
00161
00170 int read(char *data, int maxsize);
00171
00182 int write(const char *data, int size);
00183
00192 int writeResult(int *written) const;
00193
00194 Q_SIGNALS:
00198 void notify();
00199
00200 private:
00201 Q_DISABLE_COPY(QPipeDevice)
00202
00203 class Private;
00204 friend class Private;
00205 Private *d;
00206 };
00207
00217 class QCA_EXPORT QPipeEnd : public QObject
00218 {
00219 Q_OBJECT
00220 public:
00221
00225 enum Error
00226 {
00227 ErrorEOF,
00228 ErrorBroken
00229 };
00230
00236 QPipeEnd(QObject *parent = 0);
00237
00238 ~QPipeEnd();
00239
00243 void reset();
00244
00248 QPipeDevice::Type type() const;
00249
00256 bool isValid() const;
00257
00261 Q_PIPE_ID id() const;
00262
00266 int idAsInt() const;
00267
00274 void take(Q_PIPE_ID id, QPipeDevice::Type t);
00275
00276 #ifdef QPIPE_SECURE
00277
00285 void setSecurityEnabled(bool secure);
00286 #endif
00287
00294 void enable();
00295
00301 void close();
00302
00309 void release();
00310
00319 bool setInheritable(bool enabled);
00320
00324 void finalize();
00325
00329 void finalizeAndRelease();
00330
00339 int bytesAvailable() const;
00340
00349 int bytesToWrite() const;
00350
00361 QByteArray read(int bytes = -1);
00362
00372 void write(const QByteArray &a);
00373
00374 #ifdef QPIPE_SECURE
00375
00385 SecureArray readSecure(int bytes = -1);
00386
00396 void writeSecure(const SecureArray &a);
00397 #endif
00398
00405 QByteArray takeBytesToWrite();
00406
00407 #ifdef QPIPE_SECURE
00408
00414 SecureArray takeBytesToWriteSecure();
00415 #endif
00416
00417 Q_SIGNALS:
00424 void readyRead();
00425
00432 void bytesWritten(int bytes);
00433
00445 void closed();
00446
00453 void error(QCA::QPipeEnd::Error e);
00454
00455 private:
00456 Q_DISABLE_COPY(QPipeEnd)
00457
00458 class Private;
00459 friend class Private;
00460 Private *d;
00461 };
00462
00479 class QCA_EXPORT QPipe
00480 {
00481 public:
00489 QPipe(QObject *parent = 0);
00490
00491 ~QPipe();
00492
00499 void reset();
00500
00501 #ifdef QPIPE_SECURE
00502
00507 bool create(bool secure = false);
00508 #else
00509
00512 bool create();
00513 #endif
00514
00518 QPipeEnd & readEnd() { return i; }
00519
00523 QPipeEnd & writeEnd() { return o; }
00524
00525 private:
00526 Q_DISABLE_COPY(QPipe)
00527
00528 QPipeEnd i, o;
00529 };
00530
00531 }
00532
00533 #endif