[PackageKit-commit] packagekit: Branch 'master' - 21 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Wed Apr 30 04:01:57 PDT 2008
backends/alpm/pk-backend-alpm.c | 7
backends/apt/pk-backend-apt.c | 36 -
backends/apt/pk-sqlite-pkg-cache.cpp | 97 --
backends/box/pk-backend-box.c | 334 ++-------
backends/opkg/pk-backend-opkg.c | 695 ++++---------------
backends/poldek/pk-backend-poldek.c | 651 +++++-------------
backends/test/pk-backend-test-thread.c | 63 -
backends/zypp/pk-backend-zypp.cpp | 1166 +++++++++++----------------------
configure.ac | 2
libpackagekit/pk-client.c | 2
src/pk-backend-thread.c | 11
src/pk-backend-thread.h | 6
src/pk-backend.c | 433 +++++++++++-
src/pk-backend.h | 185 ++---
src/pk-security-polkit.c | 2
src/pk-transaction.c | 18
16 files changed, 1466 insertions(+), 2242 deletions(-)
New commits:
commit 0a408b85a3ed688eb3e3b9295e65b22f65f1e3e7
Author: Thomas Wood <thomas at openedhand.com>
Date: Wed Apr 30 11:52:30 2008 +0100
opkg: temporarily switch to pk_backend_thread_create_old
diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
index 4620042..f261c19 100644
--- a/backends/opkg/pk-backend-opkg.c
+++ b/backends/opkg/pk-backend-opkg.c
@@ -198,8 +198,8 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_refresh_cache_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_refresh_cache_thread,
NULL);
}
@@ -297,7 +297,7 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
params->needle = g_utf8_strdown (search, -1);
params->backend = backend;
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFuncOld) backend_search_thread, params);
}
/**
@@ -318,7 +318,7 @@ backend_search_description (PkBackend *backend, PkFilterEnum filters, const gcha
params->search_type = SEARCH_DESCRIPTION;
params->needle = g_utf8_strdown (search, -1);
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFuncOld) backend_search_thread, params);
}
static void
@@ -336,7 +336,7 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *sea
params->search_type = SEARCH_TAG;
params->needle = g_strdup_printf ("group::%s", search);
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFuncOld) backend_search_thread, params);
}
@@ -372,8 +372,8 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
pk_backend_no_percentage_updates (backend);
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_install_package_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_install_package_thread,
g_strdup (package_id));
}
@@ -430,8 +430,8 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
params[1] = GINT_TO_POINTER (allow_deps);
params[2] = GINT_TO_POINTER (autoremove);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_remove_package_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_remove_package_thread,
params);
}
@@ -474,8 +474,8 @@ backend_update_system (PkBackend *backend)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_update_system_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_update_system_thread,
NULL);
}
@@ -523,8 +523,8 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_update_package_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_update_package_thread,
/* TODO: process the entire list */
g_strdup (package_ids[0]));
}
@@ -570,8 +570,8 @@ backend_get_updates (PkBackend *backend, PkFilterEnum filters)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
- (PkBackendThreadFunc) backend_get_updates_thread,
+ pk_backend_thread_create_old (thread,
+ (PkBackendThreadFuncOld) backend_get_updates_thread,
backend);
}
commit 45319b4349d916f7e6b8d49d5366478d35dacafd
Author: Thomas Wood <thomas at openedhand.com>
Date: Wed Apr 30 10:21:04 2008 +0100
opkg: update opkg backend to use new libopkg api
diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
index edc4de0..4620042 100644
--- a/backends/opkg/pk-backend-opkg.c
+++ b/backends/opkg/pk-backend-opkg.c
@@ -24,14 +24,15 @@
#include <glib.h>
#include <string.h>
#include <pk-backend.h>
+#include <pk-backend-thread.h>
#include <pk-debug.h>
#include <pk-package-ids.h>
+#include <pk-enum.h>
-#define OPKG_LIB
-#include <libopkg.h>
+#include <libopkg/opkg.h>
-/* this is implemented in libopkg.a */
-int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
+static PkBackendThread *thread;
+static opkg_t *opkg;
enum {
SEARCH_NAME,
@@ -39,70 +40,20 @@ enum {
SEARCH_TAG
};
-/* global config structures */
-static opkg_conf_t global_conf;
-static args_t args;
-
-/* opkg has no user_data */
-PkBackend *_backend = NULL;
-
-/* Opkg message callback function */
-extern opkg_message_callback opkg_cb_message;
-static gchar *last_error;
-
-/* Opkg progress callback function */
-extern opkg_download_progress_callback opkg_cb_download_progress;
-
-/* Opkg state changed callback function */
-extern opkg_state_changed_callback opkg_cb_state_changed;
-
-int
-opkg_debug (opkg_conf_t *conf, message_level_t level, char *msg)
-{
- if (level == OPKG_NOTICE)
- pk_debug ("OPKG Notice: %s", msg);
- if (level == OPKG_ERROR)
- pk_warning ("OPKG Error: %s", msg);
-
- /* print messages only if in verbose mode */
- if (level < OPKG_NOTICE && pk_debug_enabled ())
- printf ("OPKG: %s", msg);
-
- /* free the last error message and store the new one */
- if (level == OPKG_ERROR) {
- g_free (last_error);
- last_error = g_strdup (msg);
- }
- return 0;
-}
-
-void
-pk_opkg_state_changed (opkg_state_t state, const char *data)
-{
-_ /* data is conveniently in pkgid format :-) */
- switch (state) {
- case OPKG_STATE_DOWNLOADING_PKG:
- pk_backend_package (_backend, PK_INFO_ENUM_DOWNLOADING, data, NULL);
- break;
- case OPKG_STATE_INSTALLING_PKG:
- pk_backend_package (_backend, PK_INFO_ENUM_INSTALLING, data, NULL);
- break;
- case OPKG_STATE_REMOVING_PKG:
- pk_backend_package (_backend, PK_INFO_ENUM_REMOVING, data, NULL);
- break;
- case OPKG_STATE_UPGRADING_PKG:
- pk_backend_package (_backend, PK_INFO_ENUM_UPDATING, data, NULL);
- break;
- default: return;
- }
-}
+/* parameters passed to the search thread */
+typedef struct {
+ gint search_type;
+ gchar *needle;
+ PkFilterEnum filters;
+ PkBackend *backend;
+} SearchParams;
static void
opkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
{
gchar *msg;
- msg = g_strdup_printf ("%s failed with error code %d. Last message was:\n\n%s", failed_cmd, error_code, last_error);
+ msg = g_strdup_printf ("%s failed with error code %d", failed_cmd, error_code);
pk_backend_error_code (backend, PK_ERROR_ENUM_UNKNOWN, msg);
g_free (msg);
@@ -114,14 +65,20 @@ opkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
* check an opkg package for known GUI dependancies
*/
static gboolean
-opkg_is_gui_pkg (pkg_t *pkg)
+opkg_is_gui_pkg (opkg_package_t *pkg)
{
- gint i;
- for (i = 0; i < pkg->depends_count; i++) {
- if (g_strrstr (pkg->depends_str[i], "gtk"))
- return TRUE;
- }
- return FALSE;
+
+ /* TODO: check appropriate tag */
+
+ /*
+ gint i;
+ for (i = 0; i < pkg->depends_count; i++)
+ {
+ if (g_strrstr (pkg->depends_str[i], "gtk"))
+ return TRUE;
+ }
+ */
+ return FALSE;
}
/**
@@ -130,57 +87,18 @@ opkg_is_gui_pkg (pkg_t *pkg)
* check an opkg package to determine if it is a development package
*/
static gboolean
-opkg_is_devel_pkg (pkg_t *pkg)
+opkg_is_devel_pkg (opkg_package_t *pkg)
{
- if (g_strrstr (pkg->name, "-dev"))
- return TRUE;
- if (g_strrstr (pkg->name, "-dbg"))
- return TRUE;
- if (g_strrstr (pkg->section, "devel"))
- return TRUE;
- return FALSE;
-}
-
-/**
- * opkg_vec_find_latest:
- *
- * search a pkg_vec for the latest version of a package
- */
+ if (g_strrstr (pkg->name, "-dev"))
+ return TRUE;
-static pkg_t*
-opkg_vec_find_latest_helper (pkg_vec_t *vec, pkg_t *pkg)
-{
- gint i;
- for (i = 0; i < vec->len; i++) {
- /* if the version found is newer, return it */
- if (pkg_compare_versions (pkg, vec->pkgs[i]) > 0)
- return vec->pkgs[i];
- }
- /* return NULL if there is no package newer than pkg */
- return NULL;
-}
-
-static pkg_t*
-opkg_vec_find_latest (pkg_vec_t *vec)
-{
- gint i;
- pkg_t *tmp, *ret;
-
- if (vec->len < 1)
- return NULL;
- if (vec->len == 1)
- return vec->pkgs[0];
-
- ret = tmp = vec->pkgs[0];
-
- for (i = 0; i < vec->len; i++) {
- tmp = opkg_vec_find_latest_helper (vec, ret);
- if (!tmp)
- return ret;
- else
- ret = tmp;
- }
- return NULL;
+ if (g_strrstr (pkg->name, "-dbg"))
+ return TRUE;
+/*
+ if (g_strrstr (pkg->section, "devel"))
+ return TRUE;
+*/
+ return FALSE;
}
/**
@@ -190,7 +108,7 @@ opkg_vec_find_latest (pkg_vec_t *vec)
* returns true if the tag is present
*/
gboolean
-opkg_check_tag (pkg_t *pkg, gchar *tag)
+opkg_check_tag (opkg_package_t *pkg, gchar *tag)
{
if (pkg->tags && tag)
return (g_strrstr (pkg->tags, tag) != NULL);
@@ -204,33 +122,26 @@ opkg_check_tag (pkg_t *pkg, gchar *tag)
static void
backend_initialize (PkBackend *backend)
{
- int err;
- /* we have no userdata */
- _backend = backend;
-
- /* Ipkg requires the PATH env variable to be set to find wget when
- * downloading packages. PackageKit unsets all env variables as a
- * security precaution, so we need to set PATH to something sensible
- * here */
- setenv ("PATH", "/usr/sbin:/usr/bin:/sbin:/bin", 1);
+ g_return_if_fail (backend != NULL);
- last_error = NULL;
- opkg_cb_message = opkg_debug;
+ /* we use the thread helper */
+ thread = pk_backend_thread_new ();
- opkg_cb_state_changed = pk_opkg_state_changed;
- memset(&global_conf, 0 ,sizeof(global_conf));
+ opkg = opkg_new ();
- args_init (&args);
+ if (!opkg) {
+ pk_backend_error_code (backend,
+ PK_ERROR_ENUM_FAILED_INITIALIZATION,
+ "Could not start Opkg");
+ return;
+ }
#ifdef OPKG_OFFLINE_ROOT
- args.offline_root = OPKG_OFFLINE_ROOT;
+ opkg_set_option (opkg, "offline_root", OPKG_OFFLINE_ROOT);
+ opkg_re_read_config_files (opkg);
#endif
- err = opkg_conf_init (&global_conf, &args);
- if (err) {
- opkg_unknown_error (backend, err, "Initialization");
- }
}
/**
@@ -239,129 +150,39 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- /* this appears to (sometimes) be freed elsewhere, perhaps
- * by the functions in libopkg.c */
- /* opkg_conf_deinit (&global_conf); */
- args_deinit (&args);
- g_free (last_error);
- last_error = NULL;
-}
-
-static gboolean
-backend_get_description_thread (PkBackend *backend)
-{
- pkg_t *pkg = NULL;
- PkPackageId *pi;
- gboolean ret = TRUE;
- const gchar *package_id;
-
- package_id = pk_backend_get_string (backend, "package_id");
- pi = pk_package_id_new_from_string (package_id);
- if (!pi->name || !pi->version) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "Package not found");
- ret = FALSE;
- goto out;
- }
-
- pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
- if (!pkg) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "Package not found");
- ret = FALSE;
- goto out;
- }
+ g_return_if_fail (backend != NULL);
- pk_backend_description (backend, package_id,
- "unknown", PK_GROUP_ENUM_OTHER, pkg->description, pkg->url, 0);
+ g_object_unref (thread);
-out:
- g_free (package_id);
- pk_backend_finished (backend);
- return ret;
+ opkg_free (opkg);
}
-/**
- * backend_get_description:
- */
-static void
-backend_get_description (PkBackend *backend, const gchar *package_id)
-{
- pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- pk_backend_thread_create (thread, backend_get_description_thread);
-}
static void
-pk_opkg_refresh_cache_progress_cb (int progress, char *url)
+pk_opkg_progress_cb (opkg_t *opkg, int percent, void *data)
{
- static gint sources_list_count = 0;
- static gint total_progress = 0;
- static char *old_url = NULL;
-
- /* this is a bit awkward, but basically in a package refresh there are
- * multiple files to download but we only have a progress callback for
- * each download. To create a combined total progress indication, we
- * have to:
- *
- * 1. calculate the number of files we are downloading
- * 2. notice when the file being downloaded changes, and increase the
- * total progress mark
- * 3. report the progress percentage as a fraction of the current file
- * progress, plus the percentage of files we have already
- * downloaded
- */
-
- /* calculate the number of files we are going to download */
- if (sources_list_count == 0) {
- pkg_src_list_elt_t *p;
- p = global_conf.pkg_src_list.head;
- while (p) {
- sources_list_count++;
- p = p->next;
- };
- }
-
- if (!old_url) {
- old_url = g_strdup (url);
- }
-
- /* increase the total progress mark if we are moving onto the next file */
- if (old_url && url && strcmp (old_url, url)) {
- total_progress += 100 / sources_list_count;
-
- /* store the current url for comparison next time the progress callback
- * is called */
- g_free (old_url);
- old_url = g_strdup (url);
-
- }
-
- /* set the percentage as a fraction of the current progress plus the
- * progress we have already recorded */
- if (total_progress + (progress / sources_list_count) > 100)
+ PkBackend *backend = PK_BACKEND (data);
+ if (!backend)
return;
- pk_backend_set_percentage (_backend,
- total_progress + (progress / sources_list_count));
+ pk_backend_set_percentage (backend, percent);
}
static gboolean
-backend_refresh_cache_thread (PkBackend *backend)
+backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
{
int ret;
+ PkBackend *backend;
- /* set the download progress callback */
- opkg_cb_download_progress = pk_opkg_refresh_cache_progress_cb;
+ /* get current backend */
+ backend = pk_backend_thread_get_backend (thread);
- ret = opkg_lists_update (&args);
+ ret = opkg_update_package_lists (opkg, pk_opkg_progress_cb, backend);
if (ret) {
opkg_unknown_error (backend, ret, "Refreshing cache");
}
pk_backend_finished (backend);
- /* unset the download progress callback */
- opkg_cb_download_progress = NULL;
-
return (ret == 0);
}
@@ -371,105 +192,112 @@ backend_refresh_cache_thread (PkBackend *backend)
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread, backend_refresh_cache_thread);
+
+
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_refresh_cache_thread,
+ NULL);
}
/**
- * backend_search_name:
+ * backend search:
*/
-static gboolean
-backend_search_thread (PkBackend *backend)
+
+static void
+pk_opkg_package_list_cb (opkg_t *opkg, opkg_package_t *pkg, void *data)
{
- int i;
- pkg_vec_t *available;
- pkg_t *pkg;
- gchar *search;
- PkFilterEnum filters;
- guint type;
-
- search = pk_backend_get_string (backend, "needle");
- filters = pk_backend_get_uint (backend, "filters");
- type = pk_backend_get_uint (backend, "type");
-
- available = pkg_vec_alloc();
- pkg_hash_fetch_available (&global_conf.pkg_hash, available);
- for (i=0; i < available->len; i++) {
- char *uid;
- gint status;
- gchar *version;
-
- pkg = available->pkgs[i];
-
- if (search_type == SEARCH_NAME
- && !g_strrstr (pkg->name, search))
- continue;
-
- else if (search_type == SEARCH_DESCRIPTION) {
- gchar *needle, *haystack;
- gboolean match;
- if (pkg->description && search) {
- needle = g_utf8_strdown (search, -1);
- haystack = g_utf8_strdown (pkg->description, -1);
- match = (g_strrstr (haystack, needle_local) != NULL);
- g_free (needle);
- g_free (haystack);
- }
- else
- {
- continue;
- }
+ SearchParams *params = (SearchParams*) data;
+ gchar *uid;
+ gchar *haystack;
+ gint status, match;
+ PkFilterEnum filters = params->filters;
+ if (!pkg->name)
+ return;
+
+ switch (params->search_type)
+ {
+ case SEARCH_NAME:
+ haystack = g_utf8_strdown (pkg->name, -1);
+ match = (g_strrstr (haystack, params->needle) != NULL);
+ g_free (haystack);
+ if (!match)
+ return;
+ break;
+ case SEARCH_DESCRIPTION:
+ haystack = g_utf8_strdown (pkg->description, -1);
+ match = (g_strrstr (haystack, params->needle) != NULL);
+ g_free (haystack);
if (!match)
- continue;
- }
-
- else if (search_type == SEARCH_TAG
- &&
- (!pkg->tags || !g_strrstr (pkg->tags, search)))
- continue;
-
- if ((filters & PK_FILTER_ENUM_DEVEL) && !opkg_is_devel_pkg (pkg))
- continue;
- if ((filters & PK_FILTER_ENUM_NOT_DEVEL) && opkg_is_devel_pkg (pkg))
- continue;
- if ((filters & PK_FILTER_ENUM_GUI) && !opkg_is_gui_pkg (pkg))
- continue;
- if ((filters & PK_FILTER_ENUM_NOT_GUI) && opkg_is_gui_pkg (pkg))
- continue;
- if ((filters & PK_FILTER_ENUM_INSTALLED) && (pkg->state_status == SS_NOT_INSTALLED))
- continue;
- if ((filters & PK_FILTER_ENUM_NOT_INSTALLED) && (pkg->state_status != SS_NOT_INSTALLED))
- continue;
-
- version = pkg_version_str_alloc (pkg);
- uid = g_strdup_printf ("%s;%s;%s;",
- pkg->name, version, pkg->architecture);
- g_free (version);
-
- if (pkg->state_status == SS_INSTALLED)
- status = PK_INFO_ENUM_INSTALLED;
- else
- status = PK_INFO_ENUM_AVAILABLE;
-
- pk_backend_package (backend, status, uid,pkg->description);
+ return;
+ break;
+ case SEARCH_TAG:
+ if (!g_strrstr (pkg->tags, params->needle))
+ return;
+ break;
}
- pkg_vec_free(available);
- pk_backend_finished (backend);
- return TRUE;
+ uid = g_strdup_printf ("%s;%s;%s;",
+ pkg->name, pkg->version, pkg->architecture);
+
+ if (pkg->installed)
+ status = PK_INFO_ENUM_INSTALLED;
+ else
+ status = PK_INFO_ENUM_AVAILABLE;
+
+ /* check filters */
+
+ if ((filters & PK_FILTER_ENUM_DEVELOPMENT) && !opkg_is_devel_pkg (pkg))
+ return;
+ if ((filters & PK_FILTER_ENUM_NOT_DEVELOPMENT) && opkg_is_devel_pkg (pkg))
+ return;
+ if ((filters & PK_FILTER_ENUM_GUI) && !opkg_is_gui_pkg (pkg))
+ return;
+ if ((filters & PK_FILTER_ENUM_NOT_GUI) && opkg_is_gui_pkg (pkg))
+ return;
+ if ((filters & PK_FILTER_ENUM_INSTALLED) && (!pkg->installed))
+ return;
+ if ((filters & PK_FILTER_ENUM_NOT_INSTALLED) && (pkg->installed))
+ return;
+
+ pk_backend_package (params->backend, status, uid, pkg->description);
+
+}
+
+static gboolean
+backend_search_thread (PkBackendThread *thread, SearchParams *params)
+{
+
+ opkg_list_packages (opkg, pk_opkg_package_list_cb, params);
+
+ pk_backend_finished (params->backend);
+ g_free (params->needle);
+ g_free (params);
+
+ return FALSE;
}
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
+ SearchParams *params;
+
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- pk_backend_set_uint (backend, "type", SEARCH_NAME);
- pk_backend_set_string (backend, "search", search);
- pk_backend_thread_create (backend, backend_search_thread);
+ params = g_new0 (SearchParams, 1);
+ params->filters = filters;
+ params->search_type = SEARCH_NAME;
+ params->needle = g_utf8_strdown (search, -1);
+ params->backend = backend;
+
+ pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
/**
@@ -478,53 +306,58 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_search_description (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
+ SearchParams *params;
+
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- pk_backend_set_uint (backend, "type", SEARCH_DESCRIPTION);
- pk_backend_set_string (backend, "needle", search);
- pk_backend_thread_create (backend, backend_search_thread);
+ params = g_new0 (SearchParams, 1);
+ params->filters = filters;
+ params->search_type = SEARCH_DESCRIPTION;
+ params->needle = g_utf8_strdown (search, -1);
+
+ pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- gchar *needle;
+ SearchParams *params;
+
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- pk_backend_set_uint (backend, "type", SEARCH_TAG);
- needle = g_strdup_printf ("group::%s", search);
- pk_backend_set_string (backend, "needle", needle);
- g_free (needle);
- pk_backend_thread_create (backend, backend_search_thread);
-}
+ params = g_new0 (SearchParams, 1);
+ params->filters = filters;
+ params->search_type = SEARCH_TAG;
+ params->needle = g_strdup_printf ("group::%s", search);
-static void
-pk_opkg_install_progress_cb (int percent, char* url)
-{
- /* get current backend and set percentage */
- backend = pk_backend_thread_get_backend (thread);
- pk_backend_set_percentage (backend, percent);
+ pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
+
+
+
static gboolean
-backend_install_package_thread (PkBackend *backend, gchar *package_id)
+backend_install_package_thread (PkBackendThread *thread, gchar *package_id)
{
PkPackageId *pi;
gint err;
+ PkBackend *backend;
+
+ /* get current backend */
+ backend = pk_backend_thread_get_backend (thread);
pi = pk_package_id_new_from_string (package_id);
- /* set the download progress callback */
- opkg_cb_download_progress = pk_opkg_install_progress_cb;
- err = opkg_packages_install (&args, pi->name);
+ err = opkg_install_package (opkg, pi->name, pk_opkg_progress_cb, backend);
if (err != 0)
opkg_unknown_error (backend, err, "Install");
- /* unset the download progress callback */
- opkg_cb_download_progress = NULL;
-
g_free (package_id);
pk_package_id_free (pi);
pk_backend_finished (backend);
@@ -534,30 +367,43 @@ backend_install_package_thread (PkBackend *backend, gchar *package_id)
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
+ g_return_if_fail (backend != NULL);
+
pk_backend_no_percentage_updates (backend);
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
- pk_backend_thread_create (thread, backend_install_package_thread);
+
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_install_package_thread,
+ g_strdup (package_id));
}
static gboolean
-backend_remove_package_thread (PkBackend *backend, gpointer data[3])
+backend_remove_package_thread (PkBackendThread *thread, gpointer data[3])
{
PkPackageId *pi;
gint err;
+ PkBackend *backend;
gchar *package_id;
gboolean allow_deps;
gboolean autoremove;
+
package_id = (gchar*) data[0];
allow_deps = GPOINTER_TO_INT (data[1]);
autoremove = GPOINTER_TO_INT (data[2]);
g_free (data);
+
+ /* get current backend */
+ backend = pk_backend_thread_get_backend (thread);
+
pi = pk_package_id_new_from_string (package_id);
- args.autoremove = autoremove;
- args.force_removal_of_dependent_packages = allow_deps;
- err = opkg_packages_remove (&args, pi->name, 0);
+ opkg_set_option (opkg, "autoremove", &autoremove);
+ opkg_set_option (opkg, "force_removal_of_dependent_packages", &allow_deps);
+
+ err = opkg_remove_package (opkg, pi->name, pk_opkg_progress_cb, backend);
+
/* TODO: improve error reporting */
if (err != 0)
opkg_unknown_error (backend, err, "Remove");
@@ -573,6 +419,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
{
gpointer *params;
+ g_return_if_fail (backend != NULL);
pk_backend_set_status (backend, PK_STATUS_ENUM_REMOVE);
pk_backend_no_percentage_updates (backend);
@@ -583,7 +430,10 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
params[1] = GINT_TO_POINTER (allow_deps);
params[2] = GINT_TO_POINTER (autoremove);
- pk_backend_thread_create (thread, backend_remove_package_thread, params);
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_remove_package_thread,
+ params);
+
}
/**
@@ -598,11 +448,17 @@ backend_get_filters (PkBackend *backend)
PK_FILTER_ENUM_GUI);
}
+
static gboolean
-backend_update_system_thread (PkBackend *backend)
+backend_update_system_thread (PkBackendThread *thread, gpointer data)
{
gint err;
- err = opkg_packages_upgrade (&args);
+ PkBackend *backend;
+
+ /* get current backend */
+ backend = pk_backend_thread_get_backend (thread);
+
+ opkg_upgrade_all (opkg, pk_opkg_progress_cb, backend);
if (err)
opkg_unknown_error (backend, err, "Upgrading system");
@@ -614,122 +470,32 @@ backend_update_system_thread (PkBackend *backend)
static void
backend_update_system (PkBackend *backend)
{
+ g_return_if_fail (backend != NULL);
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread, backend_update_system_thread);
-}
-
-/**
- * backend_get_depends:
- */
-
-static gboolean
-backend_get_depends_thread (PkBackend *backend, gchar *package_id)
-{
- PkPackageId *pi;
- pkg_t *pkg = NULL;
- gint i;
- GRegex *regex;
-
- pi = pk_package_id_new_from_string (package_id);
- if (!pi->name || !pi->version) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "Package not found");
- pk_package_id_free (pi);
- pk_backend_finished (backend);
- return FALSE;
- }
-
- pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
- if (!pkg) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "Package not found");
- pk_package_id_free (pi);
- pk_backend_finished (backend);
- return FALSE;
- }
-
- /* compile a regex expression to parse depends_str package names */
- regex = g_regex_new ("(.+) \\(([>=<]+) (.+)\\)", G_REGEX_OPTIMIZE, 0, NULL);
-
- for (i = 0; i < pkg->depends_count; i++) {
- pkg_t *d_pkg = NULL;
- pkg_vec_t *p_vec;
- GMatchInfo *match_info = NULL;
- gchar *uid = NULL, *pkg_name = NULL, *pkg_v = NULL, *pkg_req = NULL;
- gint status;
- gchar *version;
-
- /* find the package by name and select the package with the
- * latest version number
- */
-
- if (!g_regex_match (regex, pkg->depends_str[i], 0, &match_info)) {
- /* we couldn't parse the depends string */
-
- /* match_info is always allocated, even if the match
- * failed */
- g_match_info_free (match_info);
- continue;
- }
- pkg_name = g_match_info_fetch (match_info, 1);
- pkg_req = g_match_info_fetch (match_info, 2);
- pkg_v = g_match_info_fetch (match_info, 3);
- g_match_info_free (match_info);
-
- p_vec = pkg_vec_fetch_by_name (&global_conf.pkg_hash, pkg_name);
-
- if (!p_vec || p_vec->len < 1 || !p_vec->pkgs[0])
- continue;
-
- d_pkg = opkg_vec_find_latest (p_vec);
-
- /* TODO: check the version requirements are satisfied */
-
- g_free (pkg_name);
- g_free (pkg_req);
- g_free (pkg_v);
-
- version = pkg_version_str_alloc (d_pkg);
- uid = g_strdup_printf ("%s;%s;%s;",
- d_pkg->name, version, d_pkg->architecture);
- g_free (version);
-
- if (d_pkg->state_status == SS_INSTALLED)
- status = PK_INFO_ENUM_INSTALLED;
- else
- status = PK_INFO_ENUM_AVAILABLE;
- pk_backend_package (backend, status, uid, d_pkg->description);
- }
-
- g_regex_unref (regex);
- g_free (package_id);
- pk_backend_finished (backend);
- return TRUE;
-}
-
-static void
-backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
-{
- /* TODO: recursive is ignored */
- pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread, backend_get_depends_thread);
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_update_system_thread,
+ NULL);
}
/**
- * backend_update_package_thread:
+ * backend_update_package:
*/
static gboolean
-backend_update_package_thread (PkBackend *backend, gchar *package_id)
+backend_update_package_thread (PkBackendThread *thread, gchar *package_id)
{
PkPackageId *pi;
- pkg_t *pkg;
gint err = 0;
+ PkBackend *backend;
+
+ /* get current backend */
+ backend = pk_backend_thread_get_backend (thread);
pi = pk_package_id_new_from_string (package_id);
- if (!pi->name || !pi->version) {
+
+ if (!pi->name || !pi->version)
+ {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
pk_package_id_free (pi);
@@ -737,16 +503,10 @@ backend_update_package_thread (PkBackend *backend, gchar *package_id)
return FALSE;
}
- pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
- if (!pkg) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
- "Packge not found");
- err = -1;
- } else {
- /* TODO: determine if package is already latest? */
- err = opkg_upgrade_pkg (&global_conf, pkg);
- if (err != 0)
- opkg_unknown_error (backend, err, "Update package");
+ err = opkg_upgrade_package (opkg, pi->name, pk_opkg_progress_cb, backend);
+
+ if (err != 0) {
+ opkg_unknown_error (backend, err, "Update package");
}
g_free (package_id);
@@ -758,55 +518,46 @@ backend_update_package_thread (PkBackend *backend, gchar *package_id)
static void
backend_update_packages (PkBackend *backend, gchar **package_ids)
{
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- /* TODO: process the entire list */
- pk_backend_set_string (backend, "package_id", package_ids[0]);
- pk_backend_thread_create (thread, backend_update_package_thread);
+
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_update_package_thread,
+ /* TODO: process the entire list */
+ g_strdup (package_ids[0]));
}
/**
* backend_get_updates:
*/
-static gboolean
-backend_get_updates_thread (PkBackend *backend)
+static void
+pk_opkg_list_upgradable_cb (opkg_t *opkg, opkg_package_t *pkg, void *data)
{
- pkg_vec_t *installed;
- gint i;
+ PkBackend *backend = PK_BACKEND (data);
+ gchar *uid;
+ gint status;
- installed = pkg_vec_alloc();
- pkg_hash_fetch_all_installed (&global_conf.pkg_hash, installed);
-
- for (i=0; i < installed->len; i++) {
- gchar *uid;
- pkg_t *pkg, *best_pkg;
- gint status;
- gchar *version;
-
- pkg = installed->pkgs[i];
- best_pkg = pkg_hash_fetch_best_installation_candidate_by_name (&global_conf, pkg->name);
+ if (pkg->installed)
+ status = PK_INFO_ENUM_INSTALLED;
+ else
+ status = PK_INFO_ENUM_AVAILABLE;
- /* couldn't find an install candidate?! */
- if (!best_pkg)
- continue;
+ uid = g_strdup_printf ("%s;%s;%s;",
+ pkg->name, pkg->version, pkg->architecture);
- /* check to see if the best candidate is actually newer */
- if (pkg_compare_versions (best_pkg, pkg) <= 0)
- continue;
+ pk_backend_package (backend, status, uid, pkg->description);
+}
- version = pkg_version_str_alloc (pkg);
- uid = g_strdup_printf ("%s;%s;%s;",
- pkg->name, version, pkg->architecture);
- g_free (version);
+static gboolean
+backend_get_updates_thread (PkBackendThread *thread, gpointer data)
+{
+ PkBackend *backend = PK_BACKEND (data);
- if (pkg->state_status == SS_INSTALLED)
- status = PK_INFO_ENUM_INSTALLED;
- else
- status = PK_INFO_ENUM_AVAILABLE;
+ opkg_list_upgradable_packages (opkg, pk_opkg_list_upgradable_cb, backend);
- pk_backend_package (backend, status, uid, pkg->description);
- }
pk_backend_finished (backend);
return TRUE;
}
@@ -814,10 +565,14 @@ backend_get_updates_thread (PkBackend *backend)
static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
+ g_return_if_fail (backend != NULL);
+
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread, backend_get_updates_thread);
+ pk_backend_thread_create (thread,
+ (PkBackendThreadFunc) backend_get_updates_thread,
+ backend);
}
/**
@@ -836,6 +591,7 @@ backend_get_groups (PkBackend *backend)
PK_GROUP_ENUM_MAPS);
}
+
PK_BACKEND_OPTIONS (
"opkg", /* description */
"Thomas Wood <thomas at openedhand.com>", /* author */
@@ -844,8 +600,8 @@ PK_BACKEND_OPTIONS (
backend_get_groups, /* get_groups */
backend_get_filters, /* get_filters */
NULL, /* cancel */
- backend_get_depends, /* get_depends */
- backend_get_description, /* get_description */
+ NULL, /* get_depends */
+ NULL, /* get_description */
NULL, /* get_files */
NULL, /* get_packages */
NULL, /* get_repo_list */
diff --git a/configure.ac b/configure.ac
index f38eec2..409fc11 100755
--- a/configure.ac
+++ b/configure.ac
@@ -535,7 +535,7 @@ if test x$enable_box = xyes; then
fi
if test x$enable_opkg = xyes; then
- PKG_CHECK_MODULES(OPKG, libopkg)
+ PKG_CHECK_MODULES(OPKG, libopkg = 0.1)
AC_SUBST(OPKG_CFLAGS)
AC_SUBST(OPKG_LIBS)
fi
commit d370d547730ff23d7f30183f003def2ecbdf06b9
Author: Scott Reeves <sreeves at novell.com>
Date: Tue Apr 29 18:27:46 2008 -0600
Fix build after - convert zypp backend
diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 14592f1..9e930a3 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -595,6 +595,8 @@ backend_get_updates_thread (PkBackend *backend)
static gboolean
backend_refresh_cache_thread (PkBackend *backend)
{
+ //Fixme - we should check the network status and bail if not online
+ gboolean force = pk_backend_get_bool(backend, "force");
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
pk_backend_set_percentage (backend, 0);
@@ -684,7 +686,7 @@ backend_install_file_thread (PkBackend *backend)
zypp::target::rpm::RpmHeader::constPtr rpmHeader = zypp::target::rpm::RpmHeader::readPackage (rpmPath, zypp::target::rpm::RpmHeader::NOSIGNATURE);
if (rpmHeader == NULL) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "%s is no valid rpm-File", full_path);
+ pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "%s is not valid rpm-File", full_path);
pk_backend_finished (backend);
return FALSE;
}
@@ -940,7 +942,6 @@ backend_install_package_thread (PkBackend *backend)
PkPackageId *pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
- g_free (package_id);
pk_backend_finished (backend);
return FALSE;
}
@@ -980,7 +981,6 @@ backend_install_package_thread (PkBackend *backend)
if (!hit) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find the package.");
- g_free (package_id);
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
@@ -989,7 +989,6 @@ backend_install_package_thread (PkBackend *backend)
pk_backend_set_percentage (backend, 40);
if (!zypp_perform_execution (backend, INSTALL, FALSE)) {
- g_free (package_id);
pk_backend_finished (backend);
return FALSE;
}
@@ -999,13 +998,11 @@ backend_install_package_thread (PkBackend *backend)
} catch (const zypp::Exception &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
- g_free (package_id);
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
}
- g_free (package_id);
pk_package_id_free (pi);
pk_backend_finished (backend);
return TRUE;
@@ -1019,7 +1016,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
{
// For now, don't let the user cancel the install once it's started
pk_backend_set_allow_cancel (backend, FALSE);
- pk_backend_thread_create (backend, backend_install_package_thread, package_to_install);
+ pk_backend_thread_create (backend, backend_install_package_thread);
}
static gboolean
@@ -1114,12 +1111,12 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
static gboolean
backend_resolve_thread (PkBackend *backend)
{
- gchar *package_id;
+ const gchar *package_id = pk_backend_get_string (backend, "package_id");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
std::vector<zypp::sat::Solvable> *v;
- v = zypp_get_packages_by_name ((const gchar *)rdata->name, zypp::ResKind::package, TRUE);
+ v = zypp_get_packages_by_name (package_id, zypp::ResKind::package, TRUE);
zypp::sat::Solvable package;
for (std::vector<zypp::sat::Solvable>::iterator it = v->begin ();
@@ -1147,7 +1144,6 @@ backend_resolve_thread (PkBackend *backend)
package_id,
package.lookupStrAttribute (zypp::sat::SolvAttr::description).c_str ());
- g_free (package_id);
pk_backend_finished (backend);
return TRUE;
}
@@ -1170,7 +1166,7 @@ backend_find_packages_thread (PkBackend *backend)
//GList *list = NULL;
search = pk_backend_get_string (backend, "search");
- filters = pk_backend_get_uint (backend, "filters");
+ filters = (PkFilterEnum) pk_backend_get_uint (backend, "filters");
mode = pk_backend_get_uint (backend, "mode");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -1224,7 +1220,7 @@ backend_search_group_thread (PkBackend *backend)
PkFilterEnum filters;
group = pk_backend_get_string (backend, "group");
- filters = pk_backend_get_uint (backend, "filters");
+ filters = (PkFilterEnum) pk_backend_get_uint (backend, "filters");
if (group == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_GROUP_NOT_FOUND, "Group is invalid.");
@@ -1423,7 +1419,7 @@ static gboolean
backend_get_packages_thread (PkBackend *backend)
{
PkFilterEnum filters;
- filters = pk_backend_get_uint (backend, "filters");
+ filters = (PkFilterEnum) pk_backend_get_uint (backend, "filters");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -1473,7 +1469,7 @@ backend_update_packages_thread (PkBackend *backend)
static void
backend_update_packages(PkBackend *backend, gchar **package_ids)
{
- pk_backend_thread_create(thread, backend_update_packages_thread);
+ pk_backend_thread_create(backend, backend_update_packages_thread);
}
static gboolean
@@ -1586,7 +1582,7 @@ backend_repo_set_data_thread (PkBackend *backend)
static void
backend_repo_set_data (PkBackend *backend, const gchar *repo_id, const gchar *parameter, const gchar *value)
{
- pk_backend_thread_create (thread, backend_repo_set_data_thread);
+ pk_backend_thread_create (backend, backend_repo_set_data_thread);
}
static gboolean
commit 28f201fe1a2cf934eb7f517495aafa6b7719b9a5
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 30 02:03:53 2008 +0100
remove pk-network from alpm
diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index d9d430b..3ed1e68 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -35,7 +35,6 @@
#include <pk-backend.h>
#include <pk-debug.h>
#include <pk-package-ids.h>
-#include <pk-network.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -49,8 +48,6 @@ static int progress_percentage;
static int subprogress_percentage;
PkBackend *install_backend = NULL;
-static PkNetwork *network;
-
typedef struct _PackageSource
{
pmpkg_t *pkg;
@@ -619,8 +616,6 @@ backend_initialize (PkBackend *backend)
pk_debug ("alpm: ready to go");
alpm_option_set_dlcb(cb_dl_progress);
-
- network = pk_network_new();
}
/**
@@ -739,7 +734,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
{
g_return_if_fail (backend != NULL);
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline");
pk_backend_finished (backend);
return;
commit c55435444f4d42e067ce99cee5f9ff3833faafd0
Author: Scott Reeves <sreeves at novell.com>
Date: Tue Apr 29 17:19:16 2008 -0600
fix logic so package_ids are actually cached
diff --git a/libpackagekit/pk-client.c b/libpackagekit/pk-client.c
index ec127aa..95213ad 100644
--- a/libpackagekit/pk-client.c
+++ b/libpackagekit/pk-client.c
@@ -2310,7 +2310,7 @@ pk_client_update_packages_strv (PkClient *client, gchar **package_ids, GError **
client->priv->role = PK_ROLE_ENUM_UPDATE_PACKAGES;
/* only copy if we are not requeing */
- if (client->priv->cached_package_ids == package_ids) {
+ if (client->priv->cached_package_ids != package_ids) {
client->priv->cached_package_ids = g_strdupv (package_ids);
}
commit 95b3eb94b67f7e623bdbb5db979fe78c5a59498b
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 30 00:22:04 2008 +0100
convert the poldek backend from pk_backend_thread_create_old() to pk_backend_thread_create() and do a code review -- needs checking
diff --git a/backends/poldek/pk-backend-poldek.c b/backends/poldek/pk-backend-poldek.c
index 26726a0..21f457c 100644
--- a/backends/poldek/pk-backend-poldek.c
+++ b/backends/poldek/pk-backend-poldek.c
@@ -20,8 +20,6 @@
*/
#include <pk-backend.h>
-#include <pk-backend-thread.h>
-#include <pk-network.h>
#include <pk-package-ids.h>
#include <log.h>
@@ -59,19 +57,6 @@ enum {
};
typedef struct {
- gint mode;
- PkFilterEnum filters;
- gchar *search;
-} SearchData;
-
-/* used by GetDepends and GetRequires */
-typedef struct {
- gchar *package_id;
- PkFilterEnum filters;
- gboolean recursive;
-} DepsData;
-
-typedef struct {
gint step; // current step
/* Numer of sources to update. It's used only by refresh cache,
@@ -94,21 +79,6 @@ typedef struct {
gint subpercentage;
} PercentageData;
-typedef struct {
- TsType type;
-
- PercentageData *pd;
-
- /* required by InstallPackage and RemovePackage */
- gchar *package_id;
-
- /* required by UpdatePackages */
- gchar **package_ids;
-
- /* required by RemovePackage */
- gboolean allow_deps;
-} TsData;
-
/* I need this to avoid showing error messages more than once.
* It's initalized by backend_initalize() and destroyed by
* backend_destroy(), but every method should clean it at the
@@ -123,9 +93,6 @@ typedef struct {
} PbError;
/* global variables */
-static PkBackendThread *thread;
-static PkNetwork *network;
-
static gint verbose = 1;
static gint ref = 0;
static PbError *pberror;
@@ -154,7 +121,6 @@ do_get_files_to_download (const struct poldek_ts *ts, const gchar *mark)
if (pkgs) {
files = n_array_size (pkgs);
-
n_array_free (pkgs);
}
@@ -215,12 +181,10 @@ do_get_bytes_to_download (const struct poldek_ts *ts, const gchar *mark)
static void*
poldek_vf_progress_new (void *data, const gchar *label)
{
- TsData *td = (TsData *) data;
- PkBackend *backend;
+ PkBackend *backend = (PkBackend*) data;
+ guint ts_type = pk_backend_get_uint (backend, "ts_type");
- backend = pk_backend_thread_get_backend (thread);
-
- if (td->type == TS_TYPE_ENUM_INSTALL || td->type == TS_TYPE_ENUM_UPDATE) {
+ if (ts_type == TS_TYPE_ENUM_INSTALL || ts_type == TS_TYPE_ENUM_UPDATE) {
gchar *filename = g_path_get_basename (label), *pkgname, *command;
struct poclidek_rcmd *rcmd;
tn_array *pkgs = NULL;
@@ -238,7 +202,6 @@ poldek_vf_progress_new (void *data, const gchar *label)
if (pkgs) {
pkg = n_array_nth (pkgs, 0);
-
poldek_backend_package (pkg, PK_INFO_ENUM_DOWNLOADING);
}
@@ -249,20 +212,18 @@ poldek_vf_progress_new (void *data, const gchar *label)
g_free (filename);
}
- return td;
+ return data;
}
static void
poldek_vf_progress (void *bar, long total, long amount)
{
- TsData *td = (TsData*) bar;
- PercentageData *pd = td->pd;
- PkBackend *backend;
+ PkBackend *backend = (PkBackend*) bar;
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
guint percentage = 0;
+ guint ts_type = pk_backend_get_uint (backend, "ts_type");
- backend = pk_backend_thread_get_backend (thread);
-
- if (td->type == TS_TYPE_ENUM_INSTALL) {
+ if (ts_type == TS_TYPE_ENUM_INSTALL) {
float frac = (float)amount / (float)total;
/* file already downloaded */
@@ -276,7 +237,7 @@ poldek_vf_progress (void *bar, long total, long amount)
pd->percentage = (gint)(((float)(pd->bytesget + amount) / (float)pd->bytesdownload) * 100);
pd->subpercentage = (gint)(frac * 100);
}
- } else if (td->type == TS_TYPE_ENUM_UPDATE) {
+ } else if (ts_type == TS_TYPE_ENUM_UPDATE) {
float stepfrac = pd->stepvalue / (float)pd->filesdownload;
/* file already downloaded */
@@ -290,33 +251,33 @@ poldek_vf_progress (void *bar, long total, long amount)
pd->subpercentage = (gint)((float)(pd->bytesget + amount) / (float)pd->bytesdownload * 100);
percentage = (guint)(stepfrac * ((float)pd->filesget + ((float)pd->subpercentage / (float)100)));
}
- } else if (td->type == TS_TYPE_ENUM_REFRESH_CACHE) {
+ } else if (ts_type == TS_TYPE_ENUM_REFRESH_CACHE) {
if (pd->step == 0)
pd->percentage = 1;
else
pd->percentage = (gint)(((float)pd->step / (float)pd->nsources) * 100);
}
- if (td->type == TS_TYPE_ENUM_INSTALL ||
- td->type == TS_TYPE_ENUM_REFRESH_CACHE)
+ if (ts_type == TS_TYPE_ENUM_INSTALL ||
+ ts_type == TS_TYPE_ENUM_REFRESH_CACHE)
pk_backend_set_percentage (backend, pd->percentage);
- else if (td->type == TS_TYPE_ENUM_UPDATE)
+ else if (ts_type == TS_TYPE_ENUM_UPDATE)
if ((pd->percentage + percentage) > 1)
pk_backend_set_percentage (backend, pd->percentage + percentage);
/* RefreshCache doesn't use subpercentage */
- if (td->type == TS_TYPE_ENUM_INSTALL ||
- td->type == TS_TYPE_ENUM_UPDATE)
+ if (ts_type == TS_TYPE_ENUM_INSTALL ||
+ ts_type == TS_TYPE_ENUM_UPDATE)
pk_backend_set_sub_percentage (backend, pd->subpercentage);
- if (td->type != TS_TYPE_ENUM_REFRESH_CACHE) {
+ if (ts_type != TS_TYPE_ENUM_REFRESH_CACHE) {
if (pd->filesget == pd->filesdownload) {
/* we shouldn't cancel packages installation proccess */
poldek_backend_set_allow_cancel (backend, FALSE, FALSE);
- if (td->type == TS_TYPE_ENUM_INSTALL)
+ if (ts_type == TS_TYPE_ENUM_INSTALL)
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
- else if (td->type == TS_TYPE_ENUM_UPDATE)
+ else if (ts_type == TS_TYPE_ENUM_UPDATE)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
}
}
@@ -325,9 +286,9 @@ poldek_vf_progress (void *bar, long total, long amount)
static void
poldek_vf_progress_reset (void *bar)
{
- TsData *td = (TsData *) bar;
-
- td->pd->subpercentage = 0;
+ PkBackend *backend = (PkBackend *) bar;
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
+ pd->subpercentage = 0;
}
/**
@@ -336,7 +297,8 @@ poldek_vf_progress_reset (void *bar)
* Returns index of the first matching package. If not found, -1 will be returned.
**/
static gint
-poldek_pkg_in_array_idx (const struct pkg *pkg, const tn_array *array, tn_fn_cmp cmp_fn) {
+poldek_pkg_in_array_idx (const struct pkg *pkg, const tn_array *array, tn_fn_cmp cmp_fn)
+{
gint i;
if (array) {
@@ -352,7 +314,8 @@ poldek_pkg_in_array_idx (const struct pkg *pkg, const tn_array *array, tn_fn_cmp
}
static gboolean
-poldek_pkg_in_array (const struct pkg *pkg, const tn_array *array, tn_fn_cmp cmp_fn) {
+poldek_pkg_in_array (const struct pkg *pkg, const tn_array *array, tn_fn_cmp cmp_fn)
+{
if (poldek_pkg_in_array_idx (pkg, array, cmp_fn) == -1)
return FALSE;
else
@@ -368,11 +331,11 @@ static int
ts_confirm (void *data, struct poldek_ts *ts)
{
tn_array *ipkgs = NULL, *dpkgs = NULL, *rpkgs = NULL, *upkgs = NULL;
- TsData *td = (TsData *)data;
- PkBackend *backend;
+ PkBackend *backend = (PkBackend *)data;
gint i = 0, result = 1;
-
- backend = pk_backend_thread_get_backend (thread);
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
+ guint ts_type = pk_backend_get_uint (backend, "ts_type");
+ gboolean allow_deps;
ipkgs = poldek_ts_get_summary (ts, "I");
dpkgs = poldek_ts_get_summary (ts, "D");
@@ -382,13 +345,13 @@ ts_confirm (void *data, struct poldek_ts *ts)
case POLDEK_TS_TYPE_INSTALL:
upkgs = n_array_new (2, NULL, NULL);
- td->pd->step = 0;
+ pd->step = 0;
- td->pd->bytesget = 0;
- td->pd->bytesdownload = poldek_get_bytes_to_download (ts);
+ pd->bytesget = 0;
+ pd->bytesdownload = poldek_get_bytes_to_download (ts);
- td->pd->filesget = 0;
- td->pd->filesdownload = poldek_get_files_to_download (ts);
+ pd->filesget = 0;
+ pd->filesdownload = poldek_get_files_to_download (ts);
/* create an array with pkgs which will be updated */
if (rpkgs) {
@@ -436,13 +399,13 @@ ts_confirm (void *data, struct poldek_ts *ts)
}
/* set proper status if there are no packages to download */
- if (result == 1 && td->pd->filesdownload == 0) {
+ if (result == 1 && pd->filesdownload == 0) {
/* we shouldn't cancel packages installation proccess */
poldek_backend_set_allow_cancel (backend, FALSE, FALSE);
- if (td->type == TS_TYPE_ENUM_INSTALL)
+ if (ts_type == TS_TYPE_ENUM_INSTALL)
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
- else if (td->type == TS_TYPE_ENUM_UPDATE)
+ else if (ts_type == TS_TYPE_ENUM_UPDATE)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
}
@@ -451,7 +414,8 @@ ts_confirm (void *data, struct poldek_ts *ts)
break;
case POLDEK_TS_TYPE_UNINSTALL:
if (dpkgs) {
- if ((td->allow_deps == FALSE) && (n_array_size (dpkgs) > 0)) {
+ allow_deps = pk_backend_get_bool (backend, "allow_deps");
+ if ((allow_deps == FALSE) && (n_array_size (dpkgs) > 0)) {
result = 0;
break;
}
@@ -496,9 +460,9 @@ ts_confirm (void *data, struct poldek_ts *ts)
* setup_vf_progress:
*/
static void
-setup_vf_progress (struct vf_progress *vf_progress, TsData *td)
+setup_vf_progress (struct vf_progress *vf_progress, PkBackend *backend)
{
- vf_progress->data = td;
+ vf_progress->data = backend;
vf_progress->new = poldek_vf_progress_new;
vf_progress->progress = poldek_vf_progress;
vf_progress->reset = poldek_vf_progress_reset;
@@ -630,15 +594,18 @@ do_newest (tn_array *pkgs)
* do_requires:
*/
static void
-do_requires (tn_array *installed, tn_array *available, tn_array *requires, struct pkg *pkg, DepsData *data)
+do_requires (tn_array *installed, tn_array *available, tn_array *requires, struct pkg *pkg, PkBackend *backend)
{
tn_array *tmp = NULL;
gint i;
+ PkFilterEnum filters;
+ gboolean recursive;
tmp = n_array_new (2, NULL, NULL);
+ filters = pk_backend_get_uint (backend, "filters");
/* if ~installed doesn't exists in filters, we can query installed */
- if (!pk_enums_contain (data->filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
for (i = 0; i < n_array_size (installed); i++) {
struct pkg *ipkg = n_array_nth (installed, i);
int j;
@@ -647,8 +614,8 @@ do_requires (tn_array *installed, tn_array *available, tn_array *requires, struc
if (pkg_cmp_name_evr (pkg, ipkg) == 0)
continue;
- /* skip when there is no reqs */
- if (!ipkg->reqs)
+ /* skip when there is no reqs */
+ if (!ipkg->reqs)
continue;
/* package already added to the array */
@@ -666,51 +633,51 @@ do_requires (tn_array *installed, tn_array *available, tn_array *requires, struc
if (pkg_satisfies_req (pkg, req, 1)) {
n_array_push (requires, pkg_link (ipkg));
n_array_push (tmp, pkg_link (ipkg));
- break;
+ break;
}
- }
- }
- }
- if (!pk_enums_contain (data->filters, PK_FILTER_ENUM_INSTALLED)) {
- for (i = 0; i < n_array_size (available); i++) {
- struct pkg *apkg = n_array_nth (available, i);
- int j;
+ }
+ }
+ }
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
+ for (i = 0; i < n_array_size (available); i++) {
+ struct pkg *apkg = n_array_nth (available, i);
+ int j;
/* self match */
if (pkg_cmp_name_evr (pkg, apkg) == 0)
continue;
- if (!apkg->reqs)
- continue;
+ if (!apkg->reqs)
+ continue;
/* package already added to the array */
if (poldek_pkg_in_array (apkg, requires, (tn_fn_cmp)pkg_cmp_name_evr_rev))
continue;
- for (j = 0; j < n_array_size (apkg->reqs); j++) {
- struct capreq *req = n_array_nth (apkg->reqs, j);
+ for (j = 0; j < n_array_size (apkg->reqs); j++) {
+ struct capreq *req = n_array_nth (apkg->reqs, j);
- if (capreq_is_rpmlib (req))
- continue;
- else if (capreq_is_file (req))
- continue;
+ if (capreq_is_rpmlib (req))
+ continue;
+ else if (capreq_is_file (req))
+ continue;
- if (pkg_satisfies_req (pkg, req, 1)) {
- n_array_push (requires, pkg_link (apkg));
- n_array_push (tmp, pkg_link (apkg));
- break;
- }
- }
- }
- }
+ if (pkg_satisfies_req (pkg, req, 1)) {
+ n_array_push (requires, pkg_link (apkg));
+ n_array_push (tmp, pkg_link (apkg));
+ break;
+ }
+ }
+ }
+ }
/* FIXME: recursive takes too much time for available packages, so don't use it */
- if (pk_enums_contain (data->filters, PK_FILTER_ENUM_INSTALLED)) {
- if (data->recursive && tmp && n_array_size (tmp) > 0) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
+ recursive = pk_backend_get_bool (backend, "recursive");
+ if (recursive && tmp && n_array_size (tmp) > 0) {
for (i = 0; i < n_array_size (tmp); i++) {
struct pkg *p = n_array_nth (tmp, i);
-
- do_requires (installed, available, requires, p, data);
+ do_requires (installed, available, requires, p, backend);
}
}
}
@@ -722,13 +689,17 @@ do_requires (tn_array *installed, tn_array *available, tn_array *requires, struc
* do_depends:
*/
static void
-do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct pkg *pkg, DepsData *data)
+do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct pkg *pkg, PkBackend *backend)
{
tn_array *reqs = pkg->reqs;
tn_array *tmp = NULL;
gint i;
+ PkFilterEnum filters;
+ gboolean recursive;
tmp = n_array_new (2, NULL, NULL);
+ filters = pk_backend_get_uint (backend, "filters");
+ recursive = pk_backend_get_bool (backend, "recursive");
/* nothing to do */
if (!reqs || (reqs && n_array_size (reqs) < 1))
@@ -768,7 +739,7 @@ do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct
continue;
/* first check in installed packages */
- if (!pk_enums_contain (data->filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
for (j = 0; j < n_array_size (installed); j++) {
struct pkg *p = n_array_nth (installed, j);
@@ -785,7 +756,7 @@ do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct
continue;
/* ... now available */
- if (!pk_enums_contain (data->filters, PK_FILTER_ENUM_INSTALLED)) {
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
for (j = 0; j < n_array_size (available); j++) {
struct pkg *p = n_array_nth (available, j);
@@ -794,7 +765,7 @@ do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct
* don't return these, which are installed.
* Can be used to tell the user which packages
* will be additionaly installed. */
- if (pk_enums_contain (data->filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
gint ret;
ret = poldek_pkg_in_array_idx (p, installed, (tn_fn_cmp)pkg_cmp_name);
@@ -817,11 +788,11 @@ do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct
}
}
- if (data->recursive && tmp && n_array_size (tmp) > 0) {
+ if (recursive && tmp && n_array_size (tmp) > 0) {
for (i = 0; i < n_array_size (tmp); i++) {
struct pkg *p = n_array_nth (tmp, i);
- do_depends (installed, available, depends, p, data);
+ do_depends (installed, available, depends, p, backend);
}
}
@@ -834,14 +805,9 @@ do_depends (tn_array *installed, tn_array *available, tn_array *depends, struct
static void
poldek_backend_package (const struct pkg *pkg, gint status)
{
- PkBackend *backend;
struct pkguinf *pkgu;
gchar *evr, *package_id, *poldek_dir;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_if_fail (backend != NULL);
-
evr = poldek_pkg_evr (pkg);
if (poldek_pkg_is_installed(pkg)) {
@@ -945,44 +911,46 @@ poldek_pkg_is_gui (struct pkg *pkg)
}
/**
- * search_package:
+ * search_package_thread:
*/
static gboolean
-search_package (PkBackendThread *thread, gpointer data)
+search_package_thread (PkBackend *backend)
{
- SearchData *d = (SearchData*) data;
+ PkFilterEnum filters;
gchar *search_cmd = NULL;
struct poclidek_rcmd *cmd = NULL;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ const gchar *search;
+ guint mode;
+ PkFilterEnum filters;
pb_load_packages (backend);
cmd = poclidek_rcmd_new (cctx, NULL);
- switch (d->mode) {
+ mode = pk_backend_get_uint (backend, "mode");
+ search = pk_backend_get_string (backend, "search");
+ filters = pk_backend_get_uint (backend, "filters");
+
+ switch (mode) {
/* GetPackages */
case SEARCH_ENUM_NONE:
search_cmd = g_strdup ("ls -q");
break;
/* SearchName */
case SEARCH_ENUM_NAME:
- search_cmd = g_strdup_printf ("ls -q *%s*", d->search);
+ search_cmd = g_strdup_printf ("ls -q *%s*", search);
break;
/* SearchGroup */
case SEARCH_ENUM_GROUP:
- search_cmd = g_strdup_printf ("search -qg *%s*", d->search);
+ search_cmd = g_strdup_printf ("search -qg *%s*", search);
break;
/* SearchDetails */
case SEARCH_ENUM_DETAILS:
- search_cmd = g_strdup_printf ("search -dsq *%s*", d->search);
+ search_cmd = g_strdup_printf ("search -dsq *%s*", search);
break;
/* SearchFile */
case SEARCH_ENUM_FILE:
- search_cmd = g_strdup_printf ("search -qlf *%s*", d->search);
+ search_cmd = g_strdup_printf ("search -qlf *%s*", search);
break;
default:
/* Error */
@@ -994,7 +962,7 @@ search_package (PkBackendThread *thread, gpointer data)
gchar *command;
tn_array *pkgs = NULL, *installed = NULL, *available = NULL;
- if (!pk_enums_contain (d->filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED)) {
command = g_strdup_printf ("cd /installed; %s", search_cmd);
if (poclidek_rcmd_execline (cmd, command)) {
gint i;
@@ -1004,14 +972,14 @@ search_package (PkBackendThread *thread, gpointer data)
/* mark packages as installed */
for (i = 0; i < n_array_size (installed); i++) {
struct pkg *pkg = n_array_nth (installed, i);
-
+
poldek_pkg_set_installed (pkg, TRUE);
}
}
g_free (command);
}
- if (!pk_enums_contain (d->filters, PK_FILTER_ENUM_INSTALLED)) {
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED)) {
command = g_strdup_printf ("cd /all-avail; %s", search_cmd);
if (poclidek_rcmd_execline (cmd, command))
available = poclidek_rcmd_get_packages (cmd);
@@ -1019,8 +987,8 @@ search_package (PkBackendThread *thread, gpointer data)
g_free (command);
}
- if (!pk_enums_contain (d->filters, PK_FILTER_ENUM_INSTALLED) &&
- !pk_enums_contain (d->filters, PK_FILTER_ENUM_NOT_INSTALLED) &&
+ if (!pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED) &&
+ !pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED) &&
installed && available) {
gint i;
@@ -1041,7 +1009,7 @@ search_package (PkBackendThread *thread, gpointer data)
n_array_sort_ex(pkgs, (tn_fn_cmp)pkg_cmp_name_evr_rev_recno);
n_array_free (available);
- } else if (pk_enums_contain (d->filters, PK_FILTER_ENUM_NOT_INSTALLED) || available) {
+ } else if (pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED) || available) {
gint i;
pkgs = available;
@@ -1051,13 +1019,13 @@ search_package (PkBackendThread *thread, gpointer data)
poldek_pkg_set_installed (pkg, FALSE);
}
- } else if (pk_enums_contain (d->filters, PK_FILTER_ENUM_INSTALLED) || installed)
+ } else if (pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED) || installed)
pkgs = installed;
if (pkgs) {
gint i;
- if (pk_enums_contain (d->filters, PK_FILTER_ENUM_NEWEST))
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_NEWEST))
do_newest (pkgs);
for (i = 0; i < n_array_size (pkgs); i++) {
@@ -1068,9 +1036,9 @@ search_package (PkBackendThread *thread, gpointer data)
/* check if we have to do development filtering
* (devel or ~devel in filters) */
- if (pk_enums_contain (d->filters, PK_FILTER_ENUM_DEVELOPMENT) ||
- pk_enums_contain (d->filters, PK_FILTER_ENUM_NOT_DEVELOPMENT)) {
- if (pk_enums_contain (d->filters, PK_FILTER_ENUM_DEVELOPMENT)) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_DEVELOPMENT) ||
+ pk_enums_contain (filters, PK_FILTER_ENUM_NOT_DEVELOPMENT)) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_DEVELOPMENT)) {
/* devel in filters */
if (!poldek_pkg_is_devel (pkg))
continue;
@@ -1083,9 +1051,9 @@ search_package (PkBackendThread *thread, gpointer data)
/* check if we have to do gui filtering
* (gui or ~gui in filters) */
- if (pk_enums_contain (d->filters, PK_FILTER_ENUM_GUI) ||
- pk_enums_contain (d->filters, PK_FILTER_ENUM_NOT_GUI)) {
- if (pk_enums_contain (d->filters, PK_FILTER_ENUM_GUI)) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_GUI) ||
+ pk_enums_contain (filters, PK_FILTER_ENUM_NOT_GUI)) {
+ if (pk_enums_contain (filters, PK_FILTER_ENUM_GUI)) {
/* gui in filters */
if (!poldek_pkg_is_gui (pkg))
continue;
@@ -1106,7 +1074,7 @@ search_package (PkBackendThread *thread, gpointer data)
}
if (sigint_reached ()) {
- switch (d->mode) {
+ switch (mode) {
case SEARCH_ENUM_NAME:
case SEARCH_ENUM_GROUP:
case SEARCH_ENUM_DETAILS:
@@ -1119,11 +1087,8 @@ search_package (PkBackendThread *thread, gpointer data)
}
g_free (search_cmd);
- g_free (d->search);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
@@ -1194,7 +1159,6 @@ pb_error_clean (void)
static void
poldek_backend_log (void *data, int pri, char *message)
{
- PkBackend *backend;
/* skip messages that we don't want to show */
if (g_str_has_prefix (message, "Nothing")) // 'Nothing to do'
@@ -1202,8 +1166,6 @@ poldek_backend_log (void *data, int pri, char *message)
if (g_str_has_prefix (message, "There we")) // 'There were errors'
return;
- backend = pk_backend_thread_get_backend (thread);
-
/* catch vfff messages */
if (g_str_has_prefix (message, "vfff: ")) {
if (g_str_has_prefix (message, "vfff: Inter")) // 'Interrupted system call'
@@ -1233,8 +1195,6 @@ poldek_backend_log (void *data, int pri, char *message)
static void
poldek_backend_set_allow_cancel (PkBackend *backend, gboolean allow_cancel, gboolean reset)
{
- g_return_if_fail (backend != NULL);
-
if (reset)
sigint_reset ();
@@ -1242,9 +1202,12 @@ poldek_backend_set_allow_cancel (PkBackend *backend, gboolean allow_cancel, gboo
}
static void
-do_poldek_init (void) {
+do_poldek_init (void)
+{
+ PercentageData *pd;
+
poldeklib_init ();
-
+
ctx = poldek_new (0);
poldek_load_config (ctx, "/etc/poldek/poldek.conf", NULL, 0);
@@ -1253,6 +1216,9 @@ do_poldek_init (void) {
cctx = poclidek_new (ctx);
+ pd = g_new0 (PercentageData, 1);
+ pk_backend_set_pointer (backend, "percentage_ptr", pd);
+
poldek_set_verbose (1);
/* disable LOGFILE and LOGTTY logging */
poldek_configure (ctx, POLDEK_CONF_LOGFILE, NULL);
@@ -1275,8 +1241,12 @@ do_poldek_init (void) {
static void
do_poldek_destroy (void)
{
+ PercentageData *pd;
sigint_destroy ();
+ pd = (gpointer) pk_backend_get_pointer (backend, "percentage_ptr");
+ g_free (pd);
+
poclidek_free (cctx);
poldek_free (ctx);
@@ -1290,7 +1260,6 @@ poldek_reload (PkBackend *backend, gboolean load_packages) {
if (load_packages)
pb_load_packages (backend);
-
}
/**
@@ -1299,19 +1268,13 @@ poldek_reload (PkBackend *backend, gboolean load_packages) {
static void
backend_initalize (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
pberror = g_new0 (PbError, 1);
pberror->tslog = g_string_new ("");
- thread = pk_backend_thread_new ();
-
/* reference count for the global variables */
if (ref++ > 1)
return;
- network = pk_network_new ();
-
do_poldek_init ();
}
/**
@@ -1320,13 +1283,9 @@ backend_initalize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
- g_object_unref (thread);
-
if (ref-- > 0)
return;
-
+
do_poldek_destroy ();
/* release PbError struct */
@@ -1356,8 +1315,6 @@ backend_get_filters (PkBackend *backend)
static void
backend_get_cancel (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_CANCEL);
sigint_emit ();
@@ -1367,17 +1324,12 @@ backend_get_cancel (PkBackend *backend)
* backend_get_depends:
*/
static gboolean
-backend_get_depends_thread (PkBackendThread *thread, gpointer data)
+backend_get_depends_thread (PkBackend *backend)
{
- DepsData *d = (DepsData*) data;
- PkBackend *backend;
struct pkg *pkg;
tn_array *deppkgs, *available, *installed;
gint i;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ const gchar *package_id;
pb_load_packages (backend);
@@ -1385,10 +1337,11 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
installed = poldek_get_installed_packages ();
available = poldek_get_avail_packages (ctx);
+ package_id = pk_backend_get_string (backend, "package_id");
- pkg = poldek_get_pkg_from_package_id (d->package_id);
+ pkg = poldek_get_pkg_from_package_id (package_id);
- do_depends (installed, available, deppkgs, pkg, d);
+ do_depends (installed, available, deppkgs, pkg, backend);
n_array_sort_ex(deppkgs, (tn_fn_cmp)pkg_cmp_name_evr_rev);
@@ -1404,44 +1357,28 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
n_array_free (available);
n_array_free (installed);
- g_free (d->package_id);
- g_free (d);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- DepsData *data = g_new0 (DepsData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- data->package_id = g_strdup (package_id);
- data->filters = filters;
- data->recursive = recursive;
- pk_backend_thread_create_old (thread, backend_get_depends_thread, data);
+ pk_backend_thread_create (backend, backend_get_depends_thread);
}
/**
* backend_get_description:
*/
static gboolean
-backend_get_description_thread (PkBackendThread *thread, gchar *package_id)
+backend_get_description_thread (PkBackend *backend, gchar *package_id)
{
- PkBackend *backend;
struct pkg *pkg = NULL;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
pb_load_packages (backend);
pkg = poldek_get_pkg_from_package_id (package_id);
@@ -1477,37 +1414,27 @@ backend_get_description_thread (PkBackendThread *thread, gchar *package_id)
g_free (package_id);
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_description (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc)backend_get_description_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_get_description_thread);
}
/**
* backend_get_files:
*/
static gboolean
-backend_get_files_thread (PkBackendThread *thread, gchar *package_id)
+backend_get_files_thread (PkBackend *backend, gchar *package_id)
{
- PkBackend *backend;
struct pkg *pkg;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
pb_load_packages (backend);
pkg = poldek_get_pkg_from_package_id (package_id);
@@ -1559,22 +1486,17 @@ backend_get_files_thread (PkBackendThread *thread, gchar *package_id)
g_free (package_id);
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_files (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc)backend_get_files_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_get_files_thread);
}
/**
@@ -1583,44 +1505,35 @@ backend_get_files (PkBackend *backend, const gchar *package_id)
static void
backend_get_packages (PkBackend *backend, PkFilterEnum filters)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- data->mode = SEARCH_ENUM_NONE;
- data->filters = filters;
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_NONE);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
* backend_get_requires:
*/
static gboolean
-backend_get_requires_thread (PkBackendThread *thread, gpointer data)
+backend_get_requires_thread (PkBackend *backend)
{
- DepsData *d = (DepsData*) data;
- PkBackend *backend;
struct pkg *pkg;
tn_array *reqpkgs, *available, *installed;
gint i;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ const gchar *package_id;
pb_load_packages (backend);
reqpkgs = n_array_new (2, NULL, NULL);
- pkg = poldek_get_pkg_from_package_id (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pkg = poldek_get_pkg_from_package_id (package_id);
installed = poldek_get_installed_packages ();
available = poldek_get_avail_packages (ctx);
- do_requires (installed, available, reqpkgs, pkg, d);
+ do_requires (installed, available, reqpkgs, pkg, backend);
/* sort output */
n_array_sort_ex(reqpkgs, (tn_fn_cmp)pkg_cmp_name_evr_rev);
@@ -1635,46 +1548,30 @@ backend_get_requires_thread (PkBackendThread *thread, gpointer data)
n_array_free (installed);
n_array_free (available);
- g_free (d->package_id);
- g_free (d);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- DepsData *data = g_new0 (DepsData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- data->package_id = g_strdup (package_id);
- data->filters = filters;
- data->recursive = recursive;
- pk_backend_thread_create_old (thread, backend_get_requires_thread, data);
+ pk_backend_thread_create (backend, backend_get_requires_thread);
}
/**
* backend_get_update_detail:
*/
static gboolean
-backend_get_update_detail_thread (PkBackendThread *thread, gchar *package_id)
+backend_get_update_detail_thread (PkBackend *backend, gchar *package_id)
{
- PkBackend *backend;
PkPackageId *pi;
struct poclidek_rcmd *rcmd;
gchar *command;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
pb_load_packages (backend);
pi = pk_package_id_new_from_string (package_id);
@@ -1733,37 +1630,27 @@ backend_get_update_detail_thread (PkBackendThread *thread, gchar *package_id)
pk_package_id_free (pi);
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_update_detail (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc)backend_get_update_detail_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_get_update_detail_thread);
}
/**
* backend_get_updates:
*/
static gboolean
-backend_get_updates_thread (PkBackendThread *thread, gpointer data)
+backend_get_updates_thread (PkBackend *backend)
{
- PkBackend *backend;
struct poclidek_rcmd *rcmd = NULL;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
pb_load_packages (backend);
rcmd = poclidek_rcmd_new (cctx, NULL);
@@ -1800,52 +1687,45 @@ backend_get_updates_thread (PkBackendThread *thread, gpointer data)
pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_CANCELLED, "Action cancelled.");
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create (backend, backend_get_updates_thread);
}
/**
* backend_install_package:
*/
static gboolean
-backend_install_package_thread (PkBackendThread *thread, gpointer data)
+backend_install_package_thread (PkBackend *backend)
{
- TsData *td = (TsData *)data;
- PkBackend *backend;
struct poldek_ts *ts;
struct poclidek_rcmd *rcmd;
gchar *command, *nvra;
struct vf_progress vf_progress;
+ const gchar *package_id;
- td->type = TS_TYPE_ENUM_INSTALL;
-
- setup_vf_progress (&vf_progress, td);
+ pk_backend_set_uint (backend, "ts_type", TS_TYPE_ENUM_INSTALL);
+ package_id = pk_backend_get_string (backend, "package_id");
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ setup_vf_progress (&vf_progress, backend);
pb_load_packages (backend);
/* setup callbacks */
- poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, td);
+ poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, backend);
ts = poldek_ts_new (ctx, 0);
rcmd = poclidek_rcmd_new (cctx, ts);
- nvra = poldek_get_nvra_from_package_id (td->package_id);
+ nvra = poldek_get_nvra_from_package_id (package_id);
command = g_strdup_printf ("install %s", nvra);
pk_backend_set_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
@@ -1861,26 +1741,14 @@ backend_install_package_thread (PkBackendThread *thread, gpointer data)
poldek_ts_free (ts);
poclidek_rcmd_free (rcmd);
- g_free (td->pd);
- g_free (td->package_id);
- g_free (td);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
- TsData *data = g_new0 (TsData, 1);
-
- g_return_if_fail (backend != NULL);
-
- if (pk_network_is_online (network) == FALSE) {
- /* free allocated memory */
- g_free (data);
-
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install package when offline!");
pk_backend_finished (backend);
return;
@@ -1889,9 +1757,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- data->package_id = g_strdup (package_id);
- data->pd = g_new0 (PercentageData, 1);
- pk_backend_thread_create_old (thread, backend_install_package_thread, data);
+ pk_backend_thread_create (backend, backend_install_package_thread);
}
/**
@@ -1899,20 +1765,13 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
* backend_refresh_cache:
*/
static gboolean
-backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
+backend_refresh_cache_thread (PkBackend *backend)
{
- PkBackend *backend;
tn_array *sources = NULL;
- TsData *td = g_new0 (TsData, 1);
- PercentageData *pd = g_new0 (PercentageData, 1);
struct vf_progress vfpro;
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
- td->pd = pd;
- setup_vf_progress (&vfpro, td);
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ setup_vf_progress (&vfpro, backend);
pk_backend_set_percentage (backend, 1);
@@ -1921,7 +1780,7 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
if (sources) {
gint i;
- td->type = TS_TYPE_ENUM_REFRESH_CACHE;
+ pk_backend_set_uint (backend, "ts_type", TS_TYPE_ENUM_REFRESH_CACHE);
pd->step = 0;
pd->nsources = 0;
@@ -1953,57 +1812,48 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
pk_backend_set_percentage (backend, 100);
- g_free (td->pd);
- g_free (td);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache when offline!");
pk_backend_finished (backend);
return;
}
- pk_backend_thread_create_old (thread, backend_refresh_cache_thread, NULL);
+ pk_backend_thread_create (backend, backend_refresh_cache_thread);
}
/**
* backend_remove_package:
*/
static gboolean
-backend_remove_package_thread (PkBackendThread *thread, gpointer data)
+backend_remove_package_thread (PkBackend *backend)
{
- TsData *td = (TsData *) data;
- PkBackend *backend;
+ PkBackend *backend = (PkBackend *) data;
struct poclidek_rcmd *rcmd;
struct poldek_ts *ts;
gchar *nvra, *command;
+ const gchar *package_id;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
+ package_id = pk_backend_get_string (backend, "package_id");
pb_load_packages (backend);
/* setup callbacks */
- poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, td);
+ poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, backend);
ts = poldek_ts_new (ctx, 0);
rcmd = poclidek_rcmd_new (cctx, ts);
- nvra = poldek_get_nvra_from_package_id (td->package_id);
+ nvra = poldek_get_nvra_from_package_id (package_id);
command = g_strdup_printf ("uninstall %s", nvra);
pk_backend_set_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
@@ -2019,27 +1869,16 @@ backend_remove_package_thread (PkBackendThread *thread, gpointer data)
poldek_ts_free (ts);
poclidek_rcmd_free (rcmd);
- g_free (td->package_id);
- g_free (td);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps, gboolean autoremove)
{
- TsData *data = g_new0 (TsData, 1);
-
- g_return_if_fail (backend != NULL);
-
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
-
- data->package_id = g_strdup (package_id);
- data->allow_deps = allow_deps;
- pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
+ pk_backend_thread_create (backend, backend_remove_package_thread);
}
/**
@@ -2048,17 +1887,10 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
static void
backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
-
- data->mode = SEARCH_ENUM_NAME;
- data->filters = filters;
- data->search = g_strdup (package);
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_NAME);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
@@ -2067,18 +1899,11 @@ backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
static void
backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
-
- data->mode = SEARCH_ENUM_DETAILS;
- data->filters = filters;
- data->search = g_strdup (search);
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_DETAILS);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
@@ -2087,18 +1912,11 @@ backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *s
static void
backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
-
- data->mode = SEARCH_ENUM_FILE;
- data->filters = filters;
- data->search = g_strdup (search);
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_FILE);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
@@ -2107,18 +1925,11 @@ backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
-
- data->mode = SEARCH_ENUM_GROUP;
- data->filters = filters;
- data->search = g_strdup (search);
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_GROUP);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
@@ -2127,49 +1938,40 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *sea
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchData *data = g_new0 (SearchData, 1);
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
-
- data->mode = SEARCH_ENUM_NAME;
- data->filters = filters;
- data->search = g_strdup (search);
- pk_backend_thread_create_old (thread, search_package, data);
+ pk_backend_set_uint (backend, "mode", SEARCH_ENUM_NAME);
+ pk_backend_thread_create (backend, search_package_thread);
}
/**
* backend_update_packages:
*/
static gboolean
-backend_update_packages_thread (PkBackendThread *thread, gpointer data)
+backend_update_packages_thread (PkBackend *backend)
{
- TsData *td = (TsData *)data;
- PkBackend *backend;
struct poldek_ts *ts;
struct poclidek_rcmd *rcmd;
struct vf_progress vf_progress;
guint i;
gboolean update_cancelled = FALSE;
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
+ gchar **package_ids;
- setup_vf_progress (&vf_progress, td);
+ package_ids = pk_backend_get_strv (backend, "package_ids");
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ setup_vf_progress (&vf_progress, backend);
pb_load_packages (backend);
/* setup callbacks */
- poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, td);
+ poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, backend);
pk_backend_set_percentage (backend, 1);
- td->pd->stepvalue = (float)100 / (float)g_strv_length (td->package_ids);
+ pd->stepvalue = (float)100 / (float)g_strv_length (package_ids);
- for (i = 0; i < g_strv_length (td->package_ids); i++) {
+ for (i = 0; i < g_strv_length (package_ids); i++) {
struct pkg *pkg = NULL;
pk_backend_set_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
@@ -2177,7 +1979,7 @@ backend_update_packages_thread (PkBackendThread *thread, gpointer data)
pk_backend_set_sub_percentage (backend, 0);
- pkg = poldek_get_pkg_from_package_id (td->package_ids[i]);
+ pkg = poldek_get_pkg_from_package_id (package_ids[i]);
/* don't try to update blocked packages */
if (!(pkg->flags & PKG_HELD)) {
@@ -2186,7 +1988,7 @@ backend_update_packages_thread (PkBackendThread *thread, gpointer data)
ts = poldek_ts_new (ctx, 0);
rcmd = poclidek_rcmd_new (cctx, ts);
- nvra = poldek_get_nvra_from_package_id (td->package_ids[i]);
+ nvra = poldek_get_nvra_from_package_id (package_ids[i]);
command = g_strdup_printf ("upgrade %s", nvra);
if (!poclidek_rcmd_execline (rcmd, command)) {
@@ -2208,10 +2010,10 @@ backend_update_packages_thread (PkBackendThread *thread, gpointer data)
break;
}
- td->pd->percentage = (gint)((float)(i + 1) * td->pd->stepvalue);
+ pd->percentage = (gint)((float)(i + 1) * pd->stepvalue);
- if (td->pd->percentage > 1)
- pk_backend_set_percentage (backend, td->pd->percentage);
+ if (pd->percentage > 1)
+ pk_backend_set_percentage (backend, pd->percentage);
pkg_free (pkg);
}
@@ -2219,25 +2021,14 @@ backend_update_packages_thread (PkBackendThread *thread, gpointer data)
if (!update_cancelled)
pk_backend_set_percentage (backend, 100);
- g_free (td->pd);
- g_strfreev (td->package_ids);
- g_free (td);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_update_packages (PkBackend *backend, gchar **package_ids)
{
- TsData *data = g_new0 (TsData, 1);
-
- g_return_if_fail (backend != NULL);
-
- if (pk_network_is_online (network) == FALSE) {
- /* free allocated memory */
- g_free (data);
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot update packages when offline!");
pk_backend_finished (backend);
@@ -2247,37 +2038,30 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- data->package_ids = g_strdupv (package_ids);
- data->pd = g_new0 (PercentageData, 1);
- data->type = TS_TYPE_ENUM_UPDATE;
- pk_backend_thread_create_old (thread, backend_update_packages_thread, data);
+ pk_backend_set_uint (backend, "ts_type", TS_TYPE_ENUM_UPDATE);
+ pk_backend_thread_create (backend, backend_update_packages_thread);
}
/**
* backend_update_system:
**/
static gboolean
-backend_update_system_thread (PkBackendThread *thread, gpointer data)
+backend_update_system_thread (PkBackend *backend)
{
- TsData *td = (TsData *)data;
- PkBackend *backend;
struct vf_progress vf_progress;
struct poldek_ts *ts;
struct poclidek_rcmd *rcmd;
tn_array *upkgs;
gint i;
gboolean update_cancelled = FALSE;
+ PercentageData *pd = pk_backend_get_pointer (backend, "percentage_ptr");
- setup_vf_progress (&vf_progress, td);
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
+ setup_vf_progress (&vf_progress, backend);
pb_load_packages (backend);
/* setup callbacks */
- poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, td);
+ poldek_configure (ctx, POLDEK_CONF_TSCONFIRM_CB, ts_confirm, backend);
/* get packages to update */
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -2308,7 +2092,7 @@ backend_update_system_thread (PkBackendThread *thread, gpointer data)
/* start */
pk_backend_set_percentage (backend, 1);
- td->pd->stepvalue = (float)100 / (float)n_array_size (upkgs);
+ pd->stepvalue = (float)100 / (float)n_array_size (upkgs);
for (i = 0; i < n_array_size (upkgs); i++) {
struct pkg *pkg = n_array_nth (upkgs, i);
@@ -2343,46 +2127,33 @@ backend_update_system_thread (PkBackendThread *thread, gpointer data)
break;
}
- td->pd->percentage = (gint)((float)(i + 1) * td->pd->stepvalue);
+ pd->percentage = (gint)((float)(i + 1) * pd->stepvalue);
- if (td->pd->percentage > 1)
- pk_backend_set_percentage (backend, td->pd->percentage);
+ if (pd->percentage > 1)
+ pk_backend_set_percentage (backend, pd->percentage);
}
if (!update_cancelled)
pk_backend_set_percentage (backend, 100);
- g_free (td->pd);
- g_free (td);
-
pk_backend_finished (backend);
-
return TRUE;
}
static void
backend_update_system (PkBackend *backend)
{
- TsData *data = g_new0 (TsData, 1);
-
- g_return_if_fail (backend != NULL);
-
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot update system when offline!");
pk_backend_finished (backend);
-
- g_free (data);
-
return;
}
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- data->pd = g_new0 (PercentageData, 1);
- data->type = TS_TYPE_ENUM_UPDATE;
-
- pk_backend_thread_create_old (thread, backend_update_system_thread, data);
+ pk_backend_set_uint (backend, "ts_type", TS_TYPE_ENUM_UPDATE);
+ pk_backend_thread_create (backend, backend_update_system_thread);
}
/**
@@ -2393,8 +2164,6 @@ backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
{
tn_array *sources = NULL;
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
commit 4c4716735115d39ccf751ad626667a36d0ab1533
Author: Scott Reeves <sreeves at novell.com>
Date: Tue Apr 29 15:39:29 2008 -0600
when debugging also dump the action
diff --git a/src/pk-security-polkit.c b/src/pk-security-polkit.c
index c0613d1..e0f1c51 100644
--- a/src/pk-security-polkit.c
+++ b/src/pk-security-polkit.c
@@ -73,7 +73,7 @@ pk_security_can_do_action (PkSecurity *security, const gchar *dbus_sender, const
polkit_action_set_action_id (pk_action, action);
/* set caller */
- pk_debug ("using caller %s", dbus_sender);
+ pk_debug ("using caller %s for action %s", dbus_sender, action);
dbus_error_init (&dbus_error);
pk_caller = polkit_caller_new_from_dbus_name (security->priv->connection, dbus_sender, &dbus_error);
if (pk_caller == NULL) {
commit 8601afb6a74844771709599732756f76066f50f8
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 23:04:02 2008 +0100
convert the apt backend from pk_backend_thread_create_old() to pk_backend_thread_create() and do a code review -- needs checking
diff --git a/backends/apt/pk-backend-apt.c b/backends/apt/pk-backend-apt.c
index 2732b01..19084c6 100644
--- a/backends/apt/pk-backend-apt.c
+++ b/backends/apt/pk-backend-apt.c
@@ -23,14 +23,12 @@
#include <gmodule.h>
#include <glib.h>
#include <string.h>
-#include <pk-network.h>
#include <pk-backend.h>
#include <pk-backend-spawn.h>
#include "pk-apt-search.h"
#include "config.h"
PkBackendSpawn *spawn;
-static PkNetwork *network;
/**
* backend_initialize:
@@ -39,9 +37,7 @@ static PkNetwork *network;
static void
backend_initialize (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
pk_debug ("FILTER: initialize");
- network = pk_network_new ();
spawn = pk_backend_spawn_new ();
pk_backend_spawn_set_name (spawn, "apt");
backend_init_search (backend);
@@ -54,11 +50,8 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
pk_debug ("FILTER: destroy");
backend_finish_search (backend);
- g_object_unref (network);
g_object_unref (spawn);
}
@@ -111,8 +104,6 @@ static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
gchar *filters_text;
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
filters_text = pk_filter_enums_to_text (filters);
pk_backend_spawn_helper (spawn, "get-depends.py", filters_text, package_id, pk_backend_bool_to_text (recursive), NULL);
g_free (filters_text);
@@ -125,8 +116,6 @@ static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
gchar *filters_text;
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
filters_text = pk_filter_enums_to_text (filters);
pk_backend_spawn_helper (spawn, "get-updates.py", filters_text, NULL);
g_free (filters_text);
@@ -138,8 +127,6 @@ backend_get_updates (PkBackend *backend, PkFilterEnum filters)
static void
backend_get_update_detail (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
pk_backend_spawn_helper (spawn, "get-update-detail.py", package_id, NULL);
}
@@ -149,11 +136,8 @@ backend_get_update_detail (PkBackend *backend, const gchar *package_id)
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
-
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install when offline");
pk_backend_finished (backend);
return;
@@ -168,11 +152,8 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
-
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline");
pk_backend_finished (backend);
return;
@@ -187,8 +168,6 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
static void
backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps, gboolean autoremove)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
pk_backend_spawn_helper (spawn, "remove.py", pk_backend_bool_to_text (allow_deps), package_id, NULL);
} */
@@ -198,11 +177,8 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
static void
backend_update_package (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
-
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install when offline");
pk_backend_finished (backend);
return;
@@ -217,8 +193,6 @@ backend_update_package (PkBackend *backend, const gchar *package_id)
static void
backend_update_system (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
pk_backend_spawn_helper (spawn, "update-system.py", NULL);
}
@@ -229,8 +203,6 @@ static void
backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package_id)
{
gchar *filters_text;
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
filters_text = pk_filter_enums_to_text (filters);
pk_backend_spawn_helper (spawn, "resolve.py", filters_text, package_id, NULL);
g_free (filters_text);
@@ -243,8 +215,6 @@ static void
backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
{
gchar *filters_text;
- g_return_if_fail (backend != NULL);
- g_return_if_fail (spawn != NULL);
filters_text = pk_filter_enums_to_text (filters);
pk_backend_spawn_helper (spawn, "get-repo-list.py", filters_text, NULL);
g_free (filters_text);
diff --git a/backends/apt/pk-sqlite-pkg-cache.cpp b/backends/apt/pk-sqlite-pkg-cache.cpp
index 715c343..8b60e57 100644
--- a/backends/apt/pk-sqlite-pkg-cache.cpp
+++ b/backends/apt/pk-sqlite-pkg-cache.cpp
@@ -24,7 +24,7 @@
#include "pk-sqlite-pkg-cache.h"
static sqlite3 *db = NULL;
-static PkBackendThread *thread;
+static PkBackend *backend;
static gboolean(*is_installed) (const PkPackageId *) = NULL;
void sqlite_set_installed_check(gboolean(*func) (const PkPackageId *))
@@ -32,16 +32,6 @@ void sqlite_set_installed_check(gboolean(*func) (const PkPackageId *))
is_installed = func;
}
-typedef struct {
- PkPackageId *pi;
-} desc_task;
-
-typedef struct {
- gchar *search;
- gchar *filter;
- SearchDepth depth;
-} search_task;
-
void
sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fname, void (*build_db)(PkBackend *, sqlite3 *))
{
@@ -49,8 +39,6 @@ sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fn
struct stat st;
time_t db_age;
- thread = pk_backend_thread_new ();
-
ret = sqlite3_open (dbname, &db);
g_assert(ret == SQLITE_OK);
g_assert(db!=NULL);
@@ -79,35 +67,33 @@ sqlite_init_cache(PkBackend *backend, const char* dbname, const char *compare_fn
sqlite3_exec(db,"insert into params values ('build_complete',1)", NULL, NULL, NULL);
}
-
void sqlite_finish_cache(PkBackend *backend)
{
sqlite3_close(db);
}
-
// sqlite_search_packages_thread
static gboolean
-sqlite_search_packages_thread (PkBackendThread *thread, gpointer data)
+sqlite_search_packages_thread (PkBackend *backend)
{
- search_task *st = (search_task *) data;
int res;
gchar *sel;
- PkBackend *backend;
+ const gchar *search;
- backend = pk_backend_thread_get_backend (thread);
pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates(backend);
+ type = pk_backend_get_uint (backend, "type");
+ search = pk_backend_get_string (backend, "search");
- pk_debug("finding %s", st->search);
+ pk_debug("finding %s", search);
sqlite3_stmt *package = NULL;
- g_strdelimit(st->search," ",'%');
+ g_strdelimit(search," ",'%');
- if (st->depth == SEARCH_NAME)
- sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",st->search);
- else if (st->depth == SEARCH_DETAILS)
- sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",st->search, st->search, st->search);
+ if (type == SEARCH_NAME)
+ sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%'",search);
+ else if (type == SEARCH_DETAILS)
+ sel = g_strdup_printf("select name,version,arch,repo,short_desc from packages where name like '%%%s%%' or short_desc like '%%%s%%' or long_desc like '%%%s%%'",search, search, search);
else
{
pk_backend_error_code(backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Unknown search task type");
@@ -147,35 +133,19 @@ sqlite_search_packages_thread (PkBackendThread *thread, gpointer data)
g_assert(0);
}
- end_search_packages:
- g_free(st->search);
- g_free(st);
-
+end_search_packages:
pk_backend_finished (backend);
return TRUE;
}
/**
- * backend_search_common
- **/
-void
-backend_search_common(PkBackend * backend, const gchar * filter, const gchar * search, SearchDepth which, PkBackendThreadFunc func)
-{
- g_return_if_fail (backend != NULL);
- search_task *data = g_new(search_task, 1);
- data->search = g_strdup(search);
- data->filter = g_strdup(filter);
- data->depth = which;
- pk_backend_thread_create_old (thread, func, data);
-}
-
-/**
* sqlite_search_details:
*/
void
sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *search)
{
- backend_search_common(backend, filter, search, SEARCH_DETAILS, sqlite_search_packages_thread);
+ pk_backend_set_uint (backend, "type", SEARCH_DETAILS);
+ pk_backend_thread_create (backend, sqlite_search_packages_thread);
}
/**
@@ -184,31 +154,41 @@ sqlite_search_details (PkBackend *backend, const gchar *filter, const gchar *sea
void
sqlite_search_name (PkBackend *backend, const gchar *filter, const gchar *search)
{
- backend_search_common(backend, filter, search, SEARCH_NAME, sqlite_search_packages_thread);
+ pk_backend_set_uint (backend, "type", SEARCH_NAME);
+ pk_backend_thread_create (backend, sqlite_search_packages_thread);
}
// sqlite_get_description_thread
-static gboolean sqlite_get_description_thread (PkBackendThread *thread, gpointer data)
+static gboolean
+sqlite_get_description_thread (PkBackend *backend)
{
- desc_task *dt = (desc_task *) data;
+ PkPackageId *pi;
+ const gchar *package_id;
int res;
- PkBackend *backend;
- backend = pk_backend_thread_get_backend (thread);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string(package_id);
+ if (pi == NULL)
+ {
+ pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
+ pk_backend_finished(backend);
+ return;
+ }
+
pk_backend_set_status(backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates(backend);
- pk_debug("finding %s", dt->pi->name);
+ pk_debug("finding %s", pi->name);
sqlite3_stmt *package = NULL;
- gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",dt->pi->name,dt->pi->version,dt->pi->data);
+ gchar *sel = g_strdup_printf("select long_desc from packages where name = '%s' and version = '%s' and repo = '%s'",pi->name,pi->version,pi->data);
pk_debug("statement is '%s'",sel);
res = sqlite3_prepare_v2(db,sel, -1, &package, NULL);
g_free(sel);
if (res!=SQLITE_OK)
pk_error("sqlite error during select prepare: %s", sqlite3_errmsg(db));
res = sqlite3_step(package);
- pk_backend_description(backend,dt->pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0);
+ pk_backend_description(backend,pi->name, "unknown", PK_GROUP_ENUM_OTHER,(const gchar*)sqlite3_column_text(package,0),"",0);
res = sqlite3_step(package);
if (res==SQLITE_ROW)
pk_error("multiple matches for that package!");
@@ -229,18 +209,7 @@ static gboolean sqlite_get_description_thread (PkBackendThread *thread, gpointer
extern "C++" void
sqlite_get_description (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
- desc_task *data = g_new(desc_task, 1);
- data->pi = pk_package_id_new_from_string(package_id);
- if (data->pi == NULL)
- {
- pk_backend_error_code(backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
- pk_backend_finished(backend);
- return;
- }
-
- pk_backend_thread_create_old (thread, sqlite_get_description_thread, data);
+ pk_backend_thread_create (backend, sqlite_get_description_thread);
return;
}
-
commit 7d66abcb58b871f17eea34d396afede3f45dc967
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 22:39:33 2008 +0100
convert the opkg backend from pk_backend_thread_create_old() to pk_backend_thread_create() and do a code review -- needs checking
diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
index 6585946..edc4de0 100644
--- a/backends/opkg/pk-backend-opkg.c
+++ b/backends/opkg/pk-backend-opkg.c
@@ -24,15 +24,12 @@
#include <glib.h>
#include <string.h>
#include <pk-backend.h>
-#include <pk-backend-thread.h>
#include <pk-debug.h>
#include <pk-package-ids.h>
#define OPKG_LIB
#include <libopkg.h>
-static PkBackendThread *thread;
-
/* this is implemented in libopkg.a */
int opkg_upgrade_pkg(opkg_conf_t *conf, pkg_t *old);
@@ -42,17 +39,13 @@ enum {
SEARCH_TAG
};
-/* parameters passed to the search thread */
-typedef struct {
- gint search_type;
- gchar *needle;
- PkFilterEnum filters;
-} SearchParams;
-
/* global config structures */
static opkg_conf_t global_conf;
static args_t args;
+/* opkg has no user_data */
+PkBackend *_backend = NULL;
+
/* Opkg message callback function */
extern opkg_message_callback opkg_cb_message;
static gchar *last_error;
@@ -63,13 +56,9 @@ extern opkg_download_progress_callback opkg_cb_download_progress;
/* Opkg state changed callback function */
extern opkg_state_changed_callback opkg_cb_state_changed;
-
int
opkg_debug (opkg_conf_t *conf, message_level_t level, char *msg)
{
- PkBackend *backend;
- backend = pk_backend_thread_get_backend (thread);
-
if (level == OPKG_NOTICE)
pk_debug ("OPKG Notice: %s", msg);
if (level == OPKG_ERROR)
@@ -80,35 +69,29 @@ opkg_debug (opkg_conf_t *conf, message_level_t level, char *msg)
printf ("OPKG: %s", msg);
/* free the last error message and store the new one */
- if (level == OPKG_ERROR)
- {
+ if (level == OPKG_ERROR) {
g_free (last_error);
last_error = g_strdup (msg);
}
return 0;
}
-
-
void
pk_opkg_state_changed (opkg_state_t state, const char *data)
{
- PkBackend *backend;
- backend = pk_backend_thread_get_backend (thread);
-
- /* data is conveniently in pkgid format :-) */
+_ /* data is conveniently in pkgid format :-) */
switch (state) {
case OPKG_STATE_DOWNLOADING_PKG:
- pk_backend_package (backend, PK_INFO_ENUM_DOWNLOADING, data, NULL);
+ pk_backend_package (_backend, PK_INFO_ENUM_DOWNLOADING, data, NULL);
break;
case OPKG_STATE_INSTALLING_PKG:
- pk_backend_package (backend, PK_INFO_ENUM_INSTALLING, data, NULL);
+ pk_backend_package (_backend, PK_INFO_ENUM_INSTALLING, data, NULL);
break;
case OPKG_STATE_REMOVING_PKG:
- pk_backend_package (backend, PK_INFO_ENUM_REMOVING, data, NULL);
+ pk_backend_package (_backend, PK_INFO_ENUM_REMOVING, data, NULL);
break;
case OPKG_STATE_UPGRADING_PKG:
- pk_backend_package (backend, PK_INFO_ENUM_UPDATING, data, NULL);
+ pk_backend_package (_backend, PK_INFO_ENUM_UPDATING, data, NULL);
break;
default: return;
}
@@ -133,14 +116,12 @@ opkg_unknown_error (PkBackend *backend, gint error_code, gchar *failed_cmd)
static gboolean
opkg_is_gui_pkg (pkg_t *pkg)
{
- gint i;
-
- for (i = 0; i < pkg->depends_count; i++)
- {
- if (g_strrstr (pkg->depends_str[i], "gtk"))
- return TRUE;
- }
- return FALSE;
+ gint i;
+ for (i = 0; i < pkg->depends_count; i++) {
+ if (g_strrstr (pkg->depends_str[i], "gtk"))
+ return TRUE;
+ }
+ return FALSE;
}
/**
@@ -151,16 +132,13 @@ opkg_is_gui_pkg (pkg_t *pkg)
static gboolean
opkg_is_devel_pkg (pkg_t *pkg)
{
- if (g_strrstr (pkg->name, "-dev"))
- return TRUE;
-
- if (g_strrstr (pkg->name, "-dbg"))
- return TRUE;
-
- if (g_strrstr (pkg->section, "devel"))
- return TRUE;
-
- return FALSE;
+ if (g_strrstr (pkg->name, "-dev"))
+ return TRUE;
+ if (g_strrstr (pkg->name, "-dbg"))
+ return TRUE;
+ if (g_strrstr (pkg->section, "devel"))
+ return TRUE;
+ return FALSE;
}
/**
@@ -173,8 +151,7 @@ static pkg_t*
opkg_vec_find_latest_helper (pkg_vec_t *vec, pkg_t *pkg)
{
gint i;
- for (i = 0; i < vec->len; i++)
- {
+ for (i = 0; i < vec->len; i++) {
/* if the version found is newer, return it */
if (pkg_compare_versions (pkg, vec->pkgs[i]) > 0)
return vec->pkgs[i];
@@ -196,8 +173,7 @@ opkg_vec_find_latest (pkg_vec_t *vec)
ret = tmp = vec->pkgs[0];
- for (i = 0; i < vec->len; i++)
- {
+ for (i = 0; i < vec->len; i++) {
tmp = opkg_vec_find_latest_helper (vec, ret);
if (!tmp)
return ret;
@@ -207,8 +183,6 @@ opkg_vec_find_latest (pkg_vec_t *vec)
return NULL;
}
-
-
/**
* opkg_check_tag:
* check a tag name and value on a package
@@ -231,11 +205,8 @@ static void
backend_initialize (PkBackend *backend)
{
int err;
- g_return_if_fail (backend != NULL);
-
- /* we use the thread helper */
- thread = pk_backend_thread_new ();
-
+ /* we have no userdata */
+ _backend = backend;
/* Ipkg requires the PATH env variable to be set to find wget when
* downloading packages. PackageKit unsets all env variables as a
@@ -268,10 +239,6 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
- g_object_unref (thread);
-
/* this appears to (sometimes) be freed elsewhere, perhaps
* by the functions in libopkg.c */
/* opkg_conf_deinit (&global_conf); */
@@ -280,21 +247,17 @@ backend_destroy (PkBackend *backend)
last_error = NULL;
}
-
static gboolean
-backend_get_description_thread (PkBackendThread *thread, gchar *package_id)
+backend_get_description_thread (PkBackend *backend)
{
pkg_t *pkg = NULL;
PkPackageId *pi;
- PkBackend *backend;
gboolean ret = TRUE;
+ const gchar *package_id;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ package_id = pk_backend_get_string (backend, "package_id");
pi = pk_package_id_new_from_string (package_id);
-
- if (!pi->name || !pi->version)
- {
+ if (!pi->name || !pi->version) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
ret = FALSE;
@@ -302,9 +265,7 @@ backend_get_description_thread (PkBackendThread *thread, gchar *package_id)
}
pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
-
- if (!pkg)
- {
+ if (!pkg) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
ret = FALSE;
@@ -312,13 +273,12 @@ backend_get_description_thread (PkBackendThread *thread, gchar *package_id)
}
pk_backend_description (backend, package_id,
- "unknown", PK_GROUP_ENUM_OTHER, pkg->description, pkg->url, 0);
+ "unknown", PK_GROUP_ENUM_OTHER, pkg->description, pkg->url, 0);
out:
g_free (package_id);
pk_backend_finished (backend);
return ret;
-
}
/**
@@ -327,18 +287,13 @@ out:
static void
backend_get_description (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_get_description_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_get_description_thread);
}
static void
pk_opkg_refresh_cache_progress_cb (int progress, char *url)
{
- PkBackend *backend;
static gint sources_list_count = 0;
static gint total_progress = 0;
static char *old_url = NULL;
@@ -357,25 +312,21 @@ pk_opkg_refresh_cache_progress_cb (int progress, char *url)
*/
/* calculate the number of files we are going to download */
- if (sources_list_count == 0)
- {
+ if (sources_list_count == 0) {
pkg_src_list_elt_t *p;
p = global_conf.pkg_src_list.head;
- while (p)
- {
+ while (p) {
sources_list_count++;
p = p->next;
};
}
- if (!old_url)
- {
+ if (!old_url) {
old_url = g_strdup (url);
}
/* increase the total progress mark if we are moving onto the next file */
- if (old_url && url && strcmp (old_url, url))
- {
+ if (old_url && url && strcmp (old_url, url)) {
total_progress += 100 / sources_list_count;
/* store the current url for comparison next time the progress callback
@@ -385,27 +336,19 @@ pk_opkg_refresh_cache_progress_cb (int progress, char *url)
}
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
/* set the percentage as a fraction of the current progress plus the
* progress we have already recorded */
if (total_progress + (progress / sources_list_count) > 100)
return;
- pk_backend_set_percentage (backend,
+ pk_backend_set_percentage (_backend,
total_progress + (progress / sources_list_count));
-
}
static gboolean
-backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
+backend_refresh_cache_thread (PkBackend *backend)
{
int ret;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
/* set the download progress callback */
opkg_cb_download_progress = pk_opkg_refresh_cache_progress_cb;
@@ -428,41 +371,27 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
pk_backend_no_percentage_updates (backend);
-
-
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_refresh_cache_thread,
- NULL);
+ pk_backend_thread_create (thread, backend_refresh_cache_thread);
}
/**
* backend_search_name:
*/
static gboolean
-backend_search_thread (PkBackendThread *thread, SearchParams *params)
+backend_search_thread (PkBackend *backend)
{
int i;
pkg_vec_t *available;
pkg_t *pkg;
gchar *search;
PkFilterEnum filters;
- PkBackend *backend;
-
- if (!params->needle)
- {
- g_free (params);
- return FALSE;
- }
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ guint type;
- search = params->needle;
- filters = params->filters;
+ search = pk_backend_get_string (backend, "needle");
+ filters = pk_backend_get_uint (backend, "filters");
+ type = pk_backend_get_uint (backend, "type");
available = pkg_vec_alloc();
pkg_hash_fetch_available (&global_conf.pkg_hash, available);
@@ -473,19 +402,17 @@ backend_search_thread (PkBackendThread *thread, SearchParams *params)
pkg = available->pkgs[i];
- if (params->search_type == SEARCH_NAME
+ if (search_type == SEARCH_NAME
&& !g_strrstr (pkg->name, search))
continue;
- else if (params->search_type == SEARCH_DESCRIPTION)
- {
+ else if (search_type == SEARCH_DESCRIPTION) {
gchar *needle, *haystack;
gboolean match;
- if (pkg->description && search)
- {
+ if (pkg->description && search) {
needle = g_utf8_strdown (search, -1);
haystack = g_utf8_strdown (pkg->description, -1);
- match = (g_strrstr (haystack, needle) != NULL);
+ match = (g_strrstr (haystack, needle_local) != NULL);
g_free (needle);
g_free (haystack);
}
@@ -498,7 +425,7 @@ backend_search_thread (PkBackendThread *thread, SearchParams *params)
continue;
}
- else if (params->search_type == SEARCH_TAG
+ else if (search_type == SEARCH_TAG
&&
(!pkg->tags || !g_strrstr (pkg->tags, search)))
continue;
@@ -531,28 +458,18 @@ backend_search_thread (PkBackendThread *thread, SearchParams *params)
pkg_vec_free(available);
pk_backend_finished (backend);
-
- g_free (params->needle);
- g_free (params);
return TRUE;
}
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchParams *params;
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- params = g_new0 (SearchParams, 1);
- params->filters = filters;
- params->search_type = SEARCH_NAME;
- params->needle = g_strdup (search);
-
- pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_set_uint (backend, "type", SEARCH_NAME);
+ pk_backend_set_string (backend, "search", search);
+ pk_backend_thread_create (backend, backend_search_thread);
}
/**
@@ -561,64 +478,43 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_search_description (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchParams *params;
-
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- params = g_new0 (SearchParams, 1);
- params->filters = filters;
- params->search_type = SEARCH_DESCRIPTION;
- params->needle = g_strdup (search);
-
- pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_set_uint (backend, "type", SEARCH_DESCRIPTION);
+ pk_backend_set_string (backend, "needle", search);
+ pk_backend_thread_create (backend, backend_search_thread);
}
static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- SearchParams *params;
-
- g_return_if_fail (backend != NULL);
-
+ gchar *needle;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- params = g_new0 (SearchParams, 1);
- params->filters = filters;
- params->search_type = SEARCH_TAG;
- params->needle = g_strdup_printf ("group::%s", search);
-
- pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_set_uint (backend, "type", SEARCH_TAG);
+ needle = g_strdup_printf ("group::%s", search);
+ pk_backend_set_string (backend, "needle", needle);
+ g_free (needle);
+ pk_backend_thread_create (backend, backend_search_thread);
}
-
-
-
static void
pk_opkg_install_progress_cb (int percent, char* url)
{
- PkBackend *backend;
-
/* get current backend and set percentage */
backend = pk_backend_thread_get_backend (thread);
pk_backend_set_percentage (backend, percent);
}
static gboolean
-backend_install_package_thread (PkBackendThread *thread, gchar *package_id)
+backend_install_package_thread (PkBackend *backend, gchar *package_id)
{
PkPackageId *pi;
gint err;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
pi = pk_package_id_new_from_string (package_id);
-
/* set the download progress callback */
opkg_cb_download_progress = pk_opkg_install_progress_cb;
@@ -638,38 +534,26 @@ backend_install_package_thread (PkBackendThread *thread, gchar *package_id)
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_no_percentage_updates (backend);
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
-
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_install_package_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_install_package_thread);
}
static gboolean
-backend_remove_package_thread (PkBackendThread *thread, gpointer data[3])
+backend_remove_package_thread (PkBackend *backend, gpointer data[3])
{
PkPackageId *pi;
gint err;
- PkBackend *backend;
gchar *package_id;
gboolean allow_deps;
gboolean autoremove;
-
package_id = (gchar*) data[0];
allow_deps = GPOINTER_TO_INT (data[1]);
autoremove = GPOINTER_TO_INT (data[2]);
g_free (data);
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
pi = pk_package_id_new_from_string (package_id);
-
args.autoremove = autoremove;
args.force_removal_of_dependent_packages = allow_deps;
@@ -689,7 +573,6 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
{
gpointer *params;
- g_return_if_fail (backend != NULL);
pk_backend_set_status (backend, PK_STATUS_ENUM_REMOVE);
pk_backend_no_percentage_updates (backend);
@@ -700,10 +583,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
params[1] = GINT_TO_POINTER (allow_deps);
params[2] = GINT_TO_POINTER (autoremove);
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_remove_package_thread,
- params);
-
+ pk_backend_thread_create (thread, backend_remove_package_thread, params);
}
/**
@@ -718,16 +598,11 @@ backend_get_filters (PkBackend *backend)
PK_FILTER_ENUM_GUI);
}
-
static gboolean
-backend_update_system_thread (PkBackendThread *thread, gpointer data)
+backend_update_system_thread (PkBackend *backend)
{
gint err;
err = opkg_packages_upgrade (&args);
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
if (err)
opkg_unknown_error (backend, err, "Upgrading system");
@@ -739,13 +614,9 @@ backend_update_system_thread (PkBackendThread *thread, gpointer data)
static void
backend_update_system (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
-
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_update_system_thread,
- NULL);
+ pk_backend_thread_create (thread, backend_update_system_thread);
}
/**
@@ -753,21 +624,15 @@ backend_update_system (PkBackend *backend)
*/
static gboolean
-backend_get_depends_thread (PkBackendThread *thread, gchar *package_id)
+backend_get_depends_thread (PkBackend *backend, gchar *package_id)
{
PkPackageId *pi;
pkg_t *pkg = NULL;
gint i;
GRegex *regex;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
pi = pk_package_id_new_from_string (package_id);
-
- if (!pi->name || !pi->version)
- {
+ if (!pi->name || !pi->version) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
pk_package_id_free (pi);
@@ -776,9 +641,7 @@ backend_get_depends_thread (PkBackendThread *thread, gchar *package_id)
}
pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
-
- if (!pkg)
- {
+ if (!pkg) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
pk_package_id_free (pi);
@@ -789,8 +652,7 @@ backend_get_depends_thread (PkBackendThread *thread, gchar *package_id)
/* compile a regex expression to parse depends_str package names */
regex = g_regex_new ("(.+) \\(([>=<]+) (.+)\\)", G_REGEX_OPTIMIZE, 0, NULL);
- for (i = 0; i < pkg->depends_count; i++)
- {
+ for (i = 0; i < pkg->depends_count; i++) {
pkg_t *d_pkg = NULL;
pkg_vec_t *p_vec;
GMatchInfo *match_info = NULL;
@@ -802,8 +664,7 @@ backend_get_depends_thread (PkBackendThread *thread, gchar *package_id)
* latest version number
*/
- if (!g_regex_match (regex, pkg->depends_str[i], 0, &match_info))
- {
+ if (!g_regex_match (regex, pkg->depends_str[i], 0, &match_info)) {
/* we couldn't parse the depends string */
/* match_info is always allocated, even if the match
@@ -843,44 +704,32 @@ backend_get_depends_thread (PkBackendThread *thread, gchar *package_id)
}
g_regex_unref (regex);
- pk_backend_finished (backend);
g_free (package_id);
-
+ pk_backend_finished (backend);
return TRUE;
}
static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- /* TODO: revursive is ignored */
- g_return_if_fail (backend != NULL);
-
+ /* TODO: recursive is ignored */
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
-
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_get_depends_thread,
- g_strdup (package_id));
+ pk_backend_thread_create (thread, backend_get_depends_thread);
}
/**
- * backend_update_package:
+ * backend_update_package_thread:
*/
static gboolean
-backend_update_package_thread (PkBackendThread *thread, gchar *package_id)
+backend_update_package_thread (PkBackend *backend, gchar *package_id)
{
PkPackageId *pi;
pkg_t *pkg;
gint err = 0;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
pi = pk_package_id_new_from_string (package_id);
-
- if (!pi->name || !pi->version)
- {
+ if (!pi->name || !pi->version) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Package not found");
pk_package_id_free (pi);
@@ -889,7 +738,6 @@ backend_update_package_thread (PkBackendThread *thread, gchar *package_id)
}
pkg = pkg_hash_fetch_by_name_version (&global_conf.pkg_hash, pi->name, pi->version);
-
if (!pkg) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND,
"Packge not found");
@@ -910,15 +758,11 @@ backend_update_package_thread (PkBackendThread *thread, gchar *package_id)
static void
backend_update_packages (PkBackend *backend, gchar **package_ids)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
-
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_update_package_thread,
- /* TODO: process the entire list */
- g_strdup (package_ids[0]));
+ /* TODO: process the entire list */
+ pk_backend_set_string (backend, "package_id", package_ids[0]);
+ pk_backend_thread_create (thread, backend_update_package_thread);
}
/**
@@ -926,21 +770,15 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
*/
static gboolean
-backend_get_updates_thread (PkBackendThread *thread, gpointer data)
+backend_get_updates_thread (PkBackend *backend)
{
pkg_vec_t *installed;
gint i;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
installed = pkg_vec_alloc();
-
pkg_hash_fetch_all_installed (&global_conf.pkg_hash, installed);
for (i=0; i < installed->len; i++) {
-
gchar *uid;
pkg_t *pkg, *best_pkg;
gint status;
@@ -976,14 +814,10 @@ backend_get_updates_thread (PkBackendThread *thread, gpointer data)
static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create_old (thread,
- (PkBackendThreadFunc) backend_get_updates_thread,
- NULL);
+ pk_backend_thread_create (thread, backend_get_updates_thread);
}
/**
@@ -1002,7 +836,6 @@ backend_get_groups (PkBackend *backend)
PK_GROUP_ENUM_MAPS);
}
-
PK_BACKEND_OPTIONS (
"opkg", /* description */
"Thomas Wood <thomas at openedhand.com>", /* author */
commit 636f7a716add17200919cd2d847ee2e8a78842a3
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 22:09:34 2008 +0100
convert the zypp backend from pk_backend_thread_create_old() to pk_backend_thread_create() and do a code review -- needs checking
diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index 81baf47..14592f1 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -22,7 +22,6 @@
#include <gmodule.h>
#include <glib.h>
#include <pk-backend.h>
-#include <pk-backend-thread.h>
#include <unistd.h>
#include <pk-debug.h>
#include <string>
@@ -76,64 +75,12 @@ enum DepsBehavior {
DEPS_NO_ALLOW = 1
};
-typedef struct {
- gchar *search;
- PkFilterEnum filters;
- gint mode;
-} FindData;
-
-typedef struct {
- gchar *pkGroup;
- PkFilterEnum filters;
-} GroupData;
-
-typedef struct {
- gchar *name;
- PkFilterEnum filters;
-} ResolveData;
-
-typedef struct {
- gchar *package_id;
- gint type;
-} ThreadData;
-
-typedef struct {
- gchar *full_path;
-} InstFileData;
-
-typedef struct {
- gchar *package_id;
- PkFilterEnum filters;
- gint type;
-} FilterData;
-
-typedef struct {
- gboolean force;
-} RefreshData;
-
-typedef struct {
- gchar *package_id;
- gint deps_behavior;
-} RemovePackageData;
-
-typedef struct {
- gchar **packages;
-} UpdateData;
-
-typedef struct {
- gchar *repo_id;
- gchar *parameter;
- gchar *value;
-} RepoData;
-
/**
* A map to keep track of the EventDirector objects for
* each zypp backend that is created.
*/
static std::map<PkBackend *, EventDirector *> _eventDirectors;
-static PkBackendThread *thread;
-
/**
* backend_initialize:
* This should only be run once per backend load, i.e. not every transaction
@@ -141,13 +88,10 @@ static PkBackendThread *thread;
static void
backend_initialize (PkBackend *backend)
{
- zypp::base::LogControl::instance ().logfile("/var/log/pk_backend_zypp");
- g_return_if_fail (backend != NULL);
+ zypp::base::LogControl::instance ().logfile("/var/log/pk_backend_zypp");
pk_debug ("zypp_backend_initialize");
EventDirector *eventDirector = new EventDirector (backend);
_eventDirectors [backend] = eventDirector;
-
- thread = pk_backend_thread_new ();
}
/**
@@ -157,161 +101,139 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
- pk_debug ("zypp_backend_destroy");
+ pk_debug ("zypp_backend_destroy");
EventDirector *eventDirector = _eventDirectors [backend];
if (eventDirector != NULL) {
delete (eventDirector);
_eventDirectors.erase (backend);
}
-
- g_object_unref (thread);
}
/**
* backend_get_requires_thread:
*/
static gboolean
-backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
-
- PkPackageId *pi;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- FilterData *d = (FilterData*) data;
+backend_get_requires_thread (PkBackend *backend)
+{
+ PkPackageId *pi;
+ const gchar *package_id;
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
- zypp::sat::Solvable solvable = zypp_get_package_by_id (d->package_id);
- zypp::PoolItem package;
-
- if (solvable.isSystem ()) {
- zypp::ResPool pool = zypp_build_pool (true);
-
- gboolean found = FALSE;
-
- for (zypp::ResPool::byIdent_iterator it = pool.byIdentBegin (zypp::ResKind::package, pi->name);
- it != pool.byIdentEnd (zypp::ResKind::package, pi->name); it++) {
- if (it->status ().isInstalled ()) {
- package = (*it);
- found = TRUE;
- }
- }
-
- if (found == FALSE) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED, "Package is not installed");
- pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
- return FALSE;
- }
-
- // set Package as to be uninstalled
- package.status ().setToBeUninstalled (zypp::ResStatus::USER);
-
- }else{
-
- if (solvable == zypp::sat::Solvable::noSolvable) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Package couldn't be found");
- pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
- return FALSE;
- }
-
- zypp::ResPool pool = zypp::ResPool::instance ();
- package = pool.find (solvable);
- //set Package as to be installed
- package.status ().setToBeInstalled (zypp::ResStatus::USER);
- }
+ zypp::sat::Solvable solvable = zypp_get_package_by_id (package_id);
+ zypp::PoolItem package;
+
+ if (solvable.isSystem ()) {
+ zypp::ResPool pool = zypp_build_pool (true);
+
+ gboolean found = FALSE;
+
+ for (zypp::ResPool::byIdent_iterator it = pool.byIdentBegin (zypp::ResKind::package, pi->name);
+ it != pool.byIdentEnd (zypp::ResKind::package, pi->name); it++) {
+ if (it->status ().isInstalled ()) {
+ package = (*it);
+ found = TRUE;
+ }
+ }
+
+ if (found == FALSE) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_INSTALLED, "Package is not installed");
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
+
+ // set Package as to be uninstalled
+ package.status ().setToBeUninstalled (zypp::ResStatus::USER);
+ } else {
+ if (solvable == zypp::sat::Solvable::noSolvable) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Package couldn't be found");
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
+
+ zypp::ResPool pool = zypp::ResPool::instance ();
+ package = pool.find (solvable);
+ //set Package as to be installed
+ package.status ().setToBeInstalled (zypp::ResStatus::USER);
+ }
pk_backend_set_percentage (backend, 40);
- // solver run
- zypp::ResPool pool = zypp::ResPool::instance ();
- zypp::Resolver solver(pool);
+ // solver run
+ zypp::ResPool pool = zypp::ResPool::instance ();
+ zypp::Resolver solver(pool);
- solver.setForceResolve (true);
+ solver.setForceResolve (true);
- if (solver.resolvePool () == FALSE) {
- std::list<zypp::ResolverProblem_Ptr> problems = solver.problems ();
- for(std::list<zypp::ResolverProblem_Ptr>::iterator it = problems.begin (); it != problems.end (); it++){
- pk_warning("Solver problem (This should never happen): '%s'", (*it)->description ().c_str ());
- }
+ if (solver.resolvePool () == FALSE) {
+ std::list<zypp::ResolverProblem_Ptr> problems = solver.problems ();
+ for (std::list<zypp::ResolverProblem_Ptr>::iterator it = problems.begin (); it != problems.end (); it++){
+ pk_warning("Solver problem (This should never happen): '%s'", (*it)->description ().c_str ());
+ }
pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Resolution failed");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
pk_backend_set_percentage (backend, 60);
- // look for packages which would be uninstalled
- for (zypp::ResPool::byKind_iterator it = pool.byKindBegin (zypp::ResKind::package);
- it != pool.byKindEnd (zypp::ResKind::package); it++) {
- PkInfoEnum status = PK_INFO_ENUM_UNKNOWN;
-
- gboolean hit = FALSE;
-
- if (it->status ().isToBeUninstalled ()) {
- status = PK_INFO_ENUM_REMOVING;
- hit = TRUE;
- }else if (it->status ().isToBeInstalled ()) {
- status = PK_INFO_ENUM_INSTALLING;
- hit = TRUE;
- }else if (it->status ().isToBeUninstalledDueToUpgrade ()) {
- status = PK_INFO_ENUM_UPDATING;
- hit = TRUE;
- }else if (it->status ().isToBeUninstalledDueToObsolete ()) {
- status = PK_INFO_ENUM_OBSOLETING;
- hit = TRUE;
- }
-
- if (hit) {
- gchar *package_id;
-
- package_id = pk_package_id_build ( it->resolvable ()->name ().c_str(),
- it->resolvable ()->edition ().asString ().c_str(),
- it->resolvable ()->arch ().c_str(),
- it->resolvable ()->repoInfo().alias ().c_str ());
-
- pk_backend_package (backend,
- status,
- package_id,
- "");
+ // look for packages which would be uninstalled
+ for (zypp::ResPool::byKind_iterator it = pool.byKindBegin (zypp::ResKind::package);
+ it != pool.byKindEnd (zypp::ResKind::package); it++) {
+ PkInfoEnum status = PK_INFO_ENUM_UNKNOWN;
+
+ gboolean hit = FALSE;
+
+ if (it->status ().isToBeUninstalled ()) {
+ status = PK_INFO_ENUM_REMOVING;
+ hit = TRUE;
+ }else if (it->status ().isToBeInstalled ()) {
+ status = PK_INFO_ENUM_INSTALLING;
+ hit = TRUE;
+ }else if (it->status ().isToBeUninstalledDueToUpgrade ()) {
+ status = PK_INFO_ENUM_UPDATING;
+ hit = TRUE;
+ }else if (it->status ().isToBeUninstalledDueToObsolete ()) {
+ status = PK_INFO_ENUM_OBSOLETING;
+ hit = TRUE;
+ }
+
+ if (hit) {
+ gchar *package_id;
+ package_id = pk_package_id_build ( it->resolvable ()->name ().c_str(),
+ it->resolvable ()->edition ().asString ().c_str(),
+ it->resolvable ()->arch ().c_str(),
+ it->resolvable ()->repoInfo().alias ().c_str ());
+
+ pk_backend_package (backend, status, package_id, "");
// FIXME There is something in our descriptions which let crash pk
- //it->resolvable ()->description ().c_str ());
+ //it->resolvable ()->description ().c_str ());
- g_free (package_id);
- }
- it->statusReset ();
- }
+ g_free (package_id);
+ }
+ it->statusReset ();
+ }
- // undo the status-change of the package and disable forceResolve
- package.statusReset ();
- solver.setForceResolve (false);
+ // undo the status-change of the package and disable forceResolve
+ package.statusReset ();
+ solver.setForceResolve (false);
- pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
+ pk_package_id_free (pi);
- return TRUE;
+ pk_backend_finished (backend);
+ return TRUE;
}
/**
@@ -320,13 +242,7 @@ backend_get_requires_thread (PkBackendThread *thread, gpointer data) {
static void
backend_get_requires(PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- g_return_if_fail (backend != NULL);
-
- FilterData *data = g_new0(FilterData, 1);
- data->package_id = g_strdup(package_id);
- data->type = recursive;
- data->filters = filters;
- pk_backend_thread_create_old (thread, backend_get_requires_thread, data);
+ pk_backend_thread_create (backend, backend_get_requires_thread);
}
/**
@@ -335,12 +251,11 @@ backend_get_requires(PkBackend *backend, PkFilterEnum filters, const gchar *pack
static PkGroupEnum
backend_get_groups (PkBackend *backend)
{
- g_return_val_if_fail (backend != NULL, PK_GROUP_ENUM_UNKNOWN);
return (PkGroupEnum)(PK_GROUP_ENUM_ADMIN_TOOLS |
PK_GROUP_ENUM_COMMUNICATION |
PK_GROUP_ENUM_DESKTOP_GNOME |
- PK_GROUP_ENUM_DESKTOP_KDE |
- PK_GROUP_ENUM_DESKTOP_OTHER |
+ PK_GROUP_ENUM_DESKTOP_KDE |
+ PK_GROUP_ENUM_DESKTOP_OTHER |
PK_GROUP_ENUM_DESKTOP_XFCE |
PK_GROUP_ENUM_EDUCATION |
PK_GROUP_ENUM_GAMES |
@@ -362,7 +277,6 @@ backend_get_groups (PkBackend *backend)
static PkFilterEnum
backend_get_filters (PkBackend *backend)
{
- g_return_val_if_fail (backend != NULL, PK_FILTER_ENUM_UNKNOWN);
return (PkFilterEnum) (PK_FILTER_ENUM_INSTALLED |
PK_FILTER_ENUM_NOT_INSTALLED |
PK_FILTER_ENUM_ARCH |
@@ -370,21 +284,17 @@ backend_get_filters (PkBackend *backend)
}
static gboolean
-backend_get_depends_thread (PkBackendThread *thread, gpointer data)
+backend_get_depends_thread (PkBackend *backend)
{
- PkBackend *backend;
- backend = pk_backend_thread_get_backend (thread);
-
- ThreadData *d = (ThreadData*) data;
+ const gchar *package_id;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
- PkPackageId *pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ PkPackageId *pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -424,15 +334,12 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
if (pool_item_found == FALSE) {
pk_backend_error_code (backend, PK_ERROR_ENUM_DEP_RESOLUTION_FAILED, "Did not find the specified package.");
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
// Gather up any dependencies
pk_backend_set_status (backend, PK_STATUS_ENUM_DEP_RESOLVE);
-
pk_backend_set_percentage (backend, 60);
// get dependencies
@@ -448,7 +355,6 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
for (zypp::sat::WhatProvides::const_iterator it2 = provider.begin ();
it2 != provider.end ();
it2++) {
-
// Adding Packages only one time
std::map<std::string, zypp::sat::Solvable>::iterator mIt;
mIt = caps.find(it->asString ());
@@ -458,7 +364,7 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
caps.erase (mIt);
caps[it->asString ()] = *it2;
}
- }else{
+ } else {
caps[it->asString ()] = *it2;
}
temp.push_back(it2->name ());
@@ -470,8 +376,7 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
for (std::map<std::string, zypp::sat::Solvable>::iterator it = caps.begin ();
it != caps.end();
it++) {
-
- gchar *package_id;
+ gchar *package_id_temp;
gchar *package_name;
/* do not emit packages with invalid names generated above via dependencies such as "rpmlib(PayloadFilesHavePrefix) <= 4.0-1"
@@ -488,80 +393,69 @@ backend_get_depends_thread (PkBackendThread *thread, gpointer data)
}
g_free (package_name);
- package_id = pk_package_id_build (it->second.name ().c_str(),
+ package_id_temp = pk_package_id_build (it->second.name ().c_str(),
it->second.edition ().asString ().c_str(),
it->second.arch ().c_str(),
it->second.repository ().name ().c_str());
-
+
zypp::PoolItem item = zypp::ResPool::instance ().find (it->second);
-
+
if (it->second.isSystem ()) {
pk_backend_package (backend,
PK_INFO_ENUM_INSTALLED,
- package_id,
+ package_id_temp,
item->description ().c_str());
- }else{
+ } else {
pk_backend_package (backend,
PK_INFO_ENUM_AVAILABLE,
- package_id,
+ package_id_temp,
"");
}
- g_free (package_id);
+ g_free (package_id_temp);
}
pk_backend_set_percentage (backend, 100);
} catch (const zypp::repo::RepoNotFoundException &ex) {
// TODO: make sure this dumps out the right sring.
pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
- g_free (d->package_id);
- g_free (d);
+
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
} catch (const zypp::Exception &ex) {
//pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Error enumerating repositories");
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
- g_free (d->package_id);
- g_free (d);
+
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
}
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return TRUE;
}
-
/**
* backend_get_depends:
*/
static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- g_return_if_fail (backend != NULL);
- ThreadData *data = g_new0(ThreadData, 1);
- data->package_id = g_strdup (package_id);
- data->type = DEPS_TYPE_DEPENDS;
- pk_backend_thread_create_old (thread, backend_get_depends_thread, data);
+ pk_backend_set_uint (backend, "type", DEPS_TYPE_DEPENDS);
+ pk_backend_thread_create (backend, backend_get_depends_thread);
}
static gboolean
-backend_get_description_thread (PkBackendThread *thread, gpointer data)
+backend_get_description_thread (PkBackend *backend)
{
- PkBackend *backend;
+ const gchar *package_id;
PkPackageId *pi;
- ThreadData *d = (ThreadData*) data;
- backend = pk_backend_thread_get_backend (thread);
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -587,15 +481,12 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
g_free (version);
g_free (arch);
}
-
delete (v);
delete (v2);
if (package == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "couldn't find package");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -607,16 +498,16 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
zypp::target::rpm::RpmHeader::constPtr rpmHeader = zypp_get_rpmHeader (package.name (), package.edition ());
pk_backend_description (backend,
- d->package_id, // package_id
+ package_id, // package_id
rpmHeader->tag_license ().c_str (), // const gchar *license
- group, // PkGroupEnum group
+ group, // PkGroupEnum group
package.lookupStrAttribute (zypp::sat::SolvAttr::description).c_str (), //pkg->description ().c_str (),
- rpmHeader->tag_url (). c_str (), // const gchar *url
- (gulong)rpmHeader->tag_archivesize ()); // gulong size
+ rpmHeader->tag_url (). c_str (), // const gchar *url
+ (gulong)rpmHeader->tag_archivesize ()); // gulong size
- }else{
+ } else {
pk_backend_description (backend,
- d->package_id,
+ package_id,
package.lookupStrAttribute (zypp::sat::SolvAttr::license).c_str (), //pkg->license ().c_str (),
group,
package.lookupStrAttribute (zypp::sat::SolvAttr::description).c_str (), //pkg->description ().c_str (),
@@ -627,22 +518,17 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
} catch (const zypp::target::rpm::RpmException &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Couldn't open rpm-database");
pk_backend_finished (backend);
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
} catch (const zypp::Exception &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString ().c_str ());
pk_backend_finished (backend);
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
}
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
@@ -652,41 +538,31 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
static void
backend_get_description (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
- ThreadData *data = g_new0(ThreadData, 1);
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_get_description_thread, data);
+ pk_backend_thread_create (backend, backend_get_description_thread);
}
static gboolean
-backend_get_updates_thread (PkBackendThread *thread, gpointer data)
+backend_get_updates_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- backend = pk_backend_thread_get_backend (thread);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
zypp::ResPool pool = zypp_build_pool (TRUE);
pk_backend_set_percentage (backend, 40);
-
- // get all Packages and Patches for Update
- std::set<zypp::PoolItem> *candidates = zypp_get_updates ();
+ // get all Packages and Patches for Update
+ std::set<zypp::PoolItem> *candidates = zypp_get_updates ();
std::set<zypp::PoolItem> *candidates2 = zypp_get_patches ();
candidates->insert (candidates2->begin (), candidates2->end ());
pk_backend_set_percentage (backend, 80);
- std::set<zypp::PoolItem>::iterator cb = candidates->begin (), ce = candidates->end (), ci;
+ std::set<zypp::PoolItem>::iterator cb = candidates->begin (), ce = candidates->end (), ci;
for (ci = cb; ci != ce; ++ci) {
zypp::ResObject::constPtr res = ci->resolvable();
// Emit the package
-
PkInfoEnum infoEnum = PK_INFO_ENUM_ENHANCEMENT;
-
if (zypp::isKind<zypp::Patch>(res)) {
zypp::Patch::constPtr patch = zypp::asKind<zypp::Patch>(res);
if (patch->category () == "recommended") {
@@ -695,18 +571,14 @@ backend_get_updates_thread (PkBackendThread *thread, gpointer data)
infoEnum = PK_INFO_ENUM_LOW;
}else if (patch->category () == "security") {
infoEnum = PK_INFO_ENUM_SECURITY;
- }else{
+ } else {
infoEnum = PK_INFO_ENUM_NORMAL;
}
}
-
gchar *package_id = zypp_build_package_id_from_resolvable (res->satSolvable ());
- pk_backend_package (backend,
- infoEnum,
- package_id,
- "");
- // some package descriptions generate markup parse failures
+ pk_backend_package (backend, infoEnum, package_id, "");
+ // some package descriptions generate markup parse failures
// causing the update to show empty package lines, comment for now
// res->description ().c_str ());
g_free (package_id);
@@ -721,15 +593,8 @@ backend_get_updates_thread (PkBackendThread *thread, gpointer data)
}
static gboolean
-backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
+backend_refresh_cache_thread (PkBackend *backend)
{
- PkBackend *backend;
- RefreshData *d = (RefreshData*) data;
-
- backend = pk_backend_thread_get_backend (thread);
- gboolean force = d->force;
- g_free (d);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
pk_backend_set_percentage (backend, 0);
@@ -764,7 +629,7 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
continue;
try {
- // Refreshing metadata
+ // Refreshing metadata
manager.refreshMetadata (repo, force == TRUE ?
zypp::RepoManager::RefreshForced :
zypp::RepoManager::RefreshIfNeeded);
@@ -775,8 +640,8 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
}
try {
- // Building cache
- manager.buildCache (repo, force == TRUE ?
+ // Building cache
+ manager.buildCache (repo, force == TRUE ?
zypp::RepoManager::BuildForced :
zypp::RepoManager::BuildIfNeeded);
//} catch (const zypp::repo::RepoNoUrlException &ex) {
@@ -785,16 +650,14 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
//} catch (const zypp::repo::RepoException &ex) {
} catch (const zypp::Exception &ex) {
// TODO: Handle the exceptions in manager.refreshMetadata
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "%s: %s", repo.alias ().c_str (), ex.asUserString().c_str() );
+ pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "%s: %s",
+ repo.alias ().c_str (), ex.asUserString().c_str() );
pk_backend_finished (backend);
return FALSE;
}
// Update the percentage completed
- pk_backend_set_percentage (backend,
- i == num_of_repos ?
- 100 :
- i * percentage_increment);
+ pk_backend_set_percentage (backend, i == num_of_repos ? 100 : i * percentage_increment);
}
pk_backend_finished (backend);
@@ -807,27 +670,21 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
- g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create (backend, backend_get_updates_thread);
}
static gboolean
-backend_install_file_thread (PkBackendThread *thread, gpointer data)
+backend_install_file_thread (PkBackend *backend)
{
- PkBackend *backend;
- InstFileData *d = (InstFileData*) data;
-
- backend = pk_backend_thread_get_backend (thread);
+ const gchar *full_path;
// check if file is really a rpm
-
- zypp::Pathname rpmPath (d->full_path);
+ full_path = pk_backend_get_string (backend, "full_path");
+ zypp::Pathname rpmPath (full_path);
zypp::target::rpm::RpmHeader::constPtr rpmHeader = zypp::target::rpm::RpmHeader::readPackage (rpmPath, zypp::target::rpm::RpmHeader::NOSIGNATURE);
if (rpmHeader == NULL) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "%s is no valid rpm-File", d->full_path);
- g_free (d->full_path);
- g_free (d);
+ pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "%s is no valid rpm-File", full_path);
pk_backend_finished (backend);
return FALSE;
}
@@ -836,8 +693,6 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
zypp::filesystem::TmpDir tmpDir;
if (tmpDir == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "Could not create a temporary directory");
- g_free (d->full_path);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -845,10 +700,8 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
// copy the rpm into tmpdir
std::string tempDest = tmpDir.path ().asString () + "/" + rpmHeader->tag_name () + ".rpm";
- if (zypp::filesystem::copy (d->full_path, tempDest) != 0) {
+ if (zypp::filesystem::copy (full_path, tempDest) != 0) {
pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "Could not copy the rpm-file into the temp-dir");
- g_free (d->full_path);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -857,7 +710,6 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
zypp::RepoInfo tmpRepo;
try {
-
tmpRepo.setType(zypp::repo::RepoType::RPMPLAINDIR);
std::string url = "dir://" + tmpDir.path ().asString ();
tmpRepo.addBaseUrl(zypp::Url::parseUrl(url));
@@ -876,20 +728,18 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
} catch (const zypp::url::UrlException &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString ().c_str ());
- g_free (d->full_path);
- g_free (d);
+
pk_backend_finished (backend);
return FALSE;
} catch (const zypp::Exception &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
- g_free (d->full_path);
- g_free (d);
+
pk_backend_finished (backend);
return FALSE;
}
// look for the package and try to install it
- std::vector<zypp::sat::Solvable> *solvables = new std::vector<zypp::sat::Solvable>;
+ std::vector<zypp::sat::Solvable> *solvables = new std::vector<zypp::sat::Solvable>;
solvables = zypp_get_packages_by_name (rpmHeader->tag_name ().c_str (), zypp::ResKind::package, FALSE);
zypp::PoolItem *item = NULL;
gboolean found = FALSE;
@@ -904,13 +754,13 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
if (!found) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Could not find the rpm-Package in Pool");
- }else{
+ } else {
zypp::ResStatus status = item->status ().setToBeInstalled (zypp::ResStatus::USER);
if (!zypp_perform_execution (backend, INSTALL, FALSE)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_LOCAL_INSTALL_FAILED, "Could not install the rpm-file.");
- }
+ }
- item->statusReset ();
+ item->statusReset ();
}
//remove tmp-dir and the tmp-repo
@@ -921,8 +771,6 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
}
- g_free (d->full_path);
- g_free (d);
delete (solvables);
delete (item);
pk_backend_finished (backend);
@@ -935,33 +783,27 @@ backend_install_file_thread (PkBackendThread *thread, gpointer data)
static void
backend_install_file (PkBackend *backend, gboolean trusted, const gchar *full_path)
{
- g_return_if_fail (backend != NULL);
- InstFileData *data = g_new0(InstFileData, 1);
- data->full_path = g_strdup (full_path);
-
- pk_backend_thread_create_old (thread, backend_install_file_thread, data);
+ pk_backend_thread_create (backend, backend_install_file_thread);
}
static gboolean
-backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
+backend_get_update_detail_thread (PkBackend *backend)
{
- PkBackend *backend;
PkPackageId *pi;
- ThreadData *d = (ThreadData*) data;
+ const gchar *package_id;
- backend = pk_backend_thread_get_backend (thread);
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
+
pk_backend_finished (backend);
return FALSE;
}
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- zypp::sat::Solvable solvable = zypp_get_package_by_id (d->package_id);
+ zypp::sat::Solvable solvable = zypp_get_package_by_id (package_id);
zypp::Capabilities obs = solvable.obsoletes ();
zypp::Capabilities upd = solvable.freshens ();
@@ -972,7 +814,7 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
PkRestartEnum restart = PK_RESTART_ENUM_NONE;
zypp::PoolItem item = zypp::ResPool::instance ().find (solvable);
-
+
gchar *bugzilla = new gchar ();
gchar *cve = new gchar ();
@@ -980,7 +822,7 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
zypp::Patch::constPtr patch = zypp::asKind<zypp::Patch>(item);
if (patch->rebootSuggested ()) {
restart = PK_RESTART_ENUM_SYSTEM;
- }else if (patch->restartSuggested ()) {
+ } else if (patch->restartSuggested ()) {
restart = PK_RESTART_ENUM_SESSION;
}
@@ -989,18 +831,18 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
if (it.type () == "bugzilla") {
if (strlen (bugzilla) == 0) {
bugzilla = g_strconcat (it.href ().c_str (), ";", it.title ().c_str (), (gchar *)NULL);
- }else{
+ } else {
bugzilla = g_strconcat (bugzilla, ";", it.href ().c_str (), ";", it.title ().c_str (), (gchar *)NULL);
}
- }else{
+ } else {
if (strlen (cve) == 0) {
cve = g_strconcat (it.href ().c_str (), ";", it.title ().c_str (), (gchar *)NULL);
- }else{
+ } else {
cve = g_strconcat (cve, it.href ().c_str (), ";", it.title ().c_str (), ";", (gchar *)NULL);
}
}
}
-
+
zypp::sat::SolvableSet content = patch->contents ();
for (zypp::sat::SolvableSet::const_iterator it = content.begin (); it != content.end (); it++) {
@@ -1010,7 +852,7 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
}
pk_backend_update_detail (backend,
- d->package_id,
+ package_id,
updates, // updates
obsoletes, // CURRENTLY CAUSES SEGFAULT obsoletes,
"", // CURRENTLY CAUSES SEGFAULT solvable.vendor ().c_str (),
@@ -1024,10 +866,8 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
g_free (obsoletes);
g_free (updates);
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
+ pk_backend_finished (backend);
return TRUE;
}
@@ -1037,27 +877,20 @@ backend_get_update_detail_thread (PkBackendThread *thread, gpointer data)
static void
backend_get_update_detail (PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
- ThreadData *data = g_new0(ThreadData, 1);
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_get_update_detail_thread, data);
+ pk_backend_thread_create (backend, backend_get_update_detail_thread);
}
static gboolean
-backend_update_system_thread (PkBackendThread *thread, gpointer data)
+backend_update_system_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- backend = pk_backend_thread_get_backend (thread);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
zypp::ResPool pool = zypp_build_pool (TRUE);
pk_backend_set_percentage (backend, 40);
- // get all Packages for Update
- std::set<zypp::PoolItem> *candidates = zypp_get_updates ();
+ // get all Packages for Update
+ std::set<zypp::PoolItem> *candidates = zypp_get_updates ();
//get all Patches for Update
std::set<zypp::PoolItem> *candidates2 = zypp_get_patches ();
@@ -1066,21 +899,21 @@ backend_update_system_thread (PkBackendThread *thread, gpointer data)
candidates->insert (candidates->begin (), candidates->end ());
pk_backend_set_percentage (backend, 80);
- std::set<zypp::PoolItem>::iterator cb = candidates->begin (), ce = candidates->end (), ci;
+ std::set<zypp::PoolItem>::iterator cb = candidates->begin (), ce = candidates->end (), ci;
for (ci = cb; ci != ce; ++ci) {
- // set the status of the update to ToBeInstalled
- zypp::ResStatus &status = ci->status ();
- status.setToBeInstalled (zypp::ResStatus::USER);
+ // set the status of the update to ToBeInstalled
+ zypp::ResStatus &status = ci->status ();
+ status.setToBeInstalled (zypp::ResStatus::USER);
}
- if (!zypp_perform_execution (backend, UPDATE, FALSE)) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_ERROR, "Couldn't perform the installation.");
- pk_backend_finished (backend);
- return FALSE;
- }
+ if (!zypp_perform_execution (backend, UPDATE, FALSE)) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_ERROR, "Couldn't perform the installation.");
+ pk_backend_finished (backend);
+ return FALSE;
+ }
delete (candidates2);
- delete (candidates);
+ delete (candidates);
pk_backend_set_percentage (backend, 100);
pk_backend_finished (backend);
return TRUE;
@@ -1092,21 +925,18 @@ backend_update_system_thread (PkBackendThread *thread, gpointer data)
static void
backend_update_system (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_update_system_thread, NULL);
+ pk_backend_thread_create (backend, backend_update_system_thread);
}
static gboolean
-backend_install_package_thread (PkBackendThread *thread, gpointer data)
+backend_install_package_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- backend = pk_backend_thread_get_backend (thread);
- gchar *package_id = (gchar *)data;
+ const gchar *package_id;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
+ package_id = pk_backend_get_string (backend, "package_id");
PkPackageId *pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
@@ -1120,63 +950,62 @@ backend_install_package_thread (PkBackendThread *thread, gpointer data)
try
{
- zypp::ResPool pool = zypp_build_pool (TRUE);
- pk_backend_set_percentage (backend, 10);
- gboolean hit = false;
+ zypp::ResPool pool = zypp_build_pool (TRUE);
+ pk_backend_set_percentage (backend, 10);
+ gboolean hit = false;
// Iterate over the selectables and mark the one with the right name
- zypp::ui::Selectable::Ptr selectable;
+ zypp::ui::Selectable::Ptr selectable;
for (zypp::ResPoolProxy::const_iterator it = zypp->poolProxy().byKindBegin <zypp::Package>();
it != zypp->poolProxy().byKindEnd <zypp::Package>(); it++) {
if (strcmp ((*it)->name ().c_str (), pi->name) == 0) {
- selectable = *it;
- break;
- }
+ selectable = *it;
+ break;
+ }
+ }
+
+ // Choose the PoolItem with the right architecture and version
+ zypp::PoolItem item;
+ for (zypp::ui::Selectable::available_iterator it = selectable->availableBegin ();
+ it != selectable->availableEnd (); it++) {
+ if (strcmp ((*it)->edition ().asString ().c_str (), pi->version) == 0
+ && strcmp ((*it)->arch ().c_str (), pi->arch) == 0 ) {
+ hit = true;
+ // set status to ToBeInstalled
+ it->status ().setToBeInstalled (zypp::ResStatus::USER);
+ item = *it;
+ break;
+ }
}
- // Choose the PoolItem with the right architecture and version
- zypp::PoolItem item;
- for (zypp::ui::Selectable::available_iterator it = selectable->availableBegin ();
- it != selectable->availableEnd (); it++) {
- if (strcmp ((*it)->edition ().asString ().c_str (), pi->version) == 0
- && strcmp ((*it)->arch ().c_str (), pi->arch) == 0 ) {
- hit = true;
- // set status to ToBeInstalled
- it->status ().setToBeInstalled (zypp::ResStatus::USER);
- item = *it;
- break;
- }
- }
-
- if (!hit) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find the package.");
- g_free (package_id);
- pk_package_id_free (pi);
- pk_backend_finished (backend);
- return FALSE;
- }
+ if (!hit) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "Couldn't find the package.");
+ g_free (package_id);
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
pk_backend_set_percentage (backend, 40);
if (!zypp_perform_execution (backend, INSTALL, FALSE)) {
+ g_free (package_id);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
- g_free (package_id);
- pk_backend_finished (backend);
- return FALSE;
- }
-
- item.statusReset ();
+ item.statusReset ();
pk_backend_set_percentage (backend, 100);
- } catch (const zypp::Exception &ex) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
- g_free (package_id);
- pk_package_id_free (pi);
- pk_backend_finished (backend);
- return FALSE;
- }
+ } catch (const zypp::Exception &ex) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
+ g_free (package_id);
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
- g_free (package_id);
+ g_free (package_id);
pk_package_id_free (pi);
pk_backend_finished (backend);
return TRUE;
@@ -1188,46 +1017,36 @@ backend_install_package_thread (PkBackendThread *thread, gpointer data)
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
- //pk_debug ("package_id=%s", package_id);
- g_return_if_fail (backend != NULL);
-
// For now, don't let the user cancel the install once it's started
pk_backend_set_allow_cancel (backend, FALSE);
-
- gchar *package_to_install = g_strdup (package_id);
- pk_backend_thread_create_old (thread, backend_install_package_thread, package_to_install);
+ pk_backend_thread_create (backend, backend_install_package_thread, package_to_install);
}
static gboolean
-backend_remove_package_thread (PkBackendThread *thread, gpointer data)
+backend_remove_package_thread (PkBackend *backend)
{
- PkBackend *backend;
- RemovePackageData *d = (RemovePackageData *)data;
-
- backend = pk_backend_thread_get_backend (thread);
+ const gchar *package_id;
PkPackageId *pi;
pk_backend_set_status (backend, PK_STATUS_ENUM_REMOVE);
pk_backend_set_percentage (backend, 0);
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
zypp::Target_Ptr target;
-
zypp::ZYpp::Ptr zypp;
zypp = get_zypp ();
target = zypp->target ();
// Load all the local system "resolvables" (packages)
- target->load ();
+ target->load ();
pk_backend_set_percentage (backend, 10);
try
@@ -1241,61 +1060,46 @@ backend_remove_package_thread (PkBackendThread *thread, gpointer data)
break;
}
}
-
+
pk_backend_set_percentage (backend, 40);
- if (!zypp_perform_execution (backend, REMOVE, TRUE)){
- pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_ERROR, "Couldn't remove the package");
- g_free (d->package_id);
- g_free (d);
- pk_package_id_free (pi);
- pk_backend_finished (backend);
- return FALSE;
- }
+ if (!zypp_perform_execution (backend, REMOVE, TRUE)){
+ pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_ERROR, "Couldn't remove the package");
+
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return FALSE;
+ }
pk_backend_set_percentage (backend, 100);
} catch (const zypp::repo::RepoNotFoundException &ex) {
// TODO: make sure this dumps out the right sring.
pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, ex.asUserString().c_str() );
- g_free (d->package_id);
- g_free (d);
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
} catch (const zypp::Exception &ex) {
//pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Error enumerating repositories");
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asUserString().c_str() );
- g_free (d->package_id);
- g_free (d);
pk_package_id_free (pi);
pk_backend_finished (backend);
return FALSE;
}
-
-
- g_free (d->package_id);
- g_free (d);
pk_package_id_free (pi);
pk_backend_finished (backend);
return TRUE;
}
-
/**
* backend_remove_package:
*/
static void
backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps, gboolean autoremove)
{
- g_return_if_fail (backend != NULL);
-
- RemovePackageData *data = g_new0 (RemovePackageData, 1);
- data->package_id = g_strdup (package_id);
- data->deps_behavior = allow_deps == TRUE ? DEPS_ALLOW : DEPS_NO_ALLOW;
-
- pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
+ pk_backend_set_uint (backend, "allow_deps", allow_deps == TRUE ? DEPS_ALLOW : DEPS_NO_ALLOW);
+ pk_backend_thread_create (backend, backend_remove_package_thread);
}
/**
@@ -1304,29 +1108,14 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
- g_return_if_fail (backend != NULL);
-
- // check network state
- /*
- if (pk_network_is_online (backend) == FALSE) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache while offline");
- pk_backend_finished (backend);
- return;
- }
- */
- RefreshData *data = g_new(RefreshData, 1);
- data->force = force;
- pk_backend_thread_create_old (thread, backend_refresh_cache_thread, data);
+ pk_backend_thread_create (backend, backend_refresh_cache_thread);
}
static gboolean
-backend_resolve_thread (PkBackendThread *thread, gpointer data)
+backend_resolve_thread (PkBackend *backend)
{
- PkBackend *backend;
gchar *package_id;
- backend = pk_backend_thread_get_backend (thread);
- ResolveData *rdata = (ResolveData*) data;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
std::vector<zypp::sat::Solvable> *v;
@@ -1347,8 +1136,6 @@ backend_resolve_thread (PkBackendThread *thread, gpointer data)
if (package == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "couldn't find package");
- g_free (rdata->name);
- g_free (rdata);
pk_backend_finished (backend);
return FALSE;
}
@@ -1360,8 +1147,6 @@ backend_resolve_thread (PkBackendThread *thread, gpointer data)
package_id,
package.lookupStrAttribute (zypp::sat::SolvAttr::description).c_str ());
- g_free (rdata->name);
- g_free (rdata);
g_free (package_id);
pk_backend_finished (backend);
return TRUE;
@@ -1373,83 +1158,53 @@ backend_resolve_thread (PkBackendThread *thread, gpointer data)
static void
backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
- //printf("Enter backend_resolve - filter:%s, package_id:%s\n", filter, package_id);
- ResolveData *data = g_new0(ResolveData, 1);
- data->name = g_strdup (package_id);
- data->filters = filters;
- pk_backend_thread_create_old (thread, backend_resolve_thread, data);
+ pk_backend_thread_create (backend, backend_resolve_thread);
}
-static void
-find_packages_real (PkBackend *backend, const gchar *search, PkFilterEnum filters, gint mode)
+static gboolean
+backend_find_packages_thread (PkBackend *backend)
{
+ const gchar *search;
+ PkFilterEnum filters;
+ guint mode;
//GList *list = NULL;
- g_return_if_fail (backend != NULL);
+ search = pk_backend_get_string (backend, "search");
+ filters = pk_backend_get_uint (backend, "filters");
+ mode = pk_backend_get_uint (backend, "mode");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
-
pk_backend_no_percentage_updates (backend);
- std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable>;
+ std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable>;
switch (mode) {
case SEARCH_TYPE_NAME:
v = zypp_get_packages_by_name (search, zypp::ResKind::package, TRUE);
break;
-
- case SEARCH_TYPE_DETAILS:
- v = zypp_get_packages_by_details (search, TRUE);
- break;
- case SEARCH_TYPE_FILE:
- v = zypp_get_packages_by_file (search);
- break;
- };
+ case SEARCH_TYPE_DETAILS:
+ v = zypp_get_packages_by_details (search, TRUE);
+ break;
+ case SEARCH_TYPE_FILE:
+ v = zypp_get_packages_by_file (search);
+ break;
+ };
zypp_emit_packages_in_list (backend, v, filters);
delete (v);
-}
-
-static gboolean
-backend_find_packages_thread (PkBackendThread *thread, gpointer data)
-{
- PkBackend *backend;
- FindData *d = (FindData*) data;
-
- backend = pk_backend_thread_get_backend (thread);
- g_return_val_if_fail (backend != NULL, FALSE);
-
- find_packages_real (backend, d->search, d->filters, d->mode);
- g_free(d->search);
- g_free(d);
pk_backend_finished (backend);
-
return TRUE;
}
-static void
-find_packages (PkBackend *backend, const gchar *search, PkFilterEnum filters, gint mode)
-{
- FindData *data = g_new0(FindData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->search = g_strdup(search);
- data->filters = filters;
- data->mode = mode;
- pk_backend_thread_create_old (thread, backend_find_packages_thread, data);
-}
-
/**
* backend_search_name:
*/
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_NAME);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_NAME);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -1458,22 +1213,21 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_DETAILS);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_DETAILS);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
static gboolean
-backend_search_group_thread (PkBackendThread *thread, gpointer data)
+backend_search_group_thread (PkBackend *backend)
{
- GroupData *d = (GroupData*) data;
+ const gchar *group;
+ PkFilterEnum filters;
- PkBackend *backend;
- backend = pk_backend_thread_get_backend (thread);
+ group = pk_backend_get_string (backend, "group");
+ filters = pk_backend_get_uint (backend, "filters");
- if (d->pkGroup == NULL) {
+ if (group == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_GROUP_NOT_FOUND, "Group is invalid.");
- g_free (d->pkGroup);
- g_free (d);
pk_backend_finished (backend);
return FALSE;
}
@@ -1481,12 +1235,12 @@ backend_search_group_thread (PkBackendThread *thread, gpointer data)
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_set_percentage (backend, 0);
- zypp::ResPool pool = zypp_build_pool(true);
+ zypp::ResPool pool = zypp_build_pool(true);
pk_backend_set_percentage (backend, 30);
- std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable> ();
- PkGroupEnum pkGroup = pk_group_enum_from_text (d->pkGroup);
+ std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable> ();
+ PkGroupEnum pkGroup = pk_group_enum_from_text (group);
zypp::sat::LookupAttr look (zypp::sat::SolvAttr::group);
@@ -1498,17 +1252,12 @@ backend_search_group_thread (PkBackendThread *thread, gpointer data)
pk_backend_set_percentage (backend, 70);
- zypp_emit_packages_in_list (backend ,v, d->filters);
-
- delete (v);
+ zypp_emit_packages_in_list (backend ,v, filters);
+ delete (v);
pk_backend_set_percentage (backend, 100);
-
- g_free (d->pkGroup);
- g_free (d);
pk_backend_finished (backend);
-
- return TRUE;
+ return TRUE;
}
/**
@@ -1517,12 +1266,7 @@ backend_search_group_thread (PkBackendThread *thread, gpointer data)
static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *pkGroup)
{
- g_return_if_fail (backend != NULL);
-
- GroupData *data = g_new0(GroupData, 1);
- data->pkGroup = g_strdup(pkGroup);
- data->filters = filters;
- pk_backend_thread_create_old (thread, backend_search_group_thread, data);
+ pk_backend_thread_create (backend, backend_search_group_thread);
}
/**
@@ -1531,8 +1275,8 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *pkG
static void
backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_FILE);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_FILE);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -1541,9 +1285,7 @@ backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
{
- //Fixme - use the new param - filter
-
- g_return_if_fail (backend != NULL);
+ //FIXME - use the new param - filter
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -1580,8 +1322,6 @@ backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
static void
backend_repo_enable (PkBackend *backend, const gchar *rid, gboolean enabled)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
zypp::RepoManager manager;
@@ -1603,21 +1343,17 @@ backend_repo_enable (PkBackend *backend, const gchar *rid, gboolean enabled)
}
static gboolean
-backend_get_files_thread (PkBackendThread *thread, gpointer data) {
-
- PkPackageId *pi;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- ThreadData *d = (ThreadData*) data;
+backend_get_files_thread (PkBackend *backend)
+{
+ PkPackageId *pi;
+ const gchar *package_id;
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
+
pk_backend_finished (backend);
return FALSE;
}
@@ -1643,43 +1379,35 @@ backend_get_files_thread (PkBackendThread *thread, gpointer data) {
if (package == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_NOT_FOUND, "couldn't find package");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
+
pk_backend_finished (backend);
return FALSE;
}
- std::string temp;
- if (package.isSystem ()){
-
- try {
- zypp::target::rpm::RpmHeader::constPtr rpmHeader = zypp_get_rpmHeader (package.name (), package.edition ());
- std::list<std::string> files = rpmHeader->tag_filenames ();
-
- for (std::list<std::string>::iterator it = files.begin (); it != files.end (); it++) {
- temp.append (*it);
- temp.append (";");
- }
-
- } catch (const zypp::target::rpm::RpmException &ex) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Couldn't open rpm-database");
- pk_backend_finished (backend);
- return FALSE;
- }
- }else{
- temp = "Only available for installed packages";
- }
-
- pk_backend_files (backend,
- d->package_id, // package_id
- temp.c_str ()); // file_list
-
- pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
+ std::string temp;
+ if (package.isSystem ()){
+ try {
+ zypp::target::rpm::RpmHeader::constPtr rpmHeader = zypp_get_rpmHeader (package.name (), package.edition ());
+ std::list<std::string> files = rpmHeader->tag_filenames ();
+
+ for (std::list<std::string>::iterator it = files.begin (); it != files.end (); it++) {
+ temp.append (*it);
+ temp.append (";");
+ }
+
+ } catch (const zypp::target::rpm::RpmException &ex) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Couldn't open rpm-database");
+ pk_backend_finished (backend);
+ return FALSE;
+ }
+ } else {
+ temp = "Only available for installed packages";
+ }
- return TRUE;
+ pk_backend_files (backend, package_id, temp.c_str ()); // file_list
+ pk_package_id_free (pi);
+ pk_backend_finished (backend);
+ return TRUE;
}
/**
@@ -1688,39 +1416,29 @@ backend_get_files_thread (PkBackendThread *thread, gpointer data) {
static void
backend_get_files(PkBackend *backend, const gchar *package_id)
{
- g_return_if_fail (backend != NULL);
-
- ThreadData *data = g_new0(ThreadData, 1);
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_get_files_thread, data);
+ pk_backend_thread_create (backend, backend_get_files_thread);
}
static gboolean
-backend_get_packages_thread (PkBackendThread *thread, gpointer data) {
- PkBackend *backend;
-
- /*get current backend */
- backend = pk_backend_thread_get_backend (thread);
- PkFilterEnum* filter = (PkFilterEnum*) data;
+backend_get_packages_thread (PkBackend *backend)
+{
+ PkFilterEnum filters;
+ filters = pk_backend_get_uint (backend, "filters");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable>;
+ std::vector<zypp::sat::Solvable> *v = new std::vector<zypp::sat::Solvable>;
zypp_build_pool (TRUE);
-
zypp::ResPool pool = zypp::ResPool::instance ();
-
for (zypp::ResPool::byKind_iterator it = pool.byKindBegin (zypp::ResKind::package); it != pool.byKindEnd (zypp::ResKind::package); it++) {
v->push_back (it->satSolvable ());
}
- zypp_emit_packages_in_list (backend, v, *filter);
+ zypp_emit_packages_in_list (backend, v, filters);
delete (v);
- g_free (filter);
pk_backend_finished (backend);
-
return TRUE;
}
/**
@@ -1729,36 +1447,24 @@ backend_get_packages_thread (PkBackendThread *thread, gpointer data) {
static void
backend_get_packages (PkBackend *backend, PkFilterEnum filter)
{
- g_return_if_fail (backend != NULL);
- PkFilterEnum *data = g_new0(PkFilterEnum, 1);
- *data = filter;
-
- pk_backend_thread_create_old (thread, backend_get_packages_thread, data);
+ pk_backend_thread_create (backend, backend_get_packages_thread);
}
static gboolean
-backend_update_packages_thread (PkBackendThread *thread, gpointer data) {
-
- PkBackend *backend;
-
- /*get current backend */
- backend = pk_backend_thread_get_backend (thread);
- UpdateData *d = (UpdateData*) data;
-
- for (guint i = 0; i < g_strv_length (d->packages); i++) {
- zypp::sat::Solvable solvable = zypp_get_package_by_id (d->packages[i]);
- zypp::PoolItem item = zypp::ResPool::instance ().find (solvable);
+backend_update_packages_thread (PkBackend *backend)
+{
+ gchar **package_ids;
+ package_ids = pk_backend_get_strv (backend, "package_ids");
- item.status ().setToBeInstalled (zypp::ResStatus::USER);
- }
-
- zypp_perform_execution (backend, UPDATE, FALSE);
+ for (guint i = 0; i < g_strv_length (package_ids); i++) {
+ zypp::sat::Solvable solvable = zypp_get_package_by_id (package_ids[i]);
+ zypp::PoolItem item = zypp::ResPool::instance ().find (solvable);
+ item.status ().setToBeInstalled (zypp::ResStatus::USER);
+ }
- g_strfreev (d->packages);
- g_free (d);
+ zypp_perform_execution (backend, UPDATE, FALSE);
pk_backend_finished (backend);
-
- return TRUE;
+ return TRUE;
}
/**
@@ -1767,121 +1473,110 @@ backend_update_packages_thread (PkBackendThread *thread, gpointer data) {
static void
backend_update_packages(PkBackend *backend, gchar **package_ids)
{
- g_return_if_fail (backend != NULL);
-
- UpdateData *data = g_new0(UpdateData, 1);
- data->packages = g_strdupv (package_ids);
-
- pk_backend_thread_create_old(thread, backend_update_packages_thread, data);
-
+ pk_backend_thread_create(thread, backend_update_packages_thread);
}
static gboolean
-backend_repo_set_data_thread (PkBackendThread *thread, gpointer data)
+backend_repo_set_data_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- RepoData *d = (RepoData*) data;
+ const gchar *repo_id;
+ const gchar *parameter;
+ const gchar *value;
+ repo_id = pk_backend_get_string (backend, "repo_id");
+ parameter = pk_backend_get_string (backend, "parameter");
+ value = pk_backend_get_string (backend, "value");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- zypp::RepoManager manager;
+ zypp::RepoManager manager;
zypp::RepoInfo repo;
- gboolean bReturn = TRUE;
-
- try {
- pk_backend_set_status(backend, PK_STATUS_ENUM_SETUP);
- // add a new repo
- if (g_ascii_strcasecmp (d->parameter, "add") == 0) {
- repo.setAlias (d->repo_id);
- repo.setBaseUrl (zypp::Url(d->value));
- repo.setAutorefresh (TRUE);
- repo.setEnabled (TRUE);
-
- manager.addRepository (repo);
-
- // remove a repo
- }else if (g_ascii_strcasecmp (d->parameter, "remove") == 0) {
- repo = manager.getRepositoryInfo (d->repo_id);
- manager.removeRepository (repo);
- // set autorefresh of a repo true/false
- }else if (g_ascii_strcasecmp (d->parameter, "refresh") == 0) {
- repo = manager.getRepositoryInfo (d->repo_id);
-
- if (g_ascii_strcasecmp (d->value, "true") == 0) {
- repo.setAutorefresh (TRUE);
- }else if (g_ascii_strcasecmp (d->value, "false") == 0) {
- repo.setAutorefresh (FALSE);
- }else{
- pk_backend_message (backend, PK_MESSAGE_ENUM_NOTICE, "Autorefresh a repo: Enter true or false");
- bReturn = FALSE;
- }
-
- manager.modifyRepository (d->repo_id, repo);
- }else if (g_ascii_strcasecmp (d->parameter, "prio") == 0) {
- repo = manager.getRepositoryInfo (d->repo_id);
+ gboolean bReturn = TRUE;
+
+ try {
+ pk_backend_set_status(backend, PK_STATUS_ENUM_SETUP);
+ // add a new repo
+ if (g_ascii_strcasecmp (parameter, "add") == 0) {
+ repo.setAlias (repo_id);
+ repo.setBaseUrl (zypp::Url(value));
+ repo.setAutorefresh (TRUE);
+ repo.setEnabled (TRUE);
+
+ manager.addRepository (repo);
+
+ // remove a repo
+ }else if (g_ascii_strcasecmp (parameter, "remove") == 0) {
+ repo = manager.getRepositoryInfo (repo_id);
+ manager.removeRepository (repo);
+ // set autorefresh of a repo true/false
+ }else if (g_ascii_strcasecmp (parameter, "refresh") == 0) {
+ repo = manager.getRepositoryInfo (repo_id);
+
+ if (g_ascii_strcasecmp (value, "true") == 0) {
+ repo.setAutorefresh (TRUE);
+ }else if (g_ascii_strcasecmp (value, "false") == 0) {
+ repo.setAutorefresh (FALSE);
+ } else {
+ pk_backend_message (backend, PK_MESSAGE_ENUM_NOTICE, "Autorefresh a repo: Enter true or false");
+ bReturn = FALSE;
+ }
+
+ manager.modifyRepository (repo_id, repo);
+ }else if (g_ascii_strcasecmp (parameter, "prio") == 0) {
+ repo = manager.getRepositoryInfo (repo_id);
gint prio = 0;
- gint length = strlen (d->value);
-
+ gint length = strlen (value);
+
if (length > 2) {
pk_backend_message (backend, PK_MESSAGE_ENUM_NOTICE, "Priorities has to be between 1 (highest) and 99");
bReturn = false;
- }else{
+ } else {
for (gint i = 0; i < length; i++) {
- gint tmp = g_ascii_digit_value (d->value[i]);
+ gint tmp = g_ascii_digit_value (value[i]);
if (tmp == -1) {
pk_backend_message (backend, PK_MESSAGE_ENUM_NOTICE, "Priorities has to be a number between 1 (highest) and 99");
bReturn = FALSE;
prio = 0;
break;
- }else{
-
+ } else {
if (length == 2 && i == 0) {
prio = tmp * 10;
- }else{
+ } else {
prio = prio + tmp;
}
}
- }
+ }
if (prio != 0) {
repo.setPriority (prio);
- manager.modifyRepository (d->repo_id, repo);
+ manager.modifyRepository (repo_id, repo);
}
}
- }else{
+ } else {
pk_backend_error_code (backend, PK_ERROR_ENUM_NOT_SUPPORTED, "Valid parameters for set_repo_data are remove/add/refresh/prio");
bReturn = FALSE;
}
- } catch (const zypp::repo::RepoNotFoundException &ex) {
+ } catch (const zypp::repo::RepoNotFoundException &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_REPO_NOT_FOUND, "Couldn't find the specified repository");
- bReturn = FALSE;
- } catch (const zypp::repo::RepoAlreadyExistsException &ex) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "This repo already exists");
- bReturn = FALSE;
- } catch (const zypp::repo::RepoUnknownTypeException &ex) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Type of the repo can't be determined");
- bReturn = FALSE;
- } catch (const zypp::repo::RepoException &ex) {
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Can't access the given URL");
- bReturn = FALSE;
+ bReturn = FALSE;
+ } catch (const zypp::repo::RepoAlreadyExistsException &ex) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "This repo already exists");
+ bReturn = FALSE;
+ } catch (const zypp::repo::RepoUnknownTypeException &ex) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Type of the repo can't be determined");
+ bReturn = FALSE;
+ } catch (const zypp::repo::RepoException &ex) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, "Can't access the given URL");
+ bReturn = FALSE;
} catch (const zypp::Exception &ex) {
pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR, ex.asString ().c_str ());
bReturn = FALSE;
}
- g_free (d->repo_id);
- g_free (d->parameter);
- g_free (d->value);
- g_free (d);
pk_backend_finished (backend);
-
return bReturn;
}
@@ -1889,45 +1584,30 @@ backend_repo_set_data_thread (PkBackendThread *thread, gpointer data)
* backend_repo_set_data
*/
static void
-backend_repo_set_data(PkBackend *backend, const gchar *repo_id, const gchar *parameter, const gchar *value)
+backend_repo_set_data (PkBackend *backend, const gchar *repo_id, const gchar *parameter, const gchar *value)
{
- g_return_if_fail (backend != NULL);
-
- RepoData *data = g_new0(RepoData, 1);
- data->repo_id = g_strdup (repo_id);
- data->parameter = g_strdup (parameter);
- data->value = g_strdup (value);
-
- pk_backend_thread_create_old(thread, backend_repo_set_data_thread, data);
-
+ pk_backend_thread_create (thread, backend_repo_set_data_thread);
}
static gboolean
-backend_what_provides_thread (PkBackendThread *thread, gpointer data) {
-
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
- ResolveData *d = (ResolveData*) data;
-
- zypp::Capability cap (d->name);
- zypp::sat::WhatProvides prov (cap);
+backend_what_provides_thread (PkBackend *backend)
+{
+ const gchar *search;
+ search = pk_backend_get_string (backend, "search");
+ zypp::Capability cap (search);
+ zypp::sat::WhatProvides prov (cap);
- for(zypp::sat::WhatProvides::const_iterator it = prov.begin (); it != prov.end (); it++) {
- gchar *package_id = zypp_build_package_id_from_resolvable (*it);
+ for(zypp::sat::WhatProvides::const_iterator it = prov.begin (); it != prov.end (); it++) {
+ gchar *package_id = zypp_build_package_id_from_resolvable (*it);
- PkInfoEnum info = PK_INFO_ENUM_AVAILABLE;
- if( it->isSystem ())
- info = PK_INFO_ENUM_INSTALLED;
+ PkInfoEnum info = PK_INFO_ENUM_AVAILABLE;
+ if( it->isSystem ())
+ info = PK_INFO_ENUM_INSTALLED;
- pk_backend_package (backend, info, package_id, it->lookupStrAttribute (zypp::sat::SolvAttr::summary).c_str ());
- }
+ pk_backend_package (backend, info, package_id, it->lookupStrAttribute (zypp::sat::SolvAttr::summary).c_str ());
+ }
- g_free (d->name);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
@@ -1935,19 +1615,16 @@ backend_what_provides_thread (PkBackendThread *thread, gpointer data) {
* backend_what_provides
*/
static void
-backend_what_provides(PkBackend *backend, PkFilterEnum filters, PkProvidesEnum provide, const gchar *search)
+backend_what_provides (PkBackend *backend, PkFilterEnum filters, PkProvidesEnum provide, const gchar *search)
{
- g_return_if_fail (backend != NULL);
-
- ResolveData *data = g_new0(ResolveData, 1);
- data->name = g_strdup(search);
- data->filters = filters;
- pk_backend_thread_create_old (thread, backend_what_provides_thread, data);
+ pk_backend_thread_create (backend, backend_what_provides_thread);
}
extern "C" PK_BACKEND_OPTIONS (
"Zypp", /* description */
- "Boyd Timothy <btimothy at gmail.com>, Scott Reeves <sreeves at novell.com>, Stefan Haas <shaas at suse.de>", /* author */
+ "Boyd Timothy <btimothy at gmail.com>, "
+ "Scott Reeves <sreeves at novell.com>, "
+ "Stefan Haas <shaas at suse.de>", /* author */
backend_initialize, /* initalize */
backend_destroy, /* destroy */
backend_get_groups, /* get_groups */
@@ -1974,8 +1651,9 @@ extern "C" PK_BACKEND_OPTIONS (
backend_search_file, /* search_file */
backend_search_group, /* search_group */
backend_search_name, /* search_name */
- NULL, /* service_pack */
- backend_update_packages, /* update_packages */
+ NULL, /* service_pack */
+ backend_update_packages, /* update_packages */
backend_update_system, /* update_system */
- backend_what_provides /* what_provides */
+ backend_what_provides /* what_provides */
);
+
commit 9d06a6be3e09ee3ea7642e4360eb944a24fcb084
Author: Grzegorz Dabrowski <gdx at o2.pl>
Date: Tue Apr 29 21:04:27 2008 +0000
[box] build fix after "convert the box backend from pk_backend_thread_create_old() to pk_backend_thread_create()"
diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 169f68c..6b77a39 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -316,6 +316,7 @@ backend_get_files_thread (PkBackend *backend)
PkPackageId *pi;
gchar *files;
sqlite3 *db;
+ const gchar *package_id;
db = db_open();
package_id = pk_backend_get_string (backend, "package_id");
@@ -348,9 +349,12 @@ backend_get_depends_requires_thread (PkBackend *backend)
PkPackageId *pi;
GList *list = NULL;
sqlite3 *db;
+ const gchar *package_id;
+ int deps_type;
db = db_open ();
package_id = pk_backend_get_string (backend, "package_id");
+ deps_type = pk_backend_get_uint (backend, "type");
pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
@@ -362,9 +366,9 @@ backend_get_depends_requires_thread (PkBackend *backend)
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- if (d->type == DEPS_TYPE_DEPENDS)
+ if (deps_type == DEPS_TYPE_DEPENDS)
list = box_db_repos_get_depends(db, pi->name);
- else if (d->type == DEPS_TYPE_REQUIRES)
+ else if (deps_type == DEPS_TYPE_REQUIRES)
list = box_db_repos_get_requires(db, pi->name);
add_packages_from_list (backend, list, FALSE);
@@ -381,6 +385,7 @@ static gboolean
backend_remove_package_thread (PkBackend *backend)
{
PkPackageId *pi;
+ const gchar *package_id;
package_id = pk_backend_get_string (backend, "package_id");
pi = pk_package_id_new_from_string (package_id);
@@ -448,6 +453,7 @@ backend_get_filters (PkBackend *backend)
static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
+ pk_backend_set_uint (backend, "type", DEPS_TYPE_DEPENDS);
pk_backend_thread_create (backend, backend_get_depends_requires_thread);
}
@@ -475,6 +481,7 @@ backend_get_files (PkBackend *backend, const gchar *package_id)
static void
backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
+ pk_backend_set_uint (backend, "type", DEPS_TYPE_REQUIRES);
pk_backend_thread_create (backend, backend_get_depends_requires_thread);
}
commit 2854bbac95452730cf34347cdb38cbac97ae7c01
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 20:10:03 2008 +0100
convert the box backend from pk_backend_thread_create_old() to pk_backend_thread_create() and do a code review -- needs checking
diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 59c7feb..169f68c 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -24,9 +24,7 @@
#include <string.h>
#include <unistd.h>
#include <pk-backend.h>
-#include <pk-backend-thread.h>
#include <pk-debug.h>
-#include <pk-network.h>
#include <sqlite3.h>
#include <libbox/libbox-db.h>
@@ -37,9 +35,6 @@
#define ROOT_DIRECTORY "/"
-static PkBackendThread *thread;
-static PkNetwork *network;
-
enum PkgSearchType {
SEARCH_TYPE_NAME = 0,
SEARCH_TYPE_DETAILS = 1,
@@ -57,19 +52,6 @@ enum DepsBehaviour {
DEPS_NO_ALLOW = 1
};
-typedef struct {
- gchar *search;
- PkFilterEnum filters;
- gint mode;
-} FindData;
-
-typedef struct {
- gchar *package_id;
- gchar **package_ids;
- gint type;
-} ThreadData;
-
-
static sqlite3*
db_open()
{
@@ -114,19 +96,23 @@ add_packages_from_list (PkBackend *backend, GList *list, gboolean updates)
else
info = PK_INFO_ENUM_AVAILABLE;
pk_backend_package (backend, info, pkg_string, package->description);
-
g_free(pkg_string);
}
}
-static void
-find_packages_real (PkBackend *backend, const gchar *search, PkFilterEnum filters, gint mode)
+static gboolean
+backend_find_packages_thread (PkBackend *backend)
{
+ PkFilterEnum filters;
+ const gchar *search;
+ guint mode;
GList *list = NULL;
sqlite3 *db = NULL;
gint filter_box = 0;
- g_return_if_fail (backend != NULL);
+ filters = pk_backend_get_uint (backend, "filters");
+ mode = pk_backend_get_uint (backend, "mode");
+ search = pk_backend_get_string (backend, "search");
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -180,49 +166,15 @@ find_packages_real (PkBackend *backend, const gchar *search, PkFilterEnum filter
}
db_close(db);
-}
-
-static gboolean
-backend_find_packages_thread (PkBackendThread *thread, gpointer data)
-{
- FindData *d = (FindData*) data;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
- find_packages_real (backend, d->search, d->filters, d->mode);
-
- g_free(d->search);
- g_free(d);
pk_backend_finished (backend);
-
return TRUE;
}
-
-static void
-find_packages (PkBackend *backend, const gchar *search, PkFilterEnum filters, gint mode)
-{
- FindData *data = g_new0(FindData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->search = g_strdup(search);
- data->filters = filters;
- data->mode = mode;
- pk_backend_thread_create_old (thread, backend_find_packages_thread, data);
-}
-
static gboolean
-backend_get_updates_thread (PkBackendThread *thread, gpointer data)
+backend_get_updates_thread (PkBackend *backend)
{
GList *list = NULL;
sqlite3 *db = NULL;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
@@ -238,130 +190,100 @@ backend_get_updates_thread (PkBackendThread *thread, gpointer data)
}
static gboolean
-backend_update_system_thread (PkBackendThread *thread, gpointer data)
+backend_update_system_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
box_upgrade_dist(ROOT_DIRECTORY, common_progress, backend);
pk_backend_finished (backend);
-
return TRUE;
}
static gboolean
-backend_install_package_thread (PkBackendThread *thread, gpointer data)
+backend_install_package_thread (PkBackend *backend)
{
- ThreadData *d = (ThreadData*) data;
gboolean result;
PkPackageId *pi;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ const gchar *package_id;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
-
return FALSE;
}
result = box_package_install(pi->name, ROOT_DIRECTORY, common_progress, backend, FALSE);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return result;
}
static gboolean
-backend_update_packages_thread (PkBackendThread *thread, gpointer data)
+backend_update_packages_thread (PkBackend *backend)
{
- ThreadData *d = (ThreadData*) data;
gboolean result = TRUE;
+ gchar **package_ids;
PkPackageId *pi;
- PkBackend *backend;
gint i;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+ package_ids = pk_backend_get_strv (backend, "package_ids");
- for (i = 0; i < g_strv_length (d->package_ids); i++)
+ for (i = 0; i < g_strv_length (package_ids); i++)
{
- pi = pk_package_id_new_from_string (d->package_ids[i]);
+ pi = pk_package_id_new_from_string (package_ids[i]);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
- g_strfreev (d->package_ids);
- g_free (d);
+ g_strfreev (package_ids);
return FALSE;
}
result |= box_package_install(pi->name, ROOT_DIRECTORY, common_progress, backend, FALSE);
-
}
- g_strfreev (d->package_ids);
- g_free (d);
pk_backend_finished (backend);
-
return result;
}
+
static gboolean
-backend_install_file_thread (PkBackendThread *thread, gpointer data)
+backend_install_file_thread (PkBackend *backend)
{
- ThreadData *d = (ThreadData*) data;
gboolean result;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ const gchar *full_path;
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- result = box_package_install(d->package_id, ROOT_DIRECTORY, common_progress, backend, FALSE);
+ full_path = pk_backend_get_string (backend, "full_path");
+ result = box_package_install(full_path, ROOT_DIRECTORY, common_progress, backend, FALSE);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
return result;
}
static gboolean
-backend_get_description_thread (PkBackendThread *thread, gpointer data)
+backend_get_description_thread (PkBackend *backend)
{
PkPackageId *pi;
PackageSearch *ps;
GList *list;
- ThreadData *d = (ThreadData*) data;
sqlite3 *db;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ const gchar *package_id;
+ package_id = pk_backend_get_string (backend, "package_id");
db = db_open();
- pi = pk_package_id_new_from_string (d->package_id);
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
db_close (db);
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
}
@@ -374,87 +296,67 @@ backend_get_description_thread (PkBackendThread *thread, gpointer data)
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "cannot find package by id");
pk_package_id_free (pi);
db_close (db);
- g_free (d->package_id);
- g_free (d);
return FALSE;
}
ps = (PackageSearch*) list->data;
- pk_backend_description (backend, d->package_id, "unknown", PK_GROUP_ENUM_OTHER, ps->description, "", 0);
+ pk_backend_description (backend, package_id, "unknown", PK_GROUP_ENUM_OTHER, ps->description, "", 0);
pk_package_id_free (pi);
box_db_repos_package_list_free (list);
db_close(db);
-
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
static gboolean
-backend_get_files_thread (PkBackendThread *thread, gpointer data)
+backend_get_files_thread (PkBackend *backend)
{
PkPackageId *pi;
- ThreadData *d = (ThreadData*) data;
gchar *files;
sqlite3 *db;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
db = db_open();
+ package_id = pk_backend_get_string (backend, "package_id");
- pi = pk_package_id_new_from_string (d->package_id);
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
pk_package_id_free (pi);
db_close (db);
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
}
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
files = box_db_repos_get_files_string (db, pi->name, pi->version);
- pk_backend_files (backend, d->package_id, files);
+ pk_backend_files (backend, package_id, files);
pk_package_id_free (pi);
-
db_close(db);
-
g_free (files);
- g_free (d->package_id);
- g_free (d);
- pk_backend_finished (backend);
+ pk_backend_finished (backend);
return TRUE;
}
static gboolean
-backend_get_depends_requires_thread (PkBackendThread *thread, gpointer data)
+backend_get_depends_requires_thread (PkBackend *backend)
{
PkPackageId *pi;
GList *list = NULL;
- ThreadData *d = (ThreadData*) data;
sqlite3 *db;
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
db = db_open ();
+ package_id = pk_backend_get_string (backend, "package_id");
- pi = pk_package_id_new_from_string (d->package_id);
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
db_close (db);
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
}
@@ -471,28 +373,20 @@ backend_get_depends_requires_thread (PkBackendThread *thread, gpointer data)
db_close (db);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
static gboolean
-backend_remove_package_thread (PkBackendThread *thread, gpointer data)
+backend_remove_package_thread (PkBackend *backend)
{
- ThreadData *d = (ThreadData*) data;
PkPackageId *pi;
- PkBackend *backend;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
- pi = pk_package_id_new_from_string (d->package_id);
+ package_id = pk_backend_get_string (backend, "package_id");
+ pi = pk_package_id_new_from_string (package_id);
if (pi == NULL) {
pk_backend_error_code (backend, PK_ERROR_ENUM_PACKAGE_ID_INVALID, "invalid package id");
- g_free (d->package_id);
- g_free (d);
+
return FALSE;
}
@@ -504,26 +398,17 @@ backend_remove_package_thread (PkBackendThread *thread, gpointer data)
}
pk_package_id_free (pi);
- g_free (d->package_id);
- g_free (d);
pk_backend_finished (backend);
-
return TRUE;
}
static gboolean
-backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
+backend_refresh_cache_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_REFRESH_CACHE);
box_repos_sync(ROOT_DIRECTORY, common_progress, backend);
pk_backend_finished (backend);
-
return TRUE;
}
@@ -535,10 +420,6 @@ backend_refresh_cache_thread (PkBackendThread *thread, gpointer data)
static void
backend_initialize (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
- thread = pk_backend_thread_new ();
- network = pk_network_new ();
}
/**
@@ -547,10 +428,6 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
-
- g_object_unref (thread);
- g_object_unref (network);
}
/**
@@ -571,13 +448,7 @@ backend_get_filters (PkBackend *backend)
static void
backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->package_id = g_strdup(package_id);
- data->type = DEPS_TYPE_DEPENDS;
- pk_backend_thread_create_old (thread, backend_get_depends_requires_thread, data);
+ pk_backend_thread_create (backend, backend_get_depends_requires_thread);
}
/**
@@ -586,12 +457,7 @@ backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *pack
static void
backend_get_description (PkBackend *backend, const gchar *package_id)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_get_description_thread, data);
+ pk_backend_thread_create (backend, backend_get_description_thread);
}
/**
@@ -600,12 +466,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
static void
backend_get_files (PkBackend *backend, const gchar *package_id)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_get_files_thread, data);
+ pk_backend_thread_create (backend, backend_get_files_thread);
}
/**
@@ -614,13 +475,7 @@ backend_get_files (PkBackend *backend, const gchar *package_id)
static void
backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *package_id, gboolean recursive)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->package_id = g_strdup(package_id);
- data->type = DEPS_TYPE_REQUIRES;
- pk_backend_thread_create_old (thread, backend_get_depends_requires_thread, data);
+ pk_backend_thread_create (backend, backend_get_depends_requires_thread);
}
/**
@@ -629,29 +484,23 @@ backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *pac
static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
- g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create (backend, backend_get_updates_thread);
}
-
/**
* backend_install_package:
*/
static void
backend_install_package (PkBackend *backend, const gchar *package_id)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot install when offline");
pk_backend_finished (backend);
return;
}
- data->package_id = g_strdup(package_id);
- pk_backend_thread_create_old (thread, backend_install_package_thread, data);
+ pk_backend_thread_create (backend, backend_install_package_thread);
}
/**
@@ -660,12 +509,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
static void
backend_install_file (PkBackend *backend, gboolean trusted, const gchar *file)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- data->package_id = g_strdup(file);
- pk_backend_thread_create_old (thread, backend_install_file_thread, data);
+ pk_backend_thread_create (backend, backend_install_file_thread);
}
/**
@@ -674,14 +518,13 @@ backend_install_file (PkBackend *backend, gboolean trusted, const gchar *file)
static void
backend_refresh_cache (PkBackend *backend, gboolean force)
{
- g_return_if_fail (backend != NULL);
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot refresh cache whilst offline");
pk_backend_finished (backend);
return;
}
- pk_backend_thread_create_old (thread, backend_refresh_cache_thread, NULL);
+ pk_backend_thread_create (backend, backend_refresh_cache_thread);
}
/**
@@ -690,18 +533,8 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
static void
backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean allow_deps, gboolean autoremove)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
-
- if (allow_deps == TRUE) {
- data->type = DEPS_ALLOW;
- } else {
- data->type = DEPS_NO_ALLOW;
- }
- data->package_id = g_strdup (package_id);
-
- pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
+ pk_backend_set_uint (backend, "type", DEPS_ALLOW);
+ pk_backend_thread_create (backend, backend_remove_package_thread);
}
/**
@@ -710,8 +543,8 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
static void
backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, package, filters, SEARCH_TYPE_RESOLVE);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_RESOLVE);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -720,8 +553,8 @@ backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
static void
backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_DETAILS);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_DETAILS);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -730,8 +563,8 @@ backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *s
static void
backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_FILE);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_FILE);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -740,8 +573,8 @@ backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- find_packages (backend, search, filters, SEARCH_TYPE_NAME);
+ pk_backend_set_uint (backend, "mode", SEARCH_TYPE_NAME);
+ pk_backend_thread_create (backend, backend_find_packages_thread);
}
/**
@@ -750,18 +583,13 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_update_packages (PkBackend *backend, gchar **package_ids)
{
- ThreadData *data = g_new0(ThreadData, 1);
-
- g_return_if_fail (backend != NULL);
/* check network state */
- if (pk_network_is_online (network) == FALSE) {
+ if (!pk_backend_is_online (backend)) {
pk_backend_error_code (backend, PK_ERROR_ENUM_NO_NETWORK, "Cannot update when offline");
pk_backend_finished (backend);
return;
}
-
- data->package_ids = g_strdupv (package_ids);
- pk_backend_thread_create_old (thread, backend_update_packages_thread, data);
+ pk_backend_thread_create (backend, backend_update_packages_thread);
}
/**
@@ -770,8 +598,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
static void
backend_update_system (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_update_system_thread, NULL);
+ pk_backend_thread_create (backend, backend_update_system_thread);
}
/**
@@ -784,8 +611,6 @@ backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
GList *li;
RepoInfo *repo;
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
list = box_repos_list_get ();
@@ -805,13 +630,11 @@ backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
static void
backend_repo_enable (PkBackend *backend, const gchar *rid, gboolean enabled)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
box_repos_enable_repo(rid, enabled);
- pk_backend_finished (backend);
+ pk_backend_finished (backend);
}
/**
@@ -820,19 +643,15 @@ backend_repo_enable (PkBackend *backend, const gchar *rid, gboolean enabled)
static void
backend_repo_set_data (PkBackend *backend, const gchar *rid, const gchar *parameter, const gchar *value)
{
- g_return_if_fail (backend != NULL);
-
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- if (!box_repos_set_param (rid, parameter, value))
- {
+ if (!box_repos_set_param (rid, parameter, value)) {
pk_warning ("Cannot set PARAMETER '%s' TO '%s' for REPO '%s'", parameter, value, rid);
}
pk_backend_finished (backend);
}
-
PK_BACKEND_OPTIONS (
"Box", /* description */
"Grzegorz DÄ
browski <grzegorz.dabrowski at gmail.com>", /* author */
commit a4ea7eb62af5a0996376909688e3b14a959648a2
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 19:36:41 2008 +0100
add a simple helper to get the online status so each backend doesn't need to muck about with PkNetwork
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 7a3c36b..371cde6 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -31,6 +31,7 @@
#include <glib.h>
#include <gmodule.h>
#include <glib/gprintf.h>
+#include <pk-network.h>
#include "pk-debug.h"
#include "pk-common.h"
@@ -89,6 +90,7 @@ struct _PkBackendPrivate
gboolean set_signature;
gboolean set_eula;
gboolean has_sent_package;
+ PkNetwork *network;
PkRoleEnum role; /* this never changes for the lifetime of a transaction */
PkStatusEnum status; /* this changes */
PkExitEnum exit;
@@ -1482,6 +1484,15 @@ pk_backend_not_implemented_yet (PkBackend *backend, const gchar *method)
}
/**
+ * pk_backend_is_online:
+ **/
+gboolean
+pk_backend_is_online (PkBackend *backend)
+{
+ return pk_network_is_online (backend->priv->network);
+}
+
+/**
* pk_backend_thread_create:
**/
gboolean
@@ -1654,6 +1665,7 @@ pk_backend_finalize (GObject *object)
g_free (backend->priv->c_tid);
g_object_unref (backend->priv->time);
g_object_unref (backend->priv->inhibit);
+ g_object_unref (backend->priv->network);
g_hash_table_destroy (backend->priv->eulas);
g_hash_table_unref (backend->priv->hash_string);
g_hash_table_unref (backend->priv->hash_strv);
@@ -1799,6 +1811,7 @@ pk_backend_init (PkBackend *backend)
backend->priv->signal_error_timeout = 0;
backend->priv->during_initialize = FALSE;
backend->priv->time = pk_time_new ();
+ backend->priv->network = pk_network_new ();
backend->priv->inhibit = pk_inhibit_new ();
backend->priv->eulas = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
backend->priv->hash_string = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
diff --git a/src/pk-backend.h b/src/pk-backend.h
index 38cc6db..37e4929 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -155,6 +155,7 @@ gboolean pk_backend_not_implemented_yet (PkBackend *backend,
typedef gboolean (*PkBackendThreadFunc) (PkBackend *backend);
gboolean pk_backend_thread_create (PkBackend *backend,
PkBackendThreadFunc func);
+gboolean pk_backend_is_online (PkBackend *backend);
/* config changed functions */
typedef void (*PkBackendFileChanged) (PkBackend *backend,
commit 9551f88c49a710302df0e00314fb46d1bac37f81
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 18:52:02 2008 +0100
we don't have to set the data now it's all set in PkTransaction for us
diff --git a/backends/test/pk-backend-test-thread.c b/backends/test/pk-backend-test-thread.c
index 1b45b12..f5b4b90 100644
--- a/backends/test/pk-backend-test-thread.c
+++ b/backends/test/pk-backend-test-thread.c
@@ -33,7 +33,6 @@ static gboolean is_cancelled = FALSE;
static void
backend_initialize (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
pk_debug ("FILTER: initialize");
}
@@ -44,7 +43,6 @@ backend_initialize (PkBackend *backend)
static void
backend_destroy (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
pk_debug ("FILTER: destroy");
}
@@ -71,7 +69,6 @@ backend_search_group_thread (PkBackend *backend)
static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
pk_backend_thread_create (backend, backend_search_group_thread);
}
@@ -126,9 +123,6 @@ backend_search_name_thread (PkBackend *backend)
static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
- g_return_if_fail (backend != NULL);
- pk_backend_set_uint (backend, "filters", filters);
- pk_backend_set_string (backend, "search", search);
pk_backend_thread_create (backend, backend_search_name_thread);
}
@@ -138,7 +132,6 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
static void
backend_cancel (PkBackend *backend)
{
- g_return_if_fail (backend != NULL);
pk_debug ("cancelling %p", backend);
is_cancelled = TRUE;
}
commit 02bb87c97d4f072569960fd5080daa7a135b972d
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 18:05:22 2008 +0100
save backend parameters in the internal hash table
diff --git a/src/pk-transaction.c b/src/pk-transaction.c
index 60c924c..45f8f91 100644
--- a/src/pk-transaction.c
+++ b/src/pk-transaction.c
@@ -788,6 +788,24 @@ pk_transaction_set_running (PkTransaction *transaction)
/* mark running */
transaction->priv->running = TRUE;
+ /* set all possible arguments for backend */
+ pk_backend_set_bool (priv->backend, "force", priv->cached_force);
+ pk_backend_set_bool (priv->backend, "allow_deps", priv->cached_allow_deps);
+ pk_backend_set_bool (priv->backend, "autoremove", priv->cached_autoremove);
+ pk_backend_set_bool (priv->backend, "enabled", priv->cached_enabled);
+ pk_backend_set_bool (priv->backend, "trusted", priv->cached_trusted);
+ pk_backend_set_uint (priv->backend, "filters", priv->cached_filters);
+ pk_backend_set_uint (priv->backend, "provides", priv->cached_provides);
+ pk_backend_set_strv (priv->backend, "package_ids", priv->cached_package_ids);
+ pk_backend_set_string (priv->backend, "package_id", priv->cached_package_id);
+ pk_backend_set_string (priv->backend, "transaction_id", priv->cached_transaction_id);
+ pk_backend_set_string (priv->backend, "full_path", priv->cached_full_path);
+ pk_backend_set_string (priv->backend, "search", priv->cached_search);
+ pk_backend_set_string (priv->backend, "repo_id", priv->cached_repo_id);
+ pk_backend_set_string (priv->backend, "key_id", priv->cached_key_id);
+ pk_backend_set_string (priv->backend, "parameter", priv->cached_parameter);
+ pk_backend_set_string (priv->backend, "value", priv->cached_value);
+
/* lets reduce pointer dereferences... */
desc = priv->backend->desc;
commit 6dc42664e0f299c1e715f78ffeb3b36d9826d74f
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 18:04:35 2008 +0100
allow data to be NULL for pk_backend_set_string and pk_backend_set_strv, but ignore it
diff --git a/src/pk-backend.c b/src/pk-backend.c
index f13c12d..7a3c36b 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -264,7 +264,11 @@ pk_backend_set_string (PkBackend *backend, const gchar *key, const gchar *data)
gpointer value;
g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
+
+ /* valid, but do nothing */
+ if (data == NULL) {
+ return FALSE;
+ }
/* does already exist? */
value = g_hash_table_lookup (backend->priv->hash_string, (gpointer) key);
@@ -286,7 +290,11 @@ pk_backend_set_strv (PkBackend *backend, const gchar *key, gchar **data)
gpointer value;
g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
g_return_val_if_fail (key != NULL, FALSE);
- g_return_val_if_fail (data != NULL, FALSE);
+
+ /* valid, but do nothing */
+ if (data == NULL) {
+ return FALSE;
+ }
/* does already exist? */
value = g_hash_table_lookup (backend->priv->hash_strv, (gpointer) key);
commit 1ff48511c3cad7e4cae0ab73b538808b8175a469
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 17:28:10 2008 +0100
allow strv types to be stored in the per-backend table
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 2de1e84..f13c12d 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -106,6 +106,7 @@ struct _PkBackendPrivate
guint signal_error_timeout;
GThread *thread;
GHashTable *hash_string;
+ GHashTable *hash_strv;
GHashTable *hash_pointer;
};
@@ -277,6 +278,28 @@ pk_backend_set_string (PkBackend *backend, const gchar *key, const gchar *data)
}
/**
+ * pk_backend_set_strv:
+ **/
+gboolean
+pk_backend_set_strv (PkBackend *backend, const gchar *key, gchar **data)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_strv, (gpointer) key);
+ if (value != NULL) {
+ pk_warning ("already set data for %s", key);
+ return FALSE;
+ }
+ pk_debug ("saving %p for %s", data, key);
+ g_hash_table_insert (backend->priv->hash_strv, g_strdup (key), (gpointer) g_strdupv (data));
+ return TRUE;
+}
+
+/**
* pk_backend_set_uint:
**/
gboolean
@@ -360,6 +383,25 @@ pk_backend_get_string (PkBackend *backend, const gchar *key)
}
/**
+ * pk_backend_get_strv:
+ **/
+gchar **
+pk_backend_get_strv (PkBackend *backend, const gchar *key)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_strv, (gpointer) key);
+ if (value == NULL) {
+ pk_warning ("not set data for %s", key);
+ return FALSE;
+ }
+ return (gchar **) value;
+}
+
+/**
* pk_backend_get_uint:
**/
uint
@@ -1321,6 +1363,7 @@ pk_backend_finished_delay (gpointer data)
pk_debug ("resetting hash tables to blank");
g_hash_table_remove_all (backend->priv->hash_pointer);
g_hash_table_remove_all (backend->priv->hash_string);
+ g_hash_table_remove_all (backend->priv->hash_strv);
pk_debug ("emit finished %i", backend->priv->exit);
g_signal_emit (backend, signals [PK_BACKEND_FINISHED], 0, backend->priv->exit);
@@ -1605,6 +1648,7 @@ pk_backend_finalize (GObject *object)
g_object_unref (backend->priv->inhibit);
g_hash_table_destroy (backend->priv->eulas);
g_hash_table_unref (backend->priv->hash_string);
+ g_hash_table_unref (backend->priv->hash_strv);
g_hash_table_unref (backend->priv->hash_pointer);
if (backend->priv->handle != NULL) {
@@ -1750,6 +1794,7 @@ pk_backend_init (PkBackend *backend)
backend->priv->inhibit = pk_inhibit_new ();
backend->priv->eulas = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
backend->priv->hash_string = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ backend->priv->hash_strv = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_strfreev);
backend->priv->hash_pointer = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
/* monitor config files for changes */
diff --git a/src/pk-backend.h b/src/pk-backend.h
index 0fff22e..38cc6db 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -124,6 +124,9 @@ gboolean pk_backend_eula_required (PkBackend *backend,
gboolean pk_backend_set_string (PkBackend *backend,
const gchar *key,
const gchar *data);
+gboolean pk_backend_set_strv (PkBackend *backend,
+ const gchar *key,
+ gchar **data);
gboolean pk_backend_set_uint (PkBackend *backend,
const gchar *key,
guint data);
@@ -137,6 +140,8 @@ gboolean pk_backend_set_pointer (PkBackend *backend,
/* get backend instance data */
const gchar *pk_backend_get_string (PkBackend *backend,
const gchar *key);
+gchar **pk_backend_get_strv (PkBackend *backend,
+ const gchar *key);
guint pk_backend_get_uint (PkBackend *backend,
const gchar *key);
gboolean pk_backend_get_bool (PkBackend *backend,
commit d078412513bfba837d16c8f774a25f8d3ce43405
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 17:17:29 2008 +0100
convert the test thread backend from pk_backend_thread_create_old to pk_backend_thread_create
diff --git a/backends/test/pk-backend-test-thread.c b/backends/test/pk-backend-test-thread.c
index cfcff44..1b45b12 100644
--- a/backends/test/pk-backend-test-thread.c
+++ b/backends/test/pk-backend-test-thread.c
@@ -23,9 +23,8 @@
#include <glib.h>
#include <string.h>
#include <pk-backend.h>
-#include <pk-backend-thread.h>
-static PkBackendThread *thread;
+static gboolean is_cancelled = FALSE;
/**
* backend_initialize:
@@ -36,9 +35,6 @@ backend_initialize (PkBackend *backend)
{
g_return_if_fail (backend != NULL);
pk_debug ("FILTER: initialize");
-
- /* we use the thread helper */
- thread = pk_backend_thread_new ();
}
/**
@@ -50,19 +46,14 @@ backend_destroy (PkBackend *backend)
{
g_return_if_fail (backend != NULL);
pk_debug ("FILTER: destroy");
- g_object_unref (thread);
}
/**
* backend_search_group_thread:
*/
static gboolean
-backend_search_group_thread (PkBackendThread *thread, gpointer data)
+backend_search_group_thread (PkBackend *backend)
{
- PkBackend *backend;
-
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
/* emit */
@@ -81,37 +72,45 @@ static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_search_group_thread, NULL);
+ pk_backend_thread_create (backend, backend_search_group_thread);
}
/**
* backend_search_name_thread:
*/
static gboolean
-backend_search_name_thread (PkBackendThread *thread, gpointer data)
+backend_search_name_thread (PkBackend *backend)
{
GTimer *timer;
- gdouble elapsed;
guint percentage;
- PkBackend *backend;
+ PkFilterEnum filters;
+ gchar *filters_text;
+ const gchar *search;
- /* get current backend */
- backend = pk_backend_thread_get_backend (thread);
+ filters = pk_backend_get_uint (backend, "filters");
+ search = pk_backend_get_string (backend, "search");
- pk_debug ("started task (%p,%p)", backend, data);
+ filters_text = pk_filter_enums_to_text (filters);
+ pk_debug ("started task (%p) search=%s filters=%s", backend, search, filters_text);
+ g_free (filters_text);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
timer = g_timer_new ();
percentage = 0;
do {
+ /* now is a good time to see if we should cancel the thread */
+ if (is_cancelled) {
+ pk_backend_error_code (backend, PK_ERROR_ENUM_TRANSACTION_CANCELLED,
+ "The thread was stopped successfully");
+ pk_backend_finished (backend);
+ return TRUE;
+ }
pk_backend_set_percentage (backend, percentage);
- percentage += 1;
+ percentage += 10;
g_usleep (1000*100);
- elapsed = g_timer_elapsed (timer, NULL);
- pk_debug ("elapsed task (%p,%p) = %f", backend, data, elapsed);
- } while (elapsed < 10.0);
+ } while (percentage < 100);
g_timer_destroy (timer);
pk_backend_set_percentage (backend, 100);
- pk_debug ("exited task (%p,%p)", backend, data);
+ pk_debug ("exited task (%p)", backend);
pk_backend_package (backend, PK_INFO_ENUM_INSTALLED,
"glib2;2.14.0;i386;fedora", "The GLib library");
@@ -128,7 +127,20 @@ static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create_old (thread, backend_search_name_thread, NULL);
+ pk_backend_set_uint (backend, "filters", filters);
+ pk_backend_set_string (backend, "search", search);
+ pk_backend_thread_create (backend, backend_search_name_thread);
+}
+
+/**
+ * backend_cancel:
+ */
+static void
+backend_cancel (PkBackend *backend)
+{
+ g_return_if_fail (backend != NULL);
+ pk_debug ("cancelling %p", backend);
+ is_cancelled = TRUE;
}
PK_BACKEND_OPTIONS (
@@ -138,7 +150,7 @@ PK_BACKEND_OPTIONS (
backend_destroy, /* destroy */
NULL, /* get_groups */
NULL, /* get_filters */
- NULL, /* cancel */
+ backend_cancel, /* cancel */
NULL, /* get_depends */
NULL, /* get_description */
NULL, /* get_files */
commit a3b182256053d05bcbe80aaba95e528f7c967233
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 17:06:37 2008 +0100
remove the name clash over pk_backend_thread_create and convert all the users to the _old one
diff --git a/backends/apt/pk-sqlite-pkg-cache.cpp b/backends/apt/pk-sqlite-pkg-cache.cpp
index e8a4fc0..715c343 100644
--- a/backends/apt/pk-sqlite-pkg-cache.cpp
+++ b/backends/apt/pk-sqlite-pkg-cache.cpp
@@ -166,7 +166,7 @@ backend_search_common(PkBackend * backend, const gchar * filter, const gchar * s
data->search = g_strdup(search);
data->filter = g_strdup(filter);
data->depth = which;
- pk_backend_thread_create (thread, func, data);
+ pk_backend_thread_create_old (thread, func, data);
}
/**
@@ -239,7 +239,7 @@ sqlite_get_description (PkBackend *backend, const gchar *package_id)
return;
}
- pk_backend_thread_create (thread, sqlite_get_description_thread, data);
+ pk_backend_thread_create_old (thread, sqlite_get_description_thread, data);
return;
}
diff --git a/backends/box/pk-backend-box.c b/backends/box/pk-backend-box.c
index 7c7ca0d..59c7feb 100644
--- a/backends/box/pk-backend-box.c
+++ b/backends/box/pk-backend-box.c
@@ -211,7 +211,7 @@ find_packages (PkBackend *backend, const gchar *search, PkFilterEnum filters, gi
data->search = g_strdup(search);
data->filters = filters;
data->mode = mode;
- pk_backend_thread_create (thread, backend_find_packages_thread, data);
+ pk_backend_thread_create_old (thread, backend_find_packages_thread, data);
}
static gboolean
@@ -577,7 +577,7 @@ backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *pack
data->package_id = g_strdup(package_id);
data->type = DEPS_TYPE_DEPENDS;
- pk_backend_thread_create (thread, backend_get_depends_requires_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_depends_requires_thread, data);
}
/**
@@ -591,7 +591,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
g_return_if_fail (backend != NULL);
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_get_description_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_description_thread, data);
}
/**
@@ -605,7 +605,7 @@ backend_get_files (PkBackend *backend, const gchar *package_id)
g_return_if_fail (backend != NULL);
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_get_files_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_files_thread, data);
}
/**
@@ -620,7 +620,7 @@ backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *pac
data->package_id = g_strdup(package_id);
data->type = DEPS_TYPE_REQUIRES;
- pk_backend_thread_create (thread, backend_get_depends_requires_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_depends_requires_thread, data);
}
/**
@@ -630,7 +630,7 @@ static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
}
@@ -651,7 +651,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
}
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_install_package_thread, data);
+ pk_backend_thread_create_old (thread, backend_install_package_thread, data);
}
/**
@@ -665,7 +665,7 @@ backend_install_file (PkBackend *backend, gboolean trusted, const gchar *file)
g_return_if_fail (backend != NULL);
data->package_id = g_strdup(file);
- pk_backend_thread_create (thread, backend_install_file_thread, data);
+ pk_backend_thread_create_old (thread, backend_install_file_thread, data);
}
/**
@@ -681,7 +681,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
pk_backend_finished (backend);
return;
}
- pk_backend_thread_create (thread, backend_refresh_cache_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_refresh_cache_thread, NULL);
}
/**
@@ -701,7 +701,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
}
data->package_id = g_strdup (package_id);
- pk_backend_thread_create (thread, backend_remove_package_thread, data);
+ pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
}
/**
@@ -761,7 +761,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
}
data->package_ids = g_strdupv (package_ids);
- pk_backend_thread_create (thread, backend_update_packages_thread, data);
+ pk_backend_thread_create_old (thread, backend_update_packages_thread, data);
}
/**
@@ -771,7 +771,7 @@ static void
backend_update_system (PkBackend *backend)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_update_system_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_update_system_thread, NULL);
}
/**
diff --git a/backends/opkg/pk-backend-opkg.c b/backends/opkg/pk-backend-opkg.c
index 2f94bc3..6585946 100644
--- a/backends/opkg/pk-backend-opkg.c
+++ b/backends/opkg/pk-backend-opkg.c
@@ -330,7 +330,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
g_return_if_fail (backend != NULL);
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_get_description_thread,
g_strdup (package_id));
}
@@ -434,7 +434,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_refresh_cache_thread,
NULL);
}
@@ -552,7 +552,7 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
params->search_type = SEARCH_NAME;
params->needle = g_strdup (search);
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
/**
@@ -573,7 +573,7 @@ backend_search_description (PkBackend *backend, PkFilterEnum filters, const gcha
params->search_type = SEARCH_DESCRIPTION;
params->needle = g_strdup (search);
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
static void
@@ -591,7 +591,7 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *sea
params->search_type = SEARCH_TAG;
params->needle = g_strdup_printf ("group::%s", search);
- pk_backend_thread_create (thread, (PkBackendThreadFunc) backend_search_thread, params);
+ pk_backend_thread_create_old (thread, (PkBackendThreadFunc) backend_search_thread, params);
}
@@ -643,7 +643,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
pk_backend_no_percentage_updates (backend);
pk_backend_set_status (backend, PK_STATUS_ENUM_INSTALL);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_install_package_thread,
g_strdup (package_id));
}
@@ -700,7 +700,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
params[1] = GINT_TO_POINTER (allow_deps);
params[2] = GINT_TO_POINTER (autoremove);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_remove_package_thread,
params);
@@ -743,7 +743,7 @@ backend_update_system (PkBackend *backend)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_update_system_thread,
NULL);
}
@@ -858,7 +858,7 @@ backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *pack
pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_get_depends_thread,
g_strdup (package_id));
}
@@ -915,7 +915,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_update_package_thread,
/* TODO: process the entire list */
g_strdup (package_ids[0]));
@@ -981,7 +981,7 @@ backend_get_updates (PkBackend *backend, PkFilterEnum filters)
pk_backend_set_status (backend, PK_STATUS_ENUM_UPDATE);
pk_backend_no_percentage_updates (backend);
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc) backend_get_updates_thread,
NULL);
}
diff --git a/backends/poldek/pk-backend-poldek.c b/backends/poldek/pk-backend-poldek.c
index 03f1826..26726a0 100644
--- a/backends/poldek/pk-backend-poldek.c
+++ b/backends/poldek/pk-backend-poldek.c
@@ -1426,7 +1426,7 @@ backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *pack
data->package_id = g_strdup (package_id);
data->filters = filters;
data->recursive = recursive;
- pk_backend_thread_create (thread, backend_get_depends_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_depends_thread, data);
}
/**
@@ -1490,7 +1490,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc)backend_get_description_thread,
g_strdup (package_id));
}
@@ -1572,7 +1572,7 @@ backend_get_files (PkBackend *backend, const gchar *package_id)
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc)backend_get_files_thread,
g_strdup (package_id));
}
@@ -1593,7 +1593,7 @@ backend_get_packages (PkBackend *backend, PkFilterEnum filters)
data->mode = SEARCH_ENUM_NONE;
data->filters = filters;
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -1657,7 +1657,7 @@ backend_get_requires (PkBackend *backend, PkFilterEnum filters, const gchar *pac
data->package_id = g_strdup (package_id);
data->filters = filters;
data->recursive = recursive;
- pk_backend_thread_create (thread, backend_get_requires_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_requires_thread, data);
}
/**
@@ -1746,7 +1746,7 @@ backend_get_update_detail (PkBackend *backend, const gchar *package_id)
poldek_backend_set_allow_cancel (backend, FALSE, TRUE);
pb_error_clean ();
- pk_backend_thread_create (thread,
+ pk_backend_thread_create_old (thread,
(PkBackendThreadFunc)backend_get_update_detail_thread,
g_strdup (package_id));
}
@@ -1813,7 +1813,7 @@ backend_get_updates (PkBackend *backend, PkFilterEnum filters)
poldek_backend_set_allow_cancel (backend, TRUE, TRUE);
pb_error_clean ();
- pk_backend_thread_create (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
}
/**
@@ -1891,7 +1891,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
data->package_id = g_strdup (package_id);
data->pd = g_new0 (PercentageData, 1);
- pk_backend_thread_create (thread, backend_install_package_thread, data);
+ pk_backend_thread_create_old (thread, backend_install_package_thread, data);
}
/**
@@ -1976,7 +1976,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
return;
}
- pk_backend_thread_create (thread, backend_refresh_cache_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_refresh_cache_thread, NULL);
}
/**
@@ -2039,7 +2039,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
data->package_id = g_strdup (package_id);
data->allow_deps = allow_deps;
- pk_backend_thread_create (thread, backend_remove_package_thread, data);
+ pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
}
/**
@@ -2058,7 +2058,7 @@ backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
data->mode = SEARCH_ENUM_NAME;
data->filters = filters;
data->search = g_strdup (package);
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -2078,7 +2078,7 @@ backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *s
data->mode = SEARCH_ENUM_DETAILS;
data->filters = filters;
data->search = g_strdup (search);
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -2098,7 +2098,7 @@ backend_search_file (PkBackend *backend, PkFilterEnum filters, const gchar *sear
data->mode = SEARCH_ENUM_FILE;
data->filters = filters;
data->search = g_strdup (search);
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -2118,7 +2118,7 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *sea
data->mode = SEARCH_ENUM_GROUP;
data->filters = filters;
data->search = g_strdup (search);
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -2138,7 +2138,7 @@ backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *sear
data->mode = SEARCH_ENUM_NAME;
data->filters = filters;
data->search = g_strdup (search);
- pk_backend_thread_create (thread, search_package, data);
+ pk_backend_thread_create_old (thread, search_package, data);
}
/**
@@ -2250,7 +2250,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
data->package_ids = g_strdupv (package_ids);
data->pd = g_new0 (PercentageData, 1);
data->type = TS_TYPE_ENUM_UPDATE;
- pk_backend_thread_create (thread, backend_update_packages_thread, data);
+ pk_backend_thread_create_old (thread, backend_update_packages_thread, data);
}
/**
@@ -2382,7 +2382,7 @@ backend_update_system (PkBackend *backend)
data->pd = g_new0 (PercentageData, 1);
data->type = TS_TYPE_ENUM_UPDATE;
- pk_backend_thread_create (thread, backend_update_system_thread, data);
+ pk_backend_thread_create_old (thread, backend_update_system_thread, data);
}
/**
diff --git a/backends/test/pk-backend-test-thread.c b/backends/test/pk-backend-test-thread.c
index a74afe1..cfcff44 100644
--- a/backends/test/pk-backend-test-thread.c
+++ b/backends/test/pk-backend-test-thread.c
@@ -81,7 +81,7 @@ static void
backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_search_group_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_search_group_thread, NULL);
}
/**
@@ -128,7 +128,7 @@ static void
backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_search_name_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_search_name_thread, NULL);
}
PK_BACKEND_OPTIONS (
diff --git a/backends/zypp/pk-backend-zypp.cpp b/backends/zypp/pk-backend-zypp.cpp
index bf5d74c..81baf47 100644
--- a/backends/zypp/pk-backend-zypp.cpp
+++ b/backends/zypp/pk-backend-zypp.cpp
@@ -326,7 +326,7 @@ backend_get_requires(PkBackend *backend, PkFilterEnum filters, const gchar *pack
data->package_id = g_strdup(package_id);
data->type = recursive;
data->filters = filters;
- pk_backend_thread_create (thread, backend_get_requires_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_requires_thread, data);
}
/**
@@ -545,7 +545,7 @@ backend_get_depends (PkBackend *backend, PkFilterEnum filters, const gchar *pack
ThreadData *data = g_new0(ThreadData, 1);
data->package_id = g_strdup (package_id);
data->type = DEPS_TYPE_DEPENDS;
- pk_backend_thread_create (thread, backend_get_depends_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_depends_thread, data);
}
static gboolean
@@ -656,7 +656,7 @@ backend_get_description (PkBackend *backend, const gchar *package_id)
ThreadData *data = g_new0(ThreadData, 1);
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_get_description_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_description_thread, data);
}
static gboolean
@@ -808,7 +808,7 @@ static void
backend_get_updates (PkBackend *backend, PkFilterEnum filters)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_get_updates_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_get_updates_thread, NULL);
}
static gboolean
@@ -939,7 +939,7 @@ backend_install_file (PkBackend *backend, gboolean trusted, const gchar *full_pa
InstFileData *data = g_new0(InstFileData, 1);
data->full_path = g_strdup (full_path);
- pk_backend_thread_create (thread, backend_install_file_thread, data);
+ pk_backend_thread_create_old (thread, backend_install_file_thread, data);
}
static gboolean
@@ -1041,7 +1041,7 @@ backend_get_update_detail (PkBackend *backend, const gchar *package_id)
ThreadData *data = g_new0(ThreadData, 1);
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_get_update_detail_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_update_detail_thread, data);
}
static gboolean
@@ -1093,7 +1093,7 @@ static void
backend_update_system (PkBackend *backend)
{
g_return_if_fail (backend != NULL);
- pk_backend_thread_create (thread, backend_update_system_thread, NULL);
+ pk_backend_thread_create_old (thread, backend_update_system_thread, NULL);
}
static gboolean
@@ -1195,7 +1195,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
pk_backend_set_allow_cancel (backend, FALSE);
gchar *package_to_install = g_strdup (package_id);
- pk_backend_thread_create (thread, backend_install_package_thread, package_to_install);
+ pk_backend_thread_create_old (thread, backend_install_package_thread, package_to_install);
}
static gboolean
@@ -1295,7 +1295,7 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
data->package_id = g_strdup (package_id);
data->deps_behavior = allow_deps == TRUE ? DEPS_ALLOW : DEPS_NO_ALLOW;
- pk_backend_thread_create (thread, backend_remove_package_thread, data);
+ pk_backend_thread_create_old (thread, backend_remove_package_thread, data);
}
/**
@@ -1316,7 +1316,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
*/
RefreshData *data = g_new(RefreshData, 1);
data->force = force;
- pk_backend_thread_create (thread, backend_refresh_cache_thread, data);
+ pk_backend_thread_create_old (thread, backend_refresh_cache_thread, data);
}
static gboolean
@@ -1378,7 +1378,7 @@ backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package_
ResolveData *data = g_new0(ResolveData, 1);
data->name = g_strdup (package_id);
data->filters = filters;
- pk_backend_thread_create (thread, backend_resolve_thread, data);
+ pk_backend_thread_create_old (thread, backend_resolve_thread, data);
}
static void
@@ -1439,7 +1439,7 @@ find_packages (PkBackend *backend, const gchar *search, PkFilterEnum filters, gi
data->search = g_strdup(search);
data->filters = filters;
data->mode = mode;
- pk_backend_thread_create (thread, backend_find_packages_thread, data);
+ pk_backend_thread_create_old (thread, backend_find_packages_thread, data);
}
/**
@@ -1522,7 +1522,7 @@ backend_search_group (PkBackend *backend, PkFilterEnum filters, const gchar *pkG
GroupData *data = g_new0(GroupData, 1);
data->pkGroup = g_strdup(pkGroup);
data->filters = filters;
- pk_backend_thread_create (thread, backend_search_group_thread, data);
+ pk_backend_thread_create_old (thread, backend_search_group_thread, data);
}
/**
@@ -1692,7 +1692,7 @@ backend_get_files(PkBackend *backend, const gchar *package_id)
ThreadData *data = g_new0(ThreadData, 1);
data->package_id = g_strdup(package_id);
- pk_backend_thread_create (thread, backend_get_files_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_files_thread, data);
}
static gboolean
@@ -1733,7 +1733,7 @@ backend_get_packages (PkBackend *backend, PkFilterEnum filter)
PkFilterEnum *data = g_new0(PkFilterEnum, 1);
*data = filter;
- pk_backend_thread_create (thread, backend_get_packages_thread, data);
+ pk_backend_thread_create_old (thread, backend_get_packages_thread, data);
}
static gboolean
@@ -1772,7 +1772,7 @@ backend_update_packages(PkBackend *backend, gchar **package_ids)
UpdateData *data = g_new0(UpdateData, 1);
data->packages = g_strdupv (package_ids);
- pk_backend_thread_create(thread, backend_update_packages_thread, data);
+ pk_backend_thread_create_old(thread, backend_update_packages_thread, data);
}
@@ -1898,7 +1898,7 @@ backend_repo_set_data(PkBackend *backend, const gchar *repo_id, const gchar *par
data->parameter = g_strdup (parameter);
data->value = g_strdup (value);
- pk_backend_thread_create(thread, backend_repo_set_data_thread, data);
+ pk_backend_thread_create_old(thread, backend_repo_set_data_thread, data);
}
@@ -1942,7 +1942,7 @@ backend_what_provides(PkBackend *backend, PkFilterEnum filters, PkProvidesEnum p
ResolveData *data = g_new0(ResolveData, 1);
data->name = g_strdup(search);
data->filters = filters;
- pk_backend_thread_create (thread, backend_what_provides_thread, data);
+ pk_backend_thread_create_old (thread, backend_what_provides_thread, data);
}
extern "C" PK_BACKEND_OPTIONS (
diff --git a/src/pk-backend-thread.c b/src/pk-backend-thread.c
index 9349b29..3f45ab8 100644
--- a/src/pk-backend-thread.c
+++ b/src/pk-backend-thread.c
@@ -66,12 +66,13 @@ struct PkBackendThreadPrivate
G_DEFINE_TYPE (PkBackendThread, pk_backend_thread, G_TYPE_OBJECT)
/**
- * pk_backend_thread_create:
+ * pk_backend_thread_create_old:
**/
gboolean
-pk_backend_thread_create (PkBackendThread *backend_thread, PkBackendThreadFunc func, gpointer data)
+pk_backend_thread_create_old (PkBackendThread *backend_thread, PkBackendThreadFuncOld func, gpointer data)
{
g_return_val_if_fail (PK_IS_BACKEND_THREAD (backend_thread), FALSE);
+ pk_warning ("*** DO NOT USE THIS FUNCTION *** - use pk_backend_thread_create() instead ***");
return pk_thread_list_create (backend_thread->priv->thread_list, (PkThreadFunc) func, backend_thread, data);
}
@@ -217,7 +218,7 @@ libst_backend_thread (LibSelfTest *test)
/************************************************************/
libst_title (test, "wait for a thread to return true");
- ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_true, NULL);
+ ret = pk_backend_thread_create_old (backend_thread, pk_backend_thread_test_func_true, NULL);
if (ret) {
libst_success (test, NULL);
} else {
@@ -247,7 +248,7 @@ libst_backend_thread (LibSelfTest *test)
/************************************************************/
libst_title (test, "wait for a thread to return false");
- ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_false, NULL);
+ ret = pk_backend_thread_create_old (backend_thread, pk_backend_thread_test_func_false, NULL);
if (ret) {
libst_success (test, NULL);
} else {
@@ -277,7 +278,7 @@ libst_backend_thread (LibSelfTest *test)
/************************************************************/
libst_title (test, "wait for a thread to return false (straight away)");
- ret = pk_backend_thread_create (backend_thread, pk_backend_thread_test_func_immediate_false, NULL);
+ ret = pk_backend_thread_create_old (backend_thread, pk_backend_thread_test_func_immediate_false, NULL);
if (ret) {
libst_success (test, NULL);
} else {
diff --git a/src/pk-backend-thread.h b/src/pk-backend-thread.h
index d7b4f30..204750b 100644
--- a/src/pk-backend-thread.h
+++ b/src/pk-backend-thread.h
@@ -52,10 +52,10 @@ typedef struct
/* general */
GType pk_backend_thread_get_type (void) G_GNUC_CONST;
PkBackendThread *pk_backend_thread_new (void);
-typedef gboolean (*PkBackendThreadFunc) (PkBackendThread *backend_thread,
+typedef gboolean (*PkBackendThreadFuncOld) (PkBackendThread *backend_thread,
gpointer data);
-gboolean pk_backend_thread_create (PkBackendThread *backend_thread,
- PkBackendThreadFunc func,
+gboolean pk_backend_thread_create_old (PkBackendThread *backend_thread,
+ PkBackendThreadFuncOld func,
gpointer data);
PkBackend *pk_backend_thread_get_backend (PkBackendThread *backend_thread);
commit b80e450f1790ccb8ed8ce9d4d4386b5fffb0a0a7
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 16:56:19 2008 +0100
add a simple thread handler in PkBackend
diff --git a/src/pk-backend.c b/src/pk-backend.c
index c38f48e..2de1e84 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -104,6 +104,7 @@ struct _PkBackendPrivate
guint last_remaining;
guint signal_finished;
guint signal_error_timeout;
+ GThread *thread;
GHashTable *hash_string;
GHashTable *hash_pointer;
};
@@ -1192,7 +1193,7 @@ pk_backend_error_code (PkBackend *backend, PkErrorCodeEnum code, const gchar *fo
/* we mark any transaction with errors as failed */
pk_backend_set_exit_code (backend, PK_EXIT_ENUM_FAILED);
- pk_debug ("emit error-code %i, %s", code, buffer);
+ pk_debug ("emit error-code %s, %s", pk_error_enum_to_text (code), buffer);
g_signal_emit (backend, signals [PK_BACKEND_ERROR_CODE], 0, code, buffer);
out:
@@ -1430,6 +1431,27 @@ pk_backend_not_implemented_yet (PkBackend *backend, const gchar *method)
}
/**
+ * pk_backend_thread_create:
+ **/
+gboolean
+pk_backend_thread_create (PkBackend *backend, PkBackendThreadFunc func)
+{
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (func != NULL, FALSE);
+
+ if (backend->priv->thread != NULL) {
+ pk_warning ("already has thread");
+ return FALSE;
+ }
+ backend->priv->thread = g_thread_create ((GThreadFunc) func, backend, FALSE, NULL);
+ if (backend->priv->thread == NULL) {
+ pk_warning ("failed to create thread");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
* pk_backend_get_backend_detail:
*/
gboolean
@@ -1575,6 +1597,8 @@ pk_backend_finalize (GObject *object)
g_source_remove (backend->priv->signal_error_timeout);
}
+ /* TODO: need to wait for Finished() if running */
+
g_free (backend->priv->name);
g_free (backend->priv->c_tid);
g_object_unref (backend->priv->time);
@@ -1694,6 +1718,7 @@ pk_backend_reset (PkBackend *backend)
backend->priv->allow_cancel = FALSE;
backend->priv->finished = FALSE;
backend->priv->has_sent_package = FALSE;
+ backend->priv->thread = NULL;
backend->priv->status = PK_STATUS_ENUM_UNKNOWN;
backend->priv->exit = PK_EXIT_ENUM_UNKNOWN;
backend->priv->role = PK_ROLE_ENUM_UNKNOWN;
@@ -1790,6 +1815,21 @@ pk_backend_test_watch_file_cb (PkBackend *backend, gpointer data)
libst_loopquit (test);
}
+static gboolean
+pk_backend_test_func_true (PkBackend *backend)
+{
+ g_usleep (1000*1000);
+ pk_backend_finished (backend);
+ return TRUE;
+}
+
+static gboolean
+pk_backend_test_func_immediate_false (PkBackend *backend)
+{
+ pk_backend_finished (backend);
+ return FALSE;
+}
+
void
libst_backend (LibSelfTest *test)
{
@@ -2119,31 +2159,49 @@ libst_backend (LibSelfTest *test)
}
/************************************************************/
- pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error");
+ libst_title (test, "wait for a thread to return true");
+ ret = pk_backend_thread_create (backend, pk_backend_test_func_true);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "wait for a thread failed");
+ }
- /* wait for finished */
- libst_loopwait (test, PK_BACKEND_FINISHED_ERROR_TIMEOUT + 200);
+ /* wait for Finished */
+ libst_loopwait (test, 2000);
libst_loopcheck (test);
- libst_title (test, "check we enforce finished after error_code");
- if (number_messages == 1) {
+ /* reset */
+ pk_backend_reset (backend);
+
+ /************************************************************/
+ libst_title (test, "wait for a thread to return false (straight away)");
+ ret = pk_backend_thread_create (backend, pk_backend_test_func_immediate_false);
+ if (ret) {
libst_success (test, NULL);
} else {
- libst_failed (test, "we messaged %i times!", number_messages);
+ libst_failed (test, "returned false!");
}
- /* reset */
- pk_backend_reset (backend);
- number_messages = 0;
+ /* wait for Finished */
+ libst_loopwait (test, PK_BACKEND_FINISHED_TIMEOUT_GRACE + 100);
+ libst_loopcheck (test);
/************************************************************/
- pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error1");
- pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error2");
+ pk_backend_reset (backend);
+ pk_backend_error_code (backend, PK_ERROR_ENUM_GPG_FAILURE, "test error");
/* wait for finished */
- libst_loopwait (test, PK_BACKEND_FINISHED_ERROR_TIMEOUT + 100);
+ libst_loopwait (test, PK_BACKEND_FINISHED_ERROR_TIMEOUT + 200);
libst_loopcheck (test);
+ libst_title (test, "check we enforce finished after error_code");
+ if (number_messages == 1) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "we messaged %i times!", number_messages);
+ }
+
g_object_unref (backend);
libst_end (test);
diff --git a/src/pk-backend.h b/src/pk-backend.h
index 353c435..0fff22e 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -121,32 +121,35 @@ gboolean pk_backend_eula_required (PkBackend *backend,
const gchar *license_agreement);
/* set backend instance data */
-gboolean pk_backend_set_string (PkBackend *backend,
- const gchar *key,
- const gchar *data);
-gboolean pk_backend_set_uint (PkBackend *backend,
- const gchar *key,
- guint data);
-gboolean pk_backend_set_bool (PkBackend *backend,
- const gchar *key,
- gboolean data);
-gboolean pk_backend_set_pointer (PkBackend *backend,
- const gchar *key,
- gpointer data);
+gboolean pk_backend_set_string (PkBackend *backend,
+ const gchar *key,
+ const gchar *data);
+gboolean pk_backend_set_uint (PkBackend *backend,
+ const gchar *key,
+ guint data);
+gboolean pk_backend_set_bool (PkBackend *backend,
+ const gchar *key,
+ gboolean data);
+gboolean pk_backend_set_pointer (PkBackend *backend,
+ const gchar *key,
+ gpointer data);
/* get backend instance data */
-const gchar *pk_backend_get_string (PkBackend *backend,
- const gchar *key);
-guint pk_backend_get_uint (PkBackend *backend,
- const gchar *key);
-gboolean pk_backend_get_bool (PkBackend *backend,
- const gchar *key);
-gpointer pk_backend_get_pointer (PkBackend *backend,
- const gchar *key);
+const gchar *pk_backend_get_string (PkBackend *backend,
+ const gchar *key);
+guint pk_backend_get_uint (PkBackend *backend,
+ const gchar *key);
+gboolean pk_backend_get_bool (PkBackend *backend,
+ const gchar *key);
+gpointer pk_backend_get_pointer (PkBackend *backend,
+ const gchar *key);
/* helper functions */
gboolean pk_backend_not_implemented_yet (PkBackend *backend,
const gchar *method);
+typedef gboolean (*PkBackendThreadFunc) (PkBackend *backend);
+gboolean pk_backend_thread_create (PkBackend *backend,
+ PkBackendThreadFunc func);
/* config changed functions */
typedef void (*PkBackendFileChanged) (PkBackend *backend,
@@ -160,82 +163,82 @@ gboolean pk_backend_watch_file (PkBackend *backend,
* PkBackendDesc:
*/
typedef struct {
- const char *description;
- const char *author;
- void (*initialize) (PkBackend *backend);
- void (*destroy) (PkBackend *backend);
- PkGroupEnum (*get_groups) (PkBackend *backend);
- PkFilterEnum (*get_filters) (PkBackend *backend);
- void (*cancel) (PkBackend *backend);
- void (*get_depends) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *package_id,
- gboolean recursive);
- void (*get_description) (PkBackend *backend,
- const gchar *package_id);
- void (*get_files) (PkBackend *backend,
- const gchar *package_id);
- void (*get_packages) (PkBackend *backend,
- PkFilterEnum filters);
- void (*get_repo_list) (PkBackend *backend,
- PkFilterEnum filters);
- void (*get_requires) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *package_id,
- gboolean recursive);
- void (*get_update_detail) (PkBackend *backend,
- const gchar *package_id);
- void (*get_updates) (PkBackend *backend,
- PkFilterEnum filters);
- void (*install_file) (PkBackend *backend,
- gboolean trusted,
- const gchar *full_path);
- void (*install_package) (PkBackend *backend,
- const gchar *package_id);
- void (*install_signature) (PkBackend *backend,
- PkSigTypeEnum type,
- const gchar *key_id,
- const gchar *package_id);
- void (*refresh_cache) (PkBackend *backend,
- gboolean force);
- void (*remove_package) (PkBackend *backend,
- const gchar *package_id,
- gboolean allow_deps,
- gboolean autoremove);
- void (*repo_enable) (PkBackend *backend,
- const gchar *repo_id,
- gboolean enabled);
- void (*repo_set_data) (PkBackend *backend,
- const gchar *repo_id,
- const gchar *parameter,
- const gchar *value);
- void (*resolve) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *package);
- void (*rollback) (PkBackend *backend,
- const gchar *transaction_id);
- void (*search_details) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *search);
- void (*search_file) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *search);
- void (*search_group) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *search);
- void (*search_name) (PkBackend *backend,
- PkFilterEnum filters,
- const gchar *search);
- void (*service_pack) (PkBackend *backend,
- const gchar *location,
- gboolean enabled);
- void (*update_packages) (PkBackend *backend,
- gchar **package_ids);
- void (*update_system) (PkBackend *backend);
- void (*what_provides) (PkBackend *backend,
- PkFilterEnum filters,
- PkProvidesEnum provide,
- const gchar *search);
+ const gchar *description;
+ const gchar *author;
+ void (*initialize) (PkBackend *backend);
+ void (*destroy) (PkBackend *backend);
+ PkGroupEnum (*get_groups) (PkBackend *backend);
+ PkFilterEnum (*get_filters) (PkBackend *backend);
+ void (*cancel) (PkBackend *backend);
+ void (*get_depends) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *package_id,
+ gboolean recursive);
+ void (*get_description) (PkBackend *backend,
+ const gchar *package_id);
+ void (*get_files) (PkBackend *backend,
+ const gchar *package_id);
+ void (*get_packages) (PkBackend *backend,
+ PkFilterEnum filters);
+ void (*get_repo_list) (PkBackend *backend,
+ PkFilterEnum filters);
+ void (*get_requires) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *package_id,
+ gboolean recursive);
+ void (*get_update_detail) (PkBackend *backend,
+ const gchar *package_id);
+ void (*get_updates) (PkBackend *backend,
+ PkFilterEnum filters);
+ void (*install_file) (PkBackend *backend,
+ gboolean trusted,
+ const gchar *full_path);
+ void (*install_package) (PkBackend *backend,
+ const gchar *package_id);
+ void (*install_signature) (PkBackend *backend,
+ PkSigTypeEnum type,
+ const gchar *key_id,
+ const gchar *package_id);
+ void (*refresh_cache) (PkBackend *backend,
+ gboolean force);
+ void (*remove_package) (PkBackend *backend,
+ const gchar *package_id,
+ gboolean allow_deps,
+ gboolean autoremove);
+ void (*repo_enable) (PkBackend *backend,
+ const gchar *repo_id,
+ gboolean enabled);
+ void (*repo_set_data) (PkBackend *backend,
+ const gchar *repo_id,
+ const gchar *parameter,
+ const gchar *value);
+ void (*resolve) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *package);
+ void (*rollback) (PkBackend *backend,
+ const gchar *transaction_id);
+ void (*search_details) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *search);
+ void (*search_file) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *search);
+ void (*search_group) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *search);
+ void (*search_name) (PkBackend *backend,
+ PkFilterEnum filters,
+ const gchar *search);
+ void (*service_pack) (PkBackend *backend,
+ const gchar *location,
+ gboolean enabled);
+ void (*update_packages) (PkBackend *backend,
+ gchar **package_ids);
+ void (*update_system) (PkBackend *backend);
+ void (*what_provides) (PkBackend *backend,
+ PkFilterEnum filters,
+ PkProvidesEnum provide,
+ const gchar *search);
gpointer padding[10];
} PkBackendDesc;
commit e386c904c18e2be750601397c6eb0a368f3b6444
Author: Richard Hughes <richard at hughsie.com>
Date: Tue Apr 29 16:05:54 2008 +0100
add per-backend instance getters and setters to PkBackend
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 7a6f00f..c38f48e 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -104,6 +104,8 @@ struct _PkBackendPrivate
guint last_remaining;
guint signal_finished;
guint signal_error_timeout;
+ GHashTable *hash_string;
+ GHashTable *hash_pointer;
};
G_DEFINE_TYPE (PkBackend, pk_backend, G_TYPE_OBJECT)
@@ -252,28 +254,166 @@ pk_backend_get_actions (PkBackend *backend)
}
/**
- * pk_backend_set_internal:
- *
- * Designed for volatile internal state, such as the authentication prompt
- * response, the proxy to use and that sort of thing
+ * pk_backend_set_string:
**/
gboolean
-pk_backend_set_internal (PkBackend *backend, const gchar *key, const gchar *data)
+pk_backend_set_string (PkBackend *backend, const gchar *key, const gchar *data)
{
+ gpointer value;
g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
- return FALSE;
+ g_return_val_if_fail (key != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_string, (gpointer) key);
+ if (value != NULL) {
+ pk_warning ("already set data for %s", key);
+ return FALSE;
+ }
+ pk_debug ("saving '%s' for %s", data, key);
+ g_hash_table_insert (backend->priv->hash_string, g_strdup (key), (gpointer) g_strdup (data));
+ return TRUE;
}
/**
- * pk_backend_get_internal:
- *
- * Must g_free() the return value. Returns NULL on error.
+ * pk_backend_set_uint:
**/
-gchar *
-pk_backend_get_internal (PkBackend *backend, const gchar *key)
+gboolean
+pk_backend_set_uint (PkBackend *backend, const gchar *key, guint data)
{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value != NULL) {
+ pk_warning ("already set data for %s", key);
+ return FALSE;
+ }
+ pk_debug ("saving %i for %s", data, key);
+ g_hash_table_insert (backend->priv->hash_pointer, g_strdup (key), GINT_TO_POINTER (data+1));
+ return TRUE;
+}
+
+/**
+ * pk_backend_set_bool:
+ **/
+gboolean
+pk_backend_set_bool (PkBackend *backend, const gchar *key, gboolean data)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value != NULL) {
+ pk_warning ("already set data for %s", key);
+ return FALSE;
+ }
+ pk_debug ("saving %i for %s", data, key);
+ g_hash_table_insert (backend->priv->hash_pointer, g_strdup (key), GINT_TO_POINTER (data+1));
+ return TRUE;
+}
+
+/**
+ * pk_backend_set_pointer:
+ **/
+gboolean
+pk_backend_set_pointer (PkBackend *backend, const gchar *key, gpointer data)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+ g_return_val_if_fail (data != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value != NULL) {
+ pk_warning ("already set data for %s", key);
+ return FALSE;
+ }
+ pk_debug ("saving %p for %s", data, key);
+ g_hash_table_insert (backend->priv->hash_pointer, g_strdup (key), data+1);
+ return TRUE;
+}
+
+/**
+ * pk_backend_get_string:
+ **/
+const gchar *
+pk_backend_get_string (PkBackend *backend, const gchar *key)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), NULL);
+ g_return_val_if_fail (key != NULL, NULL);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_string, (gpointer) key);
+ if (value == NULL) {
+ pk_warning ("not set data for %s", key);
+ return FALSE;
+ }
+ return (const gchar *) value;
+}
+
+/**
+ * pk_backend_get_uint:
+ **/
+uint
+pk_backend_get_uint (PkBackend *backend, const gchar *key)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), 0);
+ g_return_val_if_fail (key != NULL, 0);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value == NULL) {
+ pk_warning ("not set data for %s", key);
+ return FALSE;
+ }
+ /* we do the +1/-1 as NULL also means missing in the hash table */
+ return GPOINTER_TO_INT (value)-1;
+}
+
+/**
+ * pk_backend_get_bool:
+ **/
+gboolean
+pk_backend_get_bool (PkBackend *backend, const gchar *key)
+{
+ gpointer value;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (key != NULL, FALSE);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value == NULL) {
+ pk_warning ("not set data for %s", key);
+ return FALSE;
+ }
+ return GPOINTER_TO_INT (value)-1;
+}
+
+/**
+ * pk_backend_get_pointer:
+ **/
+gpointer
+pk_backend_get_pointer (PkBackend *backend, const gchar *key)
+{
+ gpointer value;
g_return_val_if_fail (PK_IS_BACKEND (backend), NULL);
- return NULL;
+ g_return_val_if_fail (key != NULL, NULL);
+
+ /* does already exist? */
+ value = g_hash_table_lookup (backend->priv->hash_pointer, (gpointer) key);
+ if (value == NULL) {
+ pk_warning ("not set data for %s", key);
+ return FALSE;
+ }
+ return value-1;
}
/**
@@ -1177,6 +1317,10 @@ pk_backend_finished_delay (gpointer data)
pk_backend_set_exit_code (backend, PK_EXIT_ENUM_SUCCESS);
}
+ pk_debug ("resetting hash tables to blank");
+ g_hash_table_remove_all (backend->priv->hash_pointer);
+ g_hash_table_remove_all (backend->priv->hash_string);
+
pk_debug ("emit finished %i", backend->priv->exit);
g_signal_emit (backend, signals [PK_BACKEND_FINISHED], 0, backend->priv->exit);
backend->priv->signal_finished = 0;
@@ -1436,6 +1580,8 @@ pk_backend_finalize (GObject *object)
g_object_unref (backend->priv->time);
g_object_unref (backend->priv->inhibit);
g_hash_table_destroy (backend->priv->eulas);
+ g_hash_table_unref (backend->priv->hash_string);
+ g_hash_table_unref (backend->priv->hash_pointer);
if (backend->priv->handle != NULL) {
g_module_close (backend->priv->handle);
@@ -1578,6 +1724,8 @@ pk_backend_init (PkBackend *backend)
backend->priv->time = pk_time_new ();
backend->priv->inhibit = pk_inhibit_new ();
backend->priv->eulas = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+ backend->priv->hash_string = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+ backend->priv->hash_pointer = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
/* monitor config files for changes */
backend->priv->file_monitor = pk_file_monitor_new ();
@@ -1649,6 +1797,9 @@ libst_backend (LibSelfTest *test)
gchar *text;
gboolean ret;
const gchar *filename;
+ const gchar *data_string;
+ guint data_uint;
+ gboolean data_bool;
if (libst_start (test, "PkBackend", CLASS_AUTO) == FALSE) {
return;
@@ -1664,6 +1815,114 @@ libst_backend (LibSelfTest *test)
}
/************************************************************/
+ libst_title (test, "set a blank string");
+ ret = pk_backend_set_string (backend, "dave2", "");
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "set a ~bool");
+ ret = pk_backend_set_bool (backend, "roger2", FALSE);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "set a zero uint");
+ ret = pk_backend_set_uint (backend, "linda2", 0);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a blank string");
+ data_string = pk_backend_get_string (backend, "dave2");
+ if (pk_strequal (data_string, "")) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %s", data_string);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a ~bool");
+ data_bool = pk_backend_get_bool (backend, "roger2");
+ if (!data_bool) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %i", data_bool);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a zero uint");
+ data_uint = pk_backend_get_uint (backend, "linda2");
+ if (data_uint == 0) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %i", data_uint);
+ }
+
+ /************************************************************/
+ libst_title (test, "set a string");
+ ret = pk_backend_set_string (backend, "dave", "ania");
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "set a bool");
+ ret = pk_backend_set_bool (backend, "roger", TRUE);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "set a uint");
+ ret = pk_backend_set_uint (backend, "linda", 999);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a string");
+ data_string = pk_backend_get_string (backend, "dave");
+ if (pk_strequal (data_string, "ania")) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %s", data_string);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a bool");
+ data_bool = pk_backend_get_bool (backend, "roger");
+ if (data_bool) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %i", data_bool);
+ }
+
+ /************************************************************/
+ libst_title (test, "get a uint");
+ data_uint = pk_backend_get_uint (backend, "linda");
+ if (data_uint == 999) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "data was %i", data_uint);
+ }
+
+ /************************************************************/
libst_title (test, "create a config file");
filename = "/tmp/dave";
ret = g_file_set_contents (filename, "foo", -1, NULL);
diff --git a/src/pk-backend.h b/src/pk-backend.h
index 19998c9..353c435 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -120,13 +120,29 @@ gboolean pk_backend_eula_required (PkBackend *backend,
const gchar *vendor_name,
const gchar *license_agreement);
-/* internal state */
-gboolean pk_backend_set_internal (PkBackend *backend,
- const gchar *key,
- const gchar *data);
-gchar *pk_backend_get_internal (PkBackend *backend,
- const gchar *key);
+/* set backend instance data */
+gboolean pk_backend_set_string (PkBackend *backend,
+ const gchar *key,
+ const gchar *data);
+gboolean pk_backend_set_uint (PkBackend *backend,
+ const gchar *key,
+ guint data);
+gboolean pk_backend_set_bool (PkBackend *backend,
+ const gchar *key,
+ gboolean data);
+gboolean pk_backend_set_pointer (PkBackend *backend,
+ const gchar *key,
+ gpointer data);
+/* get backend instance data */
+const gchar *pk_backend_get_string (PkBackend *backend,
+ const gchar *key);
+guint pk_backend_get_uint (PkBackend *backend,
+ const gchar *key);
+gboolean pk_backend_get_bool (PkBackend *backend,
+ const gchar *key);
+gpointer pk_backend_get_pointer (PkBackend *backend,
+ const gchar *key);
/* helper functions */
gboolean pk_backend_not_implemented_yet (PkBackend *backend,
More information about the PackageKit-commit
mailing list