From owner-svn-soc-all@FreeBSD.ORG Tue Jun 25 21:40:23 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id D5FDCBB5 for ; Tue, 25 Jun 2013 21:40:23 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id B76E218C7 for ; Tue, 25 Jun 2013 21:40:23 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5PLeN79010000 for ; Tue, 25 Jun 2013 21:40:23 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5PLeNVa009980 for svn-soc-all@FreeBSD.org; Tue, 25 Jun 2013 21:40:23 GMT (envelope-from mattbw@FreeBSD.org) Date: Tue, 25 Jun 2013 21:40:23 GMT Message-Id: <201306252140.r5PLeNVa009980@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253500 - in soc2013/mattbw/backend: . actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 25 Jun 2013 21:40:23 -0000 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_ */