[PATCH] libnm-glib: add NMDeviceOlpcMesh



The patch adds OlpcMesh device to libnm-glib.

Jirka
>From dd4d91eabd3b2a3e5cfc92787d34935cdc24d6ba Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes redhat com>
Date: Wed, 22 Feb 2012 13:34:07 +0100
Subject: [PATCH] libnm-glib: add NMDeviceOlpcMesh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit


Signed-off-by: Jiří Klimeš <jklimes redhat com>
---
 include/NetworkManager.h         |    3 +-
 libnm-glib/Makefile.am           |    2 +
 libnm-glib/libnm-glib.ver        |    5 +
 libnm-glib/nm-device-olpc-mesh.c |  312 ++++++++++++++++++++++++++++++++++++++
 libnm-glib/nm-device-olpc-mesh.h |   69 +++++++++
 libnm-glib/nm-device.c           |    5 +
 6 files changed, 395 insertions(+), 1 deletions(-)
 create mode 100644 libnm-glib/nm-device-olpc-mesh.c
 create mode 100644 libnm-glib/nm-device-olpc-mesh.h

diff --git a/include/NetworkManager.h b/include/NetworkManager.h
index 01dd48c..115c0c2 100644
--- a/include/NetworkManager.h
+++ b/include/NetworkManager.h
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2004 - 2011 Red Hat, Inc.
+ * (C) Copyright 2004 - 2012 Red Hat, Inc.
  */
 
 #ifndef NETWORK_MANAGER_H
@@ -36,6 +36,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_DEVICE_MODEM      NM_DBUS_INTERFACE_DEVICE ".Modem"
diff --git a/libnm-glib/Makefile.am b/libnm-glib/Makefile.am
index 0e9c0bd..08d87cc 100644
--- a/libnm-glib/Makefile.am
+++ b/libnm-glib/Makefile.am
@@ -60,6 +60,7 @@ libnminclude_HEADERS = \
 	nm-device-infiniband.h \
 	nm-device-wifi.h \
 	nm-device-bt.h \
+	nm-device-olpc-mesh.h \
 	nm-access-point.h \
 	nm-ip4-config.h \
 	nm-device-modem.h \
@@ -90,6 +91,7 @@ libnm_glib_la_csources = \
 	nm-device-infiniband.c \
 	nm-device-wifi.c \
 	nm-device-bt.c \
+	nm-device-olpc-mesh.c \
 	nm-access-point.c \
 	nm-ip4-config.c \
 	nm-device-modem.c \
diff --git a/libnm-glib/libnm-glib.ver b/libnm-glib/libnm-glib.ver
index 2dbc4a5..4420453 100644
--- a/libnm-glib/libnm-glib.ver
+++ b/libnm-glib/libnm-glib.ver
@@ -98,6 +98,11 @@ global:
 	nm_device_modem_get_modem_capabilities;
 	nm_device_modem_get_type;
 	nm_device_new;
+	nm_device_olpc_mesh_get_active_channel;
+	nm_device_olpc_mesh_get_companion;
+	nm_device_olpc_mesh_get_hw_address;
+	nm_device_olpc_mesh_get_type;
+	nm_device_olpc_mesh_new;
 	nm_device_wifi_get_access_point_by_path;
 	nm_device_wifi_get_access_points;
 	nm_device_wifi_get_active_access_point;
