00001 #ifndef SERVICE_H_ 00002 #define SERVICE_H_ 00003 00004 #include "pthread.h" 00005 #include <string> 00006 00017 using namespace std; 00018 00019 namespace dtn 00020 { 00021 namespace utils 00022 { 00023 class Service 00024 { 00025 public: 00029 Service(string name); 00030 00034 virtual ~Service(); 00035 00036 void start(); 00037 void abort(); 00038 void waitFor(); 00039 bool isRunning(); 00040 string getName(); 00041 00042 protected: 00046 virtual void tick() = 0; 00047 00048 void finished(); 00049 00050 virtual void initialize() 00051 {}; 00052 00053 virtual void terminate() 00054 {}; 00055 00056 private: 00057 void run(); 00058 static void * entryPoint(void*); 00059 00060 bool m_running; 00061 bool m_started; 00062 00063 pthread_t m_thread; 00064 string m_name; 00065 }; 00066 } 00067 } 00068 00069 #endif /*SERVICE_H_*/
1.5.6