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

Richard Hughes hughsient at kemper.freedesktop.org
Tue Sep 4 11:41:06 PDT 2007


 helpers/BACKENDS                |    2 
 helpers/conary/conaryBackend.py |   46 +++--
 src/pk-engine.c                 |  341 ++++++++++++++++++++++++++++------------
 src/pk-task-common.c            |   25 --
 src/pk-task-common.h            |    3 
 src/pk-task-conary.c            |   23 +-
 src/pk-task.h                   |    1 
 7 files changed, 290 insertions(+), 151 deletions(-)

New commits:
diff-tree 1fe19bdb1342d43b6cbf5bb581c6c484a993ed58 (from 25a0c0c9e29ac2e44737998346b81316847f8043)
Author: Richard Hughes <richard at hughsie.com>
Date:   Tue Sep 4 19:40:51 2007 +0100

    move the job id getting and setting out of the task, the task should be abstract and not know about external implimentation

diff --git a/src/pk-engine.c b/src/pk-engine.c
index 3415e78..6842dcb 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -78,6 +78,11 @@ enum {
 	PK_ENGINE_LAST_SIGNAL
 };
 
+typedef struct {
+	guint		 job;
+	PkTask		*task;
+} PkEngineMap;
+
 static guint	     signals [PK_ENGINE_LAST_SIGNAL] = { 0, };
 
 G_DEFINE_TYPE (PkEngine, pk_engine, G_TYPE_OBJECT)
