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

Last change on this file since 64 was 64, checked in by Marek Kurdej, 11 years ago

Modified property: added svn:keywords=Id.

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