|
1 /* -*- mode: C; c-file-style: "gnu" -*- */ |
|
2 /* dbus-glib.c General GLib binding stuff |
|
3 * |
|
4 * Copyright (C) 2004 Red Hat, Inc. |
|
5 * Portion Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
6 * Licensed under the Academic Free License version 2.1 |
|
7 * |
|
8 * This program is free software; you can redistribute it and/or modify |
|
9 * it under the terms of the GNU General Public License as published by |
|
10 * the Free Software Foundation; either version 2 of the License, or |
|
11 * (at your option) any later version. |
|
12 * |
|
13 * This program is distributed in the hope that it will be useful, |
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 * GNU General Public License for more details. |
|
17 * |
|
18 * You should have received a copy of the GNU General Public License |
|
19 * along with this program; if not, write to the Free Software |
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
21 * |
|
22 */ |
|
23 |
|
24 #ifndef __SYMBIAN32__ |
|
25 #include <config.h> |
|
26 #else |
|
27 #include "config.h" |
|
28 #endif //__SYMBIAN32__ |
|
29 #include "dbus-glib.h" |
|
30 #include "dbus-glib-lowlevel.h" |
|
31 #include "dbus-gtest.h" |
|
32 #include "dbus-gutils.h" |
|
33 #include "dbus-gobject.h" |
|
34 #include <string.h> |
|
35 |
|
36 #ifndef __SYMBIAN32__ |
|
37 #include <libintl.h> |
|
38 #define _(x) dgettext (GETTEXT_PACKAGE, x) |
|
39 #define N_(x) x |
|
40 #else |
|
41 |
|
42 #define _(x) x |
|
43 #define N_(x) x |
|
44 #endif |
|
45 |
|
46 #ifdef __SYMBIAN32__ |
|
47 #include "libdbus_glib_wsd_solution.h" |
|
48 #endif |
|
49 |
|
50 /** |
|
51 * SECTION:dbus-gconnection |
|
52 * @short_description: DBus Connection |
|
53 * @see_also: #DBusConnection |
|
54 * @stability: Stable |
|
55 * |
|
56 * A #DBusGConnection is a boxed type abstracting a DBusConnection. |
|
57 */ |
|
58 |
|
59 /** |
|
60 * dbus_g_connection_flush: |
|
61 * @connection: the #DBusGConnection to flush |
|
62 * |
|
63 * Blocks until outgoing calls and signal emissions have been sent. |
|
64 */ |
|
65 #ifdef __SYMBIAN32__ |
|
66 EXPORT_C |
|
67 #endif |
|
68 void |
|
69 dbus_g_connection_flush (DBusGConnection *connection) |
|
70 { |
|
71 dbus_connection_flush (DBUS_CONNECTION_FROM_G_CONNECTION (connection)); |
|
72 } |
|
73 |
|
74 /** |
|
75 * dbus_g_connection_ref: |
|
76 * @gconnection the #DBusGConnection to ref |
|
77 * |
|
78 * Increment refcount on a #DBusGConnection |
|
79 * |
|
80 * Returns: the connection that was ref'd |
|
81 */ |
|
82 #ifdef __SYMBIAN32__ |
|
83 EXPORT_C |
|
84 #endif |
|
85 DBusGConnection* |
|
86 dbus_g_connection_ref (DBusGConnection *gconnection) |
|
87 { |
|
88 DBusConnection *c; |
|
89 |
|
90 c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection); |
|
91 dbus_connection_ref (c); |
|
92 return gconnection; |
|
93 } |
|
94 |
|
95 |
|
96 /** |
|
97 * dbus_g_connection_unref: |
|
98 * @gconnection: the connection to unref |
|
99 * |
|
100 * Decrement refcount on a #DBusGConnection |
|
101 */ |
|
102 #ifdef __SYMBIAN32__ |
|
103 EXPORT_C |
|
104 #endif |
|
105 void |
|
106 dbus_g_connection_unref (DBusGConnection *gconnection) |
|
107 { |
|
108 DBusConnection *c; |
|
109 |
|
110 c = DBUS_CONNECTION_FROM_G_CONNECTION (gconnection); |
|
111 dbus_connection_unref (c); |
|
112 } |
|
113 |
|
114 |
|
115 /** |
|
116 * SECTION:dbus-gmessage |
|
117 * @short_description: DBus Message |
|
118 * @see_also: #DBusMessage |
|
119 * @stability: Stable |
|
120 * |
|
121 * A #DBusGConnection is a boxed type abstracting a DBusMessage. |
|
122 */ |
|
123 |
|
124 /** |
|
125 * dbus_g_message_ref: |
|
126 * @gmessage: the message to ref |
|
127 * |
|
128 * Increment refcount on a #DBusGMessage |
|
129 * |
|
130 * Returns: the message that was ref'd |
|
131 */ |
|
132 #ifdef __SYMBIAN32__ |
|
133 EXPORT_C |
|
134 #endif |
|
135 DBusGMessage* |
|
136 dbus_g_message_ref (DBusGMessage *gmessage) |
|
137 { |
|
138 DBusMessage *c; |
|
139 |
|
140 c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage); |
|
141 dbus_message_ref (c); |
|
142 return gmessage; |
|
143 } |
|
144 |
|
145 /** |
|
146 * dbus_g_message_unref: |
|
147 * @gmessage: the message to unref |
|
148 * |
|
149 * Decrement refcount on a #DBusGMessage |
|
150 */ |
|
151 #ifdef __SYMBIAN32__ |
|
152 EXPORT_C |
|
153 #endif |
|
154 void |
|
155 dbus_g_message_unref (DBusGMessage *gmessage) |
|
156 { |
|
157 DBusMessage *c; |
|
158 |
|
159 c = DBUS_MESSAGE_FROM_G_MESSAGE (gmessage); |
|
160 dbus_message_unref (c); |
|
161 } |
|
162 |
|
163 /** |
|
164 * SECTION:dbus-gerror |
|
165 * @short_description: DBus GError |
|
166 * @see_also: #GError |
|
167 * @stability: Stable |
|
168 * |
|
169 * #DBusGError is the #GError used by DBus. |
|
170 */ |
|
171 |
|
172 /** |
|
173 * dbus_g_error_quark: |
|
174 * |
|
175 * The implementation of #DBUS_GERROR error domain. See documentation |
|
176 * for #GError in GLib reference manual. |
|
177 * |
|
178 * Returns: the error domain quark for use with #GError |
|
179 */ |
|
180 |
|
181 #if EMULATOR |
|
182 GET_STATIC_VAR_FROM_TLS(quark,dbus_glib,GQuark ) |
|
183 #define quark (*GET_DBUS_WSD_VAR_NAME(quark,dbus_glib,s)()) |
|
184 |
|
185 #endif |
|
186 #ifdef __SYMBIAN32__ |
|
187 EXPORT_C |
|
188 #endif |
|
189 GQuark |
|
190 dbus_g_error_quark (void) |
|
191 { |
|
192 #ifndef EMULATOR |
|
193 static GQuark quark=0; |
|
194 #endif |
|
195 if (quark == 0) |
|
196 quark = g_quark_from_static_string ("dbus-glib-error-quark"); |
|
197 return quark; |
|
198 } |
|
199 |
|
200 /** |
|
201 * dbus_g_error_has_name: |
|
202 * @error: the GError given from the remote method |
|
203 * @name: the D-BUS error name |
|
204 * @msg: the D-BUS error detailed message |
|
205 * |
|
206 * Determine whether D-BUS error name for a remote exception matches |
|
207 * the given name. This function is intended to be invoked on a |
|
208 * GError returned from an invocation of a remote method, e.g. via |
|
209 * dbus_g_proxy_end_call. It will silently return FALSE for errors |
|
210 * which are not remote D-BUS exceptions (i.e. with a domain other |
|
211 * than DBUS_GERROR or a code other than |
|
212 * DBUS_GERROR_REMOTE_EXCEPTION). |
|
213 * |
|
214 * Returns: TRUE iff the remote error has the given name |
|
215 */ |
|
216 #ifdef __SYMBIAN32__ |
|
217 EXPORT_C |
|
218 #endif |
|
219 gboolean |
|
220 dbus_g_error_has_name (GError *error, const char *name) |
|
221 { |
|
222 g_return_val_if_fail (error != NULL, FALSE); |
|
223 |
|
224 if (error->domain != DBUS_GERROR |
|
225 || error->code != DBUS_GERROR_REMOTE_EXCEPTION) |
|
226 return FALSE; |
|
227 |
|
228 return !strcmp (dbus_g_error_get_name (error), name); |
|
229 } |
|
230 |
|
231 /** |
|
232 * dbus_g_error_get_name: |
|
233 * @error: the #GError given from the remote method |
|
234 * @name: the D-BUS error name |
|
235 * @msg: the D-BUS error detailed message |
|
236 * |
|
237 * This function may only be invoked on a #GError returned from an |
|
238 * invocation of a remote method, e.g. via dbus_g_proxy_end_call. |
|
239 * Moreover, you must ensure that the error's domain is #DBUS_GERROR, |
|
240 * and the code is #DBUS_GERROR_REMOTE_EXCEPTION. |
|
241 * |
|
242 * Returns: the D-BUS name for a remote exception. |
|
243 */ |
|
244 #ifdef __SYMBIAN32__ |
|
245 EXPORT_C |
|
246 #endif |
|
247 const char * |
|
248 dbus_g_error_get_name (GError *error) |
|
249 { |
|
250 g_return_val_if_fail (error != NULL, NULL); |
|
251 g_return_val_if_fail (error->domain == DBUS_GERROR, NULL); |
|
252 g_return_val_if_fail (error->code == DBUS_GERROR_REMOTE_EXCEPTION, NULL); |
|
253 |
|
254 return error->message + strlen (error->message) + 1; |
|
255 } |
|
256 |
|
257 /** |
|
258 * dbus_connection_get_g_type: |
|
259 * Get the GLib type ID for a #DBusConnection boxed type. |
|
260 * |
|
261 * Returns: the GLib type |
|
262 */ |
|
263 /* |
|
264 #if EMULATOR |
|
265 GET_STATIC_VAR_FROM_TLS(our_type,dbus_glib,GType ) |
|
266 #define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,p)()) |
|
267 #endif |
|
268 */ |
|
269 |
|
270 #ifdef __SYMBIAN32__ |
|
271 EXPORT_C |
|
272 #endif |
|
273 GType |
|
274 dbus_connection_get_g_type (void) |
|
275 { |
|
276 #ifndef EMULATOR |
|
277 |
|
278 static GType our_type = 0; |
|
279 #else |
|
280 // RETURN_WSD_VAR(our_type,dbus_glib,p) //(libdbus_glib_ImpurePtr()->GET_DBUS_WSD_VAR_NAME(var,filename,prefix)) |
|
281 // #define GET_DBUS_WSD_VAR_NAME(var,filename,prefix) _##prefix##_##filename##_##var |
|
282 #ifdef our_type |
|
283 #undef our_type |
|
284 #endif |
|
285 #define our_type RETURN_WSD_VAR(our_type,dbus_glib,p) |
|
286 // #define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,p)()) //(*_p_dbus_glib_our_type()) |
|
287 |
|
288 |
|
289 #endif |
|
290 |
|
291 |
|
292 |
|
293 if (our_type == 0) |
|
294 our_type = g_boxed_type_register_static ("DBusConnection", |
|
295 (GBoxedCopyFunc) dbus_connection_ref, |
|
296 (GBoxedFreeFunc) dbus_connection_unref); |
|
297 |
|
298 return our_type; |
|
299 |
|
300 } |
|
301 |
|
302 /** |
|
303 * dbus_message_get_g_type: |
|
304 * Get the GLib type ID for a #DBusMessage boxed type. |
|
305 * |
|
306 * Returns: the GLib type |
|
307 */ |
|
308 |
|
309 /* |
|
310 #if EMULATOR |
|
311 GET_STATIC_VAR_FROM_TLS(out_type,dbus_glib,GType ) |
|
312 #define our_type (*GET_DBUS_WSD_VAR_NAME(our_type,dbus_glib,q)()) |
|
313 #endif*/ |
|
314 |
|
315 #ifdef __SYMBIAN32__ |
|
316 EXPORT_C |
|
317 #endif |
|
318 GType |
|
319 dbus_message_get_g_type (void) |
|
320 { |
|
321 |
|
322 #ifndef EMULATOR |
|
323 static GType our_type = 0; |
|
324 #else |
|
325 #ifdef our_type |
|
326 #undef our_type |
|
327 #endif |
|
328 #define our_type RETURN_WSD_VAR(our_type,dbus_glib,q) |
|
329 #endif |
|
330 |
|
331 |
|
332 if (our_type == 0) |
|
333 our_type = g_boxed_type_register_static ("DBusMessage", |
|
334 (GBoxedCopyFunc) dbus_message_ref, |
|
335 (GBoxedFreeFunc) dbus_message_unref); |
|
336 |
|
337 return our_type; |
|
338 } |
|
339 |
|
340 /** |
|
341 * dbus_g_connection_get_g_type: |
|
342 * Get the GLib type ID for a DBusGConnection boxed type. |
|
343 * |
|
344 * Returns: the GLib type |
|
345 */ |
|
346 |
|
347 |
|
348 #ifdef __SYMBIAN32__ |
|
349 EXPORT_C |
|
350 #endif |
|
351 GType |
|
352 dbus_g_connection_get_g_type (void) |
|
353 { |
|
354 #ifndef EMULATOR |
|
355 static GType our_type = 0; |
|
356 #else |
|
357 #ifdef our_type |
|
358 #undef our_type |
|
359 #endif |
|
360 #define our_type RETURN_WSD_VAR(our_type,dbus_glib,r) |
|
361 #endif |
|
362 |
|
363 |
|
364 if (our_type == 0) |
|
365 our_type = g_boxed_type_register_static ("DBusGConnection", |
|
366 (GBoxedCopyFunc) dbus_g_connection_ref, |
|
367 (GBoxedFreeFunc) dbus_g_connection_unref); |
|
368 |
|
369 return our_type; |
|
370 } |
|
371 |
|
372 /** |
|
373 * dbus_g_message_get_g_type: |
|
374 * Get the GLib type ID for a #DBusGMessage boxed type. |
|
375 * |
|
376 * Returns: the GLib type |
|
377 */ |
|
378 #ifdef __SYMBIAN32__ |
|
379 EXPORT_C |
|
380 #endif |
|
381 GType |
|
382 dbus_g_message_get_g_type (void) |
|
383 { |
|
384 #ifndef EMULATOR |
|
385 static GType our_type = 0; |
|
386 #else |
|
387 #ifdef our_type |
|
388 #undef our_type |
|
389 #endif |
|
390 #define our_type RETURN_WSD_VAR(our_type,dbus_glib,s) |
|
391 |
|
392 #endif |
|
393 |
|
394 if (our_type == 0) |
|
395 our_type = g_boxed_type_register_static ("DBusGMessage", |
|
396 (GBoxedCopyFunc) dbus_g_message_ref, |
|
397 (GBoxedFreeFunc) dbus_g_message_unref); |
|
398 |
|
399 return our_type; |
|
400 } |
|
401 |
|
402 /** |
|
403 * SECTION:dbus-glib-lowlevel |
|
404 * @short_description: DBus lower level functions |
|
405 * @stability: Unstable |
|
406 * |
|
407 * These functions can be used to access lower level of DBus. |
|
408 */ |
|
409 |
|
410 /** |
|
411 * dbus_g_connection_get_connection: |
|
412 * @gconnection: a #DBusGConnection |
|
413 * |
|
414 * Get the #DBusConnection corresponding to this #DBusGConnection. |
|
415 * The return value does not have its refcount incremented. |
|
416 * |
|
417 * Returns: #DBusConnection |
|
418 */ |
|
419 #ifdef __SYMBIAN32__ |
|
420 EXPORT_C |
|
421 #endif |
|
422 DBusConnection* |
|
423 dbus_g_connection_get_connection (DBusGConnection *gconnection) |
|
424 { |
|
425 g_return_val_if_fail (gconnection, NULL); |
|
426 return DBUS_CONNECTION_FROM_G_CONNECTION (gconnection); |
|
427 } |
|
428 |
|
429 #if EMULATOR |
|
430 dbus_int32_t GET_DBUS_WSD_VAR_NAME(_dbus_gmain_connection_slot,dbus_gmain,dbus_int32_t)(); |
|
431 #define _dbus_gmain_connection_slot (GET_DBUS_WSD_VAR_NAME(_dbus_gmain_connection_slot,dbus_gmain,g)()) |
|
432 #else |
|
433 extern dbus_int32_t _dbus_gmain_connection_slot; |
|
434 #endif |
|
435 /** |
|
436 * dbus_connection_get_g_connection: |
|
437 * @connection: a #DBusConnection |
|
438 * |
|
439 * Get the #DBusGConnection corresponding to this #DBusConnection. This only |
|
440 * makes sense if the #DBusConnection was originally a #DBusGConnection that was |
|
441 * registered with the GLib main loop. The return value does not have its |
|
442 * refcount incremented. |
|
443 * |
|
444 * Returns: #DBusGConnection |
|
445 */ |
|
446 #ifdef __SYMBIAN32__ |
|
447 EXPORT_C |
|
448 #endif |
|
449 DBusGConnection* |
|
450 dbus_connection_get_g_connection (DBusConnection *connection) |
|
451 { |
|
452 g_return_val_if_fail (connection, NULL); |
|
453 g_return_val_if_fail (dbus_connection_get_data (connection, _dbus_gmain_connection_slot), NULL); |
|
454 |
|
455 return DBUS_G_CONNECTION_FROM_CONNECTION (connection); |
|
456 } |
|
457 |
|
458 |
|
459 /** |
|
460 * dbus_g_message_get_message: |
|
461 * @gmessage: a #DBusGMessage |
|
462 * |
|
463 * Get the #DBusMessage corresponding to this #DBusGMessage. |
|
464 * The return value does not have its refcount incremented. |
|
465 * |
|
466 * Returns: #DBusMessage |
|
467 */ |
|
468 #ifdef __SYMBIAN32__ |
|
469 EXPORT_C |
|
470 #endif |
|
471 DBusMessage* |
|
472 dbus_g_message_get_message (DBusGMessage *gmessage) |
|
473 { |
|
474 return DBUS_MESSAGE_FROM_G_MESSAGE (gmessage); |
|
475 } |
|
476 |
|
477 #ifdef DBUS_BUILD_TESTS |
|
478 |
|
479 /** |
|
480 * @ingroup DBusGLibInternals |
|
481 * Unit test for general glib stuff |
|
482 * Returns: #TRUE on success. |
|
483 */ |
|
484 #ifdef __SYMBIAN32__ |
|
485 EXPORT_C |
|
486 #endif |
|
487 gboolean |
|
488 _dbus_glib_test (const char *test_data_dir) |
|
489 { |
|
490 DBusError err; |
|
491 GError *gerror = NULL; |
|
492 |
|
493 dbus_error_init (&err); |
|
494 dbus_set_error_const (&err, DBUS_ERROR_NO_MEMORY, "Out of memory!"); |
|
495 |
|
496 dbus_set_g_error (&gerror, &err); |
|
497 g_assert (gerror != NULL); |
|
498 g_assert (gerror->domain == DBUS_GERROR); |
|
499 g_assert (gerror->code == DBUS_GERROR_NO_MEMORY); |
|
500 g_assert (!strcmp (gerror->message, "Out of memory!")); |
|
501 |
|
502 dbus_error_init (&err); |
|
503 g_clear_error (&gerror); |
|
504 |
|
505 return TRUE; |
|
506 } |
|
507 |
|
508 #endif /* DBUS_BUILD_TESTS */ |