[PackageKit-commit] packagekit: Branch 'master' - 7 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Wed Apr 23 06:04:35 PDT 2008
backends/alpm/pk-backend-alpm.c | 244 ++++++++++++----------------------------
docs/spec/Makefile.am | 3
docs/spec/pk-developer-faq.xml | 70 +++++++++++
docs/spec/pk-faq-error-code.png |binary
docs/spec/pk-faq-status.png |binary
docs/spec/pk-reference.xml | 1
src/Makefile.am | 6
src/pk-backend.c | 114 +++++++++++++++++-
src/pk-backend.h | 8 +
src/pk-engine.c | 23 ++-
src/pk-file-monitor-dummy.c | 157 +++++++++++++++++++++++++
src/pk-file-monitor-gio.c | 205 +++++++++++++++++++++++++++++++++
src/pk-file-monitor.h | 57 +++++++++
src/pk-restart-dummy.c | 149 ------------------------
src/pk-restart-gio.c | 196 --------------------------------
src/pk-restart.h | 54 --------
src/pk-self-test.c | 4
17 files changed, 701 insertions(+), 590 deletions(-)
New commits:
commit d2e123030526f5c16cfdcdd6d6eed25f9f8bd730
Merge: 9ee932d... 24bff50...
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 14:01:36 2008 +0100
Merge branch 'restart2generic'
commit 24bff50d4bdd964f3c2849fb4aca84bae0ffc068
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 14:01:06 2008 +0100
provide a pk_backend_watch_file() function that can be used in backends to detect when a config file has changed
diff --git a/src/pk-backend.c b/src/pk-backend.c
index ba480c1..c4bc81d 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -39,6 +39,7 @@
#include "pk-backend.h"
#include "pk-time.h"
#include "pk-inhibit.h"
+#include "pk-file-monitor.h"
#define PK_BACKEND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_BACKEND, PkBackendPrivate))
@@ -91,6 +92,9 @@ struct _PkBackendPrivate
PkStatusEnum status; /* this changes */
PkExitEnum exit;
PkInhibit *inhibit;
+ PkFileMonitor *file_monitor;
+ PkBackendFileChanged file_changed_func;
+ gpointer file_changed_data;
gboolean during_initialize;
gboolean allow_cancel;
gboolean finished;
@@ -1342,6 +1346,44 @@ pk_backend_is_eula_valid (PkBackend *backend, const gchar *eula_id)
return FALSE;
}
+
+/**
+ * pk_backend_watch_file:
+ */
+gboolean
+pk_backend_watch_file (PkBackend *backend, const gchar *filename, PkBackendFileChanged func, gpointer data)
+{
+ gboolean ret;
+
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ g_return_val_if_fail (filename != NULL, FALSE);
+ g_return_val_if_fail (func != NULL, FALSE);
+
+ if (backend->priv->file_changed_func != NULL) {
+ pk_warning ("already set");
+ return FALSE;
+ }
+ ret = pk_file_monitor_set_file (backend->priv->file_monitor, filename);;
+
+ /* if we set it up, set the function callback */
+ if (ret) {
+ backend->priv->file_changed_func = func;
+ backend->priv->file_changed_data = data;
+ }
+ return ret;
+}
+
+/**
+ * pk_backend_file_monitor_changed_cb:
+ **/
+static void
+pk_backend_file_monitor_changed_cb (PkFileMonitor *file_monitor, PkBackend *backend)
+{
+ g_return_if_fail (PK_IS_BACKEND (backend));
+ pk_debug ("config file changed");
+ backend->priv->file_changed_func (backend, backend->priv->file_changed_data);
+}
+
/**
* pk_backend_finalize:
**/
@@ -1503,6 +1545,8 @@ pk_backend_init (PkBackend *backend)
backend->priv->handle = NULL;
backend->priv->name = NULL;
backend->priv->c_tid = NULL;
+ backend->priv->file_changed_func = NULL;
+ backend->priv->file_changed_data = NULL;
backend->priv->locked = FALSE;
backend->priv->signal_finished = 0;
backend->priv->signal_error_timeout = 0;
@@ -1510,6 +1554,12 @@ 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);
+
+ /* monitor config files for changes */
+ backend->priv->file_monitor = pk_file_monitor_new ();
+ g_signal_connect (backend->priv->file_monitor, "file-changed",
+ G_CALLBACK (pk_backend_file_monitor_changed_cb), backend);
+
pk_backend_reset (backend);
}
@@ -1535,6 +1585,7 @@ pk_backend_new (void)
***************************************************************************/
#ifdef PK_BUILD_TESTS
#include <libselftest.h>
+#include <glib/gstdio.h>
static guint number_messages = 0;
@@ -1557,12 +1608,23 @@ pk_backend_test_finished_cb (PkBackend *backend, PkExitEnum exit, LibSelfTest *t
libst_loopquit (test);
}
+/**
+ * pk_backend_test_watch_file_cb:
+ **/
+static void
+pk_backend_test_watch_file_cb (PkBackend *backend, gpointer data)
+{
+ LibSelfTest *test = (LibSelfTest *) data;
+ libst_loopquit (test);
+}
+
void
libst_backend (LibSelfTest *test)
{
PkBackend *backend;
gchar *text;
gboolean ret;
+ const gchar *filename;
if (libst_start (test, "PkBackend", CLASS_AUTO) == FALSE) {
return;
@@ -1577,6 +1639,47 @@ libst_backend (LibSelfTest *test)
libst_failed (test, NULL);
}
+ /************************************************************/
+ libst_title (test, "create a config file");
+ filename = "/tmp/dave";
+ ret = g_file_set_contents (filename, "foo", -1, NULL);
+ if (ret) {
+ libst_success (test, "set contents");
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /************************************************************/
+ libst_title (test, "set up a watch file on a config file");
+ ret = pk_backend_watch_file (backend, filename, pk_backend_test_watch_file_cb, test);
+ if (ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, "eula valid");
+ }
+
+ /************************************************************/
+ libst_title (test, "change the config file");
+ ret = g_file_set_contents (filename, "bar", -1, NULL);
+ if (ret) {
+ libst_success (test, "set contents");
+ } else {
+ libst_failed (test, NULL);
+ }
+
+ /* wait for config file change */
+ libst_loopwait (test, 2000);
+ libst_loopcheck (test);
+
+ /************************************************************/
+ libst_title (test, "delete the config file");
+ ret = g_unlink (filename);
+ if (!ret) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+
g_signal_connect (backend, "message", G_CALLBACK (pk_backend_test_message_cb), NULL);
g_signal_connect (backend, "finished", G_CALLBACK (pk_backend_test_finished_cb), test);
diff --git a/src/pk-backend.h b/src/pk-backend.h
index 65db1c0..19998c9 100644
--- a/src/pk-backend.h
+++ b/src/pk-backend.h
@@ -132,6 +132,14 @@ gchar *pk_backend_get_internal (PkBackend *backend,
gboolean pk_backend_not_implemented_yet (PkBackend *backend,
const gchar *method);
+/* config changed functions */
+typedef void (*PkBackendFileChanged) (PkBackend *backend,
+ gpointer data);
+gboolean pk_backend_watch_file (PkBackend *backend,
+ const gchar *filename,
+ PkBackendFileChanged func,
+ gpointer data);
+
/**
* PkBackendDesc:
*/
commit 9ee932d29abbe9f0456d2968bcc7b51a19e5ad4f
Author: Valeriy Lyasotskiy <onestep at ukr.net>
Date: Wed Apr 23 15:39:40 2008 +0300
improvements in search functions
diff --git a/backends/alpm/pk-backend-alpm.c b/backends/alpm/pk-backend-alpm.c
index 91a4178..b5250f7 100644
--- a/backends/alpm/pk-backend-alpm.c
+++ b/backends/alpm/pk-backend-alpm.c
@@ -20,6 +20,13 @@
*/
#define ALPM_CONFIG_PATH "/etc/pacman.conf"
+
+#define ALPM_ROOT "/"
+#define ALPM_DBPATH "/var/lib/pacman"
+#define ALPM_CACHEDIR "/var/cache/pacman/pkg"
+#define ALPM_LOGFILE "/var/log/pacman.log"
+#define ALPM_XFERCOMMAND "/usr/bin/wget --passive-ftp -c -O \%o \%u"
+
#define ALPM_PROGRESS_UPDATE_INTERVAL 400
#include <gmodule.h>
@@ -107,55 +114,6 @@ state_notify (void *backend)
}
alpm_list_t *
-my_list_mmerge (alpm_list_t *left, alpm_list_t *right, alpm_list_fn_cmp fn)
-{
- alpm_list_t *newlist, *lp;
-
- if (left == NULL && right == NULL)
- return NULL;
-
- if (left == NULL)
- return right;
- if (right == NULL)
- return left;
-
- if (fn (left->data, right->data) <= 0) {
- newlist = left;
- left = left->next;
- } else {
- newlist = right;
- right = right->next;
- }
-
- newlist->prev = NULL;
- newlist->next = NULL;
- lp = newlist;
-
- while ((left != NULL) && (right != NULL)) {
- if (fn (left->data, right->data) <= 0) {
- lp->next = left;
- left->prev = lp;
- left = left->next;
- } else {
- lp->next = right;
- right->prev = lp;
- right = right->next;
- }
- lp = lp->next;
- lp->next = NULL;
- }
-
- if (left != NULL) {
- lp->next = left;
- left->prev = lp;
- } else if (right != NULL) {
- lp->next = right;
- right->prev = lp;
- }
- return(newlist);
-}
-
-alpm_list_t *
my_list_remove_node (alpm_list_t *node)
{
if (!node)
@@ -203,16 +161,11 @@ pkg_equals_to (pmpkg_t *pkg, const gchar *name, const gchar *version)
return TRUE;
}
-
-static int
-list_cmp_fn (const void *n1, const void *n2)
-{
- return 0;
-}
-
static void
add_package (PkBackend *backend, PackageSource *package)
{
+ pk_debug ("add_package: hi, package_name=%s", alpm_pkg_get_name(package->pkg));
+
PkInfoEnum info;
gchar *pkg_string;
gchar *arch = (gchar *) alpm_pkg_get_arch (package->pkg);
@@ -236,6 +189,9 @@ add_packages_from_list (PkBackend *backend, alpm_list_t *list)
PackageSource *package = NULL;
alpm_list_t *li = NULL;
+ if (list == NULL)
+ pk_warning ("add_packages_from_list: list is empty!");
+
for (li = list; li != NULL; li = alpm_list_next (li)) {
package = (PackageSource *) li->data;
add_package (backend, package);
@@ -250,49 +206,30 @@ find_packages_by_desc (const gchar *name, pmdb_t *db)
alpm_list_t *needle = NULL;
alpm_list_t *result = NULL;
- alpm_list_t *localresult = NULL;
- pmdb_t *localdb = NULL;
- const gchar *dbname = NULL;
+ alpm_list_t *query_result = NULL;
+ // determine if repository is local
+ gboolean repo_is_local = (db == alpm_option_get_localdb ());
+ // determine repository name
+ const gchar *repo = alpm_db_get_name (db);
+ // set search term
needle = alpm_list_add (needle, (gchar *) name);
- dbname = alpm_db_get_name (db);
- localdb = alpm_option_get_localdb ();
-
- alpm_list_t *i = NULL;
-
- if (db != localdb) {
- if (localdb != NULL)
- localresult = alpm_db_search (localdb, needle);
- }
+ // execute query
+ query_result = alpm_db_search (db, needle);
- result = alpm_db_search (db, needle);
- for (i = result; i; i = alpm_list_next (i)) {
+ alpm_list_t *iterator;
+ for (iterator = query_result; iterator; iterator = alpm_list_next (iterator)) {
PackageSource *source = g_malloc (sizeof (PackageSource));
- source->pkg = (pmpkg_t *) i->data;
- source->repo = (gchar *) dbname;
-
- if (localresult != NULL) {
- alpm_list_t *icmp = NULL;
- for (icmp = localresult; icmp; icmp = alpm_list_next (icmp))
- if (pkg_equal ((pmpkg_t *) icmp->data, (pmpkg_t *) i->data))
- source->installed = TRUE;
- else
- source->installed = FALSE;
- } else if (localdb == db)
- source->installed = TRUE;
- else
- source->installed = FALSE;
-
- i->data = source;
- }
+ source->pkg = (pmpkg_t *) alpm_list_getdata(iterator);
+ source->repo = (gchar *) repo;
+ source->installed = repo_is_local;
- alpm_list_free (needle);
- if (localresult != NULL) {
- // alpm_list_free_inner (localresult, (alpm_list_fn_free) alpm_pkg_free);
- alpm_list_free(localresult);
+ result = alpm_list_add (result, (PackageSource *) source);
}
+ alpm_list_free (query_result);
+ alpm_list_free (needle);
return result;
}
@@ -325,29 +262,6 @@ pkg_is_installed (const gchar *name, const gchar *version)
return FALSE;
}
-static void
-filter_packages_installed (alpm_list_t *packages, gboolean filter)
-{
- alpm_list_t *i;
- for (i = packages; i; ) {
- if (((PackageSource *) i->data)->installed == filter) {
- alpm_list_t *temp = i;
- i = alpm_list_next (i);
- package_source_free ((PackageSource *) temp->data);
- my_list_remove_node (temp);
- continue;
- }
- i = alpm_list_next (i);
- }
-}
-
-/*
-static void
-filter_packages_multiavail (alpm_list_t *packages, gboolean)
-{
-}
-*/
-
/**
* backend_destroy:
*/
@@ -481,11 +395,11 @@ parse_config (const char *file, const char *givensection, pmdb_t * const givendb
pmdb_t *db = NULL;
/* set default options */
- alpm_option_set_root ("/");
- alpm_option_set_dbpath ("/var/lib/pacman");
- alpm_option_add_cachedir ("/var/cache/pacman/pkg");
- alpm_option_set_logfile ("/var/log/pacman.log");
- alpm_option_set_xfercommand ("/usr/bin/wget --passive-ftp -c -O %%o %%u");
+ alpm_option_set_root (ALPM_ROOT);
+ alpm_option_set_dbpath (ALPM_DBPATH);
+ alpm_option_add_cachedir (ALPM_CACHEDIR);
+ alpm_option_set_logfile (ALPM_LOGFILE);
+ alpm_option_set_xfercommand (ALPM_XFERCOMMAND);
fp = fopen(file, "r");
if (fp == NULL) {
@@ -692,7 +606,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
// Next generation code?
/*
for (; syncdbs; syncdbs = alpm_list_next (syncdbs))
- result = my_list_mmerge (result, find_packages_by_desc (id->name, (pmdb_t *) syncdbs->data), list_cmp_fn);
+ result = alpm_list_join (result, find_packages_by_desc (id->name, (pmdb_t *) syncdbs->data));
if (result == NULL) {
pk_backend_error_code (backend,
@@ -862,9 +776,8 @@ backend_resolve (PkBackend *backend, PkFilterEnum filters, const gchar *package)
}
pmpkg_t *pkg = ((PackageSource *) result->data)->pkg;
- // l is for "local"
pk_backend_package (backend, PK_INFO_ENUM_INSTALLED,
- pk_package_id_build (alpm_pkg_get_name (pkg), alpm_pkg_get_version (pkg), alpm_pkg_get_arch (pkg), "l"),
+ pk_package_id_build (alpm_pkg_get_name (pkg), alpm_pkg_get_version (pkg), alpm_pkg_get_arch (pkg), "local"),
alpm_pkg_get_desc (pkg));
alpm_list_free_inner (result, (alpm_list_fn_free) package_source_free);
@@ -918,61 +831,59 @@ backend_remove_package (PkBackend *backend, const gchar *package_id, gboolean al
}
/**
- * backend_search_name:
+ * backend_search_details:
*/
static void
-backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search)
+backend_search_details (PkBackend *backend, PkFilterEnum filters, const gchar *search)
{
g_return_if_fail (backend != NULL);
alpm_list_t *result = NULL;
- alpm_list_t *localresult = NULL;
- alpm_list_t *dbs = NULL;
+ alpm_list_t *repos = NULL;
+
+ pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
gboolean installed = pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED);
gboolean ninstalled = pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED);
- pk_debug ("alpm: searching for \"%s\" - searching in installed: %i, ~installed: %i",
- search, installed, ninstalled);
-
- if (installed && !ninstalled)
- dbs = alpm_list_add (dbs, alpm_option_get_localdb ());
- if (ninstalled)
- dbs = my_list_mmerge (dbs, alpm_option_get_syncdbs (), list_cmp_fn);
-
- for (; dbs; dbs = alpm_list_next (dbs))
- result = my_list_mmerge (result,
- find_packages_by_desc (search, (pmdb_t *) dbs->data), list_cmp_fn);
-
- if (ninstalled && installed) {
- pmdb_t *localdb = alpm_option_get_localdb ();
- if (localdb != NULL) {
- localresult = find_packages_by_desc (search, localdb);
-
- alpm_list_t *i = NULL;
- for (i = alpm_list_first (result); i; i = alpm_list_next (i)) {
- alpm_list_t *icmp = NULL;
- for (icmp = localresult; icmp; )
- if (pkg_equal ((pmpkg_t *) icmp->data, (pmpkg_t *) i->data)) {
- alpm_list_t *tmp = icmp;
- icmp = alpm_list_next (icmp);
- my_list_remove_node (tmp);
- } else
- icmp = alpm_list_next (icmp);
- }
- } else
- pk_backend_error_code (backend, PK_ERROR_ENUM_INTERNAL_ERROR,
- "Could not find local db");
+ if (!ninstalled)
+ repos = alpm_list_add (repos, alpm_option_get_localdb ());
+ if (!installed)
+ repos = alpm_list_join (repos, alpm_list_copy(alpm_option_get_syncdbs ()));
- result = my_list_mmerge (result, localresult, list_cmp_fn);
- }
+ alpm_list_t *iterator;
+ for (iterator = repos; iterator; iterator = alpm_list_next (iterator))
+ result = alpm_list_join (result, find_packages_by_desc (search, (pmdb_t *) alpm_list_getdata(iterator)));
+
+ add_packages_from_list (backend, alpm_list_first (result));
+
+ alpm_list_free_inner (result, (alpm_list_fn_free) package_source_free);
+ alpm_list_free (result);
+
+ alpm_list_free (repos);
+ pk_backend_finished (backend);
+}
+
+/**
+ * backend_search_name:
+ */
+static void
+backend_search_name (PkBackend *backend, PkFilterEnum filters, const gchar *search) {
+ g_return_if_fail (backend != NULL);
+
+ alpm_list_t *repos = NULL;
+
+ pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);
+
+ gboolean installed = pk_enums_contain (filters, PK_FILTER_ENUM_INSTALLED);
+ gboolean ninstalled = pk_enums_contain (filters, PK_FILTER_ENUM_NOT_INSTALLED);
- if (!installed)
- filter_packages_installed (result, TRUE);
if (!ninstalled)
- filter_packages_installed (result, FALSE);
+ repos = alpm_list_add (repos, alpm_option_get_localdb ());
+ if (!installed)
+ repos = alpm_list_join (repos, alpm_list_copy(alpm_option_get_syncdbs ()));
- add_packages_from_list (backend, alpm_list_first (result));
+ alpm_list_free (repos);
pk_backend_finished (backend);
}
@@ -1000,7 +911,7 @@ backend_get_filters (PkBackend *backend)
}
static void
-backend_install_file (PkBackend *backend, gboolean trusted, const gchar *path)
+backend_install_file (PkBackend *backend, const gchar *path)
{
g_return_if_fail (backend != NULL);
@@ -1056,8 +967,7 @@ backend_get_repo_list (PkBackend *backend, PkFilterEnum filters)
repos = alpm_list_first (repos);
while (repos != NULL) {
pmdb_t *db = alpm_list_getdata (repos);
- pk_backend_repo_detail (backend, alpm_db_get_name (db),
- alpm_db_get_url (db), TRUE);
+ pk_backend_repo_detail (backend, alpm_db_get_name (db), alpm_db_get_url (db), TRUE);
repos = alpm_list_next (repos);
}
@@ -1090,7 +1000,7 @@ PK_BACKEND_OPTIONS (
NULL, /* repo_set_data */
backend_resolve, /* resolve */
NULL, /* rollback */
- NULL, /* search_details */
+ backend_search_details, /* search_details */
NULL, /* search_file */
NULL, /* search_group */
backend_search_name, /* search_name */
commit 87ed407beb9f84c3039e62bd4b79ebff9f6147a3
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 13:35:21 2008 +0100
rename the PkRestart files (harder) to PkFileMonitor and make it a generic object that can be reused
diff --git a/src/pk-file-monitor-dummy.c b/src/pk-file-monitor-dummy.c
index 35d3dff..9d45f5f 100644
--- a/src/pk-file-monitor-dummy.c
+++ b/src/pk-file-monitor-dummy.c
@@ -37,85 +37,93 @@
#include <glib/gi18n.h>
#include <pk-common.h>
#include <pk-debug.h>
-#include "pk-restart.h"
+#include "pk-file-monitor.h"
-static void pk_restart_class_init (PkRestartClass *klass);
-static void pk_restart_init (PkRestart *restart);
-static void pk_restart_finalize (GObject *object);
+static void pk_file_monitor_class_init (PkFileMonitorClass *klass);
+static void pk_file_monitor_init (PkFileMonitor *file_monitor);
+static void pk_file_monitor_finalize (GObject *object);
-#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
+#define PK_FILE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_FILE_MONITOR, PkFileMonitorPrivate))
-struct PkRestartPrivate
+struct PkFileMonitorPrivate
{
gboolean dummy;
};
enum {
- PK_RESTART_SCHEDULE,
- PK_RESTART_LAST_SIGNAL
+ PK_FILE_MONITOR_CHANGED,
+ PK_FILE_MONITOR_LAST_SIGNAL
};
-static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
+static guint signals [PK_FILE_MONITOR_LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
+G_DEFINE_TYPE (PkFileMonitor, pk_file_monitor, G_TYPE_OBJECT)
/**
- * pk_restart_class_init:
- * @klass: The PkRestartClass
+ * pk_file_monitor_class_init:
+ * @klass: The PkFileMonitorClass
**/
static void
-pk_restart_class_init (PkRestartClass *klass)
+pk_file_monitor_class_init (PkFileMonitorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_restart_finalize;
+ object_class->finalize = pk_file_monitor_finalize;
- signals [PK_RESTART_SCHEDULE] =
- g_signal_new ("restart-schedule",
+ signals [PK_FILE_MONITOR_CHANGED] =
+ g_signal_new ("file-changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
-
- g_type_class_add_private (klass, sizeof (PkRestartPrivate));
+ g_type_class_add_private (klass, sizeof (PkFileMonitorPrivate));
}
/**
- * pk_restart_init:
- * @restart: This class instance
+ * pk_file_monitor_init:
+ * @file_monitor: This class instance
**/
static void
-pk_restart_init (PkRestart *restart)
+pk_file_monitor_init (PkFileMonitor *file_monitor)
+{
+ file_monitor->priv = PK_FILE_MONITOR_GET_PRIVATE (file_monitor);
+}
+
+/**
+ * pk_file_monitor_set_file:
+ **/
+gboolean
+pk_file_monitor_set_file (PkFileMonitor *file_monitor, const gchar *filename)
{
- restart->priv = PK_RESTART_GET_PRIVATE (restart);
+ return TRUE;
}
/**
- * pk_restart_finalize:
+ * pk_file_monitor_finalize:
* @object: The object to finalize
**/
static void
-pk_restart_finalize (GObject *object)
+pk_file_monitor_finalize (GObject *object)
{
- PkRestart *restart;
+ PkFileMonitor *file_monitor;
- g_return_if_fail (PK_IS_RESTART (object));
+ g_return_if_fail (PK_IS_FILE_MONITOR (object));
- restart = PK_RESTART (object);
- g_return_if_fail (restart->priv != NULL);
+ file_monitor = PK_FILE_MONITOR (object);
+ g_return_if_fail (file_monitor->priv != NULL);
- G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
+ G_OBJECT_CLASS (pk_file_monitor_parent_class)->finalize (object);
}
/**
- * pk_restart_new:
+ * pk_file_monitor_new:
*
- * Return value: a new PkRestart object.
+ * Return value: a new PkFileMonitor object.
**/
-PkRestart *
-pk_restart_new (void)
+PkFileMonitor *
+pk_file_monitor_new (void)
{
- PkRestart *restart;
- restart = g_object_new (PK_TYPE_RESTART, NULL);
- return PK_RESTART (restart);
+ PkFileMonitor *file_monitor;
+ file_monitor = g_object_new (PK_TYPE_FILE_MONITOR, NULL);
+ return PK_FILE_MONITOR (file_monitor);
}
/***************************************************************************
@@ -125,23 +133,23 @@ pk_restart_new (void)
#include <libselftest.h>
void
-libst_restart (LibSelfTest *test)
+libst_file_monitor (LibSelfTest *test)
{
- PkRestart *restart;
+ PkFileMonitor *file_monitor;
- if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
+ if (libst_start (test, "PkFileMonitor", CLASS_AUTO) == FALSE) {
return;
}
/************************************************************/
- libst_title (test, "get a restart");
- restart = pk_restart_new ();
- if (restart != NULL) {
+ libst_title (test, "get a file_monitor");
+ file_monitor = pk_file_monitor_new ();
+ if (file_monitor != NULL) {
libst_success (test, NULL);
} else {
libst_failed (test, NULL);
}
- g_object_unref (restart);
+ g_object_unref (file_monitor);
libst_end (test);
}
diff --git a/src/pk-file-monitor-gio.c b/src/pk-file-monitor-gio.c
index d66e724..9f56b51 100644
--- a/src/pk-file-monitor-gio.c
+++ b/src/pk-file-monitor-gio.c
@@ -39,15 +39,16 @@
#include <pk-common.h>
#include <pk-debug.h>
#include "pk-conf.h"
-#include "pk-restart.h"
+#include "pk-file-monitor.h"
-static void pk_restart_class_init (PkRestartClass *klass);
-static void pk_restart_init (PkRestart *restart);
-static void pk_restart_finalize (GObject *object);
+static void pk_file_monitor_class_init (PkFileMonitorClass *klass);
+static void pk_file_monitor_init (PkFileMonitor *file_monitor);
+static void pk_file_monitor_finalize (GObject *object);
-#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
+#define PK_FILE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_FILE_MONITOR, PkFileMonitorPrivate))
+#define PK_FILE_MONITOR_RATE_LIMIT 1000
-struct PkRestartPrivate
+struct PkFileMonitorPrivate
{
GString *stdout_buf;
GFileMonitor *monitor;
@@ -55,114 +56,122 @@ struct PkRestartPrivate
};
enum {
- PK_RESTART_SCHEDULE,
- PK_RESTART_LAST_SIGNAL
+ PK_FILE_MONITOR_CHANGED,
+ PK_FILE_MONITOR_LAST_SIGNAL
};
-static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
+static guint signals [PK_FILE_MONITOR_LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
+G_DEFINE_TYPE (PkFileMonitor, pk_file_monitor, G_TYPE_OBJECT)
/**
- * pk_restart_class_init:
- * @klass: The PkRestartClass
+ * pk_file_monitor_class_init:
+ * @klass: The PkFileMonitorClass
**/
static void
-pk_restart_class_init (PkRestartClass *klass)
+pk_file_monitor_class_init (PkFileMonitorClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_restart_finalize;
+ object_class->finalize = pk_file_monitor_finalize;
- signals [PK_RESTART_SCHEDULE] =
- g_signal_new ("restart-schedule",
+ signals [PK_FILE_MONITOR_CHANGED] =
+ g_signal_new ("file-changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
- g_type_class_add_private (klass, sizeof (PkRestartPrivate));
+ g_type_class_add_private (klass, sizeof (PkFileMonitorPrivate));
}
/**
- * pk_restart_monitor_changed:
- * @restart: This class instance
+ * pk_file_monitor_monitor_changed:
+ * @file_monitor: This class instance
**/
static void
-pk_restart_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file,
- GFileMonitorEvent event_type, PkRestart *restart)
+pk_file_monitor_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file,
+ GFileMonitorEvent event_type, PkFileMonitor *file_monitor)
{
- pk_debug ("emit: restart-schedule");
- g_signal_emit (restart, signals [PK_RESTART_SCHEDULE], 0);
+ pk_debug ("emit: file-changed");
+ g_signal_emit (file_monitor, signals [PK_FILE_MONITOR_CHANGED], 0);
}
/**
- * pk_restart_init:
- * @restart: This class instance
+ * pk_file_monitor_set_file:
**/
-static void
-pk_restart_init (PkRestart *restart)
+gboolean
+pk_file_monitor_set_file (PkFileMonitor *file_monitor, const gchar *filename)
{
GError *error = NULL;
- gchar *filename;
- restart->priv = PK_RESTART_GET_PRIVATE (restart);
-
- /* this is the file we are interested in */
- filename = pk_conf_get_filename ();
- if (filename == NULL) {
- pk_warning ("can't get config file");
- goto out;
+
+ if (file_monitor->priv->file != NULL) {
+ pk_warning ("already set file monitor, so can't set %s", filename);
+ return FALSE;
}
- restart->priv->file = g_file_new_for_path (filename);
+
+ /* use a GFile */
+ file_monitor->priv->file = g_file_new_for_path (filename);
/* watch this */
- restart->priv->monitor = g_file_monitor_file (restart->priv->file, G_FILE_MONITOR_NONE, NULL, &error);
- if (restart->priv->monitor == NULL) {
+ file_monitor->priv->monitor = g_file_monitor_file (file_monitor->priv->file, G_FILE_MONITOR_NONE, NULL, &error);
+ if (file_monitor->priv->monitor == NULL) {
pk_warning ("failed to setup watch: %s", error->message);
g_error_free (error);
- goto out;
+ return FALSE;
}
/* we should get notified of changes */
pk_debug ("watching for changes: %s", filename);
- g_file_monitor_set_rate_limit (restart->priv->monitor, 1000);
- g_signal_connect (restart->priv->monitor, "changed",
- G_CALLBACK (pk_restart_monitor_changed), restart);
-out:
- g_free (filename);
+ g_file_monitor_set_rate_limit (file_monitor->priv->monitor, PK_FILE_MONITOR_RATE_LIMIT);
+ g_signal_connect (file_monitor->priv->monitor, "changed",
+ G_CALLBACK (pk_file_monitor_monitor_changed), file_monitor);
+ return TRUE;
+}
+
+/**
+ * pk_file_monitor_init:
+ * @file_monitor: This class instance
+ **/
+static void
+pk_file_monitor_init (PkFileMonitor *file_monitor)
+{
+ file_monitor->priv = PK_FILE_MONITOR_GET_PRIVATE (file_monitor);
+ file_monitor->priv->file = NULL;
+ file_monitor->priv->monitor = NULL;
}
/**
- * pk_restart_finalize:
+ * pk_file_monitor_finalize:
* @object: The object to finalize
**/
static void
-pk_restart_finalize (GObject *object)
+pk_file_monitor_finalize (GObject *object)
{
- PkRestart *restart;
+ PkFileMonitor *file_monitor;
- g_return_if_fail (PK_IS_RESTART (object));
+ g_return_if_fail (PK_IS_FILE_MONITOR (object));
- restart = PK_RESTART (object);
- g_return_if_fail (restart->priv != NULL);
+ file_monitor = PK_FILE_MONITOR (object);
+ g_return_if_fail (file_monitor->priv != NULL);
- g_file_monitor_cancel (restart->priv->monitor);
+ g_file_monitor_cancel (file_monitor->priv->monitor);
- g_object_unref (restart->priv->file);
- g_object_unref (restart->priv->monitor);
+ g_object_unref (file_monitor->priv->file);
+ g_object_unref (file_monitor->priv->monitor);
- G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
+ G_OBJECT_CLASS (pk_file_monitor_parent_class)->finalize (object);
}
/**
- * pk_restart_new:
+ * pk_file_monitor_new:
*
- * Return value: a new PkRestart object.
+ * Return value: a new PkFileMonitor object.
**/
-PkRestart *
-pk_restart_new (void)
+PkFileMonitor *
+pk_file_monitor_new (void)
{
- PkRestart *restart;
- restart = g_object_new (PK_TYPE_RESTART, NULL);
- return PK_RESTART (restart);
+ PkFileMonitor *file_monitor;
+ file_monitor = g_object_new (PK_TYPE_FILE_MONITOR, NULL);
+ return PK_FILE_MONITOR (file_monitor);
}
/***************************************************************************
@@ -172,23 +181,23 @@ pk_restart_new (void)
#include <libselftest.h>
void
-libst_restart (LibSelfTest *test)
+libst_file_monitor (LibSelfTest *test)
{
- PkRestart *restart;
+ PkFileMonitor *file_monitor;
- if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
+ if (libst_start (test, "PkFileMonitor", CLASS_AUTO) == FALSE) {
return;
}
/************************************************************/
- libst_title (test, "get a restart");
- restart = pk_restart_new ();
- if (restart != NULL) {
+ libst_title (test, "get a file_monitor");
+ file_monitor = pk_file_monitor_new ();
+ if (file_monitor != NULL) {
libst_success (test, NULL);
} else {
libst_failed (test, NULL);
}
- g_object_unref (restart);
+ g_object_unref (file_monitor);
libst_end (test);
}
diff --git a/src/pk-file-monitor.h b/src/pk-file-monitor.h
index d1d8f4b..984b373 100644
--- a/src/pk-file-monitor.h
+++ b/src/pk-file-monitor.h
@@ -19,36 +19,39 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#ifndef __PK_RESTART_H
-#define __PK_RESTART_H
+#ifndef __PK_FILE_MONITOR_H
+#define __PK_FILE_MONITOR_H
#include <glib-object.h>
G_BEGIN_DECLS
-#define PK_TYPE_RESTART (pk_restart_get_type ())
-#define PK_RESTART(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_RESTART, PkRestart))
-#define PK_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_RESTART, PkRestartClass))
-#define PK_IS_RESTART(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_RESTART))
-#define PK_IS_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_RESTART))
-#define PK_RESTART_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_RESTART, PkRestartClass))
+#define PK_TYPE_FILE_MONITOR (pk_file_monitor_get_type ())
+#define PK_FILE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_FILE_MONITOR, PkFileMonitor))
+#define PK_FILE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_FILE_MONITOR, PkFileMonitorClass))
+#define PK_IS_FILE_MONITOR(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_FILE_MONITOR))
+#define PK_IS_FILE_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_FILE_MONITOR))
+#define PK_FILE_MONITOR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_FILE_MONITOR, PkFileMonitorClass))
-typedef struct PkRestartPrivate PkRestartPrivate;
+typedef struct PkFileMonitorPrivate PkFileMonitorPrivate;
typedef struct
{
GObject parent;
- PkRestartPrivate *priv;
-} PkRestart;
+ PkFileMonitorPrivate *priv;
+} PkFileMonitor;
typedef struct
{
GObjectClass parent_class;
-} PkRestartClass;
+} PkFileMonitorClass;
-GType pk_restart_get_type (void) G_GNUC_CONST;
-PkRestart *pk_restart_new (void);
+GType pk_file_monitor_get_type (void) G_GNUC_CONST;
+gboolean pk_file_monitor_set_file (PkFileMonitor *file_monitor,
+ const gchar *filename);
+PkFileMonitor *pk_file_monitor_new (void);
G_END_DECLS
-#endif /* __PK_RESTART_H */
+#endif /* __PK_FILE_MONITOR_H */
+
commit 65f99a275149081d5954c5d4e512b3c7521ea2f9
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 13:34:07 2008 +0100
rename the PkRestart file to PkFileMonitor and make it a generic object that can be reused
diff --git a/src/Makefile.am b/src/Makefile.am
index fca3d27..0406be6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -59,7 +59,7 @@ shared_SOURCES = \
pk-notify.h \
pk-spawn.c \
pk-spawn.h \
- pk-restart.h \
+ pk-file-monitor.h \
pk-engine.h \
pk-engine.c \
pk-inhibit.h \
@@ -82,11 +82,11 @@ shared_SOURCES = \
if PK_BUILD_GIO
shared_SOURCES += \
- pk-restart-gio.c \
+ pk-file-monitor-gio.c \
$(NULL)
else
shared_SOURCES += \
- pk-restart-dummy.c \
+ pk-file-monitor-dummy.c \
$(NULL)
endif
diff --git a/src/pk-engine.c b/src/pk-engine.c
index a269699..a63b6e6 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -57,8 +57,9 @@
#include "pk-inhibit.h"
#include "pk-marshal.h"
#include "pk-notify.h"
-#include "pk-restart.h"
+#include "pk-file-monitor.h"
#include "pk-security.h"
+#include "pk-conf.h"
static void pk_engine_class_init (PkEngineClass *klass);
static void pk_engine_init (PkEngine *engine);
@@ -90,7 +91,7 @@ struct PkEnginePrivate
PkNetwork *network;
PkSecurity *security;
PkNotify *notify;
- PkRestart *restart;
+ PkFileMonitor *file_monitor;
PkRoleEnum actions;
PkGroupEnum groups;
PkFilterEnum filters;
@@ -463,10 +464,10 @@ pk_engine_class_init (PkEngineClass *klass)
}
/**
- * pk_engine_restart_schedule_cb:
+ * pk_engine_file_monitor_changed_cb:
**/
static void
-pk_engine_restart_schedule_cb (PkRestart *restart, PkEngine *engine)
+pk_engine_file_monitor_changed_cb (PkFileMonitor *file_monitor, PkEngine *engine)
{
g_return_if_fail (PK_IS_ENGINE (engine));
pk_debug ("setting restart_schedule TRUE");
@@ -481,6 +482,7 @@ pk_engine_init (PkEngine *engine)
{
DBusGConnection *connection;
gboolean ret;
+ gchar *filename;
engine->priv = PK_ENGINE_GET_PRIVATE (engine);
engine->priv->restart_schedule = FALSE;
@@ -528,10 +530,13 @@ pk_engine_init (PkEngine *engine)
g_signal_connect (engine->priv->notify, "updates-changed",
G_CALLBACK (pk_engine_notify_updates_changed_cb), engine);
- /* add the interface */
- engine->priv->restart = pk_restart_new ();
- g_signal_connect (engine->priv->restart, "restart-schedule",
- G_CALLBACK (pk_engine_restart_schedule_cb), engine);
+ /* monitor the config file for changes */
+ engine->priv->file_monitor = pk_file_monitor_new ();
+ filename = pk_conf_get_filename ();
+ pk_file_monitor_set_file (engine->priv->file_monitor, filename);
+ g_signal_connect (engine->priv->file_monitor, "file-changed",
+ G_CALLBACK (pk_engine_file_monitor_changed_cb), engine);
+ g_free (filename);
engine->priv->transaction_list = pk_transaction_list_new ();
g_signal_connect (engine->priv->transaction_list, "changed",
@@ -577,7 +582,7 @@ pk_engine_finalize (GObject *object)
/* compulsory gobjects */
g_timer_destroy (engine->priv->timer);
- g_object_unref (engine->priv->restart);
+ g_object_unref (engine->priv->file_monitor);
g_object_unref (engine->priv->inhibit);
g_object_unref (engine->priv->transaction_list);
g_object_unref (engine->priv->transaction_db);
diff --git a/src/pk-file-monitor-dummy.c b/src/pk-file-monitor-dummy.c
new file mode 100644
index 0000000..35d3dff
--- /dev/null
+++ b/src/pk-file-monitor-dummy.c
@@ -0,0 +1,149 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+#include <signal.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <glib/gi18n.h>
+#include <pk-common.h>
+#include <pk-debug.h>
+#include "pk-restart.h"
+
+static void pk_restart_class_init (PkRestartClass *klass);
+static void pk_restart_init (PkRestart *restart);
+static void pk_restart_finalize (GObject *object);
+
+#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
+
+struct PkRestartPrivate
+{
+ gboolean dummy;
+};
+
+enum {
+ PK_RESTART_SCHEDULE,
+ PK_RESTART_LAST_SIGNAL
+};
+
+static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
+
+/**
+ * pk_restart_class_init:
+ * @klass: The PkRestartClass
+ **/
+static void
+pk_restart_class_init (PkRestartClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_restart_finalize;
+
+ signals [PK_RESTART_SCHEDULE] =
+ g_signal_new ("restart-schedule",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (klass, sizeof (PkRestartPrivate));
+}
+
+/**
+ * pk_restart_init:
+ * @restart: This class instance
+ **/
+static void
+pk_restart_init (PkRestart *restart)
+{
+ restart->priv = PK_RESTART_GET_PRIVATE (restart);
+}
+
+/**
+ * pk_restart_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_restart_finalize (GObject *object)
+{
+ PkRestart *restart;
+
+ g_return_if_fail (PK_IS_RESTART (object));
+
+ restart = PK_RESTART (object);
+ g_return_if_fail (restart->priv != NULL);
+
+ G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
+}
+
+/**
+ * pk_restart_new:
+ *
+ * Return value: a new PkRestart object.
+ **/
+PkRestart *
+pk_restart_new (void)
+{
+ PkRestart *restart;
+ restart = g_object_new (PK_TYPE_RESTART, NULL);
+ return PK_RESTART (restart);
+}
+
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libst_restart (LibSelfTest *test)
+{
+ PkRestart *restart;
+
+ if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
+ return;
+ }
+
+ /************************************************************/
+ libst_title (test, "get a restart");
+ restart = pk_restart_new ();
+ if (restart != NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+ g_object_unref (restart);
+
+ libst_end (test);
+}
+#endif
+
diff --git a/src/pk-file-monitor-gio.c b/src/pk-file-monitor-gio.c
new file mode 100644
index 0000000..d66e724
--- /dev/null
+++ b/src/pk-file-monitor-gio.c
@@ -0,0 +1,196 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.h>
+#include <signal.h>
+
+#include <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <pk-common.h>
+#include <pk-debug.h>
+#include "pk-conf.h"
+#include "pk-restart.h"
+
+static void pk_restart_class_init (PkRestartClass *klass);
+static void pk_restart_init (PkRestart *restart);
+static void pk_restart_finalize (GObject *object);
+
+#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
+
+struct PkRestartPrivate
+{
+ GString *stdout_buf;
+ GFileMonitor *monitor;
+ GFile *file;
+};
+
+enum {
+ PK_RESTART_SCHEDULE,
+ PK_RESTART_LAST_SIGNAL
+};
+
+static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
+
+/**
+ * pk_restart_class_init:
+ * @klass: The PkRestartClass
+ **/
+static void
+pk_restart_class_init (PkRestartClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_restart_finalize;
+
+ signals [PK_RESTART_SCHEDULE] =
+ g_signal_new ("restart-schedule",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ g_type_class_add_private (klass, sizeof (PkRestartPrivate));
+}
+
+/**
+ * pk_restart_monitor_changed:
+ * @restart: This class instance
+ **/
+static void
+pk_restart_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file,
+ GFileMonitorEvent event_type, PkRestart *restart)
+{
+ pk_debug ("emit: restart-schedule");
+ g_signal_emit (restart, signals [PK_RESTART_SCHEDULE], 0);
+}
+
+/**
+ * pk_restart_init:
+ * @restart: This class instance
+ **/
+static void
+pk_restart_init (PkRestart *restart)
+{
+ GError *error = NULL;
+ gchar *filename;
+ restart->priv = PK_RESTART_GET_PRIVATE (restart);
+
+ /* this is the file we are interested in */
+ filename = pk_conf_get_filename ();
+ if (filename == NULL) {
+ pk_warning ("can't get config file");
+ goto out;
+ }
+ restart->priv->file = g_file_new_for_path (filename);
+
+ /* watch this */
+ restart->priv->monitor = g_file_monitor_file (restart->priv->file, G_FILE_MONITOR_NONE, NULL, &error);
+ if (restart->priv->monitor == NULL) {
+ pk_warning ("failed to setup watch: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* we should get notified of changes */
+ pk_debug ("watching for changes: %s", filename);
+ g_file_monitor_set_rate_limit (restart->priv->monitor, 1000);
+ g_signal_connect (restart->priv->monitor, "changed",
+ G_CALLBACK (pk_restart_monitor_changed), restart);
+out:
+ g_free (filename);
+}
+
+/**
+ * pk_restart_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_restart_finalize (GObject *object)
+{
+ PkRestart *restart;
+
+ g_return_if_fail (PK_IS_RESTART (object));
+
+ restart = PK_RESTART (object);
+ g_return_if_fail (restart->priv != NULL);
+
+ g_file_monitor_cancel (restart->priv->monitor);
+
+ g_object_unref (restart->priv->file);
+ g_object_unref (restart->priv->monitor);
+
+ G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
+}
+
+/**
+ * pk_restart_new:
+ *
+ * Return value: a new PkRestart object.
+ **/
+PkRestart *
+pk_restart_new (void)
+{
+ PkRestart *restart;
+ restart = g_object_new (PK_TYPE_RESTART, NULL);
+ return PK_RESTART (restart);
+}
+
+/***************************************************************************
+ *** MAKE CHECK TESTS ***
+ ***************************************************************************/
+#ifdef PK_BUILD_TESTS
+#include <libselftest.h>
+
+void
+libst_restart (LibSelfTest *test)
+{
+ PkRestart *restart;
+
+ if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
+ return;
+ }
+
+ /************************************************************/
+ libst_title (test, "get a restart");
+ restart = pk_restart_new ();
+ if (restart != NULL) {
+ libst_success (test, NULL);
+ } else {
+ libst_failed (test, NULL);
+ }
+ g_object_unref (restart);
+
+ libst_end (test);
+}
+#endif
+
diff --git a/src/pk-file-monitor.h b/src/pk-file-monitor.h
new file mode 100644
index 0000000..d1d8f4b
--- /dev/null
+++ b/src/pk-file-monitor.h
@@ -0,0 +1,54 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __PK_RESTART_H
+#define __PK_RESTART_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_RESTART (pk_restart_get_type ())
+#define PK_RESTART(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_RESTART, PkRestart))
+#define PK_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_RESTART, PkRestartClass))
+#define PK_IS_RESTART(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_RESTART))
+#define PK_IS_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_RESTART))
+#define PK_RESTART_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_RESTART, PkRestartClass))
+
+typedef struct PkRestartPrivate PkRestartPrivate;
+
+typedef struct
+{
+ GObject parent;
+ PkRestartPrivate *priv;
+} PkRestart;
+
+typedef struct
+{
+ GObjectClass parent_class;
+} PkRestartClass;
+
+GType pk_restart_get_type (void) G_GNUC_CONST;
+PkRestart *pk_restart_new (void);
+
+G_END_DECLS
+
+#endif /* __PK_RESTART_H */
diff --git a/src/pk-restart-dummy.c b/src/pk-restart-dummy.c
deleted file mode 100644
index 35d3dff..0000000
--- a/src/pk-restart-dummy.c
+++ /dev/null
@@ -1,149 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <pk-common.h>
-#include <pk-debug.h>
-#include "pk-restart.h"
-
-static void pk_restart_class_init (PkRestartClass *klass);
-static void pk_restart_init (PkRestart *restart);
-static void pk_restart_finalize (GObject *object);
-
-#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
-
-struct PkRestartPrivate
-{
- gboolean dummy;
-};
-
-enum {
- PK_RESTART_SCHEDULE,
- PK_RESTART_LAST_SIGNAL
-};
-
-static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
-
-/**
- * pk_restart_class_init:
- * @klass: The PkRestartClass
- **/
-static void
-pk_restart_class_init (PkRestartClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_restart_finalize;
-
- signals [PK_RESTART_SCHEDULE] =
- g_signal_new ("restart-schedule",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_type_class_add_private (klass, sizeof (PkRestartPrivate));
-}
-
-/**
- * pk_restart_init:
- * @restart: This class instance
- **/
-static void
-pk_restart_init (PkRestart *restart)
-{
- restart->priv = PK_RESTART_GET_PRIVATE (restart);
-}
-
-/**
- * pk_restart_finalize:
- * @object: The object to finalize
- **/
-static void
-pk_restart_finalize (GObject *object)
-{
- PkRestart *restart;
-
- g_return_if_fail (PK_IS_RESTART (object));
-
- restart = PK_RESTART (object);
- g_return_if_fail (restart->priv != NULL);
-
- G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
-}
-
-/**
- * pk_restart_new:
- *
- * Return value: a new PkRestart object.
- **/
-PkRestart *
-pk_restart_new (void)
-{
- PkRestart *restart;
- restart = g_object_new (PK_TYPE_RESTART, NULL);
- return PK_RESTART (restart);
-}
-
-/***************************************************************************
- *** MAKE CHECK TESTS ***
- ***************************************************************************/
-#ifdef PK_BUILD_TESTS
-#include <libselftest.h>
-
-void
-libst_restart (LibSelfTest *test)
-{
- PkRestart *restart;
-
- if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
- return;
- }
-
- /************************************************************/
- libst_title (test, "get a restart");
- restart = pk_restart_new ();
- if (restart != NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, NULL);
- }
- g_object_unref (restart);
-
- libst_end (test);
-}
-#endif
-
diff --git a/src/pk-restart-gio.c b/src/pk-restart-gio.c
deleted file mode 100644
index d66e724..0000000
--- a/src/pk-restart-gio.c
+++ /dev/null
@@ -1,196 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <errno.h>
-#include <signal.h>
-
-#include <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <glib/gi18n.h>
-#include <gio/gio.h>
-#include <pk-common.h>
-#include <pk-debug.h>
-#include "pk-conf.h"
-#include "pk-restart.h"
-
-static void pk_restart_class_init (PkRestartClass *klass);
-static void pk_restart_init (PkRestart *restart);
-static void pk_restart_finalize (GObject *object);
-
-#define PK_RESTART_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_RESTART, PkRestartPrivate))
-
-struct PkRestartPrivate
-{
- GString *stdout_buf;
- GFileMonitor *monitor;
- GFile *file;
-};
-
-enum {
- PK_RESTART_SCHEDULE,
- PK_RESTART_LAST_SIGNAL
-};
-
-static guint signals [PK_RESTART_LAST_SIGNAL] = { 0 };
-
-G_DEFINE_TYPE (PkRestart, pk_restart, G_TYPE_OBJECT)
-
-/**
- * pk_restart_class_init:
- * @klass: The PkRestartClass
- **/
-static void
-pk_restart_class_init (PkRestartClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_restart_finalize;
-
- signals [PK_RESTART_SCHEDULE] =
- g_signal_new ("restart-schedule",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- g_type_class_add_private (klass, sizeof (PkRestartPrivate));
-}
-
-/**
- * pk_restart_monitor_changed:
- * @restart: This class instance
- **/
-static void
-pk_restart_monitor_changed (GFileMonitor *monitor, GFile *file, GFile *other_file,
- GFileMonitorEvent event_type, PkRestart *restart)
-{
- pk_debug ("emit: restart-schedule");
- g_signal_emit (restart, signals [PK_RESTART_SCHEDULE], 0);
-}
-
-/**
- * pk_restart_init:
- * @restart: This class instance
- **/
-static void
-pk_restart_init (PkRestart *restart)
-{
- GError *error = NULL;
- gchar *filename;
- restart->priv = PK_RESTART_GET_PRIVATE (restart);
-
- /* this is the file we are interested in */
- filename = pk_conf_get_filename ();
- if (filename == NULL) {
- pk_warning ("can't get config file");
- goto out;
- }
- restart->priv->file = g_file_new_for_path (filename);
-
- /* watch this */
- restart->priv->monitor = g_file_monitor_file (restart->priv->file, G_FILE_MONITOR_NONE, NULL, &error);
- if (restart->priv->monitor == NULL) {
- pk_warning ("failed to setup watch: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- /* we should get notified of changes */
- pk_debug ("watching for changes: %s", filename);
- g_file_monitor_set_rate_limit (restart->priv->monitor, 1000);
- g_signal_connect (restart->priv->monitor, "changed",
- G_CALLBACK (pk_restart_monitor_changed), restart);
-out:
- g_free (filename);
-}
-
-/**
- * pk_restart_finalize:
- * @object: The object to finalize
- **/
-static void
-pk_restart_finalize (GObject *object)
-{
- PkRestart *restart;
-
- g_return_if_fail (PK_IS_RESTART (object));
-
- restart = PK_RESTART (object);
- g_return_if_fail (restart->priv != NULL);
-
- g_file_monitor_cancel (restart->priv->monitor);
-
- g_object_unref (restart->priv->file);
- g_object_unref (restart->priv->monitor);
-
- G_OBJECT_CLASS (pk_restart_parent_class)->finalize (object);
-}
-
-/**
- * pk_restart_new:
- *
- * Return value: a new PkRestart object.
- **/
-PkRestart *
-pk_restart_new (void)
-{
- PkRestart *restart;
- restart = g_object_new (PK_TYPE_RESTART, NULL);
- return PK_RESTART (restart);
-}
-
-/***************************************************************************
- *** MAKE CHECK TESTS ***
- ***************************************************************************/
-#ifdef PK_BUILD_TESTS
-#include <libselftest.h>
-
-void
-libst_restart (LibSelfTest *test)
-{
- PkRestart *restart;
-
- if (libst_start (test, "PkRestart", CLASS_AUTO) == FALSE) {
- return;
- }
-
- /************************************************************/
- libst_title (test, "get a restart");
- restart = pk_restart_new ();
- if (restart != NULL) {
- libst_success (test, NULL);
- } else {
- libst_failed (test, NULL);
- }
- g_object_unref (restart);
-
- libst_end (test);
-}
-#endif
-
diff --git a/src/pk-restart.h b/src/pk-restart.h
deleted file mode 100644
index d1d8f4b..0000000
--- a/src/pk-restart.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2008 Richard Hughes <richard at hughsie.com>
- *
- * Licensed under the GNU General Public License Version 2
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#ifndef __PK_RESTART_H
-#define __PK_RESTART_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define PK_TYPE_RESTART (pk_restart_get_type ())
-#define PK_RESTART(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_RESTART, PkRestart))
-#define PK_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_RESTART, PkRestartClass))
-#define PK_IS_RESTART(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_RESTART))
-#define PK_IS_RESTART_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_RESTART))
-#define PK_RESTART_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_RESTART, PkRestartClass))
-
-typedef struct PkRestartPrivate PkRestartPrivate;
-
-typedef struct
-{
- GObject parent;
- PkRestartPrivate *priv;
-} PkRestart;
-
-typedef struct
-{
- GObjectClass parent_class;
-} PkRestartClass;
-
-GType pk_restart_get_type (void) G_GNUC_CONST;
-PkRestart *pk_restart_new (void);
-
-G_END_DECLS
-
-#endif /* __PK_RESTART_H */
diff --git a/src/pk-self-test.c b/src/pk-self-test.c
index d0aace7..3573725 100644
--- a/src/pk-self-test.c
+++ b/src/pk-self-test.c
@@ -37,7 +37,7 @@ void libst_backend (LibSelfTest *test);
void libst_backend_spawn (LibSelfTest *test);
void libst_backend_thread (LibSelfTest *test);
void libst_backend_dbus (LibSelfTest *test);
-void libst_restart (LibSelfTest *test);
+void libst_file_monitor (LibSelfTest *test);
void libst_engine (LibSelfTest *test);
int
@@ -53,7 +53,7 @@ main (int argc, char **argv)
pk_debug_init (TRUE);
/* components */
- libst_restart (&test);
+ libst_file_monitor (&test);
libst_security (&test);
libst_time (&test);
libst_conf (&test);
commit 5cec21faccafa224d698a572cdf3545338d1cb31
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 12:42:45 2008 +0100
add the start of a developer FAQ i can point people at
diff --git a/docs/spec/Makefile.am b/docs/spec/Makefile.am
index ccb8818..5c2d013 100644
--- a/docs/spec/Makefile.am
+++ b/docs/spec/Makefile.am
@@ -1,6 +1,8 @@
IMAGE_FILES = \
pk-structure.png \
pk-structure.svg \
+ pk-faq-error-code.png \
+ pk-faq-status.png \
pk-transactions.svg \
pk-transactions-failure.png \
pk-transactions-sig-install.png \
@@ -11,6 +13,7 @@ SPEC_XML_FILES = \
pk-backend-compiled.xml \
pk-backend-dbus.xml \
pk-backend-spawn.xml \
+ pk-developer-faq.xml \
pk-concepts.xml \
pk-introduction.xml \
pk-methods.xml \
diff --git a/docs/spec/pk-developer-faq.xml b/docs/spec/pk-developer-faq.xml
new file mode 100644
index 0000000..eba28eb
--- /dev/null
+++ b/docs/spec/pk-developer-faq.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd">
+
+<chapter id="developer-faq">
+ <title>Developer FAQ</title>
+ <para>
+ The following sections explain frequently asked questions from people creating thier own
+ backend.
+ This list is not exhaustive, but please ask before adding to it.
+ </para>
+
+ <sect1 id="developer-faq-status-signals">
+ <title>Backends should send status signals...</title>
+ <para>
+ If your backend does not set status signals you will get the following dialog:
+ </para>
+ <mediaobject id="pk-faq-status">
+ <imageobject>
+ <imagedata format="PNG" fileref="pk-faq-status.png" align="center"/>
+ </imageobject>
+ </mediaobject>
+ <para>
+ For every transaction, you need to tell the datemon what the backend is doing.
+ You need to add to your backend:
+ </para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ For python: <literal>self.status(STATUS_QUERY)</literal>
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ For compiled C/C++: <literal>pk_backend_set_status (backend, PK_STATUS_ENUM_QUERY);</literal>
+ </para>
+ </listitem>
+ </itemizedlist>
+ <para>
+ You can send as many status calls as you need as the transaction progresses.
+ The more calls you send, the more the UI will reflect what is being done, for instance,
+ showing a downloading icon when <literal>PK_STATUS_ENUM_DOWNLOAD</literal> is used.
+ </para>
+ </sect1>
+
+ <sect1 id="developer-faq-error-code-finished">
+ <title>Finished() after ErrorCode()...</title>
+ <para>
+ If your backend does not send <literal>Finished()</literal> after <literal>ErrorCode()</literal>
+ then the following dialog will be shown.
+ </para>
+ <mediaobject id="pk-faq-error-code">
+ <imageobject>
+ <imagedata format="PNG" fileref="pk-faq-error-code.png" align="center"/>
+ </imageobject>
+ </mediaobject>
+ <para>
+ The daemon recovers automatically, so this warning is not fatal, but the automatic recovery
+ is not cost free.
+ Every time the daemon cleans up a transaction like this, an additional 500ms is added to the
+ transaction duration (to allow slow backends to clean up after themselves) and so the
+ next transaction is delayed from starting.
+ </para>
+ <para>
+ You need to ensure that <literal>Finished()</literal> follows <literal>ErrorCode()</literal>
+ to remove this warning.
+ </para>
+ </sect1>
+
+</chapter>
+
diff --git a/docs/spec/pk-faq-error-code.png b/docs/spec/pk-faq-error-code.png
new file mode 100644
index 0000000..2cccae1
Binary files /dev/null and b/docs/spec/pk-faq-error-code.png differ
diff --git a/docs/spec/pk-faq-status.png b/docs/spec/pk-faq-status.png
new file mode 100644
index 0000000..7c49b9c
Binary files /dev/null and b/docs/spec/pk-faq-status.png differ
diff --git a/docs/spec/pk-reference.xml b/docs/spec/pk-reference.xml
index e38bd94..7a24c81 100644
--- a/docs/spec/pk-reference.xml
+++ b/docs/spec/pk-reference.xml
@@ -36,6 +36,7 @@
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="pk-backend-compiled.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="pk-backend-spawn.xml" />
<xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="pk-backend-dbus.xml" />
+ <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="pk-developer-faq.xml" />
</book>
commit 8464e32b01bd85c675c7cc8075be24e01ad6a2e3
Author: Richard Hughes <richard at hughsie.com>
Date: Wed Apr 23 12:42:05 2008 +0100
make a developer warning less verbose
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 6ba4073..ba480c1 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -1214,16 +1214,7 @@ pk_backend_finished (PkBackend *backend)
if (backend->priv->set_error == FALSE &&
backend->priv->status == PK_STATUS_ENUM_SETUP) {
pk_backend_message (backend, PK_MESSAGE_ENUM_DAEMON,
- "Backends should send status <value> signals for %s!\n"
- "If you are:\n"
- "* Calling out to external tools, the compiled backend "
- "should call pk_backend_set_status() manually.\n"
- "* Using a scripted backend with dumb commands then "
- "this should be set at the start of the runtime call\n"
- " - see helpers/yumBackend.py:self.status()\n"
- "* Using a scripted backend with clever commands then a "
- " callback should use map values into status enums\n"
- " - see helpers/yumBackend.py:self.state_actions", role_text);
+ "Backends should send status <value> signals for %s!", role_text);
pk_warning ("GUI will remain unchanged!");
}
More information about the PackageKit-commit
mailing list