diff --git a/libnm-glib/nm-device-olpc-mesh.c b/libnm-glib/nm-device-olpc-mesh.c
new file mode 100644
index 0000000..8f90112
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.c
@@ -0,0 +1,312 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */
+/*
+ * 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) 2012 Red Hat, Inc.
+ */
+
+#include <config.h>
+#include <string.h>
+
+#include <nm-setting-connection.h>
+#include <nm-setting-olpc-mesh.h>
+
+#include "nm-device-olpc-mesh.h"
+#include "nm-device-private.h"
+#include "nm-object-private.h"
+#include "nm-device-wifi.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;
+	NMDeviceWifi *companion;
+	guint32 active_channel;
+} 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: (transfer full): a new OlpcMesh device
+ **/
+GObject *
+nm_device_olpc_mesh_new (DBusGConnection *connection, const char *path)
+{
+	GObject *device;
+
+	g_return_val_if_fail (connection != NULL, NULL);
+	g_return_val_if_fail (path != NULL, NULL);
+
+	device = g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
+	                     NM_OBJECT_DBUS_CONNECTION, connection,
+	                     NM_OBJECT_DBUS_PATH, path,
+	                     NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (device));
+	return device;
+}
+
+/**
+ * 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)
+{
+	g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (device));
+	return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address;
+}
+
+/**
+ * nm_device_olpc_mesh_get_companion:
+ * @device: a #NMDeviceOlpcMesh
+ *
+ * Gets the companion device of the #NMDeviceOlpcMesh.
+ *
+ * Returns: (transfer none): the companion of the device of %NULL
+ **/
+NMDeviceWifi *
+nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device)
+{
+	g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
+
+	_nm_object_ensure_inited (NM_OBJECT (device));
+	return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion;
+}
+
+/**
+ * nm_device_olpc_mesh_get_active_channel:
+ * @device: a #NMDeviceOlpcMesh
+ *
+ * Returns the active channel of the #NMDeviceOlpcMesh device.
+ *
+ * Returns: active channel of the device
+ **/
+guint32
+nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device)
+{
+	g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), 0);
+
+	_nm_object_ensure_inited (NM_OBJECT (device));
+	return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->active_channel;
+}
+
+static gboolean
+connection_valid (NMDevice *device, NMConnection *connection)
+{
+	NMSettingConnection *s_con;
+	NMSettingOlpcMesh *s_olpc_mesh;
+	const char *ctype;
+
+	s_con = nm_connection_get_setting_connection (connection);
+	g_assert (s_con);
+
+	ctype = nm_setting_connection_get_connection_type (s_con);
+	if (strcmp (ctype, NM_SETTING_OLPC_MESH_SETTING_NAME) != 0)
+		return FALSE;
+
+	s_olpc_mesh = nm_connection_get_setting_olpc_mesh (connection);
+	if (!s_olpc_mesh)
+		return FALSE;
+
+	return TRUE;
+}
+
+/**************************************************************/
+
+static void
+nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
+{
+	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+
+	priv->hw_address = NULL;
+	priv->companion = NULL;
+	priv->active_channel = 0;
+}
+
+static void
+register_properties (NMDeviceOlpcMesh *device)
+{
+	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
+	const NMPropertiesInfo property_info[] = {
+		{ NM_DEVICE_OLPC_MESH_HW_ADDRESS,     &priv->hw_address },
+		{ NM_DEVICE_OLPC_MESH_COMPANION,      &priv->companion, NULL, NM_TYPE_DEVICE_WIFI },
+		{ NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, &priv->active_channel },
+		{ NULL },
+	};
+
+	_nm_object_register_properties (NM_OBJECT (device),
+	                                priv->proxy,
+	                                property_info);
+}
+
+static void
+constructed (GObject *object)
+{
+	NMDeviceOlpcMeshPrivate *priv;
+
+	G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->constructed (object);
+
+	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_properties (NM_DEVICE_OLPC_MESH (object));
+}
+
+static void
+dispose (GObject *object)
+{
+	NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
+
+	if (priv->companion) {
+		g_object_unref (priv->companion);
+		priv->companion = NULL;
+	}
+	if (priv->proxy) {
+		g_object_unref (priv->proxy);
+		priv->proxy = NULL;
+	}
+
+	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 *olpc_mesh_class)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (olpc_mesh_class);
+	NMDeviceClass *device_class = NM_DEVICE_CLASS (olpc_mesh_class);
+
+	g_type_class_add_private (olpc_mesh_class, sizeof (NMDeviceOlpcMeshPrivate));
+
+	/* virtual methods */
+	object_class->constructed = constructed;
+	object_class->dispose = dispose;
+	object_class->finalize = finalize;
+	object_class->get_property = get_property;
+	device_class->connection_valid = connection_valid;
+
+	/* 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..0b04b76
--- /dev/null
+++ b/libnm-glib/nm-device-olpc-mesh.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
+/* vim: set ft=c ts=4 sts=4 sw=4 noexpandtab smartindent: */
+/*
+ * 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) 2012 Red Hat, Inc.
+ */
+
+#ifndef NM_DEVICE_OLPC_MESH_H
+#define NM_DEVICE_OLPC_MESH_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 */
diff --git a/libnm-glib/nm-device.c b/libnm-glib/nm-device.c
index a5f1a5c..911af7c 100644
--- a/libnm-glib/nm-device.c
+++ b/libnm-glib/nm-device.c
@@ -30,6 +30,7 @@
 #include "nm-device-wifi.h"
 #include "nm-device-modem.h"
 #include "nm-device-bt.h"
+#include "nm-device-olpc-mesh.h"
 #include "nm-device-wimax.h"
 #include "nm-device-infiniband.h"
 #include "nm-device.h"
@@ -628,6 +629,8 @@ _nm_device_gtype_from_dtype (NMDeviceType dtype)
 		return NM_TYPE_DEVICE_MODEM;
 	case NM_DEVICE_TYPE_BT:
 		return NM_TYPE_DEVICE_BT;
+	case NM_DEVICE_TYPE_OLPC_MESH:
+		return NM_TYPE_DEVICE_OLPC_MESH;
 	case NM_DEVICE_TYPE_WIMAX:
 		return NM_TYPE_DEVICE_WIMAX;
 	case NM_DEVICE_TYPE_INFINIBAND:
@@ -822,6 +825,8 @@ nm_device_get_device_type (NMDevice *self)
 			priv->device_type = NM_DEVICE_TYPE_MODEM;
 		else if (NM_IS_DEVICE_BT (self))
 			priv->device_type = NM_DEVICE_TYPE_BT;
+		else if (NM_IS_DEVICE_OLPC_MESH (self))
+			priv->device_type = NM_DEVICE_TYPE_OLPC_MESH;
 		else if (NM_IS_DEVICE_WIMAX (self))
 			priv->device_type = NM_DEVICE_TYPE_WIMAX;
 		else if (NM_IS_DEVICE_INFINIBAND (self))
-- 
1.7.7.6



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]