socsvn commit: r254748 - in soc2013/mattbw/backend: . actions query

mattbw at FreeBSD.org mattbw at FreeBSD.org
Sat Jul 13 10:26:13 UTC 2013


Author: mattbw
Date: Sat Jul 13 10:26:13 2013
New Revision: 254748
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=254748

Log:
  generalise job payloads ready for remove_packages

Modified:
  soc2013/mattbw/backend/actions/install_packages.c
  soc2013/mattbw/backend/actions/remove_packages.c
  soc2013/mattbw/backend/query.h
  soc2013/mattbw/backend/query/core.h
  soc2013/mattbw/backend/query/jobs.c
  soc2013/mattbw/backend/query/jobs.h

Modified: soc2013/mattbw/backend/actions/install_packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/install_packages.c	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/actions/install_packages.c	Sat Jul 13 10:26:13 2013	(r254748)
@@ -70,30 +70,12 @@
 static bool
 job(struct pkg_jobs *jobs, struct query *q)
 {
-	bool		success;
-	PkBackend      *backend;
 
-	success = false;
-	backend = query_backend(q);
-	query_set_percentage(q, 0);
-
-	pkg_event_register(event_cb, backend);
-
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_INSTALL);
-	if (pkg_jobs_count(jobs) == 0)
-		ERR(backend,
-		    PK_ERROR_ENUM_PACKAGE_ALREADY_INSTALLED,
-		    "nothing to do");			
-	else if (pkg_jobs_apply(jobs) != EPKG_OK)
-		ERR(backend,
-		    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL,
-		    "job failed");
-	else
-		success = true;
-
-	pkg_event_register(NULL, NULL);
-	query_set_percentage(q, 100);
-	return success;
+	return query_jobs_apply_emitter(jobs,
+	    q,
+	    PK_STATUS_ENUM_INSTALL,
+	    PK_ERROR_ENUM_PACKAGE_ALREADY_INSTALLED,
+	    PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL);
 }
 
 /*
@@ -102,22 +84,8 @@
 static bool
 sim_job(struct pkg_jobs *jobs, struct query *q)
 {
-	bool		success;
-	PkBackend      *backend;
-	struct pkg     *pkg;
-
-	backend = query_backend(q);
-	query_set_percentage(q, 0);
-
-	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
-	pkg = NULL;
-	while (pkg_jobs(jobs, &pkg) == EPKG_OK)
-		pkgutils_emit(pkg,
-		    backend,
-		    pkgutils_pkg_install_state(pkg));
-
-	success = true;
 
-	query_set_percentage(q, 100);
-	return success;
+	return query_jobs_simulate_emitter(jobs,
+	    q,
+	    pkgutils_pkg_install_state);
 }

Modified: soc2013/mattbw/backend/actions/remove_packages.c
==============================================================================
--- soc2013/mattbw/backend/actions/remove_packages.c	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/actions/remove_packages.c	Sat Jul 13 10:26:13 2013	(r254748)
@@ -78,18 +78,18 @@
 	backend = query_backend(q);
 	query_set_percentage(q, 0);
 
-	if (solve_job(q, jobs) == false)
-		goto cleanup;
-
 	pkg_event_register(event_cb, backend);
 
 	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_REMOVE);
-	if (pkg_jobs_apply(jobs) != EPKG_OK) {
+	if (pkg_jobs_count(jobs) == 0)
+		ERR(backend,
+		    PK_RROR_ENUM_PACKAGE_NOT_INSTALLED,
+		    "nothing to do");
+	else if (pkg_jobs_apply(jobs) != EPKG_OK)
 		ERR(backend,
 		    PK_ERROR_ENUM_PACKAGE_FAILED_TO_REMOVE,
 		    "job failed");
-		goto cleanup;
-	}
+	else
 	success = true;
 
 cleanup:

Modified: soc2013/mattbw/backend/query.h
==============================================================================
--- soc2013/mattbw/backend/query.h	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/query.h	Sat Jul 13 10:26:13 2013	(r254748)
@@ -24,6 +24,7 @@
 /* Meta-header for the public interfaces to the query system. */
 
 #include "query/do.h"		/* query_do_... */
+#include "query/jobs.h"		/* query_jobs_... */
 #include "query/match.h"	/* query_match_... */
 
 #endif				/* !_PKGNG_BACKEND_QUERY_H_ */

Modified: soc2013/mattbw/backend/query/core.h
==============================================================================
--- soc2013/mattbw/backend/query/core.h	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/query/core.h	Sat Jul 13 10:26:13 2013	(r254748)
@@ -31,11 +31,14 @@
 typedef		bool   (*job_emit_ptr) (struct pkg_jobs *jobs, struct query *q);
 typedef		bool   (*query_body_ptr) (struct query *q);
 
