Mercurial > pidgin
comparison libpurple/plugins/dbus-example.c @ 15822:32c366eeeb99
sed -ie 's/gaim/purple/g'
| author | Sean Egan <seanegan@gmail.com> |
|---|---|
| date | Mon, 19 Mar 2007 07:01:17 +0000 |
| parents | 5fe8042783c1 |
| children | 5205dd2bd035 |
comparison
equal
deleted
inserted
replaced
| 15821:84b0f9b23ede | 15822:32c366eeeb99 |
|---|---|
| 1 /* | 1 /* |
| 2 * This is an example of a gaim dbus plugin. After enabling this | 2 * This is an example of a purple dbus plugin. After enabling this |
| 3 * plugin, the following commands should work from the command line: | 3 * plugin, the following commands should work from the command line: |
| 4 * | 4 * |
| 5 * prompt$ gaim-send DbusExampleGetHelloObject | 5 * prompt$ purple-send DbusExampleGetHelloObject |
| 6 * | 6 * |
| 7 * returns, say: int32 74 | 7 * returns, say: int32 74 |
| 8 * | 8 * |
| 9 * prompt$ gaim-send DbusExampleGetText int32:74 | 9 * prompt$ purple-send DbusExampleGetText int32:74 |
| 10 * | 10 * |
| 11 * returns: string "Hello." | 11 * returns: string "Hello." |
| 12 * | 12 * |
| 13 * prompt$ gaim-send DbusExampleSetText int32:74 string:Bye! | 13 * prompt$ purple-send DbusExampleSetText int32:74 string:Bye! |
| 14 * | 14 * |
| 15 * prompt$ gaim-send DbusExampleGetText int32:74 | 15 * prompt$ purple-send DbusExampleGetText int32:74 |
| 16 * | 16 * |
| 17 * returns: string "Bye!" | 17 * returns: string "Bye!" |
| 18 * | 18 * |
| 19 * Gaim is the legal property of its developers, whose names are too numerous | 19 * Purple is the legal property of its developers, whose names are too numerous |
| 20 * to list here. Please refer to the COPYRIGHT file distributed with this | 20 * to list here. Please refer to the COPYRIGHT file distributed with this |
| 21 * source distribution. | 21 * source distribution. |
| 22 * | 22 * |
| 23 * This program is free software; you can redistribute it and/or modify | 23 * This program is free software; you can redistribute it and/or modify |
| 24 * it under the terms of the GNU General Public License as published by | 24 * it under the terms of the GNU General Public License as published by |
| 50 #include "dbus-maybe.h" | 50 #include "dbus-maybe.h" |
| 51 #include "dbus-bindings.h" | 51 #include "dbus-bindings.h" |
| 52 | 52 |
| 53 typedef struct { | 53 typedef struct { |
| 54 char *text; | 54 char *text; |
| 55 } GaimText; | 55 } PurpleText; |
| 56 | 56 |
| 57 /* This makes the structure GaimText visible to the gaim-dbus type | 57 /* This makes the structure PurpleText visible to the purple-dbus type |
| 58 system. It defines GaimText as a type with no parent. From now | 58 system. It defines PurpleText as a type with no parent. From now |
| 59 on, we will be able to register pointers to structures of this | 59 on, we will be able to register pointers to structures of this |
| 60 type. You to dbus-define types you want to be directly accessible | 60 type. You to dbus-define types you want to be directly accessible |
| 61 by external applications. */ | 61 by external applications. */ |
| 62 GAIM_DBUS_DEFINE_TYPE(GaimText) | 62 PURPLE_DBUS_DEFINE_TYPE(PurpleText) |
| 63 | 63 |
| 64 /* Here we make four functions accessible to other applications by | 64 /* Here we make four functions accessible to other applications by |
| 65 DBus. These functions can access types defined in gaim proper | 65 DBus. These functions can access types defined in purple proper |
| 66 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ | 66 (PurpleBuddy) as well as the types defined in the plugin (PurpleText). */ |
| 67 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); | 67 DBUS_EXPORT PurpleText* dbus_example_get_hello_object(void); |
| 68 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text); | 68 DBUS_EXPORT void dbus_example_set_text(PurpleText *obj, const char *text); |
| 69 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj); | 69 DBUS_EXPORT const char *dbus_example_get_text(PurpleText *obj); |
| 70 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy); | 70 DBUS_EXPORT const char *dbus_example_get_buddy_name(PurpleBuddy *buddy); |
| 71 | 71 |
| 72 /* This file has been generated by the #dbus-analize-functions.py | 72 /* This file has been generated by the #dbus-analize-functions.py |
| 73 script. It contains dbus wrappers for the four functions declared | 73 script. It contains dbus wrappers for the four functions declared |
| 74 above. */ | 74 above. */ |
| 75 #include "dbus-example-bindings.c" | 75 #include "dbus-example-bindings.c" |
| 76 | 76 |
| 77 /* This is the GaimText object we want to make publicly visible. */ | 77 /* This is the PurpleText object we want to make publicly visible. */ |
| 78 static GaimText hello; | 78 static PurpleText hello; |
| 79 | 79 |
| 80 /* Here come the definitions of the four exported functions. */ | 80 /* Here come the definitions of the four exported functions. */ |
| 81 GaimText* dbus_example_get_hello_object(void) | 81 PurpleText* dbus_example_get_hello_object(void) |
| 82 { | 82 { |
| 83 return &hello; | 83 return &hello; |
| 84 } | 84 } |
| 85 | 85 |
| 86 void dbus_example_set_text(GaimText *obj, const char *text) | 86 void dbus_example_set_text(PurpleText *obj, const char *text) |
| 87 { | 87 { |
| 88 if (obj != NULL) { | 88 if (obj != NULL) { |
| 89 g_free(obj->text); | 89 g_free(obj->text); |
| 90 obj->text = g_strdup(text); | 90 obj->text = g_strdup(text); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 const char *dbus_example_get_text(GaimText *obj) | 94 const char *dbus_example_get_text(PurpleText *obj) |
| 95 { | 95 { |
| 96 if (obj != NULL) | 96 if (obj != NULL) |
| 97 return obj->text; | 97 return obj->text; |
| 98 else | 98 else |
| 99 return NULL; | 99 return NULL; |
| 100 } | 100 } |
| 101 | 101 |
| 102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) | 102 const char *dbus_example_get_buddy_name(PurpleBuddy *buddy) |
| 103 { | 103 { |
| 104 return gaim_buddy_get_name(buddy); | 104 return purple_buddy_get_name(buddy); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /* And now standard plugin stuff */ | 107 /* And now standard plugin stuff */ |
| 108 | 108 |
| 109 static gboolean | 109 static gboolean |
| 110 plugin_load(GaimPlugin *plugin) | 110 plugin_load(PurplePlugin *plugin) |
| 111 { | 111 { |
| 112 GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); | 112 PURPLE_DBUS_RETURN_FALSE_IF_DISABLED(plugin); |
| 113 | 113 |
| 114 /* First, we have to register our four exported functions with the | 114 /* First, we have to register our four exported functions with the |
| 115 main gaim dbus loop. Without this statement, the gaim dbus | 115 main purple dbus loop. Without this statement, the purple dbus |
| 116 code wouldn't know about our functions. */ | 116 code wouldn't know about our functions. */ |
| 117 GAIM_DBUS_REGISTER_BINDINGS(plugin); | 117 PURPLE_DBUS_REGISTER_BINDINGS(plugin); |
| 118 | 118 |
| 119 /* Then, we register the hello object of type GaimText. Note that | 119 /* Then, we register the hello object of type PurpleText. Note that |
| 120 pointer registrations / unregistrations are completely dynamic; | 120 pointer registrations / unregistrations are completely dynamic; |
| 121 they don't have to be made when the plugin is loaded / | 121 they don't have to be made when the plugin is loaded / |
| 122 unloaded. Without this statement the dbus gaim code wouldn't | 122 unloaded. Without this statement the dbus purple code wouldn't |
| 123 know about the hello object. */ | 123 know about the hello object. */ |
| 124 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); | 124 PURPLE_DBUS_REGISTER_POINTER(&hello, PurpleText); |
| 125 | 125 |
| 126 hello.text = g_strdup("Hello."); | 126 hello.text = g_strdup("Hello."); |
| 127 | 127 |
| 128 return TRUE; | 128 return TRUE; |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 static gboolean | 132 static gboolean |
| 133 plugin_unload(GaimPlugin *plugin) | 133 plugin_unload(PurplePlugin *plugin) |
| 134 { | 134 { |
| 135 g_free(hello.text); | 135 g_free(hello.text); |
| 136 | 136 |
| 137 /* It is necessary to unregister all pointers registered by the module. */ | 137 /* It is necessary to unregister all pointers registered by the module. */ |
| 138 GAIM_DBUS_UNREGISTER_POINTER(&hello); | 138 PURPLE_DBUS_UNREGISTER_POINTER(&hello); |
| 139 | 139 |
| 140 return TRUE; | 140 return TRUE; |
| 141 } | 141 } |
| 142 | 142 |
| 143 static GaimPluginInfo info = | 143 static PurplePluginInfo info = |
| 144 { | 144 { |
| 145 GAIM_PLUGIN_MAGIC, | 145 PURPLE_PLUGIN_MAGIC, |
| 146 GAIM_MAJOR_VERSION, | 146 PURPLE_MAJOR_VERSION, |
| 147 GAIM_MINOR_VERSION, | 147 PURPLE_MINOR_VERSION, |
| 148 GAIM_PLUGIN_STANDARD, /**< type */ | 148 PURPLE_PLUGIN_STANDARD, /**< type */ |
| 149 NULL, /**< ui_requirement */ | 149 NULL, /**< ui_requirement */ |
| 150 0, /**< flags */ | 150 0, /**< flags */ |
| 151 NULL, /**< dependencies */ | 151 NULL, /**< dependencies */ |
| 152 GAIM_PRIORITY_DEFAULT, /**< priority */ | 152 PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 153 | 153 |
| 154 "dbus-example", /**< id */ | 154 "dbus-example", /**< id */ |
| 155 N_("DBus Example"), /**< name */ | 155 N_("DBus Example"), /**< name */ |
| 156 VERSION, /**< version */ | 156 VERSION, /**< version */ |
| 157 /** summary */ | 157 /** summary */ |
| 158 N_("DBus Plugin Example"), | 158 N_("DBus Plugin Example"), |
| 159 /** description */ | 159 /** description */ |
| 160 N_("DBus Plugin Example"), | 160 N_("DBus Plugin Example"), |
| 161 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ | 161 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ |
| 162 GAIM_WEBSITE, /**< homepage */ | 162 PURPLE_WEBSITE, /**< homepage */ |
| 163 | 163 |
| 164 plugin_load, /**< load */ | 164 plugin_load, /**< load */ |
| 165 plugin_unload, /**< unload */ | 165 plugin_unload, /**< unload */ |
| 166 NULL, /**< destroy */ | 166 NULL, /**< destroy */ |
| 167 | 167 |
| 169 NULL, /**< extra_info */ | 169 NULL, /**< extra_info */ |
| 170 NULL, /**< prefs_info */ | 170 NULL, /**< prefs_info */ |
| 171 NULL | 171 NULL |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 static void init_plugin(GaimPlugin *plugin) | 174 static void init_plugin(PurplePlugin *plugin) |
| 175 { | 175 { |
| 176 } | 176 } |
| 177 | 177 |
| 178 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) | 178 PURPLE_INIT_PLUGIN(dbus_example, init_plugin, info) |
