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))
39 NMDeviceWifi *companion;
40 guint32 active_channel;
41 } NMDeviceOlpcMeshPrivate;
53 * nm_device_olpc_mesh_get_hw_address:
54 * @device: a #NMDeviceOlpcMesh
56 * Gets the hardware (MAC) address of the #NMDeviceOlpcMesh
58 * Returns: the hardware address. This is the internal string used by the
59 * device, and must not be modified.
62 nm_device_olpc_mesh_get_hw_address (NMDeviceOlpcMesh *device)
64 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
66 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->hw_address;
70 * nm_device_olpc_mesh_get_companion:
71 * @device: a #NMDeviceOlpcMesh
73 * Gets the companion device of the #NMDeviceOlpcMesh.
75 * Returns: (transfer none): the companion of the device of %NULL
78 nm_device_olpc_mesh_get_companion (NMDeviceOlpcMesh *device)
80 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), NULL);
82 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->companion;
86 * nm_device_olpc_mesh_get_active_channel:
87 * @device: a #NMDeviceOlpcMesh
89 * Returns the active channel of the #NMDeviceOlpcMesh device.
91 * Returns: active channel of the device
94 nm_device_olpc_mesh_get_active_channel (NMDeviceOlpcMesh *device)
96 g_return_val_if_fail (NM_IS_DEVICE_OLPC_MESH (device), 0);
98 return NM_DEVICE_OLPC_MESH_GET_PRIVATE (device)->active_channel;
102 get_hw_address (NMDevice *device)
104 return nm_device_olpc_mesh_get_hw_address (NM_DEVICE_OLPC_MESH (device));
108 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
110 if (!NM_DEVICE_CLASS (nm_device_olpc_mesh_parent_class)->connection_compatible (device, connection, error))
113 if (!nm_connection_is_type (connection, NM_SETTING_OLPC_MESH_SETTING_NAME)) {
114 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
115 _("The connection was not an OLPC Mesh connection."));
123 get_setting_type (NMDevice *device)
125 return NM_TYPE_SETTING_OLPC_MESH;
128 /**************************************************************/
131 nm_device_olpc_mesh_init (NMDeviceOlpcMesh *device)
133 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_OLPC_MESH);
137 init_dbus (NMObject *object)
139 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
140 const NMPropertiesInfo property_info[] = {
141 { NM_DEVICE_OLPC_MESH_HW_ADDRESS, &priv->hw_address },
142 { NM_DEVICE_OLPC_MESH_COMPANION, &priv->companion, NULL, NM_TYPE_DEVICE_WIFI },
143 { NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, &priv->active_channel },
147 NM_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->init_dbus (object);
149 _nm_object_register_properties (object,
150 NM_DBUS_INTERFACE_DEVICE_OLPC_MESH,
155 dispose (GObject *object)
157 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
159 g_clear_object (&priv->companion);
161 G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object);
165 finalize (GObject *object)
167 NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (object);
169 g_free (priv->hw_address);
171 G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->finalize (object);
175 get_property (GObject *object,
180 NMDeviceOlpcMesh *device = NM_DEVICE_OLPC_MESH (object);
183 case PROP_HW_ADDRESS:
184 g_value_set_string (value, nm_device_olpc_mesh_get_hw_address (device));
187 g_value_set_object (value, nm_device_olpc_mesh_get_companion (device));
189 case PROP_ACTIVE_CHANNEL:
190 g_value_set_uint (value, nm_device_olpc_mesh_get_active_channel (device));
193 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
199 nm_device_olpc_mesh_class_init (NMDeviceOlpcMeshClass *olpc_mesh_class)
201 GObjectClass *object_class = G_OBJECT_CLASS (olpc_mesh_class);
202 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (olpc_mesh_class);
203 NMDeviceClass *device_class = NM_DEVICE_CLASS (olpc_mesh_class);
205 g_type_class_add_private (olpc_mesh_class, sizeof (NMDeviceOlpcMeshPrivate));
207 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_OLPC_MESH);
209 /* virtual methods */
210 object_class->dispose = dispose;
211 object_class->finalize = finalize;
212 object_class->get_property = get_property;
214 nm_object_class->init_dbus = init_dbus;
216 device_class->connection_compatible = connection_compatible;
217 device_class->get_setting_type = get_setting_type;
218 device_class->get_hw_address = get_hw_address;
223 * NMDeviceOlpcMesh:hw-address:
225 * The hardware (MAC) address of the device.
227 g_object_class_install_property
228 (object_class, PROP_HW_ADDRESS,
229 g_param_spec_string (NM_DEVICE_OLPC_MESH_HW_ADDRESS, "", "",
232 G_PARAM_STATIC_STRINGS));
235 * NMDeviceOlpcMesh:companion:
237 * The companion device.
239 g_object_class_install_property
240 (object_class, PROP_COMPANION,
241 g_param_spec_object (NM_DEVICE_OLPC_MESH_COMPANION, "", "",
244 G_PARAM_STATIC_STRINGS));
247 * NMDeviceOlpcMesh:active-channel:
249 * The device's active channel.
251 g_object_class_install_property
252 (object_class, PROP_ACTIVE_CHANNEL,
253 g_param_spec_uint (NM_DEVICE_OLPC_MESH_ACTIVE_CHANNEL, "", "",
256 G_PARAM_STATIC_STRINGS));