1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301 USA.
18 * Copyright 2012 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-setting-connection.h"
26 #include "nm-setting-olpc-mesh.h"
28 #include "nm-device-olpc-mesh.h"
29 #include "nm-device-private.h"
30 #include "nm-object-private.h"
31 #include "nm-device-wifi.h"
33 G_DEFINE_TYPE (NMDeviceOlpcMesh, nm_device_olpc_mesh, NM_TYPE_DEVICE)
35 #define NM_DEVICE_OLPC_MESH_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_OLPC_MESH, NMDeviceOlpcMeshPrivate))
41 NMDeviceWifi *companion;
42 guint32 active_channel;
43 } NMDeviceOlpcMeshPrivate;
55 * nm_device_olpc_mesh_error_quark:
57 * Registers an error quark for #NMDeviceOlpcMesh if necessary.
59 * Returns: the error quark used for #NMDeviceOlpcMesh errors.
62 nm_device_olpc_mesh_error_quark (void)
64 static GQuark quark = 0;
66 if (G_UNLIKELY (quark == 0))
67 quark = g_quark_from_static_string ("nm-device-olpc-mesh-error-quark");
72 * nm_device_olpc_mesh_new:
73 * @connection: the #DBusGConnection
74 * @path: the DBus object path of the device
76 * Creates a new #NMDeviceOlpcMesh.
78 * Returns: (transfer full): a new OlpcMesh device
81 nm_device_olpc_mesh_new (DBusGConnection *connection, const char *path)
85 g_return_val_if_fail (connection != NULL, NULL);
86 g_return_val_if_fail (path != NULL, NULL);
88 device = g_object_new (NM_TYPE_DEVICE_OLPC_MESH,
89 NM_OBJECT_DBUS_CONNECTION, connection,
90 NM_OBJECT_DBUS_PATH, path,
93 _nm_object_ensure_inited (NM_OBJECT (device));
98 * nm_device_olpc_mesh_get_hw_address:
99 * @device: a #NMDeviceOlpcMesh
101 * Gets the hardware (MAC) address of the #NMDeviceOlpcMesh
103 * Returns: the hardware address. This is the internal string used by the
104 * device, and must not be modified.
107 nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device)
109 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
111 _nm_object_ensure_inited (NM_OBJECT (device));
112 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address;
116 * nm_device_olpc_mesh_get_companion:
117 * @device: a #NMDeviceOlpcMesh
119 * Gets the companion device of the #NMDeviceOlpcMesh.
121 * Returns: (transfer none): the companion of the device of %NULL
124 nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device)
126 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
128 _nm_object_ensure_inited (NM_OBJECT (device));
129 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion;
133 * nm_device_olpc_mesh_get_active_channel:
134 * @device: a #NMDeviceOlpcMesh
136 * Returns the active channel of the #NMDeviceOlpcMesh device.
138 * Returns: active channel of the device
141 nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device)
143 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), 0);
145 _nm_object_ensure_inited (NM_OBJECT (device));
146 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->active_channel;
150 get_hw_address (NMDevice *device)
152 return nm_device_olpc_mesh_get_hw_address (NM_DEVICE_OLPC_MESH (device));
156 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
158 NMSettingConnection *s_con;
159 NMSettingOlpcMesh *s_olpc_mesh;
162 s_con = nm_connection_get_setting_connection (connection);
165 ctype = nm_setting_connection_get_connection_type (s_con);
166 if (strcmp (ctype, NM_SETTING_OLPC_MESH_SETTING_NAME) != 0) {
167 g_set_error (error, NM_DEVICE_OLPC_MESH_ERROR, NM_DEVICE_OLPC_MESH_ERROR_NOT_OLPC_MESH_CONNECTION,
168 "The connection was not a Olpc Mesh connection.");
172 s_olpc_mesh = nm_connection_get_setting_olpc_mesh (connection);
174 g_set_error (error, NM_DEVICE_OLPC_MESH_ERROR, NM_DEVICE_OLPC_MESH_ERROR_INVALID_OLPC_MESH_CONNECTION,
175 "The connection was not a valid Olpc Mesh connection.");
179 return NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->connection_compatible (device, connection, error);
183 get_setting_type (NMDevice *device)
185 return NM_TYPE_SETTING_OLPC_MESH;
188 /**************************************************************/
191 nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
193 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_OLPC_MESH);
197 register_properties (NMDeviceOlpcMesh *device)
199 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (device);
200 const NMPropertiesInfo property_info[] = {
201 { NM_DEVICE_OLPC_MESH_HW_ADDRESS, &priv->hw_address },
202 { NM_DEVICE_OLPC_MESH_COMPANION, &priv->companion, NULL, NM_TYPE_DEVICE_WIFI },
203 { NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, &priv->active_channel },
207 _nm_object_register_properties (NM_OBJECT (device),
213 constructed (GObject *object)
215 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
217 G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->constructed (object);
219 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_OLPC_MESH);
220 register_properties (NM_DEVICE_OLPC_MESH (object));
224 dispose (GObject *object)
226 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
228 g_clear_object (&priv->companion);
229 g_clear_object (&priv->proxy);
231 G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
235 finalize (GObject *object)
237 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
239 g_free (priv->hw_address);
241 G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->finalize (object);
245 get_property (GObject *object,
250 NMDeviceOlpcMesh *device = NM_DEVICE_OLPC_MESH (object);
252 _nm_object_ensure_inited (NM_OBJECT (object));
255 case PROP_HW_ADDRESS:
256 g_value_set_string (value, nm_device_olpc_mesh_get_hw_address (device));
259 g_value_set_object (value, nm_device_olpc_mesh_get_companion (device));
261 case PROP_ACTIVE_CHANNEL:
262 g_value_set_uint (value, nm_device_olpc_mesh_get_active_channel (device));
265 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
271 nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class)
273 GObjectClass *object_class = G_OBJECT_CLASS (olpc_mesh_class);
274 NMDeviceClass *device_class = NM_DEVICE_CLASS (olpc_mesh_class);
276 g_type_class_add_private (olpc_mesh_class, sizeof (NMDeviceOlpcMeshPrivate));
278 /* virtual methods */
279 object_class->constructed = constructed;
280 object_class->dispose = dispose;
281 object_class->finalize = finalize;
282 object_class->get_property = get_property;
283 device_class->connection_compatible = connection_compatible;
284 device_class->get_setting_type = get_setting_type;
285 device_class->get_hw_address = get_hw_address;
290 * NMDeviceOlpcMesh:hw-address:
292 * The hardware (MAC) address of the device.
294 g_object_class_install_property
295 (object_class, PROP_HW_ADDRESS,
296 g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS, "", "",
299 G_PARAM_STATIC_STRINGS));
302 * NMDeviceOlpcMesh:companion:
304 * The companion device.
306 g_object_class_install_property
307 (object_class, PROP_COMPANION,
308 g_param_spec_object (NM_DEVICE_OLPC_MESH_COMPANION, "", "",
311 G_PARAM_STATIC_STRINGS));
314 * NMDeviceOlpcMesh:active-channel:
316 * The device's active channel.
318 g_object_class_install_property
319 (object_class, PROP_ACTIVE_CHANNEL,
320 g_param_spec_uint (NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, "", "",
323 G_PARAM_STATIC_STRINGS));