Fawkes API  Fawkes Development Version
plugin.h
1 
2 /***************************************************************************
3  * plugin.h - Interface for a Fawkes plugin
4  *
5  * Created: Wed Aug 23 15:19:13 2006
6  * Copyright 2006-2007 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 _CORE_PLUGIN_H_
25 #define _CORE_PLUGIN_H_
26 
27 #include <core/threading/thread_list.h>
28 
29 namespace fawkes {
30 
31 class Configuration;
32 
33 class Plugin
34 {
35 public:
36  Plugin(Configuration *config);
37  virtual ~Plugin();
38 
39  void set_name(const char *name);
40  const char *name() const;
42 
43  virtual bool persistent();
44 
45 protected:
46  /** Thread list member. Initialise this list with the threads that this
47  * plugin will use. These threads must exist for the whole life time of
48  * the thread. Use sleeping threads if you need to turn on and off threads
49  * dynamically. You may not add threads later to the list, as the list
50  * is shortly after the constructor sealed.
51  * @see ThreadList
52  */
54 
55  /** Fawkes configuration. You can use the configuration to add certain threads
56  * depending on the requested feature set. Use it only in your constructor.
57  */
59 
60 private:
61  char * _name_alloc;
62  const char *_name;
63 };
64 
65 /** Plugin loader function for the shared library
66  * Do not use directly, rather use the EXPORT_PLUGIN macro.
67  * @relates fawkes::Plugin
68  */
69 typedef Plugin *(*PluginFactoryFunc)(fawkes::Configuration *);
70 
71 /** Plugin destructor function for the shared library.
72  * Do not use directly, rather use the EXPORT_PLUGIN macro.
73  * @param plugin plugin to destroy
74  * @relates fawkes::Plugin
75  */
76 typedef void (*PluginDestroyFunc)(Plugin *plugin);
77 
78 /** Plugin description function for the shared library.
79  * @return short string describing the plugin.
80  */
81 typedef const char *(*PluginDescriptionFunc)();
82 
83 /** Plugin depdendency function for the shared library.
84  * @return short string with a comma separated list of plugins that this
85  * plugin depends on.
86  */
87 typedef const char *(*PluginDependenciesFunc)();
88 
89 /** Plugin factory function for this plugin.
90  * @return an instance of ExamplePlugin
91  */
92 #define PLUGIN_FACTORY(plugin_class) \
93  extern "C" fawkes::Plugin *plugin_factory(fawkes::Configuration *config) \
94  { \
95  return new plugin_class(config); \
96  }
97 
98 /** Plugin destruction function for this plugin.
99  * @param plugin The plugin that is to be destroyed. Do not use this plugin
100  * afterwards
101  */
102 #define PLUGIN_DESTROY(plugin_class) \
103  extern "C" void plugin_destroy(plugin_class *plugin) \
104  { \
105  delete plugin; \
106  }
107 
108 /** Plugin description.
109  * Use this macro to set a short description of the plugi
110  * @param info_string a short string describing the plugin
111  */
112 #define PLUGIN_DESCRIPTION(info_string) \
113  extern "C" const char _plugin_description[] __attribute((__section__(".fawkes_plugin"))) \
114  __attribute((__used__)) = info_string; \
115  \
116  extern "C" const char *plugin_description() \
117  { \
118  return _plugin_description; \
119  }
120 
121 /** Set plugin dependencies.
122  * @param plugin_list a string with a comma-separated list
123  * of plugins that this plugin depends on.
124  */
125 #define PLUGIN_DEPENDS(plugin_list) \
126  extern "C" const char _plugin_dependencies[] __attribute((__section__(".fawkes_plugin"))) \
127  __attribute((__used__)) = info_string; \
128  \
129  extern "C" const char *plugin_depends() \
130  { \
131  return _plugin_dependencies; \
132  }
133 
134 /** Export plugin.
135  * This will create appropriate plugin factory and destroy functions.
136  */
137 #define EXPORT_PLUGIN(plugin_class) \
138  PLUGIN_FACTORY(plugin_class) \
139  \
140  PLUGIN_DESTROY(plugin_class)
141 
142 } // end namespace fawkes
143 
144 #endif
fawkes::Plugin::config
Configuration * config
Fawkes configuration.
Definition: plugin.h:64
fawkes::Plugin::thread_list
ThreadList thread_list
Thread list member.
Definition: plugin.h:59
fawkes::Plugin::Plugin
Plugin(Configuration *config)
Constructor.
Definition: plugin.cpp:79
fawkes::Plugin::~Plugin
virtual ~Plugin()
Virtual destructor.
Definition: plugin.cpp:87
fawkes::Configuration
Definition: config.h:70
fawkes::Plugin::persistent
virtual bool persistent()
Determines if the plugin can be unloaded.
Definition: plugin.cpp:104
fawkes
fawkes::Plugin::threads
ThreadList & threads()
Get a list of threads.
Definition: plugin.cpp:118
Plugin
Plugin representation for JSON transfer.
Definition: Plugin.h:26
fawkes::Plugin::set_name
void set_name(const char *name)
Set plugin name.
Definition: plugin.cpp:129
fawkes::Plugin
Definition: plugin.h:39
fawkes::ThreadList
Definition: thread_list.h:61
fawkes::Plugin::name
const char * name() const
Get the name of the plugin.
Definition: plugin.cpp:149