- Aldebaran documentation |
- C++ Libraries |
- index

libalcommon 2.8.7.4

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
almodulecore.h
Go to the documentation of this file.
1
10 #pragma once
11 #ifndef _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
12 #define _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
13
14 # include <alcommon/api.h>
15 # include <boost/enable_shared_from_this.hpp>
16 # include <boost/shared_ptr.hpp>
17 # include <boost/noncopyable.hpp>
18
19 # include <alcommon/almoduleinfo.h>
20 # include <alcommon/almethodinfo.h>
21 # include <alcommon/alfunctor.h>
22
23 # include <alerror/alerror.h>
24 # include <qi/log.hpp>
25 # include <map>
26
27 #include <qi/anyfunction.hpp>
28 #include <qi/signature.hpp>
29 #include <qi/type/dynamicobject.hpp>
30 #include <qi/type/dynamicobjectbuilder.hpp>
31
32 //legacy hell, LEGACY HELL
33 #define BIND_OBJ_METHOD(objptr, meth) _builder.advertiseMethod(_mBuilder, objptr, &meth)
34 #define BIND_METHOD(meth) _builder.advertiseMethod(_mBuilder, this, &meth)
35
36 #define BIND_OBJ_METHOD_PTR(objptr, methptr) _builder.advertiseMethod(_mBuilder, objptr, methptr)
37 #define BIND_METHOD_PTR(methptr) _builder.advertiseMethod(_mBuilder, this, methptr)
38
39 namespace AL
40 {
41 class ALBroker;
42 class ALProxy;
43 class ALValue;
44 class ALModuleCorePrivate;
45
57 class ALCOMMON_API ALModuleCore: public ::boost::enable_shared_from_this<ALModuleCore>, public ::boost::noncopyable, public qi::DynamicObject
58 {
59 public:
65 typedef boost::shared_ptr<ALModuleCore> Ptr;
71 typedef boost::weak_ptr<ALModuleCore> WeakPtr;
72
78 enum ModuleType
79 {
80 CPP = 0,
81 PYTHON = 1,
82 RUBY = 2,
83 LUA = 3,
84 MATLAB = 4,
85 URBI
86 };
87
97 ALModuleCore(boost::shared_ptr<ALBroker> pBroker,
98 const std::string &pName);
99
101 virtual ~ALModuleCore();
102
108 ALMethodInfo& getCurrentMethodDescription();
109
114 boost::shared_ptr<ALModuleCore> getThis();
119 boost::shared_ptr<const ALModuleCore> getThis() const;
120
125 bool isClosing();
126
132 void initModule(void);
133
141 boost::shared_ptr<AL::ALProxy> getProxy(const std::string &pModuleName);
142
147 std::string getBrokerName();
148
153 ModuleType getModuleType(void);
154
159 void setModuleType(ModuleType pType);
160
169 virtual ALMethodInfo* execute(const std::string &pMethod,
170 const AL::ALValue &pParams,
171 AL::ALValue &pResult);
172
177 std::vector<std::string> getMethodList();
178
198 AL::ALValue getMethodHelp(const std::string &pMethodName);
199
205 ALMethodInfo getMethodHelpObject(const std::string &pMethodName);
206
211 AL::ALValue moduleHelp();
212
217 bool ping(void);
218
223 virtual std::string version();
224
228 virtual void exit();
229
234 const std::string& getName() const;
235
240 boost::shared_ptr<ALModuleInfo> getModuleInfo();
241
251 ALMethodInfo* getMethodInfoByNameMember(const std::string &pName,
252 const std::vector<std::string> &paramType,
253 bool softCompare = true);
254
260 ALMethodInfo* getMethodInfo(const std::string &pName);
261
268 ALMethodInfo* getMethodInfo(const std::string &pName,
269 std::vector<std::string> pParamsType);
270
277 ALMethodInfo* getMethodInfo(const std::string &pName,
278 const AL::ALValue &pParams);
279
284 ALMethodInfo* getFunctionDesc(const std::string &pName);
285
290 ALMethodInfo* getFunctionDesc(const std::string &pName,
291 std::vector<std::string> pParamsType);
292
297 ALMethodInfo* getFunctionDesc(const std::string &pName,
298 const AL::ALValue &pParams);
299
304 ALMethodInfo* getFunctionDescByNameMember(const std::string &pName,
305 const std::vector<std::string> &paramType,
306 bool softCompare = true);
307
312 boost::shared_ptr<ALBroker> getParentBroker() const;
313
318 void functionStop(int pTaskID);
319
320
325 void setModuleDescription(const std::string &pDesc);
326
332 std::string getUsage(const std::string &methodName);
333
340 template <class T>
341 static boost::shared_ptr<T> createModuleCore(boost::shared_ptr<ALBroker> pBroker)
342 {
343 boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker));
344 module->initModule(); // register module in broker
345 try
346 {
347 // we call init on a ALModule::Ptr as init may be protected
348 // init is a virtual method that can be reimplemented
349 (boost::static_pointer_cast<ALModuleCore>(module))->init();
350 }
351 catch(const ALError& e)
352 {
353 module->exit();
354 throw(e);
355 }
356 return module;
357 }
358
366 template <class T>
367 static boost::shared_ptr<T> createModuleCoreNoRegister(boost::shared_ptr<ALBroker> pBroker, const std::string &name)
368 {
369 boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker, name));
370 //module->initModule(); // register module in broker
371 try
372 {
373 // we call init on a ALModule::Ptr as init may be protected
374 // init is a virtual method that can be reimplemented
375 (boost::static_pointer_cast<ALModuleCore>(module))->init();
376 }
377 catch(const ALError& e)
378 {
379 module->exit();
380 throw(e);
381 }
382 return module;
383 }
384
392 template <class T>
393 static boost::shared_ptr<T> createModuleCore(boost::shared_ptr<ALBroker> pBroker,
394 const std::string &name)
395 {
396 boost::shared_ptr<T> module = boost::shared_ptr<T>(new T(pBroker, name));
397 module->initModule();
398 try
399 {
400 // init if you redefined it
401 (boost::static_pointer_cast<ALModuleCore>(module))->init();
402 }
403 catch(const ALError& e)
404 {
405 module->exit();
406 throw(e);
407 }
408 return module;
409 }
410
417 template <class T>
418 static boost::shared_ptr<T> createUrbiModule(boost::shared_ptr<ALBroker> pBroker,
419 const std::string &name)
420 {
421 boost::shared_ptr<T> module = createModuleCore<T>(pBroker, name);
422 module->setModuleType(AL::ALModuleCore::URBI);
423 return module;
424 }
425
430 bool isModuleStopped();
431
436 void setModuleID(int id);
437
442 int getModuleID();
443
448 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor);
449
458 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor,
459 const std::string &pName,
460 const std::string &pClass,
461 const std::string &pFunctionDescription,
462 const ALMethodInfo &pMethodDescription);
463
468 void bindMethodOverload(boost::shared_ptr<ALFunctorBase> pFunctor);
469
478 void functionName(const std::string &pName,
479 const std::string &pClass,
480 const std::string &pFunctionDescription,
481 int pMask = 0);
482
489 void addParam(const std::string &pName,
490 const std::string &pDesc);
491
497 void addModuleExample(const std::string &pLanguage,
498 const std::string &pExample);
499
505 void addMethodExample(const std::string &pLanguage,
506 const std::string &pExample);
507
513 void setReturn(const std::string &pName, const std::string &pDesc);
514
515 virtual qi::Future<qi::AnyReference> metaCall(qi::AnyObject context, unsigned int method, const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature);
516
517
518 qi::AnyObject asObject();
519
524 qi::DynamicObjectBuilder& getBuilder() {return _builder;}
525
526
530 int pCall(const qi::AnyArguments& args);
531
532 protected:
538 virtual void init(void) {}
539
540 private:
541 int _pCall(const unsigned int &methodId, const std::vector<qi::AnyValue> &args);
542
543 protected:
544 qi::DynamicObjectBuilder _builder;
545 friend class baseModule; // for inaoqi that needs to advertise methods
546 public:
547 qi::GenericObject _go;
548 ALModuleCorePrivate *_p;
549 qi::MetaMethodBuilder _mBuilder;
550
551 }; // !ALModuleCore
552 }
553
554 #endif // _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
api.h
AL::ALModuleCore::_mBuilder
qi::MetaMethodBuilder _mBuilder
Definition: almodulecore.h:549
AL::ALModuleCore::ModuleType
ModuleType
Module type (Ruby, lua, and matlab are not currently used)
Definition: almodulecore.h:78
AL::ALModuleCore::createModuleCoreNoRegister
static boost::shared_ptr< T > createModuleCoreNoRegister(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a module core, do not register on the broker.
Definition: almodulecore.h:367
almethodinfo.h
AL::ALModuleCore
ALModuleCore is the superclass of user modules.
Definition: almodulecore.h:57
AL::ALModuleCore::WeakPtr
boost::weak_ptr< ALModuleCore > WeakPtr
Weak pointer to ALModuleCore.
Definition: almodulecore.h:71
AL::ALModuleCore::createModuleCore
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a module core link to a broker.
Definition: almodulecore.h:393
AL::ALModuleCore::_builder
qi::DynamicObjectBuilder _builder
Definition: almodulecore.h:544
AL::ALModuleCore::createUrbiModule
static boost::shared_ptr< T > createUrbiModule(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a URBI module core link to a broker.
Definition: almodulecore.h:418
AL::ALModuleCore::init
virtual void init(void)
Call at every module creation.
Definition: almodulecore.h:538
AL::ALMethodInfo
ALMethodInfo is the introspection container.
Definition: almethodinfo.h:33
AL::ALModuleCore::_p
ALModuleCorePrivate * _p
Definition: almodulecore.h:548
AL::ALModuleCore::_go
qi::GenericObject _go
Definition: almodulecore.h:547
AL::ALModuleCore::Ptr
boost::shared_ptr< ALModuleCore > Ptr
Shared pointer to ALModuleCore.
Definition: almodulecore.h:65
AL::ALValue
AL::ALModuleCore::createModuleCore
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker)
Create a module core link to a broker.
Definition: almodulecore.h:341
ALCOMMON_API
#define ALCOMMON_API
Definition: api.h:14
AL::ALModuleCore::getBuilder
qi::DynamicObjectBuilder & getBuilder()
Definition: almodulecore.h:524
alfunctor.h
AL::ALModuleCore::URBI
Definition: almodulecore.h:85
almoduleinfo.h