libalcommon  2.4.3.28-r2
 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 <alcommon/api.h>
15 # include <qi/macro.hpp>
16 # include <alcommon/almodulecore.h>
17 # include <boost/signals2.hpp>
18 
20 namespace AL
21 {
22  class ALBroker;
23  class ALProxy;
24  class ALValue;
25 
26 
27  namespace detail
28  {
30  {
31  public:
33  virtual ~ALProcessSignals() {}
34 
35  typedef boost::signals2::signal<void ()> ProcessSignal;
36  typedef boost::signals2::signal<void ()>::slot_function_type ProcessSignalSlot;
37  typedef boost::signals2::connect_position ProcessSignalPosition;
38  typedef boost::signals2::connection ProcessSignalConnection;
39 
44  ProcessSignalSlot subscriber,
45  ProcessSignalPosition pos = boost::signals2::at_back)
46  {
47  return fPreProcess.connect(subscriber, pos);
48  }
49 
52  ProcessSignalSlot subscriber,
53  ProcessSignalPosition pos = boost::signals2::at_back)
54  {
55  return fPostProcess.connect(subscriber, pos);
56  }
57 
58  inline void removeAllPreProcess(void) {
59  fPreProcess.disconnect_all_slots();
60  }
61 
62  inline void removeAllPostProcess(void) {
63  fPostProcess.disconnect_all_slots();
64  }
65 
67  inline void preProcess(void) {
68  fPreProcess();
69  }
70 
72  inline void postProcess(void) {
73  fPostProcess();
74  }
75 
76  protected:
79  };
80  }
81 
82 
106  {
107  friend class baseModule;
108 
109  public:
116  template <class T>
117  static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker)
118  {
119  boost::shared_ptr<T> module(new T(pBroker));
120  module->initModule();
121  try
122  {
123  // we call init on a ALModule::Ptr as init may be protected
124  // init is a virtual method that can be reimplemented
125  (boost::static_pointer_cast<ALModule>(module))->init();
126  }
127  catch(const ALError& e)
128  {
129  module->exit();
130  throw(e);
131  }
132  return module;
133  }
134 
142  template <class T, typename P1>
143  static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker, P1 p1)
144  {
145  boost::shared_ptr<T> module(new T(pBroker, p1));
146  module->initModule();
147  try
148  {
149  // we call init on a ALModule::Ptr as init may be protected
150  // init is a virtual method that can be reimplemented
151  (boost::static_pointer_cast<ALModule>(module))->init();
152  }
153  catch(const ALError& e)
154  {
155  module->exit();
156  throw(e);
157  }
158  return module;
159  }
160 
171  ALModule(boost::shared_ptr<ALBroker> pBroker, const std::string& pName);
172 
174  virtual ~ALModule();
175 
182  virtual std::string httpGet();
183 
194  virtual void stop(const int &taskId);
195 
201  bool isStopRequired(const int &taskId = -1);
202 
210  bool wait(const int &taskId, const int &timeout);
211 
218  qi::FutureSync<void> wait(const int &taskId);
219 
225  bool isRunning(const int &taskId);
226 
234  int getMethodID(void);
235 
240  bool isPCalled();
241 
242 
246  virtual void exit();
247 
257  QI_API_DEPRECATED void functionStop(int pIDTask);
258 
262  virtual void init(void) {}
263  };
264 }
265 
266 #endif // _LIBALCOMMON_ALCOMMON_ALMODULE_H_
ProcessSignalConnection atPostProcess(ProcessSignalSlot subscriber, ProcessSignalPosition pos=boost::signals2::at_back)
Connect to the postProcess signal.
Definition: almodule.h:51
ProcessSignal fPostProcess
Definition: almodule.h:78
virtual std::string httpGet()
Called by the broker webpage to detail the module. This can be overriden to provide information speci...
void preProcess(void)
Trigger methods attached to preProcess.
Definition: almodule.h:67
ALModule can be used as a base class for user modules to help serve and advertise their methods...
Definition: almodule.h:105
ALModule(boost::shared_ptr< ALBroker > pBroker, const std::string &pName)
Creates an ALModule.
bool wait(const int &taskId, const int &timeout)
Waits until the end of a long running method using the ID that was returned from a method started wit...
int getMethodID(void)
Return unique ID if method call.
ProcessSignal fPreProcess
Definition: almodule.h:77
virtual ~ALModule()
Destructor.
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:57
boost::signals2::signal< void()>::slot_function_type ProcessSignalSlot
Definition: almodule.h:36
void removeAllPostProcess(void)
Definition: almodule.h:62
virtual void stop(const int &taskId)
Stops a module's method using the ID given returned by a 'post' call. Module authors are encouraged t...
boost::signals2::connection ProcessSignalConnection
Definition: almodule.h:38
bool isPCalled()
Check if the module is pcalled.
virtual void init(void)
It will be called at every module creation, user can overload it.
Definition: almodule.h:262
static boost::shared_ptr< T > createModule(boost::shared_ptr< ALBroker > pBroker)
Create a module and link it to a broker.
Definition: almodule.h:117
friend class baseModule
Definition: almodule.h:107
virtual void exit()
Exit the module and unregister it.
static boost::shared_ptr< T > createModule(boost::shared_ptr< ALBroker > pBroker, P1 p1)
Create a module and link it to a broker.
Definition: almodule.h:143
boost::signals2::connect_position ProcessSignalPosition
Definition: almodule.h:37
ProcessSignalConnection atPreProcess(ProcessSignalSlot subscriber, ProcessSignalPosition pos=boost::signals2::at_back)
Definition: almodule.h:43
boost::signals2::signal< void()> ProcessSignal
Definition: almodule.h:35
void postProcess(void)
Trigger methods attached to postProcess.
Definition: almodule.h:72
void removeAllPreProcess(void)
Definition: almodule.h:58
QI_API_DEPRECATED void functionStop(int pIDTask)
deprecated
bool isRunning(const int &taskId)
Determines if the method created with a 'post' is still running.
bool isStopRequired(const int &taskId=-1)
Check if the user call stop.