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

Last change on this file since 62 was 62, checked in by Marek Kurdej, 12 years ago

Update: license info.

File size: 4.9 KB
Line 
1// This file is part of the PACPUS framework distributed under the
2// CECILL-C License, Version 1.0.
3//
4/// @author Gerald Dherbomez <firstname.surname@utc.fr>
5/// @date Month, Year
6/// @version $Id$
7/// @copyright Copyright (c) UTC/CNRS Heudiasyc 2006 - 2013. All rights reserved.
8/// @brief Brief description.
9///
10/// Detailed description.
11
12#ifndef DEF_PACPUS_COMPONENTMANAGER_H
13#define DEF_PACPUS_COMPONENTMANAGER_H
14
15#include <cstddef>
16
17#include <QMap>
18#include <QList>
19#include <QPluginLoader>
20
21#include <Pacpus/kernel/pacpus.h>
22#include <Pacpus/kernel/ComponentFactoryBase.h>
23#include <Pacpus/kernel/PacpusPluginInterface.h>
24#include <Pacpus/kernel/XmlConfigFile.h>
25
26namespace pacpus {
27
28class ComponentBase;
29
30typedef QMap<QString, ComponentBase *> ComponentMap;
31typedef QMap<QString, ComponentFactoryBase *> FactoryMap;
32
33/** ComponentManager
34 * @brief Singleton recording the components and managing them.
35 */
36class ComponentManager
37{
38 friend class ComponentBase;
39
40public:
41 /// @returns a pointer to the ComponentManager object
42 /// @deprecated use getInstance()
43 PACPUS_DEPRECATED_MSG( static PACPUSLIB_API ComponentManager * create(), "use 'getInstance()'" );
44
45 /** Get the singleton of the ComponentManager class.
46 * @return Pointer to the ComponentManager singleton.
47 */
48 static PACPUSLIB_API ComponentManager* getInstance();
49
50 /** Destroy the ComponentManager singleton.
51 * After this call, every pointer to the ComponentManager becomes invalid.
52 */
53 static PACPUSLIB_API void destroy();
54
55 struct destroyer {
56 void operator()(ComponentManager * mgr) const
57 {
58 if (!mgr) {
59 return;
60 }
61 mgr->destroy();
62 }
63 };
64
65 /** Load the components included in the XML config file.
66 * @param file Name of the XML file.
67 * @return Number of components loaded by the manager.
68 */
69 PACPUSLIB_API std::size_t loadComponents(const QString& file);
70
71 /** Start all the components
72 * @return True if all the component has been started, otherwise false.
73 */
74 PACPUSLIB_API bool start();
75
76 /** Start only the component passed in parameter.
77 * @param component Component to start.
78 * @return True if the component exists and has been started, otherwise false.
79 */
80 PACPUSLIB_API bool start(const QString& component);
81
82 /** Stop all the components
83 * @return True if all the component has been stopped, otherwise false.
84 */
85 PACPUSLIB_API bool stop();
86
87 /** Stop only the component passed in parameter.
88 * @param component Component to stop.
89 * @return True if the component has been stopped, otherwise false.
90 */
91 PACPUSLIB_API bool stop(const QString& component);
92
93 /** Get a pointer to the component referred by @em name.
94 * @param name Name of the component.
95 * @return Pointer to the component if it exists, otherwise @em NULL.
96 */
97 PACPUSLIB_API ComponentBase* getComponent(const QString& name);
98
99 /** Get the list of all the names of the component known by the manager.
100 * @return List of all the component's name.
101 */
102 PACPUSLIB_API QStringList getAllComponentsName() const;
103
104 /** Load a new plugin from the file filename (it may be a .so/.dll file)
105 * @param filename Name of the shared object or the dll.
106 * @return True if the plugin has been loaded, otherwise false.
107 */
108 PACPUSLIB_API bool loadPlugin(const QString& filename);
109
110private:
111 /// Create a new component of type 'type' and with the name 'name'
112 bool createComponent(const QString& type, const QString& name);
113
114 bool registerComponent(ComponentBase* addr, const QString& name);
115 bool registerComponentFactory(ComponentFactoryBase* addr, const QString& type);
116
117 bool unRegisterComponent(const QString& name);
118 bool unRegisterComponentFactory(const QString& type);
119
120 // Allow 2 functions to access to private members of ComponentManager
121 friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString & type);
122 friend void ComponentFactoryBase::addComponent(const QString & name);
123
124 /// private constructor accessible only via static create() function
125 ComponentManager();
126
127 /// private destructor accessible only via static destroy() function
128 ~ComponentManager();
129
130private:
131 /// The static pointer to this object (ComponentManager is a singleton)
132 static ComponentManager * mInstance;
133
134 /// The map of available factories of component
135 FactoryMap factoryMap_;
136
137 /// The map of loaded components
138 ComponentMap componentMap_;
139
140 /// a pointer on the xml interface
141 pacpus::XmlConfigFile * xmlTree_;
142
143 /// a list of QObject in which plugins are embedded
144 QObjectList pluginList_;
145
146 /// The object used to load the plugins
147 QPluginLoader pluginLoader_;
148};
149
150} // namespace pacpus
151
152#endif
Note: See TracBrowser for help on using the repository browser.