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/plugin.h>
28 #include <core/exception.h>
29 
30 #include <string>
31 
32 namespace fawkes {
33 #if 0 /* just to make Emacs auto-indent happy */
34 }
35 #endif
36 
37 class Module;
38 class Configuration;
39 class ModuleManager;
40 
42 {
43  public:
44  PluginLoadException(const char *plugin, const char *message);
45  PluginLoadException(const char *plugin, const char *message, Exception &e);
46  ~PluginLoadException() throw();
47 
48  std::string plugin_name() const;
49 
50  private:
51  std::string __plugin_name;
52 };
53 
55 {
56  public:
57  PluginUnloadException(const char *plugin_type, const char *add_msg = NULL);
58 };
59 
60 
61 class PluginLoader {
62  public:
63 
64  PluginLoader(const char *plugin_base_dir, Configuration *config);
65  ~PluginLoader();
66 
67  Plugin * load(const char *plugin_name);
68  void unload(Plugin *plugin);
69 
70  std::string get_description(const char *plugin_name);
71 
72  bool is_loaded(const char *plugin_name);
73 
74  ModuleManager * get_module_manager() const;
75 
76  private:
77  Module * open_module(const char *plugin_name);
78  std::string get_string_symbol(const char *plugin_name, const char *symbol_name,
79  const char *section_name = ".fawkes_plugin");
80  Plugin * create_instance(const char *plugin_name, Module *module);
81 
82  private:
83  class Data;
84 
85  Data *d_;
86  Configuration *config_;
87  std::string plugin_base_dir_;
88 };
89 
90 
91 } // end namespace fawkes
92 
93 #endif
Plugin interface class.
Definition: plugin.h:33
This exception is thrown if the requested plugin could not be unloaded.
Definition: loader.h:54
Fawkes library namespace.
This exception is thrown if the requested plugin could not be loaded.
Definition: loader.h:41
~PluginLoadException()
Destructor.
Definition: loader.cpp:72
PluginLoadException(const char *plugin, const char *message)
Constructor.
Definition: loader.cpp:64
This class manages plugins.
Definition: loader.h:61
Dynamic module loader for Linux, FreeBSD, and MacOS X.
Definition: module.h:40
Base class for exceptions in Fawkes.
Definition: exception.h:36
std::string plugin_name() const
Get name of plugin which failed to load.
Definition: loader.cpp:93
Dynamic module manager.
Interface for configuration handling.
Definition: config.h:67