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:
00278 SyncThread(QObject *parent = 0);
00279
00285 ~SyncThread();
00286
00292 void start();
00293
00299 void stop();
00300
00319 QVariant call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = 0);
00320
00321 protected:
00325 virtual void atStart() = 0;
00326
00330 virtual void atEnd() = 0;
00331
00335 virtual void run();
00336
00337 private:
00338 Q_DISABLE_COPY(SyncThread)
00339
00340 class Private;
00341 friend class Private;
00342 Private *d;
00343 };
00344
00345 class QCA_EXPORT Synchronizer : public QObject
00346 {
00347 Q_OBJECT
00348 public:
00349 Synchronizer(QObject *parent);
00350 ~Synchronizer();
00351
00352 bool waitForCondition(int msecs = -1);
00353 void conditionMet();
00354
00355 private:
00356 Q_DISABLE_COPY(Synchronizer)
00357
00358 class Private;
00359 Private *d;
00360 };
00361
00362 class QCA_EXPORT DirWatch : public QObject
00363 {
00364 Q_OBJECT
00365 public:
00366 explicit DirWatch(const QString &dir = QString(), QObject *parent = 0);
00367 ~DirWatch();
00368
00369 QString dirName() const;
00370 void setDirName(const QString &dir);
00371
00372 Q_SIGNALS:
00373 void changed();
00374
00375 private:
00376 Q_DISABLE_COPY(DirWatch)
00377
00378 class Private;
00379 friend class Private;
00380 Private *d;
00381 };
00382
00393 class QCA_EXPORT FileWatch : public QObject
00394 {
00395 Q_OBJECT
00396 public:
00404 explicit FileWatch(const QString &file = QString(), QObject *parent = 0);
00405 ~FileWatch();
00406
00410 QString fileName() const;
00411
00417 void setFileName(const QString &file);
00418
00419 Q_SIGNALS:
00424 void changed();
00425
00426 private:
00427 Q_DISABLE_COPY(FileWatch)
00428
00429 class Private;
00430 friend class Private;
00431 Private *d;
00432 };
00433
00434 class ConsolePrivate;
00435 class ConsoleReferencePrivate;
00436 class ConsoleReference;
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481 class QCA_EXPORT Console : public QObject
00482 {
00483 Q_OBJECT
00484 public:
00485 enum Type
00486 {
00487 Tty,
00488 Stdio
00489 };
00490
00491 enum ChannelMode
00492 {
00493 Read,
00494 ReadWrite
00495 };
00496
00497 enum TerminalMode
00498 {
00499 Default,
00500 Interactive
00501 };
00502
00503 Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = 0);
00504 ~Console();
00505
00506 Type type() const;
00507 ChannelMode channelMode() const;
00508 TerminalMode terminalMode() const;
00509
00510 static bool isStdinRedirected();
00511 static bool isStdoutRedirected();
00512
00513 static Console *ttyInstance();
00514 static Console *stdioInstance();
00515
00516
00517 void release();
00518 QByteArray bytesLeftToRead();
00519 QByteArray bytesLeftToWrite();
00520
00521 private:
00522 Q_DISABLE_COPY(Console)
00523
00524 friend class ConsolePrivate;
00525 ConsolePrivate *d;
00526
00527 friend class ConsoleReference;
00528 };
00529
00530
00531 class QCA_EXPORT ConsoleReference : public QObject
00532 {
00533 Q_OBJECT
00534 public:
00535 enum SecurityMode
00536 {
00537 SecurityDisabled,
00538 SecurityEnabled
00539 };
00540
00541 ConsoleReference(QObject *parent = 0);
00542 ~ConsoleReference();
00543
00544 bool start(Console *console, SecurityMode mode = SecurityDisabled);
00545 void stop();
00546
00547 Console *console() const;
00548 SecurityMode securityMode() const;
00549
00550
00551 QByteArray read(int bytes = -1);
00552 void write(const QByteArray &a);
00553
00554
00555 SecureArray readSecure(int bytes = -1);
00556 void writeSecure(const SecureArray &a);
00557
00558
00559 void closeOutput();
00560
00561 int bytesAvailable() const;
00562 int bytesToWrite() const;
00563
00564 Q_SIGNALS:
00565 void readyRead();
00566 void bytesWritten(int bytes);
00567 void inputClosed();
00568 void outputClosed();
00569
00570 private:
00571 Q_DISABLE_COPY(ConsoleReference)
00572
00573 friend class ConsoleReferencePrivate;
00574 ConsoleReferencePrivate *d;
00575
00576 friend class Console;
00577 };
00578
00579 class QCA_EXPORT ConsolePrompt : public QObject
00580 {
00581 Q_OBJECT
00582 public:
00583 ConsolePrompt(QObject *parent = 0);
00584 ~ConsolePrompt();
00585
00586 void getHidden(const QString &promptStr);
00587 void getChar();
00588 void waitForFinished();
00589
00590 SecureArray result() const;
00591 QChar resultChar() const;
00592
00593 signals:
00594 void finished();
00595
00596 private:
00597 Q_DISABLE_COPY(ConsolePrompt)
00598
00599 class Private;
00600 friend class Private;
00601 Private *d;
00602 };
00603
00604 class AbstractLogDevice;
00605
00627 class QCA_EXPORT Logger : public QObject
00628 {
00629 Q_OBJECT
00630 public:
00637 enum Severity
00638 {
00639 Quiet = 0,
00640 Emergency = 1,
00641 Alert = 2,
00642 Critical = 3,
00643 Error = 4,
00644 Warning = 5,
00645 Notice = 6,
00646 Information = 7,
00647 Debug = 8
00648 };
00649
00655 inline Logger::Severity level() const { return m_logLevel; }
00656
00664 void setLevel(Logger::Severity level);
00665
00671 void logTextMessage(const QString &message, Severity = Information);
00672
00682 void logBinaryMessage(const QByteArray &blob, Severity = Information);
00683
00689 void registerLogDevice(AbstractLogDevice *logger);
00690
00698 void unregisterLogDevice(const QString &loggerName);
00699
00703 QStringList currentLogDevices() const;
00704
00705 private:
00706 Q_DISABLE_COPY(Logger)
00707
00708 friend class Global;
00709
00713 Logger();
00714
00715 ~Logger();
00716
00717 QStringList m_loggerNames;
00718 QList<AbstractLogDevice*> m_loggers;
00719 Severity m_logLevel;
00720 };
00721
00729 class QCA_EXPORT AbstractLogDevice : public QObject
00730 {
00731 Q_OBJECT
00732 public:
00736 QString name() const;
00737
00745 virtual void logTextMessage(const QString &message, enum Logger::Severity severity);
00746
00754 virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
00755
00756 protected:
00763 explicit AbstractLogDevice(const QString &name, QObject *parent = 0);
00764
00765 virtual ~AbstractLogDevice() = 0;
00766
00767 private:
00768 Q_DISABLE_COPY(AbstractLogDevice)
00769
00770 class Private;
00771 Private *d;
00772
00773 QString m_name;
00774 };
00775
00776 }
00777
00778 #endif