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

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

Added: PacpusException - base class for all exceptions. DbiteExceptions inherits from it.
Added: PacpusLibConfig.h - dllimport/dllexport clauses separated from pacpus.h.
Update: comments.

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