Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Jul 2013 06:55:06 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r254404 - in soc2013/mattbw/backend: . actions
Message-ID:  <201307080655.r686t6f4090728@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Mon Jul  8 06:55:06 2013
New Revision: 254404
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254404

Log:
  (in progress) even more changing around ready for resolve

Added:
  soc2013/mattbw/backend/actions/resolve.c
Modified:
  soc2013/mattbw/backend/Makefile
  soc2013/mattbw/backend/actions/actions.h
  soc2013/mattbw/backend/actions/install-files.c
  soc2013/mattbw/backend/db.c
  soc2013/mattbw/backend/db.h
  soc2013/mattbw/backend/pk-backend-pkgng.c
  soc2013/mattbw/backend/query.c
  soc2013/mattbw/backend/query.h

Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/Makefile	Mon Jul  8 06:55:06 2013	(r254404)
@@ -16,7 +16,8 @@
 		actions/get-files.c		\
 		actions/get-repo-list.c		\
 		actions/install-files.c		\
-		actions/install-packages.c
+		actions/install-packages.c	\
+		actions/resolve.c
 
 LIBDIR=		/usr/local/lib/packagekit-backend
 

Modified: soc2013/mattbw/backend/actions/actions.h
==============================================================================
--- soc2013/mattbw/backend/actions/actions.h	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/actions/actions.h	Mon Jul  8 06:55:06 2013	(r254404)
@@ -33,6 +33,7 @@
 gboolean	get_repo_list_thread(PkBackend *backend);
 gboolean	install_files_thread(PkBackend *backend);
 gboolean	install_packages_thread(PkBackend *backend);
+gboolean	resolve_thread(PkBackend *backend);
 gboolean	simulate_install_files_thread(PkBackend *backend);
 gboolean	simulate_install_packages_thread(PkBackend *backend);
 

Modified: soc2013/mattbw/backend/actions/install-files.c
==============================================================================
--- soc2013/mattbw/backend/actions/install-files.c	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/actions/install-files.c	Mon Jul  8 06:55:06 2013	(r254404)
@@ -22,7 +22,7 @@
 #include "../pk-backend.h"
 #include "pkg.h"
 
-#include "../db.h"		/* open_remote_db */
+#include "../db.h"		/* db_open_remote */
 #include "../hash_traverse.h"	/* HASH_FOR */
 #include "../pkgutils.h"	/* pkgutils_... */
 #include "../query_match.h"	/* query_match_... */
@@ -88,7 +88,7 @@
 	} else {
 		/* TODO: event hook */
 
-		if (open_remote_db(&db, backend) == FALSE)
+		if (db_open_remote(&db, backend) == FALSE)
 			goto cleanup;
 		
 		(void)pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL);

Added: soc2013/mattbw/backend/actions/resolve.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/resolve.c	Mon Jul  8 06:55:06 2013	(r254404)
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "../pk-backend.h"
+#include "pkg.h"
+
+#include "../db.h"		/* db_open_remote */
+#include "actions.h"		/* Prototype */
+
+static gboolean	resolve_id(struct pkgdb *db, PkBackend *backend, gchar *id);
+static gboolean	resolve_name(struct pkgdb *db, PkBackend *backend, gchar *name);
+
+/*
+ * Resolves a package identifier, which may be a full PackageID or a package
+ * name, to a package that is promptly emitted.
+ */
+gboolean
+resolve_thread(PkBackend *backend)
+{
+	gboolean success;
+	struct pkgdb *db;
+	gchar **package_ids;
+
+	success = TRUE;
+
+	package_ids = pk_backend_get_strv(backend, "package_ids");
+
+	db = NULL;
+	if (db_open_remote(&db, backend) == TRUE) {
+		gchar **id_p;
+
+		for (id_p = package_ids; *id_p != NULL && success; id_p++) {
+			if (pk_package_id_check(*id_p) == TRUE)
+				success = resolve_id(db, backend, *id_p);
+			else
+				success = resolve_name(db, backend, *id_p);
+		}
+	} else
+		success = FALSE;
+	
+	pk_backend_finished(backend);
+	return success;
+}
+
+static gboolean
+resolve_id(struct pkgdb *db, PkBackend *backend, gchar *id)
+{
+
+	/* TODO: implement */
+	(void)db;
+	(void)backend;
+	(void)id;
+	return FALSE;
+}
+
+static gboolean
+resolve_name(struct pkgdb *db, PkBackend *backend, gchar *name)
+{
+
+	/* TODO: implement */
+	(void)db;
+	(void)backend;
+	(void)name;
+	return FALSE;
+}
+

Modified: soc2013/mattbw/backend/db.c
==============================================================================
--- soc2013/mattbw/backend/db.c	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/db.c	Mon Jul  8 06:55:06 2013	(r254404)
@@ -43,7 +43,7 @@
  * "pk_backend_initialize" and before "pk_backend_destroy".
  */
 gboolean
