Code_TYMPAN  4.4.0
Industrial site acoustic simulation
TYPluginManager.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) <2012> <EDF-R&D> <FRANCE>
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  * You should have received a copy of the GNU General Public License along
12  * with this program; if not, write to the Free Software Foundation, Inc.,
13  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
14  */
15 
16 #ifndef __TY_PLUGINMANAGER__
17 #define __TY_PLUGINMANAGER__
18 
19 #include <list>
20 #include <string>
21 
22 #include <qdir.h>
23 #include <qstringlist.h>
24 
25 #include "Tympan/core/defines.h"
26 #include "Tympan/core/interfaces.h"
27 #include "Tympan/core/smartptr.h"
28 #include "Tympan/core/plugin.h"
29 
30 #if TY_COMPILER == TY_COMPILER_MSVC
31  #define LIB_HANDLE hInstance
32  #define LIB_LOAD(a) LoadLibraryA(a)
33  #define LIB_GETSYM(a, b) GetProcAddress(a, b)
34  #define LIB_UNLOAD(a) FreeLibrary(a)
35 
36 struct HINSTANCE__;
37 typedef struct HINSTANCE__* hInstance;
38 
39 #else
40  #define LIB_HANDLE void*
41  #define LIB_LOAD(a) dlopen(a, RTLD_LAZY | RTLD_LOCAL)
42  #define LIB_GETSYM(a, b) dlsym(a, b)
43  #define LIB_UNLOAD(a) dlclose(a)
44 #endif
45 
46 typedef void (*TYPGStartPlugin)();
47 typedef Plugin* (*TYPGGetPlugin)();
48 typedef void (*TYPGStopPlugin)();
49 
51 {
53 
57 
58  QString filename;
59 };
60 
61 class TYPluginManager;
62 
63 // Smart pointer sur TYPluginManager.
65 
70 // UUID of the Default Solver
71 #define DEFAULT_SOLVER_UUID "{A98B320C-44C4-47a9-B689-1DD352DAA8B2}"
72 
73 class TYPluginManager : public IRefCount
74 {
75 public:
76  // Liste des plug-ins
77  typedef std::list<TYPluginData*> TYPluginList;
78 
79 public:
84 
89 
97  bool setAsSingleton();
98 
102  static LPTYPluginManager get();
103 
105 
109  QFileInfoList getPluginFileList(const QDir& directory) const;
110 
112 
116  void createPlugins(const QFileInfoList& file_list);
117 
119 
123  bool startPlugin(TYPluginData* plugin_data);
124 
126 
129  bool loadPlugins(const QString& directory);
130 
131  // Decharge les plugins charges de la memoire
132  void unloadPlugins();
133 
134  Plugin* getPlugin(const OGenID& uuid) const;
135 
136  // Retourne un SolverInterface
137  SolverInterface* getSolver(const OGenID& uuid) const;
138 
139  // Retourne les infos du solveur
140  void getInfos(pluginInfos* pInfos, const OGenID& uuid) const;
141 
143  QString getInfo(const QString& info, const OGenID& uuid) const;
144 
145  // Get plug-ins list
147 
148  // Verifie si le plugin uuid existe
149  bool exist(const OGenID& uuid);
150 
151  // Verifie si le plugin existe
152  bool exist(const QString& solverName);
153 
154  // Retourne l'identifiant de solver correspondant au nom `solverName`
155  OGenID solverID(const QString& solverName);
156 
157 private:
159 
160  // Instance unique
162 };
163 
164 class TYCalcul;
165 
166 namespace tympan
167 {
169 
173 void load_solvers(const char* path);
174 
176 // needed)
181 
183 // needed)
184 OGenID solver_id(std::string name);
185 
186 } /* namespace tympan */
187 
188 #endif // __TY_PLUGINMANAGER__
void(* TYPGStopPlugin)()
struct HINSTANCE__ * hInstance
void(* TYPGStartPlugin)()
SmartPtr< TYPluginManager > LPTYPluginManager
#define LIB_HANDLE
Plugin *(* TYPGGetPlugin)()
const char * name
Definition: idgen.h:28
Definition: plugin.h:48
Interface class for solvers.
Definition: interfaces.h:33
Calculation program.
Definition: TYCalcul.h:50
bool exist(const OGenID &uuid)
OGenID solverID(const QString &solverName)
bool loadPlugins(const QString &directory)
Load, check, create and start plugins.
static LPTYPluginManager _pInstance
QString getInfo(const QString &info, const OGenID &uuid) const
Retourne une info spécifique du solveur.
TYPluginList & getPluginList()
void createPlugins(const QFileInfoList &file_list)
Create TYPluginData related to library files to load.
std::list< TYPluginData * > TYPluginList
bool startPlugin(TYPluginData *plugin_data)
Check the loaded plugin.
Plugin * getPlugin(const OGenID &uuid) const
SolverInterface * getSolver(const OGenID &uuid) const
QFileInfoList getPluginFileList(const QDir &directory) const
Get the list of dynamic library files to load.
void getInfos(pluginInfos *pInfos, const OGenID &uuid) const
TYPluginList _plugins
static LPTYPluginManager get()
OGenID solver_id(std::string name)
Return the id of the solver named name (a previous call to tympan::load_solvers() is.
SolverInterface * select_solver(OGenID uuid)
Select a solver amongst the loaded solvers (a previous call to tympan::load_solvers() is.
void load_solvers(const char *path)
Load the solver plugins found in path
TYPGStopPlugin stopPlugin
QString filename
TYPGGetPlugin getPlugin
TYPGStartPlugin startPlugin
LIB_HANDLE pluginDllInstance