[packagekit] packagekit: Branch 'master' - 5 commits

Richard Hughes hughsient at kemper.freedesktop.org
Mon Feb 18 14:22:32 PST 2008


 libpackagekit/pk-client.c          |    4 +
 libpackagekit/pk-common.c          |   29 ++++++++++
 libpackagekit/pk-common.h          |    1 
 python/packagekit/daemonBackend.py |   28 ++++++++++
 src/pk-backend-spawn.c             |   26 +++++----
 src/pk-backend.c                   |  103 ++++++++++++++++++++++++++++++++++++-
 src/pk-thread-list.c               |   24 +-------
 7 files changed, 183 insertions(+), 32 deletions(-)

New commits:
commit c9d00759d9028b9fd766ecb6b76b19185320af6f
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 18 22:19:44 2008 +0000

    detect incorrect require-restart enum types and don't trigger a valid error to make the test suite pass

diff --git a/src/pk-backend-spawn.c b/src/pk-backend-spawn.c
index 5ce5316..c33489c 100644
--- a/src/pk-backend-spawn.c
+++ b/src/pk-backend-spawn.c
@@ -273,6 +273,12 @@ pk_backend_spawn_parse_common_error (PkBackendSpawn *backend_spawn, const gchar
 			goto out;
 		}
 		restart_enum = pk_restart_enum_from_text (sections[1]);
+		if (restart_enum == PK_RESTART_ENUM_UNKNOWN) {
+			pk_backend_message (backend_spawn->priv->backend, PK_MESSAGE_ENUM_DAEMON,
+					    "Restart enum not recognised, and hence ignored: '%s'", sections[1]);
+			ret = FALSE;
+			goto out;
+		}
 		pk_backend_require_restart (backend_spawn->priv->backend, restart_enum, sections[2]);
 	} else if (pk_strequal (command, "message") == TRUE) {
 		if (size != 3) {
@@ -752,15 +758,6 @@ libst_backend_spawn (LibSelfTest *test)
 	}
 
 	/************************************************************/
-	libst_title (test, "test pk_backend_spawn_parse_common_error Error1");
-	ret = pk_backend_spawn_parse_common_error (backend_spawn, "error\ttransaction-error\tdescription text");
-	if (ret == TRUE) {
-		libst_success (test, NULL);
-	} else {
-		libst_failed (test, "did not validate correctly");
-	}
-
-	/************************************************************/
 	libst_title (test, "test pk_backend_spawn_parse_common_error failure");
 	ret = pk_backend_spawn_parse_common_error (backend_spawn, "error\tnot-present-woohoo\tdescription text");
 	if (ret == FALSE) {
@@ -787,6 +784,15 @@ libst_backend_spawn (LibSelfTest *test)
 		libst_failed (test, "did not validate correctly");
 	}
 
+	/************************************************************/
+	libst_title (test, "test pk_backend_spawn_parse_common_error RequireRestart");
+	ret = pk_backend_spawn_parse_common_error (backend_spawn, "requirerestart\tmooville\tdetails about the restart");
+	if (ret == FALSE) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "did not detect incorrect enum");
+	}
+
 	/* needed to avoid an error */
 	pk_backend_set_name (backend_spawn->priv->backend, "test_spawn");
 
@@ -855,7 +861,7 @@ libst_backend_spawn (LibSelfTest *test)
 	if (number_packages == 2) {
 		libst_success (test, NULL);
 	} else {
-		libst_failed (test, "wrong number of packages %s", number_packages);
+		libst_failed (test, "wrong number of packages %i", number_packages);
 	}
 
 	/* done */
commit eb578035f6b6400ccf725a571685db794230acb4
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 18 22:11:26 2008 +0000

    enforce that finished is send 500ms after error_code

diff --git a/src/pk-backend.c b/src/pk-backend.c
index 71fae8e..42f5ad2 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -41,7 +41,8 @@
 #include "pk-inhibit.h"
 
 #define PK_BACKEND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_BACKEND, PkBackendPrivate))
-#define PK_BACKEND_PERCENTAGE_INVALID	101
+#define PK_BACKEND_PERCENTAGE_INVALID		101
+#define PK_BACKEND_ERROR_FINISHED_TIMEOUT	500 /* ms */
 
 struct _PkBackendPrivate
 {
@@ -62,6 +63,7 @@ struct _PkBackendPrivate
 	guint			 last_subpercentage;
 	guint			 last_remaining;
 	guint			 signal_finished;
+	guint			 signal_error_timeout;
 };
 
 G_DEFINE_TYPE (PkBackend, pk_backend, G_TYPE_OBJECT)
