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 * author: Pantelis Koukousoulas <pktoss@gmail.com>
19 * Copyright 2009 - 2011 Red Hat, Inc.
22 #include "nm-default.h"
24 #include "nm-device-adsl.h"
28 #include "nm-device-private.h"
29 #include "nm-object-private.h"
31 #include "nm-setting-adsl.h"
33 G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
35 #define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate))
43 } NMDeviceAdslPrivate;
52 * nm_device_adsl_error_quark:
54 * Registers an error quark for #NMDeviceAdsl if necessary.
56 * Returns: the error quark used for #NMDeviceAdsl errors.
59 nm_device_adsl_error_quark (void)
61 static GQuark quark = 0;
63 if (G_UNLIKELY (quark == 0))
64 quark = g_quark_from_static_string ("nm-device-adsl-error-quark");
70 * @connection: the #DBusGConnection
71 * @path: the DBus object path of the device
73 * Creates a new #NMDeviceAdsl.
75 * Returns: (transfer full): a new device
78 nm_device_adsl_new (DBusGConnection *connection, const char *path)
82 g_return_val_if_fail (connection != NULL, NULL);
83 g_return_val_if_fail (path != NULL, NULL);
85 device = g_object_new (NM_TYPE_DEVICE_ADSL,
86 NM_OBJECT_DBUS_CONNECTION, connection,
87 NM_OBJECT_DBUS_PATH, path,
89 _nm_object_ensure_inited (NM_OBJECT (device));
94 * nm_device_adsl_get_carrier:
95 * @device: a #NMDeviceAdsl
97 * Whether the device has carrier.
99 * Returns: %TRUE if the device has carrier
102 nm_device_adsl_get_carrier (NMDeviceAdsl *device)
104 g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE);
106 _nm_object_ensure_inited (NM_OBJECT (device));
107 return NM_DEVICE_ADSL_GET_PRIVATE (device)->carrier;
111 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
113 NMSettingConnection *s_con;
114 NMSettingAdsl *s_adsl;
117 s_con = nm_connection_get_setting_connection (connection);
120 ctype = nm_setting_connection_get_connection_type (s_con);
121 if (strcmp (ctype, NM_SETTING_ADSL_SETTING_NAME) != 0) {
122 g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_NOT_ADSL_CONNECTION,
123 "The connection was not an ADSL connection.");
127 s_adsl = nm_connection_get_setting_adsl (connection);
129 g_set_error (error, NM_DEVICE_ADSL_ERROR, NM_DEVICE_ADSL_ERROR_INVALID_ADSL_CONNECTION,
130 "The connection was not a valid ADSL connection.");
134 return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error);
138 get_setting_type (NMDevice *device)
140 return NM_TYPE_SETTING_ADSL;
143 /******************************************************************/
146 nm_device_adsl_init (NMDeviceAdsl *device)
148 _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ADSL);
152 register_properties (NMDeviceAdsl *device)
154 NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (device);
155 const NMPropertiesInfo property_info[] = {
156 { NM_DEVICE_ADSL_CARRIER, &priv->carrier },
160 _nm_object_register_properties (NM_OBJECT (device),
166 constructed (GObject *object)
168 NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
170 G_OBJECT_CLASS (nm_device_adsl_parent_class)->constructed (object);
172 priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_DEVICE_ADSL);
173 register_properties (NM_DEVICE_ADSL (object));
177 dispose (GObject *object)
179 NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
181 if (priv->disposed) {
182 G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
186 priv->disposed = TRUE;
188 g_object_unref (priv->proxy);
190 G_OBJECT_CLASS (nm_device_adsl_parent_class)->dispose (object);
194 finalize (GObject *object)
196 G_OBJECT_CLASS (nm_device_adsl_parent_class)->finalize (object);
200 get_property (GObject *object,
205 NMDeviceAdsl *device = NM_DEVICE_ADSL (object);
209 g_value_set_boolean (value, nm_device_adsl_get_carrier (device));
212 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
218 nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
220 GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
221 NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
223 g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
225 /* virtual methods */
226 object_class->constructed = constructed;
227 object_class->dispose = dispose;
228 object_class->finalize = finalize;
229 object_class->get_property = get_property;
230 device_class->connection_compatible = connection_compatible;
231 device_class->get_setting_type = get_setting_type;
235 * NMDeviceAdsl:carrier:
237 * Whether the device has carrier.
239 g_object_class_install_property
240 (object_class, PROP_CARRIER,
241 g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER, "", "",
244 G_PARAM_STATIC_STRINGS));