aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-service-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'libindicator/indicator-service-manager.c')
-rw-r--r--libindicator/indicator-service-manager.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c
index 13c9015..a3680c4 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;
+ guint this_service_version;
DBusGConnection * bus;
};
@@ -34,10 +35,12 @@ static guint signals[LAST_SIGNAL] = { 0 };
enum {
PROP_0,
PROP_NAME,
+ PROP_VERSION
};
/* The strings so that they can be slowly looked up. */
#define PROP_NAME_S "name"
+#define PROP_VERSION_S "version"
/* GObject Stuff */
#define INDICATOR_SERVICE_MANAGER_GET_PRIVATE(o) \
@@ -52,7 +55,6 @@ 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);
@@ -93,6 +95,12 @@ indicator_service_manager_class_init (IndicatorServiceManagerClass *klass)
"This is the name that should be used to start a service.",
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property(object_class, PROP_VERSION,
+ g_param_spec_uint(PROP_VERSION_S,
+ "The version of the service that we're expecting.",
+ "A number to check and reject a service if it gives us the wrong number. This should match across the manager and the service",
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
return;
}
@@ -107,13 +115,14 @@ indicator_service_manager_init (IndicatorServiceManager *self)
priv->dbus_proxy = NULL;
priv->service_proxy = NULL;
priv->connected = FALSE;
+ priv->this_service_version = 0;
priv->bus = NULL;
/* Start talkin' dbus */
GError * error = NULL;
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("Unable to get session bus for manager: %s", error->message);
g_error_free(error);
return;
}
@@ -153,7 +162,7 @@ indicator_service_manager_dispose (GObject *object)
/* 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);
+ dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID);
}
/* Destory our service proxy, we won't need it. */
@@ -205,6 +214,10 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec
}
break;
/* *********************** */
+ case PROP_VERSION:
+ priv->this_service_version = g_value_get_uint(value);
+ break;
+ /* *********************** */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -232,6 +245,10 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe
}
break;
/* *********************** */
+ case PROP_VERSION:
+ g_value_set_uint(value, priv->this_service_version);
+ break;
+ /* *********************** */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -241,13 +258,7 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe
}
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)
+watch_cb (DBusGProxy * proxy, guint service_api_version, guint this_service_version, GError * error, gpointer user_data)
{
IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data);
@@ -257,9 +268,15 @@ watch_cb (DBusGProxy * proxy, gint service_version, GError * error, gpointer use
return;
}
- 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);
+ if (service_api_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_api_version);
+ dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID);
+ return;
+ }
+
+ if (this_service_version != priv->this_service_version) {
+ g_warning("Service is using a API version than the manager. Expecting %d and got %d.", priv->this_service_version, this_service_version);
+ dbus_g_proxy_call_no_reply(priv->service_proxy, "UnWatch", G_TYPE_INVALID);
return;
}
@@ -292,6 +309,7 @@ start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer use
INDICATOR_SERVICE_OBJECT,
INDICATOR_SERVICE_INTERFACE,
&error);
+ g_object_add_weak_pointer(G_OBJECT(priv->service_proxy), (gpointer *)&(priv->service_proxy));
org_ayatana_indicator_service_watch_async(priv->service_proxy,
watch_cb,
@@ -347,6 +365,17 @@ indicator_service_manager_new (gchar * dbus_name)
return INDICATOR_SERVICE_MANAGER(obj);
}
+IndicatorServiceManager *
+indicator_service_manager_new_version (gchar * dbus_name, guint version)
+{
+ GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE,
+ PROP_NAME_S, dbus_name,
+ PROP_VERSION_S, version,
+ NULL);
+
+ return INDICATOR_SERVICE_MANAGER(obj);
+}
+
gboolean
indicator_service_manager_connected (IndicatorServiceManager * sm)
{