QtService  1.1.0
A platform independent library to easily create system services and use some of their features
servicebackend.h
1 #ifndef QTSERVICE_SERVICEBACKEND_H
2 #define QTSERVICE_SERVICEBACKEND_H
3 
4 #include <QtCore/qobject.h>
5 #include <QtCore/qbytearraylist.h>
6 #include <QtCore/qscopedpointer.h>
7 
8 #include "QtService/qtservice_global.h"
9 #include "QtService/service.h"
10 
11 namespace QtService {
12 
13 class ServiceBackendPrivate;
15 class Q_SERVICE_EXPORT ServiceBackend : public QObject
16 {
17  Q_OBJECT
18 
19 public:
26  ResumeCommand
27  };
28  Q_ENUM(ServiceCommand)
29 
30 
31  ServiceBackend(Service *service);
32  ~ServiceBackend() override;
33 
35  virtual int runService(int &argc, char **argv, int flags) = 0;
37  virtual void quitService() = 0;
39  virtual void reloadService() = 0;
40 
42  virtual QList<int> getActivatedSockets(const QByteArray &name);
43 
44 protected Q_SLOTS:
46  virtual void signalTriggered(int signal);
47 
49  void processServiceCommand(QtService::ServiceBackend::ServiceCommand code);
51  QVariant processServiceCallbackImpl(const QByteArray &kind, const QVariantList &args = {});
52 
53 protected:
55  QtService::Service *service() const;
56 
62  template <typename TRet, typename... TArgs>
63  TRet processServiceCallback(const QByteArray &kind, TArgs... args);
68  template <typename... TArgs>
69  void processServiceCallback(const QByteArray &kind, TArgs... args);
70 
72  bool registerForSignal(int signal);
74  bool unregisterFromSignal(int signal);
75 
77  bool preStartService();
78 
79 private Q_SLOTS:
80  void onSvcStarted(bool success);
81  void onSvcStopped();
82  void onSvcReloaded(bool success);
83  void onSvcResumed(bool success);
84  void onSvcPaused(bool success);
85 
86 private:
88 };
89 
90 template<typename TRet, typename... TArgs>
91 TRet ServiceBackend::processServiceCallback(const QByteArray &kind, TArgs... args)
92 {
93  return processServiceCallbackImpl(kind, {QVariant::fromValue(args)...}).template value<TRet>();
94 }
95 
96 template<typename... TArgs>
97 void ServiceBackend::processServiceCallback(const QByteArray &kind, TArgs... args)
98 {
100 }
101 
102 }
103 
105 
106 #endif // QTSERVICE_SERVICEBACKEND_H
ServiceCommand
The standard service commands that the library can handle.
Service should stop. Will lead to Service::onStop beeing called.
QVariant processServiceCallbackImpl(const QByteArray &kind, const QVariantList &args={})
Calls a special command as service callback synchronously.
Service should reload. Will lead to Service::onReload beeing called.
The main interface to implement to create a service.
Definition: service.h:37
TRet processServiceCallback(const QByteArray &kind, TArgs... args)
Calls a special command as service callback synchronously.
The primary namespace of the QtService library.
QVariant fromValue(const T &value)
The interface that needs to be implemented to provide the backend for the service engine...
Service should pause. Will lead to Service::onPause beeing called.
Service was started. Will lead to Service::onStart beeing called.