00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00035 #ifndef QCA_SUPPORT_H
00036 #define QCA_SUPPORT_H
00037
00038 #include <QByteArray>
00039 #include <QString>
00040 #include <QObject>
00041 #include <QVariant>
00042 #include <QVariantList>
00043 #include <QStringList>
00044 #include <QList>
00045 #include <QMetaObject>
00046 #include <QThread>
00047 #include "qca_export.h"
00048 #include "qca_tools.h"
00049
00050 namespace QCA {
00051
00100 QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> argTypes);
00101
00143 QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type = Qt::AutoConnection);
00144
00271 class QCA_EXPORT SyncThread : public QThread
00272 {
00273 Q_OBJECT
00274 public:
00280 SyncThread(QObject *parent = 0);
00281
00287 ~SyncThread();
00288
00294 void start();
00295
00301 void stop();
00302
00321 QVariant call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = 0);
00322
00323 protected:
00327 virtual void atStart() = 0;
00328
00332 virtual void atEnd() = 0;
00333
00337 virtual void run();
00338
00339 private:
00340 Q_DISABLE_COPY(SyncThread)
00341
00342 class Private;
00343 friend class Private;
00344 Private *d;
00345 };
00346
00352 class QCA_EXPORT Synchronizer : public QObject
00353 {
00354 Q_OBJECT
00355 public:
00361 Synchronizer(QObject *parent);
00362 ~Synchronizer();
00363
00371 bool waitForCondition(int msecs = -1);
00372
00376 void conditionMet();
00377
00378 private:
00379 Q_DISABLE_COPY(Synchronizer)
00380
00381 class Private;
00382 Private *d;
00383 };
00384
00400 class QCA_EXPORT DirWatch : public QObject
00401 {
00402 Q_OBJECT
00403 public:
00411 explicit DirWatch(const QString &dir = QString(), QObject *parent = 0);
00412 ~DirWatch();
00413
00417 QString dirName() const;
00418
00424 void setDirName(const QString &dir);
00425
00426 Q_SIGNALS:
00433 void changed();
00434
00435 private:
00436 Q_DISABLE_COPY(DirWatch)
00437
00438 class Private;
00439 friend class Private;
00440 Private *d;
00441 };
00442
00458 class QCA_EXPORT FileWatch : public QObject
00459 {
00460 Q_OBJECT
00461 public:
00469 explicit FileWatch(const QString &file = QString(), QObject *parent = 0);
00470 ~FileWatch();
00471
00475 QString fileName() const;
00476
00482 void setFileName(const QString &file);
00483
00484 Q_SIGNALS:
00489 void changed();
00490
00491 private:
00492 Q_DISABLE_COPY(FileWatch)
00493
00494 class Private;
00495 friend class Private;
00496 Private *d;
00497 };
00498
00499 class ConsolePrivate;
00500 class ConsoleReferencePrivate;
00501 class ConsoleReference;
00502
00551 class QCA_EXPORT Console : public QObject
00552 {
00553 Q_OBJECT
00554 public:
00558 enum Type
00559 {
00560 Tty,
00561 Stdio
00562 };
00566 enum ChannelMode
00567 {
00568 Read,
00569 ReadWrite
00570 };
00571
00575 enum TerminalMode
00576 {
00577 Default,
00578 Interactive
00579 };
00580
00598 Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = 0);
00599 ~Console();
00600
00604 Type type() const;
00605
00609 ChannelMode channelMode() const;
00610
00614 TerminalMode terminalMode() const;
00615
00621 static bool isStdinRedirected();
00622
00628 static bool isStdoutRedirected();
00629
00636 static Console *ttyInstance();
00637
00644 static Console *stdioInstance();
00645
00651 void release();
00652
00657 QByteArray bytesLeftToRead();
00658
00663 QByteArray bytesLeftToWrite();
00664
00665 private:
00666 Q_DISABLE_COPY(Console)
00667
00668 friend class ConsolePrivate;
00669 ConsolePrivate *d;
00670
00671 friend class ConsoleReference;
00672 };
00673
00683 class QCA_EXPORT ConsoleReference : public QObject
00684 {
00685 Q_OBJECT
00686 public:
00690 enum SecurityMode
00691 {
00692 SecurityDisabled,
00693 SecurityEnabled
00694 };
00695
00701 ConsoleReference(QObject *parent = 0);
00702 ~ConsoleReference();
00703
00717 bool start(Console *console, SecurityMode mode = SecurityDisabled);
00718
00722 void stop();
00723
00729 Console *console() const;
00730
00737 SecurityMode securityMode() const;
00738
00748 QByteArray read(int bytes = -1);
00749
00758 void write(const QByteArray &a);
00759
00768 SecureArray readSecure(int bytes = -1);
00769
00777 void writeSecure(const SecureArray &a);
00778
00785 void closeOutput();
00786
00791 int bytesAvailable() const;
00792
00797 int bytesToWrite() const;
00798
00799 Q_SIGNALS:
00804 void readyRead();
00805
00813 void bytesWritten(int bytes);
00814
00818 void inputClosed();
00819
00823 void outputClosed();
00824
00825 private:
00826 Q_DISABLE_COPY(ConsoleReference)
00827
00828 friend class ConsoleReferencePrivate;
00829 ConsoleReferencePrivate *d;
00830
00831 friend class Console;
00832 };
00833
00854 class QCA_EXPORT ConsolePrompt : public QObject
00855 {
00856 Q_OBJECT
00857 public:
00863 ConsolePrompt(QObject *parent = 0);
00864 ~ConsolePrompt();
00865
00875 void getHidden(const QString &promptStr);
00876
00882 void getChar();
00883
00890 void waitForFinished();
00891
00899 SecureArray result() const;
00900
00908 QChar resultChar() const;
00909
00910 signals:
00920 void finished();
00921
00922 private:
00923 Q_DISABLE_COPY(ConsolePrompt)
00924
00925 class Private;
00926 friend class Private;
00927 Private *d;
00928 };
00929
00930 class AbstractLogDevice;
00931
00953 class QCA_EXPORT Logger : public QObject
00954 {
00955 Q_OBJECT
00956 public:
00963 enum Severity
00964 {
00965 Quiet = 0,
00966 Emergency = 1,
00967 Alert = 2,
00968 Critical = 3,
00969 Error = 4,
00970 Warning = 5,
00971 Notice = 6,
00972 Information = 7,
00973 Debug = 8
00974 };
00975
00981 inline Severity level() const { return m_logLevel; }
00982
00990 void setLevel(Severity level);
00991
00997 void logTextMessage(const QString &message, Severity = Information);
00998
01008 void logBinaryMessage(const QByteArray &blob, Severity = Information);
01009
01015 void registerLogDevice(AbstractLogDevice *logger);
01016
01024 void unregisterLogDevice(const QString &loggerName);
01025
01029 QStringList currentLogDevices() const;
01030
01031 private:
01032 Q_DISABLE_COPY(Logger)
01033
01034 friend class Global;
01035
01039 Logger();
01040
01041 ~Logger();
01042
01043 QStringList m_loggerNames;
01044 QList<AbstractLogDevice*> m_loggers;
01045 Severity m_logLevel;
01046 };
01047
01055 class QCA_EXPORT AbstractLogDevice : public QObject
01056 {
01057 Q_OBJECT
01058 public:
01062 QString name() const;
01063
01074 virtual void logTextMessage(const QString &message, Logger::Severity severity);
01075
01086 virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
01087
01088 protected:
01095 explicit AbstractLogDevice(const QString &name, QObject *parent = 0);
01096
01097 virtual ~AbstractLogDevice() = 0;
01098
01099 private:
01100 Q_DISABLE_COPY(AbstractLogDevice)
01101
01102 class Private;
01103 Private *d;
01104
01105 QString m_name;
01106 };
01107
01108 }
01109
01110 #endif