Mercurial > pidgin
comparison libpurple/plugins/dbus-example.c @ 15373:5fe8042783c1
Rename gtk/ and libgaim/ to pidgin/ and libpurple/
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sat, 20 Jan 2007 02:32:10 +0000 |
parents | |
children | 32c366eeeb99 |
comparison
equal
deleted
inserted
replaced
15372:f79e0f4df793 | 15373:5fe8042783c1 |
---|---|
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 * Gaim 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 | |
21 * source distribution. | |
22 * | |
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 | |
25 * the Free Software Foundation; either version 2 of the License, or | |
26 * (at your option) any later version. | |
27 * | |
28 * This program is distributed in the hope that it will be useful, | |
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31 * GNU General Public License for more details. | |
32 * | |
33 * You should have received a copy of the GNU General Public License | |
34 * along with this program; if not, write to the Free Software | |
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
36 */ | |
37 | |
38 #include "internal.h" | |
39 | |
40 #include "blist.h" | |
41 #include "notify.h" | |
42 #include "plugin.h" | |
43 #include "version.h" | |
44 | |
45 #include <stdio.h> | |
46 #include <stdlib.h> | |
47 #include <string.h> | |
48 | |
49 #define DBUS_API_SUBJECT_TO_CHANGE | |
50 #include "dbus-maybe.h" | |
51 #include "dbus-bindings.h" | |
52 | |
53 typedef struct { | |
54 char *text; | |
55 } GaimText; | |
56 | |
57 /* This makes the structure GaimText visible to the gaim-dbus type | |
58 system. It defines GaimText as a type with no parent. From now | |
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 | |
61 by external applications. */ | |
62 GAIM_DBUS_DEFINE_TYPE(GaimText) | |
63 | |
64 /* Here we make four functions accessible to other applications by | |
65 DBus. These functions can access types defined in gaim proper | |
66 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ | |
67 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); | |
68 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text); | |
69 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj); | |
70 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy); | |
71 | |
72 /* This file has been generated by the #dbus-analize-functions.py | |
73 script. It contains dbus wrappers for the four functions declared | |
74 above. */ | |
75 #include "dbus-example-bindings.c" | |
76 | |
77 /* This is the GaimText object we want to make publicly visible. */ | |
78 static GaimText hello; | |
79 | |
80 /* Here come the definitions of the four exported functions. */ | |
81 GaimText* dbus_example_get_hello_object(void) | |
82 { | |
83 return &hello; | |
84 } | |
85 | |
86 void dbus_example_set_text(GaimText *obj, const char *text) | |
87 { | |
88 if (obj != NULL) { | |
89 g_free(obj->text); | |
90 obj->text = g_strdup(text); | |
91 } | |
92 } | |
93 | |
94 const char *dbus_example_get_text(GaimText *obj) | |
95 { | |
96 if (obj != NULL) | |
97 return obj->text; | |
98 else | |
99 return NULL; | |
100 } | |
101 | |
102 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) | |
103 { | |
104 return gaim_buddy_get_name(buddy); | |
105 } | |
106 | |
107 /* And now standard plugin stuff */ | |
108 | |
109 static gboolean | |
110 plugin_load(GaimPlugin *plugin) | |
111 { | |
112 GAIM_DBUS_RETURN_FALSE_IF_DISABLED(plugin); | |
113 | |
114 /* First, we have to register our four exported functions with the | |
115 main gaim dbus loop. Without this statement, the gaim dbus | |
116 code wouldn't know about our functions. */ | |
117 GAIM_DBUS_REGISTER_BINDINGS(plugin); | |
118 | |
119 /* Then, we register the hello object of type GaimText. Note that | |
120 pointer registrations / unregistrations are completely dynamic; | |
121 they don't have to be made when the plugin is loaded / | |
122 unloaded. Without this statement the dbus gaim code wouldn't | |
123 know about the hello object. */ | |
124 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); | |
125 | |
126 hello.text = g_strdup("Hello."); | |
127 | |
128 return TRUE; | |
129 } | |
130 | |
131 | |
132 static gboolean | |
133 plugin_unload(GaimPlugin *plugin) | |
134 { | |
135 g_free(hello.text); | |
136 | |
137 /* It is necessary to unregister all pointers registered by the module. */ | |
138 GAIM_DBUS_UNREGISTER_POINTER(&hello); | |
139 | |
140 return TRUE; | |
141 } | |
142 | |
143 static GaimPluginInfo info = | |
144 { | |
145 GAIM_PLUGIN_MAGIC, | |
146 GAIM_MAJOR_VERSION, | |
147 GAIM_MINOR_VERSION, | |
148 GAIM_PLUGIN_STANDARD, /**< type */ | |
149 NULL, /**< ui_requirement */ | |
150 0, /**< flags */ | |
151 NULL, /**< dependencies */ | |
152 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
153 | |
154 "dbus-example", /**< id */ | |
155 N_("DBus Example"), /**< name */ | |
156 VERSION, /**< version */ | |
157 /** summary */ | |
158 N_("DBus Plugin Example"), | |
159 /** description */ | |
160 N_("DBus Plugin Example"), | |
161 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ | |
162 GAIM_WEBSITE, /**< homepage */ | |
163 | |
164 plugin_load, /**< load */ | |
165 plugin_unload, /**< unload */ | |
166 NULL, /**< destroy */ | |
167 | |
168 NULL, /**< ui_info */ | |
169 NULL, /**< extra_info */ | |
170 NULL, /**< prefs_info */ | |
171 NULL | |
172 }; | |
173 | |
174 static void init_plugin(GaimPlugin *plugin) | |
175 { | |
176 } | |
177 | |
178 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) |