qpipe.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003-2007  Justin Karneges <justin@affinix.com>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301  USA
00018  *
00019  */
00020 
00031 #ifndef QPIPE_H
00032 #define QPIPE_H
00033 
00034 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00035 
00036 #ifndef QPIPE_NO_SECURE
00037 # define QPIPE_SECURE
00038 #endif
00039 
00040 #ifdef QPIPE_SECURE
00041 # include "QtCrypto"
00042 #else
00043 # define QCA_EXPORT
00044 #endif
00045 
00046 // defs adapted qprocess_p.h
00047 #ifdef Q_OS_WIN
00048 #include <windows.h>
00049 typedef HANDLE Q_PIPE_ID;
00050 #define INVALID_Q_PIPE_ID INVALID_HANDLE_VALUE
00051 #else
00052 typedef int Q_PIPE_ID;
00053 #define INVALID_Q_PIPE_ID -1
00054 #endif
00055 
00056 #endif
00057 
00058 // Note: for Windows console, I/O must be in UTF-8.  Reads are guaranteed to
00059 //   to completely decode (no partial characters).  Likewise, writes must
00060 //   not contain partial characters.
00061 
00062 namespace QCA {
00063 
00064 
00075 class QCA_EXPORT QPipeDevice : public QObject
00076 {
00077         Q_OBJECT
00078 public:
00082         enum Type
00083         {
00084                 Read, 
00085                 Write 
00086         };
00087 
00093         QPipeDevice(QObject *parent = 0);
00094         ~QPipeDevice();
00095 
00099         Type type() const;
00100 
00104         bool isValid() const;
00105 
00115         Q_PIPE_ID id() const;
00116 
00124         int idAsInt() const;
00125 
00132         void take(Q_PIPE_ID id, Type t);
00133 
00137         void enable();
00138 
00142         void close();
00143 
00147         void release();
00148 
00156         bool setInheritable(bool enabled);
00157 
00161         int bytesAvailable() const;
00162 
00171         int read(char *data, int maxsize);
00172 
00183         int write(const char *data, int size);
00184 
00193         int writeResult(int *written) const;
00194 
00195 Q_SIGNALS:
00199         void notify();
00200 
00201 private:
00202         Q_DISABLE_COPY(QPipeDevice)
00203 
00204         class Private;
00205         friend class Private;
00206         Private *d;
00207 };
00208 
00218 class QCA_EXPORT QPipeEnd : public QObject
00219 {
00220         Q_OBJECT
00221 public:
00222 
00226         enum Error
00227         {
00228                 ErrorEOF,    
00229                 ErrorBroken  
00230         };
00231 
00237         QPipeEnd(QObject *parent = 0);
00238 
00239         ~QPipeEnd();
00240 
00244         void reset();
00245 
00249         QPipeDevice::Type type() const;
00250 
00257         bool isValid() const;
00258 
00262         Q_PIPE_ID id() const;
00263 
00267         int idAsInt() const;
00268 
00275         void take(Q_PIPE_ID id, QPipeDevice::Type t);
00276 
00277 #ifdef QPIPE_SECURE
00278 
00286         void setSecurityEnabled(bool secure);
00287 #endif
00288 
00295         void enable();
00296 
00302         void close();
00303 
00310         void release();
00311 
00320         bool setInheritable(bool enabled);
00321 
00325         void finalize();
00326 
00330         void finalizeAndRelease();
00331 
00340         int bytesAvailable() const;
00341 
00350         int bytesToWrite() const;
00351 
00362         QByteArray read(int bytes = -1);
00363 
00373         void write(const QByteArray &a);
00374 
00375 #ifdef QPIPE_SECURE
00376 
00386         SecureArray readSecure(int bytes = -1);
00387 
00397         void writeSecure(const SecureArray &a);
00398 #endif
00399 
00406         QByteArray takeBytesToWrite();
00407 
00408 #ifdef QPIPE_SECURE
00409 
00415         SecureArray takeBytesToWriteSecure();
00416 #endif
00417 
00418 Q_SIGNALS:
00425         void readyRead();
00426 
00433         void bytesWritten(int bytes);
00434 
00446         void closed();
00447 
00454         void error(QCA::QPipeEnd::Error e);
00455 
00456 private:
00457         Q_DISABLE_COPY(QPipeEnd)
00458 
00459         class Private;
00460         friend class Private;
00461         Private *d;
00462 };
00463 
00480 class QCA_EXPORT QPipe
00481 {
00482 public:
00490         QPipe(QObject *parent = 0);
00491 
00492         ~QPipe();
00493 
00500         void reset();
00501 
00502 #ifdef QPIPE_SECURE
00503 
00508         bool create(bool secure = false);
00509 #else
00510 
00513         bool create();
00514 #endif
00515 
00519         QPipeEnd & readEnd() { return i; }
00520 
00524         QPipeEnd & writeEnd() { return o; }
00525 
00526 private:
00527         Q_DISABLE_COPY(QPipe)
00528 
00529         QPipeEnd i, o;
00530 };
00531 
00532 }
00533 
00534 #endif

Generated on Wed Apr 29 15:15:45 2009 for Qt Cryptographic Architecture by  doxygen 1.5.5