diff options
Diffstat (limited to 'libindicator')
-rw-r--r-- | libindicator/Makefile.am | 1 | ||||
-rw-r--r-- | libindicator/indicator-service-manager.c | 43 | ||||
-rw-r--r-- | libindicator/indicator-service-manager.h | 2 | ||||
-rw-r--r-- | libindicator/indicator-service.c | 45 | ||||
-rw-r--r-- | libindicator/indicator-service.h | 4 | ||||
-rw-r--r-- | libindicator/indicator-service.xml | 3 |
6 files changed, 91 insertions, 7 deletions
diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 717d60f..6d5c627 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -26,6 +26,7 @@ libindicator_la_SOURCES = \ libindicator_la_CFLAGS = \ $(LIBINDICATOR_CFLAGS) \ + -DG_LOG_DOMAIN=\"libindicator\" \ -Wall -Werror libindicator_la_LIBADD = \ diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 13c9015..a3f76b2 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) \ @@ -93,6 +96,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 +116,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; } @@ -205,6 +215,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 +246,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; @@ -247,7 +265,7 @@ unwatch_cb (DBusGProxy *proxy, GError *error, gpointer userdata) } 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,8 +275,14 @@ 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); + 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); + org_ayatana_indicator_service_un_watch_async(priv->service_proxy, unwatch_cb, NULL); + 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); org_ayatana_indicator_service_un_watch_async(priv->service_proxy, unwatch_cb, NULL); return; } @@ -347,6 +371,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) { diff --git a/libindicator/indicator-service-manager.h b/libindicator/indicator-service-manager.h index 127d56b..65a93ea 100644 --- a/libindicator/indicator-service-manager.h +++ b/libindicator/indicator-service-manager.h @@ -54,6 +54,8 @@ struct _IndicatorServiceManager { GType indicator_service_manager_get_type (void); IndicatorServiceManager * indicator_service_manager_new (gchar * dbus_name); +IndicatorServiceManager * indicator_service_manager_new_version (gchar * dbus_name, + guint version); gboolean indicator_service_manager_connected (IndicatorServiceManager * sm); void indicator_service_manager_set_refresh (IndicatorServiceManager * sm, guint time_in_ms); diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 5fb939d..89842bb 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -21,6 +21,7 @@ struct _IndicatorServicePrivate { DBusGProxy * dbus_proxy; guint timeout; GList * watchers; + guint this_service_version; }; /* Signals Stuff */ @@ -37,10 +38,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_GET_PRIVATE(o) \ @@ -79,6 +82,12 @@ indicator_service_class_init (IndicatorServiceClass *klass) "This is the name that should be used on DBus for this 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 implementing.", + "A number to represent the version of the other APIs the service provides. This should match across the manager and the service", + 0, G_MAXUINT, 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); /* Signals */ @@ -114,6 +123,7 @@ indicator_service_init (IndicatorService *self) priv->dbus_proxy = NULL; priv->timeout = 0; priv->watchers = NULL; + priv->this_service_version = 0; /* Start talkin' dbus */ GError * error = NULL; @@ -214,6 +224,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; @@ -241,6 +255,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; @@ -306,7 +324,7 @@ _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocati priv->timeout = 0; } - dbus_g_method_return(method, INDICATOR_SERVICE_VERSION); + dbus_g_method_return(method, INDICATOR_SERVICE_VERSION, priv->this_service_version); return TRUE; } @@ -374,3 +392,28 @@ indicator_service_new (gchar * name) return INDICATOR_SERVICE(obj); } + +/** + indicator_service_new_version: + @name: The name for the service on dbus + @version: The version of the other interfaces provide + by the service. + + This function creates the service on DBus and tries to + get a well-known name specified in @name. If the name + can't be estabilished then the #IndicatorService::shutdown + signal will be sent. + + Return value: A brand new #IndicatorService object or #NULL + if there is an error. +*/ +IndicatorService * +indicator_service_new_version (gchar * name, guint version) +{ + GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE, + PROP_NAME_S, name, + PROP_VERSION_S, version, + NULL); + + return INDICATOR_SERVICE(obj); +} diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h index b47a91a..59c5385 100644 --- a/libindicator/indicator-service.h +++ b/libindicator/indicator-service.h @@ -53,7 +53,9 @@ struct _IndicatorService { GType indicator_service_get_type (void); -IndicatorService * indicator_service_new (gchar * name); +IndicatorService * indicator_service_new (gchar * name); +IndicatorService * indicator_service_new_version (gchar * name, + guint version); G_END_DECLS diff --git a/libindicator/indicator-service.xml b/libindicator/indicator-service.xml index 8b389e2..6bd7d80 100644 --- a/libindicator/indicator-service.xml +++ b/libindicator/indicator-service.xml @@ -7,7 +7,8 @@ <!-- Methods --> <method name="Watch"> <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> - <arg type="i" name="version" direction="out" /> + <arg type="u" name="version" direction="out" /> + <arg type="u" name="service_version" direction="out" /> </method> <method name="UnWatch"> <annotation name="org.freedesktop.DBus.GLib.Async" value="true" /> |