doxygen: group/module definitions (part 2)
[oweals/gnunet.git] / src / include / gnunet_plugin_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18      Boston, MA 02110-1301, USA.
19 */
20
21 /**
22  * @author Christian Grothoff
23  *
24  * @file
25  * Plugin loading and unloading
26  *
27  * @defgroup plugin  Plugin library
28  * Plugin loading and unloading
29  * @{
30  */
31
32 #ifndef GNUNET_PLUGIN_LIB_H
33 #define GNUNET_PLUGIN_LIB_H
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #if 0                           /* keep Emacsens' auto-indent happy */
39 }
40 #endif
41 #endif
42
43 #include "gnunet_common.h"
44 #include "gnunet_configuration_lib.h"
45
46
47 /**
48  * Signature of any function exported by a plugin.
49  *
50  * @param arg argument to the function (context)
51  * @return some pointer, NULL if the plugin was
52  *         shutdown or if there was an error, otherwise
53  *         the plugin's API on success
54  */
55 typedef void *(*GNUNET_PLUGIN_Callback) (void *arg);
56
57
58 /**
59  * Test if a plugin exists.
60  *
61  * Note that the library must export a symbol called
62  * "library_name_init" for the test to succeed.
63  *
64  * @param library_name name of the plugin to test if it is installed
65  * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
66  */
67 int
68 GNUNET_PLUGIN_test (const char *library_name);
69
70
71 /**
72  * Setup plugin (runs the "init" callback and returns whatever "init"
73  * returned).  If "init" returns NULL, the plugin is unloaded.
74  *
75  * Note that the library must export symbols called
76  * "library_name_init" and "library_name_done".  These will be called
77  * when the library is loaded and unloaded respectively.
78  *
79  * @param library_name name of the plugin to load
80  * @param arg argument to the plugin initialization function
81  * @return whatever the initialization function returned, NULL on error
82  */
83 void *
84 GNUNET_PLUGIN_load (const char *library_name, void *arg);
85
86
87 /**
88  * Signature of a function called by 'GNUNET_PLUGIN_load_all'.
89  *
90  * @param cls closure
91  * @param library_name full name of the library (to be used with
92  *        #GNUNET_PLUGIN_unload)
93  * @param lib_ret return value from the initialization function
94  *        of the library (same as what #GNUNET_PLUGIN_load would
95  *        have returned for the given library name)
96  */
97 typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
98                                               const char *library_name,
99                                               void *lib_ret);
100
101
102 /**
103  * Load all compatible plugins with the given base name.
104  *
105  * Note that the library must export symbols called
106  * "basename_ANYTHING_init" and "basename_ANYTHING__done".  These will
107  * be called when the library is loaded and unloaded respectively.
108  *
109  * @param basename basename of the plugins to load
110  * @param arg argument to the plugin initialization function
111  * @param cb function to call for each plugin found
112  * @param cb_cls closure for @a cb
113  */
114 void
115 GNUNET_PLUGIN_load_all (const char *basename, void *arg,
116                         GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls);
117
118
119 /**
120  * Unload plugin (runs the "done" callback and returns whatever "done"
121  * returned).  The plugin is then unloaded.
122  *
123  * @param library_name name of the plugin to unload
124  * @param arg argument to the plugin shutdown function
125  * @return whatever the shutdown function returned, typically NULL
126  *         or a "char *" representing the error message
127  */
128 void *
129 GNUNET_PLUGIN_unload (const char *library_name, void *arg);
130
131
132 #if 0                           /* keep Emacsens' auto-indent happy */
133 {
134 #endif
135 #ifdef __cplusplus
136 }
137 #endif
138
139 /* ifndef GNUNET_PLUGIN_LIB_H */
140 #endif
141
142 /** @} */  /* end of group */
143
144 /* end of gnunet_plugin_lib.h */