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:
00068 enum Type
00069 {
00070 Read,
00071 Write
00072 };
00073
00074 QPipeDevice(QObject *parent = 0);
00075 ~QPipeDevice();
00076
00077 Type type() const;
00078 bool isValid() const;
00079 Q_PIPE_ID id() const;
00080 int idAsInt() const;
00081
00082 void take(Q_PIPE_ID id, Type t);
00083 void enable();
00084 void close();
00085 void release();
00086 bool setInheritable(bool enabled);
00087
00088 int bytesAvailable() const;
00089 int read(char *data, int maxsize);
00090 int write(const char *data, int size);
00091 int writeResult(int *written) const;
00092
00093 Q_SIGNALS:
00094 void notify();
00095
00096 private:
00097 Q_DISABLE_COPY(QPipeDevice)
00098
00099 class Private;
00100 friend class Private;
00101 Private *d;
00102 };
00103
00104
00105 class QCA_EXPORT QPipeEnd : public QObject
00106 {
00107 Q_OBJECT
00108 public:
00109 enum Error
00110 {
00111 ErrorEOF,
00112 ErrorBroken
00113 };
00114
00115 QPipeEnd(QObject *parent = 0);
00116 ~QPipeEnd();
00117
00118 void reset();
00119
00120 QPipeDevice::Type type() const;
00121 bool isValid() const;
00122 Q_PIPE_ID id() const;
00123 int idAsInt() const;
00124
00125 void take(Q_PIPE_ID id, QPipeDevice::Type t);
00126 #ifdef QPIPE_SECURE
00127 void setSecurityEnabled(bool secure);
00128 #endif
00129 void enable();
00130 void close();
00131 void release();
00132 bool setInheritable(bool enabled);
00133
00134 void finalize();
00135 void finalizeAndRelease();
00136
00137 int bytesAvailable() const;
00138 int bytesToWrite() const;
00139
00140
00141 QByteArray read(int bytes = -1);
00142 void write(const QByteArray &a);
00143
00144 #ifdef QPIPE_SECURE
00145
00146 SecureArray readSecure(int bytes = -1);
00147 void writeSecure(const SecureArray &a);
00148 #endif
00149
00150 QByteArray takeBytesToWrite();
00151
00152 #ifdef QPIPE_SECURE
00153 SecureArray takeBytesToWriteSecure();
00154 #endif
00155
00156 Q_SIGNALS:
00157 void readyRead();
00158 void bytesWritten(int bytes);
00159 void closed();
00160 void error(QCA::QPipeEnd::Error e);
00161
00162 private:
00163 Q_DISABLE_COPY(QPipeEnd)
00164
00165 class Private;
00166 friend class Private;
00167 Private *d;
00168 };
00169
00179 class QCA_EXPORT QPipe
00180 {
00181 public:
00187 QPipe(QObject *parent = 0);
00188
00189 ~QPipe();
00190
00194 void reset();
00195
00196 #ifdef QPIPE_SECURE
00197
00202 bool create(bool secure = false);
00203 #else
00204
00207 bool create();
00208 #endif
00209
00213 QPipeEnd & readEnd() { return i; }
00214
00218 QPipeEnd & writeEnd() { return o; }
00219
00220 private:
00221 Q_DISABLE_COPY(QPipe)
00222
00223 QPipeEnd i, o;
00224 };
00225
00226 }
00227
00228 #endif