[packagekit] Patch to add connman network stack support

Zhu, Peter J peter.j.zhu at intel.com
Sat May 30 20:28:45 PDT 2009


Hi All,

In case you didn't know what ConnMan is, the Connection Manager provides a daemon for managing internet connections within embedded devices running the Linux operating system. The Connection Manager is designed to be slim and to use as few resources as possible, so it can be easily integrated in other Moblin-based systems.

Here is a patch to to add ConnMan network stack support for PackageKit, which is against Package 0.4.7. Please comments.

diff -urN PackageKit-0.4.7/config.h PackageKit-0.4.7-new/config.h
--- PackageKit-0.4.7/config.h   2009-04-25 04:11:13.000000000 +0800
+++ PackageKit-0.4.7-new/config.h       2009-05-30 15:53:36.000000000 +0800
@@ -14,7 +14,7 @@
 #define GETTEXT_PACKAGE "PackageKit"

 /* Define to 1 if you have the <archive.h> header file. */
-#define HAVE_ARCHIVE_H 1
+/* #undef HAVE_ARCHIVE_H */

 /* Define to 1 if you have the `bind_textdomain_codeset' function. */
 #define HAVE_BIND_TEXTDOMAIN_CODESET 1
@@ -35,7 +35,7 @@
 #define HAVE_EXECINFO_H 1

 /* Define to 1 if you have the `gdk_app_launch_context_new' function. */
-#define HAVE_GDK_APP_LAUNCH_CONTEXT_NEW 1
+/* #undef HAVE_GDK_APP_LAUNCH_CONTEXT_NEW */

 /* Define if the GNU gettext() function is already present or preinstalled. */
 #define HAVE_GETTEXT 1
@@ -113,6 +113,9 @@
 /* Alternative user for running the PackageKit backend */
 #define PK_BACKEND_USER "root"

+/* define if Connection Manager is installed */
+#define PK_BUILD_CONNMAN 1
+
 /* Defined if gcov is enabled to force a rebuild due to config.h changing */
 /* #undef PK_BUILD_GCOV */

@@ -123,10 +126,10 @@
 /* #undef PK_BUILD_GPROF */

 /* Build local code */
-#define PK_BUILD_LOCAL 1
+/* #undef PK_BUILD_LOCAL */

 /* define if NetworkManager is installed */
-#define PK_BUILD_NETWORKMANAGER 1
+/* #undef PK_BUILD_NETWORKMANAGER */

 /* Defined if we have gcc 3.3 and thus the new gcov format */
 /* #undef PK_HAVE_GCC33_GCOV */
diff -urN PackageKit-0.4.7/config.h.in PackageKit-0.4.7-new/config.h.in
--- PackageKit-0.4.7/config.h.in        2009-05-05 23:14:40.000000000 +0800
+++ PackageKit-0.4.7-new/config.h.in    2009-05-30 15:53:36.000000000 +0800
@@ -112,6 +112,9 @@
 /* Alternative user for running the PackageKit backend */
 #undef PK_BACKEND_USER

+/* define if Connection Manager is installed */
+#undef PK_BUILD_CONNMAN
+
 /* Defined if gcov is enabled to force a rebuild due to config.h changing */
 #undef PK_BUILD_GCOV

diff -urN PackageKit-0.4.7/configure.ac PackageKit-0.4.7-new/configure.ac
--- PackageKit-0.4.7/configure.ac       2009-05-05 22:44:31.000000000 +0800
+++ PackageKit-0.4.7-new/configure.ac   2009-05-30 15:53:36.000000000 +0800
@@ -277,6 +277,20 @@
 AC_SUBST(LIBNM_LIBS)

 dnl ---------------------------------------------------------------------------
+dnl - Is ConnMan available?
+dnl ---------------------------------------------------------------------------
+PKG_CHECK_MODULES(CONNMAN, connman, PK_BUILD_CONNMAN="yes", PK_BUILD_CONNMAN="no")
+if test "x$PK_BUILD_CONNMAN" = "xyes"; then
+       with_networking_stack="ConnMan"
+       AC_DEFINE(PK_BUILD_CONNMAN, 1, [define if Connection Manager is installed])
+fi
+
+AM_CONDITIONAL(PK_BUILD_CONNMAN, test x$PK_BUILD_CONNMAN = xyes)
+AC_SUBST(CONNMAN_CFLAGS)
+AC_SUBST(CONNMAN_LIBS)
+
+
+dnl ---------------------------------------------------------------------------
 dnl - Is docbook2man available?
 dnl ---------------------------------------------------------------------------
 AC_PATH_PROG(DOCBOOK2MAN, docbook2man, no)
