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
00098 QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> argTypes);
00099
00139 QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type = Qt::AutoConnection);
00140
00141 class QCA_EXPORT SyncThread : public QThread
00142 {
00143 Q_OBJECT
00144 public:
00145 SyncThread(QObject *parent = 0);
00146 ~SyncThread();
00147
00148 void start();
00149 void stop();
00150 QVariant call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = 0);
00151
00152 protected:
00153 virtual void atStart() = 0;
00154 virtual void atEnd() = 0;
00155
00156
00157 virtual void run();
00158
00159 private:
00160 Q_DISABLE_COPY(SyncThread)
00161
00162 class Private;
00163 friend class Private;
00164 Private *d;
00165 };
00166
00167 class QCA_EXPORT Synchronizer : public QObject
00168 {
00169 Q_OBJECT
00170 public:
00171 Synchronizer(QObject *parent);
00172 ~Synchronizer();
00173
00174 bool waitForCondition(int msecs = -1);
00175 void conditionMet();
00176
00177 private:
00178 Q_DISABLE_COPY(Synchronizer)
00179
00180 class Private;
00181 Private *d;
00182 };
00183
00184 class QCA_EXPORT DirWatch : public QObject
00185 {
00186 Q_OBJECT
00187 public:
00188 explicit DirWatch(const QString &dir = QString(), QObject *parent = 0);
00189 ~DirWatch();
00190
00191 QString dirName() const;
00192 void setDirName(const QString &dir);
00193
00194 Q_SIGNALS:
00195 void changed();
00196
00197 private:
00198 Q_DISABLE_COPY(DirWatch)
00199
00200 class Private;
00201 friend class Private;
00202 Private *d;
00203 };
00204
00211 class QCA_EXPORT FileWatch : public QObject
00212 {
00213 Q_OBJECT
00214 public:
00222 explicit FileWatch(const QString &file = QString(), QObject *parent = 0);
00223 ~FileWatch();
00224
00228 QString fileName() const;
00229
00235 void setFileName(const QString &file);
00236
00237 Q_SIGNALS:
00242 void changed();
00243
00244 private:
00245 Q_DISABLE_COPY(FileWatch)
00246
00247 class Private;
00248 friend class Private;
00249 Private *d;
00250 };
00251
00252 class ConsolePrivate;
00253 class ConsoleReferencePrivate;
00254 class ConsoleReference;
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 class QCA_EXPORT Console : public QObject
00300 {
00301 Q_OBJECT
00302 public:
00303 enum Type
00304 {
00305 Tty,
00306 Stdio
00307 };
00308
00309 enum ChannelMode
00310 {
00311 Read,
00312 ReadWrite
00313 };
00314
00315 enum TerminalMode
00316 {
00317 Default,
00318 Interactive
00319 };
00320
00321 Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = 0);
00322 ~Console();
00323
00324 Type type() const;
00325 ChannelMode channelMode() const;
00326 TerminalMode terminalMode() const;
00327
00328 static bool isStdinRedirected();
00329 static bool isStdoutRedirected();
00330
00331 static Console *ttyInstance();
00332 static Console *stdioInstance();
00333
00334
00335 void release();
00336 QByteArray bytesLeftToRead();
00337 QByteArray bytesLeftToWrite();
00338
00339 private:
00340 Q_DISABLE_COPY(Console)
00341
00342 friend class ConsolePrivate;
00343 ConsolePrivate *d;
00344
00345 friend class ConsoleReference;
00346 };
00347
00348
00349 class QCA_EXPORT ConsoleReference : public QObject
00350 {
00351 Q_OBJECT
00352 public:
00353 enum SecurityMode
00354 {
00355 SecurityDisabled,
00356 SecurityEnabled
00357 };
00358
00359 ConsoleReference(QObject *parent = 0);
00360 ~ConsoleReference();
00361
00362 bool start(Console *console, SecurityMode mode = SecurityDisabled);
00363 void stop();
00364
00365 Console *console() const;
00366 SecurityMode securityMode() const;
00367
00368
00369 QByteArray read(int bytes = -1);
00370 void write(const QByteArray &a);
00371
00372
00373 SecureArray readSecure(int bytes = -1);
00374 void writeSecure(const SecureArray &a);
00375
00376
00377 void closeOutput();
00378
00379 int bytesAvailable() const;
00380 int bytesToWrite() const;
00381
00382 Q_SIGNALS:
00383 void readyRead();
00384 void bytesWritten(int bytes);
00385 void inputClosed();
00386 void outputClosed();
00387
00388 private:
00389 Q_DISABLE_COPY(ConsoleReference)
00390
00391 friend class ConsoleReferencePrivate;
00392 ConsoleReferencePrivate *d;
00393
00394 friend class Console;
00395 };
00396
00397 class QCA_EXPORT ConsolePrompt : public QObject
00398 {
00399 Q_OBJECT
00400 public:
00401 ConsolePrompt(QObject *parent = 0);
00402 ~ConsolePrompt();
00403
00404 void getHidden(const QString &promptStr);
00405 void getChar();
00406 void waitForFinished();
00407
00408 SecureArray result() const;
00409 QChar resultChar() const;
00410
00411 signals:
00412 void finished();
00413
00414 private:
00415 Q_DISABLE_COPY(ConsolePrompt)
00416
00417 class Private;
00418 friend class Private;
00419 Private *d;
00420 };
00421
00422 class AbstractLogDevice;
00423
00441 class QCA_EXPORT Logger : public QObject
00442 {
00443 Q_OBJECT
00444 public:
00451 enum Severity
00452 {
00453 Quiet = 0,
00454 Emergency = 1,
00455 Alert = 2,
00456 Critical = 3,
00457 Error = 4,
00458 Warning = 5,
00459 Notice = 6,
00460 Information = 7,
00461 Debug = 8
00462 };
00463
00469 inline Logger::Severity level() const { return m_logLevel; }
00470
00478 void setLevel(Logger::Severity level);
00479
00485 void logTextMessage(const QString &message, Severity = Information);
00486
00496 void logBinaryMessage(const QByteArray &blob, Severity = Information);
00497
00503 void registerLogDevice(AbstractLogDevice *logger);
00504
00512 void unregisterLogDevice(const QString &loggerName);
00513
00517 QStringList currentLogDevices() const;
00518
00519 private:
00520 Q_DISABLE_COPY(Logger)
00521
00522 friend class Global;
00523
00527 Logger();
00528
00529 ~Logger();
00530
00531 QStringList m_loggerNames;
00532 QList<AbstractLogDevice*> m_loggers;
00533 Severity m_logLevel;
00534 };
00535
00539 class QCA_EXPORT AbstractLogDevice : public QObject
00540 {
00541 Q_OBJECT
00542 public:
00546 QString name() const;
00547
00555 virtual void logTextMessage(const QString &message, enum Logger::Severity severity);
00556
00564 virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
00565
00566 protected:
00573 explicit AbstractLogDevice(const QString &name, QObject *parent = 0);
00574
00575 virtual ~AbstractLogDevice() = 0;
00576
00577 private:
00578 Q_DISABLE_COPY(AbstractLogDevice)
00579
00580 class Private;
00581 Private *d;
00582
00583 QString m_name;
00584 };
00585
00586 }
00587
00588 #endif