OpenDaVINCI  4.15.3
RealtimeService.h
Go to the documentation of this file.
1 
20 #ifndef OPENDAVINCI_CORE_BASE_REALTIMESERVICE_H_
21 #define OPENDAVINCI_CORE_BASE_REALTIMESERVICE_H_
22 
23 #include <memory>
24 
29 
30 namespace odcore { namespace wrapper { class Thread; } }
31 
32 namespace odcore {
33  namespace base {
34 
35  using namespace std;
36 
63  private:
64  // Internal constants.
65  enum {
66  ONEMICROSECOND = 1,
67  THOUSANDMICROSECONDS = 1000 * ONEMICROSECOND
68  };
69 
70  enum REALTIMESERVICE_STATE {
71  INITIALIZED,
72  RUNNING,
73  STOPPED
74  };
75 
76  private:
83 
89  RealtimeService& operator=(const RealtimeService &);
90 
91  public:
92  enum PERIOD {
93  ONEMILLISECOND = 1 * THOUSANDMICROSECONDS,
94  TWOMILLISECONDS = 2 * THOUSANDMICROSECONDS,
95  FIVEMILLISECONDS = 5 * THOUSANDMICROSECONDS,
96  TENMILLISECONDS = 10 * ONEMILLISECOND,
97  TWENTYMILLISECONDS = 20 * ONEMILLISECOND,
98  FIFTYMILLISECONDS = 50 * ONEMILLISECOND,
99  ONEHUNDREDMILLISECONDS = 100 * ONEMILLISECOND,
100  TWOHUNDREDMILLISECONDS = 200 * ONEMILLISECOND,
101  FIVEHUNDREDMILLISECONDS = 500 * ONEMILLISECOND,
102  ONESECOND = 1000 * ONEMILLISECOND,
103  TWOSECONDS = 2 * ONESECOND,
104  FIVESECONDS = 5 * ONESECOND
105  };
106 
113  RealtimeService(const enum PERIOD &period) throw (exceptions::ThreadException);
114 
115  virtual ~RealtimeService();
116 
120  void start();
121 
126  void stop();
127 
128  protected:
129  virtual void nextTimeSlice() = 0;
130 
131  virtual bool isRunning();
132 
133  private:
134  unique_ptr<odcore::wrapper::Thread> m_thread;
135 
136  Mutex m_realtimeServiceStateMutex;
137  REALTIMESERVICE_STATE m_realtimeServiceState;
138  };
139 
140  }
141 } // odcore::base
142 
143 #endif /*OPENDAVINCI_CORE_BASE_REALTIMESERVICE_H_*/
Definition: base/Mutex.h:49
PERIOD
Definition: RealtimeService.h:92
Definition: RealtimeRunnable.h:74
#define OPENDAVINCI_API
Definition: opendavinci.h:67
Definition: RealtimeService.h:62