diff -urN PackageKit-0.4.7/etc/PackageKit.conf.in PackageKit-0.4.7-new/etc/PackageKit.conf.in
--- PackageKit-0.4.7/etc/PackageKit.conf.in     2009-05-05 17:38:10.000000000 +0800
+++ PackageKit-0.4.7-new/etc/PackageKit.conf.in 2009-05-30 15:02:52.000000000 +0800
@@ -13,8 +13,14 @@
 # default=true
 UseNetworkManager=true

-# If NetworkManager is not available, then use the presence of a default
-# route to indicate a viable network connection.
+# Use Connman where available. If disabled, then Connman state will be ignored.
+#
+# default=true
+UseNetworkConnman=true
+
+
+# If neither NetworkManager nor ConnMan is not available, then use the presence
+# of default route to indicate a viable network connection.
 # If disabled, and no NM, then the network is assumed to be always online.
 #
 # default=true
diff -urN PackageKit-0.4.7/src/Makefile.am PackageKit-0.4.7-new/src/Makefile.am
--- PackageKit-0.4.7/src/Makefile.am    2009-05-05 17:38:10.000000000 +0800
+++ PackageKit-0.4.7-new/src/Makefile.am        2009-05-30 20:32:05.000000000 +0800
@@ -15,6 +15,7 @@
        $(POLKIT_CFLAGS)                                \
        $(PYTHON_CFLAGS)                                \
        $(LIBNM_CFLAGS)                                 \
+       $(CONNMAN_CFLAGS)                               \
        -DPACKAGE_LOCALE_DIR=\"$(localedir)\"           \
        -DBINDIR=\"$(bindir)\"                          \
        -DSBINDIR=\"$(sbindir)\"                        \
@@ -63,6 +64,7 @@
        pk-post-trans.c                                 \
        pk-post-trans.h                                 \
        pk-network-nm.h                                 \
+       pk-network-connman.h                            \
        pk-network-unix.c                               \
        pk-network-unix.h                               \
        pk-time.h                                       \
@@ -104,6 +106,14 @@
        pk-network-nm-dummy.c
 endif

+if PK_BUILD_CONNMAN
+shared_SOURCES +=                                      \
+       pk-network-connman.c
+else
+shared_SOURCES +=                                      \
+       pk-network-connman-dummy.c
+endif
+
 if PK_BUILD_GIO
 shared_SOURCES +=                                      \
        pk-file-monitor-gio.c                           \
@@ -135,6 +145,7 @@
        $(GLIB_LIBS)                                    \
        $(GMODULE_LIBS)                                 \
        $(LIBNM_LIBS)                                   \
+       $(CONNMAN_LIBS)                                 \
        $(DBUS_LIBS)                                    \
        $(SQLITE_LIBS)                                  \
        $(PK_GLIB_LIBS)                                 \
@@ -201,6 +212,7 @@
        $(DBUS_LIBS)                                    \
        $(SQLITE_LIBS)                                  \
        $(LIBNM_LIBS)                                   \
+       $(CONNMAN_LIBS)                                 \
        $(PK_GLIB_LIBS)                                 \
        $(POLKIT_LIBS)                                  \
        $(GIO_LIBS)                                     \
diff -urN PackageKit-0.4.7/src/pk-marshal.h PackageKit-0.4.7-new/src/pk-marshal.h
--- PackageKit-0.4.7/src/pk-marshal.h   2009-04-19 18:52:52.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-marshal.h       2009-05-30 20:32:05.000000000 +0800
@@ -297,6 +297,14 @@
                                                 gpointer      invocation_hint,
                                                 gpointer      marshal_data);

+/* VOID:STRING,BOXED (pk-marshal.list:38) */
+extern void pk_marshal_VOID__STRING_BOXED (GClosure     *closure,
+                                           GValue       *return_value,
+                                           guint         n_param_values,
+                                           const GValue *param_values,
+                                           gpointer      invocation_hint,
+                                           gpointer      marshal_data);
+
 G_END_DECLS

 #endif /* __pk_marshal_MARSHAL_H__ */