@@ -609,6 +611,29 @@ pk_backend_repo_detail (PkBackend *backend, const gchar *repo_id,
 }
 
 /**
+ * pk_backend_finished_delay:
+ *
+ * We have to call Finished() within PK_BACKEND_ERROR_FINISHED_TIMEOUT of ErrorCode(), enforce this.
+ **/
+static gboolean
+pk_backend_error_timeout_delay_cb (gpointer data)
+{
+	PkBackend *backend = PK_BACKEND (data);
+
+	/* check we have not already finished */
+	if (backend->priv->finished == TRUE) {
+		pk_warning ("consistency error");
+		return FALSE;
+	}
+
+	/* warn the developer */
+	pk_backend_message (backend, PK_MESSAGE_ENUM_DAEMON,
+			    "ErrorCode() has to be followed with Finished()!");
+	pk_backend_finished (backend);
+	return FALSE;
+}
+
+/**
  * pk_backend_error_code:
  **/
 gboolean
@@ -633,6 +658,10 @@ pk_backend_error_code (PkBackend *backend, PkErrorCodeEnum code, const gchar *fo
 	}
 	backend->priv->set_error = TRUE;
 
+	/* we only allow a short time to send finished after error_code */
+	backend->priv->signal_error_timeout = g_timeout_add (PK_BACKEND_ERROR_FINISHED_TIMEOUT,
+							     pk_backend_error_timeout_delay_cb, backend);
+
 	/* we mark any transaction with errors as failed */
 	backend->priv->exit = PK_EXIT_ENUM_FAILED;
 
@@ -763,6 +792,12 @@ pk_backend_finished (PkBackend *backend)
 		return FALSE;
 	}
 
+	/* if we set an error code notifier, clear */
+	if (backend->priv->signal_error_timeout != 0) {
+		g_source_remove (backend->priv->signal_error_timeout);
+		backend->priv->signal_error_timeout = 0;
+	}
+
 	/* check we sent at least one status calls */
 	if (backend->priv->set_error == FALSE &&
 	    backend->priv->status == PK_STATUS_ENUM_SETUP) {
@@ -886,6 +921,11 @@ pk_backend_finalize (GObject *object)
 		pk_backend_finished_delay (backend);
 	}
 
+	/* if we set an error code notifier, clear */
+	if (backend->priv->signal_error_timeout != 0) {
+		g_source_remove (backend->priv->signal_error_timeout);
+	}
+
 	/* unlock the backend to call destroy */
 	pk_backend_unlock (backend);
 
@@ -1023,6 +1063,7 @@ pk_backend_init (PkBackend *backend)
 	backend->priv->c_tid = NULL;
 	backend->priv->locked = FALSE;
 	backend->priv->signal_finished = 0;
+	backend->priv->signal_error_timeout = 0;
 	backend->priv->during_initialize = FALSE;
 	backend->priv->time = pk_time_new ();
 	backend->priv->inhibit = pk_inhibit_new ();
@@ -1051,6 +1092,28 @@ pk_backend_new (void)
 #ifdef PK_BUILD_TESTS
 #include <libselftest.h>
 
+static guint number_messages = 0;
+static GMainLoop *loop;
+
+/**
+ * pk_backend_test_message_cb:
+ **/
+static void
+pk_backend_test_message_cb (PkBackend *backend, PkMessageEnum message, const gchar *details, gpointer data)
+{
+	pk_debug ("details=%s", details);
+	number_messages++;
+}
+
+/**
+ * pk_backend_test_finished_cb:
+ **/
+static void
+pk_backend_test_finished_cb (PkBackend *backend, PkExitEnum exit, gpointer data)
+{
+	g_main_loop_quit (loop);
+}
+
 void
 libst_backend (LibSelfTest *test)
 {
@@ -1058,6 +1121,8 @@ libst_backend (LibSelfTest *test)
 	const gchar *text;
 	gboolean ret;
 
+	loop = g_main_loop_new (NULL, FALSE);
+
 	if (libst_start (test, "PkBackend", CLASS_AUTO) == FALSE) {
 		return;
 	}
@@ -1071,6 +1136,9 @@ libst_backend (LibSelfTest *test)
 		libst_failed (test, NULL);
 	}
 
