qca_support.h
Go to the documentation of this file.
/*
* qca_support.h - Qt Cryptographic Architecture
* Copyright (C) 2003-2005 Justin Karneges <justin@affinix.com>
* Copyright (C) 2004,2005, 2007 Brad Hards <bradh@frogmouth.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#ifndef QCA_SUPPORT_H
#define QCA_SUPPORT_H
#include "qca_export.h"
#include "qca_tools.h"
#include <QByteArray>
#include <QList>
#include <QMetaObject>
#include <QObject>
#include <QString>
#include <QStringList>
#include <QThread>
#include <QVariant>
#include <QVariantList>
namespace QCA {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QCA_EXPORT int methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList<QByteArray> &argTypes);
#else
QCA_EXPORT QByteArray methodReturnType(const QMetaObject *obj,
const QByteArray &method,
const QList<QByteArray> argTypes);
#endif
QCA_EXPORT bool invokeMethodWithVariants(QObject *obj,
const QByteArray &method,
const QVariantList &args,
QVariant *ret,
Qt::ConnectionType type = Qt::AutoConnection);
class QCA_EXPORT SyncThread : public QThread
{
Q_OBJECT
public:
SyncThread(QObject *parent = nullptr);
~SyncThread() override;
void start();
void stop();
QVariant
call(QObject *obj, const QByteArray &method, const QVariantList &args = QVariantList(), bool *ok = nullptr);
protected:
virtual void atStart() = 0;
virtual void atEnd() = 0;
void run() override;
private:
Q_DISABLE_COPY(SyncThread)
class Private;
friend class Private;
Private *d;
};
class QCA_EXPORT Synchronizer : public QObject
{
Q_OBJECT
public:
Synchronizer(QObject *parent);
~Synchronizer() override;
bool waitForCondition(int msecs = -1);
void conditionMet();
private:
Q_DISABLE_COPY(Synchronizer)
class Private;
Private *d;
};
class QCA_EXPORT DirWatch : public QObject
{
Q_OBJECT
public:
explicit DirWatch(const QString &dir = QString(), QObject *parent = nullptr);
~DirWatch() override;
QString dirName() const;
void setDirName(const QString &dir);
Q_SIGNALS:
void changed();
private:
Q_DISABLE_COPY(DirWatch)
class Private;
friend class Private;
Private *d;
};
class QCA_EXPORT FileWatch : public QObject
{
Q_OBJECT
public:
explicit FileWatch(const QString &file = QString(), QObject *parent = nullptr);
~FileWatch() override;
QString fileName() const;
void setFileName(const QString &file);
Q_SIGNALS:
void changed();
private:
Q_DISABLE_COPY(FileWatch)
class Private;
friend class Private;
Private *d;
};
class ConsolePrivate;
class ConsoleReferencePrivate;
class ConsoleReference;
class QCA_EXPORT Console : public QObject
{
Q_OBJECT
public:
enum Type
{
Tty,
Stdio
};
enum ChannelMode
{
Read,
ReadWrite
};
enum TerminalMode
{
Default,
Interactive
};
Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent = nullptr);
~Console() override;
Type type() const;
ChannelMode channelMode() const;
TerminalMode terminalMode() const;
static bool isStdinRedirected();
static bool isStdoutRedirected();
static Console *ttyInstance();
static Console *stdioInstance();
void release();
QByteArray bytesLeftToRead();
QByteArray bytesLeftToWrite();
private:
Q_DISABLE_COPY(Console)
friend class ConsolePrivate;
ConsolePrivate *d;
friend class ConsoleReference;
};
class QCA_EXPORT ConsoleReference : public QObject
{
Q_OBJECT
public:
enum SecurityMode
{
SecurityDisabled,
SecurityEnabled
};
ConsoleReference(QObject *parent = nullptr);
~ConsoleReference() override;
bool start(Console *console, SecurityMode mode = SecurityDisabled);
void stop();
Console *console() const;
SecurityMode securityMode() const;
QByteArray read(int bytes = -1);
void write(const QByteArray &a);
SecureArray readSecure(int bytes = -1);
void writeSecure(const SecureArray &a);
void closeOutput();
int bytesAvailable() const;
int bytesToWrite() const;
Q_SIGNALS:
void readyRead();
void bytesWritten(int bytes);
void inputClosed();
void outputClosed();
private:
Q_DISABLE_COPY(ConsoleReference)
friend class ConsoleReferencePrivate;
ConsoleReferencePrivate *d;
friend class Console;
};
class QCA_EXPORT ConsolePrompt : public QObject
{
Q_OBJECT
public:
ConsolePrompt(QObject *parent = nullptr);
~ConsolePrompt() override;
void getHidden(const QString &promptStr);
void getChar();
void waitForFinished();
SecureArray result() const;
QChar resultChar() const;
Q_SIGNALS:
void finished();
private:
Q_DISABLE_COPY(ConsolePrompt)
class Private;
friend class Private;
Private *d;
};
class AbstractLogDevice;
class QCA_EXPORT Logger : public QObject
{
Q_OBJECT
public:
enum Severity
{
Quiet = 0,
Emergency = 1,
Alert = 2,
Critical = 3,
Error = 4,
Warning = 5,
Notice = 6,
Information = 7,
Debug = 8
};
inline Severity level() const
{
return m_logLevel;
}
void setLevel(Severity level);
void logTextMessage(const QString &message, Severity = Information);
void logBinaryMessage(const QByteArray &blob, Severity = Information);
void registerLogDevice(AbstractLogDevice *logger);
void unregisterLogDevice(const QString &loggerName);
QStringList currentLogDevices() const;
private:
Q_DISABLE_COPY(Logger)
friend class Global;
Logger();
~Logger() override;
QStringList m_loggerNames;
QList<AbstractLogDevice *> m_loggers;
Severity m_logLevel;
};
class QCA_EXPORT AbstractLogDevice : public QObject
{
Q_OBJECT
public:
QString name() const;
virtual void logTextMessage(const QString &message, Logger::Severity severity);
virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity);
protected:
explicit AbstractLogDevice(const QString &name, QObject *parent = nullptr);
~AbstractLogDevice() override = 0;
private:
Q_DISABLE_COPY(AbstractLogDevice)
class Private;
Private *d;
QString m_name;
};
}
#endif
QCA::AbstractLogDevice
An abstract log device.
Definition qca_support.h:1068
QCA::AbstractLogDevice::name
QString name() const
The name of this log device.
QCA::AbstractLogDevice::AbstractLogDevice
AbstractLogDevice(const QString &name, QObject *parent=nullptr)
Create a new message logger.
QCA::AbstractLogDevice::logBinaryMessage
virtual void logBinaryMessage(const QByteArray &blob, Logger::Severity severity)
Log a binary blob.
QCA::AbstractLogDevice::logTextMessage
virtual void logTextMessage(const QString &message, Logger::Severity severity)
Log a message.
QCA::ConsolePrompt::getChar
void getChar()
Obtain one character from the user.
QCA::ConsolePrompt::resultChar
QChar resultChar() const
Obtain the result of the user input.
QCA::ConsolePrompt::waitForFinished
void waitForFinished()
Block waiting for user input.
QCA::ConsolePrompt::finished
void finished()
Emitted when the user input activity has been completed.
QCA::ConsolePrompt::getHidden
void getHidden(const QString &promptStr)
Allow the user to enter data without it being echo'd to the terminal.
QCA::ConsolePrompt::result
SecureArray result() const
Obtain the result of the user input.
QCA::ConsolePrompt::ConsolePrompt
ConsolePrompt(QObject *parent=nullptr)
Standard constructor.
QCA::ConsoleReference
Manager for a Console.
Definition qca_support.h:693
QCA::ConsoleReference::securityMode
SecurityMode securityMode() const
The security mode setting for the Console object managed by this object.
QCA::ConsoleReference::outputClosed
void outputClosed()
Emitted when the console output is closed.
QCA::ConsoleReference::bytesWritten
void bytesWritten(int bytes)
Emitted when bytes are written to the Console.
QCA::ConsoleReference::closeOutput
void closeOutput()
Close the write channel.
QCA::ConsoleReference::stop
void stop()
Stop processing, and release the Console.
QCA::ConsoleReference::ConsoleReference
ConsoleReference(QObject *parent=nullptr)
Standard constructor.
QCA::ConsoleReference::bytesToWrite
int bytesToWrite() const
The number of bytes remaining to be written to the Console being managed.
QCA::ConsoleReference::write
void write(const QByteArray &a)
Write data to the Console.
QCA::ConsoleReference::SecurityMode
SecurityMode
The security setting to use for the Console being managed.
Definition qca_support.h:700
QCA::ConsoleReference::writeSecure
void writeSecure(const SecureArray &a)
Write secure data to the Console.
QCA::ConsoleReference::bytesAvailable
int bytesAvailable() const
The number of bytes available to read from the Console being managed.
QCA::ConsoleReference::read
QByteArray read(int bytes=-1)
Read data from the Console.
QCA::ConsoleReference::readSecure
SecureArray readSecure(int bytes=-1)
Read secure data from the Console.
QCA::ConsoleReference::readyRead
void readyRead()
Emitted when there are bytes available to read from the Console being managed.
QCA::ConsoleReference::inputClosed
void inputClosed()
Emitted when the console input is closed.
QCA::ConsoleReference::start
bool start(Console *console, SecurityMode mode=SecurityDisabled)
Set the Console object to be managed, and start processing.
QCA::ConsoleReference::console
Console * console() const
The Console object managed by this object.
QCA::Console::ttyInstance
static Console * ttyInstance()
The current terminal-type console object.
QCA::Console::Type
Type
The type of console object.
Definition qca_support.h:568
QCA::Console::Tty
@ Tty
physical console
Definition qca_support.h:569
QCA::Console::Stdio
@ Stdio
stdin/stdout
Definition qca_support.h:570
QCA::Console::Console
Console(Type type, ChannelMode cmode, TerminalMode tmode, QObject *parent=nullptr)
Standard constructor.
QCA::Console::stdioInstance
static Console * stdioInstance()
The current stdio-type console object.
QCA::Console::ChannelMode
ChannelMode
The type of I/O to use with the console object.
Definition qca_support.h:576
QCA::Console::Read
@ Read
Read only (equivalent to stdin).
Definition qca_support.h:577
QCA::Console::ReadWrite
@ ReadWrite
Read/write (equivalent to stdin and stdout).
Definition qca_support.h:578
QCA::Console::channelMode
ChannelMode channelMode() const
The ChannelMode of this Console object.
QCA::Console::bytesLeftToRead
QByteArray bytesLeftToRead()
Obtain remaining data from the Console, awaiting a read operation.
QCA::Console::type
Type type() const
The Type of this Console object.
QCA::Console::bytesLeftToWrite
QByteArray bytesLeftToWrite()
Obtain remaining data from the Console, awaiting a write operation.
QCA::Console::release
void release()
Release the Console.
QCA::Console::TerminalMode
TerminalMode
The nature of the console operation.
Definition qca_support.h:585
QCA::Console::Interactive
@ Interactive
char-by-char input, no echo
Definition qca_support.h:587
QCA::Console::Default
@ Default
use default terminal settings
Definition qca_support.h:586
QCA::Console::isStdinRedirected
static bool isStdinRedirected()
Test whether standard input is redirected.
QCA::Console::terminalMode
TerminalMode terminalMode() const
The TerminalMode of this Console object.
QCA::Console::isStdoutRedirected
static bool isStdoutRedirected()
Test whether standard output is redirected.
QCA::DirWatch::dirName
QString dirName() const
The name of the directory that is being monitored.
QCA::DirWatch::DirWatch
DirWatch(const QString &dir=QString(), QObject *parent=nullptr)
Standard constructor.
QCA::DirWatch::changed
void changed()
The changed signal is emitted when the directory is changed (e.g. modified by addition or deletion of...
QCA::DirWatch::setDirName
void setDirName(const QString &dir)
Change the directory being monitored.
QCA::FileWatch::FileWatch
FileWatch(const QString &file=QString(), QObject *parent=nullptr)
Standard constructor.
QCA::FileWatch::fileName
QString fileName() const
The name of the file that is being monitored.
QCA::FileWatch::setFileName
void setFileName(const QString &file)
Change the file being monitored.
QCA::FileWatch::changed
void changed()
The changed signal is emitted when the file is changed (e.g.
QCA::Logger::currentLogDevices
QStringList currentLogDevices() const
Get a list of the names of all registered log devices.
QCA::Logger::level
Severity level() const
Get the current logging level.
Definition qca_support.h:990
QCA::Logger::registerLogDevice
void registerLogDevice(AbstractLogDevice *logger)
Add an AbstractLogDevice subclass to the existing list of loggers.
QCA::Logger::Severity
Severity
The severity of the message.
Definition qca_support.h:973
QCA::Logger::Debug
@ Debug
Debug: debug-level messages.
Definition qca_support.h:982
QCA::Logger::Error
@ Error
Error: error conditions.
Definition qca_support.h:978
QCA::Logger::Notice
@ Notice
Notice: normal but significant condition.
Definition qca_support.h:980
QCA::Logger::Information
@ Information
Informational: informational messages.
Definition qca_support.h:981
QCA::Logger::Quiet
@ Quiet
Quiet: turn of logging.
Definition qca_support.h:974
QCA::Logger::Warning
@ Warning
Warning: warning conditions.
Definition qca_support.h:979
QCA::Logger::Emergency
@ Emergency
Emergency: system is unusable.
Definition qca_support.h:975
QCA::Logger::Alert
@ Alert
Alert: action must be taken immediately.
Definition qca_support.h:976
QCA::Logger::Critical
@ Critical
Critical: critical conditions.
Definition qca_support.h:977
QCA::Logger::logBinaryMessage
void logBinaryMessage(const QByteArray &blob, Severity=Information)
Log a binary blob to all available log devices.
QCA::Logger::setLevel
void setLevel(Severity level)
Set the current logging level.
QCA::Logger::unregisterLogDevice
void unregisterLogDevice(const QString &loggerName)
Remove an AbstractLogDevice subclass from the existing list of loggers.
QCA::Logger::logTextMessage
void logTextMessage(const QString &message, Severity=Information)
Log a message to all available log devices.
QCA::SecureArray
Secure array of bytes.
Definition qca_tools.h:317
QCA::SyncThread::invokeMethodWithVariants
QCA_EXPORT bool invokeMethodWithVariants(QObject *obj, const QByteArray &method, const QVariantList &args, QVariant *ret, Qt::ConnectionType type=Qt::AutoConnection)
Convenience method to invoke a method by name, using a variant list of arguments.
QCA::SyncThread::atStart
virtual void atStart()=0
Reimplement this to perform your initialization.
QCA::SyncThread::call
QVariant call(QObject *obj, const QByteArray &method, const QVariantList &args=QVariantList(), bool *ok=nullptr)
Calls a slot of an object in the thread.
QCA::SyncThread::run
void run() override
Starts the event loop and calls atStart and atStop as necessary.
QCA::SyncThread::methodReturnType
QCA_EXPORT int methodReturnType(const QMetaObject *obj, const QByteArray &method, const QList< QByteArray > &argTypes)
Convenience method to determine the return type of a method.
QCA::SyncThread::stop
void stop()
Stops the event loop of the thread, calls atStop() in the thread, and instructs the thread to finish.
QCA::SyncThread::SyncThread
SyncThread(QObject *parent=nullptr)
Standard constructor.
QCA::SyncThread::atEnd
virtual void atEnd()=0
Reimplement this to perform your deinitialization.
QCA::SyncThread::start
void start()
Starts the thread, begins the event loop the thread, and then calls atStart() in the thread.
QCA::SyncThread::~SyncThread
~SyncThread() override
Calls stop() and then destructs.
QCA::Synchronizer::waitForCondition
bool waitForCondition(int msecs=-1)
Call to pause execution in this thread.
QCA::Synchronizer::conditionMet
void conditionMet()
Call to continue execution in the paused thread.
QCA::Synchronizer::Synchronizer
Synchronizer(QObject *parent)
Standard constructor.
QList
QObject
QThread
QCA
QCA - the Qt Cryptographic Architecture.
Definition qca_basic.h:41
QCA::logger
QCA_EXPORT Logger * logger()
Return a reference to the QCA Logger, which is used for diagnostics and error recording.
qca_tools.h
Header file for "tool" classes used in QCA.