OpenDaVINCI  4.15.3
Service.h
Go to the documentation of this file.
1 
20 #ifndef OPENDAVINCI_CORE_BASE_SERVICE_H_
21 #define OPENDAVINCI_CORE_BASE_SERVICE_H_
22 
23 #include <memory>
24 
30 
31 namespace odcore { namespace wrapper { class Thread; } }
32 
33 namespace odcore {
34  namespace base {
35 
36  using namespace std;
37 
63  private:
64  enum SERVICE_STATE {
65  INITIALIZED,
66  RUNNING,
67  STOPPED
68  };
69 
70  private:
76  Service(const Service &);
77 
83  Service& operator=(const Service &);
84 
85  public:
86  Service() throw (exceptions::ThreadException) ;
87 
88  virtual ~Service();
89 
94  void start();
95 
100  void stop();
101 
107  void serviceReady();
108 
109  protected:
113  virtual void beforeStop() = 0;
114 
115  virtual void run() = 0;
116 
117  virtual bool isRunning();
118 
119  private:
120  unique_ptr<odcore::wrapper::Thread> m_thread;
121 
122  Mutex m_serviceStateMutex;
123  SERVICE_STATE m_serviceState;
124  Condition m_serviceReadyCondition;
125  bool m_serviceReady;
126  };
127 
128  }
129 } // odcore::base
130 
131 #endif /*OPENDAVINCI_CORE_BASE_SERVICE_H_*/
Definition: base/Condition.h:64
Definition: base/Mutex.h:49
Definition: Service.h:62
#define OPENDAVINCI_API
Definition: opendavinci.h:67
Definition: Runnable.h:35