socsvn commit: r255157 - in soc2013/mattbw/backend: . actions query
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Thu Jul 25 12:51:35 UTC 2013
Author: mattbw
Date: Thu Jul 25 12:51:34 2013
New Revision: 255157
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255157
Log:
last two commits accidentally implemented UpdateSystem; moving to rectify; moving out some jobs code that isn't dependent on query in preparation
Added:
soc2013/mattbw/backend/actions/update_system.c
soc2013/mattbw/backend/jobs.c
soc2013/mattbw/backend/jobs.h
Modified:
soc2013/mattbw/backend/Makefile
soc2013/mattbw/backend/actions.h
soc2013/mattbw/backend/query/jobs.c
soc2013/mattbw/backend/query/jobs.h
Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile Thu Jul 25 12:07:48 2013 (r255156)
+++ soc2013/mattbw/backend/Makefile Thu Jul 25 12:51:34 2013 (r255157)
@@ -27,6 +27,7 @@
event.c \
group.c \
group_map.c \
+ jobs.c \
licenses.c \
pkgutils.c \
search.c \
Modified: soc2013/mattbw/backend/actions.h
==============================================================================
--- soc2013/mattbw/backend/actions.h Thu Jul 25 12:07:48 2013 (r255156)
+++ soc2013/mattbw/backend/actions.h Thu Jul 25 12:51:34 2013 (r255157)
@@ -43,7 +43,7 @@
gboolean simulate_install_files_thread(PkBackend *backend);
gboolean simulate_install_packages_thread(PkBackend *backend);
gboolean simulate_remove_packages_thread(PkBackend *backend);
-gboolean simulate_update_packages_thread(PkBackend *backend);
-gboolean update_packages_thread(PkBackend *backend);
+gboolean simulate_update_system_thread(PkBackend *backend);
+gboolean update_system_thread(PkBackend *backend);
#endif /* !_PKGNG_BACKEND_ACTIONS_H_ */
Added: soc2013/mattbw/backend/actions/update_system.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/actions/update_system.c Thu Jul 25 12:51:34 2013 (r255157)
@@ -0,0 +1,100 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at 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 <assert.h> /* assert */
+#include <glib.h> /* gboolean */
+#include <stdbool.h> /* bool, true, false */
+#include "../pk-backend.h" /* pk..., Pk... */
+#include "pkg.h" /* pkg... */
+
+#include "../actions.h" /* update_packages_thread prototype */
+#include "../pkgutils.h" /* pkgutils_... */
+#include "../query.h" /* query_... */
+
+static bool job(struct pkg_jobs *jobs, struct query *q);
+static bool sim_job(struct pkg_jobs *jobs, struct query *q);
+
+/*
+ * The thread that performs an UpdatePackages operation. Should be invoked
+ * by the pk_backend_update_packages hook.
+ */
+gboolean
+update_packages_thread(PkBackend *backend)
+{
+ bool success;
+
+ assert(backend != NULL);
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ success = query_match_id_to_job(backend, PKG_JOBS_INSTALL, job);
+
+ (void)pk_backend_finished(backend);
+ return success ? TRUE : FALSE;
+}
+
+/*
+ * The thread that performs a SimulateUpdatePackages operation. Should be
+ * invoked by the pk_backend_simulate_update_packages hook.
+ */
+gboolean
+simulate_update_packages_thread(PkBackend *backend)
+{
+ bool success;
+
+ assert(backend != NULL);
+
+ (void)pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
+ success = query_match_id_to_job(backend, PKG_JOBS_UPGRADE, sim_job);
+
+ (void)pk_backend_finished(backend);
+ return success ? TRUE : FALSE;
+}
+
+/*
+ * Tries to process the given solved installation jobs.
+ */
+static bool
+job(struct pkg_jobs *jobs, struct query *q)
+{
+
+ assert(jobs != NULL);
+ assert(q != NULL);
+
+ return query_jobs_apply_emitter(jobs,
+ q,
+ PK_STATUS_ENUM_UPDATE,
+ PK_ERROR_ENUM_NO_PACKAGES_TO_UPDATE,
+ PK_ERROR_ENUM_PACKAGE_FAILED_TO_INSTALL);
+}
+
+/*
+ * Tries to simulate processing the given installation jobs.
+ */
+static bool
+sim_job(struct pkg_jobs *jobs, struct query *q)
+{
+
+ assert(jobs != NULL);
+ assert(q != NULL);
+
+ return query_jobs_simulate_emitter(jobs,
+ q,
+ pkgutils_pkg_install_state);
+}
Added: soc2013/mattbw/backend/jobs.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/jobs.c Thu Jul 25 12:51:34 2013 (r255157)
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at 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.
+ */
+
+/* Helpers for jobs that don't rely on the query system. */
+
+#include <assert.h> /* assert */
+#include "pk-backend.h" /* pk_..., Pk... */
+#include "pkg.h" /* pkg_... */
+
+#include "pkgutils.h" /* pkgutils_... */
+#include "jobs.h" /* jobs_... */
+
+/* Emits each package queued up in a (solved) job. */
+void
+jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend,
+ pkg_info_ptr info)
+{
+ struct pkg *pkg;
+
+ assert(jobs != NULL);
+ assert(backend != NULL);
+ assert(info != NULL);
+
+ pkg = NULL;
+ while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
+ assert(pkg != NULL);
+ pkgutils_emit(pkg, backend, info(pkg));
+ }
+}
Added: soc2013/mattbw/backend/jobs.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ soc2013/mattbw/backend/jobs.h Thu Jul 25 12:51:34 2013 (r255157)
@@ -0,0 +1,31 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw at 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.
+ */
+
+#ifndef _PKGNG_BACKEND_JOBS_H_
+#define _PKGNG_BACKEND_JOBS_H_
+
+#include <glib.h> /* gboolean */
+#include "pk-backend.h" /* PkBackend */
+
+typedef PkInfoEnum (*pkg_info_ptr) (struct pkg *pkg);
+
+void jobs_emit_packages(struct pkg_jobs *jobs, PkBackend *backend, pkg_info_ptr info);
+
+#endif /* !_PKGNG_BACKEND_JOBS_H_ */
Modified: soc2013/mattbw/backend/query/jobs.c
==============================================================================
--- soc2013/mattbw/backend/query/jobs.c Thu Jul 25 12:07:48 2013 (r255156)
+++ soc2013/mattbw/backend/query/jobs.c Thu Jul 25 12:51:34 2013 (r255157)
@@ -24,6 +24,7 @@
#include "pkg.h" /* pkg... */
#include "../event.h" /* event_... */
+#include "../jobs.h" /* jobs_... */
#include "../pkgutils.h" /* pkgutils_... */
#include "../utils.h" /* ERR */
#include "core.h" /* query_... */
@@ -139,24 +140,20 @@
pkg_info_ptr info)
{
PkBackend *backend;
- struct pkg *pkg;
assert(jobs != NULL);
assert(q != NULL);
+ assert(info != NULL);
backend = query_backend(q);
assert (backend != NULL);
- query_set_percentage(q, 0);
- (void)pk_backend_set_status(backend, PK_STATUS_ENUM_RUNNING);
- pkg = NULL;
- while (pkg_jobs(jobs, &pkg) == EPKG_OK) {
- assert(pkg != NULL);
- pkgutils_emit(pkg, backend, info(pkg));
- }
+ query_set_percentage(q, 0);
+ STATUS(backend, PK_STATUS_ENUM_RUNNING);
+ jobs_emit_packages(jobs, backend, info);
+ query_set_percentage(q, 100);
pkg_jobs_free(jobs);
- query_set_percentage(q, 100);
return true;
}
Modified: soc2013/mattbw/backend/query/jobs.h
==============================================================================
--- soc2013/mattbw/backend/query/jobs.h Thu Jul 25 12:07:48 2013 (r255156)
+++ soc2013/mattbw/backend/query/jobs.h Thu Jul 25 12:51:34 2013 (r255157)
@@ -23,10 +23,9 @@
#include "pkg.h" /* struct pkg */
+#include "../jobs.h" /* pk_info_ptr */
#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);
More information about the svn-soc-all
mailing list