Mercurial > pidgin
annotate src/plugin.h @ 6485:70d5122bc3ff
[gaim-migrate @ 6999]
Removed the old event system and replaced it with a much better signal
system. There will most likely be some bugs in this, but it seems to be
working for now. Plugins can now generate their own signals, and other
plugins can find those plugins and connect to them. This could give
plugins a form of IPC. It's also useful for other things. It's rather
flexible, except for the damn marshalling, but there's no way around that
that I or the glib people can see.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Mon, 18 Aug 2003 01:03:43 +0000 |
parents | 90d0849abd3c |
children | fab81e4b885c |
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> | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
8 * |
5205 | 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 /** | |
35 * Plugin types. | |
36 */ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
37 typedef enum |
5205 | 38 { |
39 GAIM_PLUGIN_UNKNOWN = -1, /**< Unknown type. */ | |
40 GAIM_PLUGIN_STANDARD = 0, /**< Standard plugin. */ | |
41 GAIM_PLUGIN_LOADER, /**< Loader plugin. */ | |
42 GAIM_PLUGIN_PROTOCOL /**< Protocol plugin. */ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
43 |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
44 } GaimPluginType; |
5205 | 45 |
46 #define GAIM_PRIORITY_DEFAULT 0 | |
47 #define GAIM_PRIORITY_HIGHEST 9999 | |
48 #define GAIM_PRIORITY_LOWEST -9999 | |
49 | |
50 #define GAIM_PLUGIN_ID_UNSET { 0, 0, 0, 0 } | |
51 | |
52 /** | |
53 * Detailed information about a plugin. | |
54 * | |
55 * This is used in the version 2.0 API and up. | |
56 */ | |
57 struct _GaimPluginInfo | |
58 { | |
59 unsigned int api_version; | |
60 GaimPluginType type; | |
61 char *ui_requirement; | |
62 unsigned long flags; | |
63 GList *dependencies; | |
64 GaimPluginPriority priority; | |
65 | |
66 char *id; | |
67 char *name; | |
68 char *version; | |
69 char *summary; | |
70 char *description; | |
71 char *author; | |
72 char *homepage; | |
73 | |
74 gboolean (*load)(GaimPlugin *plugin); | |
75 gboolean (*unload)(GaimPlugin *plugin); | |
76 void (*destroy)(GaimPlugin *plugin); | |
77 | |
78 void *ui_info; | |
79 void *extra_info; | |
80 }; | |
81 | |
82 /** | |
83 * Extra information for loader plugins. | |
84 */ | |
85 struct _GaimPluginLoaderInfo | |
86 { | |
87 GList *exts; | |
88 | |
89 gboolean (*probe)(GaimPlugin *plugin); | |
90 gboolean (*load)(GaimPlugin *plugin); | |
91 gboolean (*unload)(GaimPlugin *plugin); | |
92 void (*destroy)(GaimPlugin *plugin); | |
93 | |
6485
70d5122bc3ff
[gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents:
5949
diff
changeset
|
94 /* XXX GaimSignalBroadcastFunc broadcast; */ |
5205 | 95 }; |
96 | |
97 /** | |
98 * A plugin handle. | |
99 */ | |
100 struct _GaimPlugin | |
101 { | |
102 gboolean native_plugin; /**< Native C plugin. */ | |
103 gboolean loaded; /**< The loaded state. */ | |
104 void *handle; /**< The module handle. */ | |
105 char *path; /**< The path to the plugin. */ | |
106 GaimPluginInfo *info; /**< The plugin information. */ | |
107 char *error; | |
108 void *extra; /**< Plugin-specific data. */ | |
109 }; | |
110 | |
111 #define GAIM_PLUGIN_LOADER_INFO(plugin) \ | |
112 ((GaimPluginLoaderInfo *)(plugin)->info->extra_info) | |
113 | |
114 /** | |
115 * Handles the initialization of modules. | |
116 */ | |
5449 | 117 #ifndef GAIM_PLUGINS |
5205 | 118 # define GAIM_INIT_PLUGIN(pluginname, initfunc, plugininfo) \ |
119 gboolean gaim_init_##pluginname##_plugin(void) { \ | |
120 GaimPlugin *plugin = gaim_plugin_new(TRUE, NULL); \ | |
121 plugin->info = &(plugininfo); \ | |
122 initfunc((plugin)); \ | |
123 return gaim_plugin_register(plugin); \ | |
124 } | |
5449 | 125 #else /* GAIM_PLUGINS */ |
5205 | 126 # define GAIM_INIT_PLUGIN(pluginname, initfunc, plugininfo) \ |
5224
5160333a80df
[gaim-migrate @ 5594]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
5205
diff
changeset
|
127 G_MODULE_EXPORT gboolean gaim_init_plugin(GaimPlugin *plugin) { \ |
5205 | 128 plugin->info = &(plugininfo); \ |
129 initfunc((plugin)); \ | |
130 return gaim_plugin_register(plugin); \ | |
131 } | |
132 #endif | |
133 | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
134 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
135 extern "C" { |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
136 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
137 |
5205 | 138 /**************************************************************************/ |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
139 /** @name Plugin API */ |
5205 | 140 /**************************************************************************/ |
141 /*@{*/ | |
142 | |
143 /** | |
144 * Creates a new plugin structure. | |
145 * | |
146 * @param native Whether or not the plugin is native. | |
147 * @param path The path to the plugin, or @c NULL if statically compiled. | |
148 * | |
149 * @return A new GaimPlugin structure. | |
150 */ | |
151 GaimPlugin *gaim_plugin_new(gboolean native, const char *path); | |
152 | |
153 /** | |
154 * Probes a plugin, retrieving the information on it and adding it to the | |
155 * list of available plugins. | |
156 * | |
157 * @param filename The plugin's filename. | |
158 * | |
159 * @return The plugin handle. | |
160 * | |
161 * @see gaim_plugin_load() | |
162 * @see gaim_plugin_destroy() | |
163 */ | |
164 GaimPlugin *gaim_plugin_probe(const char *filename); | |
165 | |
166 /** | |
167 * Registers a plugin and prepares it for loading. | |
168 * | |
169 * This shouldn't be called by anything but the internal module code. | |
170 * | |
171 * @param plugin The plugin to register. | |
172 */ | |
173 gboolean gaim_plugin_register(GaimPlugin *plugin); | |
174 | |
175 /** | |
176 * Attempts to load a previously probed plugin. | |
177 * | |
178 * @param filename The plugin's filename. | |
179 * | |
180 * @return @c TRUE if successful, or @c FALSE otherwise. | |
181 * | |
182 * @see gaim_plugin_reload() | |
183 * @see gaim_plugin_unload() | |
184 */ | |
185 gboolean gaim_plugin_load(GaimPlugin *plugin); | |
186 | |
187 /** | |
188 * Unloads the specified plugin. | |
189 * | |
190 * @param plugin The plugin handle. | |
191 * | |
192 * @return @c TRUE if successful, or @c FALSE otherwise. | |
193 * | |
194 * @see gaim_plugin_load() | |
195 * @see gaim_plugin_reload() | |
196 */ | |
197 gboolean gaim_plugin_unload(GaimPlugin *plugin); | |
198 | |
199 /** | |
200 * Reloads a plugin. | |
201 * | |
202 * @param plugin The old plugin handle. | |
203 * | |
204 * @return @c TRUE if successful, or @c FALSE otherwise. | |
205 * | |
206 * @see gaim_plugin_load() | |
207 * @see gaim_plugin_unload() | |
208 */ | |
209 gboolean gaim_plugin_reload(GaimPlugin *plugin); | |
210 | |
211 /** | |
212 * Unloads a plugin and destroys the structure from memory. | |
213 * | |
214 * @param plugin The plugin handle. | |
215 */ | |
216 void gaim_plugin_destroy(GaimPlugin *plugin); | |
217 | |
218 /** | |
219 * Returns whether or not a plugin is currently loaded. | |
220 * | |
221 * @param plugin The plugin. | |
222 * | |
223 * @return TRUE if loaded, or FALSE otherwise. | |
224 */ | |
225 gboolean gaim_plugin_is_loaded(const GaimPlugin *plugin); | |
226 | |
227 /*@}*/ | |
228 | |
229 /**************************************************************************/ | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
230 /** @name Plugins API */ |
5205 | 231 /**************************************************************************/ |
232 /*@{*/ | |
233 | |
234 /** | |
235 * Sets the search paths for plugins. | |
236 * | |
237 * @param count The number of search paths. | |
238 * @param paths The search paths. | |
239 */ | |
240 void gaim_plugins_set_search_paths(size_t count, char **paths); | |
241 | |
242 /** | |
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
243 * Unloads all loaded plugins. |
5205 | 244 */ |
245 void gaim_plugins_unload_all(void); | |
246 | |
5242
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
247 |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
248 /** |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
249 * Destroys all registered plugins. |
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 void gaim_plugins_destroy_all(void); |
fd81a00480ac
[gaim-migrate @ 5613]
Christian Hammond <chipx86@chipx86.com>
parents:
5224
diff
changeset
|
252 |
5205 | 253 /** |
5949
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
254 * Attempts to load all the plugins in the specified preference key |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
255 * that were loaded when gaim last quit. |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
256 * |
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
257 * @param key The preference key containing the list of plugins. |
5838 | 258 */ |
5949
90d0849abd3c
[gaim-migrate @ 6393]
Christian Hammond <chipx86@chipx86.com>
parents:
5944
diff
changeset
|
259 void gaim_plugins_load_saved(const char *key); |
5838 | 260 |
261 /** | |
5205 | 262 * Probes for plugins in the registered module paths. |
263 * | |
264 * @param ext The extension type to probe for, or @c NULL for all. | |
265 * | |
266 * @see gaim_plugin_set_probe_path() | |
267 */ | |
268 void gaim_plugins_probe(const char *ext); | |
269 | |
270 /** | |
271 * Returns whether or not plugin support is enabled. | |
272 * | |
273 * @return TRUE if plugin support is enabled, or FALSE otherwise. | |
274 */ | |
275 gboolean gaim_plugins_enabled(void); | |
276 | |
277 /** | |
278 * Registers a function that will be called when probing is finished. | |
279 * | |
280 * @param func The callback function. | |
281 * @param data Data to pass to the callback. | |
282 */ | |
283 void gaim_plugins_register_probe_notify_cb(void (*func)(void *), void *data); | |
284 | |
285 /** | |
286 * Unregisters a function that would be called when probing is finished. | |
287 * | |
288 * @param func The callback function. | |
289 */ | |
290 void gaim_plugins_unregister_probe_notify_cb(void (*func)(void *)); | |
291 | |
292 /** | |
293 * Registers a function that will be called when a plugin is loaded. | |
294 * | |
295 * @param func The callback functino. | |
296 * @param data Data to pass to the callback. | |
297 */ | |
298 void gaim_plugins_register_load_notify_cb(void (*func)(GaimPlugin *, void *), | |
299 void *data); | |
300 | |
301 /** | |
302 * Unregisters a function that would be called when a plugin is loaded. | |
303 * | |
304 * @param func The callback functino. | |
305 */ | |
306 void gaim_plugins_unregister_load_notify_cb(void (*func)(GaimPlugin *, void *)); | |
307 | |
308 /** | |
309 * Registers a function that will be called when a plugin is unloaded. | |
310 * | |
311 * @param func The callback functino. | |
312 * @param data Data to pass to the callback. | |
313 */ | |
314 void gaim_plugins_register_unload_notify_cb(void (*func)(GaimPlugin *, void *), | |
315 void *data); | |
316 | |
317 /** | |
318 * Unregisters a function that would be called when a plugin is unloaded. | |
319 * | |
320 * @param func The callback functino. | |
321 */ | |
322 void gaim_plugins_unregister_unload_notify_cb(void (*func)(GaimPlugin *, | |
323 void *)); | |
324 | |
325 /** | |
326 * Finds a plugin with the specified name. | |
327 * | |
328 * @param name The plugin name. | |
329 * | |
330 * @return The plugin if found, or @c NULL if not found. | |
331 */ | |
332 GaimPlugin *gaim_plugins_find_with_name(const char *name); | |
333 | |
334 /** | |
335 * Finds a plugin with the specified filename. | |
336 * | |
337 * @param filename The plugin filename. | |
338 * | |
339 * @return The plugin if found, or @c NULL if not found. | |
340 */ | |
341 GaimPlugin *gaim_plugins_find_with_filename(const char *filename); | |
342 | |
343 /** | |
344 * Finds a plugin with the specified plugin ID. | |
345 * | |
346 * @param id The plugin ID. | |
347 * | |
348 * @return The plugin if found, or @c NULL if not found. | |
349 */ | |
350 GaimPlugin *gaim_plugins_find_with_id(const char *id); | |
351 | |
352 /** | |
353 * Returns a list of all loaded plugins. | |
354 * | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
355 * @return A list of all loaded plugins. |
5205 | 356 */ |
357 GList *gaim_plugins_get_loaded(void); | |
358 | |
359 /** | |
5573
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
360 * Returns a list of all protocol plugins. |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
361 * |
5e7de337a053
[gaim-migrate @ 5976]
Christian Hammond <chipx86@chipx86.com>
parents:
5449
diff
changeset
|
362 * @return 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 GList *gaim_plugins_get_protocols(void); |
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 /** |
5205 | 367 * Returns a list of all plugins, whether loaded or not. |
368 * | |
369 * @return A list of all plugins. | |
370 */ | |
371 GList *gaim_plugins_get_all(void); | |
372 | |
373 /*@}*/ | |
374 | |
5944
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
375 #ifdef __cplusplus |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
376 } |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
377 #endif |
158196b2db19
[gaim-migrate @ 6385]
Christian Hammond <chipx86@chipx86.com>
parents:
5840
diff
changeset
|
378 |
5205 | 379 #endif /* _GAIM_PLUGIN_H_ */ |