charon-core  0.3.1
PluginManager.h
Go to the documentation of this file.
1 /* This file is part of Charon.
2 
3  Charon is free software: you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Charon is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public License
14  along with Charon. If not, see <http://www.gnu.org/licenses/>.
15  */
24 #ifndef PLUGINMANAGER_H_
25 #define PLUGINMANAGER_H_
26 
35 #if defined(_WIN32) || defined(__WIN32__)
36  #include "WindowsPluginLoader.h"
37  #define PLUGIN_LOADER WindowsPluginLoader
38  #define PLUGIN_EXTENSION ".dll"
39 #else // UNIX
40  #include "UnixPluginLoader.h"
41  #include <set>
42  #define PLUGIN_LOADER UnixPluginLoader
43 
44  #ifdef APPLE
45  #define PLUGIN_EXTENSION ".dylib"
46  #else /* APPLE */
47  #define PLUGIN_EXTENSION ".so"
48  #endif /* APPLE */
49 #endif
50 
51 #include <iostream>
52 #include <map>
53 #include <list>
54 #include "PluginManagerInterface.h"
55 #include "ParameteredObject.h"
56 
142 private:
144  std::vector<std::string> pluginPaths;
145 
147  std::string libSuffix;
148 
150  std::map<std::string, PLUGIN_LOADER*> _loadedPlugins;
151 
153 
154  std::map<ParameteredObject*, PLUGIN_LOADER*> _instances;
155 
158 
161 
163 
164  void _destroyAllInstances(PLUGIN_LOADER * p);
165 
167  void _unloadAllPlugins();
168 
170  bool isInternal(ParameteredObject* obj);
171 
173 
175  void _unloadPlugin(PLUGIN_LOADER * p, bool erase = true);
176 
178 
187  bool _generateMetadataForPlugin(
188  const std::string& pluginName,
189  const std::string& filename);
190 
192 
197  std::list<ParameteredObject*> _determineTargetPoints();
198 
200  // @{
201 
205  void _getConnected(std::set<std::string>& visited, const std::set<
206  std::string>& cur) const;
207 
214  void _getConnected(std::set<std::string>& visited, const std::set<
215  std::string>& cur, const ParameterFile& pf) const;
216  // @}
217 
219  std::vector<std::string> _excludeList;
220 
222  std::map<std::string, ParameteredObject *> objects;
223 
224  bool _initializePluginOnLoad;
225 
226 public:
228 #ifdef NDEBUG
229  #define DEFAULT_DEBUG_SUFFIX false
230 #else
231  #define DEFAULT_DEBUG_SUFFIX true
232 #endif
233 
235 
246  const std::vector<std::string>& pluginPaths,
247  bool debugSuffix = DEFAULT_DEBUG_SUFFIX,
248  bool initializeOnLoad=false,
249  PluginVersionCheckLevel versionInfo=PluginVersionIgnore
250  );
251 
253 
266  const std::string& globalPath,
267  const std::string& localPath = "",
268  bool debugSuffix = DEFAULT_DEBUG_SUFFIX,
269  bool initializeOnLoad=false,
270  PluginVersionCheckLevel versionInfo=PluginVersionIgnore
271  );
272 
274 
284  void loadPlugin(std::string name)
286 
288 
298  void unloadPlugin(const std::string & name)
300 
302 
304  bool isLoaded(const std::string & name) const;
305 
307  const std::vector<std::string>& getPluginPaths() const;
308 
310  size_t getLoadedPluginsCount() const;
311 
313  size_t getInstancesCount() const;
314 
316 
318  ParameteredObject* getInstance(const std::string & instanceName) const
320 
322 
323  const std::map<std::string, ParameteredObject *>&
324  getObjectList() const {
325  return objects;
326  }
327 
329 
350  ParameteredObject* createInstance(
351  std::string pluginName,
353  std::string instanceName = "")
354  throw (AbstractPluginLoader::PluginException);
355 
357 
368  ParameteredObject* createInstance(const std::string & pluginName,
369  const std::string & instanceName = "")
370  throw (AbstractPluginLoader::PluginException);
371 
373 
379  void insertInstance(ParameteredObject* instance);
380 
382 
394  void destroyInstance(ParameteredObject * toDestroy)
395  throw (AbstractPluginLoader::PluginException);
396 
398 
409  void loadParameterFile(const ParameterFile& pf);
410 
412 
419  void loadParameterFile(const std::string& path);
420 
422 
429  void saveParameterFile(ParameterFile& paramFile) const;
430 
432 
437  void saveParameterFile(const std::string & path) const;
438 
440 
451  void setDefaultTemplateType(ParameteredObject::template_type t);
452 
454 
464  ParameteredObject::template_type getDefaultTemplateType() const;
465 
467 
470  void runWorkflow();
471 
473  charon_DEPRECATED void executeWorkflow() {
474  runWorkflow();
475  }
476 
478  void setExcludeList(const std::vector<std::string>& list);
479 
481 
482  void resetExecuted();
483 
485 
492  void createMetadata(const std::string & targetPath = "");
493 
495 
510  void createDynamicMetadata(const ParameterFile& paramFile,
511  const std::string& filePrefix);
512 
515 
522  void createDynamicMetadata(const std::string& pluginName,
523  const ParameterFile& paramFile, const std::string& fileName);
524 
526 
531  void reset();
532 
534 
538  virtual ~PluginManager();
539 
541  // \{
542 
544 
547  std::set<std::string> getNeighbours(const std::string& root) const;
548 
550 
554  std::set<std::string> getNeighbours(const std::string& root,
555  const ParameterFile& pf) const;
556 
558 
570  virtual std::set<std::string> getConnected(const std::string& root,
571  const ParameterFile& pf) const;
572 
574 
580  std::set<std::string> getConnected(const std::string& root) const;
581 
583  std::set<std::string> getConnected(ParameterFile & pf,
584  ParameteredObject * obj) const;
585 
587 
592  bool connect(Slot& slot1, Slot& slot2);
593 
595 
599  bool connect(Slot* slot1, Slot* slot2);
600 
602 
610  bool connect(const std::string& slot1, const std::string& slot2);
611 
613 
618  bool disconnect(Slot& slot1, Slot& slot2);
619 
621 
628  bool disconnect(const std::string& slot1, const std::string& slot2);
629  // \}
630 
632 
641  std::list<ParameteredObject*> determineExecutionOrder();
642 
643  virtual bool initializePluginOnLoad() const;
644  virtual void setInitiailizePluginOnLoad (bool initOnLoad);
645  virtual std::string templateTypeToString(
647 };
648 
649 #endif /* PLUGINMANAGER_H_ */
#define charon_DEPRECATED
handle deprecated messages on GCC and MSVC
Definition: DllEx.h:87
std::string libSuffix
Lib suffix e.g. _d for debug builds.
Interface for a plugin manager.
Manages ParameteredObject based plugins and their instances.
Provides an interface for a plugin manager.
This class serves to store parameters used within the Charon Project.
Definition: ParameterFile.h:68
template_type
Integer which represents a template type.
Base class for serializable objects.
virtual ParameteredObject * getInstance(const std::string &instanceName) const =0
Get an existing instance of a loaded plugin.
Implements a plugin Loader for Unix systems.
ParameteredObject::template_type _defaultTemplateType
current default template type.
std::map< std::string, ParameteredObject * > objects
currently existing instances that are handled by this PluginManager
Declaration of the base class ParameteredObject.
std::map< ParameteredObject *, PLUGIN_LOADER * > _instances
Links the instances to their PluginLoader.
std::map< std::string, PLUGIN_LOADER * > _loadedPlugins
Saves the currently loaded plugins.
charon_DEPRECATED typedef ParameteredObject::template_type template_type
for transition to ParameteredObject::template_type
PluginVersionCheckLevel
info how to handle version information
std::vector< std::string > pluginPaths
Paths where the plugins are stored.
Commom properties of slot objects.
Definition: Slots.h:47
std::vector< std::string > _excludeList
exclude list for metadata generation
const std::map< std::string, ParameteredObject * > & getObjectList() const
Get names of existing instances.
PluginVersionCheckLevel _versionInfo
load plugin regardless of version information in the library file
#define charon_plugins_DLL_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:83
virtual std::set< std::string > getConnected(const std::string &root, const ParameterFile &pf) const =0
Recurse into object list and find connected objects.
virtual std::string templateTypeToString(ParameteredObject::template_type t) const =0
Converts template_type to std::string.
Abstract base class for a plugin loader.
#define DEFAULT_DEBUG_SUFFIX
default lib suffix
#define PLUGIN_LOADER
plugin loader classname (unix/win)
Definition: PluginManager.h:42