From c21c6e9a3e204bccae7b9a30c56845cbc45661ff Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Mon, 3 Dec 2012 15:42:46 +0000 Subject: Stop using IndicatorService This doesn't require every consumer ("panel") to know about IndicatorServiceManager's protocol. Also, it ensures that objects are exported before the name is acquired, getting rid of a race condition (when a consumer tries to access objects in NameAppeared before they're exported). This patch also adds a --replace command line option -- replacing the INDICATOR_SERVICE_REPLACE_MODE environment variable. --- src/messages-service.c | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'src/messages-service.c') diff --git a/src/messages-service.c b/src/messages-service.c index 61e786f..d10e98a 100644 --- a/src/messages-service.c +++ b/src/messages-service.c @@ -23,7 +23,6 @@ with this program. If not, see . #include #include -#include #include #include @@ -44,15 +43,6 @@ static GMenu *toplevel_menu; static ImPhoneMenu *menu; static GSettings *settings; -static void -service_shutdown (IndicatorService * service, gpointer user_data) -{ - GMainLoop *mainloop = user_data; - - g_warning("Shutting down service!"); - g_main_loop_quit(mainloop); -} - static void register_application (IndicatorMessagesService *service, GDBusMethodInvocation *invocation, @@ -87,20 +77,12 @@ unregister_application (IndicatorMessagesService *service, } static void -got_bus (GObject *object, - GAsyncResult * res, - gpointer user_data) +on_bus_acquired (GDBusConnection *bus, + const gchar *name, + gpointer user_data) { - GDBusConnection *bus; GError *error = NULL; - bus = g_bus_get_finish (res, &error); - if (!bus) { - g_warning ("unable to connect to the session bus: %s", error->message); - g_error_free (error); - return; - } - g_dbus_connection_export_action_group (bus, INDICATOR_MESSAGES_DBUS_OBJECT, im_application_list_get_action_group (applications), &error); @@ -130,22 +112,28 @@ got_bus (GObject *object, g_object_unref (bus); } +static void +on_name_lost (GDBusConnection *bus, + const gchar *name, + gpointer user_data) +{ + GMainLoop *mainloop = user_data; + + g_main_loop_quit (mainloop); +} + int main (int argc, char ** argv) { GMainLoop * mainloop = NULL; - IndicatorService * service = NULL; GMenuItem *root; + GBusNameOwnerFlags flags; /* Glib init */ g_type_init(); mainloop = g_main_loop_new (NULL, FALSE); - /* Create the Indicator Service interface */ - service = indicator_service_new_version(INDICATOR_MESSAGES_DBUS_NAME, 1); - g_signal_connect(service, INDICATOR_SERVICE_SIGNAL_SHUTDOWN, G_CALLBACK(service_shutdown), mainloop); - /* Setting up i18n and gettext. Apparently, we need all of these. */ setlocale (LC_ALL, ""); @@ -155,7 +143,12 @@ main (int argc, char ** argv) /* Bring up the service DBus interface */ messages_service = indicator_messages_service_skeleton_new (); - g_bus_get (G_BUS_TYPE_SESSION, NULL, got_bus, NULL); + flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; + if (argc >= 2 && g_str_equal (argv[1], "--replace")) + flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; + + g_bus_own_name (G_BUS_TYPE_SESSION, "com.canonical.indicator.messages", flags, + on_bus_acquired, NULL, on_name_lost, mainloop, NULL); g_signal_connect (messages_service, "handle-register-application", G_CALLBACK (register_application), NULL); -- cgit v1.2.3