Re: [PATCH] Adding OLPC Mesh device to libnm-glib library
- From: Jirka Klimes <jklimes redhat com>
- To: Dan Williams <dcbw redhat com>
- Cc: networkmanager-list gnome org
- Subject: Re: [PATCH] Adding OLPC Mesh device to libnm-glib library
- Date: Tue, 19 Jan 2010 14:06:30 +0100
On Thursday 14 January 2010 23:36:32 Dan Williams wrote:
> On Wed, 2010-01-13 at 11:43 -0800, Dan Williams wrote:
> > On Tue, 2010-01-12 at 14:40 +0100, Jirka Klimes wrote:
> > > Hello,
> > > libnm-glib is missing OLPC device support, even if NM contains it and
> > > exports via DBus.
> > >
> > > This patch adds the device to libnm-glib library.
> > > Could someone review and possibly test?
> >
> > Bother; found out that the olpc-mesh device Companion property should
> > really be an object path instead of a string, like the wifi device's
> > active-ap property is. I'll need to fix up the NM side of this and then
> > you can respin this patch with the right bits to expose the companion
> > device as a real NMDeviceWifi object instead...
>
> Now fixed up in master and stable. Companion property is now an object
> path.
>
> Dan
>
Great; patch respin with the companion property as NMDeviceWifi.
Jirka
diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index c8d5074..cf4c7f9 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -33,6 +33,7 @@
#define NM_DBUS_INTERFACE_DEVICE_WIRED NM_DBUS_INTERFACE_DEVICE ".Wired"
#define NM_DBUS_INTERFACE_DEVICE_WIRELESS NM_DBUS_INTERFACE_DEVICE ".Wireless"
#define NM_DBUS_INTERFACE_DEVICE_BLUETOOTH NM_DBUS_INTERFACE_DEVICE ".Bluetooth"
+#define NM_DBUS_INTERFACE_DEVICE_OLPC_MESH NM_DBUS_INTERFACE_DEVICE ".OlpcMesh"
#define NM_DBUS_PATH_ACCESS_POINT NM_DBUS_PATH "/AccessPoint"
#define NM_DBUS_INTERFACE_ACCESS_POINT NM_DBUS_INTERFACE ".AccessPoint"
#define NM_DBUS_INTERFACE_SERIAL_DEVICE NM_DBUS_INTERFACE_DEVICE ".Serial"
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index 2aa6124..b422db8 100644
--- a/libnm-glib/Makefile.am
+++ b/libnm-glib/Makefile.am
@@ -10,6 +10,7 @@ BUILT_SOURCES = \
nm-device-ethernet-bindings.h \
nm-device-wifi-bindings.h \
nm-device-bt-bindings.h \
+ nm-device-olpc-mesh-bindings.h \
nm-exported-connection-glue.h \
nm-exported-connection-bindings.h \
nm-settings-glue.h \
@@ -40,6 +41,7 @@ libnminclude_HEADERS = \
nm-device-ethernet.h \
nm-device-wifi.h \
nm-device-bt.h \
+ nm-device-olpc-mesh.h \
nm-access-point.h \
nm-ip4-config.h \
nm-gsm-device.h \
@@ -73,6 +75,7 @@ libnm_glib_la_SOURCES = \
nm-device-ethernet.c \
nm-device-wifi.c \
nm-device-bt.c \
+ nm-device-olpc-mesh.c \
nm-access-point.c \
nm-ip4-config.c \
nm-gsm-device.c \
@@ -136,6 +139,9 @@ nm-device-wifi-bindings.h: $(top_srcdir)/introspection/nm-device-wifi.xml
nm-device-bt-bindings.h: $(top_srcdir)/introspection/nm-device-bt.xml
dbus-binding-tool --prefix=nm_device_bt --mode=glib-client --output=$@ $<
+nm-device-olpc-mesh-bindings.h: $(top_srcdir)/introspection/nm-device-olpc-mesh.xml
+ dbus-binding-tool --prefix=nm_device_olpc_mesh --mode=glib-client --output=$@ $<
+
nm-access-point-bindings.h: $(top_srcdir)/introspection/nm-access-point.xml
dbus-binding-tool --prefix=nm_access_point --mode=glib-client --output=$@ $<
diff --git a/libnm-glib/nm-device-olpc-mesh.c b/libnm-glib/nm-device-olpc-mesh.c
new file mode 100644
index 0000000..973414a
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.c
@@ -0,0 +1,370 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm-glib -- Access network status & information from glib applications
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ */
+
+#include <string.h>
+
+#include "nm-device-olpc-mesh.h"
+#include "nm-device-private.h"
+#include "nm-object-private.h"
+#include "nm-object-cache.h"
+#include "nm-device-wifi.h"
+
+#include "nm-device-olpc-mesh-bindings.h"
+
+G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE)
+
+#define NM_DEVICE_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshPrivate))
+
+static gboolean demarshal_companion (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field);
+
+typedef struct {
+ DBusGProxy *proxy;
+
+ char *hw_address;
+ NMDeviceWifi *companion;
+ gboolean null_companion;
+ guint32 active_channel;
+
+ gboolean disposed;
+} NMDeviceOlpcMeshPrivate;
+
+enum {
+ PROP_0,
+ PROP_HW_ADDRESS,
+ PROP_COMPANION,
+ PROP_ACTIVE_CHANNEL,
+
+ LAST_PROP
+};
+
+#define DBUS_PROP_HW_ADDRESS "HwAddress"
+#define DBUS_PROP_COMPANION "Companion"
+#define DBUS_PROP_ACTIVE_CHANNEL "ActiveChannel"
+
+/**
+ * nm_device_olpc_mesh_new:
+ * @connection: the #DBusGConnection
+ * @path: the DBus object path of the device
+ *
+ * Creates a new #NMDeviceOlpcMesh.
+ *
+ * Returns: a new device
+ **/
+GObject *
+nm_device_olpc_mesh_new (DBusGConnection *connection, const char *path)
+{
+ g_return_val_if_fail (connection != NULL, NULL);
+ g_return_val_if_fail (path != NULL, NULL);
+
+ return g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
+ NM_OBJECT_DBUS_CONNECTION, connection,
+ NM_OBJECT_DBUS_PATH, path,
+ NULL);
+}
+
+/**
+ * nm_device_olpc_mesh_get_hw_address:
+ * @device: a #NMDeviceOlpcMesh
+ *
+ * Gets the hardware (MAC) address of the #NMDeviceOlpcMesh
+ *
+ * Returns: the hardware address. This is the internal string used by the
+ * device, and must not be modified.
+ **/
+const char *
+nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device)
+{
+ NMDeviceOlpcMeshPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
+
+ priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+ if (!priv->hw_address) {
+ priv->hw_address = _nm_object_get_string_property (NM_OBJECT (device),
+ NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
+ DBUS_PROP_HW_ADDRESS);
+ }
+
+ return priv->hw_address;
+}
+
+/**
+ * nm_device_olpc_mesh_get_companion:
+ * @device: a #NMDeviceOlpcMesh
+ *
+ * Gets the companion device of the #NMDeviceOlpcMesh.
+ *
+ * Returns: the companion of the device
+ **/
+NMDeviceWifi *
+nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device)
+{
+ NMDeviceOlpcMeshPrivate *priv;
+ char *path;
+ GValue value = { 0 };
+
+ g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
+
+ priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+ if (priv->companion)
+ return priv->companion;
+ if (priv->null_companion)
+ return NULL;
+
+ path = _nm_object_get_object_path_property (NM_OBJECT (device),
+ NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
+ DBUS_PROP_COMPANION);
+ if (path) {
+ g_value_init (&value, DBUS_TYPE_G_OBJECT_PATH);
+ g_value_take_boxed (&value, path);
+ demarshal_companion (NM_OBJECT (device), NULL, &value, &priv->companion);
+ g_value_unset (&value);
+ }
+
+ return priv->companion;
+}
+
+/**
+ * nm_device_olpc_mesh_get_active_channel:
+ * @device: a #NMDeviceOlpcMesh
+ *
+ * Returns the ative channel of the OLPC device.
+ *
+ * Returns: active channel of the device
+ **/
+guint32
+nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device)
+{
+ NMDeviceOlpcMeshPrivate *priv;
+
+ g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), 0);
+
+ priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+ if (!priv->active_channel) {
+ priv->active_channel = _nm_object_get_uint_property (NM_OBJECT (device),
+ NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
+ DBUS_PROP_ACTIVE_CHANNEL);
+ }
+
+ return priv->active_channel;
+}
+
+static void
+nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
+{
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+
+ priv->companion = NULL;
+ priv->null_companion = FALSE;
+ priv->disposed = FALSE;
+}
+
+static gboolean
+demarshal_companion (NMObject *object, GParamSpec *pspec, GValue *value, gpointer field)
+{
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
+ const char *path;
+ NMDeviceWifi *companion = NULL;
+ DBusGConnection *connection;
+
+ if (!G_VALUE_HOLDS (value, DBUS_TYPE_G_OBJECT_PATH))
+ return FALSE;
+
+ priv->null_companion = FALSE;
+
+ path = g_value_get_boxed (value);
+ if (path) {
+ if (!strcmp (path, "/"))
+ priv->null_companion = TRUE;
+ else {
+ companion = NM_DEVICE_WIFI (_nm_object_cache_get (path));
+ if (companion)
+ companion = g_object_ref (companion);
+ else {
+ connection = nm_object_get_connection (object);
+ companion = NM_DEVICE_WIFI (nm_device_wifi_new (connection, path));
+ }
+ }
+ }
+
+ if (priv->companion) {
+ g_object_unref (priv->companion);
+ priv->companion = NULL;
+ }
+
+ if (companion)
+ priv->companion = companion;
+
+ _nm_object_queue_notify (object, NM_DEVICE_OLPC_MESH_COMPANION);
+ return TRUE;
+}
+
+static void
+register_for_property_changed (NMDeviceOlpcMesh *device)
+{
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+ const NMPropertiesChangedInfo property_changed_info[] = {
+ { NM_DEVICE_OLPC_MESH_HW_ADDRESS, _nm_object_demarshal_generic, &priv->hw_address },
+ { NM_DEVICE_OLPC_MESH_COMPANION, demarshal_companion, &priv->companion },
+ { NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, _nm_object_demarshal_generic, &priv->active_channel },
+ { NULL },
+ };
+
+ _nm_object_handle_properties_changed (NM_OBJECT (device),
+ priv->proxy,
+ property_changed_info);
+}
+
+static GObject*
+constructor (GType type,
+ guint n_construct_params,
+ GObjectConstructParam *construct_params)
+{
+ GObject *object;
+
+ object = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->constructor (type,
+ n_construct_params,
+ construct_params);
+ if (object) {
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
+
+ priv->proxy = dbus_g_proxy_new_for_name (nm_object_get_connection (NM_OBJECT (object)),
+ NM_DBUS_SERVICE,
+ nm_object_get_path (NM_OBJECT (object)),
+ NM_DBUS_INTERFACE_DEVICE_OLPC_MESH);
+
+ register_for_property_changed (NM_DEVICE_OLPC_MESH (object));
+ }
+
+ return object;
+}
+
+static void
+dispose (GObject *object)
+{
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
+
+ if (priv->disposed) {
+ G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
+ return;
+ }
+ priv->disposed = TRUE;
+
+ if (priv->companion) {
+ g_object_unref (priv->companion);
+ priv->companion = NULL;
+ }
+ g_object_unref (priv->proxy);
+
+ G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
+}
+
+static void
+finalize (GObject *object)
+{
+ NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
+
+ g_free (priv->hw_address);
+
+ G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->finalize (object);
+}
+
+static void
+get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ NMDeviceOlpcMesh *device = NM_DEVICE_OLPC_MESH (object);
+
+ switch (prop_id) {
+ case PROP_HW_ADDRESS:
+ g_value_set_string (value, nm_device_olpc_mesh_get_hw_address (device));
+ break;
+ case PROP_COMPANION:
+ g_value_set_object (value, nm_device_olpc_mesh_get_companion (device));
+ break;
+ case PROP_ACTIVE_CHANNEL:
+ g_value_set_uint (value, nm_device_olpc_mesh_get_active_channel (device));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *device_class)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (device_class);
+
+ g_type_class_add_private (device_class, sizeof (NMDeviceOlpcMeshPrivate));
+
+ /* virtual methods */
+ object_class->constructor = constructor;
+ object_class->dispose = dispose;
+ object_class->finalize = finalize;
+ object_class->get_property = get_property;
+
+ /* properties */
+
+ /**
+ * NMDeviceOlpcMesh:hw-address:
+ *
+ * The hardware (MAC) address of the device.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_HW_ADDRESS,
+ g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS,
+ "MAC Address",
+ "Hardware MAC address",
+ NULL,
+ G_PARAM_READABLE));
+
+ /**
+ * NMDeviceOlpcMesh:companion:
+ *
+ * The companion device.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_COMPANION,
+ g_param_spec_object (NM_DEVICE_OLPC_MESH_COMPANION,
+ "Companion device",
+ "Companion device",
+ NM_TYPE_DEVICE_WIFI,
+ G_PARAM_READABLE));
+
+ /**
+ * NMDeviceOlpcMesh:active-channel:
+ *
+ * The device's active channel.
+ **/
+ g_object_class_install_property
+ (object_class, PROP_ACTIVE_CHANNEL,
+ g_param_spec_uint (NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL,
+ "Active channel",
+ "Active channel",
+ 0, G_MAXUINT32, 0,
+ G_PARAM_READABLE));
+
+}
+
diff --git a/libnm-glib/nm-device-olpc-mesh.h b/libnm-glib/nm-device-olpc-mesh.h
new file mode 100644
index 0000000..ec2687d
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.h
@@ -0,0 +1,71 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/*
+ * libnm-glib -- Access network status & information from glib applications
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ */
+
+#ifndef NM_DEVICE_OLPC_MESH_H
+#define NM_DEVICE_OLPC_MESH_H
+
+#include "NetworkManager.h"
+#include "nm-device.h"
+#include "nm-device-wifi.h"
+
+G_BEGIN_DECLS
+
+#define NM_TYPE_DEVICE_OLPC_MESH (nm_device_olpc_mesh_get_type ())
+#define NM_DEVICE_OLPC_MESH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMesh))
+#define NM_DEVICE_OLPC_MESH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshClass))
+#define NM_IS_DEVICE_OLPC_MESH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_DEVICE_OLPC_MESH))
+#define NM_IS_DEVICE_OLPC_MESH_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_DEVICE_OLPC_MESH))
+#define NM_DEVICE_OLPC_MESH_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshClass))
+
+#define NM_DEVICE_OLPC_MESH_HW_ADDRESS "hw-address"
+#define NM_DEVICE_OLPC_MESH_COMPANION "companion"
+#define NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL "active-channel"
+
+typedef struct {
+ NMDevice parent;
+} NMDeviceOlpcMesh;
+
+typedef struct {
+ NMDeviceClass parent;
+
+ /* Padding for future expansion */
+ void (*_reserved1) (void);
+ void (*_reserved2) (void);
+ void (*_reserved3) (void);
+ void (*_reserved4) (void);
+ void (*_reserved5) (void);
+ void (*_reserved6) (void);
+} NMDeviceOlpcMeshClass;
+
+GType nm_device_olpc_mesh_get_type (void);
+
+GObject *nm_device_olpc_mesh_new (DBusGConnection *connection, const char *path);
+
+const char *nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device);
+
+NMDeviceWifi *nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device);
+
+guint32 nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device);
+
+G_END_DECLS
+
+#endif /* NM_DEVICE_OLPC_MESH_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]