Quark  0.1
Service.h++
Go to the documentation of this file.
1 
2 #ifndef __libquark_service_Service_hxx
3 #define __libquark_service_Service_hxx
4 
5 #include <QCoreApplication>
6 #include <QString>
7 
8 #ifdef Q_OS_WIN32
9 #include <windows.h>
10 #endif
11 
12 namespace quark {
13 namespace service {
14 
15 class Service : public QCoreApplication
16 {
17  Q_OBJECT;
18 
19  public:
20 
21  virtual ~Service();
22 
23  protected:
24 
25  Service(int argc, char **argv, const QString &name,
26  const QString &displayName, const QString &description);
27 
28  bool detach();
29  virtual bool init() = 0;
30  virtual void shutdown() = 0;
31  void testShutdown();
32 
33  inline bool isDebug() const
34  { return(_debug); }
35 
36  QString getError() const
37  { return(_error); }
38 
39  private slots:
40 
41  void postLaunch();
42 
43  private:
44 
45  static Service *getInstance();
46 
47  bool _shouldStop;
48 
49 #ifdef Q_OS_WIN32
50  static void _serviceMain(int argc, char **argv);
51  bool _initService();
52  static void _controlHandler(DWORD code);
53  bool _startService();
54  bool _stopService();
55  bool _installService();
56  bool _uninstallService();
57  bool _waitForStatus(SC_HANDLE handle, DWORD pending, DWORD final);
58 
59  SERVICE_STATUS_HANDLE _handle;
60  SERVICE_STATUS _status;
61  enum Action { None, Start, Stop, Install, Uninstall } _action;
62  UINT _oldErrorMode;
63 #endif
64 
65  QString _name;
66  QString _displayName;
67  QString _description;
68  bool _shutdown;
69  bool _debug;
70  QString _workingDir;
71  QString _error;
72 
73 #ifdef Q_OS_UNIX
74  static void _sighandler(int sig);
75 
76  QString _pidFile;
77 #endif
78 
79 };
80 
81 } // namespace service
82 } // namespace quark
83 
84 #endif // __libquark_service_Service_hxx
Service(int argc, char **argv, const QString &name, const QString &displayName, const QString &description)
Definition: BarChartView.h++:6
bool isDebug() const
Definition: Service.h++:33
virtual bool init()=0
virtual void shutdown()=0
QString getError() const
Definition: Service.h++:36
Definition: Service.h++:15