socsvn commit: r256507 - in soc2013/mattbw/backend: . actions query
mattbw at FreeBSD.org
mattbw at FreeBSD.org
Sun Aug 25 12:15:23 UTC 2013
Author: mattbw
Date: Sun Aug 25 12:15:23 2013
New Revision: 256507
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256507
Log:
(Still broken) Make resolve.c work.
Nothing else does, though. Sorry!
Modified:
soc2013/mattbw/backend/Makefile
soc2013/mattbw/backend/actions/resolve.c
soc2013/mattbw/backend/db.c
soc2013/mattbw/backend/db.h
soc2013/mattbw/backend/query/do.c
soc2013/mattbw/backend/query/do.h
soc2013/mattbw/backend/query/match.h
Modified: soc2013/mattbw/backend/Makefile
==============================================================================
--- soc2013/mattbw/backend/Makefile Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/Makefile Sun Aug 25 12:15:23 2013 (r256507)
@@ -51,10 +51,10 @@
actions/update_system.c
SRCS+= \
- query/core.c \
- query/depends.c \
query/do.c \
- query/match.c
+ query/id.c \
+ query/match.c \
+ query/packages.c
SRCS+= \
jobs/check.c \
Modified: soc2013/mattbw/backend/actions/resolve.c
==============================================================================
--- soc2013/mattbw/backend/actions/resolve.c Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/actions/resolve.c Sun Aug 25 12:15:23 2013 (r256507)
@@ -17,7 +17,8 @@
* 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 <stdbool.h> /* bool, true, false */
#include "../pk-backend.h"
#include "pkg.h"
@@ -27,8 +28,7 @@
#include "../utils.h" /* INTENTIONALLY_IGNORE */
#include "../actions.h" /* resolve_thread prototype */
-static bool emit(struct pkg *pkg, const gchar *id, struct query *q);
-static bool query_with_db(struct pkgdb *db, PkBackend *backend);
+static bool emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
/*
* Resolves a package identifier, which may be a full PackageID or a package
@@ -38,72 +38,21 @@
resolve_thread(PkBackend *backend)
{
bool success;
- struct pkgdb *db;
assert(backend != NULL);
- db = db_open_remote(backend);
- if (db != NULL) {
- success = query_with_db(db, backend);
-
- db_close(&db);
- }
-/*
- s.type = QUERY_BACKEND_MIXED;
- t.load_flags = PKG_LOAD_BASIC;
- t.f = emit;
- t.error_if_not_found = true;
-
- success = query_do(backend, &s, &t);
-*/
+ success = query_do_from_backend_names(backend, PKG_LOAD_BASIC, emit);
(void)pk_backend_finished(backend);
return success ? TRUE : FALSE;
}
static bool
-query_with_db(struct pkgdb *db, PkBackend *backend)
+emit(PkBackend *backend, struct pkgdb *db, struct pkg *pkg)
{
- bool success;
- guint count;
- struct query_id *query_ids;
- gchar **names;
- struct pkg **packages;
-
- assert(db != NULL);
- assert(backend != NULL);
-
- success = false;
- names = pk_backend_get_strv("package_ids");
- assert(names != NULL);
- count = g_strv_length(names);
-
- query_ids = query_id_array_from_names(names, count);
- if (query_ids != NULL) {
- packages = query_match_ids(query_ids, count, db,
- PKG_LOAD_BASIC);
- }
-
- if (packages != NULL) {
- success = emit_packages(backend, db, emit, packages, count);
- query_free_packages(packages, count);
- }
+ INTENTIONALLY_IGNORE(db);
- return success;
-}
-
-static bool
-emit(struct pkg *pkg, const gchar *id, struct query *q)
-{
- PkBackend *backend;
-
- INTENTIONALLY_IGNORE(id);
- backend = query_backend(q);
-
- query_set_percentage(q, 0);
pkgutils_emit(pkg, backend, pkgutils_pkg_current_state(pkg));
- query_set_percentage(q, 100);
-
return true;
}
Modified: soc2013/mattbw/backend/db.c
==============================================================================
--- soc2013/mattbw/backend/db.c Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/db.c Sun Aug 25 12:15:23 2013 (r256507)
@@ -38,9 +38,9 @@
* Opens a pkgdb ready for remote operations. This will always return TRUE if
* and only if a database ready for use is now pointed to by *db, and FALSE
* if and only if there isn't.
- *
+ *
* This will also emit PackageKit errors if it fails.
- *
+ *
* This must be called during the lifetime of "backend", eg after
* "pk_backend_initialize" and before "pk_backend_destroy".
*/
@@ -62,6 +62,20 @@
return db;
}
+void
+db_close(struct pkgdb **db_p)
+{
+
+ assert(db_p != NULL);
+
+ if (*db_p != NULL) {
+ pkgdb_close(*db_p);
+ *db_p = NULL;
+ }
+
+ assert(*db_p == NULL);
+}
+
static bool
has_remote_access(PkBackend *backend)
{
Modified: soc2013/mattbw/backend/db.h
==============================================================================
--- soc2013/mattbw/backend/db.h Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/db.h Sun Aug 25 12:15:23 2013 (r256507)
@@ -25,5 +25,6 @@
#include "pkg.h" /* struct pkgdb */
struct pkgdb *db_open_remote(PkBackend *backend);
+void db_close(struct pkgdb **db_p);
#endif /* !_PKGNG_BACKEND_DB_H_ */
Modified: soc2013/mattbw/backend/query/do.c
==============================================================================
--- soc2013/mattbw/backend/query/do.c Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/query/do.c Sun Aug 25 12:15:23 2013 (r256507)
@@ -31,8 +31,12 @@
#include "do.h" /* query_do_... */
#include "core.h" /* query_... */
+typedef struct query_id (*query_id_func_ptr) (gchar **strings, guint count);
+
static bool emit_packages(PkBackend *backend, struct pkgdb *db, emit_ptr emitter, struct pkg *packages, unsigned int count);
+static bool query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags, emit_ptr emitter, query_id_func_ptr to_query_ids)
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.
@@ -40,9 +44,40 @@
* This is a wrapper over several lower level query functions.
*/
bool
-query_do_from_backend(PkBackend *backend, unsigned int load_flags,
+query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags,
emit_ptr emitter)
{
+
+ assert(backend != NULL);
+ assert(emitter != NULL);
+
+ return query_do_from_backend(backend, load_flags, emitter,
+ query_id_array_from_package_ids);
+}
+
+
+/*
+ * Runs a query over the package names selected in the backend that sends the
+ * first match to an emitting function.
+ *
+ * This is a wrapper over several lower level query functions.
+ */
+bool
+query_do_from_backend_names(PkBackend *backend, unsigned int load_flags,
+ emit_ptr emitter)
+{
+
+ assert(backend != NULL);
+ assert(emitter != NULL);
+
+ return query_do_from_backend(backend, load_flags, emitter,
+ query_id_array_from_names);
+}
+
+static bool
+query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags,
+ emit_ptr emitter, query_id_func_ptr to_query_ids)
+{
bool success;
struct pkgdb *db;
@@ -53,7 +88,8 @@
db = db_open_remote(backend);
if (db != NULL) {
- success = query_with_db(db, backend, load_flags, emitter);
+ success = query_with_db(db, backend, load_flags, emitter,
+ to_query_ids);
db_close(&db);
}
Modified: soc2013/mattbw/backend/query/do.h
==============================================================================
--- soc2013/mattbw/backend/query/do.h Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/query/do.h Sun Aug 25 12:15:23 2013 (r256507)
@@ -23,10 +23,10 @@
#include <stdbool.h>
#include "../pk-backend.h"
-#include "pkg.h"
-#include "core.h" /* struct query_... */
+typedef bool (*emit_ptr) (PkBackend *backend, struct pkgdb *db, struct pkg *pkg);
-bool query_do (PkBackend *backend, struct query_source *s, struct query_target *t);
+bool query_do_from_backend_ids(PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
+bool query_do_from_backend_names(PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
#endif /* !_PKGNG_BACKEND_QUERY_DO_H_ */
Modified: soc2013/mattbw/backend/query/match.h
==============================================================================
--- soc2013/mattbw/backend/query/match.h Sun Aug 25 11:42:53 2013 (r256506)
+++ soc2013/mattbw/backend/query/match.h Sun Aug 25 12:15:23 2013 (r256507)
@@ -22,11 +22,11 @@
#define _PKGNG_BACKEND_QUERY_MATCH_H_
#include <stdbool.h>
-#include "../pk-backend.h"
#include "pkg.h"
-#include "core.h" /* *_ptr */
+#include "id.h" /* struct query_id */
-bool query_match_id_to_emitter(PkBackend *backend, unsigned int load_flags, emit_ptr emitter);
+struct pkg **query_match_ids(struct query_id *query_ids, unsigned int count, struct pkgdb *db, int load_flags);
+bool query_match_id(struct pkg **package_p, struct query_id *query_id, struct pkgdb *db, int load_flags);
#endif /* !_PKGNG_BACKEND_QUERY_MATCH_H_ */
More information about the svn-soc-all
mailing list