aboutsummaryrefslogtreecommitdiff
path: root/src/messages-service.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2012-12-03 15:42:46 +0000
committerLars Uebernickel <lars.uebernickel@canonical.com>2012-12-03 15:42:46 +0000
commitc21c6e9a3e204bccae7b9a30c56845cbc45661ff (patch)
tree2c12a39e8a984157f8fe5b0761e862e7a15ec49d /src/messages-service.c
parenta128285efe183232aa3a5a6058cd9983fc7375c3 (diff)
downloadayatana-indicator-messages-c21c6e9a3e204bccae7b9a30c56845cbc45661ff.tar.gz
ayatana-indicator-messages-c21c6e9a3e204bccae7b9a30c56845cbc45661ff.tar.bz2
ayatana-indicator-messages-c21c6e9a3e204bccae7b9a30c56845cbc45661ff.zip
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.
Diffstat (limited to 'src/messages-service.c')
-rw-r--r--src/messages-service.c47
1 files changed, 20 insertions, 27 deletions
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 <http://www.gnu.org/licenses/>.
#include <config.h>
#include <locale.h>
-#include <libindicator/indicator-service.h>
#include <gio/gio.h>
#include <glib/gi18n.h>
@@ -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);