Orocos Real-Time Toolkit  2.8.3
ComponentLoader.hpp
Go to the documentation of this file.
1 #ifndef ORO_COMPONENTLOADER_HPP_
2 #define ORO_COMPONENTLOADER_HPP_
3 
4 #include <string>
5 #include <vector>
6 #include <boost/shared_ptr.hpp>
7 #include <rtt/Component.hpp>
8 
9 namespace RTT {
23  {
28  class LoadedLib{
29  public:
30  LoadedLib(std::string n, std::string short_name, void* h)
31  : filename(n), shortname(short_name), handle(h)
32  {
33  }
37  std::string filename;
41  std::string shortname;
42 
46  void* handle;
47 
48  std::vector<std::string> components_type;
49  };
50 
51  struct ComponentData {
52  ComponentData()
53  : instance(0), type("")
54  {}
58  RTT::TaskContext* instance;
59  std::string type;
60  };
61 
65  typedef std::map<std::string, ComponentData> CompList;
66 
67  CompList comps;
68 
69 
70  std::vector< LoadedLib > loadedLibs;
71 
72  std::vector< std::string > loadedPackages;
73 
77  std::string component_path;
78 
87  bool loadInProcess(std::string filename, std::string shortname, bool log_error );
88 
95  bool reloadInProcess(std::string filename, std::string shortname);
96 
104  bool isCompatibleComponent(std::string const& filepath);
105 
109  bool importInstalledPackage(std::string const& package, std::string const& path_list);
110  public:
111  typedef boost::shared_ptr<ComponentLoader> shared_ptr;
117  static boost::shared_ptr<ComponentLoader> Instance();
118 
123  static void Release();
124 
132  bool import(std::string const& path_list);
133 
143  bool isImported(std::string type_name);
144 
152  bool import(std::string const& name, std::string const& path_list);
153 
159  bool loadLibrary(std::string const& path);
160 
165  bool reloadLibrary(std::string const& filepath);
166 
173  RTT::TaskContext* loadComponent(std::string const& name, std::string const& type);
174 
181  bool unloadComponent( RTT::TaskContext* tc );
182 
187  std::vector<std::string> listComponents() const;
188 
193  std::vector<std::string> listComponentTypes() const;
194 
201  std::string getComponentPath() const;
202 
209  void setComponentPath( std::string const& newpath );
210 
215  const FactoryMap& getFactories() const;
216 
220  void addFactory( std::string const& name, ComponentLoaderSignature factory );
221  };
222 }
223 
224 
225 #endif /* ORO_COMPONENTLOADER_HPP_ */
TaskContext *(* ComponentLoaderSignature)(std::string instance_name)
This signature defines how a component can be instantiated.
Definition: Component.hpp:50
boost::shared_ptr< ComponentLoader > shared_ptr
bool isImported(std::string type_name)
Checks if a given Component type, filename or package name has been imported.
RTT::TaskContext * loadComponent(std::string const &name, std::string const &type)
Creates a new component an earlier discovered component type.
void addFactory(std::string const &name, ComponentLoaderSignature factory)
Adds a factory to the component factory map.
static boost::shared_ptr< ComponentLoader > Instance()
Create the instance of the ComponentLoader.
std::map< std::string, ComponentLoaderSignature > FactoryMap
Definition: Component.hpp:51
This file contains the macros and definitions to create dynamically loadable components.
std::vector< std::string > listComponents() const
Lists all Component created by loadComponent().
std::string getComponentPath() const
Returns the current Component path list.
bool loadLibrary(std::string const &path)
Loads a library as component library.
std::vector< std::string > listComponentTypes() const
Lists all Component types discovered by the ComponentLoader.
bool reloadLibrary(std::string const &filepath)
Reloads a component library.
void setComponentPath(std::string const &newpath)
Sets the Component path list.
bool unloadComponent(RTT::TaskContext *tc)
Destroys an earlier created component.
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:51
static void Release()
Release the ComponentLoader, erasing all knowledge of loaded libraries.
const FactoryMap & getFactories() const
Returns the factory singleton which creates all types of components for the ComponentLoader.