socsvn commit: r256217 - soc2013/mattbw/backend/query

mattbw at FreeBSD.org mattbw at FreeBSD.org
Tue Aug 20 19:47:53 UTC 2013


Author: mattbw
Date: Tue Aug 20 19:47:52 2013
New Revision: 256217
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256217

Log:
  (still broken) Flesh out the template from last commit.
  
  Focus will be on creating a new function, "query_match_ids", which takes a
  list of QueryIDs and a database, and returns a list of packages if and only
  if all QueryIDs could be matched to packages.
  

Modified:
  soc2013/mattbw/backend/query/match.c

Modified: soc2013/mattbw/backend/query/match.c
==============================================================================
--- soc2013/mattbw/backend/query/match.c	Tue Aug 20 19:23:56 2013	(r256216)
+++ soc2013/mattbw/backend/query/match.c	Tue Aug 20 19:47:52 2013	(r256217)
@@ -26,6 +26,10 @@
 #include "match.h"		/* query_match_... */
 
 
+static bool emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter, struct pkg *packages, unsigned int count);
+static bool query_with_db(struct pkgdb *db, PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
+
+
 /*
  * Runs a query over the PackageIDs selected in the backend that sends the
  * first match to an emitting function.
@@ -35,14 +39,38 @@
     emit_ptr emitter)
 {
 	bool		success;
+
+	assert(backend != NULL);
+	assert(emitter != NULL);
+
+	success = false;
+
+	db = db_open_remote(backend);
+	if (db != NULL) {
+		success = query_with_db(db, backend, load_flags, emitter);
+
+		db_close(&db);
+	}
+	return success;
+}
+
+static bool
+query_with_db(struct pkgdb *db, PkBackend *backend, unsigned int load_flags,
+    emit_ptr emitter)
+{
+	bool		success;
 	guint		count;
-	gchar	      **package_ids;
+	struct pkg     *packages;
+	struct pkgdb   *db;
 	struct query_id *query_ids;
+	gchar	      **package_ids;
 
 	assert(backend != NULL);
+	assert(db != NULL);
 	assert(emitter != NULL);
 
 	success = false;
+	packages = NULL;
 
 	package_ids = pk_backend_get_strv("package_ids");
 	assert(package_ids != NULL);
@@ -50,7 +78,35 @@
 
 	query_ids = query_id_array_from_package_ids(package_ids, count);
 	if (query_ids != NULL) {
-		/* More stuff here */
+		packages = query_match_ids(query_ids, count, load_flags);
+	}
+
+	if (packages != NULL) {
+		success = emit_packages(backend, db, emitter, packages, count);
+		query_free_packages(packages, count);
+	}
+
+	return success;
+}
+
+static bool
+emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter,
+    struct pkg *packages, unsigned int count)
+{
+	bool		success;
+	unsigned int	i;
+
+	assert(backend != NULL);
+	assert(db != NULL);
+	assert(emitter != NULL);
+	assert(packages != NULL);
+
+	success = true;
+	for (i = 0; i < count; i++) {
+		success = emitter(backend, packages + i);
+		if (success = false) {
+			break;
+		}
 	}
 
 	return success;


More information about the svn-soc-all mailing list