QtService
1.1.0
A platform independent library to easily create system services and use some of their features
|
The interface that needs to be implemented to provide the backend for the service engine. More...
#include <servicebackend.h>
Public Types | |
enum | ServiceCommand { StartCommand, StopCommand, ReloadCommand, PauseCommand, ResumeCommand } |
The standard service commands that the library can handle. More... | |
Public Member Functions | |
ServiceBackend (Service *service) | |
Constructor with the service instance the backend was created for. | |
virtual int | runService (int &argc, char **argv, int flags)=0 |
Is called as the services main function by the library from Service::exec. More... | |
virtual void | quitService ()=0 |
Is called by Service::quit to stop the service programatically. More... | |
virtual void | reloadService ()=0 |
Is called by Service::reload to reload the service programatically. More... | |
virtual QList< int > | getActivatedSockets (const QByteArray &name) |
Is called by Service::getSockets and Service::getSocket to get the activated sockets. More... | |
Public Member Functions inherited from QObject | |
virtual const QMetaObject * | metaObject () const const |
virtual void * | qt_metacast (const char *) |
virtual int | qt_metacall (QMetaObject::Call, int, void **) |
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 Slots | |
virtual void | signalTriggered (int signal) |
Is called by the library if a unix signal or windows console signal was triggered. More... | |
void | processServiceCommand (QtService::ServiceBackend::ServiceCommand code) |
Calls the Service standard methods for the given command code. More... | |
QVariant | processServiceCallbackImpl (const QByteArray &kind, const QVariantList &args={}) |
Calls a special command as service callback synchronously. More... | |
Protected Member Functions | |
QtService::Service * | service () const |
The Service instance this backend was created with. | |
template<typename TRet , typename... TArgs> | |
TRet | processServiceCallback (const QByteArray &kind, TArgs... args) |
Calls a special command as service callback synchronously. More... | |
template<typename... TArgs> | |
void | processServiceCallback (const QByteArray &kind, TArgs... args) |
Calls a special command as service callback synchronously. More... | |
bool | registerForSignal (int signal) |
Register for a unix/windows signal your backend wants to handle. More... | |
bool | unregisterFromSignal (int signal) |
Unregister from a unix/windows signal your backend doesn't want to handle anymore. More... | |
bool | preStartService () |
Calls the Service::preStart method synchronously. More... | |
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) |
Additional Inherited Members | |
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) |
Properties inherited from QObject | |
objectName | |
The interface that needs to be implemented to provide the backend for the service engine.
This class is only needed when implementing your own service backend. It's what the Service uses internally to properly run and interact with the service systems
Definition at line 15 of file servicebackend.h.
The standard service commands that the library can handle.
Enumerator | |
---|---|
StartCommand | Service was started. Will lead to Service::onStart beeing called. |
StopCommand | Service should stop. Will lead to Service::onStop beeing called. |
ReloadCommand | Service should reload. Will lead to Service::onReload beeing called. |
PauseCommand | Service should pause. Will lead to Service::onPause beeing called. |
ResumeCommand | Service was resumed. Will lead to Service::onResume beeing called. |
Definition at line 21 of file servicebackend.h.
|
virtual |
Is called by Service::getSockets and Service::getSocket to get the activated sockets.
name | The name of the socket(s) to be retrieved, or a null name for the default socket. |
If your service backends supports socket activation, implement this method to make the available. It is either called with a name passed to Service::getSockets, or with a null bytearray if the default socket (Service::getSocket) was requested. Sockets returned from this method should be ready to use, aka in the listening state (this is typically the case for bound sockets)
|
protected |
Calls the Service::preStart method synchronously.
You should call this method right after creating the QCoreApplication object and after setting up logging. It's a wrapper that calls Service::preStart and returns it's value. If false is returned the service cannot start properly and you should exit as soon as possible.
|
protected |
Calls a special command as service callback synchronously.
TRet | The return type |
TArgs | Generic arguments types |
kind | The kind of callback to be called |
args | The arguments of the callback |
Wrapper that calls Service::onCallback and returns it's value. This method call is, unlike other commands, synchronous.
Definition at line 91 of file servicebackend.h.
|
protected |
Calls a special command as service callback synchronously.
TArgs | Generic arguments types |
kind | The kind of callback to be called |
args | The arguments of the callback |
Wrapper that calls Service::onCallback and returns it's value. This method call is, unlike other commands, synchronous.
Definition at line 97 of file servicebackend.h.
|
protectedslot |
Calls a special command as service callback synchronously.
kind | The kind of callback to be called |
args | The arguments of the callback |
Wrapper that calls Service::onCallback and returns it's value. This method call is, unlike other commands, synchronous.
|
protectedslot |
Calls the Service standard methods for the given command code.
code | The command code to be executed |
This method calls the correspondig onCommand method of the Service instance. This method takes care of both sync and async calls. For usage, you should always assume asynchronous runs. In other words, do not complete the operation after this method returns. Instead connect to the coresponding done signal and continue from there.
The methods called and signals to connect to for each command are:
|
pure virtual |
Is called by Service::quit to stop the service programatically.
Your implementation should perform a graceful service exit. This means a call to this method should behave the same as stopping the service from the service manager.
|
protected |
Register for a unix/windows signal your backend wants to handle.
signal | The signal to register for |
You need to call this method to register a signal you want to handle. After registering it, it will be delivered via ServiceBackend::signalTriggered as soon as it is triggered.
|
pure virtual |
Is called by Service::reload to reload the service programatically.
Your implementation should perform a service reload. This means a call to this method should behave the same as reloading the service from the service manager. If reloading is not supported by your backend, simply call processServiceCommand(ReloadCommand);
to properly handle the reload with doing anything service-manager related.
|
pure virtual |
Is called as the services main function by the library from Service::exec.
argc | The argc from Service, i.e. from the main |
argv | The argv from Service, i.e. from the main |
flags | The flags from Service, i.e. from the main |
This method should perform all the required startup stuff for the service, prepare logging etc. What must do is to create a QCoreApplication (or another application) and eventually run QCoreApplication::exec - as this method should also block until execution finished. You should return the exit code form the main if possible.
Returning from this method early should typically be done only in case of an error and an error exit code returned.
Internally, you must use ServiceBackend::processServiceCommand (and ServiceBackend::processServiceCallback) at the appropriate points in your implementation to call the corresponding service methods.
|
protectedvirtualslot |
Is called by the library if a unix signal or windows console signal was triggered.
signal | The signal that was triggered |
If you need to handle signals, this is the easiest way. Please note that this method is called asynchronously. So if you need signal handlers that are synchronous, you must implement them yourself. The signal values are the standard defined values of signals for all platforms, i.e. the SIGINT signal on unix is the same as that define from the signal.h header.
In order to be able to catch signals with this method they must be registered first. Use ServiceBackend::registerForSignal to do so.
|
protected |
Unregister from a unix/windows signal your backend doesn't want to handle anymore.
signal | The signal to unregister from |
After unregistering, the "default signal handler" will be used again to handle such a signal. In other words the state before the registration is recovered.