[PackageKit-commit] packagekit: Branch 'master' - 9 commits
Richard Hughes
hughsient at kemper.freedesktop.org
Thu May 1 14:20:28 PDT 2008
backends/yum/pk-backend-yum.c | 10 -
backends/yum2/pk-backend-yum2.c | 10 -
docs/api/PackageKit-docs.sgml | 1
docs/html/pk-faq.html | 62 +++++++++++
etc/PackageKit.conf.in | 17 ++-
libpackagekit/Makefile.am | 14 --
libpackagekit/pk-control.c | 96 ++++++++++++++++-
libpackagekit/pk-control.h | 2
libpackagekit/pk-enum.c | 37 ++++++
libpackagekit/pk-enum.h | 14 ++
libpackagekit/pk-network-dummy.c | 165 ------------------------------
libpackagekit/pk-network-nm.c | 203 ------------------------------------
libpackagekit/pk-network.h | 67 ------------
src/Makefile.am | 15 ++
src/pk-backend.c | 8 +
src/pk-engine.c | 47 +++++++-
src/pk-engine.h | 3
src/pk-interface.xml | 6 +
src/pk-network-nm-dummy.c | 139 +++++++++++++++++++++++++
src/pk-network-nm.c | 185 +++++++++++++++++++++++++++++++++
src/pk-network-nm.h | 68 ++++++++++++
src/pk-network-unix.c | 145 ++++++++++++++++++++++++++
src/pk-network-unix.h | 68 ++++++++++++
src/pk-network.c | 214 +++++++++++++++++++++++++++++++++++++++
src/pk-network.h | 67 ++++++++++++
25 files changed, 1187 insertions(+), 476 deletions(-)
New commits:
commit f8058f6fa65a4eb6dc9ef500fda1c61ee1f62333
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 17:06:35 2008 +0100
fix ake dist
diff --git a/backends/yum/pk-backend-yum.c b/backends/yum/pk-backend-yum.c
index f1f4de5..e6bf0ea 100644
--- a/backends/yum/pk-backend-yum.c
+++ b/backends/yum/pk-backend-yum.c
@@ -19,13 +19,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <pk-network.h>
#include <pk-backend.h>
#include <pk-backend-spawn.h>
#include <pk-package-ids.h>
static PkBackendSpawn *spawn;
-static PkNetwork *network;
/**
* backend_initialize:
@@ -36,7 +34,6 @@ 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, "yum");
}
@@ -51,7 +48,6 @@ backend_destroy (PkBackend *backend)
g_return_if_fail (backend != NULL);
g_return_if_fail (spawn != NULL);
pk_debug ("FILTER: destroy");
- g_object_unref (network);
g_object_unref (spawn);
}
@@ -221,7 +217,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
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;
@@ -266,7 +262,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
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;
@@ -354,7 +350,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
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;
diff --git a/backends/yum2/pk-backend-yum2.c b/backends/yum2/pk-backend-yum2.c
index 39d450b..53836c7 100644
--- a/backends/yum2/pk-backend-yum2.c
+++ b/backends/yum2/pk-backend-yum2.c
@@ -19,12 +19,10 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
-#include <pk-network.h>
#include <pk-backend.h>
#include <pk-backend-dbus.h>
static PkBackendDbus *dbus;
-static PkNetwork *network;
#define PK_DBUS_BACKEND_SERVICE_YUM "org.freedesktop.PackageKitYumBackend"
@@ -37,7 +35,6 @@ backend_initialize (PkBackend *backend)
{
g_return_if_fail (backend != NULL);
pk_debug ("FILTER: initialize");
- network = pk_network_new ();
dbus = pk_backend_dbus_new ();
pk_backend_dbus_set_name (dbus, PK_DBUS_BACKEND_SERVICE_YUM);
}
@@ -52,7 +49,6 @@ backend_destroy (PkBackend *backend)
g_return_if_fail (backend != NULL);
g_return_if_fail (dbus != NULL);
pk_debug ("FILTER: destroy");
- g_object_unref (network);
pk_backend_dbus_kill (dbus);
g_object_unref (dbus);
}
@@ -186,7 +182,7 @@ backend_install_package (PkBackend *backend, const gchar *package_id)
g_return_if_fail (dbus != 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;
@@ -216,7 +212,7 @@ backend_refresh_cache (PkBackend *backend, gboolean force)
g_return_if_fail (dbus != 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;
@@ -290,7 +286,7 @@ backend_update_packages (PkBackend *backend, gchar **package_ids)
g_return_if_fail (dbus != 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;
diff --git a/docs/api/PackageKit-docs.sgml b/docs/api/PackageKit-docs.sgml
index 601074f..61eb8cc 100644
--- a/docs/api/PackageKit-docs.sgml
+++ b/docs/api/PackageKit-docs.sgml
@@ -21,7 +21,6 @@
<xi:include href="xml/pk-polkit-client.xml"/>
<xi:include href="xml/pk-extra.xml"/>
<xi:include href="xml/pk-client.xml"/>
- <xi:include href="xml/pk-network.xml"/>
<xi:include href="xml/pk-package-list.xml"/>
<xi:include href="xml/pk-control.xml"/>
<xi:include href="xml/pk-task-list.xml"/>
commit 71ae7f2a09bccc14467f363da5e3664b1fdb8ab3
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 17:02:25 2008 +0100
get the default parameters from the config file, rather than hardcoding it
diff --git a/src/pk-network.c b/src/pk-network.c
index 32c91a3..9656958 100644
--- a/src/pk-network.c
+++ b/src/pk-network.c
@@ -47,6 +47,7 @@
#include "pk-network-nm.h"
#include "pk-network-unix.h"
#include "pk-marshal.h"
+#include "pk-conf.h"
static void pk_network_class_init (PkNetworkClass *klass);
static void pk_network_init (PkNetwork *network);
@@ -65,6 +66,7 @@ struct _PkNetworkPrivate
gboolean use_unix;
PkNetworkNm *net_nm;
PkNetworkUnix *net_unix;
+ PkConf *conf;
};
enum {
@@ -153,8 +155,7 @@ static void
pk_network_init (PkNetwork *network)
{
network->priv = PK_NETWORK_GET_PRIVATE (network);
- network->priv->use_nm = TRUE;
- network->priv->use_unix = TRUE;
+ network->priv->conf = pk_conf_new ();
network->priv->net_nm = pk_network_nm_new ();
g_signal_connect (network->priv->net_nm, "state-changed",
G_CALLBACK (pk_network_nm_network_changed_cb), network);
@@ -162,9 +163,16 @@ pk_network_init (PkNetwork *network)
g_signal_connect (network->priv->net_unix, "state-changed",
G_CALLBACK (pk_network_unix_network_changed_cb), network);
+ /* get the defaults from the config file */
+ network->priv->use_nm = pk_conf_get_bool (network->priv->conf, "UseNetworkManager");
+ network->priv->use_unix = pk_conf_get_bool (network->priv->conf, "UseNetworkHeuristic");
+
#if !PK_BUILD_NETWORKMANAGER
- /* hardcode */
- network->priv->use_nm = FALSE;
+ /* check we can actually use the default */
+ if (network->priv->use_nm) {
+ pk_warning ("UseNetworkManager true, but not built with NM support");
+ network->priv->use_nm = FALSE;
+ }
#endif
}
@@ -181,6 +189,7 @@ pk_network_finalize (GObject *object)
network = PK_NETWORK (object);
g_return_if_fail (network->priv != NULL);
+ g_object_unref (network->priv->conf);
g_object_unref (network->priv->net_nm);
g_object_unref (network->priv->net_unix);
G_OBJECT_CLASS (pk_network_parent_class)->finalize (object);
commit ee46ebd91e28968e1ea077a21b20de848d5506e2
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 17:01:08 2008 +0100
protect against running an old daemon with new client tools
diff --git a/libpackagekit/pk-control.c b/libpackagekit/pk-control.c
index b4e9ea4..f2de5ae 100644
--- a/libpackagekit/pk-control.c
+++ b/libpackagekit/pk-control.c
@@ -421,6 +421,7 @@ gboolean
pk_control_allocate_transaction_id (PkControl *control, gchar **tid, GError **error)
{
gboolean ret;
+ gchar *tid_local = NULL;
g_return_val_if_fail (PK_IS_CONTROL (control), FALSE);
@@ -431,13 +432,25 @@ pk_control_allocate_transaction_id (PkControl *control, gchar **tid, GError **er
}
ret = dbus_g_proxy_call (control->priv->proxy, "GetTid", error,
G_TYPE_INVALID,
- G_TYPE_STRING, tid,
+ G_TYPE_STRING, &tid_local,
G_TYPE_INVALID);
if (!ret) {
pk_control_error_fixup (error);
- return FALSE;
+ goto out;
+ }
+
+ /* check we are not running new client tools with an old server */
+ if (g_strrstr (tid_local, ";") != NULL) {
+ pk_control_error_set (error, PK_CONTROL_ERROR_FAILED, "Incorrect path with ';' returned!");
+ ret = FALSE;
+ goto out;
}
- pk_debug ("Got tid: '%s'", *tid);
+
+ /* copy */
+ *tid = g_strdup (tid_local);
+ pk_debug ("Got tid: '%s'", tid_local);
+out:
+ g_free (tid_local);
return ret;
}
commit 49eeedfdeedaebbae4d0e71f9ffeca12903c968e
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 16:48:43 2008 +0100
move PkNetwork into src (as it can use the dbus interface) and make building a unix backend to fallback to for NM missing
diff --git a/libpackagekit/Makefile.am b/libpackagekit/Makefile.am
index d33bc36..6b8c6b8 100644
--- a/libpackagekit/Makefile.am
+++ b/libpackagekit/Makefile.am
@@ -4,7 +4,6 @@ NULL =
INCLUDES = \
$(GLIB_CFLAGS) \
$(DBUS_CFLAGS) \
- $(LIBNM_CFLAGS) \
$(SQLITE_CFLAGS) \
-I$(top_srcdir)/libpackagekit \
-I$(top_srcdir)/libgbus \
@@ -36,7 +35,6 @@ libpackagekit_include_HEADERS = \
pk-debug.h \
pk-extra.h \
pk-connection.h \
- pk-network.h \
pk-package-id.h \
pk-package-ids.h \
pk-package-list.h \
@@ -57,7 +55,6 @@ libpackagekit_la_SOURCES = \
pk-extra.h \
pk-connection.c \
pk-connection.h \
- pk-network.h \
pk-package-id.c \
pk-package-id.h \
pk-package-ids.c \
@@ -78,21 +75,10 @@ libpackagekit_la_SOURCES = \
pk-polkit-client.h \
$(NULL)
-if PK_BUILD_NETWORKMANAGER
-libpackagekit_la_SOURCES += \
- pk-network-nm.c \
- $(NULL)
-else
-libpackagekit_la_SOURCES += \
- pk-network-dummy.c \
- $(NULL)
-endif
-
libpackagekit_la_LIBADD = \
$(GLIB_LIBS) \
$(DBUS_LIBS) \
$(GBUS_LIBS) \
- $(LIBNM_LIBS) \
$(SQLITE_LIBS) \
$(NULL)
diff --git a/libpackagekit/pk-network-dummy.c b/libpackagekit/pk-network-dummy.c
deleted file mode 100644
index 1a64d5a..0000000
--- a/libpackagekit/pk-network-dummy.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 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.
- */
-
-/**
- * SECTION:pk-network-dummy
- * @short_description: Dummy network detection code
- *
- * This file contains a dummy network implimentation.
- * It is designed for people that don't have NetworkManager installed.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <time.h>
-#include <errno.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-debug.h"
-#include "pk-network.h"
-#include "pk-marshal.h"
-
-static void pk_network_class_init (PkNetworkClass *klass);
-static void pk_network_init (PkNetwork *network);
-static void pk_network_finalize (GObject *object);
-
-#define PK_NETWORK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK, PkNetworkPrivate))
-
-/**
- * _PkNetworkPrivate:
- *
- * Private #PkNetwork data
- **/
-struct _PkNetworkPrivate
-{
- gpointer data;
-};
-
-enum {
- PK_NETWORK_ONLINE,
- PK_NETWORK_LAST_SIGNAL
-};
-
-static guint signals [PK_NETWORK_LAST_SIGNAL] = { 0 };
-static gpointer pk_network_object = NULL;
-
-G_DEFINE_TYPE (PkNetwork, pk_network, G_TYPE_OBJECT)
-
-/**
- * pk_network_is_online:
- * @network: a valid #PkNetwork instance
- *
- * Return value: %TRUE if the network is online
- * Note: This is a dummy file and no checks are done
- **/
-gboolean
-pk_network_is_online (PkNetwork *network)
-{
- g_return_val_if_fail (PK_IS_NETWORK (network), FALSE);
- /* don't do any checks */
- return TRUE;
-}
-
-/**
- * pk_network_is_modem:
- * @network: a valid #PkNetwork instance
- *
- * Return value: %TRUE if the network is a modem, on a slow or expensive connection
- **/
-gboolean
-pk_network_is_modem (PkNetwork *network)
-{
- g_return_val_if_fail (PK_IS_NETWORK (network), FALSE);
- /* don't do any checks */
- return TRUE;
-}
-
-
-/**
- * pk_network_class_init:
- * @klass: The PkNetworkClass
- **/
-static void
-pk_network_class_init (PkNetworkClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_network_finalize;
- signals [PK_NETWORK_ONLINE] =
- g_signal_new ("online",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- g_type_class_add_private (klass, sizeof (PkNetworkPrivate));
-}
-
-/**
- * pk_network_init:
- * @network: This class instance
- **/
-static void
-pk_network_init (PkNetwork *network)
-{
- network->priv = PK_NETWORK_GET_PRIVATE (network);
-}
-
-/**
- * pk_network_finalize:
- * @object: The object to finalize
- **/
-static void
-pk_network_finalize (GObject *object)
-{
- PkNetwork *network;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_NETWORK (object));
- network = PK_NETWORK (object);
-
- g_return_if_fail (network->priv != NULL);
- G_OBJECT_CLASS (pk_network_parent_class)->finalize (object);
-}
-
-/**
- * pk_network_new:
- *
- * Return value: a new PkNetwork object.
- **/
-PkNetwork *
-pk_network_new (void)
-{
- if (pk_network_object != NULL) {
- g_object_ref (pk_network_object);
- } else {
- pk_network_object = g_object_new (PK_TYPE_NETWORK, NULL);
- g_object_add_weak_pointer (pk_network_object, &pk_network_object);
- }
- return PK_NETWORK (pk_network_object);
-}
-
diff --git a/libpackagekit/pk-network-nm.c b/libpackagekit/pk-network-nm.c
deleted file mode 100644
index e3ac25a..0000000
--- a/libpackagekit/pk-network-nm.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 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 <string.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
-
-#include <sys/wait.h>
-#include <fcntl.h>
-
-#include <glib/gi18n.h>
-#include <libnm_glib.h>
-
-#include "pk-debug.h"
-#include "pk-network.h"
-#include "pk-marshal.h"
-
-static void pk_network_class_init (PkNetworkClass *klass);
-static void pk_network_init (PkNetwork *network);
-static void pk_network_finalize (GObject *object);
-
-#define PK_NETWORK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK, PkNetworkPrivate))
-
-/**
- * PkNetworkPrivate:
- *
- * Private #PkNetwork data
- **/
-struct _PkNetworkPrivate
-{
- libnm_glib_ctx *ctx;
- guint callback_id;
-};
-
-enum {
- PK_NETWORK_ONLINE,
- PK_NETWORK_LAST_SIGNAL
-};
-
-static guint signals [PK_NETWORK_LAST_SIGNAL] = { 0 };
-static gpointer pk_network_object = NULL;
-
-G_DEFINE_TYPE (PkNetwork, pk_network, G_TYPE_OBJECT)
-
-/**
- * pk_network_is_online:
- * @network: a valid #PkNetwork instance
- *
- * Return value: %TRUE if the network is online
- **/
-gboolean
-pk_network_is_online (PkNetwork *network)
-{
- libnm_glib_state state;
- gboolean ret;
-
- g_return_val_if_fail (PK_IS_NETWORK (network), FALSE);
-
- state = libnm_glib_get_network_state (network->priv->ctx);
- switch (state) {
- case LIBNM_NO_NETWORK_CONNECTION:
- ret = FALSE;
- break;
- default:
- ret = TRUE;
- }
- return ret;
-}
-
-/**
- * pk_network_is_modem:
- * @network: a valid #PkNetwork instance
- *
- * Return value: %TRUE if the network is a modem, on a slow or expensive connection
- **/
-gboolean
-pk_network_is_modem (PkNetwork *network)
-{
- g_return_val_if_fail (PK_IS_NETWORK (network), FALSE);
- return TRUE;
-}
-
-/**
- * pk_network_nm_changed_cb:
- **/
-static void
-pk_network_nm_changed_cb (libnm_glib_ctx *libnm_ctx, gpointer data)
-{
- gboolean ret;
- PkNetwork *network = (PkNetwork *) data;
-
- g_return_if_fail (PK_IS_NETWORK (network));
-
- ret = pk_network_is_online (network);
- g_signal_emit (network, signals [PK_NETWORK_ONLINE], 0, ret);
-}
-
-/**
- * pk_network_class_init:
- * @klass: The PkNetworkClass
- **/
-static void
-pk_network_class_init (PkNetworkClass *klass)
-{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = pk_network_finalize;
- signals [PK_NETWORK_ONLINE] =
- g_signal_new ("online",
- G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
- 0, NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
- g_type_class_add_private (klass, sizeof (PkNetworkPrivate));
-}
-
-/**
- * pk_network_init:
- * @network: This class instance
- **/
-static void
-pk_network_init (PkNetwork *network)
-{
- GMainContext *context;
-
- network->priv = PK_NETWORK_GET_PRIVATE (network);
- context = g_main_context_default ();
- network->priv->ctx = libnm_glib_init ();
- network->priv->callback_id =
- libnm_glib_register_callback (network->priv->ctx,
- pk_network_nm_changed_cb,
- network, context);
- pk_debug ("ctx=%p, id=%i", network->priv->ctx, network->priv->callback_id);
-}
-
-/**
- * pk_network_finalize:
- * @object: The object to finalize
- **/
-static void
-pk_network_finalize (GObject *object)
-{
- PkNetwork *network;
- g_return_if_fail (object != NULL);
- g_return_if_fail (PK_IS_NETWORK (object));
- network = PK_NETWORK (object);
-
- g_return_if_fail (network->priv != NULL);
-
- pk_debug ("ctx=%p, id=%i", network->priv->ctx, network->priv->callback_id);
- libnm_glib_unregister_callback (network->priv->ctx, network->priv->callback_id);
- libnm_glib_shutdown (network->priv->ctx);
-
- /* be paranoid */
- network->priv->ctx = NULL;
- network->priv->callback_id = 0;
-
- G_OBJECT_CLASS (pk_network_parent_class)->finalize (object);
-}
-
-/**
- * pk_network_new:
- *
- * Return value: a new PkNetwork object.
- **/
-PkNetwork *
-pk_network_new (void)
-{
- if (pk_network_object != NULL) {
- g_object_ref (pk_network_object);
- } else {
- pk_network_object = g_object_new (PK_TYPE_NETWORK, NULL);
- g_object_add_weak_pointer (pk_network_object, &pk_network_object);
- }
- return PK_NETWORK (pk_network_object);
-}
-
diff --git a/libpackagekit/pk-network.h b/libpackagekit/pk-network.h
deleted file mode 100644
index 230b5b2..0000000
--- a/libpackagekit/pk-network.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- *
- * Copyright (C) 2007 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.
- */
-
-/**
- * SECTION:pk-network
- * @short_description: An abstract network access GObject
- *
- * This allows a switchable network backend.
- */
-
-#ifndef __PK_NETWORK_H
-#define __PK_NETWORK_H
-
-#include <glib-object.h>
-
-G_BEGIN_DECLS
-
-#define PK_TYPE_NETWORK (pk_network_get_type ())
-#define PK_NETWORK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_NETWORK, PkNetwork))
-#define PK_NETWORK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_NETWORK, PkNetworkClass))
-#define PK_IS_NETWORK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_NETWORK))
-#define PK_IS_NETWORK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_NETWORK))
-#define PK_NETWORK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_NETWORK, PkNetworkClass))
-#define PK_NETWORK_ERROR (pk_network_error_quark ())
-#define PK_NETWORK_TYPE_ERROR (pk_network_error_get_type ())
-
-typedef struct _PkNetworkPrivate PkNetworkPrivate;
-typedef struct _PkNetwork PkNetwork;
-typedef struct _PkNetworkClass PkNetworkClass;
-
-struct _PkNetwork
-{
- GObject parent;
- PkNetworkPrivate *priv;
-};
-
-struct _PkNetworkClass
-{
- GObjectClass parent_class;
-};
-
-GType pk_network_get_type (void) G_GNUC_CONST;
-PkNetwork *pk_network_new (void);
-gboolean pk_network_is_online (PkNetwork *network);
-gboolean pk_network_is_modem (PkNetwork *network);
-
-G_END_DECLS
-
-#endif /* __PK_NETWORK_H */
diff --git a/src/Makefile.am b/src/Makefile.am
index bd34af6..fb7a7ec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@ INCLUDES = \
$(DBUS_CFLAGS) \
$(SQLITE_CFLAGS) \
$(POLKIT_CFLAGS) \
+ $(LIBNM_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
-DSBINDIR=\"$(sbindir)\" \
-DDATADIR=\"$(datadir)\" \
@@ -48,6 +49,11 @@ shared_SOURCES = \
pk-backend.h \
pk-backend-internal.h \
pk-security.h \
+ pk-network.c \
+ pk-network.h \
+ pk-network-nm.h \
+ pk-network-unix.c \
+ pk-network-unix.h \
pk-time.h \
pk-time.c \
pk-conf.c \
@@ -75,6 +81,14 @@ shared_SOURCES = \
pk-transaction-list.h \
$(NULL)
+if PK_BUILD_NETWORKMANAGER
+shared_SOURCES += \
+ pk-network-nm.c
+else
+shared_SOURCES += \
+ pk-network-nm-dummy.c
+endif
+
if PK_BUILD_GIO
shared_SOURCES += \
pk-file-monitor-gio.c \
@@ -105,6 +119,7 @@ packagekitd_SOURCES = \
packagekitd_LDADD = \
$(GLIB_LIBS) \
$(GMODULE_LIBS) \
+ $(LIBNM_LIBS) \
$(DBUS_LIBS) \
$(SQLITE_LIBS) \
$(PK_LIBS) \
diff --git a/src/pk-backend.c b/src/pk-backend.c
index 371cde6..c331bbe 100644
--- a/src/pk-backend.c
+++ b/src/pk-backend.c
@@ -1489,7 +1489,13 @@ pk_backend_not_implemented_yet (PkBackend *backend, const gchar *method)
gboolean
pk_backend_is_online (PkBackend *backend)
{
- return pk_network_is_online (backend->priv->network);
+ PkNetworkEnum state;
+ g_return_val_if_fail (PK_IS_BACKEND (backend), FALSE);
+ state = pk_network_get_network_state (backend->priv->network);
+ if (pk_enums_contain (state, PK_NETWORK_ENUM_ONLINE)) {
+ return TRUE;
+ }
+ return FALSE;
}
/**
diff --git a/src/pk-engine.c b/src/pk-engine.c
index dbab2e6..a24f41c 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -263,9 +263,11 @@ pk_engine_get_tid (PkEngine *engine, gchar **tid, GError **error)
gboolean
pk_engine_get_network_state (PkEngine *engine, gchar **state, GError **error)
{
+ PkNetworkEnum network;
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
- //TODO: get the network state
- *state = g_strdup (pk_network_enum_to_text (PK_NETWORK_ENUM_UNKNOWN));
+ /* get the network state */
+ network = pk_network_get_network_state (engine->priv->network);
+ *state = g_strdup (pk_network_enum_to_text (network));
return TRUE;
}
@@ -292,14 +294,14 @@ pk_engine_get_transaction_list (PkEngine *engine, gchar ***transaction_list, GEr
static gboolean
pk_engine_state_changed_cb (gpointer data)
{
- gboolean ret;
+ PkNetworkEnum state;
PkEngine *engine = PK_ENGINE (data);
g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
- /* if NetworkManager is not up, then just reschedule */
- ret = pk_network_is_online (engine->priv->network);
- if (!ret) {
+ /* if network is not up, then just reschedule */
+ state = pk_network_get_network_state (engine->priv->network);
+ if (state == PK_NETWORK_ENUM_OFFLINE) {
/* wait another timeout of PK_ENGINE_STATE_CHANGED_TIMEOUT */
return TRUE;
}
@@ -493,6 +495,19 @@ pk_engine_file_monitor_changed_cb (PkFileMonitor *file_monitor, PkEngine *engine
}
/**
+ * pk_engine_network_state_changed_cb:
+ **/
+static void
+pk_engine_network_state_changed_cb (PkNetwork *file_monitor, PkNetworkEnum state, PkEngine *engine)
+{
+ const gchar *state_text;
+ g_return_if_fail (PK_IS_ENGINE (engine));
+ state_text = pk_network_enum_to_text (state);
+ pk_debug ("emitting network-state-changed: %s", state_text);
+ g_signal_emit (engine, signals [PK_ENGINE_NETWORK_STATE_CHANGED], 0, state_text);
+}
+
+/**
* pk_engine_init:
**/
static void
@@ -517,9 +532,13 @@ pk_engine_init (PkEngine *engine)
}
/* we dont need this, just don't keep creating and destroying it */
- engine->priv->network = pk_network_new ();
engine->priv->security = pk_security_new ();
+ /* proxy the network state */
+ engine->priv->network = pk_network_new ();
+ g_signal_connect (engine->priv->network, "state-changed",
+ G_CALLBACK (pk_engine_network_state_changed_cb), engine);
+
/* create a new backend so we can get the static stuff */
engine->priv->actions = pk_backend_get_actions (engine->priv->backend);
engine->priv->groups = pk_backend_get_groups (engine->priv->backend);
diff --git a/src/pk-network-nm-dummy.c b/src/pk-network-nm-dummy.c
new file mode 100644
index 0000000..e7753d1
--- /dev/null
+++ b/src/pk-network-nm-dummy.c
@@ -0,0 +1,139 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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 <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <sys/wait.h>
+#include <fcntl.h>
+
+#include <glib/gi18n.h>
+
+#include "pk-debug.h"
+#include "pk-network_nm.h"
+#include "pk-marshal.h"
+
+static void pk_network_nm_class_init (PkNetworkNmClass *klass);
+static void pk_network_nm_init (PkNetworkNm *network_nm);
+static void pk_network_nm_finalize (GObject *object);
+
+#define PK_NETWORK_NM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK_NM, PkNetworkNmPrivate))
+
+/**
+ * PkNetworkNmPrivate:
+ *
+ * Private #PkNetworkNm data
+ **/
+struct _PkNetworkNmPrivate
+{
+ guint callback_id;
+};
+
+enum {
+ PK_NETWORK_NM_STATE_CHANGED,
+ PK_NETWORK_NM_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_NM_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkNetworkNm, pk_network_nm, G_TYPE_OBJECT)
+
+/**
+ * pk_network_nm_get_network_state:
+ * @network_nm: a valid #PkNetworkNm instance
+ *
+ * Return value: always %TRUE - this method should never be called
+ **/
+PkNetworkEnum
+pk_network_nm_get_network_state (PkNetworkNm *network_nm)
+{
+ g_return_val_if_fail (PK_IS_NETWORK_NM (network_nm), PK_NETWORK_ENUM_UNKNOWN);
+ /* don't do any checks */
+ return PK_NETWORK_ENUM_ONLINE;
+}
+
+/**
+ * pk_network_nm_class_init:
+ * @klass: The PkNetworkNmClass
+ **/
+static void
+pk_network_nm_class_init (PkNetworkNmClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_network_nm_finalize;
+ signals [PK_NETWORK_NM_STATE_CHANGED] =
+ g_signal_new ("state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ g_type_class_add_private (klass, sizeof (PkNetworkNmPrivate));
+}
+
+/**
+ * pk_network_nm_init:
+ * @network_nm: This class instance
+ **/
+static void
+pk_network_nm_init (PkNetworkNm *network_nm)
+{
+ network_nm->priv = PK_NETWORK_NM_GET_PRIVATE (network_nm);
+}
+
+/**
+ * pk_network_nm_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_nm_finalize (GObject *object)
+{
+ PkNetworkNm *network_nm;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (PK_IS_NETWORK_NM (object));
+ network_nm = PK_NETWORK_NM (object);
+
+ g_return_if_fail (network_nm->priv != NULL);
+ G_OBJECT_CLASS (pk_network_nm_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_nm_new:
+ *
+ * Return value: a new PkNetworkNm object.
+ **/
+PkNetworkNm *
+pk_network_nm_new (void)
+{
+ PkNetworkNm *network_nm;
+ network_nm = g_object_new (PK_TYPE_NETWORK_NM, NULL);
+ return PK_NETWORK_NM (network_nm);
+}
+
diff --git a/src/pk-network-nm.c b/src/pk-network-nm.c
new file mode 100644
index 0000000..ae17b8e
--- /dev/null
+++ b/src/pk-network-nm.c
@@ -0,0 +1,185 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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 <string.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <sys/wait.h>
+#include <fcntl.h>
+
+#include <glib/gi18n.h>
+#include <libnm_glib.h>
+
+#include "pk-debug.h"
+#include "pk-network-nm.h"
+#include "pk-marshal.h"
+
+static void pk_network_nm_class_init (PkNetworkNmClass *klass);
+static void pk_network_nm_init (PkNetworkNm *network_nm);
+static void pk_network_nm_finalize (GObject *object);
+
+#define PK_NETWORK_NM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK_NM, PkNetworkNmPrivate))
+
+/**
+ * PkNetworkNmPrivate:
+ *
+ * Private #PkNetworkNm data
+ **/
+struct _PkNetworkNmPrivate
+{
+ libnm_glib_ctx *ctx;
+ guint callback_id;
+};
+
+enum {
+ PK_NETWORK_NM_STATE_CHANGED,
+ PK_NETWORK_NM_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_NM_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkNetworkNm, pk_network_nm, G_TYPE_OBJECT)
+
+/**
+ * pk_network_nm_get_network_state:
+ * @network_nm: a valid #PkNetworkNm instance
+ *
+ * Return value: %TRUE if the network_nm is online
+ **/
+PkNetworkEnum
+pk_network_nm_get_network_state (PkNetworkNm *network_nm)
+{
+ libnm_glib_state state;
+ PkNetworkEnum ret;
+
+ g_return_val_if_fail (PK_IS_NETWORK_NM (network_nm), PK_NETWORK_ENUM_UNKNOWN);
+
+ state = libnm_glib_get_network_state (network_nm->priv->ctx);
+ switch (state) {
+ case LIBNM_NO_NETWORK_CONNECTION:
+ ret = PK_NETWORK_ENUM_OFFLINE;
+ break;
+ default:
+ ret = PK_NETWORK_ENUM_ONLINE;
+ }
+ return ret;
+}
+
+/**
+ * pk_network_nm_nm_changed_cb:
+ **/
+static void
+pk_network_nm_nm_changed_cb (libnm_glib_ctx *libnm_ctx, gpointer data)
+{
+ gboolean ret;
+ PkNetworkNm *network_nm = (PkNetworkNm *) data;
+
+ g_return_if_fail (PK_IS_NETWORK_NM (network_nm));
+
+ ret = pk_network_nm_get_network_state (network_nm);
+ g_signal_emit (network_nm, signals [PK_NETWORK_NM_STATE_CHANGED], 0, ret);
+}
+
+/**
+ * pk_network_nm_class_init:
+ * @klass: The PkNetworkNmClass
+ **/
+static void
+pk_network_nm_class_init (PkNetworkNmClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_network_nm_finalize;
+ signals [PK_NETWORK_NM_STATE_CHANGED] =
+ g_signal_new ("state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ g_type_class_add_private (klass, sizeof (PkNetworkNmPrivate));
+}
+
+/**
+ * pk_network_nm_init:
+ * @network_nm: This class instance
+ **/
+static void
+pk_network_nm_init (PkNetworkNm *network_nm)
+{
+ GMainContext *context;
+
+ network_nm->priv = PK_NETWORK_NM_GET_PRIVATE (network_nm);
+ context = g_main_context_default ();
+ network_nm->priv->ctx = libnm_glib_init ();
+ network_nm->priv->callback_id =
+ libnm_glib_register_callback (network_nm->priv->ctx,
+ pk_network_nm_nm_changed_cb,
+ network_nm, context);
+ pk_debug ("ctx=%p, id=%i", network_nm->priv->ctx, network_nm->priv->callback_id);
+}
+
+/**
+ * pk_network_nm_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_nm_finalize (GObject *object)
+{
+ PkNetworkNm *network_nm;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (PK_IS_NETWORK_NM (object));
+ network_nm = PK_NETWORK_NM (object);
+
+ g_return_if_fail (network_nm->priv != NULL);
+
+ pk_debug ("ctx=%p, id=%i", network_nm->priv->ctx, network_nm->priv->callback_id);
+ libnm_glib_unregister_callback (network_nm->priv->ctx, network_nm->priv->callback_id);
+ libnm_glib_shutdown (network_nm->priv->ctx);
+
+ /* be paranoid */
+ network_nm->priv->ctx = NULL;
+ network_nm->priv->callback_id = 0;
+
+ G_OBJECT_CLASS (pk_network_nm_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_nm_new:
+ *
+ * Return value: a new PkNetworkNm object.
+ **/
+PkNetworkNm *
+pk_network_nm_new (void)
+{
+ PkNetworkNm *network_nm;
+ network_nm = g_object_new (PK_TYPE_NETWORK_NM, NULL);
+ return PK_NETWORK_NM (network_nm);
+}
+
diff --git a/src/pk-network-nm.h b/src/pk-network-nm.h
new file mode 100644
index 0000000..0b0e5ec
--- /dev/null
+++ b/src/pk-network-nm.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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.
+ */
+
+/**
+ * SECTION:pk-network-nm
+ * @short_description: An NetworkManager access GObject
+ *
+ * This allows a switchable network backend.
+ */
+
+#ifndef __PK_NETWORK_NM_H
+#define __PK_NETWORK_NM_H
+
+#include <glib-object.h>
+#include <pk-enum.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_NETWORK_NM (pk_network_nm_get_type ())
+#define PK_NETWORK_NM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_NETWORK_NM, PkNetworkNm))
+#define PK_NETWORK_NM_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_NETWORK_NM, PkNetworkNmClass))
+#define PK_IS_NETWORK_NM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_NETWORK_NM))
+#define PK_IS_NETWORK_NM_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_NETWORK_NM))
+#define PK_NETWORK_NM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_NETWORK_NM, PkNetworkNmClass))
+#define PK_NETWORK_NM_ERROR (pk_network_nm_error_quark ())
+#define PK_NETWORK_NM_TYPE_ERROR (pk_network_nm_error_get_type ())
+
+typedef struct _PkNetworkNmPrivate PkNetworkNmPrivate;
+typedef struct _PkNetworkNm PkNetworkNm;
+typedef struct _PkNetworkNmClass PkNetworkNmClass;
+
+struct _PkNetworkNm
+{
+ GObject parent;
+ PkNetworkNmPrivate *priv;
+};
+
+struct _PkNetworkNmClass
+{
+ GObjectClass parent_class;
+};
+
+GType pk_network_nm_get_type (void) G_GNUC_CONST;
+PkNetworkNm *pk_network_nm_new (void);
+PkNetworkEnum pk_network_nm_get_network_state (PkNetworkNm *network_nm);
+
+G_END_DECLS
+
+#endif /* __PK_NETWORK_NM_H */
+
diff --git a/src/pk-network-unix.c b/src/pk-network-unix.c
new file mode 100644
index 0000000..43fa500
--- /dev/null
+++ b/src/pk-network-unix.c
@@ -0,0 +1,145 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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.
+ */
+
+/**
+ * SECTION:pk-network_unix-dummy
+ * @short_description: Dummy network_unix detection code
+ *
+ * This file contains a unix network implimentation.
+ * It is designed for people that don't have NetworkUnixManager installed.
+ * It polls the network to wait to see if it's up
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.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-debug.h"
+#include "pk-network-unix.h"
+#include "pk-marshal.h"
+
+static void pk_network_unix_class_init (PkNetworkUnixClass *klass);
+static void pk_network_unix_init (PkNetworkUnix *network_unix);
+static void pk_network_unix_finalize (GObject *object);
+
+#define PK_NETWORK_UNIX_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK_UNIX, PkNetworkUnixPrivate))
+
+/**
+ * _PkNetworkUnixPrivate:
+ *
+ * Private #PkNetworkUnix data
+ **/
+struct _PkNetworkUnixPrivate
+{
+ gpointer data;
+};
+
+enum {
+ PK_NETWORK_UNIX_STATE_CHANGED,
+ PK_NETWORK_UNIX_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_UNIX_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkNetworkUnix, pk_network_unix, G_TYPE_OBJECT)
+
+/**
+ * pk_network_unix_get_network_state:
+ * @network_unix: a valid #PkNetworkUnix instance
+ *
+ * Return value: %TRUE if the network is online
+ **/
+PkNetworkEnum
+pk_network_unix_get_network_state (PkNetworkUnix *network_unix)
+{
+ g_return_val_if_fail (PK_IS_NETWORK_UNIX (network_unix), PK_NETWORK_ENUM_UNKNOWN);
+ /* TODO: check the default route */
+ return PK_NETWORK_ENUM_ONLINE;
+}
+
+/**
+ * pk_network_unix_class_init:
+ * @klass: The PkNetworkUnixClass
+ **/
+static void
+pk_network_unix_class_init (PkNetworkUnixClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_network_unix_finalize;
+ signals [PK_NETWORK_UNIX_STATE_CHANGED] =
+ g_signal_new ("state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ g_type_class_add_private (klass, sizeof (PkNetworkUnixPrivate));
+}
+
+/**
+ * pk_network_unix_init:
+ * @network_unix: This class instance
+ **/
+static void
+pk_network_unix_init (PkNetworkUnix *network_unix)
+{
+ network_unix->priv = PK_NETWORK_UNIX_GET_PRIVATE (network_unix);
+}
+
+/**
+ * pk_network_unix_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_unix_finalize (GObject *object)
+{
+ PkNetworkUnix *network_unix;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (PK_IS_NETWORK_UNIX (object));
+ network_unix = PK_NETWORK_UNIX (object);
+
+ g_return_if_fail (network_unix->priv != NULL);
+ G_OBJECT_CLASS (pk_network_unix_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_unix_new:
+ *
+ * Return value: a new PkNetworkUnix object.
+ **/
+PkNetworkUnix *
+pk_network_unix_new (void)
+{
+ PkNetworkUnix *network_unix;
+ network_unix = g_object_new (PK_TYPE_NETWORK_UNIX, NULL);
+ return PK_NETWORK_UNIX (network_unix);
+}
+
diff --git a/src/pk-network-unix.h b/src/pk-network-unix.h
new file mode 100644
index 0000000..2c4ce26
--- /dev/null
+++ b/src/pk-network-unix.h
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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.
+ */
+
+/**
+ * SECTION:pk-network-unix
+ * @short_description: An abstract unix network access GObject
+ *
+ * This allows a switchable network backend.
+ */
+
+#ifndef __PK_NETWORK_UNIX_H
+#define __PK_NETWORK_UNIX_H
+
+#include <glib-object.h>
+#include <pk-enum.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_NETWORK_UNIX (pk_network_unix_get_type ())
+#define PK_NETWORK_UNIX(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_NETWORK_UNIX, PkNetworkUnix))
+#define PK_NETWORK_UNIX_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_NETWORK_UNIX, PkNetworkUnixClass))
+#define PK_IS_NETWORK_UNIX(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_NETWORK_UNIX))
+#define PK_IS_NETWORK_UNIX_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_NETWORK_UNIX))
+#define PK_NETWORK_UNIX_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_NETWORK_UNIX, PkNetworkUnixClass))
+#define PK_NETWORK_UNIX_ERROR (pk_network_unix_error_quark ())
+#define PK_NETWORK_UNIX_TYPE_ERROR (pk_network_unix_error_get_type ())
+
+typedef struct _PkNetworkUnixPrivate PkNetworkUnixPrivate;
+typedef struct _PkNetworkUnix PkNetworkUnix;
+typedef struct _PkNetworkUnixClass PkNetworkUnixClass;
+
+struct _PkNetworkUnix
+{
+ GObject parent;
+ PkNetworkUnixPrivate *priv;
+};
+
+struct _PkNetworkUnixClass
+{
+ GObjectClass parent_class;
+};
+
+GType pk_network_unix_get_type (void) G_GNUC_CONST;
+PkNetworkUnix *pk_network_unix_new (void);
+PkNetworkEnum pk_network_unix_get_network_state (PkNetworkUnix *network_unix);
+
+G_END_DECLS
+
+#endif /* __PK_NETWORK_UNIX_H */
+
diff --git a/src/pk-network.c b/src/pk-network.c
new file mode 100644
index 0000000..32c91a3
--- /dev/null
+++ b/src/pk-network.c
@@ -0,0 +1,205 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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.
+ */
+
+/**
+ * SECTION:pk-network
+ * @short_description: network detection code
+ *
+ * This file contains a network checker.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <time.h>
+#include <errno.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-debug.h"
+#include "pk-network.h"
+#include "pk-network-nm.h"
+#include "pk-network-unix.h"
+#include "pk-marshal.h"
+
+static void pk_network_class_init (PkNetworkClass *klass);
+static void pk_network_init (PkNetwork *network);
+static void pk_network_finalize (GObject *object);
+
+#define PK_NETWORK_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK, PkNetworkPrivate))
+
+/**
+ * _PkNetworkPrivate:
+ *
+ * Private #PkNetwork data
+ **/
+struct _PkNetworkPrivate
+{
+ gboolean use_nm;
+ gboolean use_unix;
+ PkNetworkNm *net_nm;
+ PkNetworkUnix *net_unix;
+};
+
+enum {
+ PK_NETWORK_STATE_CHANGED,
+ PK_NETWORK_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_LAST_SIGNAL] = { 0 };
+static gpointer pk_network_object = NULL;
+
+G_DEFINE_TYPE (PkNetwork, pk_network, G_TYPE_OBJECT)
+
+/**
+ * pk_network_get_network_state:
+ * @network: a valid #PkNetwork instance
+ *
+ * Return value: %TRUE if the network is online
+ * Note: This is a dummy file and no checks are done
+ **/
+PkNetworkEnum
+pk_network_get_network_state (PkNetwork *network)
+{
+ g_return_val_if_fail (PK_IS_NETWORK (network), PK_NETWORK_ENUM_UNKNOWN);
+ /* use the correct backend */
+ if (network->priv->use_nm) {
+ return pk_network_nm_get_network_state (network->priv->net_nm);
+ }
+ if (network->priv->use_unix) {
+ return pk_network_unix_get_network_state (network->priv->net_unix);
+ }
+ return PK_NETWORK_ENUM_ONLINE;
+}
+
+/**
+ * pk_network_nm_network_changed_cb:
+ **/
+static void
+pk_network_nm_network_changed_cb (PkNetworkNm *net_nm, gboolean online, PkNetwork *network)
+{
+ PkNetworkEnum ret;
+ g_return_if_fail (PK_IS_NETWORK (network));
+ if (network->priv->use_nm) {
+ if (online) {
+ ret = PK_NETWORK_ENUM_ONLINE;
+ } else {
+ ret = PK_NETWORK_ENUM_OFFLINE;
+ }
+ g_signal_emit (network, signals [PK_NETWORK_STATE_CHANGED], 0, ret);
+ }
+}
+
+/**
+ * pk_network_unix_network_changed_cb:
+ **/
+static void
+pk_network_unix_network_changed_cb (PkNetworkUnix *net_unix, gboolean online, PkNetwork *network)
+{
+ g_return_if_fail (PK_IS_NETWORK (network));
+ if (network->priv->use_unix) {
+ g_signal_emit (network, signals [PK_NETWORK_STATE_CHANGED], 0, online);
+ }
+}
+
+/**
+ * pk_network_class_init:
+ * @klass: The PkNetworkClass
+ **/
+static void
+pk_network_class_init (PkNetworkClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = pk_network_finalize;
+ signals [PK_NETWORK_STATE_CHANGED] =
+ g_signal_new ("state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ g_type_class_add_private (klass, sizeof (PkNetworkPrivate));
+}
+
+/**
+ * pk_network_init:
+ * @network: This class instance
+ **/
+static void
+pk_network_init (PkNetwork *network)
+{
+ network->priv = PK_NETWORK_GET_PRIVATE (network);
+ network->priv->use_nm = TRUE;
+ network->priv->use_unix = TRUE;
+ network->priv->net_nm = pk_network_nm_new ();
+ g_signal_connect (network->priv->net_nm, "state-changed",
+ G_CALLBACK (pk_network_nm_network_changed_cb), network);
+ network->priv->net_unix = pk_network_unix_new ();
+ g_signal_connect (network->priv->net_unix, "state-changed",
+ G_CALLBACK (pk_network_unix_network_changed_cb), network);
+
+#if !PK_BUILD_NETWORKMANAGER
+ /* hardcode */
+ network->priv->use_nm = FALSE;
+#endif
+}
+
+/**
+ * pk_network_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_finalize (GObject *object)
+{
+ PkNetwork *network;
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (PK_IS_NETWORK (object));
+ network = PK_NETWORK (object);
+
+ g_return_if_fail (network->priv != NULL);
+ g_object_unref (network->priv->net_nm);
+ g_object_unref (network->priv->net_unix);
+ G_OBJECT_CLASS (pk_network_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_new:
+ *
+ * Return value: a new PkNetwork object.
+ **/
+PkNetwork *
+pk_network_new (void)
+{
+ if (pk_network_object != NULL) {
+ g_object_ref (pk_network_object);
+ } else {
+ pk_network_object = g_object_new (PK_TYPE_NETWORK, NULL);
+ g_object_add_weak_pointer (pk_network_object, &pk_network_object);
+ }
+ return PK_NETWORK (pk_network_object);
+}
+
diff --git a/src/pk-network.h b/src/pk-network.h
new file mode 100644
index 0000000..df3f2f5
--- /dev/null
+++ b/src/pk-network.h
@@ -0,0 +1,67 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-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.
+ */
+
+/**
+ * SECTION:pk-network
+ * @short_description: An abstract network access GObject
+ *
+ * This allows a switchable network backend.
+ */
+
+#ifndef __PK_NETWORK_H
+#define __PK_NETWORK_H
+
+#include <glib-object.h>
+#include <pk-enum.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_NETWORK (pk_network_get_type ())
+#define PK_NETWORK(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_NETWORK, PkNetwork))
+#define PK_NETWORK_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_NETWORK, PkNetworkClass))
+#define PK_IS_NETWORK(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_NETWORK))
+#define PK_IS_NETWORK_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_NETWORK))
+#define PK_NETWORK_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_NETWORK, PkNetworkClass))
+#define PK_NETWORK_ERROR (pk_network_error_quark ())
+#define PK_NETWORK_TYPE_ERROR (pk_network_error_get_type ())
+
+typedef struct _PkNetworkPrivate PkNetworkPrivate;
+typedef struct _PkNetwork PkNetwork;
+typedef struct _PkNetworkClass PkNetworkClass;
+
+struct _PkNetwork
+{
+ GObject parent;
+ PkNetworkPrivate *priv;
+};
+
+struct _PkNetworkClass
+{
+ GObjectClass parent_class;
+};
+
+GType pk_network_get_type (void) G_GNUC_CONST;
+PkNetwork *pk_network_new (void);
+PkNetworkEnum pk_network_get_network_state (PkNetwork *network);
+
+G_END_DECLS
+
+#endif /* __PK_NETWORK_H */
commit 01afd57c7f8bf1d66fa174758ecb60d9a7f21e9e
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 16:35:28 2008 +0100
make valid html in the faq page
diff --git a/docs/html/pk-faq.html b/docs/html/pk-faq.html
index e299d3b..4dd418e 100644
--- a/docs/html/pk-faq.html
+++ b/docs/html/pk-faq.html
@@ -589,7 +589,7 @@ For example, the following code snippet would install a package by name:
</p>
<pre>
-#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib.h>
DBusGConnection *connection;
DBusGProxy *proxy;
commit 5b37cc85cd93877e21deb487ba72164eaf83f701
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 16:16:07 2008 +0100
add a FAQ entry
diff --git a/docs/html/pk-faq.html b/docs/html/pk-faq.html
index a9e2bb7..e299d3b 100644
--- a/docs/html/pk-faq.html
+++ b/docs/html/pk-faq.html
@@ -22,6 +22,7 @@
<h2>Table Of Contents</h2>
<ul>
<li><a href="#how-complete">How complete are the backends?</a></li>
+<li><a href="#session-methods">How do I use PackageKit in my application?</a></li>
<li><a href="#rawhide-updates">Why don't I get update details with Fedora Rawhide?</a></li>
<li><a href="#selinux">Why doesn't PackageKit work with SELinux?</a></li>
<li><a href="#tray-icons">What do the tray icons mean?</a></li>
@@ -563,6 +564,67 @@
</table>
<hr>
+<h3><a name="session-methods">How do I use PackageKit in my application?</a></h3>
+<p>
+If you are using <a href="http://www.gnome.org/">GNOME</a>, or running the
+<code>gpk-update-icon</code> then you can use the session dbus interface
+provided by this process.
+If you are not using GNOME, or choose to not use the <code>gpk-update-icon</code>
+applet then you can use an alternate interface provided by your desktop.
+</p>
+<p>
+Using this shared session service you can use the following DBUS methods
+to make PackageKit just do the right thing.
+All the additional
+<a href="http://www.packagekit.org/pk-reference.html#introduction-ideas-transactions">
+confirmation, package downloads, GPG and EULA prompting is done automatically.</a>
+</p>
+<p>
+The DBUS methods are designed to be run syncronously, but can be run
+async using <code>dbus_g_proxy_begin_call</code> and then returning on
+the <code>DBusGProxyCallNotify</code>.
+</p>
+<p>
+For example, the following code snippet would install a package by name:
+</p>
+
+<pre>
+#include <dbus/dbus-glib.h>
+
+DBusGConnection *connection;
+DBusGProxy *proxy;
+GError *error = NULL;
+gboolean ret;
+
+connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
+proxy = dbus_g_proxy_new_for_name (connection,
+ "org.freedesktop.PackageKit",
+ "/org/freedesktop/PackageKit",
+ "org.freedesktop.PackageKit");
+/* execute sync method */
+ret = dbus_g_proxy_call (proxy, "InstallPackageName", &error,
+ G_TYPE_STRING, "openoffice-clipart",
+ G_TYPE_INVALID, G_TYPE_INVALID);
+if (!ret) {
+ g_warning ("failed: %s", error->message);
+ g_error_free (error);
+}
+</pre>
+<p>
+The methods available on this interface are:
+</p>
+<ul>
+<li><code>InstallPackageName("openoffice-clipart")</code></li>
+<li><code>InstallProvideFile("/usr/share/fonts/sarai/Sarai_07.ttf")</code></li>
+<li><code>InstallLocalFile("/home/dave/Desktop/lirc-0.6.6-4.rhfc1.dag.i686.rpm")</code></li>
+</ul>
+<p>
+Please email me or the
+<a href="http://lists.freedesktop.org/mailman/listinfo/packagekit">mailing list</a>
+if you have any other questions
+</p>
+
+<hr>
<h3><a name="tray-icons">What do the tray icons mean?</a></h3>
<table>
<tr><td><img src="img/pk-update-bugfix.png"/></td><td>Bugfix update</td></tr>
commit 16677b11df83b8c5be781dd78be94c170ffac35d
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 16:09:46 2008 +0100
add some extra switches to the config file for network handling
diff --git a/etc/PackageKit.conf.in b/etc/PackageKit.conf.in
index 7d6fca8..a6af99b 100644
--- a/etc/PackageKit.conf.in
+++ b/etc/PackageKit.conf.in
@@ -3,16 +3,31 @@
[Daemon]
-# Log transactions to the database
+# Should we log transactions to the database.
+#
# default=yes
TransactionLogging=true
+# Use NetworkManager where available. If disabled, then NM state will be ignored.
+#
+# default=yes
+UseNetworkManager=true
+
+# If NetworkManager is not available, then use the presence of a default
+# route to indicate a viable network connection.
+# If disabled, and no NM, then the network is assumed to be always online.
+#
+# default=yes
+UseNetworkHeuristic=true
+
# Shut down the daemon after this many seconds idle. 0 means don't shutdown.
+#
# default=300
ShutdownTimeout=300
# Default backend, as chosen in the configure script. This will be used where
# no --backend="foo" option is given to the daemon.
+#
# default=@defaultbackend@
DefaultBackend=@defaultbackend@
commit b9a83e537d6f4f979cc6e80fe82cabf42fc872e8
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 15:25:42 2008 +0100
RepoListChanged does not have any arguments -- not sure how this has worked for so long
diff --git a/libpackagekit/pk-control.c b/libpackagekit/pk-control.c
index 52bdc9e..b4e9ea4 100644
--- a/libpackagekit/pk-control.c
+++ b/libpackagekit/pk-control.c
@@ -736,8 +736,7 @@ pk_control_init (PkControl *control)
dbus_g_proxy_connect_signal (control->priv->proxy, "UpdatesChanged",
G_CALLBACK (pk_control_updates_changed_cb), control, NULL);
- dbus_g_proxy_add_signal (control->priv->proxy, "RepoListChanged",
- G_TYPE_STRING, G_TYPE_INVALID);
+ dbus_g_proxy_add_signal (control->priv->proxy, "RepoListChanged", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (control->priv->proxy, "RepoListChanged",
G_CALLBACK (pk_control_repo_list_changed_cb), control, NULL);
commit 2254e1c1676028137847ecd800c0078e911e83b9
Author: Richard Hughes <richard at hughsie.com>
Date: Thu May 1 15:24:07 2008 +0100
add proper dbus accessors for the network state so we can share a dbus interface rather than a library
diff --git a/libpackagekit/pk-control.c b/libpackagekit/pk-control.c
index 13a4d20..52bdc9e 100644
--- a/libpackagekit/pk-control.c
+++ b/libpackagekit/pk-control.c
@@ -72,6 +72,7 @@ enum {
PK_CONTROL_RESTART_SCHEDULE,
PK_CONTROL_UPDATES_CHANGED,
PK_CONTROL_REPO_LIST_CHANGED,
+ PK_CONTROL_NETWORK_STATE_CHANGED,
PK_CONTROL_LAST_SIGNAL
};
@@ -240,6 +241,45 @@ out:
}
/**
+ * pk_control_get_network_state:
+ * @control: a valid #PkControl instance
+ *
+ * Return value: an enumerated network state
+ **/
+PkNetworkEnum
+pk_control_get_network_state (PkControl *control)
+{
+ gboolean ret;
+ GError *error = NULL;
+ gchar *network_state;
+ PkGroupEnum network_state_enum = PK_NETWORK_ENUM_UNKNOWN;
+
+ g_return_val_if_fail (PK_IS_CONTROL (control), PK_NETWORK_ENUM_UNKNOWN);
+
+ /* check to see if we have a valid proxy */
+ if (control->priv->proxy == NULL) {
+ pk_warning ("No proxy for manager");
+ goto out;
+ }
+ ret = dbus_g_proxy_call (control->priv->proxy, "GetNetworkState", &error,
+ G_TYPE_INVALID,
+ G_TYPE_STRING, &network_state,
+ G_TYPE_INVALID);
+ if (!ret) {
+ /* abort as the DBUS method failed */
+ pk_warning ("GetNetworkState failed :%s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* convert to enumerated types */
+ network_state_enum = pk_network_enum_from_text (network_state);
+ g_free (network_state);
+out:
+ return network_state_enum;
+}
+
+/**
* pk_control_get_filters:
* @control: a valid #PkControl instance
*
@@ -541,6 +581,20 @@ pk_control_repo_list_changed_cb (DBusGProxy *proxy, PkControl *control)
}
/**
+ * pk_control_network_state_changed_cb:
+ */
+static void
+pk_control_network_state_changed_cb (DBusGProxy *proxy, const gchar *network_text, PkControl *control)
+{
+ PkNetworkEnum network;
+ g_return_if_fail (PK_IS_CONTROL (control));
+
+ network = pk_network_enum_from_text (network_text);
+ pk_debug ("emitting network-state-changed: %s", network_text);
+ g_signal_emit (control, signals [PK_CONTROL_NETWORK_STATE_CHANGED], 0, network);
+}
+
+/**
* pk_control_locked_cb:
*/
static void
@@ -587,6 +641,19 @@ pk_control_class_init (PkControlClass *klass)
NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
/**
+ * PkControl::network-state-changed:
+ * @control: the #PkControl instance that emitted the signal
+ *
+ * The ::network-state-changed signal is emitted when the network has changed speed or
+ * connections state.
+ **/
+ signals [PK_CONTROL_NETWORK_STATE_CHANGED] =
+ g_signal_new ("network-state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PkControlClass, network_state_changed),
+ NULL, NULL, g_cclosure_marshal_VOID__UINT,
+ G_TYPE_NONE, 1, G_TYPE_UINT);
+ /**
* PkControl::restart_schedule:
* @control: the #PkControl instance that emitted the signal
*
@@ -674,6 +741,11 @@ pk_control_init (PkControl *control)
dbus_g_proxy_connect_signal (control->priv->proxy, "RepoListChanged",
G_CALLBACK (pk_control_repo_list_changed_cb), control, NULL);
+ dbus_g_proxy_add_signal (control->priv->proxy, "NetworkStateChanged",
+ G_TYPE_STRING, G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal (control->priv->proxy, "NetworkStateChanged",
+ G_CALLBACK (pk_control_network_state_changed_cb), control, NULL);
+
dbus_g_proxy_add_signal (control->priv->proxy, "RestartSchedule", G_TYPE_INVALID);
dbus_g_proxy_connect_signal (control->priv->proxy, "RestartSchedule",
G_CALLBACK (pk_control_restart_schedule_cb), control, NULL);
@@ -711,6 +783,8 @@ pk_control_finalize (GObject *object)
G_CALLBACK (pk_control_updates_changed_cb), control);
dbus_g_proxy_disconnect_signal (control->priv->proxy, "RepoListChanged",
G_CALLBACK (pk_control_repo_list_changed_cb), control);
+ dbus_g_proxy_disconnect_signal (control->priv->proxy, "NetworkStateChanged",
+ G_CALLBACK (pk_control_network_state_changed_cb), control);
dbus_g_proxy_disconnect_signal (control->priv->proxy, "RestartSchedule",
G_CALLBACK (pk_control_restart_schedule_cb), control);
diff --git a/libpackagekit/pk-control.h b/libpackagekit/pk-control.h
index fa29890..63b30d3 100644
--- a/libpackagekit/pk-control.h
+++ b/libpackagekit/pk-control.h
@@ -69,6 +69,7 @@ struct _PkControlClass
void (* transaction_list_changed) (PkControl *control);
void (* updates_changed) (PkControl *control);
void (* repo_list_changed) (PkControl *control);
+ void (* network_state_changed) (PkControl *control);
void (* restart_schedule) (PkControl *control);
void (* locked) (PkControl *control,
gboolean is_locked);
@@ -90,6 +91,7 @@ gboolean pk_control_allocate_transaction_id (PkControl *control,
PkRoleEnum pk_control_get_actions (PkControl *control);
PkFilterEnum pk_control_get_filters (PkControl *control);
PkGroupEnum pk_control_get_groups (PkControl *control);
+PkNetworkEnum pk_control_get_network_state (PkControl *control);
gboolean pk_control_get_backend_detail (PkControl *control,
gchar **name,
gchar **author,
diff --git a/libpackagekit/pk-enum.c b/libpackagekit/pk-enum.c
index 526c0ee..d3161af 100644
--- a/libpackagekit/pk-enum.c
+++ b/libpackagekit/pk-enum.c
@@ -279,6 +279,15 @@ static PkEnumMatch enum_provides[] = {
{0, NULL}
};
+static PkEnumMatch enum_network[] = {
+ {PK_NETWORK_ENUM_UNKNOWN, "unknown"}, /* fall though value */
+ {PK_NETWORK_ENUM_OFFLINE, "offline"},
+ {PK_NETWORK_ENUM_ONLINE, "online"},
+ {PK_NETWORK_ENUM_SLOW, "slow"},
+ {PK_NETWORK_ENUM_FAST, "fast"},
+ {0, NULL}
+};
+
static PkEnumMatch enum_free_licenses[] = {
{PK_LICENSE_ENUM_UNKNOWN, "unknown"}, /* fall though value */
{PK_LICENSE_ENUM_GLIDE, "Glide"},
@@ -621,6 +630,34 @@ pk_exit_enum_to_text (PkExitEnum exit)
}
/**
+ * pk_network_enum_from_text:
+ * @network: Text describing the enumerated type
+ *
+ * Converts a text enumerated type to its unsigned integer representation
+ *
+ * Return value: the enumerated constant value, e.g. PK_SIGTYPE_ENUM_GPG
+ */
+PkNetworkEnum
+pk_network_enum_from_text (const gchar *network)
+{
+ return pk_enum_find_value (enum_network, network);
+}
+
+/**
+ * pk_network_enum_to_text:
+ * @network: The enumerated type value
+ *
+ * Converts a enumerated type to its text representation
+ *
+ * Return value: the enumerated constant value, e.g. "available"
+ **/
+const gchar *
+pk_network_enum_to_text (PkNetworkEnum network)
+{
+ return pk_enum_find_string (enum_network, network);
+}
+
+/**
* pk_status_enum_from_text:
* @status: Text describing the enumerated type
*
diff --git a/libpackagekit/pk-enum.h b/libpackagekit/pk-enum.h
index a28fa17..b4dc918 100644
--- a/libpackagekit/pk-enum.h
+++ b/libpackagekit/pk-enum.h
@@ -147,6 +147,17 @@ typedef enum {
} PkExitEnum;
/**
+ * PkNetworkEnum:
+ **/
+typedef enum { /* fso */
+ PK_NETWORK_ENUM_OFFLINE = 0, /* 000 */
+ PK_NETWORK_ENUM_ONLINE = 1, /* 001 */
+ PK_NETWORK_ENUM_SLOW = 3, /* 011 */
+ PK_NETWORK_ENUM_FAST = 5, /* 101 */
+ PK_NETWORK_ENUM_UNKNOWN = 7 /* 111 */
+} PkNetworkEnum;
+
+/**
* PkFilterEnum:
*
* The filter types
@@ -505,6 +516,9 @@ const gchar *pk_freq_enum_to_text (PkFreqEnum freq);
PkExitEnum pk_exit_enum_from_text (const gchar *exit);
const gchar *pk_exit_enum_to_text (PkExitEnum exit);
+PkNetworkEnum pk_network_enum_from_text (const gchar *network);
+const gchar *pk_network_enum_to_text (PkNetworkEnum network);
+
PkStatusEnum pk_status_enum_from_text (const gchar *status);
const gchar *pk_status_enum_to_text (PkStatusEnum status);
diff --git a/src/pk-engine.c b/src/pk-engine.c
index a63b6e6..dbab2e6 100644
--- a/src/pk-engine.c
+++ b/src/pk-engine.c
@@ -102,6 +102,7 @@ enum {
PK_ENGINE_LOCKED,
PK_ENGINE_TRANSACTION_LIST_CHANGED,
PK_ENGINE_REPO_LIST_CHANGED,
+ PK_ENGINE_NETWORK_STATE_CHANGED,
PK_ENGINE_RESTART_SCHEDULE,
PK_ENGINE_UPDATES_CHANGED,
PK_ENGINE_LAST_SIGNAL
@@ -257,6 +258,18 @@ pk_engine_get_tid (PkEngine *engine, gchar **tid, GError **error)
}
/**
+ * pk_engine_get_network_state:
+ **/
+gboolean
+pk_engine_get_network_state (PkEngine *engine, gchar **state, GError **error)
+{
+ g_return_val_if_fail (PK_IS_ENGINE (engine), FALSE);
+ //TODO: get the network state
+ *state = g_strdup (pk_network_enum_to_text (PK_NETWORK_ENUM_UNKNOWN));
+ return TRUE;
+}
+
+/**
* pk_engine_get_transaction_list:
**/
gboolean
@@ -454,6 +467,11 @@ pk_engine_class_init (PkEngineClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
0, NULL, NULL, g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ signals [PK_ENGINE_NETWORK_STATE_CHANGED] =
+ g_signal_new ("network-state-changed",
+ G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+ 0, NULL, NULL, g_cclosure_marshal_VOID__STRING,
+ G_TYPE_NONE, 1, G_TYPE_STRING);
signals [PK_ENGINE_UPDATES_CHANGED] =
g_signal_new ("updates-changed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/src/pk-engine.h b/src/pk-engine.h
index 8446611..14b4cca 100644
--- a/src/pk-engine.h
+++ b/src/pk-engine.h
@@ -85,6 +85,9 @@ gboolean pk_engine_get_groups (PkEngine *engine,
gboolean pk_engine_get_tid (PkEngine *engine,
gchar **tid,
GError **error);
+gboolean pk_engine_get_network_state (PkEngine *engine,
+ gchar **state,
+ GError **error);
gboolean pk_engine_get_time_since_action (PkEngine *engine,
const gchar *role_text,
guint *seconds,
diff --git a/src/pk-interface.xml b/src/pk-interface.xml
index a11a194..c2fe870 100644
--- a/src/pk-interface.xml
+++ b/src/pk-interface.xml
@@ -27,6 +27,9 @@
</method>
<method name="StateHasChanged">
</method>
+ <method name="GetNetworkState">
+ <arg type="s" name="state" direction="out"/>
+ </method>
<signal name="TransactionListChanged">
<arg type="as" name="transactions" direction="out"/>
@@ -34,6 +37,9 @@
<signal name="Locked">
<arg type="b" name="is_locked" direction="out"/>
</signal>
+ <signal name="NetworkStateChanged">
+ <arg type="s" name="state" direction="out"/>
+ </signal>
<signal name="RestartSchedule">
</signal>
<signal name="RepoListChanged">
More information about the PackageKit-commit
mailing list