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"
29 #include "nm-setting-connection.h"
31 G_DEFINE_TYPE (NMDeviceGeneric, nm_device_generic, NM_TYPE_DEVICE)
33 #define NM_DEVICE_GENERIC_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_GENERIC, NMDeviceGenericPrivate))
37 char *type_description;
38 } NMDeviceGenericPrivate;
43 PROP_TYPE_DESCRIPTION,
49 * nm_device_generic_get_hw_address:
50 * @device: a #NMDeviceGeneric
52 * Gets the hardware address of the #NMDeviceGeneric
54 * Returns: the hardware address. This is the internal string used by the
55 * device, and must not be modified.
58 nm_device_generic_get_hw_address (NMDeviceGeneric *device)
60 g_return_val_if_fail (NM_IS_DEVICE_GENERIC (device), NULL);
62 return NM_DEVICE_GENERIC_GET_PRIVATE (device)->hw_address;
65 /***********************************************************/
68 get_type_description (NMDevice *device)
70 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (device);
72 return priv->type_description;
76 get_hw_address (NMDevice *device)
78 return nm_device_generic_get_hw_address (NM_DEVICE_GENERIC (device));
82 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
84 const char *iface_name;
86 if (!NM_DEVICE_CLASS (nm_device_generic_parent_class)->connection_compatible (device, connection, error))
89 if (!nm_connection_is_type (connection, NM_SETTING_GENERIC_SETTING_NAME)) {
90 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
91 _("The connection was not a generic connection."));
95 iface_name = nm_connection_get_interface_name (connection);
97 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
98 _("The connection did not specify an interface name."));
106 get_setting_type (NMDevice *device)
108 return NM_TYPE_SETTING_GENERIC;
111 /***********************************************************/
114 nm_device_generic_init (NMDeviceGeneric *device)
116 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_GENERIC);
120 init_dbus (NMObject *object)
122 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
123 const NMPropertiesInfo property_info[] = {
124 { NM_DEVICE_GENERIC_HW_ADDRESS, &priv->hw_address },
125 { NM_DEVICE_GENERIC_TYPE_DESCRIPTION, &priv->type_description },
129 NM_OBJECT_CLASS (nm_device_generic_parent_class)->init_dbus (object);
131 _nm_object_register_properties (object,
132 NM_DBUS_INTERFACE_DEVICE_GENERIC,
137 finalize (GObject *object)
139 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
141 g_free (priv->hw_address);
142 g_free (priv->type_description);
144 G_OBJECT_CLASS (nm_device_generic_parent_class)->finalize (object);
148 get_property (GObject *object,
153 NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE (object);
156 case PROP_HW_ADDRESS:
157 g_value_set_string (value, priv->hw_address);
159 case PROP_TYPE_DESCRIPTION:
160 g_value_set_string (value, priv->type_description);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169 nm_device_generic_class_init (NMDeviceGenericClass *klass)
171 GObjectClass *object_class = G_OBJECT_CLASS (klass);
172 NMObjectClass *nm_object_class = NM_OBJECT_CLASS (klass);
173 NMDeviceClass *device_class = NM_DEVICE_CLASS (klass);
175 g_type_class_add_private (klass, sizeof (NMDeviceGenericPrivate));
177 _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_GENERIC);
179 object_class->finalize = finalize;
180 object_class->get_property = get_property;
182 nm_object_class->init_dbus = init_dbus;
184 device_class->get_type_description = get_type_description;
185 device_class->get_hw_address = get_hw_address;
186 device_class->connection_compatible = connection_compatible;
187 device_class->get_setting_type = get_setting_type;
190 * NMDeviceGeneric:hw-address:
192 * The hardware address of the device.
194 g_object_class_install_property
195 (object_class, PROP_HW_ADDRESS,
196 g_param_spec_string (NM_DEVICE_GENERIC_HW_ADDRESS, "", "",
199 G_PARAM_STATIC_STRINGS));
202 * NMDeviceGeneric:type-description:
204 * A description of the specific type of device this is, or %NULL
207 g_object_class_install_property
208 (object_class, PROP_TYPE_DESCRIPTION,
209 g_param_spec_string (NM_DEVICE_GENERIC_TYPE_DESCRIPTION, "", "",
212 G_PARAM_STATIC_STRINGS));