libalcommon  2.1.4.13
 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/signal.hpp>
18 
20 namespace AL
21 {
22  class ALBroker;
23  class ALProxy;
24  class ALValue;
25 
26 
27  namespace detail
28  {
29  class ALProcessSignals
30  {
31  public:
32  ALProcessSignals() {}
33  virtual ~ALProcessSignals() {}
34 
35  typedef boost::signal<void ()> ProcessSignal;
36  typedef boost::signal<void ()>::slot_function_type ProcessSignalSlot;
37  typedef boost::signals::connect_position ProcessSignalPosition;
38  typedef boost::signals::connection ProcessSignalConnection;
39 
43  inline ProcessSignalConnection atPreProcess(
44  ProcessSignalSlot subscriber,
45  ProcessSignalPosition pos = boost::signals::at_back)
46  {
47  return fPreProcess.connect(subscriber, pos);
48  }
49 
51  inline ProcessSignalConnection atPostProcess(
52  ProcessSignalSlot subscriber,
53  ProcessSignalPosition pos = boost::signals::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:
77  ProcessSignal fPreProcess;
78  ProcessSignal fPostProcess;
79  };
80  }
81 
82 
105  class ALModule: public ALModuleCore, public detail::ALProcessSignals
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 
217  bool isRunning(const int &taskId);
218 
226  int getMethodID(void);
227 
232  bool isPCalled();
233 
234 
238  virtual void exit();
239 
249  QI_API_DEPRECATED void functionStop(int pIDTask);
250 
254  virtual void init(void) {}
255  };
256 }
257 
258 #endif // _LIBALCOMMON_ALCOMMON_ALMODULE_H_
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
virtual ~ALModule()
Destructor.
bool isRunning(const int &taskId)
Determines if the method created with a 'post' is still running.
static boost::shared_ptr< T > createModule(boost::shared_ptr< ALBroker > pBroker)
Create a module and link it to a broker.
Definition: almodule.h:117
QI_API_DEPRECATED void functionStop(int pIDTask)
deprecated
bool isPCalled()
Check if the module is pcalled.
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:58
bool isStopRequired(const int &taskId=-1)
Check if the user call stop.
ALModule(boost::shared_ptr< ALBroker > pBroker, const std::string &pName)
Creates an ALModule.
virtual void exit()
Exit the module and unregister it.
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...
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...
ALModule can be used as a base class for user modules to help serve and advertise their methods...
Definition: almodule.h:105
friend class baseModule
Definition: almodule.h:107
virtual void init(void)
It will be called at every module creation, user can overload it.
Definition: almodule.h:254
virtual std::string httpGet()
Called by the broker webpage to detail the module. This can be overriden to provide information speci...
int getMethodID(void)
Return unique ID if method call.