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

libqi-api 2.8.7.4

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

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
anymodule.hpp
Go to the documentation of this file.
1 /*
2 ** Copyright (C) 2012 Aldebaran Robotics
3 ** See COPYING for the license
4 */
5
6 #ifndef _QITYPE_PACKAGE_HPP_
7 #define _QITYPE_PACKAGE_HPP_
8
9 #include <string>
10 #include <map>
11 #include <vector>
12
13 #include <qi/log.hpp>
14 #include <qi/anyobject.hpp>
15 #include <qi/anyvalue.hpp>
16 #include <boost/thread/recursive_mutex.hpp>
17 #include <boost/shared_ptr.hpp>
18 #include <qi/type/objecttypebuilder.hpp>
19 #include <qi/type/dynamicobjectbuilder.hpp>
20
21 namespace qi
22 {
23 class ModuleBuilder;
24
25 /* Factory helper functions
26 */
27
28 struct ModuleInfo {
29 std::string name;
30 std::string type;
31 std::string path;
32 };
33
38 class QI_API AnyModule : public AnyObject
39 {
40 public:
41 AnyModule()
42 {}
43
44 AnyModule(const ModuleInfo &moduleInfo, const qi::AnyObject& object)
45 : AnyObject(object)
46 , _moduleInfo(moduleInfo)
47 {}
48
49 const std::string& moduleName() const {
50 return _moduleInfo.name;
51 }
52
53 const ModuleInfo &moduleInfo() const {
54 return _moduleInfo;
55 }
56
57 ModuleInfo _moduleInfo;
58 };
59
60
63 class QI_API ModuleBuilder : public DynamicObjectBuilder {
64 public:
65 ModuleBuilder(const ModuleInfo& mi)
66 : _moduleInfo(mi)
67 {
68 this->setThreadingModel(ObjectThreadingModel_MultiThread);
69 }
70
71 void setModuleInfo(const ModuleInfo& mi) {
72 _moduleInfo = mi;
73 }
74
75 void setModulePath(const std::string& name) {
76 _moduleInfo.path = name;
77 }
78
79 ModuleInfo& moduleInfo() {
80 return _moduleInfo;
81 }
82
83 const std::string& moduleName() const {
84 return _moduleInfo.name;
85 }
86
87 AnyModule module() {
88 if (!_mod)
89 _mod = AnyModule(_moduleInfo, object());
90 return _mod;
91 }
92
93 ModuleInfo _moduleInfo;
94 AnyObject _object;
95 AnyModule _mod;
96 };
97
100 QI_API bool registerCppEmbeddedModule(const std::string& moduleName, boost::function<void (ModuleBuilder*)> fun);
101
102 // ###### MODULE API ######
106 QI_API std::vector<ModuleInfo> listModules();
107
108
113 QI_API AnyModule import(const std::string& name);
114 QI_API AnyModule import(const ModuleInfo& name);
115
116 }
117
118 QI_TYPE_STRUCT(qi::ModuleInfo, name, type, path);
119
122 #define QI_REGISTER_MODULE(modname, fun) \
123 extern "C" QI_EXPORT_API void qi_module_init(::qi::ModuleBuilder *mb) { \
124 if (modname != mb->moduleName()) { \
125 qiLogCategory("qi.module"); \
126 qiLogError() << "module name do not match: '" \
127 << modname << "' vs '" << mb->moduleName() << "'"; \
128 return; \
129 } \
130 (*fun)(mb); \
131 }
132
135 #define QI_REGISTER_MODULE_EMBEDDED(name, fun) \
136 static bool BOOST_PP_CAT(_register_module, __COUNTER__) QI_ATTR_UNUSED \
137 = ::qi::registerCppEmbeddedModule(name, fun);
138
139
140 //####################### MODULE LANGUAGE FACTORY #########################
141
147 namespace qi {
148
149 using ModuleFactoryFunctor = boost::function<AnyModule(const qi::ModuleInfo&)>;
152 QI_API bool registerModuleFactory(const std::string& name, ModuleFactoryFunctor fun);
153 }
154
159 #define QI_REGISTER_MODULE_FACTORY(factoryType, fun) \
160 static bool BOOST_PP_CAT(_register_module_factory, __COUNTER__) QI_ATTR_UNUSED \
161 = ::qi::registerModuleFactory(factoryType, fun)
162
165 #define QI_REGISTER_MODULE_FACTORY_PLUGIN(factoryType, fun) \
166 extern "C" QI_EXPORT_API void module_factory_plugin() { \
167 ::qi::registerModuleFactory(factoryType, fun); \
168 }
169
170
171
172
173 #endif
qi::AnyModule::moduleInfo
const ModuleInfo & moduleInfo() const
Definition: anymodule.hpp:53
QI_TYPE_STRUCT
QI_TYPE_STRUCT(qi::ModuleInfo, name, type, path)
QI_API
#define QI_API
Definition: api.hpp:33
objecttypebuilder.hpp
qi::ModuleBuilder::moduleName
const std::string & moduleName() const
Definition: anymodule.hpp:83
qi::listModules
std::vector< ModuleInfo > listModules()
dynamicobjectbuilder.hpp
qi::ModuleBuilder::setModuleInfo
void setModuleInfo(const ModuleInfo &mi)
Definition: anymodule.hpp:71
qi::ModuleBuilder::setModulePath
void setModulePath(const std::string &name)
Definition: anymodule.hpp:75
qi::ModuleInfo::name
std::string name
Definition: anymodule.hpp:29
qi::ObjectThreadingModel_MultiThread
Object is thread safe, multiple calls can occur in different threads in parallel. ...
Definition: manageable.hpp:38
qi::AnyModule::moduleName
const std::string & moduleName() const
Definition: anymodule.hpp:49
qi::ModuleBuilder::_mod
AnyModule _mod
Definition: anymodule.hpp:95
qi::DynamicObjectBuilder
Definition: dynamicobjectbuilder.hpp:18
qi::AnyModule::AnyModule
AnyModule()
Definition: anymodule.hpp:41
qi::ModuleBuilder::module
AnyModule module()
Definition: anymodule.hpp:87
qi::AnyModule::AnyModule
AnyModule(const ModuleInfo &moduleInfo, const qi::AnyObject &object)
Definition: anymodule.hpp:44
qi::ModuleBuilder::_object
AnyObject _object
Definition: anymodule.hpp:94
anyvalue.hpp
qi::ModuleInfo::type
std::string type
Definition: anymodule.hpp:30
qi::AnyModule
Definition: anymodule.hpp:38
qi::ModuleFactoryFunctor
boost::function< AnyModule(const qi::ModuleInfo &)> ModuleFactoryFunctor
Definition: anymodule.hpp:149
qi::Object< Empty >
qi::log::env::QI_DEFAULT_LOGHANDLER::name
char const *const name
qi::registerCppEmbeddedModule
bool registerCppEmbeddedModule(const std::string &moduleName, boost::function< void(ModuleBuilder *)> fun)
log.hpp
Convenient log macro.
qi::ModuleBuilder
Definition: anymodule.hpp:63
qi::ModuleInfo::path
std::string path
Definition: anymodule.hpp:31
qi::ModuleBuilder::_moduleInfo
ModuleInfo _moduleInfo
Definition: anymodule.hpp:93
anyobject.hpp
qi::ModuleInfo
Definition: anymodule.hpp:28
qi::registerModuleFactory
bool registerModuleFactory(const std::string &name, ModuleFactoryFunctor fun)
qi::ModuleBuilder::ModuleBuilder
ModuleBuilder(const ModuleInfo &mi)
Definition: anymodule.hpp:65
qi::ModuleBuilder::moduleInfo
ModuleInfo & moduleInfo()
Definition: anymodule.hpp:79
qi::AnyModule::_moduleInfo
ModuleInfo _moduleInfo
Definition: anymodule.hpp:57