| 237 /** |
237 /** |
| 238 * PURPLE_PLUGIN_INIT: |
238 * PURPLE_PLUGIN_INIT: |
| 239 * |
239 * |
| 240 * Defines the plugin's entry points. |
240 * Defines the plugin's entry points. |
| 241 */ |
241 */ |
| 242 #if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL) |
242 #ifdef PURPLE_PLUGINS |
| 243 #define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \ |
|
| 244 PurplePluginInfo * pluginname##_plugin_query(void); \ |
|
| 245 PurplePluginInfo * pluginname##_plugin_query(void) { \ |
|
| 246 return pluginquery(NULL); \ |
|
| 247 } \ |
|
| 248 gboolean pluginname##_plugin_load(void); \ |
|
| 249 gboolean pluginname##_plugin_load(void) { \ |
|
| 250 GError *e = NULL; \ |
|
| 251 gboolean loaded = pluginload(NULL, &e); \ |
|
| 252 if (e) g_error_free(e); \ |
|
| 253 return loaded; \ |
|
| 254 } \ |
|
| 255 gboolean pluginname##_plugin_unload(void); \ |
|
| 256 gboolean pluginname##_plugin_unload(void) { \ |
|
| 257 GError *e = NULL; \ |
|
| 258 gboolean unloaded = pluginunload(NULL, &e); \ |
|
| 259 if (e) g_error_free(e); \ |
|
| 260 return unloaded; \ |
|
| 261 } |
|
| 262 #else /* PURPLE_PLUGINS && !PURPLE_STATIC_PRPL */ |
|
| 263 #define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \ |
243 #define PURPLE_PLUGIN_INIT(pluginname,pluginquery,pluginload,pluginunload) \ |
| 264 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e); \ |
244 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e); \ |
| 265 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e) { \ |
245 G_MODULE_EXPORT GPluginPluginInfo *gplugin_query(GError **e) { \ |
| 266 return GPLUGIN_PLUGIN_INFO(pluginquery(e)); \ |
246 return GPLUGIN_PLUGIN_INFO(pluginquery(e)); \ |
| 267 } \ |
247 } \ |
| 283 * |
263 * |
| 284 * A convenience macro for type implementations, which defines a *_get_type() |
264 * A convenience macro for type implementations, which defines a *_get_type() |
| 285 * function; and a *_register_type() function for use in your plugin's load |
265 * function; and a *_register_type() function for use in your plugin's load |
| 286 * function. You must define an instance initialization function *_init() |
266 * function. You must define an instance initialization function *_init() |
| 287 * and a class initialization function *_class_init() for the type. |
267 * and a class initialization function *_class_init() for the type. |
| 288 * |
268 */ |
| 289 * The type will be registered statically if used in a static protocol or if |
269 #ifdef PURPLE_PLUGINS |
| 290 * plugins support is disabled. |
|
| 291 */ |
|
| 292 #if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL) |
|
| 293 #define PURPLE_DEFINE_TYPE(TN, t_n, T_P) \ |
|
| 294 PURPLE_DEFINE_STATIC_TYPE(TN, t_n, T_P) |
|
| 295 #else |
|
| 296 #define PURPLE_DEFINE_TYPE(TN, t_n, T_P) \ |
270 #define PURPLE_DEFINE_TYPE(TN, t_n, T_P) \ |
| 297 PURPLE_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) |
271 PURPLE_DEFINE_DYNAMIC_TYPE(TN, t_n, T_P) |
| 298 #endif |
272 #endif |
| 299 |
273 |
| 300 /** |
274 /** |
| 306 * @CODE: Custom code that gets inserted in *_get_type(). |
280 * @CODE: Custom code that gets inserted in *_get_type(). |
| 307 * |
281 * |
| 308 * A more general version of PURPLE_DEFINE_TYPE() which allows you to |
282 * A more general version of PURPLE_DEFINE_TYPE() which allows you to |
| 309 * specify #GTypeFlags and custom code. |
283 * specify #GTypeFlags and custom code. |
| 310 */ |
284 */ |
| 311 #if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL) |
285 #ifdef PURPLE_PLUGINS |
| 312 #define PURPLE_DEFINE_TYPE_EXTENDED \ |
|
| 313 PURPLE_DEFINE_STATIC_TYPE_EXTENDED |
|
| 314 #else |
|
| 315 #define PURPLE_DEFINE_TYPE_EXTENDED \ |
286 #define PURPLE_DEFINE_TYPE_EXTENDED \ |
| 316 PURPLE_DEFINE_DYNAMIC_TYPE_EXTENDED |
287 PURPLE_DEFINE_DYNAMIC_TYPE_EXTENDED |
| 317 #endif |
288 #endif |
| 318 |
289 |
| 319 /** |
290 /** |
| 339 * |
310 * |
| 340 * A convenience macro to ease interface addition in the CODE section |
311 * A convenience macro to ease interface addition in the CODE section |
| 341 * of PURPLE_DEFINE_TYPE_EXTENDED(). You should use this macro if the |
312 * of PURPLE_DEFINE_TYPE_EXTENDED(). You should use this macro if the |
| 342 * interface lives in the plugin. |
313 * interface lives in the plugin. |
| 343 */ |
314 */ |
| 344 #if !defined(PURPLE_PLUGINS) || defined(PURPLE_STATIC_PRPL) |
315 #ifdef PURPLE_PLUGINS |
| 345 #define PURPLE_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) \ |
|
| 346 PURPLE_IMPLEMENT_INTERFACE_STATIC(TYPE_IFACE, iface_init) |
|
| 347 #else |
|
| 348 #define PURPLE_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) \ |
316 #define PURPLE_IMPLEMENT_INTERFACE(TYPE_IFACE, iface_init) \ |
| 349 PURPLE_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) |
317 PURPLE_IMPLEMENT_INTERFACE_DYNAMIC(TYPE_IFACE, iface_init) |
| 350 #endif |
318 #endif |
| 351 |
319 |
| 352 /** |
320 /** |
| 398 (GInterfaceInitFunc) iface_init, NULL, NULL \ |
366 (GInterfaceInitFunc) iface_init, NULL, NULL \ |
| 399 }; \ |
367 }; \ |
| 400 purple_plugin_add_interface(plugin, type_id, TYPE_IFACE, &interface_info); \ |
368 purple_plugin_add_interface(plugin, type_id, TYPE_IFACE, &interface_info); \ |
| 401 } |
369 } |
| 402 |
370 |
| 403 /** |
|
| 404 * PURPLE_DEFINE_STATIC_TYPE: |
|
| 405 * |
|
| 406 * A convenience macro for static type implementations. |
|
| 407 */ |
|
| 408 #define PURPLE_DEFINE_STATIC_TYPE(TN, t_n, T_P) \ |
|
| 409 PURPLE_DEFINE_STATIC_TYPE_EXTENDED (TN, t_n, T_P, 0, {}) |
|
| 410 |
|
| 411 /** |
|
| 412 * PURPLE_DEFINE_STATIC_TYPE_EXTENDED: |
|
| 413 * |
|
| 414 * A more general version of PURPLE_DEFINE_STATIC_TYPE(). |
|
| 415 */ |
|
| 416 #define PURPLE_DEFINE_STATIC_TYPE_EXTENDED(TypeName, type_name, TYPE_PARENT, flags, CODE) \ |
|
| 417 static GType type_name##_type_id = 0; \ |
|
| 418 GType type_name##_get_type(void) { \ |
|
| 419 if (G_UNLIKELY(type_name##_type_id == 0)) { \ |
|
| 420 GType type_id; \ |
|
| 421 const GTypeInfo type_info = { \ |
|
| 422 sizeof (TypeName##Class), \ |
|
| 423 (GBaseInitFunc) NULL, \ |
|
| 424 (GBaseFinalizeFunc) NULL, \ |
|
| 425 (GClassInitFunc) type_name##_class_init, \ |
|
| 426 (GClassFinalizeFunc) NULL, \ |
|
| 427 NULL, \ |
|
| 428 sizeof (TypeName), \ |
|
| 429 0, \ |
|
| 430 (GInstanceInitFunc) type_name##_init, \ |
|
| 431 NULL \ |
|
| 432 }; \ |
|
| 433 type_id = g_type_register_static(TYPE_PARENT, #TypeName, &type_info, \ |
|
| 434 (GTypeFlags) flags); \ |
|
| 435 type_name##_type_id = type_id; \ |
|
| 436 { CODE ; } \ |
|
| 437 } \ |
|
| 438 return type_name##_type_id; \ |
|
| 439 } \ |
|
| 440 void type_name##_register_type(PurplePlugin *); \ |
|
| 441 void type_name##_register_type(PurplePlugin *plugin) { } |
|
| 442 |
|
| 443 G_BEGIN_DECLS |
371 G_BEGIN_DECLS |
| 444 |
372 |
| 445 /**************************************************************************/ |
373 /**************************************************************************/ |
| 446 /* Plugin API */ |
374 /* Plugin API */ |
| 447 /**************************************************************************/ |
375 /**************************************************************************/ |