libalcommon  1.14
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
almodule.h
Go to the documentation of this file.
1 
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALMODULE_H_
12 #define _LIBALCOMMON_ALCOMMON_ALMODULE_H_
13 
14 # include <qi/macro.hpp>
15 # include <alcommon/almodulecore.h>
16 # include <boost/signal.hpp>
17 
19 namespace AL
20 {
21  class ALBroker;
22  class ALProxy;
23  class ALValue;
24 
25 
26  namespace detail
27  {
28  class ALProcessSignals
29  {
30  public:
31  ALProcessSignals() {}
32  virtual ~ALProcessSignals() {}
33 
34  typedef boost::signal<void ()> ProcessSignal;
35  typedef boost::signal<void ()>::slot_function_type ProcessSignalSlot;
36  typedef boost::signals::connect_position ProcessSignalPosition;
37  typedef boost::signals::connection ProcessSignalConnection;
38 
42  inline ProcessSignalConnection atPreProcess(
43  ProcessSignalSlot subscriber,
44  ProcessSignalPosition pos = boost::signals::at_back)
45  {
46  return fPreProcess.connect(subscriber, pos);
47  }
48 
50  inline ProcessSignalConnection atPostProcess(
51  ProcessSignalSlot subscriber,
52  ProcessSignalPosition pos = boost::signals::at_back)
53  {
54  return fPostProcess.connect(subscriber, pos);
55  }
56 
57  inline void removeAllPreProcess(void) {
58  fPreProcess.disconnect_all_slots();
59  }
60 
61  inline void removeAllPostProcess(void) {
62  fPostProcess.disconnect_all_slots();
63  }
64 
66  inline void preProcess(void) {
67  fPreProcess();
68  }
69 
71  inline void postProcess(void) {
72  fPostProcess();
73  }
74 
75  protected:
76  ProcessSignal fPreProcess;
77  ProcessSignal fPostProcess;
78  };
79  }
80 
81 
104  class ALModule: public ALModuleCore, public detail::ALProcessSignals
105  {
106  friend class baseModule;
107 
108  public:
115  template <class T>
116  static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker)
117  {
118  boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker));
119  module->initModule();
120  try
121  {
122  // we call init on a ALModule::Ptr as init may be protected
123  // init is a virtual method that can be reimplemented
124  (boost::static_pointer_cast<ALModule>(module))->init();
125  }
126  catch(const ALError& e)
127  {
128  module->exit();
129  throw(e);
130  }
131  return module;
132  }
133 
141  template <class T, typename P1>
142  static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker, P1 p1)
143  {
144  boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker, p1));
145  module->initModule();
146  try
147  {
148  // we call init on a ALModule::Ptr as init may be protected
149  // init is a virtual method that can be reimplemented
150  (boost::static_pointer_cast<ALModule>(module))->init();
151  }
152  catch(const ALError& e)
153  {
154  module->exit();
155  throw(e);
156  }
157  return module;
158  }
159 
170  ALModule(boost::shared_ptr<ALBroker> pBroker, const std::string& pName);
171 
173  virtual ~ALModule();
174 
181  virtual std::string httpGet();
182 
193  virtual void stop(const int &id);
194 
200  bool isStopRequired(const int &id = -1);
201 
209  bool wait(const int &id, const int &timeout);
210 
216  bool isRunning(const int &id);
217 
225  int getMethodID(void);
226 
231  bool isPCalled();
232 
233 
237  virtual void exit();
238 
248  QI_API_DEPRECATED void functionStop(int pIDTask);
249 
253  virtual void init(void) {}
254  };
255 }
256 #endif // _LIBALCOMMON_ALCOMMON_ALMODULE_H_