libalcommon  2.1.0.18
/home/opennao/work/master/sdk/libnaoqi/libalcommon/alcommon/almodule.h
Go to the documentation of this file.
00001 
00010 #pragma once
00011 #ifndef _LIBALCOMMON_ALCOMMON_ALMODULE_H_
00012 #define _LIBALCOMMON_ALCOMMON_ALMODULE_H_
00013 
00014 # include <alcommon/api.h>
00015 # include <qi/macro.hpp>
00016 # include <alcommon/almodulecore.h>
00017 # include <boost/signal.hpp>
00018 
00020 namespace AL
00021 {
00022   class ALBroker;
00023   class ALProxy;
00024   class ALValue;
00025 
00026 
00027   namespace detail
00028   {
00029     class ALProcessSignals
00030     {
00031     public:
00032       ALProcessSignals()  {}
00033       virtual ~ALProcessSignals() {}
00034 
00035       typedef boost::signal<void ()>                     ProcessSignal;
00036       typedef boost::signal<void ()>::slot_function_type ProcessSignalSlot;
00037       typedef boost::signals::connect_position           ProcessSignalPosition;
00038       typedef boost::signals::connection                 ProcessSignalConnection;
00039 
00043       inline ProcessSignalConnection atPreProcess(
00044           ProcessSignalSlot subscriber,
00045           ProcessSignalPosition pos = boost::signals::at_back)
00046       {
00047         return fPreProcess.connect(subscriber, pos);
00048       }
00049 
00051       inline ProcessSignalConnection atPostProcess(
00052           ProcessSignalSlot subscriber,
00053           ProcessSignalPosition pos = boost::signals::at_back)
00054       {
00055         return fPostProcess.connect(subscriber, pos);
00056       }
00057 
00058       inline void removeAllPreProcess(void) {
00059         fPreProcess.disconnect_all_slots();
00060       }
00061 
00062       inline void removeAllPostProcess(void) {
00063         fPostProcess.disconnect_all_slots();
00064       }
00065 
00067       inline void preProcess(void) {
00068         fPreProcess();
00069       }
00070 
00072       inline void postProcess(void) {
00073         fPostProcess();
00074       }
00075 
00076     protected:
00077       ProcessSignal fPreProcess;
00078       ProcessSignal fPostProcess;
00079     };
00080   }
00081 
00082 
00105   class ALModule: public ALModuleCore, public detail::ALProcessSignals
00106   {
00107     friend class baseModule;
00108 
00109   public:
00116     template <class T>
00117     static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker)
00118     {
00119       boost::shared_ptr<T> module(new T(pBroker));
00120       module->initModule();
00121       try
00122       {
00123         // we call init on a ALModule::Ptr as init may be protected
00124         // init is a virtual method that can be reimplemented
00125         (boost::static_pointer_cast<ALModule>(module))->init();
00126       }
00127       catch(const ALError& e)
00128       {
00129         module->exit();
00130         throw(e);
00131       }
00132       return module;
00133     }
00134 
00142     template <class T, typename P1>
00143     static boost::shared_ptr<T> createModule(boost::shared_ptr<ALBroker> pBroker, P1 p1)
00144     {
00145       boost::shared_ptr<T> module(new T(pBroker, p1));
00146       module->initModule();
00147       try
00148       {
00149         // we call init on a ALModule::Ptr as init may be protected
00150         // init is a virtual method that can be reimplemented
00151         (boost::static_pointer_cast<ALModule>(module))->init();
00152       }
00153       catch(const ALError& e)
00154       {
00155         module->exit();
00156         throw(e);
00157       }
00158       return module;
00159     }
00160 
00171     ALModule(boost::shared_ptr<ALBroker> pBroker, const std::string& pName);
00172 
00174     virtual ~ALModule();
00175 
00182     virtual std::string httpGet();
00183 
00194     virtual void stop(const int &taskId);
00195 
00201     bool isStopRequired(const int &taskId = -1);
00202 
00210     bool wait(const int &taskId, const int &timeout);
00211 
00217     bool isRunning(const int &taskId);
00218 
00226     int getMethodID(void);
00227 
00232     bool isPCalled();
00233 
00234 
00238     virtual void exit();
00239 
00249     QI_API_DEPRECATED void functionStop(int pIDTask);
00250 
00254     virtual void init(void) {}
00255   };
00256 }
00257 
00258 #endif  // _LIBALCOMMON_ALCOMMON_ALMODULE_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines