[PATCH] Adding OLPC Mesh device to libnm-glib library



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?

Thanks,
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..0e6d8b0
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.c
@@ -0,0 +1,304 @@
+/* -*- 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 "nm-device-olpc-mesh.h"
+#include "nm-device-private.h"
+#include "nm-object-private.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))
+
+typedef struct {
+	DBusGProxy *proxy;
+
+	char *hw_address;
+	char *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 name of the companion device of the #NMDeviceOlpcMesh.
+ *
+ * Returns: the companion of the device
+ **/
+const char *
+nm_device_olpc_mesh_get_companion (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->companion) {
+		priv->companion = _nm_object_get_string_property (NM_OBJECT (device),
+		                                                  NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
+		                                                  DBUS_PROP_COMPANION);
+	}
+
+	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)
+{
+}
+
+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,      _nm_object_demarshal_generic, &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;
+
+	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_free (priv->companion);
+
+	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_string (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 name of the companion device.
+	 **/
+	g_object_class_install_property
+		(object_class, PROP_COMPANION,
+		 g_param_spec_string (NM_DEVICE_OLPC_MESH_COMPANION,
+		                      "Companion device",
+		                      "Companion device object path",
+		                      NULL,
+		                      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..52198ad
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.h
@@ -0,0 +1,70 @@
+/* -*- 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"
+
+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);
+
+const char *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]