source: pacpusframework/trunk/include/Pacpus/kernel/ComponentManager.h@ 10

Last change on this file since 10 was 3, checked in by sgosseli, 12 years ago
  • Add the existing Pacpus files from pacpusdev and pacpuscore.
  • Provide a clean build system based on multiple CMake files.
File size: 3.9 KB
RevLine 
[3]1/*********************************************************************
2// created: 2006/02/07 - 11:20
3// filename: componentManager.h
4//
5// author: Gerald Dherbomez
6//
7// purpose: This class records the components and manages them
8// This class is a singleton
9// Use the static ComponentManager::create() function
10// to get a pointer on this object.
11*********************************************************************/
12
13#ifndef COMPONENTMANAGER_H
14#define COMPONENTMANAGER_H
15
16#include <cstddef>
17#include <qmap.h>
18#include <qlist.h>
19#include <qpluginloader.h>
20
21#include "pacpus.h"
22#include "ComponentFactoryBase.h"
23#include "PacpusPluginInterface.h"
24#include "XmlConfigFile.h"
25
26namespace pacpus {
27
28class ComponentBase;
29//class ComponentFactoryBase;
30
31typedef QMap<QString, ComponentBase *> ComponentMap;
32typedef QMap<QString, ComponentFactoryBase *> FactoryMap;
33
34class ComponentManager
35{
36 friend class ComponentBase;
37
38public:
39 /// @returns a pointer to the ComponentManager object
40 /// @deprecated use getInstance()
41 PACPUS_DEPRECATED_MSG( static PACPUSLIB_API ComponentManager * create(), "use 'getInstance()'" );
42
43 /// @returns a pointer to the ComponentManager object
44 static PACPUSLIB_API ComponentManager * getInstance();
45
46 /// Destroys the ComponentManager object
47 static PACPUSLIB_API void destroy();
48
49 struct destroyer {
50 void operator()(ComponentManager * mgr) const
51 {
52 if (!mgr) {
53 return;
54 }
55 mgr->destroy();
56 }
57 };
58
59 /// Call this function to load the components included in the XML config file
60 /// Usually, this is done in the main() !
61 std::size_t PACPUSLIB_API loadComponents(QString file);
62
63 /// Start all the components
64 int PACPUSLIB_API start();
65
66 /// Start only the component passed in parameter
67 int PACPUSLIB_API start(QString component);
68
69 /// Stop all the components
70 int PACPUSLIB_API stop();
71
72 /// Stop only the component passed in parameter
73 int PACPUSLIB_API stop(QString component);
74
75 /// Get a pointer to the component referred by 'name' parameter
76 PACPUSLIB_API ComponentBase* getComponent(QString name);
77
78 /// Get the list of all the names of the component known by the manager
79 PACPUSLIB_API QStringList getAllComponentsName();
80
81 /// Load a new plugin from the file filename (it may be a .so/.dll file)
82 bool PACPUSLIB_API loadPlugin(QString filename);
83
84private:
85 /// Create a new component of type 'type' and with the name 'name'
86 bool createComponent(QString type, QString name);
87
88 bool registerComponent(ComponentBase * addr, QString name);
89 bool registerComponentFactory(ComponentFactoryBase * addr, QString type);
90
91 bool unRegisterComponent(QString name);
92 bool unRegisterComponentFactory(QString type);
93
94 // Allow 2 functions to access to private members of ComponentManager
95 friend void ComponentFactoryBase::addFactory(ComponentFactoryBase * addr, const QString & type);
96 friend void ComponentFactoryBase::addComponent(const QString & name);
97
98 /// private constructor accessible only via static create() function
99 ComponentManager();
100
101 /// private destructor accessible only via static destroy() function
102 ~ComponentManager();
103
104private:
105 /// The static pointer to this object (ComponentManager is a singleton)
106 static ComponentManager * mInstance;
107
108 /// The map of available factories of component
109 FactoryMap factoryMap_;
110
111 /// The map of loaded components
112 ComponentMap componentMap_;
113
114 /// a pointer on the xml interface
115 pacpus::XmlConfigFile * xmlTree_;
116
117 /// a list of QObject in which plugins are embedded
118 QObjectList pluginList_;
119
120 /// The object used to load the plugins
121 QPluginLoader pluginLoader_;
122};
123
124} // namespace pacpus
125
126#endif // COMPONENTMANAGER_H
Note: See TracBrowser for help on using the repository browser.