ComponentManager.h
1 
27 #ifndef COSMO_COMPONENT_MANAGER_H
28 #define COSMO_COMPONENT_MANAGER_H
29 
30 #include <Pt/Cosmo/Component.h>
31 #include <Pt/Cosmo/ComponentPlugin.h>
32 #include <Pt/Cosmo/IComponentManager.h>
33 #include <Pt/Cosmo/Enumerable.h>
34 
35 #include <string>
36 
37 namespace Pt {
38 
39 namespace Cosmo {
40 
41 class ComponentInfo;
42 class IComponentInfo;
43 
52 class PT_COSMO_API ComponentManager : public Component
53 {
54  public:
55  template <typename I>
56  I* getInterface();
57 
58  public:
62 
66 
69  void setModulesDir(const std::string& dir);
70 
73  void importComponents(const std::string& manifest);
74 
78  const std::string& require,
79  const std::string& instanceId);
80 
83  void load();
84 
87  void load(const std::string& instanceId);
88 
91  void unload(IComponentPlugin& plugin);
92 
95  void unload(const std::string& instanceId);
96 
100 
101  private:
102  class ComponentManagerPlugin* _plugin;
103  class ComponentManagerImpl* _impl;
104 };
105 
108 class ComponentManagerFactory
109 {
110  public:
113  explicit ComponentManagerFactory(ComponentManager& cm)
114  : _cm(&cm)
115  {}
116 
117  Component* create()
118  { return _cm; }
119 
120  void destroy(Component* instance)
121  { }
122 
123  private:
124  ComponentManager* _cm;
125 };
126 
129 class ComponentManagerPlugin : public ComponentPlugin<ComponentManager,
130  ComponentManagerFactory>
131 {
132  public:
133  static const char* FeatureId()
134  { return "Cosmo.ComponentManager"; }
135 
136  static const char* ClassId()
137  { return "Cosmo.ComponentManager"; }
138 
139  static const char* Info()
140  { return "Cosmo.Default"; }
141 
142  public:
143  ComponentManagerPlugin(ComponentManager& cm);
144 };
145 
146 } // namespace Cosmo
147 
148 } // namespace Pt
149 
150 #endif
Core module.
Definition: Allocator.h:33
Enumerable interface.
Definition: IEnumerable.h:58
Component base class.
Definition: Component.h:52
Component plugin interface.
Definition: IComponentPlugin.h:51
@ Info
Infos and more severe messages.
Definition: LogLevel.h:46
void setModulesDir(const std::string &dir)
Set modules search directory.
Default component manager.
Definition: ComponentManager.h:53
void unload(IComponentPlugin &plugin)
Unloads a component plugin.
ComponentManager()
Constructor.
void unload(const std::string &instanceId)
Unloads a component by instance ID.
~ComponentManager()
Destructor.
void importComponents(const std::string &manifest)
Imports all components from manifest.
void registerComponent(IComponentPlugin &plugin, const std::string &require, const std::string &instanceId)
Registers component.
void load()
Loads all registered components.
void load(const std::string &instanceId)
Loads registered component.
const IEnumerable< ComponentInfo > & components() const
Enumerates all components.