-doxygen
[oweals/gnunet.git] / src / include / gnunet_plugin_lib.h
1 /*
2      This file is part of GNUnet.
3      (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., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file include/gnunet_plugin_lib.h
23  * @brief plugin loading and unloading
24  * @author Christian Grothoff
25  */
26
27 #ifndef GNUNET_PLUGIN_LIB_H
28 #define GNUNET_PLUGIN_LIB_H
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 #include "gnunet_common.h"
39 #include "gnunet_configuration_lib.h"
40
41
42 /**
43  * Signature of any function exported by a plugin.
44  *
45  * @param arg argument to the function (context)
46  * @return some pointer, NULL if the plugin was
47  *         shutdown or if there was an error, otherwise
48  *         the plugin's API on success
49  */
50 typedef void *(*GNUNET_PLUGIN_Callback) (void *arg);
51
52
53 /**
54  * Test if a plugin exists.
55  *
56  * Note that the library must export a symbol called
57  * "library_name_init" for the test to succeed.
58  *
59  * @param library_name name of the plugin to test if it is installed
60  * @return GNUNET_YES if the plugin exists, GNUNET_NO if not
61  */
62 int
63 GNUNET_PLUGIN_test (const char *library_name);
64
65
66 /**
67  * Setup plugin (runs the "init" callback and returns whatever "init"
68  * returned).  If "init" returns NULL, the plugin is unloaded.
69  *
70  * Note that the library must export symbols called
71  * "library_name_init" and "library_name_done".  These will be called
72  * when the library is loaded and unloaded respectively.
73  *
74  * @param library_name name of the plugin to load
75  * @param arg argument to the plugin initialization function
76  * @return whatever the initialization function returned, NULL on error
77  */
78 void *
79 GNUNET_PLUGIN_load (const char *library_name, void *arg);
80
81
82 /**
83  * Signature of a function called by 'GNUNET_PLUGIN_load_all'.
84  *
85  * @param cls closure
86  * @param library_name full name of the library (to be used with
87  *        #GNUNET_PLUGIN_unload)
88  * @param lib_ret return value from the initialization function
89  *        of the library (same as what #GNUNET_PLUGIN_load would
90  *        have returned for the given library name)
91  */
92 typedef void (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
93                                               const char *library_name,
94                                               void *lib_ret);
95
96
97 /**
98  * Load all compatible plugins with the given base name.
99  *
100  * Note that the library must export symbols called
101  * "basename_ANYTHING_init" and "basename_ANYTHING__done".  These will
102  * be called when the library is loaded and unloaded respectively.
103  *
104  * @param basename basename of the plugins to load
105  * @param arg argument to the plugin initialization function
106  * @param cb function to call for each plugin found
107  * @param cb_cls closure for @a cb
108  */
109 void
110 GNUNET_PLUGIN_load_all (const char *basename, void *arg,
111                         GNUNET_PLUGIN_LoaderCallback cb, void *cb_cls);
112
113
114 /**
115  * Unload plugin (runs the "done" callback and returns whatever "done"
116  * returned).  The plugin is then unloaded.
117  *
118  * @param library_name name of the plugin to unload
119  * @param arg argument to the plugin shutdown function
120  * @return whatever the shutdown function returned, typically NULL
121  *         or a "char *" representing the error message
122  */
123 void *
124 GNUNET_PLUGIN_unload (const char *library_name, void *arg);
125
126
127 #if 0                           /* keep Emacsens' auto-indent happy */
128 {
129 #endif
130 #ifdef __cplusplus
131 }
132 #endif
133
134
135 /* ifndef GNUNET_PLUGIN_LIB_H */
136 #endif
137 /* end of gnunet_plugin_lib.h */