charon-core  0.3.1
AbstractPluginLoader.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  */
29 #ifndef ABSTRACTPLUGINLOADER_H_
30 #define ABSTRACTPLUGINLOADER_H_
31 
32 #include "ParameteredObject.hxx"
33 #include <iostream>
34 #include <stdexcept>
35 
41 protected:
43  std::string pluginName;
44 
46  ParameteredObject* (*create) (
47  const std::string&, ParameteredObject::template_type);
48 
51 
54 
56  std::vector<std::string>& pluginPaths;
57 
59  std::string &libSuffix;
60 
63 
64 public:
66 
67  class charon_plugins_DLL_PUBLIC PluginException: public std::runtime_error {
68  public:
70  enum ErrorCode {
72  FILE_NOT_FOUND = 1,
75  FILE_DAMAGED = 2,
77  INVALID_PLUGIN_FORMAT = 3,
79  ALREADY_LOADED = 4,
82  PLUGIN_NOT_LOADED = 5,
84  NO_SUCH_INSTANCE = 6,
86  DUPLICATE_INSTANCE_NAME = 7,
88  INCOMPATIBLE_BUILD_TYPE = 8,
91  VERSION_INFORMATION_MISSING = 9,
94  VERSION_MISSMATCH = 10,
96  OTHER = 0
97  };
98 
100 
104  PluginException(const std::string & message,
105  const std::string & pluginName = "", ErrorCode err = OTHER);
106 
108 
109  const std::string & getPluginName() const;
110 
112 
113  ErrorCode getErrorCode() const;
114 
116  virtual ~PluginException() throw ();
117 
118  private:
120  std::string _nameOfPlugin;
121 
123  ErrorCode _err;
124  };
125 
127 
136  AbstractPluginLoader(const std::string& name,
137  std::vector<std::string> &plpaths, std::string& lSuffix,
138  PluginManagerInterface::PluginVersionCheckLevel versionCheck =
139  PluginManagerInterface::PluginVersionIgnore);
140 
142 
147  virtual void load() throw (PluginException) = 0;
148 
150 
154  virtual void unload() throw (PluginException) = 0;
155 
157 
158  virtual const std::string& getName() const;
159 
161 
172  virtual ParameteredObject * createInstance(const std::string & name,
174  throw (PluginException);
175 
177 
181  virtual void destroyInstance(ParameteredObject * p)
182  throw (PluginException);
183 
185 
186  virtual ~AbstractPluginLoader();
187 };
188 
189 #endif /* ABSTRACTPLUGINLOADER_H_ */
Interface for a plugin manager.
forstatement_DECLDIR ParameteredObject::build_type getBuildType()
Report build configuration to prevent linking of incompatibel runtime libs.
forstatement_DECLDIR void destroy(ParameteredObject *b)
Deletes an instance of the plugin.
build_type
defined build type
template_type
Integer which represents a template type.
Base class for serializable objects.
Convenience file to iclude all ParameteredObject dependencies and Template functions.
std::vector< std::string > & pluginPaths
Paths where the plugins are stored.
std::string pluginName
The name of the Plugin (without prefix "lib" and without extension)
charon_DEPRECATED typedef ParameteredObject::template_type template_type
for transition to ParameteredObject::template_type
std::string & libSuffix
Lib suffix e.g. _d for debug builds.
PluginVersionCheckLevel
info how to handle version information
PluginManagerInterface::PluginVersionCheckLevel _versionCheck
should the Loader ignore embedded charon-core version strings?
#define charon_plugins_DLL_PUBLIC
Preprocessor macro to define this class/function as public visible, i.e.
Definition: DllEx.h:83
Abstract base class for a plugin loader.