Orocos Real-Time Toolkit  2.8.3
Classes | Namespaces | Macros | Typedefs
Component.hpp File Reference

This file contains the macros and definitions to create dynamically loadable components. More...

#include <string>
#include <map>
#include <vector>
#include "rtt-fwd.hpp"
#include "rtt-config.h"

Go to the source code of this file.

Classes

class  RTT::ComponentFactories
 A global variable storing all component factories added with ORO_LIST_COMPONENT_TYPE. More...
 
class  RTT::ComponentFactoryLoader< C >
 A helper class storing a single component factory in case of static library deployments. More...
 

Namespaces

 RTT
 Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
 

Macros

#define ORO_CONCAT_LINE2(x, y)   x##y
 
#define ORO_CONCAT_LINE1(x, y)   ORO_CONCAT_LINE2(x,y)
 
#define ORO_CONCAT_LINE(x)   ORO_CONCAT_LINE1(x,__LINE__)
 
#define ORO_LIST_COMPONENT_TYPE_str(s)   ORO_LIST_COMPONENT_TYPE__str(s)
 
#define ORO_LIST_COMPONENT_TYPE__str(s)   #s
 
#define ORO_CREATE_COMPONENT(CNAME)
 Use this macro to register a single component in a shared library (plug-in). More...
 
#define ORO_CREATE_COMPONENT_LIBRARY()
 Use this macro to create a component library which contains all components listed with ORO_LIST_COMPONENT_TYPE. More...
 
#define ORO_LIST_COMPONENT_TYPE(CLASS_NAME)   namespace { namespace ORO_CONCAT_LINE(LOADER_) { RTT::ComponentFactoryLoader<CLASS_NAME> m_cloader(ORO_LIST_COMPONENT_TYPE_str(CLASS_NAME)); } }
 Use this macro to register multiple components in a shared library (plug-in). More...
 
#define ORO_CREATE_COMPONENT_TYPE()   ORO_CREATE_COMPONENT_LIBRARY( )
 Backwards compatibility macro which is now replaced by ORO_CREATE_COMPONENT_LIBRARY( ) More...
 

Typedefs

typedef TaskContext *(* RTT::ComponentLoaderSignature) (std::string instance_name)
 This signature defines how a component can be instantiated. More...
 
typedef std::map< std::string, ComponentLoaderSignature > RTT::FactoryMap
 

Detailed Description

This file contains the macros and definitions to create dynamically loadable components.

You need to include this header and use one of the macros if you wish to make a run-time loadable component.

Definition in file Component.hpp.

Macro Definition Documentation

#define ORO_CONCAT_LINE (   x)    ORO_CONCAT_LINE1(x,__LINE__)

Definition at line 97 of file Component.hpp.

#define ORO_CONCAT_LINE1 (   x,
 
)    ORO_CONCAT_LINE2(x,y)

Definition at line 96 of file Component.hpp.

#define ORO_CONCAT_LINE2 (   x,
 
)    x##y

Definition at line 95 of file Component.hpp.

#define ORO_CREATE_COMPONENT (   CNAME)
Value:
extern "C" { \
RTT_EXPORT RTT::TaskContext* createComponent(std::string instance_name); \
RTT::TaskContext* createComponent(std::string instance_name) \
{ \
return new CNAME(instance_name); \
} \
RTT_EXPORT std::string getComponentType(); \
std::string getComponentType() \
{ \
return ORO_LIST_COMPONENT_TYPE_str(CNAME); \
} \
} /* extern "C" */
#define RTT_EXPORT
Definition: rtt-config.h:98
#define ORO_LIST_COMPONENT_TYPE_str(s)
Definition: Component.hpp:99
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93

Use this macro to register a single component in a shared library (plug-in).

You can only use this macro once in a .cpp file for the whole shared library and you may not link with another component library when using this macro. Use ORO_CREATE_COMPONENT_LIBRARY if you are in that situation.

It adds a function 'createComponent', which will return a new instance of the library's component type and a function 'getComponentType', which returns the type (namespace::class) name of the component.

The advantage of this approach is that the user does not need to know the class name of the component, he just needs to locate the shared library itself. The disadvantage is that only one component type per shared library can be created.

Parameters
CNAMEthe class name of the component you are adding to the library.

Definition at line 125 of file Component.hpp.

#define ORO_CREATE_COMPONENT_LIBRARY ( )
Value:
RTT::FactoryMap* RTT::ComponentFactories::Factories = 0; \
extern "C" { \
RTT_EXPORT RTT::TaskContext* createComponentType(std::string instance_name, std::string type_name) \
{ \
if( RTT::ComponentFactories::Instance().count(type_name) ) \
return RTT::ComponentFactories::Instance()[type_name](instance_name); \
return 0; \
} \
RTT_EXPORT std::vector<std::string> getComponentTypeNames() \
{ \
std::vector<std::string> ret; \
RTT::FactoryMap::iterator it; \
for(it = RTT::ComponentFactories::Instance().begin(); it != RTT::ComponentFactories::Instance().end(); ++it) { \
ret.push_back(it->first); \
} \
return ret; \
} \
RTT_EXPORT RTT::FactoryMap* getComponentFactoryMap() { return &RTT::ComponentFactories::Instance(); } \
} /* extern "C" */
#define RTT_EXPORT
Definition: rtt-config.h:98
static RTT_HIDE FactoryMap & Instance()
Definition: Component.hpp:67
std::map< std::string, ComponentLoaderSignature > FactoryMap
Definition: Component.hpp:51
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93

Use this macro to create a component library which contains all components listed with ORO_LIST_COMPONENT_TYPE.

It will add to your library an extern "C" function 'createComponentType' which can create a component of each class added with ORO_LIST_COMPONENT_TYPE.

Definition at line 146 of file Component.hpp.

#define ORO_CREATE_COMPONENT_TYPE ( )    ORO_CREATE_COMPONENT_LIBRARY( )

Backwards compatibility macro which is now replaced by ORO_CREATE_COMPONENT_LIBRARY( )

Definition at line 205 of file Component.hpp.

#define ORO_LIST_COMPONENT_TYPE (   CLASS_NAME)    namespace { namespace ORO_CONCAT_LINE(LOADER_) { RTT::ComponentFactoryLoader<CLASS_NAME> m_cloader(ORO_LIST_COMPONENT_TYPE_str(CLASS_NAME)); } }

Use this macro to register multiple components in a shared library (plug-in).

For each component, add this line in the .cpp file. Use this macro in combination with ORO_CREATE_COMPONENT_LIBRARY.

The advantage of this approach is that one library can create different component types and that you may link multiple component libraries with each other.

This macro can be used for both shared and static libraries. In case of a shared library, the component factory will be registered to the shared library's local FactoryMap. In case of a static library, the component factory will be registered in the static library's global FactoryMap. In both cases, the DeploymentComponent can access these factories and create the registered component types.

Parameters
CLASS_NAMEthe class name of the component you are adding to the library.

Definition at line 200 of file Component.hpp.

#define ORO_LIST_COMPONENT_TYPE__str (   s)    #s

Definition at line 100 of file Component.hpp.

#define ORO_LIST_COMPONENT_TYPE_str (   s)    ORO_LIST_COMPONENT_TYPE__str(s)

Definition at line 99 of file Component.hpp.