+/*
+ * Types of query source.
+ */
 enum query_source_type {
-	QUERY_SINGLE_ID,
-	QUERY_SINGLE_NAME,
-	QUERY_BACKEND_IDS,
-	QUERY_BACKEND_MIXED
+	QUERY_SINGLE_ID,	/* Expect one (strict) PackageID. */
+	QUERY_SINGLE_NAME,	/* Expect one package name or name-version. */
+	QUERY_BACKEND_IDS,	/* Use the backend "package_ids" strv. */
+	QUERY_BACKEND_MIXED	/* As above but treat non-PackeIDs as names. */
 };
 
 enum query_target_type {

Modified: soc2013/mattbw/backend/query/jobs.c
==============================================================================
--- soc2013/mattbw/backend/query/jobs.c	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/query/jobs.c	Sat Jul 13 10:26:13 2013	(r254748)
@@ -23,6 +23,8 @@
 #include "../pk-backend.h"	/* pk..., Pk... */
 #include "pkg.h"		/* pkg... */
 
+#include "../event.h"		/* event_... */
+#include "../pkgutils.h"	/* pkgutils_... */
 #include "../utils.h"		/* ERR */
 #include "core.h"		/* query_... */
 #include "jobs.h"		/* query_jobs_... */
@@ -31,6 +33,36 @@
 static int	repo_from_query(struct pkg_jobs *jobs, struct query *q);
  
 /*
+ * Generic emitter helper for applying a job with typical failure conditions,
+ * the standard event handler, and PackageKit backend boilerplate.
+ */
+bool
+query_jobs_apply_emitter(struct pkg_jobs *jobs, struct query *q,
+    PkStatusEnum status, PkErrorEnum no_jobs, PkErrorEnum job_failed)
+{
+	bool		success;
+	PkBackend      *backend;
+
+	success = false;
+	backend = query_backend(q);
+	query_set_percentage(q, 0);
+
+	pkg_event_register(event_cb, backend);
+
+	(void)pk_backend_set_status(backend, status);
+	if (pkg_jobs_count(jobs) == 0)
+		ERR(backend, no_jobs, "nothing to do");
+	else if (pkg_jobs_apply(jobs) != EPKG_OK)
+		ERR(backend, job_failed, "job failed");
+	else
+		success = true;
+
+	pkg_event_register(NULL, NULL);
+	query_set_percentage(q, 100);
+	return success;
+}
+
+/*
  * Creates a job of type "type" for the given package, solves it, and sends it
  * to the emitter function "f" alongside its parent query.
  */
@@ -83,6 +115,29 @@
 	return success;
 }
 
+/*
+ * Like query_jobs_apply_emitter, but just emits all the packages with the
+ * information field taken from info(pkg).
+ */
+bool
+query_jobs_simulate_emitter(struct pkg_jobs *jobs, struct query *q,
+    pkg_info_ptr info)
+{
+	PkBackend      *backend;
+	struct pkg     *pkg;
+
+	backend = query_backend(q);
+	query_set_percentage(q, 0);
+
+	(void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
+	pkg = NULL;
+	while (pkg_jobs(jobs, &pkg) == EPKG_OK)
+		pkgutils_emit(pkg, backend, info(pkg));
+
+	query_set_percentage(q, 100);
+	return true;    	
+}
+
 /* Adds a single package to a jobs structure. */
 static int
 add_pkg(struct pkg_jobs *jobs, match_t type, struct pkg *pkg)

Modified: soc2013/mattbw/backend/query/jobs.h
==============================================================================
--- soc2013/mattbw/backend/query/jobs.h	Sat Jul 13 08:17:55 2013	(r254747)
+++ soc2013/mattbw/backend/query/jobs.h	Sat Jul 13 10:26:13 2013	(r254748)
@@ -25,6 +25,10 @@
 
 #include "core.h"		/* struct query */
 
+typedef		PkInfoEnum (*pkg_info_ptr) (struct pkg *pkg);
+
+bool	query_jobs_apply_emitter(struct pkg_jobs *jobs, struct query *q, PkStatusEnum status, PkErrorEnum no_jobs, PkErrorEnum job_failed);
 bool	query_jobs_run(struct query *q, struct pkg *pkg, pkg_jobs_t type, job_emit_ptr f);
+bool	query_jobs_simulate_emitter(struct pkg_jobs *jobs, struct query *q, pkg_info_ptr info);
 
 #endif				/* !_PKGNG_BACKEND_QUERY_JOBS_H_ */


More information about the svn-soc-all mailing list