device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm / nm-device-adsl.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
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.
7  *
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.
12  *
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.
17  *
18  * author: Pantelis Koukousoulas <pktoss@gmail.com>
19  * Copyright 2009 - 2011 Red Hat, Inc.
20  */
21
22 #include "nm-default.h"
23
24 #include "nm-device-adsl.h"
25
26 #include <string.h>
27
28 #include "nm-device-private.h"
29 #include "nm-object-private.h"
30
31 #include "nm-setting-adsl.h"
32 #include "nm-setting-connection.h"
33
34
35 G_DEFINE_TYPE (NMDeviceAdsl, nm_device_adsl, NM_TYPE_DEVICE)
36
37 #define NM_DEVICE_ADSL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_DEVICE_ADSL, NMDeviceAdslPrivate))
38
39 typedef struct {
40         gboolean carrier;
41
42 } NMDeviceAdslPrivate;
43
44 enum {
45         PROP_0,
46         PROP_CARRIER,
47         LAST_PROP
48 };
49
50 /**
51  * nm_device_adsl_get_carrier:
52  * @device: a #NMDeviceAdsl
53  *
54  * Whether the device has carrier.
55  *
56  * Returns: %TRUE if the device has carrier
57  **/
58 gboolean
59 nm_device_adsl_get_carrier (NMDeviceAdsl *device)
60 {
61         g_return_val_if_fail (NM_IS_DEVICE_ADSL (device), FALSE);
62
63         return NM_DEVICE_ADSL_GET_PRIVATE (device)->carrier;
64 }
65
66 static gboolean
67 connection_compatible (NMDevice *device, NMConnection *connection, GError **error)
68 {
69         if (!NM_DEVICE_CLASS (nm_device_adsl_parent_class)->connection_compatible (device, connection, error))
70                 return FALSE;
71
72         if (!nm_connection_is_type (connection, NM_SETTING_ADSL_SETTING_NAME)) {
73                 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
74                                      _("The connection was not an ADSL connection."));
75                 return FALSE;
76         }
77
78         return TRUE;
79 }
80
81 static GType
82 get_setting_type (NMDevice *device)
83 {
84         return NM_TYPE_SETTING_ADSL;
85 }
86
87 /******************************************************************/
88
89 static void
90 nm_device_adsl_init (NMDeviceAdsl *device)
91 {
92         _nm_device_set_device_type (NM_DEVICE (device), NM_DEVICE_TYPE_ADSL);
93 }
94
95 static void
96 init_dbus (NMObject *object)
97 {
98         NMDeviceAdslPrivate *priv = NM_DEVICE_ADSL_GET_PRIVATE (object);
99         const NMPropertiesInfo property_info[] = {
100                 { NM_DEVICE_ADSL_CARRIER, &priv->carrier },
101                 { NULL },
102         };
103
104         NM_OBJECT_CLASS (nm_device_adsl_parent_class)->init_dbus (object);
105
106         _nm_object_register_properties (object,
107                                         NM_DBUS_INTERFACE_DEVICE_ADSL,
108                                         property_info);
109 }
110
111 static void
112 get_property (GObject *object,
113               guint prop_id,
114               GValue *value,
115               GParamSpec *pspec)
116 {
117         NMDeviceAdsl *device = NM_DEVICE_ADSL (object);
118
119         switch (prop_id) {
120         case PROP_CARRIER:
121                 g_value_set_boolean (value, nm_device_adsl_get_carrier (device));
122                 break;
123         default:
124                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125                 break;
126         }
127 }
128
129 static void
130 nm_device_adsl_class_init (NMDeviceAdslClass *adsl_class)
131 {
132         GObjectClass *object_class = G_OBJECT_CLASS (adsl_class);
133         NMObjectClass *nm_object_class = NM_OBJECT_CLASS (adsl_class);
134         NMDeviceClass *device_class = NM_DEVICE_CLASS (adsl_class);
135
136         g_type_class_add_private (object_class, sizeof (NMDeviceAdslPrivate));
137
138         _nm_object_class_add_interface (nm_object_class, NM_DBUS_INTERFACE_DEVICE_ADSL);
139
140         /* virtual methods */
141         object_class->get_property = get_property;
142
143         nm_object_class->init_dbus = init_dbus;
144
145         device_class->connection_compatible = connection_compatible;
146         device_class->get_setting_type = get_setting_type;
147
148         /* properties */
149         /**
150          * NMDeviceAdsl:carrier:
151          *
152          * Whether the device has carrier.
153          **/
154         g_object_class_install_property
155                 (object_class, PROP_CARRIER,
156                  g_param_spec_boolean (NM_DEVICE_ADSL_CARRIER, "", "",
157                                        FALSE,
158                                        G_PARAM_READABLE |
159                                        G_PARAM_STATIC_STRINGS));
160 }