CServiceApplicationComp.h
Go to the documentation of this file.
1 #ifndef iservice_CServiceApplicationComp_included
2 #define iservice_CServiceApplicationComp_included
3 
4 
5 // Qt includes
6 #include <QtGui/QIcon>
7 #if QT_VERSION >= 0x050000
8 #include <QtWidgets/QSystemTrayIcon>
9 #else
10 #include <QtGui/QSystemTrayIcon>
11 #endif
12 
13 // ACF includes
14 #include <ibase/IApplication.h>
15 #include <ilog/TLoggerCompWrap.h>
16 #include <icomp/CComponentBase.h>
17 
18 #ifndef Q_OS_MAC
19 #ifndef Q_OS_LINUX
20 // ACF-Solutions includes
21 #include <iservice/QtService.h>
22 #endif
23 #endif
24 
25 
26 namespace iservice
27 {
28 
29 
34  public QObject,
36  public ibase::IApplication
37 {
38  Q_OBJECT
39 public:
41  typedef QObject BaseClass2;
42 
43  I_BEGIN_COMPONENT(CServiceApplicationComp);
44  I_REGISTER_INTERFACE(ibase::IApplication);
45  I_ASSIGN(m_applicationCompPtr, "ApplicationInstance", "Service application object", true, "Application");
46  I_ASSIGN(m_serviceDescriptionAttrPtr, "SeriviceDescription", "Service description", true, "This services provides...");
47  I_ASSIGN(m_serviceNameAttrPtr, "ServiceName", "The name of the service", true, "MyService");
48  I_ASSIGN(m_manualStartupAttrPtr, "ManualStartup", "If enabled, the service is registered with manual start up", false, false);
49  I_END_COMPONENT;
50 
51  QStringList GetApplicationArguments(int argc, char** argv) const;
52 
53  // reimplemented (ibase::IApplication)
54  virtual bool InitializeApplication(int argc, char** argv);
55  virtual int Execute(int argc, char** argv);
56  virtual QString GetHelpText() const;
57  virtual QStringList GetApplicationArguments() const;
58 
59  // reimplemented (QObject)
60  virtual bool eventFilter(QObject* sourcePtr, QEvent* eventPtr);
61 
62 protected Q_SLOTS:
63  void OnTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
64 
65 #ifdef Q_OS_WIN
66 
67 protected:
68  class CService: public QtServiceBase
69  {
70  public:
71  typedef QtServiceBase BaseClass;
72 
73  CService(CServiceApplicationComp& parent,
74  ibase::IApplication& application,
75  int serviceArgc,
76  char** serviceArgv,
77  const QString &name);
78 
79  protected:
80  // reimplemented (QtServiceBase)
81  virtual void start();
82  virtual void stop();
83  virtual void pause();
84  virtual void resume();
85  virtual void createApplication(int &argc, char **argv);
86  virtual int executeApplication();
87 
88  private:
89  QVector<char*> GetApplicationArguments() const;
90 
91  private:
92  CServiceApplicationComp& m_parent;
93  ibase::IApplication& m_application;
94  QStringList m_applicationArguments;
95  };
96 
97  istd::TDelPtr<CService> m_servicePtr;
98 #endif // Q_OS_WIN
99 
100 private:
101  I_REF(ibase::IApplication, m_applicationCompPtr);
102  I_TEXTATTR(m_serviceDescriptionAttrPtr);
103  I_ATTR(QString, m_serviceNameAttrPtr);
104  I_ATTR(bool, m_manualStartupAttrPtr);
105 };
106 
107 
108 } // namespace iservice
109 
110 
111 #endif // iservice_CServiceApplicationComp_included
112 
void OnTrayIconActivated(QSystemTrayIcon::ActivationReason reason)
virtual QString GetHelpText() const
virtual bool InitializeApplication(int argc, char **argv)
virtual QStringList GetApplicationArguments() const
Qt based component for service-based application.
ilog::CLoggerComponentBase BaseClass
virtual int Execute(int argc, char **argv)
virtual bool eventFilter(QObject *sourcePtr, QEvent *eventPtr)

© 2007-2017 Witold Gantzke and Kirill Lepskiy