From 088eff44dd923a80d2bc357be72b9ace0c97d06e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Dec 2009 10:19:11 -0600 Subject: When destroying the object we tell the watched service that we're not watching it. --- libindicator/indicator-service-manager.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 4eaed23..956eb90 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -51,6 +51,7 @@ static void indicator_service_manager_finalize (GObject *object); static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void start_service (IndicatorServiceManager * service); +static void unwatch_cb (DBusGProxy *proxy, GError *error, gpointer userdata); G_DEFINE_TYPE (IndicatorServiceManager, indicator_service_manager, G_TYPE_OBJECT); @@ -147,6 +148,12 @@ indicator_service_manager_dispose (GObject *object) priv->dbus_proxy = NULL; } + /* If we have a proxy, tell it we're shutting down. Just + to be polite about it. */ + if (priv->service_proxy != NULL) { + org_ayatana_indicator_service_un_watch_async(priv->service_proxy, unwatch_cb, NULL); + } + /* Destory our service proxy, we won't need it. */ if (priv->service_proxy != NULL) { g_object_unref(G_OBJECT(priv->service_proxy)); @@ -231,6 +238,12 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe return; } +static void +unwatch_cb (DBusGProxy *proxy, GError *error, gpointer userdata) +{ + return; +} + static void watch_cb (DBusGProxy * proxy, gint service_version, GError * error, gpointer user_data) { -- cgit v1.2.3 From 824d1e8bc5bbc240140d6c2cea7246308c563fd8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Dec 2009 10:20:36 -0600 Subject: Unwatching if we have mismatched version. --- libindicator/indicator-service-manager.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 956eb90..d7e54bd 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -257,6 +257,7 @@ watch_cb (DBusGProxy * proxy, gint service_version, GError * error, gpointer use if (service_version != INDICATOR_SERVICE_VERSION) { g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, service_version); + org_ayatana_indicator_service_un_watch_async(priv->service_proxy, unwatch_cb, NULL); return; } -- cgit v1.2.3 From 4ba1af342c78aefdf5dc163163c80de6b25f85ec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Dec 2009 13:44:30 -0600 Subject: Trying to get a proxy before starting the service every time. If it exists, let's use it. --- libindicator/indicator-service-manager.c | 37 +++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index d7e54bd..4dcc200 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -308,16 +308,43 @@ start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer use static void start_service (IndicatorServiceManager * service) { + GError * error = NULL; IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(service); g_return_if_fail(priv->dbus_proxy != NULL); g_return_if_fail(priv->name != NULL); - org_freedesktop_DBus_start_service_by_name_async (priv->dbus_proxy, - priv->name, - 0, - start_service_cb, - service); + /* Check to see if we can get a proxy to it first. */ + DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + if (error != NULL) { + g_error("Unable to get session bus: %s", error->message); + g_error_free(error); + return; + } + + /* Tries to get the proxy first. */ + priv->service_proxy = dbus_g_proxy_new_for_name_owner(session_bus, + priv->name, + INDICATOR_SERVICE_OBJECT, + INDICATOR_SERVICE_INTERFACE, + &error); + + if (error != NULL) { + /* We don't care about the error, just start the service anyway. */ + g_error_free(error); + org_freedesktop_DBus_start_service_by_name_async (priv->dbus_proxy, + priv->name, + 0, + start_service_cb, + service); + } else { + /* If we got a proxy just because we're good people then + we need to call watch on it just like 'start_service_cb' + does. */ + org_ayatana_indicator_service_watch_async(priv->service_proxy, + watch_cb, + service); + } return; } -- cgit v1.2.3 From b7864d8626cd5bdde3fe94f2086d9a1cfdb66a49 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 1 Dec 2009 16:07:26 -0600 Subject: Only getting the bus once. --- libindicator/indicator-service-manager.c | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 4dcc200..13c9015 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -16,6 +16,7 @@ struct _IndicatorServiceManagerPrivate { DBusGProxy * dbus_proxy; DBusGProxy * service_proxy; gboolean connected; + DBusGConnection * bus; }; /* Signals Stuff */ @@ -106,17 +107,18 @@ indicator_service_manager_init (IndicatorServiceManager *self) priv->dbus_proxy = NULL; priv->service_proxy = NULL; priv->connected = FALSE; + priv->bus = NULL; /* Start talkin' dbus */ GError * error = NULL; - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + priv->bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); if (error != NULL) { g_error("Unable to get session bus: %s", error->message); g_error_free(error); return; } - priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(session_bus, + priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -285,14 +287,7 @@ start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer use } /* Woot! it's running. Let's do it some more. */ - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error("Unable to get session bus: %s", error->message); - g_error_free(error); - return; - } - - priv->service_proxy = dbus_g_proxy_new_for_name_owner(session_bus, + priv->service_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, priv->name, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE, @@ -315,15 +310,7 @@ start_service (IndicatorServiceManager * service) g_return_if_fail(priv->name != NULL); /* Check to see if we can get a proxy to it first. */ - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - if (error != NULL) { - g_error("Unable to get session bus: %s", error->message); - g_error_free(error); - return; - } - - /* Tries to get the proxy first. */ - priv->service_proxy = dbus_g_proxy_new_for_name_owner(session_bus, + priv->service_proxy = dbus_g_proxy_new_for_name_owner(priv->bus, priv->name, INDICATOR_SERVICE_OBJECT, INDICATOR_SERVICE_INTERFACE, -- cgit v1.2.3