diff -urN PackageKit-0.4.7/src/pk-marshal.list PackageKit-0.4.7-new/src/pk-marshal.list
--- PackageKit-0.4.7/src/pk-marshal.list        2009-03-26 23:36:06.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-marshal.list    2009-05-30 20:32:05.000000000 +0800
@@ -35,4 +35,4 @@
 VOID:STRING,STRING,BOOL,STRING,UINT,STRING,UINT,STRING
 VOID:POINTER,UINT,STRING
 VOID:POINTER,UINT,UINT
-
+VOID:STRING,BOXED
diff -urN PackageKit-0.4.7/src/pk-network.c PackageKit-0.4.7-new/src/pk-network.c
--- PackageKit-0.4.7/src/pk-network.c   2009-05-05 17:02:35.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-network.c       2009-05-30 20:32:05.000000000 +0800
@@ -46,6 +46,7 @@
 #include "egg-dbus-monitor.h"
 #include "pk-network.h"
 #include "pk-network-nm.h"
+#include "pk-network-connman.h"
 #include "pk-network-unix.h"
 #include "pk-marshal.h"
 #include "pk-conf.h"
@@ -62,11 +63,14 @@
 struct _PkNetworkPrivate
 {
        gboolean                 use_nm;
+       gboolean                 use_connman;
        gboolean                 use_unix;
        PkNetworkNm             *net_nm;
+       PkNetworkConnman        *net_connman;
        PkNetworkUnix           *net_unix;
        PkConf                  *conf;
        EggDbusMonitor          *nm_bus;
+       EggDbusMonitor          *connman_bus;
 };

 enum {
@@ -93,6 +97,8 @@
        /* use the correct backend */
        if (network->priv->use_nm)
                return pk_network_nm_get_network_state (network->priv->net_nm);
+       if (network->priv->use_connman)
+               return pk_network_connman_get_network_state (network->priv->net_connman);
        if (network->priv->use_unix)
                return pk_network_unix_get_network_state (network->priv->net_unix);
        return PK_NETWORK_ENUM_ONLINE;
@@ -113,6 +119,20 @@
 }

 /**
+ * pk_network_connman_network_changed_cb:
+ **/
+static void
+pk_network_connman_network_changed_cb (PkNetworkConnman *net_connman, gboolean online, PkNetwork *network)
+{
+        PkNetworkEnum state;
+
+        g_return_if_fail (PK_IS_NETWORK (network));
+
+        state = pk_network_get_network_state (network);
+        g_signal_emit (network, signals [PK_NETWORK_STATE_CHANGED], 0, state);
+}
+
+/**
  * pk_network_unix_network_changed_cb:
  **/
 static void
@@ -147,18 +167,22 @@
 static void
 pk_network_init (PkNetwork *network)
 {
-       gboolean nm_alive;
+       gboolean nm_alive, connman_alive;
        network->priv = PK_NETWORK_GET_PRIVATE (network);
        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);
+       network->priv->net_connman = pk_network_connman_new ();
+       g_signal_connect (network->priv->net_connman, "state-changed",
+                         G_CALLBACK (pk_network_connman_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);

        /* get the defaults from the config file */
        network->priv->use_nm = pk_conf_get_bool (network->priv->conf, "UseNetworkManager");
+       network->priv->use_connman = pk_conf_get_bool (network->priv->conf, "UseNetworkConnman");
        network->priv->use_unix = pk_conf_get_bool (network->priv->conf, "UseNetworkHeuristic");

        /* check if NM is on the bus */
@@ -178,7 +202,26 @@
                egg_warning ("UseNetworkManager true, but not built with NM support");
                network->priv->use_nm = FALSE;
        }
