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

Richard Hughes hughsient at kemper.freedesktop.org
Sat Sep 8 04:14:13 PDT 2007


 TODO                          |    5 -
 backends/box/pk-backend-box.c |  169 +++++++++++++++++++++++++++++++-----------
 2 files changed, 128 insertions(+), 46 deletions(-)

New commits:
diff-tree 024561883c5c4e71e82c1a99a1b3654f2672f0f9 (from parents)
Merge: 75365d5e6f273a83a7523fffdcb159bafc89a3e8 0b2aaf199aecffb344e0a43c1b1ab066f08c933f
Author: Richard Hughes <richard at hughsie.com>
Date:   Sat Sep 8 12:13:27 2007 +0100

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

diff-tree 0b2aaf199aecffb344e0a43c1b1ab066f08c933f (from 23b9a4332f7e52a0be8826d366c623e8d8321c53)
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date:   Sat Sep 8 10:19:45 2007 +0000

    added more asserts

diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index d81dc60..f2ae5ea 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -112,7 +112,7 @@ parse_filter (const gchar *filter, gbool
 	g_strfreev (sections);
 }
 
-static gboolean
+static void
 find_packages_real (PkBackend *backend, const gchar *search, const gchar *filter, gint mode)
 {
 	GList *list = NULL;
@@ -125,6 +125,8 @@ find_packages_real (PkBackend *backend, 
 	gboolean gui;
 	gboolean text;
 
+	g_return_if_fail (backend != NULL);
+
 	pk_backend_change_job_status (backend, PK_ROLE_ENUM_QUERY);
 	parse_filter (filter, &installed, &available, &devel, &nondevel, &gui, &text);
 
@@ -147,7 +149,6 @@ find_packages_real (PkBackend *backend, 
 		box_db_repos_package_list_free (list);
 		pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
 	} else {
-
 		if (installed == FALSE && available == FALSE) {
 			pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, "invalid search mode");
 			pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
@@ -166,8 +167,6 @@ find_packages_real (PkBackend *backend, 
 	}
 
 	db_close(db);
-
-	return TRUE;
 }
 
 void*
@@ -175,6 +174,8 @@ find_packages_thread (gpointer data)
 {
 	FindData *d = (FindData*) data;
 
+	g_return_val_if_fail (d->backend != NULL, NULL);
+
 	find_packages_real (d->backend, d->search, d->filter, d->mode);
 
 	g_free(d->search);
@@ -185,11 +186,13 @@ find_packages_thread (gpointer data)
 }
 
 
-static gboolean
+static void
 find_packages (PkBackend *backend, const gchar *search, const gchar *filter, gint mode)
 {
 	FindData *data = g_new0(FindData, 1);
 
+	g_return_if_fail (backend != NULL);
+
 	if (data == NULL) {
 		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory");
 		pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
@@ -205,7 +208,6 @@ find_packages (PkBackend *backend, const
 		}
 		
 	}
-	return TRUE;
 }
 
 static GList*
diff-tree 23b9a4332f7e52a0be8826d366c623e8d8321c53 (from 76e35bcdaa1a5ba6da7a842ad918017b8424dbff)
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date:   Sat Sep 8 09:23:15 2007 +0000

    use threading in box backend

diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 2ba311f..d81dc60 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -29,24 +29,38 @@
 #include <libbox/libbox-db-utils.h>
 #include <libbox/libbox-db-repos.h>
 
-/**
- * backend_initalize:
- */
-static void
-backend_initalize (PkBackend *backend)
+typedef struct {
+	PkBackend *backend;
+	gchar *search;
+	gchar *filter;
+	gint mode;
+} FindData;
+
+typedef struct {
+	PkBackend *backend;
+} UpdateData;
+
+
+static sqlite3*
+db_open()
 {
-	g_return_if_fail (backend != NULL);
+	sqlite3 *db;
+
+	db = box_db_open("/");
+	box_db_attach_repo(db, "/", "core");
+	box_db_repos_init(db);
+
+	return db;
 }
 
-/**
- * backend_destroy:
- */
 static void
-backend_destroy (PkBackend *backend)
+db_close(sqlite3 *db)
 {
-	g_return_if_fail (backend != NULL);
+	box_db_detach_repo(db, "core");
+	box_db_close(db);
 }
 
+
 static void
 add_packages_from_list (PkBackend *backend, GList *list)
 {
@@ -99,7 +113,7 @@ parse_filter (const gchar *filter, gbool
 }
 
 static gboolean
-find_packages (PkBackend *backend, const gchar *search, const gchar *filter, gint mode)
+find_packages_real (PkBackend *backend, const gchar *search, const gchar *filter, gint mode)
 {
 	GList *list = NULL;
 	sqlite3 *db = NULL;
@@ -124,13 +138,10 @@ find_packages (PkBackend *backend, const
 	pk_backend_change_job_status (backend, PK_STATUS_ENUM_QUERY);
 	pk_backend_no_percentage_updates (backend);
 
-	db = box_db_open ("/");
-	box_db_attach_repo (db, "/", "core");
-	box_db_repos_init (db);
+	db = db_open();
 
 	if (mode == 1) {
 		/* TODO: allow filtering */
-		/* TODO: make it more async */
 		list = box_db_repos_search_file (db, search);
 		add_packages_from_list (backend, list);
 		box_db_repos_package_list_free (list);
@@ -141,7 +152,6 @@ find_packages (PkBackend *backend, const
 			pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, "invalid search mode");
 			pk_backend_finished (backend, PK_EXIT_ENUM_FAILED);
 		} else	{
-			/* TODO: make it more async */
 			if (installed == TRUE && available == TRUE) {
 				list = box_db_repos_packages_search_all(db, (gchar *)search, devel_filter);
 			} else if (installed == TRUE) {
@@ -155,9 +165,46 @@ find_packages (PkBackend *backend, const
 		}
 	}
 
-	box_db_detach_repo(db, "core");
-	box_db_close(db);
+	db_close(db);
+
+	return TRUE;
+}
+
+void*
+find_packages_thread (gpointer data)
+{
+	FindData *d = (FindData*) data;
+
+	find_packages_real (d->backend, d->search, d->filter, d->mode);
+
+	g_free(d->search);
+	g_free(d->filter);
+	g_free(d);
+
+	return NULL;
+}
+
 
+static gboolean
+find_packages (PkBackend *backend, const gchar *search, const gchar *filter, gint mode)
+{
+	FindData *data = g_new0(FindData, 1);
+
+	if (data == NULL) {
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory");
+		pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
+	} else {
+		data->backend = backend;
+		data->search = g_strdup(search);
+		data->filter = g_strdup(filter);
+		data->mode = mode;
+
+		if (g_thread_create(find_packages_thread, data, FALSE, NULL) == NULL) {
+			pk_backend_error_code(backend, PK_ERROR_ENUM_CREATE_THREAD_FAILED, "Failed to create thread");
+			pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
+		}
+		
+	}
 	return TRUE;
 }
 
@@ -167,21 +214,61 @@ find_package_by_id (PkPackageId *pi)
 	sqlite3 *db = NULL;
 	GList *list;
 
-	db = box_db_open("/");
-	box_db_attach_repo(db, "/", "core");
-	box_db_repos_init(db);
+	db = db_open();
 
 	/* only one element is returned */
 	list = box_db_repos_packages_search_by_data(db, pi->name, pi->version);
 	if (list == NULL)
 		return NULL;
 
-	box_db_detach_repo(db, "core");
-	box_db_close(db);
+	db_close(db);
 
 	return list;
 }
 
+
+static void*
+get_updates_thread(gpointer data)
+{
+	GList *list = NULL;
+	sqlite3 *db = NULL;
+	UpdateData *d = (UpdateData*) data;
+
+	db = db_open ();
+
+	list = box_db_repos_packages_for_upgrade (db);
+	add_packages_from_list (d->backend, list);
+	box_db_repos_package_list_free (list);
+
+	pk_backend_finished (d->backend, PK_EXIT_ENUM_SUCCESS);
+
+	g_free(d);
+	db_close (db);
+
+	return NULL;
+}
+
+
+/* ===================================================================== */
+
+/**
+ * backend_initalize:
+ */
+static void
+backend_initalize (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+}
+
+/**
+ * backend_destroy:
+ */
+static void
+backend_destroy (PkBackend *backend)
+{
+	g_return_if_fail (backend != NULL);
+}
+
 /**
  * backend_get_description:
  */
@@ -226,26 +313,24 @@ backend_get_description (PkBackend *back
 static void
 backend_get_updates (PkBackend *backend)
 {
-	GList *list = NULL;
-	sqlite3 *db = NULL;
+	UpdateData *data = g_new0(UpdateData, 1);
 
 	g_return_if_fail (backend != NULL);
 
 	pk_backend_change_job_status (backend, PK_STATUS_ENUM_QUERY);
 
-	db = box_db_open ("/");
-	box_db_attach_repo (db, "/", "core");
-	box_db_repos_init (db);
-
-	/* TODO: make it more async */
-	list = box_db_repos_packages_for_upgrade (db);
-	add_packages_from_list (backend, list);
-	box_db_repos_package_list_free (list);
-
-	pk_backend_finished (backend, PK_EXIT_ENUM_SUCCESS);
+	if (data == NULL) {
+		pk_backend_error_code(backend, PK_ERROR_ENUM_OOM, "Failed to allocate memory");
+		pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
+	} else {
+		data->backend = backend;
 
-	box_db_detach_repo (db, "core");
-	box_db_close (db);
+		if (g_thread_create(get_updates_thread, data, FALSE, NULL) == NULL) {
+			pk_backend_error_code(backend, PK_ERROR_ENUM_CREATE_THREAD_FAILED, "Failed to create thread");
+			pk_backend_finished(backend, PK_EXIT_ENUM_FAILED);
+		}
+		
+	}
 }
 
 /**
diff-tree 75365d5e6f273a83a7523fffdcb159bafc89a3e8 (from parents)
Merge: 3891882974daa4e62e5ab99f7b2396acb620cec0 23b9a4332f7e52a0be8826d366c623e8d8321c53
Author: Richard Hughes <richard at hughsie.com>
Date:   Sat Sep 8 09:22:40 2007 +0100

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

diff-tree 3891882974daa4e62e5ab99f7b2396acb620cec0 (from 76e35bcdaa1a5ba6da7a842ad918017b8424dbff)
Author: Richard Hughes <richard at hughsie.com>
Date:   Sat Sep 8 01:54:45 2007 +0100

    update TODO

diff --git a/TODO b/TODO
index e9d5e81..52f7143 100644
--- a/TODO
+++ b/TODO
@@ -55,11 +55,6 @@ string update_text
 For the icon to update after we've done a system upgrade
 NOTE: RELEASE BLOCKER
 
-*** Have to load parameters from a conf file ***
-  - autoshutdown-timeout
-  - default-backend
-  - logging-detail
-
 *** Dummy backend should use subpercent and install deps ***
 It's not a great test case right now...
 



More information about the PackageKit mailing list