-open_remote_db(struct pkgdb **db_p, PkBackend *backend)
+db_open_remote(struct pkgdb **db_p, PkBackend *backend)
 {
 	gboolean	success;
 

Modified: soc2013/mattbw/backend/db.h
==============================================================================
--- soc2013/mattbw/backend/db.h	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/db.h	Mon Jul  8 06:55:06 2013	(r254404)
@@ -26,6 +26,6 @@
 #include "pk-backend.h"		/* PkBackend */
 #include "pkg.h"		/* struct pkgdb */
 
-gboolean	open_remote_db(struct pkgdb **db, PkBackend *backend);
+gboolean	db_open_remote(struct pkgdb **db, PkBackend *backend);
 
-#endif				/* !_PKGNG_BACKEND_DETAILS_H_ */
+#endif				/* !_PKGNG_BACKEND_DB_H_ */

Modified: soc2013/mattbw/backend/pk-backend-pkgng.c
==============================================================================
--- soc2013/mattbw/backend/pk-backend-pkgng.c	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/pk-backend-pkgng.c	Mon Jul  8 06:55:06 2013	(r254404)
@@ -172,6 +172,15 @@
 }
 
 void
+pk_backend_resolve(PkBackend *backend, PkBitfield filters, gchar **package_ids)
+{
+
+	INTENTIONALLY_IGNORE(filters);		/* retrieved from backend */
+	INTENTIONALLY_IGNORE(package_ids);	/* retrieved from backend */
+	pk_backend_thread_create(backend, resolve_thread);
+}
+
+void
 pk_backend_simulate_install_files(PkBackend *backend, gchar **full_paths)
 {
 

Modified: soc2013/mattbw/backend/query.c
==============================================================================
--- soc2013/mattbw/backend/query.c	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/query.c	Mon Jul  8 06:55:06 2013	(r254404)
@@ -25,7 +25,7 @@
 
 #include "query.h"		/* Prototypes */
 
-#include "db.h"			/* open_remote_db */
+#include "db.h"			/* db_open_remote */
 #include "hash_traverse.h"	/* HASH_FOR */
 #include "utils.h"		/* string_match */
 #include "pkgutils.h"		/* pkgutils_... */
@@ -168,29 +168,31 @@
 	(void)pk_backend_set_percentage(backend,
 	    PK_BACKEND_PERCENTAGE_INVALID);
 
+	/*
+	 * We're using length/index instead of incrementing the pointer to NULL
+	 * so that we can infer the progress bar percentage.
+	 */
 	package_ids = pk_backend_get_strv(backend, "package_ids");
 	len = g_strv_length(package_ids);
 
 	db = NULL;
 	q = NULL;
 
-	no_error_yet = open_remote_db(&db, backend);
+	no_error_yet = db_open_remote(&db, backend);
 
 	pk_backend_set_percentage(backend, 0);
 	for (i = 0; i < len && no_error_yet; i++) {
-		no_error_yet = query_init(package_ids[i],
+		no_error_yet = query_do_single(package_ids[i],
 		    backend,
 		    db,
 		    load_flags,
 		    emitter,
 		    job_type,
 		    job_emitter,
-		    &q);
-		if (no_error_yet == TRUE)
-			no_error_yet = body(q);
+		    body);
 		pk_backend_set_percentage(backend, ((i * 100) / len));
 	}
-	query_free(q);
+
 	pkgdb_close(db);
 
 	pk_backend_finished(backend);
@@ -199,6 +201,41 @@
 }
 
 /*
+ * Runs a query over one PackageID.
+ * 
+ * This provides the emitting function with a query structure ready to run, but
+ * does not do any backend housekeeping.
+ */
+gboolean
+query_do_single(gchar *package_id,
+    PkBackend *backend,
+    struct pkgdb *db,
+    unsigned int load_flags,
+    emit_ptr emitter,
+    pkg_jobs_t job_type,
+    job_emit_ptr job_emitter,
+    query_body_ptr body)
+{
+	gboolean success;
+	struct query *q;
+
+	q = NULL;
+	success = query_init(package_id,
+	    backend,
+	    db,
+	    load_flags,
+	    emitter,
+	    job_type,
+	    job_emitter,
+	    &q);
+	if (success)
+	    success = body(q);
+
+	query_free(q);
+	return success;
+}
+
+/*
  * For adapting an emitter function into one that solves and applies a job.
  */
 gboolean

Modified: soc2013/mattbw/backend/query.h
==============================================================================
--- soc2013/mattbw/backend/query.h	Mon Jul  8 05:58:09 2013	(r254403)
+++ soc2013/mattbw/backend/query.h	Mon Jul  8 06:55:06 2013	(r254404)
@@ -33,6 +33,7 @@
 
 PkBackend      *query_backend(struct query *q);
 gboolean	query_do(PkBackend *backend, unsigned int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, query_body_ptr body);
+gboolean	query_do_single(gchar *package_id, PkBackend *backend, struct pkgdb *db, unsigned int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, query_body_ptr body);
 gboolean	query_emit_to_job(struct pkg *pkg, const gchar *id, struct query *q);
 gboolean	query_find_match(struct query *q);
 gboolean	query_init(const gchar *id, PkBackend *backend, struct pkgdb *db, unsigned int load_flags, emit_ptr emitter, pkg_jobs_t job_type, job_emit_ptr job_emitter, struct query **q_p);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201307080655.r686t6f4090728>