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 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;
141 boost::shared_ptr<AL::ALProxy>
getProxy(
const std::string &pModuleName);
234 const std::string&
getName()
const;
258 const std::vector<std::string> ¶mType,
259 bool softCompare =
true);
275 std::vector<std::string> pParamsType);
297 std::vector<std::string> pParamsType);
311 const std::vector<std::string> ¶mType,
312 bool softCompare =
true);
338 std::string
getUsage(
const std::string &methodName);
349 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker));
350 module->initModule();
355 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
357 catch(
const ALError& e)
375 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
381 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
383 catch(
const ALError& e)
400 const std::string &name)
402 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
403 module->initModule();
407 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
409 catch(
const ALError& e)
425 const std::string &name)
427 boost::shared_ptr<T> module = createModuleCore<T>(pBroker, name);
454 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor);
464 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor,
465 const std::string &pName,
466 const std::string &pClass,
467 const std::string &pFunctionDescription,
485 const std::string &pClass,
486 const std::string &pFunctionDescription,
495 void addParam(
const std::string &pName,
496 const std::string &pDesc);
504 const std::string &pExample);
512 const std::string &pExample);
519 void setReturn(
const std::string &pName,
const std::string &pDesc);
521 virtual qi::Future<qi::AnyReference>
metaCall(qi::AnyObject context,
unsigned int method,
const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature);
536 int pCall(
const qi::AnyArguments& args);
547 int _pCall(
const unsigned int &methodId,
const std::vector<qi::AnyValue> &args);
554 ALModuleCorePrivate *
_p;
560 #endif // _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
ALMethodInfo * getMethodInfo(const std::string &pName)
Call by a proxy to check function's parameter.
boost::shared_ptr< AL::ALProxy > getProxy(const std::string &pModuleName)
Get access to a module.
qi::MetaMethodBuilder _mBuilder
void setReturn(const std::string &pName, const std::string &pDesc)
Sets the description of the return value.
ModuleType
Module type (Ruby, lua, and matlab are not currently used)
ALMethodInfo * getFunctionDescByNameMember(const std::string &pName, const std::vector< std::string > ¶mType, bool softCompare=true)
deprecated
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.
void bindMethod(boost::shared_ptr< ALFunctorBase > pFunctor)
Bind a method.
ALMethodInfo & getCurrentMethodDescription()
Get a reference to a temporary object used to construct method help.
bool ping(void)
Just a ping. Used to test connectivity to a module.
void addMethodExample(const std::string &pLanguage, const std::string &pExample)
Add a method example.
ALModuleCore is the superclass of user modules.
boost::shared_ptr< ALModuleCore > getThis()
Getter to the class.
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.
void initModule(void)
Register a module to a broker.
ALMethodInfo getMethodHelpObject(const std::string &pMethodName)
Get a method's description string.
qi::DynamicObjectBuilder _builder
virtual ~ALModuleCore()
Destructor.
boost::shared_ptr< ALBroker > getParentBroker() const
Get a pointer to the broker context.
ALModuleCore(boost::shared_ptr< ALBroker > pBroker, const std::string &pName)
Constructor.
virtual std::string httpGet()
Called by the broker webpage to detail the module.
static boost::shared_ptr< T > createUrbiModule(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a URBI module core link to a broker.
ALMethodInfo * getMethodInfoByNameMember(const std::string &pName, const std::vector< std::string > ¶mType, bool softCompare=true)
Find method information by name and argument type not only by map key.
virtual void init(void)
Call at every module creation.
std::string getBrokerName()
Get the name of the registered broker.
ALMethodInfo is the introspection container.
int pCall(const qi::AnyArguments &args)
void bindMethodOverload(boost::shared_ptr< ALFunctorBase > pFunctor)
Use to define a bound method.
int getModuleID()
Get the module id given to it be the broker.
std::string getUsage(const std::string &methodName)
Get the usage of a method as a string.
void setModuleDescription(const std::string &pDesc)
Set the description of the module.
boost::shared_ptr< ALModuleCore > Ptr
Shared pointer to ALModuleCore.
void functionName(const std::string &pName, const std::string &pClass, const std::string &pFunctionDescription, int pMask=0)
Define the name of a bound method.
const std::string & getName() const
Get the name of the module given when constructing.
ModuleType getModuleType(void)
Get the type of the module.
AL::ALValue moduleHelp()
Get the module's description.
void functionStop(int pTaskID)
Local stop. Use stop(id) for remote/local compatibility.
void setModuleID(int id)
Set the id of the module used to determine the shutdown order.
AL::ALValue getMethodHelp(const std::string &pMethodName)
Get a method's description string.
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker)
Create a module core link to a broker.
bool isClosing()
Check if someone want to exit the module.
void addModuleExample(const std::string &pLanguage, const std::string &pExample)
Add a module example.
std::vector< std::string > getMethodList()
Get the module method list.
void setModuleType(ModuleType pType)
Set the type of the module.
bool isModuleStopped()
Know if program or module termination is asked.
void addParam(const std::string &pName, const std::string &pDesc)
Add a documented parameter to a method.
qi::DynamicObjectBuilder & getBuilder()
virtual ALMethodInfo * execute(const std::string &pMethod, const AL::ALValue &pParams, AL::ALValue &pResult)
Execute a method with some arguments and store the result.
ALMethodInfo * getFunctionDesc(const std::string &pName)
deprecated
virtual std::string version()
Get module's version.
virtual qi::Future< qi::AnyReference > metaCall(qi::AnyObject context, unsigned int method, const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature)
boost::shared_ptr< ALModuleInfo > getModuleInfo()
Get information about the module.
virtual void exit()
Exit the module and unregister it.