diff options
-rw-r--r-- | .bzrignore | 6 | ||||
-rw-r--r-- | debian/changelog | 6 | ||||
-rw-r--r-- | libindicator/Makefile.am | 1 | ||||
-rw-r--r-- | libindicator/indicator-service-manager.c | 55 | ||||
-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 | ||||
-rw-r--r-- | tests/Makefile.am | 80 | ||||
-rw-r--r-- | tests/service-version-bad-service.c | 47 | ||||
-rw-r--r-- | tests/service-version-bad.service.in | 3 | ||||
-rw-r--r-- | tests/service-version-good-service.c | 47 | ||||
-rw-r--r-- | tests/service-version-good.service.in | 3 | ||||
-rw-r--r-- | tests/service-version-manager.c | 64 | ||||
-rw-r--r-- | tests/service-version-values.h | 4 |
15 files changed, 347 insertions, 23 deletions
@@ -135,5 +135,11 @@ tests/service-manager-connect-tester tests/session.conf tests/service-manager-connect.service tools/indicator-loader +tests/service-version-bad-service +tests/service-version-bad.service +tests/service-version-good-service +tests/service-version-good.service +tests/service-version-manager +tests/service-version-tester tests/service-manager-connect-nostart-tester tests/service-manager-nostart-connect diff --git a/debian/changelog b/debian/changelog index 86cd05b..64e94f0 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libindicator (0.3.0~dev-0ubuntu1~ppa9) UNRELEASED; urgency=low + + * Adding in a service API version number. + + -- Ted Gould <ted@ubuntu.com> Mon, 07 Dec 2009 13:10:14 -0600 + libindicator (0.3.0~dev-0ubuntu1~ppa8) karmic; urgency=low * autogen.sh fix. (LP: #491907) 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..b4d5915 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 different 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) { 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" /> diff --git a/tests/Makefile.am b/tests/Makefile.am index 09a227d..7fcccb6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,13 +1,7 @@ TESTS = DISTCLEANFILES = -check_PROGRAMS = \ - test-loader \ - service-manager-no-connect \ - service-manager-connect \ - service-manager-connect-service \ - service-manager-nostart-connect \ - service-shutdown-timeout +check_PROGRAMS = lib_LTLIBRARIES = \ libdummy-indicator-blank.la \ @@ -21,6 +15,8 @@ DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.c # Test Loader ############################# +check_PROGRAMS += test-loader + test_loader_SOURCES = \ test-loader.c @@ -118,6 +114,8 @@ libdummy_indicator_simple_la_LDFLAGS = \ # Service Shutdown Timeout ############################# +check_PROGRAMS += service-shutdown-timeout + service_shutdown_timeout_SOURCES = \ service-shutdown-timeout.c @@ -141,6 +139,8 @@ DISTCLEANFILES += service-shutdown-timeout-tester # Service Manager No Connect ############################# +check_PROGRAMS += service-manager-no-connect + service_manager_no_connect_SOURCES = \ service-manager-no-connect.c @@ -170,6 +170,8 @@ session.conf: $(srcdir)/session.conf.in Makefile.am service-manager-connect.service: $(srcdir)/service-manager-connect.service.in Makefile.am sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ +check_PROGRAMS += service-manager-connect + service_manager_connect_SOURCES = \ service-manager-connect.c @@ -181,6 +183,8 @@ service_manager_connect_LDADD = \ $(LIBINDICATOR_LIBS) \ $(top_builddir)/libindicator/.libs/libindicator.a +check_PROGRAMS += service-manager-connect-service + service_manager_connect_service_SOURCES = \ service-manager-connect-service.c @@ -201,9 +205,71 @@ TESTS += service-manager-connect-tester DISTCLEANFILES += service-manager-connect-tester session.conf service-manager-connect.service ############################# +# Service Versions +############################# + +service-version-good.service: $(srcdir)/service-version-good.service.in Makefile.am + sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ + +service-version-bad.service: $(srcdir)/service-version-bad.service.in Makefile.am + sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ + +check_PROGRAMS += service-version-manager + +service_version_manager_SOURCES = \ + service-version-values.h \ + service-version-manager.c + +service_version_manager_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_version_manager_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +check_PROGRAMS += service-version-bad-service + +service_version_bad_service_SOURCES = \ + service-version-values.h \ + service-version-bad-service.c + +service_version_bad_service_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_version_bad_service_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +check_PROGRAMS += service-version-good-service + +service_version_good_service_SOURCES = \ + service-version-values.h \ + service-version-good-service.c + +service_version_good_service_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_version_good_service_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-version-tester: service-version-manager service-version-bad-service service-version-good-service session.conf service-version-bad.service service-version-good.service Makefile.am + @echo "#!/bin/sh" > $@ + @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-version-manager >> $@ + @chmod +x $@ + +TESTS += service-version-tester +DISTCLEANFILES += service-version-tester service-version-bad.service service-version-good.service + +############################# # Service Manager Shutdown ############################# +check_PROGRAMS += service-manager-nostart-connect + service_manager_nostart_connect_SOURCES = \ service-manager-nostart-connect.c diff --git a/tests/service-version-bad-service.c b/tests/service-version-bad-service.c new file mode 100644 index 0000000..6057e74 --- /dev/null +++ b/tests/service-version-bad-service.c @@ -0,0 +1,47 @@ + +#include <glib.h> +#include "libindicator/indicator-service.h" +#include "service-version-values.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_debug("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_debug("Shutdown"); + passed = TRUE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new_version("org.ayatana.version.bad", SERVICE_VERSION_BAD); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-version-bad.service.in b/tests/service-version-bad.service.in new file mode 100644 index 0000000..1e763eb --- /dev/null +++ b/tests/service-version-bad.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.ayatana.version.bad +Exec=@builddir@/service-version-bad-service diff --git a/tests/service-version-good-service.c b/tests/service-version-good-service.c new file mode 100644 index 0000000..bcfe46d --- /dev/null +++ b/tests/service-version-good-service.c @@ -0,0 +1,47 @@ + +#include <glib.h> +#include "libindicator/indicator-service.h" +#include "service-version-values.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_debug("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_debug("Shutdown"); + passed = TRUE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-version-good.service.in b/tests/service-version-good.service.in new file mode 100644 index 0000000..c57a04f --- /dev/null +++ b/tests/service-version-good.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.ayatana.version.good +Exec=@builddir@/service-version-good-service diff --git a/tests/service-version-manager.c b/tests/service-version-manager.c new file mode 100644 index 0000000..aedc0ed --- /dev/null +++ b/tests/service-version-manager.c @@ -0,0 +1,64 @@ + +#include <glib.h> +#include "libindicator/indicator-service-manager.h" +#include "service-version-values.h" + +static GMainLoop * mainloop = NULL; +static gboolean con_good = FALSE; +static gboolean con_bad = FALSE; + +gboolean +timeout (gpointer data) +{ + g_debug("Timeout."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +connection_bad (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) +{ + if (!connected) return; + g_debug("Connection From Bad!"); + con_bad = TRUE; + return; +} + +void +connection_good (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) +{ + if (!connected) return; + g_debug("Connection From Good."); + con_good = TRUE; + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + g_print("Manager: DBUS_SESSION_BUS_ADDRESS = %s\n", g_getenv("DBUS_SESSION_BUS_ADDRESS")); + + IndicatorServiceManager * goodis = indicator_service_manager_new_version("org.ayatana.version.good", SERVICE_VERSION_GOOD); + g_signal_connect(G_OBJECT(goodis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_good), NULL); + + IndicatorServiceManager * badis = indicator_service_manager_new_version("org.ayatana.version.bad", SERVICE_VERSION_GOOD); + g_signal_connect(G_OBJECT(badis), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_bad), NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_object_unref(goodis); + g_object_unref(badis); + + g_debug("Quiting"); + if (con_good && !con_bad) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-version-values.h b/tests/service-version-values.h new file mode 100644 index 0000000..e9fb087 --- /dev/null +++ b/tests/service-version-values.h @@ -0,0 +1,4 @@ + +#define SERVICE_VERSION_GOOD 1342 +#define SERVICE_VERSION_BAD 543 + |