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 2013 Red Hat, Inc.
21 #include "nm-default.h"
25 #include "nm-device-generic.h"
26 #include "nm-device-private.h"
27 #include "nm-object-private.h"
28 #include "nm-setting-generic.h"
30 G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
32 #define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate))
38 char *type_description;
39 } NMDeviceGenericPrivate;
44 PROP_TYPE_DESCRIPTION,
50 * nm_device_generic_error_quark:
52 * Registers an error quark for #NMDeviceGeneric if necessary.
54 * Returns: the error quark used for #NMDeviceGeneric errors.
59 nm_device_generic_error_quark (void)
61 static GQuark quark = 0;
63 if (G_UNLIKELY (quark == 0))
64 quark = g_quark_from_static_string ("nm-device-generic-error-quark");
69 * nm_device_generic_new:
70 * @connection: the #DBusGConnection
71 * @path: the DBus object path of the device
73 * Creates a new #NMDeviceGeneric.
75 * Returns: (transfer full): a new device
80 nm_device_generic_new (DBusGConnection *connection, const char *path)
84 g_return_val_if_fail (connection != NULL, NULL);
85 g_return_val_if_fail (path != NULL, NULL);
87 device = g_object_new (NM_TYPE_DEVICE_GENERIC,
88 NM_OBJECT_DBUS_CONNECTION, connection,
89 NM_OBJECT_DBUS_PATH, path,
91 _nm_object_ensure_inited (NM_OBJECT (device));
96 * nm_device_generic_get_hw_address:
97 * @device: a #NMDeviceGeneric
99 * Gets the hardware address of the #NMDeviceGeneric
101 * Returns: the hardware address. This is the internal string used by the
102 * device, and must not be modified.
107 nm_device_generic_get_hw_address (NMDeviceGeneric *device)
109 g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL);
111 _nm_object_ensure_inited (NM_OBJECT (device));
112 return NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address;
115 /***********************************************************/
118 get_type_description (NMDevice *device)
120 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
122 _nm_object_ensure_inited (NM_OBJECT (device));
123 return priv->type_description;
127 get_hw_address (NMDevice *device)
129 return nm_device_generic_get_hw_address (NM_DEVICE_GENERIC (device));
133 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
135 NMSettingConnection *s_con;
136 const char *ctype, *iface_name;
138 s_con = nm_connection_get_setting_connection (connection);
141 ctype = nm_setting_connection_get_connection_type (s_con);
142 if (strcmp (ctype, NM_SETTING_GENERIC_SETTING_NAME) != 0) {
143 g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_NOT_GENERIC_CONNECTION,
144 "The connection was not a generic connection.");
148 iface_name = nm_setting_connection_get_interface_name (s_con);
150 g_set_error (error, NM_DEVICE_GENERIC_ERROR, NM_DEVICE_GENERIC_ERROR_MISSING_INTERFACE_NAME,
151 "The connection did not specify an interface name.");
155 return NM_DEVICE_CLASS (nm_device_generic_parent_class)->connection_compatible (device, connection, error);
159 get_setting_type (NMDevice *device)
161 return NM_TYPE_SETTING_GENERIC;
164 /***********************************************************/
167 nm_device_generic_init (NMDeviceGeneric *device)
169 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_GENERIC);
173 register_properties (NMDeviceGeneric *device)
175 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
176 const NMPropertiesInfo property_info[] = {
177 { NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address },
178 { NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description },
182 _nm_object_register_properties (NM_OBJECT (device),
188 _device_type_to_interface (NMDeviceType type)
191 case NM_DEVICE_TYPE_GENERIC:
192 return NM_DBUS_INTERFACE_DEVICE_GENERIC;
193 case NM_DEVICE_TYPE_TUN:
194 return NM_DBUS_INTERFACE_DEVICE_TUN;
201 constructed (GObject *object)
203 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
205 DBusGConnection *connection;
206 const char *path, *interface;
208 G_OBJECT_CLASS (nm_device_generic_parent_class)->constructed (object);
210 g_object_get (object,
211 NM_OBJECT_DBUS_CONNECTION, &connection,
212 NM_OBJECT_DBUS_PATH, &path,
215 type = _nm_device_type_for_path (connection, path);
216 interface = _device_type_to_interface (type);
219 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, interface);
220 register_properties (NM_DEVICE_GENERIC (object));
225 dispose (GObject *object)
227 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
229 g_clear_object (&priv->proxy);
231 G_OBJECT_CLASS (nm_device_generic_parent_class)->dispose (object);
235 finalize (GObject *object)
237 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
239 g_free (priv->hw_address);
240 g_free (priv->type_description);
242 G_OBJECT_CLASS (nm_device_generic_parent_class)->finalize (object);
246 get_property (GObject *object,
251 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
253 _nm_object_ensure_inited (NM_OBJECT (object));
256 case PROP_HW_ADDRESS:
257 g_value_set_string (value, priv->hw_address);
259 case PROP_TYPE_DESCRIPTION:
260 g_value_set_string (value, priv->type_description);
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
269 nm_device_generic_class_init (NMDeviceGenericClass *klass)
271 GObjectClass *object_class = G_OBJECT_CLASS (klass);
272 NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
274 g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate));
276 object_class->constructed = constructed;
277 object_class->dispose = dispose;
278 object_class->finalize = finalize;
279 object_class->get_property = get_property;
281 device_class->get_type_description = get_type_description;
282 device_class->get_hw_address = get_hw_address;
283 device_class->connection_compatible = connection_compatible;
284 device_class->get_setting_type = get_setting_type;
287 * NMDeviceGeneric:hw-address:
289 * The hardware address of the device.
291 g_object_class_install_property
292 (object_class, PROP_HW_ADDRESS,
293 g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "",
296 G_PARAM_STATIC_STRINGS));
299 * NMDeviceGeneric:type-description:
301 * A description of the specific type of device this is, or %NULL
304 g_object_class_install_property
305 (object_class, PROP_TYPE_DESCRIPTION,
306 g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
309 G_PARAM_STATIC_STRINGS));