Mercurial > pidgin
annotate plugins/dbus-example.c @ 19809:b488205ad0bc
[gaim-migrate @ 16884]
chat function ok
debugging the multiple soap request in one ssl connection
not stable.
comitted by MaYuan<mayuan2006@gmail.com>
committer: Ethan Blanton <elb@pidgin.im>
author | Ma Yuan <mayuan2006@gmail.com> |
---|---|
date | Sat, 19 Aug 2006 14:12:41 +0000 |
parents | a7b24ba66570 |
children | 2d6f7ac4b6f2 |
rev | line source |
---|---|
13555
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
1 /* |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
2 * This is an example of a gaim dbus plugin. After enabling this |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
3 * plugin, the following commands should work from the command line: |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
4 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
5 * prompt$ gaim-send DbusExampleGetHelloObject |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
6 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
7 * returns, say: int32 74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
8 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
9 * prompt$ gaim-send DbusExampleGetText int32:74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
10 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
11 * returns: string "Hello." |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
12 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
13 * prompt$ gaim-send DbusExampleSetText int32:74 string:Bye! |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
14 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
15 * prompt$ gaim-send DbusExampleGetText int32:74 |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
16 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
17 * returns: string "Bye!" |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
18 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
19 * Gaim is the legal property of its developers, whose names are too numerous |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
20 * to list here. Please refer to the COPYRIGHT file distributed with this |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
21 * source distribution. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
22 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
23 * This program is free software; you can redistribute it and/or modify |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
24 * it under the terms of the GNU General Public License as published by |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
25 * the Free Software Foundation; either version 2 of the License, or |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
26 * (at your option) any later version. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
27 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
28 * This program is distributed in the hope that it will be useful, |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
31 * GNU General Public License for more details. |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
32 * |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
33 * You should have received a copy of the GNU General Public License |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
34 * along with this program; if not, write to the Free Software |
a7b24ba66570
[gaim-migrate @ 15933]
Richard Laager <rlaager@wiktel.com>
parents:
11200
diff
changeset
|
35 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
11173 | 36 */ |
37 | |
38 #include "internal.h" | |
39 | |
40 #include "plugin.h" | |
41 #include "blist.h" | |
42 #include "version.h" | |
43 | |
44 #include <stdio.h> | |
45 #include <stdlib.h> | |
46 #include <string.h> | |
47 | |
48 #define DBUS_API_SUBJECT_TO_CHANGE | |
49 #include "dbus-maybe.h" | |
50 #include "dbus-bindings.h" | |
51 | |
52 typedef struct { | |
53 char *text; | |
54 } GaimText; | |
55 | |
56 /* This makes the structure GaimText visible to the gaim-dbus type | |
57 system. It defines GaimText as a type with no parent. From now | |
58 on, we will be able to register pointers to structures of this | |
59 type. You to dbus-define types you want to be directly accessible | |
60 by external applications. */ | |
61 GAIM_DBUS_DEFINE_TYPE(GaimText) | |
62 | |
63 /* Here we make four functions accessible to other applications by | |
64 DBus. These functions can access types defined in gaim proper | |
65 (GaimBuddy) as well as the types defined in the plugin (GaimText). */ | |
66 DBUS_EXPORT GaimText* dbus_example_get_hello_object(void); | |
67 DBUS_EXPORT void dbus_example_set_text(GaimText *obj, const char *text); | |
68 DBUS_EXPORT const char *dbus_example_get_text(GaimText *obj); | |
69 DBUS_EXPORT const char *dbus_example_get_buddy_name(GaimBuddy *buddy); | |
70 | |
71 /* This file has been generated by the #dbus-analize-functions.py | |
72 script. It contains dbus wrappers for the four functions declared | |
73 above. */ | |
74 #include "dbus-example-bindings.c" | |
75 | |
76 /* This is the GaimText object we want to make publicly visible. */ | |
77 static GaimText hello; | |
78 | |
79 /* Here come the definitions of the four exported functions. */ | |
80 GaimText* dbus_example_get_hello_object(void) | |
81 { | |
82 return &hello; | |
83 } | |
84 | |
85 void dbus_example_set_text(GaimText *obj, const char *text) | |
86 { | |
87 if (obj != NULL) { | |
88 g_free(obj->text); | |
89 obj->text = g_strdup(text); | |
90 } | |
91 } | |
92 | |
93 const char *dbus_example_get_text(GaimText *obj) | |
94 { | |
95 if (obj != NULL) | |
96 return obj->text; | |
97 else | |
98 return NULL; | |
99 } | |
100 | |
101 const char *dbus_example_get_buddy_name(GaimBuddy *buddy) | |
102 { | |
103 return gaim_buddy_get_name(buddy); | |
104 } | |
105 | |
106 /* And now standard plugin stuff */ | |
107 | |
108 static gboolean | |
109 plugin_load(GaimPlugin *plugin) | |
110 { | |
111 /* First, we have to register our four exported functions with the | |
112 main gaim dbus loop. Without this statement, the gaim dbus | |
113 code wouldn't know about our functions. */ | |
114 GAIM_DBUS_REGISTER_BINDINGS(plugin); | |
115 | |
116 /* Then, we register the hello object of type GaimText. Note that | |
117 pointer registrations / unregistrations are completely dynamic; | |
118 they don't have to be made when the plugin is loaded / | |
119 unloaded. Without this statement the dbus gaim code wouldn't | |
120 know about the hello object. */ | |
121 GAIM_DBUS_REGISTER_POINTER(&hello, GaimText); | |
122 | |
123 hello.text = g_strdup("Hello."); | |
124 | |
125 return TRUE; | |
126 } | |
127 | |
128 | |
129 static gboolean | |
130 plugin_unload(GaimPlugin *plugin) | |
131 { | |
132 g_free(hello.text); | |
133 | |
134 /* It is necessary to unregister all pointers registered by the module. */ | |
135 GAIM_DBUS_UNREGISTER_POINTER(&hello); | |
136 | |
137 return TRUE; | |
138 } | |
139 | |
140 static GaimPluginInfo info = | |
141 { | |
142 GAIM_PLUGIN_MAGIC, | |
143 GAIM_MAJOR_VERSION, | |
144 GAIM_MINOR_VERSION, | |
145 GAIM_PLUGIN_STANDARD, /**< type */ | |
146 NULL, /**< ui_requirement */ | |
147 0, /**< flags */ | |
148 NULL, /**< dependencies */ | |
149 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
150 | |
151 "dbus-example", /**< id */ | |
152 N_("DBus"), /**< name */ | |
153 VERSION, /**< version */ | |
154 /** summary */ | |
155 N_("DBus Plugin Example"), | |
156 /** description */ | |
157 N_("DBus Plugin Example"), | |
158 "Piotr Zielinski (http://cl.cam.ac.uk/~pz215)", /**< author */ | |
159 GAIM_WEBSITE, /**< homepage */ | |
160 | |
161 plugin_load, /**< load */ | |
162 plugin_unload, /**< unload */ | |
163 NULL, /**< destroy */ | |
164 | |
165 NULL, /**< ui_info */ | |
166 NULL, /**< extra_info */ | |
167 NULL, /**< prefs_info */ | |
168 NULL | |
169 }; | |
170 | |
171 static void init_plugin(GaimPlugin *plugin) | |
172 { | |
173 } | |
174 | |
175 GAIM_INIT_PLUGIN(dbus_example, init_plugin, info) |