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 <qitype/dynamicobject.hpp>
28 #include <qitype/signature.hpp>
29 #include <qitype/anyfunction.hpp>
30 #include <qitype/dynamicobjectbuilder.hpp>
31 #include <qitype/dynamicobject.hpp>
34 #define BIND_OBJ_METHOD(objptr, meth) _builder.advertiseMethod(_mBuilder, objptr, &meth)
35 #define BIND_METHOD(meth) _builder.advertiseMethod(_mBuilder, this, &meth)
37 #define BIND_OBJ_METHOD_PTR(objptr, methptr) _builder.advertiseMethod(_mBuilder, objptr, methptr)
38 #define BIND_METHOD_PTR(methptr) _builder.advertiseMethod(_mBuilder, this, methptr)
45 class ALModuleCorePrivate;
58 class ALModuleCore:
public ::boost::enable_shared_from_this<ALModuleCore>,
public ::boost::noncopyable,
public qi::DynamicObject
66 typedef boost::shared_ptr<ALModuleCore>
Ptr;
72 typedef boost::weak_ptr<ALModuleCore>
WeakPtr;
99 const std::string &pName);
115 boost::shared_ptr<ALModuleCore>
getThis();
120 boost::shared_ptr<const ALModuleCore>
getThis()
const;
142 boost::shared_ptr<AL::ALProxy>
getProxy(
const std::string &pModuleName);
235 const std::string&
getName()
const;
259 const std::vector<std::string> ¶mType,
260 bool softCompare =
true);
276 std::vector<std::string> pParamsType);
298 std::vector<std::string> pParamsType);
312 const std::vector<std::string> ¶mType,
313 bool softCompare =
true);
339 std::string
getUsage(
const std::string &methodName);
350 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker));
351 module->initModule();
356 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
358 catch(
const ALError& e)
376 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
382 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
384 catch(
const ALError& e)
401 const std::string &name)
403 boost::shared_ptr<T> module = boost::shared_ptr<T>(
new T(pBroker, name));
404 module->initModule();
408 (boost::static_pointer_cast<
ALModuleCore>(module))->init();
410 catch(
const ALError& e)
426 const std::string &name)
428 boost::shared_ptr<T> module = createModuleCore<T>(pBroker, name);
455 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor);
465 void bindMethod(boost::shared_ptr<ALFunctorBase> pFunctor,
466 const std::string &pName,
467 const std::string &pClass,
468 const std::string &pFunctionDescription,
486 const std::string &pClass,
487 const std::string &pFunctionDescription,
496 void addParam(
const std::string &pName,
497 const std::string &pDesc);
505 const std::string &pExample);
513 const std::string &pExample);
520 void setReturn(
const std::string &pName,
const std::string &pDesc);
522 virtual qi::Future<qi::AnyReference>
metaCall(qi::AnyObject context,
unsigned int method,
const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature);
537 int pCall(
const qi::AnyArguments& args);
548 int _pCall(
const unsigned int &methodId,
const std::vector<qi::AnyValue> &args);
555 ALModuleCorePrivate *
_p;
561 #endif // _LIBALCOMMON_ALCOMMON_ALMODULECORE_H_
ModuleType
Module type (Ruby, lua, and matlab are not currently used)
boost::shared_ptr< ALBroker > getParentBroker() const
Get a pointer to the broker context.
boost::shared_ptr< ALModuleCore > getThis()
Getter to the class.
boost::shared_ptr< ALModuleCore > Ptr
Shared pointer to ALModuleCore.
boost::shared_ptr< AL::ALProxy > getProxy(const std::string &pModuleName)
Get access to a module.
virtual qi::Future< qi::AnyReference > metaCall(qi::AnyObject context, unsigned int method, const qi::GenericFunctionParameters &in, qi::MetaCallType callType, qi::Signature returnSignature)
AL::ALValue getMethodHelp(const std::string &pMethodName)
Get a method's description string.
boost::shared_ptr< ALModuleInfo > getModuleInfo()
Get information about the module.
void functionStop(int pTaskID)
Local stop. Use stop(id) for remote/local compatibility.
void addMethodExample(const std::string &pLanguage, const std::string &pExample)
Add a method example.
ALMethodInfo getMethodHelpObject(const std::string &pMethodName)
Get a method's description string.
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.
void bindMethod(boost::shared_ptr< ALFunctorBase > pFunctor)
Bind a method.
std::string getBrokerName()
Get the name of the registered broker.
void functionName(const std::string &pName, const std::string &pClass, const std::string &pFunctionDescription, int pMask=0)
Define the name of a bound method.
void bindMethodOverload(boost::shared_ptr< ALFunctorBase > pFunctor)
Use to define a bound method.
void initModule(void)
Register a module to a broker.
ALMethodInfo * getFunctionDescByNameMember(const std::string &pName, const std::vector< std::string > ¶mType, bool softCompare=true)
deprecated
qi::DynamicObjectBuilder _builder
void setModuleDescription(const std::string &pDesc)
Set the description of the module.
ALModuleCore(boost::shared_ptr< ALBroker > pBroker, const std::string &pName)
Constructor.
ALModuleCore is the superclass of user modules.
void setModuleType(ModuleType pType)
Set the type of the module.
const std::string & getName() const
Get the name of the module given when constructing.
ModuleType getModuleType(void)
Get the type of the module.
virtual ALMethodInfo * execute(const std::string &pMethod, const AL::ALValue &pParams, AL::ALValue &pResult)
Execute a method with some arguments and store the result.
int getModuleID()
Get the module id given to it be the broker.
virtual std::string httpGet()
Called by the broker webpage to detail the module.
ALMethodInfo * getMethodInfo(const std::string &pName)
Call by a proxy to check function's parameter.
virtual void exit()
Exit the module and unregister it.
bool ping(void)
Just a ping. Used to test connectivity to a module.
virtual ~ALModuleCore()
Destructor.
qi::DynamicObjectBuilder & getBuilder()
ALMethodInfo & getCurrentMethodDescription()
Get a reference to a temporary object used to construct method help.
void addParam(const std::string &pName, const std::string &pDesc)
Add a documented parameter to a method.
AL::ALValue moduleHelp()
Get the module's description.
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a module core link to a broker.
qi::MetaMethodBuilder _mBuilder
virtual void init(void)
Call at every module creation.
std::vector< std::string > getMethodList()
Get the module method list.
virtual std::string version()
Get module's version.
static boost::shared_ptr< T > createModuleCore(boost::shared_ptr< ALBroker > pBroker)
Create a module core link to a broker.
static boost::shared_ptr< T > createUrbiModule(boost::shared_ptr< ALBroker > pBroker, const std::string &name)
Create a URBI module core link to a broker.
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.
bool isClosing()
Check if someone want to exit the module.
void addModuleExample(const std::string &pLanguage, const std::string &pExample)
Add a module example.
bool isModuleStopped()
Know if program or module termination is asked.
int pCall(const qi::AnyArguments &args)
ALMethodInfo * getFunctionDesc(const std::string &pName)
deprecated
ALMethodInfo is the introspection container.
void setReturn(const std::string &pName, const std::string &pDesc)
Sets the description of the return value.
void setModuleID(int id)
Set the id of the module used to determine the shutdown order.
boost::weak_ptr< ALModuleCore > WeakPtr
Weak pointer to ALModuleCore.
std::string getUsage(const std::string &methodName)
Get the usage of a method as a string.