Mercurial > pidgin
annotate src/plugin.h @ 6429:bda4b264806a
[gaim-migrate @ 6937]
Etan Reisner noticed this the other day, but noone was around to commit it.
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Mon, 11 Aug 2003 19:52:47 +0000 |
parents | 90d0849abd3c |
children | 70d5122bc3ff |
rev | line source |
---|---|
5205 | 1 /** |
2 * @file plugin.h Plugin API | |
3 * @ingroup core | |
4 * | |
5 * gaim | |
6 * | |
7 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
8 * | |
9 * This program is free software; you can redistribute it and/or modify | |
10 * it under the terms of the GNU General Public License as published by | |
11 * the Free Software Foundation; either version 2 of the License, or | |
12 * (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
22 */ | |
23 #ifndef _GAIM_PLUGIN_H_ | |
24 #define _GAIM_PLUGIN_H_ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
25 |
5224
5160333a80df
[gaim-migrate @ 5594]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5205
diff
changeset
|
26 #include <gmodule.h> |
5205 | 27 |
28 typedef struct _GaimPlugin GaimPlugin; /**< GaimPlugin */ | |
29 typedef struct _GaimPluginInfo GaimPluginInfo; /**< GaimPluginInfo */ | |
30 typedef struct _GaimPluginLoaderInfo GaimPluginLoaderInfo; | |
31 | |
32 typedef int GaimPluginPriority; /**< Plugin priority. */ | |
33 | |
34 #include "event.h" | |
35 | |
36 /** | |
37 * Plugin types. | |
38 */ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
39 typedef enum |
5205 | 40 { |
41 GAIM_PLUGIN_UNKNOWN = -1, /**< Unknown type. */ | |
42 GAIM_PLUGIN_STANDARD = 0, /**< Standard plugin. */ | |
43 GAIM_PLUGIN_LOADER, /**< Loader plugin. */ | |
44 GAIM_PLUGIN_PROTOCOL /**< Protocol plugin. */ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
45 |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
46 } GaimPluginType; |
5205 | 47 |
48 #define GAIM_PRIORITY_DEFAULT 0 | |
49 #define GAIM_PRIORITY_HIGHEST 9999 | |
50 #define GAIM_PRIORITY_LOWEST -9999 | |
51 | |
52 #define GAIM_PLUGIN_ID_UNSET { 0, 0, 0, 0 } | |
53 | |
54 /** | |
55 * Detailed information about a plugin. | |
56 * | |
57 * This is used in the version 2.0 API and up. | |
58 */ | |
59 struct _GaimPluginInfo | |
60 { | |
61 unsigned int api_version; | |
62 GaimPluginType type; | |
63 char *ui_requirement; | |
64 unsigned long flags; | |
65 GList *dependencies; | |
66 GaimPluginPriority priority; | |
67 | |
68 char *id; | |
69 char *name; | |
70 char *version; | |
71 char *summary; | |
72 char *description; | |
73 char *author; | |
74 char *homepage; | |
75 | |
76 gboolean (*load)(GaimPlugin *plugin); | |
77 gboolean (*unload)(GaimPlugin *plugin); | |
78 void (*destroy)(GaimPlugin *plugin); | |
79 | |
80 void *ui_info; | |
81 void *extra_info; | |
82 }; | |
83 | |
84 /** | |
85 * Extra information for loader plugins. | |
86 */ | |
87 struct _GaimPluginLoaderInfo | |
88 { | |
89 GList *exts; | |
90 | |
91 gboolean (*probe)(GaimPlugin *plugin); | |
92 gboolean (*load)(GaimPlugin *plugin); | |
93 gboolean (*unload)(GaimPlugin *plugin); | |
94 void (*destroy)(GaimPlugin *plugin); | |
95 | |
96 GaimSignalBroadcastFunc broadcast; | |
97 }; | |
98 | |
99 /** | |
100 * A plugin handle. | |
101 */ | |
102 struct _GaimPlugin | |
103 { | |
104 gboolean native_plugin; /**< Native C plugin. */ | |
105 gboolean loaded; /**< The loaded state. */ | |
106 void *handle; /**< The module handle. */ | |
107 char *path; /**< The path to the plugin. */ | |
108 GaimPluginInfo *info; /**< The plugin information. */ | |
109 char *error; | |
110 void *extra; /**< Plugin-specific data. */ | |
111 }; | |
112 | |
113 #define GAIM_PLUGIN_LOADER_INFO(plugin) \ | |
114 ((GaimPluginLoaderInfo *)(plugin)->info->extra_info) | |
115 | |
116 /** | |
117 * Handles the initialization of modules. | |
118 */ | |
5449 | 119 #ifndef GAIM_PLUGINS |
5205 | 120 # define GAIM_INIT_PLUGIN(pluginname, initfunc, plugininfo) \ |
121 gboolean gaim_init_##pluginname##_plugin(void) { \ | |
122 GaimPlugin *plugin = gaim_plugin_new(TRUE, NULL); \ | |
123 plugin->info = &(plugininfo); \ | |
124 initfunc((plugin)); \ | |
125 return gaim_plugin_register(plugin); \ | |
126 } | |
5449 | 127 #else /* GAIM_PLUGINS */ |
5205 | 128 # define GAIM_INIT_PLUGIN(pluginname, initfunc, plugininfo) \ |
5224
5160333a80df
[gaim-migrate @ 5594]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5205
diff
changeset
|
129 G_MODULE_EXPORT gboolean gaim_init_plugin(GaimPlugin *plugin) { \ |
5205 | 130 plugin->info = &(plugininfo); \ |
131 initfunc((plugin)); \ | |
132 return gaim_plugin_register(plugin); \ | |
133 } | |
134 #endif | |
135 | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
136 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
137 extern "C" { |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
138 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
139 |
5205 | 140 /**************************************************************************/ |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
141 /** @name Plugin API */ |
5205 | 142 /**************************************************************************/ |
143 /*@{*/ | |
144 | |
145 /** | |
146 * Creates a new plugin structure. | |
147 * | |
148 * @param native Whether or not the plugin is native. | |
149 * @param path The path to the plugin, or @c NULL if statically compiled. | |
150 * | |
151 * @return A new GaimPlugin structure. | |
152 */ | |
153 GaimPlugin *gaim_plugin_new(gboolean native, const char *path); | |
154 | |
155 /** | |
156 * Probes a plugin, retrieving the information on it and adding it to the | |
157 * list of available plugins. | |
158 * | |
159 * @param filename The plugin's filename. | |
160 * | |
161 * @return The plugin handle. | |
162 * | |
163 * @see gaim_plugin_load() | |
164 * @see gaim_plugin_destroy() | |
165 */ | |
166 GaimPlugin *gaim_plugin_probe(const char *filename); | |
167 | |
168 /** | |
169 * Registers a plugin and prepares it for loading. | |
170 * | |
171 * This shouldn't be called by anything but the internal module code. | |
172 * | |
173 * @param plugin The plugin to register. | |
174 */ | |
175 gboolean gaim_plugin_register(GaimPlugin *plugin); | |
176 | |
177 /** | |
178 * Attempts to load a previously probed plugin. | |
179 * | |
180 * @param filename The plugin's filename. | |
181 * | |
182 * @return @c TRUE if successful, or @c FALSE otherwise. | |
183 * | |
184 * @see gaim_plugin_reload() | |
185 * @see gaim_plugin_unload() | |
186 */ | |
187 gboolean gaim_plugin_load(GaimPlugin *plugin); | |
188 | |
189 /** | |
190 * Unloads the specified plugin. | |
191 * | |
192 * @param plugin The plugin handle. | |
193 * | |
194 * @return @c TRUE if successful, or @c FALSE otherwise. | |
195 * | |
196 * @see gaim_plugin_load() | |
197 * @see gaim_plugin_reload() | |
198 */ | |
199 gboolean gaim_plugin_unload(GaimPlugin *plugin); | |
200 | |
201 /** | |
202 * Reloads a plugin. | |
203 * | |
204 * @param plugin The old plugin handle. | |
205 * | |
206 * @return @c TRUE if successful, or @c FALSE otherwise. | |
207 * | |
208 * @see gaim_plugin_load() | |
209 * @see gaim_plugin_unload() | |
210 */ | |
211 gboolean gaim_plugin_reload(GaimPlugin *plugin); | |
212 | |
213 /** | |
214 * Unloads a plugin and destroys the structure from memory. | |
215 * | |
216 * @param plugin The plugin handle. | |
217 */ | |
218 void gaim_plugin_destroy(GaimPlugin *plugin); | |
219 | |
220 /** | |
221 * Returns whether or not a plugin is currently loaded. | |
222 * | |
223 * @param plugin The plugin. | |
224 * | |
225 * @return TRUE if loaded, or FALSE otherwise. | |
226 */ | |
227 gboolean gaim_plugin_is_loaded(const GaimPlugin *plugin); | |
228 | |
229 /*@}*/ | |
230 | |
231 /**************************************************************************/ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
232 /** @name Plugins API */ |
5205 | 233 /**************************************************************************/ |
234 /*@{*/ | |
235 | |
236 /** | |
237 * Sets the search paths for plugins. | |
238 * | |
239 * @param count The number of search paths. | |
240 * @param paths The search paths. | |
241 */ | |
242 void gaim_plugins_set_search_paths(size_t count, char **paths); | |
243 | |
244 /** | |
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
245 * Unloads all loaded plugins. |
5205 | 246 */ |
247 void gaim_plugins_unload_all(void); | |
248 | |
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
249 |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
250 /** |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
251 * Destroys all registered plugins. |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
252 */ |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
253 void gaim_plugins_destroy_all(void); |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
254 |
5205 | 255 /** |
5949
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
256 * Attempts to load all the plugins in the specified preference key |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
257 * that were loaded when gaim last quit. |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
258 * |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
259 * @param key The preference key containing the list of plugins. |
5838 | 260 */ |
5949
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
261 void gaim_plugins_load_saved(const char *key); |
5838 | 262 |
263 /** | |
5205 | 264 * Probes for plugins in the registered module paths. |
265 * | |
266 * @param ext The extension type to probe for, or @c NULL for all. | |
267 * | |
268 * @see gaim_plugin_set_probe_path() | |
269 */ | |
270 void gaim_plugins_probe(const char *ext); | |
271 | |
272 /** | |
273 * Returns whether or not plugin support is enabled. | |
274 * | |
275 * @return TRUE if plugin support is enabled, or FALSE otherwise. | |
276 */ | |
277 gboolean gaim_plugins_enabled(void); | |
278 | |
279 /** | |
280 * Registers a function that will be called when probing is finished. | |
281 * | |
282 * @param func The callback function. | |
283 * @param data Data to pass to the callback. | |
284 */ | |
285 void gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data); | |
286 | |
287 /** | |
288 * Unregisters a function that would be called when probing is finished. | |
289 * | |
290 * @param func The callback function. | |
291 */ | |
292 void gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)); | |
293 | |
294 /** | |
295 * Registers a function that will be called when a plugin is loaded. | |
296 * | |
297 * @param func The callback functino. | |
298 * @param data Data to pass to the callback. | |
299 */ | |
300 void gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
301 void *data); | |
302 | |
303 /** | |
304 * Unregisters a function that would be called when a plugin is loaded. | |
305 * | |
306 * @param func The callback functino. | |
307 */ | |
308 void gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)); | |
309 | |
310 /** | |
311 * Registers a function that will be called when a plugin is unloaded. | |
312 * | |
313 * @param func The callback functino. | |
314 * @param data Data to pass to the callback. | |
315 */ | |
316 void gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
317 void *data); | |
318 | |
319 /** | |
320 * Unregisters a function that would be called when a plugin is unloaded. | |
321 * | |
322 * @param func The callback functino. | |
323 */ | |
324 void gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, | |
325 void *)); | |
326 | |
327 /** | |
328 * Finds a plugin with the specified name. | |
329 * | |
330 * @param name The plugin name. | |
331 * | |
332 * @return The plugin if found, or @c NULL if not found. | |
333 */ | |
334 GaimPlugin *gaim_plugins_find_with_name(const char *name); | |
335 | |
336 /** | |
337 * Finds a plugin with the specified filename. | |
338 * | |
339 * @param filename The plugin filename. | |
340 * | |
341 * @return The plugin if found, or @c NULL if not found. | |
342 */ | |
343 GaimPlugin *gaim_plugins_find_with_filename(const char *filename); | |
344 | |
345 /** | |
346 * Finds a plugin with the specified plugin ID. | |
347 * | |
348 * @param id The plugin ID. | |
349 * | |
350 * @return The plugin if found, or @c NULL if not found. | |
351 */ | |
352 GaimPlugin *gaim_plugins_find_with_id(const char *id); | |
353 | |
354 /** | |
355 * Returns a list of all loaded plugins. | |
356 * | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
357 * @return A list of all loaded plugins. |
5205 | 358 */ |
359 GList *gaim_plugins_get_loaded(void); | |
360 | |
361 /** | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
362 * Returns a list of all protocol plugins. |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
363 * |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
364 * @return A list of all protocol plugins. |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
365 */ |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
366 GList *gaim_plugins_get_protocols(void); |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
367 |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
368 /** |
5205 | 369 * Returns a list of all plugins, whether loaded or not. |
370 * | |
371 * @return A list of all plugins. | |
372 */ | |
373 GList *gaim_plugins_get_all(void); | |
374 | |
375 /*@}*/ | |
376 | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
377 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
378 } |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
379 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
380 |
5205 | 381 #endif /* _GAIM_PLUGIN_H_ */ |