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
29namespace fawkes {
30
31class Configuration;
32
33class Plugin
34{
35public:
37 virtual ~Plugin();
38
39 void set_name(const char *name);
40 const char *name() const;
42
43 virtual bool persistent();
44
45protected:
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
60private:
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 */
69typedef 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 */
76typedef void (*PluginDestroyFunc)(Plugin *plugin);
77
78/** Plugin description function for the shared library.
79 * @return short string describing the plugin.
80 */
81typedef 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 */
87typedef 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
Interface for configuration handling.
Definition: config.h:68
Plugin interface class.
Definition: plugin.h:34
virtual bool persistent()
Determines if the plugin can be unloaded.
Definition: plugin.cpp:97
void set_name(const char *name)
Set plugin name.
Definition: plugin.cpp:122
Plugin(Configuration *config)
Constructor.
Definition: plugin.cpp:72
ThreadList thread_list
Thread list member.
Definition: plugin.h:53
ThreadList & threads()
Get a list of threads.
Definition: plugin.cpp:111
virtual ~Plugin()
Virtual destructor.
Definition: plugin.cpp:80
Configuration * config
Fawkes configuration.
Definition: plugin.h:58
const char * name() const
Get the name of the plugin.
Definition: plugin.cpp:142
List of threads.
Definition: thread_list.h:56
Fawkes library namespace.