2e6be6615d5d6a06714dbfa9de8e0bec2a666834
[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 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14 */
15
16 /**
17  * @author Christian Grothoff
18  *
19  * @file
20  * Plugin loading and unloading
21  *
22  * @defgroup plugin  Plugin library
23  * Plugin loading and unloading
24  * @{
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 *
51 (*GNUNET_PLUGIN_Callback) (void *arg);
52
53
54 /**
55  * Test if a plugin exists.
56  *
57  * Note that the library must export a symbol called
58  * "library_name_init" for the test to succeed.
59  *
60  * @param library_name name of the plugin to test if it is installed
61  * @return #GNUNET_YES if the plugin exists, #GNUNET_NO if not
62  */
63 int
64 GNUNET_PLUGIN_test (const char *library_name);
65
66
67 /**
68  * Setup plugin (runs the "init" callback and returns whatever "init"
69  * returned).  If "init" returns NULL, the plugin is unloaded.
70  *
71  * Note that the library must export symbols called
72  * "library_name_init" and "library_name_done".  These will be called
73  * when the library is loaded and unloaded respectively.
74  *
75  * @param library_name name of the plugin to load
76  * @param arg argument to the plugin initialization function
77  * @return whatever the initialization function returned, NULL on error
78  */
79 void *
80 GNUNET_PLUGIN_load (const char *library_name,
81                     void *arg);
82
83
84 /**
85  * Signature of a function called by #GNUNET_PLUGIN_load_all().
86  *
87  * @param cls closure
88  * @param library_name full name of the library (to be used with
89  *        #GNUNET_PLUGIN_unload)
90  * @param lib_ret return value from the initialization function
91  *        of the library (same as what #GNUNET_PLUGIN_load would
92  *        have returned for the given library name)
93  */
94 typedef void
95 (*GNUNET_PLUGIN_LoaderCallback) (void *cls,
96                                  const char *library_name,
97                                  void *lib_ret);
98
99
100 /**
101  * Load all compatible plugins with the given base name.
102  *
103  * Note that the library must export symbols called
104  * "basename_ANYTHING_init" and "basename_ANYTHING__done".  These will
105  * be called when the library is loaded and unloaded respectively.
106  *
107  * @param basename basename of the plugins to load
108  * @param arg argument to the plugin initialization function
109  * @param cb function to call for each plugin found
110  * @param cb_cls closure for @a cb
111  */
112 void
113 GNUNET_PLUGIN_load_all (const char *basename,
114                         void *arg,
115                         GNUNET_PLUGIN_LoaderCallback cb,
116                         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,
130                       void *arg);
131
132
133 #if 0                           /* keep Emacsens' auto-indent happy */
134 {
135 #endif
136 #ifdef __cplusplus
137 }
138 #endif
139
140 /* ifndef GNUNET_PLUGIN_LIB_H */
141 #endif
142
143 /** @} */  /* end of group */
144
145 /* end of gnunet_plugin_lib.h */