libalcommon
1.14.5
|
00001 00010 #pragma once 00011 #ifndef _LIBALCOMMON_ALCOMMON_ALMODULE_H_ 00012 #define _LIBALCOMMON_ALCOMMON_ALMODULE_H_ 00013 00014 # include <qi/macro.hpp> 00015 # include <alcommon/almodulecore.h> 00016 # include <boost/signal.hpp> 00017 00019 namespace AL 00020 { 00021 class ALBroker; 00022 class ALProxy; 00023 class ALValue; 00024 00025 00026 namespace detail 00027 { 00028 class ALProcessSignals 00029 { 00030 public: 00031 ALProcessSignals() {} 00032 virtual ~ALProcessSignals() {} 00033 00034 typedef boost::signal<void ()> ProcessSignal; 00035 typedef boost::signal<void ()>::slot_function_type ProcessSignalSlot; 00036 typedef boost::signals::connect_position ProcessSignalPosition; 00037 typedef boost::signals::connection ProcessSignalConnection; 00038 00042 inline ProcessSignalConnection atPreProcess( 00043 ProcessSignalSlot subscriber, 00044 ProcessSignalPosition pos = boost::signals::at_back) 00045 { 00046 return fPreProcess.connect(subscriber, pos); 00047 } 00048 00050 inline ProcessSignalConnection atPostProcess( 00051 ProcessSignalSlot subscriber, 00052 ProcessSignalPosition pos = boost::signals::at_back) 00053 { 00054 return fPostProcess.connect(subscriber, pos); 00055 } 00056 00057 inline void removeAllPreProcess(void) { 00058 fPreProcess.disconnect_all_slots(); 00059 } 00060 00061 inline void removeAllPostProcess(void) { 00062 fPostProcess.disconnect_all_slots(); 00063 } 00064 00066 inline void preProcess(void) { 00067 fPreProcess(); 00068 } 00069 00071 inline void postProcess(void) { 00072 fPostProcess(); 00073 } 00074 00075 protected: 00076 ProcessSignal fPreProcess; 00077 ProcessSignal fPostProcess; 00078 }; 00079 } 00080 00081 00104 class ALModule: public ALModuleCore, public detail::ALProcessSignals 00105 { 00106 friend class baseModule; 00107 00108 public: 00115 template <class T> 00116 static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker) 00117 { 00118 boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker)); 00119 module->initModule(); 00120 try 00121 { 00122 // we call init on a ALModule::Ptr as init may be protected 00123 // init is a virtual method that can be reimplemented 00124 (boost::static_pointer_cast<ALModule>(module))->init(); 00125 } 00126 catch(const ALError& e) 00127 { 00128 module->exit(); 00129 throw(e); 00130 } 00131 return module; 00132 } 00133 00141 template <class T, typename P1> 00142 static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker, P1 p1) 00143 { 00144 boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker, p1)); 00145 module->initModule(); 00146 try 00147 { 00148 // we call init on a ALModule::Ptr as init may be protected 00149 // init is a virtual method that can be reimplemented 00150 (boost::static_pointer_cast<ALModule>(module))->init(); 00151 } 00152 catch(const ALError& e) 00153 { 00154 module->exit(); 00155 throw(e); 00156 } 00157 return module; 00158 } 00159 00170 ALModule(boost::shared_ptr<ALBroker> pBroker, const std::string& pName); 00171 00173 virtual ~ALModule(); 00174 00181 virtual std::string httpGet(); 00182 00193 virtual void stop(const int &id); 00194 00200 bool isStopRequired(const int &id = -1); 00201 00209 bool wait(const int &id, const int &timeout); 00210 00216 bool isRunning(const int &id); 00217 00225 int getMethodID(void); 00226 00231 bool isPCalled(); 00232 00233 00237 virtual void exit(); 00238 00248 QI_API_DEPRECATED void functionStop(int pIDTask); 00249 00253 virtual void init(void) {} 00254 }; 00255 } 00256 #endif // _LIBALCOMMON_ALCOMMON_ALMODULE_H_