+	g_signal_connect (backend, "message", G_CALLBACK (pk_backend_test_message_cb), NULL);
+	g_signal_connect (backend, "finished", G_CALLBACK (pk_backend_test_finished_cb), NULL);
+
 	/************************************************************/
 	libst_title (test, "get backend name");
 	text = pk_backend_get_name (backend);
@@ -1168,6 +1236,39 @@ libst_backend (LibSelfTest *test)
 		libst_failed (test, "we did not clear finish!");
 	}
 
+	pk_backend_lock (backend);
+
+	/************************************************************/
+	libst_title (test, "check we enforce finished after error_code");
+	pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error");
+
+	/* wait for finished */
+	g_main_loop_run (loop);
+
+	if (number_messages == 1) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "we messaged %i times!", number_messages);
+	}
+
+	/* reset */
+	pk_backend_reset (backend);
+	number_messages = 0;
+
+	/************************************************************/
+	libst_title (test, "check we enforce finished after two error_codes");
+	pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error1");
+	pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error2");
+
+	/* wait for finished */
+	g_main_loop_run (loop);
+
+	if (number_messages == 2) {
+		libst_success (test, NULL);
+	} else {
+		libst_failed (test, "we messaged %i times!", number_messages);
+	}
+
 	g_object_unref (backend);
 
 	libst_end (test);
commit 156b9fad33b6e7752b50ab4eb6f88f03c3873cf4
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 18 21:55:26 2008 +0000

    use a new function pk_delay_yield to avoid code duplication

diff --git a/libpackagekit/pk-common.c b/libpackagekit/pk-common.c
index 6752123..9286c3a 100644
--- a/libpackagekit/pk-common.c
+++ b/libpackagekit/pk-common.c
@@ -557,6 +557,33 @@ pk_strpad_extra (const gchar *data, guint length, guint *extra)
 }
 
 /**
+ * pk_delay_yield:
+ * @delay: the desired delay in seconds
+ *
+ * Return value: success
+ **/
+gboolean
+pk_delay_yield (gfloat delay)
+{
+	GTimer *timer;
+	gdouble elapsed;
+	guint count = 0;
+
+	pk_debug ("started task");
+	timer = g_timer_new ();
+	do {
+		g_usleep (10);
+		g_thread_yield ();
+		elapsed = g_timer_elapsed (timer, NULL);
+		if (++count % 10000 == 0) {
+			pk_debug ("elapsed %.2f", elapsed);
+		}
+	} while (elapsed < delay);
+	g_timer_destroy (timer);
+	return TRUE;
+}
+
+/**
  * pk_strbuild_va:
  * @first_element: The first string item, or NULL
  * @args: the va_list
@@ -640,6 +667,8 @@ libst_common (LibSelfTest *test)
 		return;
 	}
 
+	pk_delay_yield (2.0);
+
 	/************************************************************
 	 ****************        build var args        **************
 	 ************************************************************/