@@ -140,9 +145,8 @@ pk_engine_create_job_list (PkEngine *eng
 {
 	guint i;
 	guint length;
-	guint job;
-	PkTask *task;
 	GArray *job_list;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -153,23 +157,21 @@ pk_engine_create_job_list (PkEngine *eng
 	/* find all the jobs in progress */
 	length = engine->priv->array->len;
 	for (i=0; i<length; i++) {
-		task = (PkTask *) g_ptr_array_index (engine->priv->array, i);
-		job = pk_task_get_job (task);
-		job_list = g_array_append_val (job_list, job);
+		map = (PkEngineMap *) g_ptr_array_index (engine->priv->array, i);
+		job_list = g_array_append_val (job_list, map->job);
 	}
 	return job_list;
 }
 
 /**
- * pk_get_task_from_job:
+ * pk_get_map_from_job:
  **/
-static PkTask *
-pk_get_task_from_job (PkEngine *engine, guint job)
+static PkEngineMap *
+pk_get_map_from_job (PkEngine *engine, guint job)
 {
 	guint i;
 	guint length;
-	guint job_tmp;
-	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, NULL);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), NULL);
@@ -177,15 +179,37 @@ pk_get_task_from_job (PkEngine *engine, 
 	/* find the task with the job ID */
 	length = engine->priv->array->len;
 	for (i=0; i<length; i++) {
-		task = (PkTask *) g_ptr_array_index (engine->priv->array, i);
-		job_tmp = pk_task_get_job (task);
-		if (job_tmp == job) {
-			return task;
+		map = (PkEngineMap *) g_ptr_array_index (engine->priv->array, i);
+		if (map->job == job) {
+			return map;
 		}
 	}
 	return NULL;
 }
 
+/**
+ * pk_get_map_from_task:
+ **/
+static PkEngineMap *
+pk_get_map_from_task (PkEngine *engine, PkTask *task)
+{
+	guint i;
+	guint length;
+	PkEngineMap *map;
+
+	g_return_val_if_fail (engine != NULL, NULL);
+	g_return_val_if_fail (PK_IS_ENGINE (engine), NULL);
+
+	/* find the task with the job ID */
+	length = engine->priv->array->len;
+	for (i=0; i<length; i++) {
+		map = (PkEngineMap *) g_ptr_array_index (engine->priv->array, i);
+		if (map->task == task) {
+			return map;
+		}
+	}
+	return NULL;
+}
 
 /**
  * pk_engine_job_list_changed:
@@ -212,17 +236,21 @@ pk_engine_job_list_changed (PkEngine *en
 static void
 pk_engine_job_status_changed_cb (PkTask *task, PkTaskStatus status, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 	const gchar *status_text;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 	status_text = pk_task_status_to_text (status);
 
-	pk_debug ("emitting job-status-changed job:%i, '%s'", job, status_text);
-	g_signal_emit (engine, signals [PK_ENGINE_JOB_STATUS_CHANGED], 0, job, status_text);
+	pk_debug ("emitting job-status-changed job:%i, '%s'", map->job, status_text);
+	g_signal_emit (engine, signals [PK_ENGINE_JOB_STATUS_CHANGED], 0, map->job, status_text);
 	pk_engine_reset_timer (engine);
 }
 
@@ -232,14 +260,18 @@ pk_engine_job_status_changed_cb (PkTask 
 static void
 pk_engine_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
-	pk_debug ("emitting percentage-changed job:%i %i", job, percentage);
-	g_signal_emit (engine, signals [PK_ENGINE_PERCENTAGE_CHANGED], 0, job, percentage);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	pk_debug ("emitting percentage-changed job:%i %i", map->job, percentage);
+	g_signal_emit (engine, signals [PK_ENGINE_PERCENTAGE_CHANGED], 0, map->job, percentage);
 	pk_engine_reset_timer (engine);
 }
 
@@ -249,14 +281,18 @@ pk_engine_percentage_changed_cb (PkTask 
 static void
 pk_engine_sub_percentage_changed_cb (PkTask *task, guint percentage, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
-	pk_debug ("emitting sub-percentage-changed job:%i %i", job, percentage);
-	g_signal_emit (engine, signals [PK_ENGINE_SUB_PERCENTAGE_CHANGED], 0, job, percentage);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	pk_debug ("emitting sub-percentage-changed job:%i %i", map->job, percentage);
+	g_signal_emit (engine, signals [PK_ENGINE_SUB_PERCENTAGE_CHANGED], 0, map->job, percentage);
 	pk_engine_reset_timer (engine);
 }
 
@@ -266,14 +302,18 @@ pk_engine_sub_percentage_changed_cb (PkT
 static void
 pk_engine_no_percentage_updates_cb (PkTask *task, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
-	pk_debug ("emitting no-percentage-updates job:%i", job);
-	g_signal_emit (engine, signals [PK_ENGINE_NO_PERCENTAGE_UPDATES], 0, job);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	pk_debug ("emitting no-percentage-updates job:%i", map->job);
+	g_signal_emit (engine, signals [PK_ENGINE_NO_PERCENTAGE_UPDATES], 0, map->job);
 	pk_engine_reset_timer (engine);
 }
 
@@ -283,14 +323,18 @@ pk_engine_no_percentage_updates_cb (PkTa
 static void
 pk_engine_package_cb (PkTask *task, guint value, const gchar *package_id, const gchar *summary, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
-	pk_debug ("emitting package job:%i value=%i %s, %s", job, value, package_id, summary);
-	g_signal_emit (engine, signals [PK_ENGINE_PACKAGE], 0, job, value, package_id, summary);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	pk_debug ("emitting package job:%i value=%i %s, %s", map->job, value, package_id, summary);
+	g_signal_emit (engine, signals [PK_ENGINE_PACKAGE], 0, map->job, value, package_id, summary);
 	pk_engine_reset_timer (engine);
 }
 
@@ -300,16 +344,20 @@ pk_engine_package_cb (PkTask *task, guin
 static void
 pk_engine_error_code_cb (PkTask *task, PkTaskErrorCode code, const gchar *details, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 	const gchar *code_text;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 	code_text = pk_task_error_code_to_text (code);
-	pk_debug ("emitting error-code job:%i %s, '%s'", job, code_text, details);
-	g_signal_emit (engine, signals [PK_ENGINE_ERROR_CODE], 0, job, code_text, details);
+	pk_debug ("emitting error-code job:%i %s, '%s'", map->job, code_text, details);
+	g_signal_emit (engine, signals [PK_ENGINE_ERROR_CODE], 0, map->job, code_text, details);
 	pk_engine_reset_timer (engine);
 }
 
@@ -319,16 +367,20 @@ pk_engine_error_code_cb (PkTask *task, P
 static void
 pk_engine_require_restart_cb (PkTask *task, PkTaskRestart restart, const gchar *details, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 	const gchar *restart_text;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 	restart_text = pk_task_restart_to_text (restart);
-	pk_debug ("emitting error-code job:%i %s, '%s'", job, restart_text, details);
-	g_signal_emit (engine, signals [PK_ENGINE_REQUIRE_RESTART], 0, job, restart_text, details);
+	pk_debug ("emitting error-code job:%i %s, '%s'", map->job, restart_text, details);
+	g_signal_emit (engine, signals [PK_ENGINE_REQUIRE_RESTART], 0, map->job, restart_text, details);
 	pk_engine_reset_timer (engine);
 }
 
@@ -339,17 +391,21 @@ static void
 pk_engine_description_cb (PkTask *task, const gchar *package_id, PkTaskGroup group,
 			  const gchar *detail, const gchar *url, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 	const gchar *group_text;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 	group_text = pk_task_group_to_text (group);
 
-	pk_debug ("emitting description job:%i, %s, %s, %s, %s", job, package_id, group_text, detail, url);
-	g_signal_emit (engine, signals [PK_ENGINE_DESCRIPTION], 0, job, package_id, group_text, detail, url);
+	pk_debug ("emitting description job:%i, %s, %s, %s, %s", map->job, package_id, group_text, detail, url);
+	g_signal_emit (engine, signals [PK_ENGINE_DESCRIPTION], 0, map->job, package_id, group_text, detail, url);
 }
 
 /**
@@ -358,25 +414,31 @@ pk_engine_description_cb (PkTask *task, 
 static void
 pk_engine_finished_cb (PkTask *task, PkTaskExit exit, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 	const gchar *exit_text;
 	gdouble time;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 	exit_text = pk_task_exit_to_text (exit);
 
 	/* find the length of time we have been running */
 	time = g_timer_elapsed (task->timer, NULL);
 	pk_debug ("task was running for %f seconds", time);
 
-	pk_debug ("emitting finished job: %i, '%s', %i", job, exit_text, (guint) time);
-	g_signal_emit (engine, signals [PK_ENGINE_FINISHED], 0, job, exit_text, (guint) time);
+	pk_debug ("emitting finished job: %i, '%s', %i", map->job, exit_text, (guint) time);
+	g_signal_emit (engine, signals [PK_ENGINE_FINISHED], 0, map->job, exit_text, (guint) time);
 
 	/* remove from array and unref */
-	g_ptr_array_remove (engine->priv->array, task);
+	g_ptr_array_remove (engine->priv->array, map);
+	g_free (map);
+
 	pk_task_common_free (task);
 	g_object_unref (task);
 	pk_debug ("removed task %p", task);
@@ -390,15 +452,19 @@ pk_engine_finished_cb (PkTask *task, PkT
 static void
 pk_engine_allow_interrupt_cb (PkTask *task, gboolean allow_kill, PkEngine *engine)
 {
-	guint job;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
 
-	job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
 
-	pk_debug ("emitting allow-interrpt job:%i, %i", job, allow_kill);
-	g_signal_emit (engine, signals [PK_ENGINE_ALLOW_INTERRUPT], 0, job, allow_kill);
+	pk_debug ("emitting allow-interrpt job:%i, %i", map->job, allow_kill);
+	g_signal_emit (engine, signals [PK_ENGINE_ALLOW_INTERRUPT], 0, map->job, allow_kill);
 }
 
 /**
@@ -479,14 +545,8 @@ pk_engine_new_task (PkEngine *engine)
 
 	/* initialise some stuff */
 	pk_task_common_init (task);
-
-	/* set the job ID */
-	pk_task_set_job (task, engine->priv->job_count);
 	pk_engine_reset_timer (engine);
 
-	/* in an ideal workd we don't need this, but do it in case the daemon is ctrl-c;d */
-	pk_engine_save_job_count (engine);
-
 	/* we don't add to the array or do the job-list-changed yet
 	 * as this job might fail */
 	return task;
@@ -498,8 +558,16 @@ pk_engine_new_task (PkEngine *engine)
 static gboolean
 pk_engine_add_task (PkEngine *engine, PkTask *task)
 {
+	PkEngineMap *map;
+
 	/* add to the array */
-	g_ptr_array_add (engine->priv->array, task);
+	map = g_new0 (PkEngineMap, 1);
+	map->task = task;
+	map->job = engine->priv->job_count;
+	g_ptr_array_add (engine->priv->array, map);
+
+	/* in an ideal world we don't need this, but do it in case the daemon is ctrl-c;d */
+	pk_engine_save_job_count (engine);
 
 	/* emit a signal */
 	pk_engine_job_list_changed (engine);
@@ -574,6 +642,7 @@ pk_engine_refresh_cache (PkEngine *engin
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -588,7 +657,12 @@ pk_engine_refresh_cache (PkEngine *engin
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -601,6 +675,7 @@ pk_engine_get_updates (PkEngine *engine,
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -615,7 +690,12 @@ pk_engine_get_updates (PkEngine *engine,
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -681,6 +761,7 @@ pk_engine_search_name (PkEngine *engine,
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -707,7 +788,12 @@ pk_engine_search_name (PkEngine *engine,
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -721,6 +807,7 @@ pk_engine_search_details (PkEngine *engi
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -747,7 +834,12 @@ pk_engine_search_details (PkEngine *engi
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -761,6 +853,7 @@ pk_engine_search_group (PkEngine *engine
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -787,7 +880,12 @@ pk_engine_search_group (PkEngine *engine
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -801,6 +899,7 @@ pk_engine_search_file (PkEngine *engine,
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -827,7 +926,12 @@ pk_engine_search_file (PkEngine *engine,
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -841,6 +945,7 @@ pk_engine_get_depends (PkEngine *engine,
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -863,7 +968,12 @@ pk_engine_get_depends (PkEngine *engine,
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -877,6 +987,7 @@ pk_engine_get_requires (PkEngine *engine
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -899,7 +1010,12 @@ pk_engine_get_requires (PkEngine *engine
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -913,6 +1029,7 @@ pk_engine_get_description (PkEngine *eng
 {
 	gboolean ret;
 	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
@@ -927,7 +1044,12 @@ pk_engine_get_description (PkEngine *eng
 		return FALSE;
 	}
 	pk_engine_add_task (engine, task);
-	*job = pk_task_get_job (task);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return FALSE;
+	}
+	*job = map->job;
 
 	return TRUE;
 }
@@ -940,12 +1062,12 @@ pk_engine_update_system (PkEngine *engin
 			 DBusGMethodInvocation *context, GError **dead_error)
 {
 	guint i;
-	guint job;
 	guint length;
 	PkTaskRole role;
-	PkTask *task;
 	gboolean ret;
 	GError *error;
+	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_if_fail (engine != NULL);
 	g_return_if_fail (PK_IS_ENGINE (engine));
@@ -960,8 +1082,8 @@ pk_engine_update_system (PkEngine *engin
 	/* check for existing job doing an update */
 	length = engine->priv->array->len;
 	for (i=0; i<length; i++) {
-		task = (PkTask *) g_ptr_array_index (engine->priv->array, i);
-		ret = pk_task_get_job_role (task, &role, NULL);
+		map = (PkEngineMap *) g_ptr_array_index (engine->priv->array, i);
+		ret = pk_task_get_job_role (map->task, &role, NULL);
 		if (ret == TRUE && role == PK_TASK_ROLE_SYSTEM_UPDATE) {
 			error = g_error_new (PK_ENGINE_ERROR, PK_ENGINE_ERROR_DENIED,
 					     "operation not yet supported by backend");
@@ -982,8 +1104,12 @@ pk_engine_update_system (PkEngine *engin
 	}
 	pk_engine_add_task (engine, task);
 
-	job = pk_task_get_job (task);
-	dbus_g_method_return (context, job);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	dbus_g_method_return (context, map->job);
 }
 
 /**
@@ -993,7 +1119,7 @@ void
 pk_engine_remove_package (PkEngine *engine, const gchar *package_id, gboolean allow_deps,
 			  DBusGMethodInvocation *context, GError **dead_error)
 {
-	guint job;
+	PkEngineMap *map;
 	gboolean ret;
 	PkTask *task;
 	GError *error;
@@ -1029,8 +1155,12 @@ pk_engine_remove_package (PkEngine *engi
 	}
 	pk_engine_add_task (engine, task);
 
-	job = pk_task_get_job (task);
-	dbus_g_method_return (context, job);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	dbus_g_method_return (context, map->job);
 }
 
 /**
@@ -1043,7 +1173,7 @@ pk_engine_install_package (PkEngine *eng
 			   DBusGMethodInvocation *context, GError **dead_error)
 {
 	gboolean ret;
-	guint job;
+	PkEngineMap *map;
 	PkTask *task;
 	GError *error;
 
@@ -1078,8 +1208,12 @@ pk_engine_install_package (PkEngine *eng
 	}
 	pk_engine_add_task (engine, task);
 
-	job = pk_task_get_job (task);
-	dbus_g_method_return (context, job);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	dbus_g_method_return (context, map->job);
 }
 
 /**
@@ -1092,7 +1226,7 @@ pk_engine_update_package (PkEngine *engi
 			   DBusGMethodInvocation *context, GError **dead_error)
 {
 	gboolean ret;
-	guint job;
+	PkEngineMap *map;
 	PkTask *task;
 	GError *error;
 
@@ -1127,8 +1261,12 @@ pk_engine_update_package (PkEngine *engi
 	}
 	pk_engine_add_task (engine, task);
 
-	job = pk_task_get_job (task);
-	dbus_g_method_return (context, job);
+	map = pk_get_map_from_task (engine, task);
+	if (map == FALSE) {
+		pk_warning ("could not find task");
+		return;
+	}
+	dbus_g_method_return (context, map->job);
 }
 
 /**
@@ -1152,19 +1290,19 @@ gboolean
 pk_engine_get_job_status (PkEngine *engine, guint job,
 			  const gchar **status, GError **error)
 {
-	PkTask *task;
 	PkTaskStatus status_enum;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
 
-	task = pk_get_task_from_job (engine, job);
-	if (task == NULL) {
+	map = pk_get_map_from_job (engine, job);
+	if (map == NULL) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_JOB,
-			     "No job:%i", job);
+			     "No job:%i", map->job);
 		return FALSE;
 	}
-	pk_task_get_job_status (task, &status_enum);
+	pk_task_get_job_status (map->task, &status_enum);
 	*status = g_strdup (pk_task_status_to_text (status_enum));
 
 	return TRUE;
@@ -1177,19 +1315,19 @@ gboolean
 pk_engine_get_job_role (PkEngine *engine, guint job,
 			const gchar **role, const gchar **package_id, GError **error)
 {
-	PkTask *task;
+	PkEngineMap *map;
 	PkTaskRole role_enum;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
 
-	task = pk_get_task_from_job (engine, job);
-	if (task == NULL) {
+	map = pk_get_map_from_job (engine, job);
+	if (map == NULL) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_JOB,
-			     "No job:%i", job);
+			     "No job:%i", map->job);
 		return FALSE;
 	}
-	pk_task_get_job_role (task, &role_enum, package_id);
+	pk_task_get_job_role (map->task, &role_enum, package_id);
 	*role = g_strdup (pk_task_role_to_text (role_enum));
 
 	return TRUE;
@@ -1202,23 +1340,22 @@ gboolean
 pk_engine_cancel_job_try (PkEngine *engine, guint job, GError **error)
 {
 	gboolean ret;
-	PkTask *task;
+	PkEngineMap *map;
 
 	g_return_val_if_fail (engine != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
 
-	task = pk_get_task_from_job (engine, job);
-	if (task == NULL) {
+	map = pk_get_map_from_job (engine, job);
+	if (map == NULL) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NO_SUCH_JOB,
-			     "No job:%i", job);
+			     "No job:%i", map->job);
 		return FALSE;
 	}
 
-	ret = pk_task_cancel_job_try (task);
+	ret = pk_task_cancel_job_try (map->task);
 	if (ret == FALSE) {
 		g_set_error (error, PK_ENGINE_ERROR, PK_ENGINE_ERROR_NOT_SUPPORTED,
 			     "operation not yet supported by backend");
-		g_object_unref (task);
 		return FALSE;
 	}
 
diff --git a/src/pk-task-common.c b/src/pk-task-common.c
index 419375b..5818399 100644
--- a/src/pk-task-common.c
+++ b/src/pk-task-common.c
@@ -596,30 +596,6 @@ pk_task_assign (PkTask *task)
 }
 
 /**
- * pk_task_get_job:
- **/
-guint
-pk_task_get_job (PkTask *task)
-{
-	g_return_val_if_fail (task != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-	return task->job;
-}
-
-/**
- * pk_task_set_job:
- **/
-gboolean
-pk_task_set_job (PkTask *task, guint job)
-{
-	g_return_val_if_fail (task != NULL, FALSE);
-	g_return_val_if_fail (PK_IS_TASK (task), FALSE);
-	pk_debug ("set job %p=%i", task, job);
-	task->job = job;
-	return TRUE;
-}
-
-/**
  * pk_task_common_init:
  **/
 gboolean
@@ -630,7 +606,6 @@ pk_task_common_init (PkTask *task)
 
 	/* track how long the job has been running for */
 	task->timer = g_timer_new ();
-	task->job = 1;
 	task->assigned = FALSE;
 	task->is_killable = FALSE;
 	task->spawn = NULL;
diff --git a/src/pk-task-common.h b/src/pk-task-common.h
index 43388de..7b81408 100644
--- a/src/pk-task-common.h
+++ b/src/pk-task-common.h
@@ -29,9 +29,6 @@ G_BEGIN_DECLS
 
 gboolean	 pk_task_common_init			(PkTask		*task);
 gboolean	 pk_task_common_free			(PkTask		*task);
-guint		 pk_task_get_job			(PkTask		*task);
-gboolean	 pk_task_set_job			(PkTask		*task,
-							 guint		 job);
 gboolean	 pk_task_change_percentage		(PkTask		*task,
 							 guint		 percentage);
 gboolean	 pk_task_change_sub_percentage		(PkTask		*task,
diff --git a/src/pk-task.h b/src/pk-task.h
index a1f1c19..5212848 100644
--- a/src/pk-task.h
+++ b/src/pk-task.h
@@ -56,7 +56,6 @@ typedef struct
 	GObject			 parent;
 	PkTaskPrivate		*priv;
 	gboolean		 assigned;
-	guint			 job;
 	PkTaskStatus		 role; /* this never changes for the lifetime of a job */
 	PkTaskStatus		 status; /* this changes */
 	gchar			*package_id; /* never changes, this is linked to role */
diff-tree 25a0c0c9e29ac2e44737998346b81316847f8043 (from e995f1940d89e8c989918057b43d46bf172d20c6)
Author: Ken VanDine <ken at vandine.org>
Date:   Mon Sep 3 22:13:43 2007 -0400

    Update the conary backend status

diff --git a/helpers/BACKENDS b/helpers/BACKENDS
index a103125..a433868 100644
--- a/helpers/BACKENDS
+++ b/helpers/BACKENDS
@@ -10,5 +10,5 @@ update-system   |           |   X   |   
 install         |           |   X   |       |       |
 remove          |           |   X   |       |       |
 get-deps        |           |   X   |       |       |
-get-description |           |       |   X   |       |
+get-description |     X     |       |   X   |       |
 search-file     |           |       |       |   X   |
diff-tree e995f1940d89e8c989918057b43d46bf172d20c6 (from parents)
Merge: b287287aa862d88dbf6022e4990823724af37a87 31ded1b2263c1edf0e7ef9737e6c47f5491cdc6b
Author: Ken VanDine <ken at vandine.org>
Date:   Mon Sep 3 22:13:05 2007 -0400

    Merge branch 'master' of ssh://kvandine@hughsient.no-ip.org/srv/git/PackageKit

diff-tree b287287aa862d88dbf6022e4990823724af37a87 (from 51f07229ffff5636b872a6fa495ab530f5396dbc)
Author: Ken VanDine <ken at vandine.org>
Date:   Mon Sep 3 22:12:52 2007 -0400

    * Make _findPackage more robust
    * more work on implementing get-description, install and remove

diff --git a/helpers/conary/conaryBackend.py b/helpers/conary/conaryBackend.py
index 7d34e96..e78169d 100644
--- a/helpers/conary/conaryBackend.py
+++ b/helpers/conary/conaryBackend.py
@@ -35,9 +35,12 @@ class PackageKitConaryBackend(PackageKit
     def _get_version(self, version):
         return version.asString()
 
-    def get_package_id(self, name, version, flavor, fullVersion=None):
+    def get_package_id(self, name, version, flavor=None, fullVersion=None):
         version = self._get_version(version)
-        arch = self._get_arch(flavor)
+        if not flavor == None:
+            arch = self._get_arch(flavor)
+        else:
+            arch = ""
         return PackageKitBaseBackend.get_package_id(self, name, version,
                                                     arch, fullVersion)
 
@@ -169,13 +172,14 @@ class PackageKitConaryBackend(PackageKit
         '''
         Implement the {backend}-install functionality
         '''
-        pkg,inst = self._findPackage(package_id)
+        name,installed,version,arch,fullVersion = self._findPackage(package_id)
 
-        if pkg:
-            if inst:
+        if name:
+            if installed:
                 self.error(ERROR_PACKAGE_ALREADY_INSTALLED,'Package already installed')
             try:
-                print "Update code goes here"
+                self.base.status(STATE_INSTALL)
+                #print "Update code goes here"
             except:
                 pass
         else:
@@ -186,13 +190,14 @@ class PackageKitConaryBackend(PackageKit
         '''
         Implement the {backend}-remove functionality
         '''
-        pkg,inst = self._findPackage(package_id)
+        name,installed,version,arch,fullVersion = self._findPackage(package_id)
 
-        if pkg:
-            if not inst:
+        if name:
+            if not installed:
                 self.error(ERROR_PACKAGE_NOT_INSTALLED,'Package not installed')
             try:
-                print "Remove code goes here"
+                self.base.status(STATE_REMOVE)
+                #print "Remove code goes here"
             except:
                 pass
         else:
@@ -200,7 +205,24 @@ class PackageKitConaryBackend(PackageKit
 
 
     def get_description(self, package_id):
-        return ''
+        '''
+        Print a detailed description for a given package
+        '''
+        name,installed,version,arch,fullVersion = self._findPackage(package_id)
+        fullVersion = versions.VersionFromString(fullVersion)
+        version = fullVersion.trailingRevision()
+        if name:
+            id = self.get_package_id(name, version)
+            desc = ""
+            desc += "%s \n" % name
+            desc += "%s \n" % version
+            desc = desc.replace('\n\n',';')
+            desc = desc.replace('\n',' ')
+            url = "http://www.foresightlinux.org/packages/" + name + ".html"
+            group = "other"
+            self.description(id, group, desc, url)
+        else:
+            self.error(ERROR_INTERNAL_ERROR,'Package was not found')
 
     def get_updates(self):
         updateItems = self.client.fullUpdateItemList()
@@ -279,7 +301,7 @@ class PackageKitConaryBackend(PackageKit
         (name,version,arch,fullVersion) = self.get_package_from_id(id)
         troveTuple = tuple([name, versions.VersionFromString(fullVersion), None])
         installed = self.check_installed(troveTuple)
-        return name,installed
+        return name,installed,version,arch,fullVersion
 
 class Cache(object):
     # Database name and path
diff --git a/src/pk-task-conary.c b/src/pk-task-conary.c
index deafa58..2c0f2f3 100644
--- a/src/pk-task-conary.c
+++ b/src/pk-task-conary.c
@@ -65,8 +65,8 @@ gchar *
 pk_task_get_actions (void)
 {
 	gchar *actions;
-	actions = pk_task_action_build (/*PK_TASK_ACTION_INSTALL,*/
-/*				        PK_TASK_ACTION_REMOVE,*/
+	actions = pk_task_action_build (PK_TASK_ACTION_INSTALL,
+				        PK_TASK_ACTION_REMOVE,
 /*				        PK_TASK_ACTION_UPDATE,*/
 				        PK_TASK_ACTION_GET_UPDATES,
 				        PK_TASK_ACTION_REFRESH_CACHE,
@@ -77,7 +77,7 @@ pk_task_get_actions (void)
 /*				        PK_TASK_ACTION_SEARCH_FILE,*/
 /*				        PK_TASK_ACTION_GET_DEPENDS,*/
 /*				        PK_TASK_ACTION_GET_REQUIRES,*/
-/*				        PK_TASK_ACTION_GET_DESCRIPTION,*/
+				        PK_TASK_ACTION_GET_DESCRIPTION,
 				        0);
 	return actions;
 }
@@ -265,8 +265,11 @@ pk_task_get_description (PkTask *task, c
 		return FALSE;
 	}
 
+	/* only copy this code if you can kill the process with no ill effect */
+	pk_task_allow_interrupt (task, TRUE);
+
 	pk_task_set_job_role (task, PK_TASK_ROLE_QUERY, package_id);
-	pk_task_not_implemented_yet (task, "GetDescription");
+	pk_task_spawn_helper (task, "get-description.py", package_id, NULL);
 	return TRUE;
 }
 
@@ -276,6 +279,7 @@ pk_task_get_description (PkTask *task, c
 gboolean
 pk_task_remove_package (PkTask *task, const gchar *package_id, gboolean allow_deps)
 {
+	const gchar *deps;
 	g_return_val_if_fail (task != NULL, FALSE);
 	g_return_val_if_fail (PK_IS_TASK (task), FALSE);
 
@@ -283,11 +287,16 @@ pk_task_remove_package (PkTask *task, co
 		return FALSE;
 	}
 
+	if (allow_deps == TRUE) {
+		deps = "yes";
+	} else {
+		deps = "no";
+	}
+
 	pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_REMOVE, package_id);
-	pk_task_not_implemented_yet (task, "RemovePackage");
+	pk_task_spawn_helper (task, "remove.py", deps, package_id, NULL);
 	return TRUE;
 }
-
 /**
  * pk_task_install_package:
  **/
@@ -309,7 +318,7 @@ pk_task_install_package (PkTask *task, c
 	}
 
 	pk_task_set_job_role (task, PK_TASK_ROLE_PACKAGE_INSTALL, package_id);
-	pk_task_not_implemented_yet (task, "InstallPackage");
+	pk_task_spawn_helper (task, "install.py", package_id, NULL);
 	return TRUE;
 }
 



More information about the PackageKit mailing list