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

Last change on this file since 71 was 71, checked in by Marek Kurdej, 12 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
RevLine 
[62]1// This file is part of the PACPUS framework distributed under the
2// CECILL-C License, Version 1.0.
3//
[66]4/// @file
[62]5/// @author Gerald Dherbomez <firstname.surname@utc.fr>
[63]6/// @date January, 2006
[62]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///
[63]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.
[3]15
[31]16#ifndef DEF_PACPUS_COMPONENTMANAGER_H
17#define DEF_PACPUS_COMPONENTMANAGER_H
[3]18
[31]19#include <Pacpus/kernel/pacpus.h>
20#include <Pacpus/kernel/ComponentFactoryBase.h>
21#include <Pacpus/kernel/PacpusPluginInterface.h>
22#include <Pacpus/kernel/XmlConfigFile.h>
[3]23
[67]24#include <cstddef>
25#include <QList>
26#include <QMap>
27#include <QPluginLoader>
28
[3]29namespace pacpus {
30
31class ComponentBase;
32
[71]33/// @todo Documentation
[3]34typedef QMap<QString, ComponentBase *> ComponentMap;
[71]35/// @todo Documentation
[3]36typedef QMap<QString, ComponentFactoryBase *> FactoryMap;
37
[71]38/// Singleton recording the components and managing them.
[3]39class ComponentManager
40{
41 friend class ComponentBase;
42
43public:
44 /// @returns a pointer to the ComponentManager object
[71]45 /// @deprecated Use getInstance()
[3]46 PACPUS_DEPRECATED_MSG( static PACPUSLIB_API ComponentManager * create(), "use 'getInstance()'" );
47
[71]48 /// Returns an instance of the singleton ComponentManager class.
49 /// @returns Pointer to the ComponentManager singleton.
[13]50 static PACPUSLIB_API ComponentManager* getInstance();
[3]51
[71]52 /// Destroys the ComponentManager singleton.
53 ///
54 /// After this call, every pointer to the ComponentManager becomes invalid.
[3]55 static PACPUSLIB_API void destroy();
56
[67]57 /// Automatic deleter class.
[3]58 struct destroyer {
[67]59 /// Invokes ComponentManager::destroy() method if @b mgr pointer is not null.
[3]60 void operator()(ComponentManager * mgr) const
61 {
62 if (!mgr) {
63 return;
64 }
65 mgr->destroy();
66 }
67 };
68
[13]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 */
[16]73 PACPUSLIB_API std::size_t loadComponents(const QString& file);
[3]74
[13]75 /** Start all the components
76 * @return True if all the component has been started, otherwise false.
77 */
[48]78 PACPUSLIB_API bool start();
[3]79
[13]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 */
[48]84 PACPUSLIB_API bool start(const QString& component);
[3]85
[13]86 /** Stop all the components
87 * @return True if all the component has been stopped, otherwise false.
88 */
[48]89 PACPUSLIB_API bool stop();
[3]90
[13]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 */
[48]95 PACPUSLIB_API bool stop(const QString& component);
[3]96
[13]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 */
[16]101 PACPUSLIB_API ComponentBase* getComponent(const QString& name);
[3]102
[13]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 */
[48]106 PACPUSLIB_API QStringList getAllComponentsName() const;
[3]107
[13]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 */
[16]112 PACPUSLIB_API bool loadPlugin(const QString& filename);
[3]113
114private:
115 /// Create a new component of type 'type' and with the name 'name'
[16]116 bool createComponent(const QString& type, const QString& name);
[3]117
[16]118 bool registerComponent(ComponentBase* addr, const QString& name);
119 bool registerComponentFactory(ComponentFactoryBase* addr, const QString& type);
[3]120
[16]121 bool unRegisterComponent(const QString& name);
122 bool unRegisterComponentFactory(const QString& type);
[3]123
124 // Allow 2 functions to access to private members of ComponentManager
[16]125 friend void ComponentFactoryBase::addFactory(ComponentFactoryBase* addr, const QString & type);
[3]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
[31]156#endif
Note: See TracBrowser for help on using the repository browser.