libalcommon  2.5.11.14a
 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 
186  virtual void stop(const int &taskId);
187 
193  bool isStopRequired(const int &taskId = -1);
194 
202  bool wait(const int &taskId, const int &timeout);
203 
210  qi::FutureSync<void> wait(const int &taskId);
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_
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
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
ProcessSignal fPreProcess
Definition: almodule.h:77
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
boost::signals2::connection ProcessSignalConnection
Definition: almodule.h:38
virtual void init(void)
It will be called at every module creation, user can overload it.
Definition: almodule.h:254
static boost::shared_ptr< T > createModule(boost::shared_ptr< ALBroker > pBroker)
Create a module and link it to a broker.
Definition: almodule.h:117
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
#define ALCOMMON_API
Definition: api.h:14
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