Mercurial > pidgin.yaz
comparison src/dbus-server.c @ 13955:2d6f7ac4b6f2
[gaim-migrate @ 16503]
Get rid of an assertion failure when trying to load our D-BUS example
plugin if the D-BUS subsystem is not initialized for whatever reason.
Not only that, the plugin gracefully fails to load and prints an
error message.
These error messages could be improved. If you're familiar with how
D-BUS works then go for it.
Also, do we need to be uninitializing any of the D-BUS stuff?
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Mon, 17 Jul 2006 05:50:28 +0000 |
parents | fd708f52defd |
children | f7cfaee79982 |
comparison
equal
deleted
inserted
replaced
13954:3cd388613624 | 13955:2d6f7ac4b6f2 |
---|---|
34 #include "dbus-server.h" | 34 #include "dbus-server.h" |
35 #include "dbus-useful.h" | 35 #include "dbus-useful.h" |
36 #include "dbus-bindings.h" | 36 #include "dbus-bindings.h" |
37 #include "debug.h" | 37 #include "debug.h" |
38 #include "core.h" | 38 #include "core.h" |
39 #include "internal.h" | |
39 #include "savedstatuses.h" | 40 #include "savedstatuses.h" |
40 #include "value.h" | 41 #include "value.h" |
41 | 42 |
42 | 43 |
43 /**************************************************************************/ | 44 /**************************************************************************/ |
56 pointers (nodes) and the corresponding handles (ids). */ | 57 pointers (nodes) and the corresponding handles (ids). */ |
57 | 58 |
58 static GHashTable *map_node_id; | 59 static GHashTable *map_node_id; |
59 static GHashTable *map_id_node; | 60 static GHashTable *map_id_node; |
60 static GHashTable *map_id_type; | 61 static GHashTable *map_id_type; |
62 | |
63 static gchar *init_error; | |
61 | 64 |
62 | 65 |
63 /* This function initializes the pointer-id traslation system. It | 66 /* This function initializes the pointer-id traslation system. It |
64 creates the three above hashtables and defines parents of some types. | 67 creates the three above hashtables and defines parents of some types. |
65 */ | 68 */ |
227 } | 230 } |
228 else { | 231 else { |
229 DBusMessageIter *sub; | 232 DBusMessageIter *sub; |
230 sub = va_arg (var_args, DBusMessageIter*); | 233 sub = va_arg (var_args, DBusMessageIter*); |
231 dbus_message_iter_recurse(iter, sub); | 234 dbus_message_iter_recurse(iter, sub); |
232 g_print("subiter %i:%i\n", (int) sub, * (int*) sub); | 235 gaim_debug_info("dbus", "subiter %p:%p\n", sub, * (gpointer*) sub); |
233 break; /* for testing only! */ | 236 break; /* for testing only! */ |
234 } | 237 } |
235 | 238 |
236 spec_type = va_arg (var_args, int); | 239 spec_type = va_arg (var_args, int); |
237 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) { | 240 if (!dbus_message_iter_next(iter) && spec_type != DBUS_TYPE_INVALID) { |
380 DBusConnection *gaim_dbus_get_connection(void) { | 383 DBusConnection *gaim_dbus_get_connection(void) { |
381 return gaim_dbus_connection; | 384 return gaim_dbus_connection; |
382 } | 385 } |
383 | 386 |
384 #include "dbus-bindings.c" | 387 #include "dbus-bindings.c" |
385 | |
386 void *gaim_dbus_get_handle(void) { | |
387 static int handle; | |
388 | |
389 return &handle; | |
390 } | |
391 | 388 |
392 static gboolean | 389 static gboolean |
393 gaim_dbus_dispatch_cb(DBusConnection *connection, | 390 gaim_dbus_dispatch_cb(DBusConnection *connection, |
394 DBusMessage *message, | 391 DBusMessage *message, |
395 void *user_data) | 392 void *user_data) |
435 | 432 |
436 return FALSE; | 433 return FALSE; |
437 } | 434 } |
438 | 435 |
439 | 436 |
440 static const char *gettext(const char **ptr) { | 437 static const char *dbus_gettext(const char **ptr) { |
441 const char *text = *ptr; | 438 const char *text = *ptr; |
442 *ptr += strlen(text) + 1; | 439 *ptr += strlen(text) + 1; |
443 return text; | 440 return text; |
444 } | 441 } |
445 | 442 |
476 | 473 |
477 text = bindings[i].parameters; | 474 text = bindings[i].parameters; |
478 while (*text) { | 475 while (*text) { |
479 const char *name, *direction, *type; | 476 const char *name, *direction, *type; |
480 | 477 |
481 direction = gettext(&text); | 478 direction = dbus_gettext(&text); |
482 type = gettext(&text); | 479 type = dbus_gettext(&text); |
483 name = gettext(&text); | 480 name = dbus_gettext(&text); |
484 | 481 |
485 g_string_append_printf(str, | 482 g_string_append_printf(str, |
486 "<arg name='%s' type='%s' direction='%s'/>\n", | 483 "<arg name='%s' type='%s' direction='%s'/>\n", |
487 name, type, direction); | 484 name, type, direction); |
488 } | 485 } |
537 bindings); | 534 bindings); |
538 } | 535 } |
539 | 536 |
540 | 537 |
541 | 538 |
542 static gboolean gaim_dbus_dispatch_init(void) | 539 static void gaim_dbus_dispatch_init(void) |
543 { | 540 { |
544 static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; | 541 static DBusObjectPathVTable vtable = {NULL, &gaim_dbus_dispatch, NULL, NULL, NULL, NULL}; |
545 | 542 |
546 DBusError error; | 543 DBusError error; |
547 int result; | 544 int result; |
548 | 545 |
549 dbus_error_init (&error); | 546 dbus_error_init (&error); |
550 gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); | 547 gaim_dbus_connection = dbus_bus_get (DBUS_BUS_STARTER, &error); |
551 | 548 |
552 if (gaim_dbus_connection == NULL) { | 549 if (gaim_dbus_connection == NULL) { |
553 gaim_debug_error("dbus", "Failed to get connection\n"); | 550 init_error = g_strdup_printf(N_("Failed to get connection: %s"), error.message); |
554 dbus_error_free(&error); | 551 dbus_error_free(&error); |
555 return FALSE; | 552 return; |
556 } | 553 } |
557 | 554 |
558 if (!dbus_connection_register_object_path (gaim_dbus_connection, | 555 if (!dbus_connection_register_object_path (gaim_dbus_connection, |
559 DBUS_PATH_GAIM, &vtable, NULL)) | 556 DBUS_PATH_GAIM, &vtable, NULL)) |
560 { | 557 { |
561 gaim_debug_error("dbus", "Failed to get name: %s\n", error.name); | 558 init_error = g_strdup_printf(N_("Failed to get name: %s"), error.name); |
562 dbus_error_free(&error); | 559 dbus_error_free(&error); |
563 return FALSE; | 560 return; |
564 } | 561 } |
565 | 562 |
566 | 563 |
567 result = dbus_bus_request_name (gaim_dbus_connection, DBUS_SERVICE_GAIM, | 564 result = dbus_bus_request_name (gaim_dbus_connection, DBUS_SERVICE_GAIM, |
568 0, &error); | 565 0, &error); |
569 | 566 |
570 if (dbus_error_is_set (&error)) { | 567 if (dbus_error_is_set (&error)) { |
571 dbus_connection_unref(gaim_dbus_connection); | 568 dbus_connection_unref(gaim_dbus_connection); |
572 dbus_error_free(&error); | 569 dbus_error_free(&error); |
573 gaim_dbus_connection = NULL; | 570 gaim_dbus_connection = NULL; |
574 gaim_debug_error("dbus", "Failed to get serv name: %s\n", error.name); | 571 init_error = g_strdup_printf(N_("Failed to get serv name: %s"), error.name); |
575 return FALSE; | 572 return; |
576 } | 573 } |
577 | 574 |
578 dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); | 575 dbus_connection_setup_with_g_main(gaim_dbus_connection, NULL); |
579 | 576 |
580 gaim_debug_misc ("dbus", "okkk\n"); | 577 gaim_debug_misc ("dbus", "okkk\n"); |
588 gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", | 585 gaim_signal_register(gaim_dbus_get_handle(), "dbus-introspect", |
589 gaim_marshal_VOID__POINTER, NULL, 1, | 586 gaim_marshal_VOID__POINTER, NULL, 1, |
590 gaim_value_new_outgoing(GAIM_TYPE_POINTER)); | 587 gaim_value_new_outgoing(GAIM_TYPE_POINTER)); |
591 | 588 |
592 GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); | 589 GAIM_DBUS_REGISTER_BINDINGS(gaim_dbus_get_handle()); |
593 | |
594 return TRUE; | |
595 } | 590 } |
596 | 591 |
597 | 592 |
598 | 593 |
599 /**************************************************************************/ | 594 /**************************************************************************/ |
707 | 702 |
708 g_free(newname); | 703 g_free(newname); |
709 dbus_message_unref(signal); | 704 dbus_message_unref(signal); |
710 } | 705 } |
711 | 706 |
712 | 707 const char * |
713 | 708 gaim_dbus_get_init_error(void) |
714 | 709 { |
715 | 710 return init_error; |
716 | 711 } |
717 gboolean gaim_dbus_init(void) | 712 |
713 void * | |
714 gaim_dbus_get_handle(void) | |
715 { | |
716 static int handle; | |
717 | |
718 return &handle; | |
719 } | |
720 | |
721 void | |
722 gaim_dbus_init(void) | |
718 { | 723 { |
719 gaim_dbus_init_ids(); | 724 gaim_dbus_init_ids(); |
720 return gaim_dbus_dispatch_init() ; | 725 |
721 } | 726 g_free(init_error); |
722 | 727 init_error = NULL; |
723 | 728 gaim_dbus_dispatch_init(); |
729 if (init_error != NULL) | |
730 gaim_debug_error("dbus", "%s\n", init_error); | |
731 } | |
732 | |
733 void | |
734 gaim_dbus_uninit(void) | |
735 { | |
736 /* Surely we must do SOME kind of uninitialization? */ | |
737 | |
738 g_free(init_error); | |
739 init_error = NULL; | |
740 } |