# qca_support.h

Go to the documentation of this file.

    00001 /*
    00002  * qca_support.h - Qt Cryptographic Architecture
    00003  * Copyright (C) 2003-2005  Justin Karneges <justin@affinix.com>
    00004  * Copyright (C) 2004,2005, 2007  Brad Hards <bradh@frogmouth.net>
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Lesser General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2.1 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Lesser General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Lesser General Public
    00017  * License along with this library; if not, write to the Free Software
    00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    00019  * 02110-1301  USA
    00020  *
    00021  */
    00022
    00036 #ifndef QCA_SUPPORT_H
    00037 #define QCA_SUPPORT_H
    00038
    00039 #include <QByteArray>
    00040 #include <QString>
    00041 #include <QObject>
    00042 #include <QVariant>
    00043 #include <QVariantList>
    00044 #include <QStringList>
    00045 #include <QList>
    00046 #include <QMetaObject>
    00047 #include <QThread>
    00048 #include "qca_export.h"
    00049 #include "qca_tools.h"
    00050
    00051 namespace QCA {
    00052
    00101 QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> argTypes);
    00102
    00144 QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type = Qt::AutoConnection);
    00145
    00272 class QCA_EXPORT SyncThread : public QThread
    00273 {
    00274         Q_OBJECT
    00275 public:
    00281         SyncThread(QObject *parent = 0);
    00282
    00288         ~SyncThread();
    00289
    00295         void start();
    00296
    00302         void stop();
    00303
    00322         QVariant call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = 0);
    00323
    00324 protected:
    00328         virtual void atStart() = 0;
    00329
    00333         virtual void atEnd() = 0;
    00334
    00338         virtual void run();
    00339
    00340 private:
    00341         Q_DISABLE_COPY(SyncThread)
    00342
    00343         class Private;
    00344         friend class Private;
    00345         Private *d;
    00346 };
    00347
    00353 class QCA_EXPORT Synchronizer : public QObject
    00354 {
    00355         Q_OBJECT
    00356 public:
    00362         Synchronizer(QObject *parent);
    00363         ~Synchronizer();
    00364
    00372         bool waitForCondition(int msecs = -1);
    00373
    00377         void conditionMet();
    00378
    00379 private:
    00380         Q_DISABLE_COPY(Synchronizer)
    00381
    00382         class Private;
    00383         Private *d;
    00384 };
    00385
    00401 class QCA_EXPORT DirWatch : public QObject
    00402 {
    00403         Q_OBJECT
    00404 public:
    00412         explicit DirWatch(const QString &dir = QString(), QObject *parent = 0);
    00413         ~DirWatch();
    00414
    00418         QString dirName() const;
    00419
    00425         void setDirName(const QString &dir);
    00426
    00427 Q_SIGNALS:
    00434         void changed();
    00435
    00436 private:
    00437         Q_DISABLE_COPY(DirWatch)
    00438
    00439         class Private;
    00440         friend class Private;
    00441         Private *d;
    00442 };
    00443
    00459 class QCA_EXPORT FileWatch : public QObject
    00460 {
    00461         Q_OBJECT
    00462 public:
    00470         explicit FileWatch(const QString &file = QString(), QObject *parent = 0);
    00471         ~FileWatch();
    00472
    00476         QString fileName() const;
    00477
    00483         void setFileName(const QString &file);
    00484
    00485 Q_SIGNALS:
    00490         void changed();
    00491
    00492 private:
    00493         Q_DISABLE_COPY(FileWatch)
    00494
    00495         class Private;
    00496         friend class Private;
    00497         Private *d;
    00498 };
    00499
    00500 class ConsolePrivate;
    00501 class ConsoleReferencePrivate;
    00502 class ConsoleReference;
    00503
    00552 class QCA_EXPORT Console : public QObject
    00553 {
    00554         Q_OBJECT
    00555 public:
    00559         enum Type
    00560         {
    00561                 Tty,
    00562                 Stdio
    00563         };
    00567         enum ChannelMode
    00568         {
    00569                 Read,
    00570                 ReadWrite
    00571         };
    00572
    00576         enum TerminalMode
    00577         {
    00578                 Default,
    00579                 Interactive
    00580         };
    00581
    00599         Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = 0);
    00600         ~Console();
    00601
    00605         Type type() const;
    00606
    00610         ChannelMode channelMode() const;
    00611
    00615         TerminalMode terminalMode() const;
    00616
    00622         static bool isStdinRedirected();
    00623
    00629         static bool isStdoutRedirected();
    00630
    00637         static Console *ttyInstance();
    00638
    00645         static Console *stdioInstance();
    00646
    00652         void release();
    00653
    00658         QByteArray bytesLeftToRead();
    00659
    00664         QByteArray bytesLeftToWrite();
    00665
    00666 private:
    00667         Q_DISABLE_COPY(Console)
    00668
    00669         friend class ConsolePrivate;
    00670         ConsolePrivate *d;
    00671
    00672         friend class ConsoleReference;
    00673 };
    00674
    00684 class QCA_EXPORT ConsoleReference : public QObject
    00685 {
    00686         Q_OBJECT
    00687 public:
    00691         enum SecurityMode
    00692         {
    00693                 SecurityDisabled,
    00694                 SecurityEnabled
    00695         };
    00696
    00702         ConsoleReference(QObject *parent = 0);
    00703         ~ConsoleReference();
    00704
    00718         bool start(Console *console, SecurityMode mode = SecurityDisabled);
    00719
    00723         void stop();
    00724
    00730         Console *console() const;
    00731
    00738         SecurityMode securityMode() const;
    00739
    00749         QByteArray read(int bytes = -1);
    00750
    00759         void write(const QByteArray &a);
    00760
    00769         SecureArray readSecure(int bytes = -1);
    00770
    00778         void writeSecure(const SecureArray &a);
    00779
    00786         void closeOutput();
    00787
    00792         int bytesAvailable() const;
    00793
    00798         int bytesToWrite() const;
    00799
    00800 Q_SIGNALS:
    00805         void readyRead();
    00806
    00814         void bytesWritten(int bytes);
    00815
    00819         void inputClosed();
    00820
    00824         void outputClosed();
    00825
    00826 private:
    00827         Q_DISABLE_COPY(ConsoleReference)
    00828
    00829         friend class ConsoleReferencePrivate;
    00830         ConsoleReferencePrivate *d;
    00831
    00832         friend class Console;
    00833 };
    00834
    00855 class QCA_EXPORT ConsolePrompt : public QObject
    00856 {
    00857         Q_OBJECT
    00858 public:
    00864         ConsolePrompt(QObject *parent = 0);
    00865         ~ConsolePrompt();
    00866
    00876         void getHidden(const QString &promptStr);
    00877
    00883         void getChar();
    00884
    00891         void waitForFinished();
    00892
    00900         SecureArray result() const;
    00901
    00909         QChar resultChar() const;
    00910
    00911 Q_SIGNALS:
    00921         void finished();
    00922
    00923 private:
    00924         Q_DISABLE_COPY(ConsolePrompt)
    00925
    00926         class Private;
    00927         friend class Private;
    00928         Private *d;
    00929 };
    00930
    00931 class AbstractLogDevice;
    00932
    00954 class QCA_EXPORT Logger : public QObject
    00955 {
    00956         Q_OBJECT
    00957 public:
    00964         enum Severity
    00965         {
    00966                 Quiet = 0,
    00967                 Emergency = 1,
    00968                 Alert = 2,
    00969                 Critical = 3,
    00970                 Error = 4,
    00971                 Warning = 5,
    00972                 Notice = 6,
    00973                 Information = 7,
    00974                 Debug = 8
    00975         };
    00976
    00982         inline Severity level() const { return m_logLevel; }
    00983
    00991         void setLevel(Severity level);
    00992
    00998         void logTextMessage(const QString &message, Severity = Information);
    00999
    01009         void logBinaryMessage(const QByteArray &blob, Severity = Information);
    01010
    01016         void registerLogDevice(AbstractLogDevice *logger);
    01017
    01025         void unregisterLogDevice(const QString &loggerName);
    01026
    01030         QStringList currentLogDevices() const;
    01031
    01032 private:
    01033         Q_DISABLE_COPY(Logger)
    01034
    01035         friend class Global;
    01036
    01040         Logger();
    01041
    01042         ~Logger();
    01043
    01044         QStringList m_loggerNames;
    01045         QList<AbstractLogDevice*> m_loggers;
    01046         Severity m_logLevel;
    01047 };
    01048
    01056 class QCA_EXPORT AbstractLogDevice : public QObject
    01057 {
    01058         Q_OBJECT
    01059 public:
    01063         QString name() const;
    01064
    01075         virtual void logTextMessage(const QString &message, Logger::Severity severity);
    01076
    01087         virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
    01088
    01089 protected:
    01096         explicit AbstractLogDevice(const QString &name, QObject *parent = 0);
    01097
    01098         virtual ~AbstractLogDevice() = 0;
    01099
    01100 private:
    01101         Q_DISABLE_COPY(AbstractLogDevice)
    01102
    01103         class Private;
    01104         Private *d;
    01105
    01106         QString m_name;
    01107 };
    01108
    01109 }
    01110
    01111 #endif