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