QtService
1.1.0
A platform independent library to easily create system services and use some of their features
|
Represents a connection to a console terminal connected to the service. More...
#include <terminal.h>
Classes | |
class | Awaitable |
A helper class to be used with QtCoroutines to await io from a coroutine. More... | |
Public Slots | |
void | disconnectTerminal () |
Disconnects the terminal from the client. More... | |
void | requestChar () |
Request a single character from the terminal. More... | |
void | requestChars (qint64 num) |
Request a given number of charactersr from the terminal. More... | |
void | requestLine () |
Request a line of characters from the terminal. More... | |
void | writeLine (const QByteArray &line, bool flush=true) |
Writes the given line, appends a newline and optionally flushes. | |
void | flush () |
Flushes the terminal. | |
void | setAutoDelete (bool autoDelete) |
WRITE accessor for Terminal::autoDelete. | |
Signals | |
void | terminalDisconnected () |
Will be emitted after the terminal has been disconnected. | |
void | terminalError (int errorCode) |
Will be emitted if an error occured. Use QIODevice::errorString to get the text. | |
void | autoDeleteChanged (bool autoDelete) |
NOTIFY accessor for Terminal::autoDelete. | |
Public Member Functions | |
bool | isSequential () const override |
Inherits QIODevice::isSequential. | |
void | close () override |
Inherits QIODevice::close. | |
bool | atEnd () const override |
Inherits QIODevice::atEnd. | |
qint64 | bytesAvailable () const override |
Inherits QIODevice::bytesAvailable. | |
qint64 | bytesToWrite () const override |
Inherits QIODevice::bytesToWrite. | |
bool | canReadLine () const override |
Inherits QIODevice::canReadLine. | |
bool | waitForReadyRead (int msecs) override |
Inherits QIODevice::waitForReadyRead. | |
bool | waitForBytesWritten (int msecs) override |
Inherits QIODevice::waitForBytesWritten. | |
Service::TerminalMode | terminalMode () const |
READ accessor for Terminal::terminalMode. | |
QStringList | command () const |
READ accessor for Terminal::command. | |
bool | isAutoDelete () const |
READ accessor for Terminal::autoDelete. | |
Awaitable | awaitChar () |
Await a single character. More... | |
Awaitable | awaitChars (qint64 num) |
Await a given number of characters. More... | |
Awaitable | awaitLine () |
Await a line of characters. More... | |
Public Member Functions inherited from QIODevice | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
QIODevice (QObject *parent) | |
QIODevice::OpenMode | openMode () const const |
void | setTextModeEnabled (bool enabled) |
bool | isTextModeEnabled () const const |
bool | isOpen () const const |
bool | isReadable () const const |
bool | isWritable () const const |
int | readChannelCount () const const |
int | writeChannelCount () const const |
int | currentReadChannel () const const |
void | setCurrentReadChannel (int channel) |
int | currentWriteChannel () const const |
void | setCurrentWriteChannel (int channel) |
virtual bool | open (QIODevice::OpenMode mode) |
virtual qint64 | pos () const const |
virtual qint64 | size () const const |
virtual bool | seek (qint64 pos) |
virtual bool | reset () |
qint64 | read (char *data, qint64 maxSize) |
QByteArray | read (qint64 maxSize) |
QByteArray | readAll () |
qint64 | readLine (char *data, qint64 maxSize) |
QByteArray | readLine (qint64 maxSize) |
void | startTransaction () |
void | commitTransaction () |
void | rollbackTransaction () |
bool | isTransactionStarted () const const |
qint64 | write (const char *data, qint64 maxSize) |
qint64 | write (const char *data) |
qint64 | write (const QByteArray &byteArray) |
qint64 | peek (char *data, qint64 maxSize) |
QByteArray | peek (qint64 maxSize) |
qint64 | skip (qint64 maxSize) |
void | ungetChar (char c) |
bool | putChar (char c) |
bool | getChar (char *c) |
QString | errorString () const const |
void | readyRead () |
void | channelReadyRead (int channel) |
void | bytesWritten (qint64 bytes) |
void | channelBytesWritten (int channel, qint64 bytes) |
void | aboutToClose () |
void | readChannelFinished () |
Public Member Functions inherited from QObject | |
QObject (QObject *parent) | |
virtual bool | event (QEvent *e) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
QString | objectName () const const |
void | setObjectName (const QString &name) |
bool | isWidgetType () const const |
bool | isWindowType () const const |
bool | signalsBlocked () const const |
bool | blockSignals (bool block) |
QThread * | thread () const const |
void | moveToThread (QThread *targetThread) |
int | startTimer (int interval, Qt::TimerType timerType) |
int | startTimer (std::chrono::milliseconds time, Qt::TimerType timerType) |
void | killTimer (int id) |
T | findChild (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QString &name, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegExp ®Exp, Qt::FindChildOptions options) const const |
QList< T > | findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const |
const QObjectList & | children () const const |
void | setParent (QObject *parent) |
void | installEventFilter (QObject *filterObj) |
void | removeEventFilter (QObject *obj) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const |
bool | disconnect (const char *signal, const QObject *receiver, const char *method) const const |
bool | disconnect (const QObject *receiver, const char *method) const const |
void | dumpObjectTree () |
void | dumpObjectInfo () |
void | dumpObjectTree () const const |
void | dumpObjectInfo () const const |
bool | setProperty (const char *name, const QVariant &value) |
QVariant | property (const char *name) const const |
QList< QByteArray > | dynamicPropertyNames () const const |
void | destroyed (QObject *obj) |
void | objectNameChanged (const QString &objectName) |
QObject * | parent () const const |
bool | inherits (const char *className) const const |
void | deleteLater () |
Protected Member Functions | |
qint64 | readData (char *data, qint64 maxlen) override |
Inherits QIODevice::readData. | |
qint64 | readLineData (char *data, qint64 maxlen) override |
Inherits QIODevice::readLineData. | |
qint64 | writeData (const char *data, qint64 len) override |
Inherits QIODevice::writeData. | |
Protected Member Functions inherited from QIODevice | |
void | setOpenMode (QIODevice::OpenMode openMode) |
void | setErrorString (const QString &str) |
Protected Member Functions inherited from QObject | |
QObject * | sender () const const |
int | senderSignalIndex () const const |
int | receivers (const char *signal) const const |
bool | isSignalConnected (const QMetaMethod &signal) const const |
virtual void | timerEvent (QTimerEvent *event) |
virtual void | childEvent (QChildEvent *event) |
virtual void | customEvent (QEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
Properties | |
QtService::Service::TerminalMode | terminalMode |
The I/O-mode the terminal operates in. More... | |
QStringList | command |
The command line arguments that have been used to create this terminal. More... | |
bool | autoDelete |
If true, the terminal will delete itself as soon as the connection has been closed. More... | |
Properties inherited from QObject | |
objectName | |
Additional Inherited Members | |
Static Public Member Functions inherited from QIODevice | |
QString | tr (const char *s, const char *c, int n) |
QString | trUtf8 (const char *s, const char *c, int n) |
Static Public Member Functions inherited from QObject | |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
QString | trUtf8 (const char *sourceText, const char *disambiguation, int n) |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
Public Attributes inherited from QIODevice | |
typedef | OpenMode |
Represents a connection to a console terminal connected to the service.
For every connected terminal, one instance of the Terminal class is created, and provided by the service. The terminal allows interaction with each connected terminal, by receiving it's stdin and sending data to it's stdout.
The Terminal implements the QIODevice interface. This allows easy integration into the application. The terminal is a sequential device.
Definition at line 15 of file terminal.h.
QtService::Terminal::awaitChar | ( | ) |
Await a single character.
This method can only be used from within a coroutine (See QtCoroutines). It basically calls requestChar() and then awaits the character on the device and returns the read data
QtService::Terminal::awaitChars | ( | qint64 | num | ) |
Await a given number of characters.
num | The amount of characters to be read |
This method can only be used from within a coroutine (See QtCoroutines). It basically calls requestChars() and then awaits the characters on the device and returns the read data
QtService::Terminal::awaitLine | ( | ) |
Await a line of characters.
This method can only be used from within a coroutine (See QtCoroutines). It basically calls requestLine() and then awaits the line on the device and returns the read data
|
slot |
Disconnects the terminal from the client.
This closes the network connection after flushing the remaining data.
|
slot |
Request a single character from the terminal.
This method can only be used when the terminal is in the Service::ReadWriteActive mode. In that case you need to request input from the client - and this method is one way to do so.
It will send a request to the client telling it to read 1 byte of data. The request is done asynchronously, which means you have to connect to QIODevice::readyRead to be notified as soon as the data has been sent back.
|
slot |
Request a given number of charactersr from the terminal.
num | The amount of characters to be requested |
This method can only be used when the terminal is in the Service::ReadWriteActive mode. In that case you need to request input from the client - and this method is one way to do so.
It will send a request to the client telling it to read num
bytes of data. The request is done asynchronously, which means you have to connect to QIODevice::readyRead to be notified as soon as the data has been sent back.
|
slot |
Request a line of characters from the terminal.
This method can only be used when the terminal is in the Service::ReadWriteActive mode. In that case you need to request input from the client - and this method is one way to do so.
It will send a request to the client telling it to read bytes of data until a newline character is found. That data, including the newline character is then sent back. The request is done asynchronously, which means you have to connect to QIODevice::readyRead to be notified as soon as the data has been sent back.
|
readwrite |
If true, the terminal will delete itself as soon as the connection has been closed.
Default: true
If set to true
the terminal will be automatically deleted, as soon as the terminal was disconnected. If you need to access the terminal even after closing, you can disable it.
Accessors | |
---|---|
READ | isAutoDelete() |
WRITE | setAutoDelete() |
NOTIFY | autoDeleteChanged() |
Definition at line 24 of file terminal.h.
|
read |
The command line arguments that have been used to create this terminal.
Default: Arguments passed to the terminal
When someone creates a terminal he does so by invoking the application with some arguments. These arguments are what can be retrieved via this property. The arguments are pre-filtered, which means the application name as well as QtService-specific arguments do not appear here. So for example, the command service.exe --terminal --backend windows hello world
can be retrieved from this property as ["hello", "world"]
Validation of the arguments must be done by the service. However, you should use Service::verifyCommand to verify the passed arguments on the clients side before connection to the service. After receiving, verify them again and then use them.
Accessors | |
---|---|
READ | command() |
CONSTANT |
Definition at line 22 of file terminal.h.
|
read |
The I/O-mode the terminal operates in.
Default: Service::ReadWriteActive
The terminal mode that this terminal used to connect to the service with. The mode determines how I/O is managed between the service and the terminal. This cannot be changed after connecting, which means you should simply discard terminals with unallowed modes.
The modes are define in Service::TerminalMode - from the clients perspective. However here is a table to explain what they are
Terminal mode | Open mode | Explanation |
---|---|---|
Service::ReadOnly | QIODevice::WriteOnly | The terminal can only receive data from the service. Useful for machine-to-machine communication. |
Service::WriteOnly | QIODevice::ReadOnly | The terminal can only send data to the service. Useful for machine-to-machine communication. |
Service::ReadWritePassive | QIODevice::ReadWrite | The terminal can read and write as much as it wants. Useful for machine-to-machine communication. |
Service::ReadWriteActive | QIODevice::ReadWrite | The terminal can read and write, but writing is limited to what the service requests. Recommended for humans using the terminal. |
Accessors | |
---|---|
READ | terminalMode() |
CONSTANT |
Definition at line 20 of file terminal.h.