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

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

Added: more documentation.
doc/doxyfile.in: turned on BUILTIN_STL_SUPPORT in Doxygen.
Added: LICENSE-header.txt to be included in all source files.

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