11 #ifndef _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
12 #define _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
15 # include <boost/enable_shared_from_this.hpp>
16 # include <boost/shared_ptr.hpp>
17 # include <boost/noncopyable.hpp>
23 # include <alerror/alerror.h>
24 # include <qi/log.hpp>
27 #include <qi/anyfunction.hpp>
28 #include <qi/signature.hpp>
29 #include <qi/type/dynamicobject.hpp>
30 #include <qi/type/dynamicobjectbuilder.hpp>
33 #define BIND_OBJ_METHOD(objptr, meth) _builder.advertiseMethod(_mBuilder, objptr, &meth)
34 #define BIND_METHOD(meth) _builder.advertiseMethod(_mBuilder, this, &meth)
36 #define BIND_OBJ_METHOD_PTR(objptr, methptr) _builder.advertiseMethod(_mBuilder, objptr, methptr)
37 #define BIND_METHOD_PTR(methptr) _builder.advertiseMethod(_mBuilder, this, methptr)
44 class ALModuleCorePrivate;
57 class ALCOMMON_API ALModuleCore:
public ::boost::enable_shared_from_this<ALModuleCore>,
public ::boost::noncopyable,
public qi::DynamicObject
65 typedef boost::shared_ptr<ALModuleCore>
Ptr;
71 typedef boost::weak_ptr<ALModuleCore>
WeakPtr;
98 const std::string &pName);
114 boost::shared_ptr<ALModuleCore> getThis();
119 boost::shared_ptr<const ALModuleCore> getThis()
const;
132 void initModule(
void);
141 boost::shared_ptr<AL::ALProxy> getProxy(
const std::string &pModuleName);
147 std::string getBrokerName();
153 ModuleType getModuleType(
void);
159 void setModuleType(ModuleType pType);
169 virtual ALMethodInfo* execute(
const std::string &pMethod,
177 std::vector<std::string> getMethodList();
198 AL::ALValue getMethodHelp(
const std::string &pMethodName);
205 ALMethodInfo getMethodHelpObject(
const std::string &pMethodName);
223 virtual std::string version();
234 const std::string& getName()
const;
240 boost::shared_ptr<ALModuleInfo> getModuleInfo();
251 ALMethodInfo* getMethodInfoByNameMember(
const std::string &pName,
252 const std::vector<std::string> ¶mType,
253 bool softCompare =
true);
269 std::vector<std::string> pParamsType);
284 ALMethodInfo* getFunctionDesc(
const std::string &pName);
291 std::vector<std::string> pParamsType);
304 ALMethodInfo* getFunctionDescByNameMember(
const std::string &pName,
305 const std::vector<std::string> ¶mType,
306 bool softCompare =
true);
312 boost::shared_ptr<ALBroker> getParentBroker()
const;
318 void functionStop(
int pTaskID);
325 void setModuleDescription(
const std::string &pDesc);
332 std::string getUsage(
const std::string &methodName);
343 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker));
344 module->initModule();
349 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
351 catch(
const ALError& e)
369 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
375 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
377 catch(
const ALError& e)
394 const std::string &name)
396 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
397 module->initModule();
401 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
403 catch(
const ALError& e)
419 const std::string &name)
421 boost::shared_ptr<T> module = createModuleCore<T>(pBroker, name);
430 bool isModuleStopped();
436 void setModuleID(
int id);
448 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor);
458 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor,
459 const std::string &pName,
460 const std::string &pClass,
461 const std::string &pFunctionDescription,
468 void bindMethodOverload(boost::shared_ptr<ALFunctorBase> pFunctor);
478 void functionName(
const std::string &pName,
479 const std::string &pClass,
480 const std::string &pFunctionDescription,
489 void addParam(
const std::string &pName,
490 const std::string &pDesc);
497 void addModuleExample(
const std::string &pLanguage,
498 const std::string &pExample);
505 void addMethodExample(
const std::string &pLanguage,
506 const std::string &pExample);
513 void setReturn(
const std::string &pName,
const std::string &pDesc);
515 virtual qi::Future<qi::AnyReference> metaCall(qi::AnyObject context,
unsigned int method,
const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature);
518 qi::AnyObject asObject();
530 int pCall(
const qi::AnyArguments& args);
541 int _pCall(
const unsigned int &methodId,
const std::vector<qi::AnyValue> &args);
545 friend class baseModule;
548 ALModuleCorePrivate *
_p;
554 #endif // _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
qi::MetaMethodBuilder _mBuilder
ModuleType
Module type (Ruby, lua, and matlab are not currently used)
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.
ALModuleCore is the superclass of user modules.
boost::weak_ptr< ALModuleCore > WeakPtr
Weak pointer to ALModuleCore.
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a module core link to a broker.
qi::DynamicObjectBuilder _builder
static boost::shared_ptr< T > createUrbiModule(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a URBI module core link to a broker.
virtual void init(void)
Call at every module creation.
ALMethodInfo is the introspection container.
boost::shared_ptr< ALModuleCore > Ptr
Shared pointer to ALModuleCore.
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker)
Create a module core link to a broker.
qi::DynamicObjectBuilder & getBuilder()