diff --git a/libpackagekit/pk-common.h b/libpackagekit/pk-common.h
index 6433f6b..fce8f6a 100644
--- a/libpackagekit/pk-common.h
+++ b/libpackagekit/pk-common.h
@@ -75,6 +75,7 @@ gboolean	 pk_strcmp_sections			(const gchar	*id1,
 gboolean	 pk_filter_check			(const gchar	*filter);
 gchar		*pk_iso8601_present			(void);
 guint		 pk_iso8601_difference			(const gchar	*isodate);
+gboolean	 pk_delay_yield				(gfloat		 delay);
 
 G_END_DECLS
 
diff --git a/src/pk-thread-list.c b/src/pk-thread-list.c
index 2edc109..135255a 100644
--- a/src/pk-thread-list.c
+++ b/src/pk-thread-list.c
@@ -36,6 +36,7 @@
 
 #include <glib/gi18n.h>
 #include "pk-debug.h"
+#include "pk-common.h"
 #include "pk-thread-list.h"
 
 static void     pk_thread_list_class_init	(PkThreadListClass *klass);
@@ -220,22 +221,12 @@ gboolean done_func2 = FALSE;
 static gboolean
 test_func1 (PkThreadList *tlist, gpointer data)
 {
-	GTimer *timer;
-	gdouble elapsed;
-
 	if (tlist != GINT_TO_POINTER(0x01) || data != GINT_TO_POINTER(0x02)) {
 		pk_debug ("WRONG PARAMS (%p, %p)", tlist, data);
 		return FALSE;
 	}
 	pk_debug ("started task (%p,%p)", tlist, data);
-	timer = g_timer_new ();
-	do {
-		g_usleep (1000*100);
-		g_thread_yield ();
-		elapsed = g_timer_elapsed (timer, NULL);
-		pk_debug ("elapsed task (%p,%p) = %f", tlist, data, elapsed);
-	} while (elapsed < 2.0);
-	g_timer_destroy (timer);
+	pk_delay_yield (2.0);
 	pk_debug ("exited task (%p,%p)", tlist, data);
 	done_func1 = TRUE;
 	return TRUE;
@@ -244,21 +235,12 @@ test_func1 (PkThreadList *tlist, gpointer data)
 static gboolean
 test_func2 (PkThreadList *tlist, gpointer data)
 {
-	GTimer *timer;
-	gdouble elapsed;
-
 	if (tlist != GINT_TO_POINTER(0x02) || data != GINT_TO_POINTER(0x03)) {
 		pk_debug ("WRONG PARAMS (%p, %p)", tlist, data);
 		return FALSE;
 	}
 	pk_debug ("started task (%p,%p)", tlist, data);
-	timer = g_timer_new ();
-	do {
-		g_usleep (1000*100);
-		elapsed = g_timer_elapsed (timer, NULL);
-		pk_debug ("elapsed task (%p,%p) = %f", tlist, data, elapsed);
-	} while (elapsed < 1.0);
-	g_timer_destroy (timer);
+	pk_delay_yield (1.0);
 	pk_debug ("exited task (%p,%p)", tlist, data);
 	done_func2 = TRUE;
 	return TRUE;
commit 1a36fcc5f2313a7d51181d8dd41f8dea0c27984f
Author: Robin Norwood <rnorwood at redhat.com>
Date:   Mon Feb 18 13:57:23 2008 -0500

    Add some missing signals to daemonBackend.py.

diff --git a/python/packagekit/daemonBackend.py b/python/packagekit/daemonBackend.py
index 733335e..404ee29 100644
--- a/python/packagekit/daemonBackend.py
+++ b/python/packagekit/daemonBackend.py
@@ -137,6 +137,34 @@ class PackageKitBaseBackend(dbus.service.Object):
         '''
         print  "MetaData (%s, %s)" % (typ,fname)
 
+    @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
+                         signature='ss')
+    def RequireRestart(self,type,details):
+        '''
+        send 'require-restart' signal:
+        @param type:   The level of restart required (system,application,session)
+        @param details:  Optional details about the restart
+        '''
+        print  "RestartRequired (%s, %s)" % (type,details)
+
+    @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
+                         signature='ss')
+    def Message(self,type,details):
+        '''
+        send 'message' signal:
+        @param type:   The type of message (warning,notice,daemon)
+        @param details:  Required details about the message
+        '''
+        print  "Message (%s, %s)" % (type,details)
+
+    @dbus.service.signal(dbus_interface=PACKAGEKIT_DBUS_INTERFACE,
+                         signature='')
+    def UpdatesChanged(self,typ,fname):
+        '''
+        send 'updates-changed' signal:
+        '''
+        print  "UpdatesChanged ()"
+
 
 #
 # Methods ( client -> engine -> backend )
commit 1cca058cbfe242f492c0374b20797f6e994444bf
Author: Richard Hughes <richard at hughsie.com>
Date:   Mon Feb 18 00:14:30 2008 +0000

    clear the has when we reset PkClient

diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index bfe9ae3..baac616 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -360,6 +360,10 @@ pk_client_reset (PkClient *client)
 	client->priv->last_status = PK_STATUS_ENUM_UNKNOWN;
 	client->priv->role = PK_ROLE_ENUM_UNKNOWN;
 	client->priv->is_finished = FALSE;
+
+	/* clear hash */
+	g_hash_table_remove_all (client->priv->hash);
+
 	pk_package_list_clear (client->priv->package_list);
 	return TRUE;
 }



More information about the PackageKit mailing list