+#endif
+       /* check if ConnMan is on the bus */
+       network->priv->connman_bus = egg_dbus_monitor_new ();
+       egg_dbus_monitor_assign (network->priv->connman_bus, EGG_DBUS_MONITOR_SYSTEM, "org.moblin.connman");
+       connman_alive = egg_dbus_monitor_is_connected (network->priv->connman_bus);
+
+       /* NetworkManager isn't up, so we can't use it */
+       if (network->priv->use_connman && !connman_alive) {
+               egg_warning ("UseNetworkConnman true, but org.moblin.connman not up");
+               network->priv->use_connman = FALSE;
+       }
+
+#if !PK_BUILD_CONNMAN
+       /* check we can actually use the default */
+       if (network->priv->use_connman) {
+               egg_warning ("UseNetworkConnman true, but not built with ConnMan support");
+               network->priv->use_connman = FALSE;
+       }
 #endif
+
 }

 /**
@@ -196,7 +239,9 @@
        g_return_if_fail (network->priv != NULL);
        g_object_unref (network->priv->conf);
        g_object_unref (network->priv->nm_bus);
+       g_object_unref (network->priv->connman_bus);
        g_object_unref (network->priv->net_nm);
+       g_object_unref (network->priv->net_connman);
        g_object_unref (network->priv->net_unix);
        G_OBJECT_CLASS (pk_network_parent_class)->finalize (object);
 }
diff -urN PackageKit-0.4.7/src/pk-network-connman.c PackageKit-0.4.7-new/src/pk-network-connman.c
--- PackageKit-0.4.7/src/pk-network-connman.c   1970-01-01 08:00:00.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-network-connman.c       2009-05-30 20:32:05.000000000 +0800
@@ -0,0 +1,315 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *
+ * 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 <glib.h>
+#include <dbus/dbus-glib.h>
+
+#include "egg-debug.h"
+#include "pk-network-connman.h"
+#include "pk-marshal.h"
+
+static void     pk_network_connman_finalize            (GObject          *object);
+
+#define PK_NETWORK_CONNMAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK_CONNMAN, PkNetworkConnmanPrivate))
+
+/**
+ * PkNetworkConnmanPrivate:
+ *
+ * Private #PkNetworkConnman data
+ **/
+struct _PkNetworkConnmanPrivate
+{
+       DBusGConnection         *bus;
+        DBusGProxy              *proxy_connman;
+};
+
+enum {
+       PK_NETWORK_CONNMAN_STATE_CHANGED,
+       PK_NETWORK_CONNMAN_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_CONNMAN_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkNetworkConnman, pk_network_connman, G_TYPE_OBJECT)
+
+#define CONNMAN_DBUS_NAME "org.moblin.connman"
+
+
+#define CONNMAN_MANAGER_DBUS_INTERFACE CONNMAN_DBUS_NAME ".Manager"
+#define CONNMAN_SERVICE_DBUS_INTERFACE CONNMAN_DBUS_NAME ".Service"
+#define CONNMAN_MANAGER_DBUS_PATH "/"
+
+
+
+static void iterate_list(const GValue *value, gpointer user_data)
+{
+        GSList **list = user_data;
+        gchar *path = g_value_dup_boxed(value);
+
+        if (path == NULL)
+                return;
+
+        *list = g_slist_append(*list, path);
+}
+
+
+/**
+ *  * pk_network_nm_get_active_connection_type_for_device:
+ *   **/
+static PkNetworkEnum
+pk_network_connman_get_connection_type (const GValue *value)
+{
+        const char *type = value ? g_value_get_string(value) : NULL;
+
+        if (type == NULL)
+                return PK_NETWORK_ENUM_UNKNOWN;
+        else if (g_str_equal(type, "ethernet") == TRUE)
+                return PK_NETWORK_ENUM_WIRED;
+        else if (g_str_equal(type, "wifi") == TRUE)
+                return PK_NETWORK_ENUM_WIFI;
+        else if (g_str_equal(type, "wimax") == TRUE)
+                return PK_NETWORK_ENUM_MOBILE;
+
+        return PK_NETWORK_ENUM_UNKNOWN;
+}
+
+
+
+/**
+ * pk_network_connman_get_network_state:
+ * @network_connman: a valid #PkNetworkConnman instance
+ *
+ * Return value: %TRUE if the network_connman is online
+ **/
+PkNetworkEnum
+pk_network_connman_get_network_state (PkNetworkConnman *network_connman)
+{
+        DBusGProxy *proxy, *proxy_service;
+       GError *error = NULL;
+       GHashTable *hash_manager = NULL, *hash_service = NULL;
+       GValue *value;
+        GSList *list, *services_list = NULL;
+        DBusGConnection *connection = network_connman->priv->bus;
+        gchar *state;
+       PkNetworkEnum type;
+
+       g_return_val_if_fail (PK_IS_NETWORK_CONNMAN (network_connman), PK_NETWORK_ENUM_UNKNOWN);
+       proxy = network_connman->priv->proxy_connman;
+       proxy_service = NULL;
+
+       /* get services  */
+       dbus_g_proxy_call (proxy, "GetProperties", &error, G_TYPE_INVALID,
+               dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &hash_manager, G_TYPE_INVALID);
+
+        if (error != NULL || hash_manager == NULL) {
+               if (error)
+                       g_clear_error (&error);
+               return PK_NETWORK_ENUM_UNKNOWN;
+       }
+
+       value = g_hash_table_lookup(hash_manager, "State");
+        state = value ? g_value_dup_string(value) : NULL;
+
+        if (g_str_equal(state, "online") == FALSE)
+               return PK_NETWORK_ENUM_OFFLINE;
+
+       value = g_hash_table_lookup(hash_manager, "Services");
+        if (value == NULL)
+               return PK_NETWORK_ENUM_UNKNOWN;
+
+       dbus_g_type_collection_value_iterate (value, iterate_list, &services_list);
+
+       for (list = services_list; list; list = list->next) {
+                gchar *path = list->data;
+
+                egg_debug ("service path is %s", path);
+
+                proxy_service = dbus_g_proxy_new_for_name(connection,
+                                                CONNMAN_DBUS_NAME, path, CONNMAN_SERVICE_DBUS_INTERFACE);
+                if (proxy_service != NULL)
+                        break;
+        }
+
+        for (list = services_list; list; list = list->next) {
+               gchar *path = list->data;
+               g_free (path);
+       }
+       g_slist_free (services_list);
+
+       if (proxy_service == NULL)
+               return PK_NETWORK_ENUM_UNKNOWN;
+
+       /* now proxy_service point to first available service*/
+       /* get connection type for it*/
+        dbus_g_proxy_call (proxy_service, "GetProperties", &error, G_TYPE_INVALID,
+                dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), &hash_service, G_TYPE_INVALID);
+
+        if (error != NULL || hash_service == NULL) {
+                if (error)
+                        g_clear_error (&error);
+                return PK_NETWORK_ENUM_OFFLINE;
+        }
+
+        value = g_hash_table_lookup(hash_service, "Type");
+       type = pk_network_connman_get_connection_type (value);
+
+       egg_debug ("network type is %s", pk_network_enum_to_text (type));
+       g_object_unref (proxy_service);
+       return type;
+}
+
+/**
+ * pk_network_connman_state_changed
+ **/
+static void
+pk_network_connman_state_changed (DBusGProxy *proxy, const char *property,
+                                        GValue *value, gpointer user_data)
+{
+       gboolean ret;
+       PkNetworkConnman *network_connman = (PkNetworkConnman *) user_data;
+
+       g_return_if_fail (PK_IS_NETWORK_CONNMAN (network_connman));
+
+       if (g_str_equal(property, "State") == TRUE) {
+                gchar *state;
+
+                state = g_value_dup_string(value);
+               if (g_str_equal(state, "online") == TRUE)
+                       ret = TRUE;
+               else
+                       ret = FALSE;
+               g_signal_emit (network_connman, signals [PK_NETWORK_CONNMAN_STATE_CHANGED], 0, ret);
+        }
+
+}
+
+/**
+ * pk_network_connman_class_init:
+ * @klass: The PkNetworkConnmanClass
+ **/
+static void
+pk_network_connman_class_init (PkNetworkConnmanClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       object_class->finalize = pk_network_connman_finalize;
+       signals [PK_NETWORK_CONNMAN_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 (PkNetworkConnmanPrivate));
+}
+
+/**
+ * pk_network_connman_init:
+ * @network_connman: This class instance
+ **/
+static void
+pk_network_connman_init (PkNetworkConnman *network_connman)
+{
+       GError *error = NULL;
+        DBusGProxy *proxy;
+
+       network_connman->priv = PK_NETWORK_CONNMAN_GET_PRIVATE (network_connman);
+
+        network_connman->priv->proxy_connman = NULL;
+
+        dbus_g_object_register_marshaller(pk_marshal_VOID__STRING_BOXED,
+                                                G_TYPE_NONE, G_TYPE_STRING,
+                                                G_TYPE_VALUE, G_TYPE_INVALID);
+
+       /* get system connection */
+       network_connman->priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+       if (network_connman->priv->bus == NULL) {
+               egg_warning ("Couldn't connect to system bus: %s", error->message);
+               g_error_free (error);
+               return;
+       }
+
+        proxy = dbus_g_proxy_new_for_name_owner (network_connman->priv->bus,
+                       CONNMAN_DBUS_NAME, CONNMAN_MANAGER_DBUS_PATH, CONNMAN_MANAGER_DBUS_INTERFACE, &error);
+       network_connman->priv->proxy_connman = proxy;
+
+        if (error != NULL) {
+                egg_warning ("Cannot connect to connman: %s", error->message);
+                g_error_free (error);
+                return;
+        }
+       dbus_g_proxy_add_signal(proxy, "PropertyChanged",
+                                G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID);
+        dbus_g_proxy_connect_signal(proxy, "PropertyChanged",
+                                G_CALLBACK(pk_network_connman_state_changed), network_connman, NULL);
+
+
+}
+
+/**
+ * pk_network_connman_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_connman_finalize (GObject *object)
+{
+       PkNetworkConnman *network_connman;
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (PK_IS_NETWORK_CONNMAN (object));
+       network_connman = PK_NETWORK_CONNMAN (object);
+
+       g_return_if_fail (network_connman->priv != NULL);
+
+        if (network_connman->priv->proxy_connman != NULL)
+               g_object_unref (network_connman->priv->proxy_connman);
+
+       G_OBJECT_CLASS (pk_network_connman_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_connman_new:
+ *
+ * Return value: a new PkNetworkConnman object.
+ **/
+PkNetworkConnman *
+pk_network_connman_new (void)
+
+{
+       PkNetworkConnman *network_connman;
+       network_connman = g_object_new (PK_TYPE_NETWORK_CONNMAN, NULL);
+       return PK_NETWORK_CONNMAN (network_connman);
+}
+
diff -urN PackageKit-0.4.7/src/pk-network-connman-dummy.c PackageKit-0.4.7-new/src/pk-network-connman-dummy.c
--- PackageKit-0.4.7/src/pk-network-connman-dummy.c     1970-01-01 08:00:00.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-network-connman-dummy.c 2009-05-30 20:32:05.000000000 +0800
@@ -0,0 +1,137 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *
+ * 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 "egg-debug.h"
+#include "pk-network-connman.h"
+#include "pk-marshal.h"
+
+static void     pk_network_connman_finalize            (GObject          *object);
+
+#define PK_NETWORK_CONNMAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PK_TYPE_NETWORK_CONNMAN, PkNetworkConnmanPrivate))
+
+/**
+ * PkNetworkConnmanPrivate:
+ *
+ * Private #PkNetworkConnman data
+ **/
+struct _PkNetworkConnmanPrivate
+{
+       guint                    callback_id;
+};
+
+enum {
+       PK_NETWORK_CONNMAN_STATE_CHANGED,
+       PK_NETWORK_CONNMAN_LAST_SIGNAL
+};
+
+static guint signals [PK_NETWORK_CONNMAN_LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (PkNetworkConnman, pk_network_connman, G_TYPE_OBJECT)
+
+/**
+ * pk_network_connman_get_network_state:
+ * @network_connman: a valid #PkNetworkConnman instance
+ *
+ * Return value: always %TRUE - this method should never be called
+ **/
+PkNetworkEnum
+pk_network_connman_get_network_state (PkNetworkConnman *network_connman)
+{
+       g_return_val_if_fail (PK_IS_NETWORK_CONNMAN (network_connman), PK_NETWORK_ENUM_UNKNOWN);
+       /* don't do any checks */
+       return PK_NETWORK_ENUM_ONLINE;
+}
+
+/**
+ * pk_network_connman_class_init:
+ * @klass: The PkNetworkConnmanClass
+ **/
+static void
+pk_network_connman_class_init (PkNetworkConnmanClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       object_class->finalize = pk_network_connman_finalize;
+       signals [PK_NETWORK_CONNMAN_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 (PkNetworkConnmanPrivate));
+}
+
+/**
+ * pk_network_connman_init:
+ * @network_connman: This class instance
+ **/
+static void
+pk_network_connman_init (PkNetworkConnman *network_connman)
+{
+       network_connman->priv = PK_NETWORK_CONNMAN_GET_PRIVATE (network_connman);
+}
+
+/**
+ * pk_network_connman_finalize:
+ * @object: The object to finalize
+ **/
+static void
+pk_network_connman_finalize (GObject *object)
+{
+       PkNetworkConnman *network_connman;
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (PK_IS_NETWORK_CONNMAN (object));
+       network_connman = PK_NETWORK_CONNMAN (object);
+
+       g_return_if_fail (network_connman->priv != NULL);
+       G_OBJECT_CLASS (pk_network_connman_parent_class)->finalize (object);
+}
+
+/**
+ * pk_network_connman_new:
+ *
+ * Return value: a new PkNetworkConnman object.
+ **/
+PkNetworkConnman *
+pk_network_connman_new (void)
+{
+       PkNetworkConnman *network_connman;
+       network_connman = g_object_new (PK_TYPE_NETWORK_CONNMAN, NULL);
+       return PK_NETWORK_CONNMAN (network_connman);
+}
+
diff -urN PackageKit-0.4.7/src/pk-network-connman.h PackageKit-0.4.7-new/src/pk-network-connman.h
--- PackageKit-0.4.7/src/pk-network-connman.h   1970-01-01 08:00:00.000000000 +0800
+++ PackageKit-0.4.7-new/src/pk-network-connman.h       2009-05-30 20:32:05.000000000 +0800
@@ -0,0 +1,68 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *
+ * 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-connman
+ * @short_description: An ConnmMan access GObject
+ *
+ * This allows a switchable network backend.
+ */
+
+#ifndef __PK_NETWORK_CONNMAN_H
+#define __PK_NETWORK_CONNMAN_H
+
+#include <glib-object.h>
+#include <packagekit-glib/packagekit.h>
+
+G_BEGIN_DECLS
+
+#define PK_TYPE_NETWORK_CONNMAN                (pk_network_connman_get_type ())
+#define PK_NETWORK_CONNMAN(o)          (G_TYPE_CHECK_INSTANCE_CAST ((o), PK_TYPE_NETWORK_CONNMAN, PkNetworkConnman))
+#define PK_NETWORK_CONNMAN_CLASS(k)    (G_TYPE_CHECK_CLASS_CAST((k), PK_TYPE_NETWORK_CONNMAN, PkNetworkConnmanClass))
+#define PK_IS_NETWORK_CONNMAN(o)       (G_TYPE_CHECK_INSTANCE_TYPE ((o), PK_TYPE_NETWORK_CONNMAN))
+#define PK_IS_NETWORK_CONNMAN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PK_TYPE_NETWORK_CONNMAN))
+#define PK_NETWORK_CONNMAN_GET_CLASS(o)        (G_TYPE_INSTANCE_GET_CLASS ((o), PK_TYPE_NETWORK_CONNMAN, PkNetworkConnmanClass))
+#define PK_NETWORK_CONNMAN_ERROR       (pk_network_connman_error_quark ())
+#define PK_NETWORK_CONNMAN_TYPE_ERROR  (pk_network_connman_error_get_type ())
+
+typedef struct _PkNetworkConnmanPrivate        PkNetworkConnmanPrivate;
+typedef struct _PkNetworkConnman       PkNetworkConnman;
+typedef struct _PkNetworkConnmanClass  PkNetworkConnmanClass;
+
+struct _PkNetworkConnman
+{
+        GObject                        parent;
+        PkNetworkConnmanPrivate        *priv;
+};
+
+struct _PkNetworkConnmanClass
+{
+       GObjectClass    parent_class;
+};
+
+GType                  pk_network_connman_get_type             (void);
+PkNetworkConnman*      pk_network_connman_new                  (void);
+PkNetworkEnum          pk_network_connman_get_network_state    (PkNetworkConnman       *network_connman);
+
+G_END_DECLS
+
+#endif /* __PK_NETWORK_CONNMAN_H */
+

Thanks,
Peter



More information about the PackageKit mailing list