| 1 /* |
|
| 2 This is an example of a gaim dbus plugin. After enabling this |
|
| 3 plugin, the following commands should work from the command line: |
|
| 4 |
|
| 5 prompt$ gaim-send DbusExampleGetHelloObject |
|
| 6 |
|
| 7 returns, say: int32 74 |
|
| 8 |
|
| 9 prompt$ gaim-send DbusExampleGetText int32:74 |
|
| 10 |
|
| 11 returns: string "Hello." |
|
| 12 |
|
| 13 prompt$ gaim-send DbusExampleSetText int32:74 string:Bye! |
|
| 14 |
|
| 15 prompt$ gaim-send DbusExampleGetText int32:74 |
|
| 16 |
|
| 17 returns: string "Bye!" |
|
| 18 |
|
| 19 */ |
|
| 20 |
|
| 21 #include "internal.h" |
|
| 22 |
|
| 23 #include "plugin.h" |
|
| 24 #include "blist.h" |
|
| 25 #include "version.h" |
|
| 26 |
|
| 27 #include <stdio.h> |
|
| 28 #include <stdlib.h> |
|
| 29 #include <string.h> |
|
| 30 |
|
| 31 #define DBUS_API_SUBJECT_TO_CHANGE |
|
| 32 #include "dbus-maybe.h" |
|
| 33 #include "dbus-bindings.h" |
|
| 34 |
|
| 35 typedef struct { |
|
| 36 char *text; |
|
| 37 } GaimText; |
|
| 38 |
|
| 39 /* This makes the structure GaimText visible to the gaim-dbus type |
|
| 40 system. It defines GaimText as a type with no parent. From now |
|
| 41 on, we will be able to register pointers to structures of this |
|
| 42 type. You to dbus-define types you want to be directly accessible |
|
| 43 by external applications. */ |
|
| 44 GAIM_DBUS_DEFINE_TYPE(GaimText) |
|
| 45 |
|
| 46 /* Here we make four functions accessible to other applications by |
|
| 47 DBus. These functions can access types defined in gaim proper |
|
| 48 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ |
|
| 49 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); |
|
| 50 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text); |
|
| 51 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj); |
|
| 52 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy); |
|
| 53 |
|
| 54 /* This file has been generated by the #dbus-analize-functions.py |
|
| 55 script. It contains dbus wrappers for the four functions declared |
|
| 56 above. */ |
|
| 57 #include "dbus-example-bindings.c" |
|
| 58 |
|
| 59 /* This is the GaimText object we want to make publicly visible. */ |
|
| 60 static GaimText hello; |
|
| 61 |
|
| 62 /* Here come the definitions of the four exported functions. */ |
|
| 63 GaimText* dbus_example_get_hello_object(void) |
|
| 64 { |
|
| 65 return &hello; |
|
| 66 } |
|
| 67 |
|
| 68 void dbus_example_set_text(GaimText *obj, const char *text) |
|
| 69 { |
|
| 70 if (obj != NULL) { |
|
| 71 g_free(obj->text); |
|
| 72 obj->text = g_strdup(text); |
|
| 73 } |
|
| 74 } |
|
| 75 |
|
| 76 const char *dbus_example_get_text(GaimText *obj) |
|
| 77 { |
|
| 78 if (obj != NULL) |
|
| 79 return obj->text; |
|
| 80 else |
|
| 81 return NULL; |
|
| 82 } |
|
| 83 |
|
| 84 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) |
|
| 85 { |
|
| 86 return gaim_buddy_get_name(buddy); |
|
| 87 } |
|
| 88 |
|
| 89 /* And now standard plugin stuff */ |
|
| 90 |
|
| 91 static gboolean |
|
| 92 plugin_load(GaimPlugin *plugin) |
|
| 93 { |
|
| 94 /* First, we have to register our four exported functions with the |
|
| 95 main gaim dbus loop. Without this statement, the gaim dbus |
|
| 96 code wouldn't know about our functions. */ |
|
| 97 GAIM_DBUS_REGISTER_BINDINGS(plugin); |
|
| 98 |
|
| 99 /* Then, we register the hello object of type GaimText. Note that |
|
| 100 pointer registrations / unregistrations are completely dynamic; |
|
| 101 they don't have to be made when the plugin is loaded / |
|
| 102 unloaded. Without this statement the dbus gaim code wouldn't |
|
| 103 know about the hello object. */ |
|
| 104 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); |
|
| 105 |
|
| 106 hello.text = g_strdup("Hello."); |
|
| 107 |
|
| 108 return TRUE; |
|
| 109 } |
|
| 110 |
|
| 111 |
|
| 112 static gboolean |
|
| 113 plugin_unload(GaimPlugin *plugin) |
|
| 114 { |
|
| 115 g_free(hello.text); |
|
| 116 |
|
| 117 /* It is necessary to unregister all pointers registered by the module. */ |
|
| 118 GAIM_DBUS_UNREGISTER_POINTER(&hello); |
|
| 119 |
|
| 120 return TRUE; |
|
| 121 } |
|
| 122 |
|
| 123 static GaimPluginInfo info = |
|
| 124 { |
|
| 125 GAIM_PLUGIN_MAGIC, |
|
| 126 GAIM_MAJOR_VERSION, |
|
| 127 GAIM_MINOR_VERSION, |
|
| 128 GAIM_PLUGIN_STANDARD, /**< type */ |
|
| 129 NULL, /**< ui_requirement */ |
|
| 130 0, /**< flags */ |
|
| 131 NULL, /**< dependencies */ |
|
| 132 GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
| 133 |
|
| 134 "dbus-example", /**< id */ |
|
| 135 N_("DBus"), /**< name */ |
|
| 136 VERSION, /**< version */ |
|
| 137 /** summary */ |
|
| 138 N_("DBus Plugin Example"), |
|
| 139 /** description */ |
|
| 140 N_("DBus Plugin Example"), |
|
| 141 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ |
|
| 142 GAIM_WEBSITE, /**< homepage */ |
|
| 143 |
|
| 144 plugin_load, /**< load */ |
|
| 145 plugin_unload, /**< unload */ |
|
| 146 NULL, /**< destroy */ |
|
| 147 |
|
| 148 NULL, /**< ui_info */ |
|
| 149 NULL, /**< extra_info */ |
|
| 150 NULL, /**< prefs_info */ |
|
| 151 NULL |
|
| 152 }; |
|
| 153 |
|
| 154 static void init_plugin(GaimPlugin *plugin) |
|
| 155 { |
|
| 156 } |
|
| 157 |
|
| 158 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) |
|