Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jun 2013 21:40:23 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r253500 - in soc2013/mattbw/backend: . actions
Message-ID:  <201306252140.r5PLeNVa009980@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Tue Jun 25 21:40:23 2013
New Revision: 253500
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253500

Log:
  move more iterating boilerplate to iterate

Modified:
  soc2013/mattbw/backend/actions/get-details.c
  soc2013/mattbw/backend/iterate.c
  soc2013/mattbw/backend/iterate.h

Modified: soc2013/mattbw/backend/actions/get-details.c
==============================================================================
--- soc2013/mattbw/backend/actions/get-details.c	Tue Jun 25 21:16:01 2013	(r253499)
+++ soc2013/mattbw/backend/actions/get-details.c	Tue Jun 25 21:40:23 2013	(r253500)
@@ -23,7 +23,6 @@
 #include "../pk-backend.h"
 #include "pkg.h"
 
-#include "../db.h"		/* open_remote_db */
 #include "../groups.h"		/* group_from_origin */
 #include "../iterate.h"		/* Package iteration */
 #include "../licenses.h"	/* license_from_pkg */
@@ -47,6 +46,15 @@
 		PkBackend *backend,
 		struct pkgdb *db);
 
+/*
+ * The thread that performs a GetDetails operation. Should be invoked by the
+ * pk_backend_get_details hook.
+ */
+gboolean
+get_details_thread(PkBackend *backend)
+{
+	return iterate_ids(backend, get_details_for);
+}
 
 /*
  * Emits the given package's details. To be used as an iterating function.
@@ -192,33 +200,4 @@
 	return success;
 }
 
-/*
- * The thread that performs a GetDetails operation. Should be invoked by the
- * pk_backend_get_details hook.
- */
-gboolean
-get_details_thread(PkBackend *backend)
-{
-	gboolean	no_error_yet;
-	gchar         **package_ids;
-	guint		len;
-	guint		i;
-	struct pkgdb   *db;
-
-
-	package_ids = pk_backend_get_strv(backend, "package_ids");
-	len = g_strv_length(package_ids);
-
-	db = NULL;
-	no_error_yet = open_remote_db(&db, backend);
-
-	pk_backend_set_percentage(backend, 0);
-	for (i = 0; i < len && no_error_yet; i++) {
-		no_error_yet = get_details_for(package_ids[i], backend, db);
-		pk_backend_set_percentage(backend, ((i * 100) / len));
-	}
-	pkgdb_close(db);
 
-	pk_backend_finished(backend);
-	return no_error_yet;
-}

Modified: soc2013/mattbw/backend/iterate.c
==============================================================================
--- soc2013/mattbw/backend/iterate.c	Tue Jun 25 21:16:01 2013	(r253499)
+++ soc2013/mattbw/backend/iterate.c	Tue Jun 25 21:40:23 2013	(r253500)
@@ -25,6 +25,8 @@
 
 #include "iterate.h"		/* Prototypes */
 
+#include "db.h"		/* open_remote_db */
+
 static gboolean
 try_id_match(struct pkg *pkg, const gchar *name, const gchar *version, const
 	     gchar *arch, const gchar *data, gchar **match_id);
@@ -39,7 +41,7 @@
 		   const gchar *arch,
 		   const gchar *data,
 		   int fetch_flags,
-		   iterate_f_pointer iterate_f)
+		   pkg_func_ptr iterate_f)
 {
 	/* TODO: Filters */
 	gboolean	found;
@@ -130,3 +132,37 @@
 
 	return result;
 }
+
+/* Iterates over a set of PackageIDs provided for this job with a function.
+ *
+ * This provides each iterating function call with an open database connection
+ * and updates the percentage after each iteration.
+ *
+ * It also *finishes* the backend job.
+ */
+gboolean
+iterate_ids(PkBackend *backend, ids_func_ptr iterate_f)
+{
+	gboolean	no_error_yet;
+	gchar         **package_ids;
+	guint		len;
+	guint		i;
+	struct pkgdb   *db;
+
+	package_ids = pk_backend_get_strv(backend, "package_ids");
+	len = g_strv_length(package_ids);
+
+	db = NULL;
+	no_error_yet = open_remote_db(&db, backend);
+
+	pk_backend_set_percentage(backend, 0);
+	for (i = 0; i < len && no_error_yet; i++) {
+		no_error_yet = iterate_f(package_ids[i], backend, db);
+		pk_backend_set_percentage(backend, ((i * 100) / len));
+	}
+	pkgdb_close(db);
+
+	pk_backend_finished(backend);
+
+	return no_error_yet;
+}

Modified: soc2013/mattbw/backend/iterate.h
==============================================================================
--- soc2013/mattbw/backend/iterate.h	Tue Jun 25 21:16:01 2013	(r253499)
+++ soc2013/mattbw/backend/iterate.h	Tue Jun 25 21:40:23 2013	(r253500)
@@ -25,9 +25,10 @@
 #include "pk-backend.h"
 #include "pkg.h"
 
-typedef void    (*iterate_f_pointer) (struct pkg *pkg,
+typedef void    (*pkg_func_ptr) (struct pkg *pkg,
 				      		const		char  *id,
 				      		PkBackend    *backend);
+typedef gboolean    (*ids_func_ptr) (gchar *id, PkBackend    *backend, struct pkgdb *db);
 
 gboolean
 iterate_id_matches(struct pkgdb_it *iterator,
@@ -37,6 +38,7 @@
 		   const gchar *arch,
 		   const gchar *data,
 		   int fetch_flags,
-		   iterate_f_pointer iterate_f);
+		   pkg_func_ptr iterate_f);
+gboolean iterate_ids(PkBackend *backend, ids_func_ptr iterate_f);
 
 #endif				/* !_PKGNG_BACKEND_ITERATE_H_ */



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