Fawkes API  Fawkes Development Version
loader.h
1 
2 /***************************************************************************
3  * loader.h - Loads plugins from .so shared objects
4  *
5  * Created: Wed Aug 23 15:18:13 2006
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef _PLUGIN_LOADER_H_
25 #define _PLUGIN_LOADER_H_
26 
27 #include <core/exception.h>
28 #include <core/plugin.h>
29 
30 #include <string>
31 
32 namespace fawkes {
33 
34 class Module;
35 class Configuration;
36 class ModuleManager;
37 
39 {
40 public:
41  PluginLoadException(const char *plugin, const char *message);
42  PluginLoadException(const char *plugin, const char *message, Exception &e);
43  ~PluginLoadException() noexcept;
44 
45  std::string plugin_name() const;
46 
47 private:
48  std::string plugin_name_;
49 };
50 
52 {
53 public:
54  PluginUnloadException(const char *plugin_type, const char *add_msg = NULL);
55 };
56 
58 {
59 public:
60  PluginLoader(const char *plugin_base_dir, Configuration *config);
61  ~PluginLoader();
62 
63  Plugin *load(const char *plugin_name);
64  void unload(Plugin *plugin);
65 
66  std::string get_description(const char *plugin_name);
67 
68  bool is_loaded(const char *plugin_name);
69 
71 
72 private:
73  Module * open_module(const char *plugin_name);
74  std::string get_string_symbol(const char *plugin_name,
75  const char *symbol_name,
76  const char *section_name = ".fawkes_plugin");
77  Plugin * create_instance(const char *plugin_name, Module *module);
78 
79 private:
80  class Data;
81 
82  Data * d_;
83  Configuration *config_;
84  std::string plugin_base_dir_;
85 };
86 
87 } // end namespace fawkes
88 
89 #endif
Interface for configuration handling.
Definition: config.h:68
Base class for exceptions in Fawkes.
Definition: exception.h:36
Dynamic module manager.
Dynamic module loader for Linux, FreeBSD, and MacOS X.
Definition: module.h:41
This exception is thrown if the requested plugin could not be loaded.
Definition: loader.h:39
~PluginLoadException() noexcept
Destructor.
Definition: loader.cpp:67
PluginLoadException(const char *plugin, const char *message)
Constructor.
Definition: loader.cpp:60
std::string plugin_name() const
Get name of plugin which failed to load.
Definition: loader.cpp:87
This class manages plugins.
Definition: loader.h:58
bool is_loaded(const char *plugin_name)
Check if a plugin is loaded.
Definition: loader.cpp:348
ModuleManager * get_module_manager() const
Get module manager.
Definition: loader.cpp:141
std::string get_description(const char *plugin_name)
Get plugin description.
Definition: loader.cpp:323
Plugin * load(const char *plugin_name)
Load a specific plugin The plugin loader is clever and guarantees that every plugin is only loaded on...
Definition: loader.cpp:200
void unload(Plugin *plugin)
Unload the given plugin This will unload the given plugin.
Definition: loader.cpp:365
~PluginLoader()
Destructor.
Definition: loader.cpp:129
PluginLoader(const char *plugin_base_dir, Configuration *config)
Constructor.
Definition: loader.cpp:120
This exception is thrown if the requested plugin could not be unloaded.
Definition: loader.h:52
PluginUnloadException(const char *plugin_type, const char *add_msg=NULL)
Constructor.
Definition: loader.cpp:100
Plugin interface class.
Definition: plugin.h:34
Fawkes library namespace.