device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-glib / nm-active-connection.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  * Copyright 2007 - 2014 Red Hat, Inc.
19  * Copyright 2008 Novell, Inc.
20  */
21
22 #include "nm-default.h"
23
24 #include <string.h>
25
26 #include "NetworkManager.h"
27 #include "nm-active-connection.h"
28 #include "nm-object-private.h"
29 #include "nm-types-private.h"
30 #include "nm-device.h"
31 #include "nm-device-private.h"
32 #include "nm-connection.h"
33 #include "nm-vpn-connection.h"
34 #include "nm-dbus-helpers-private.h"
35
36 static GType _nm_active_connection_type_for_path (DBusGConnection *connection,
37                                                   const char *path);
38 static void  _nm_active_connection_type_for_path_async (DBusGConnection *connection,
39                                                         const char *path,
40                                                         NMObjectTypeCallbackFunc callback,
41                                                         gpointer user_data);
42
43 G_DEFINE_TYPE_WITH_CODE (NMActiveConnection, nm_active_connection, NM_TYPE_OBJECT,
44                          _nm_object_register_type_func (g_define_type_id,
45                                                         _nm_active_connection_type_for_path,
46                                                         _nm_active_connection_type_for_path_async);
47                          )
48
49 #define NM_ACTIVE_CONNECTION_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_ACTIVE_CONNECTION, NMActiveConnectionPrivate))
50
51 typedef struct {
52         DBusGProxy *proxy;
53
54         char *connection;
55         char *id;
56         char *uuid;
57         char *type;
58         char *specific_object;
59         GPtrArray *devices;
60         NMActiveConnectionState state;
61         gboolean is_default;
62         NMIP4Config *ip4_config;
63         NMDHCP4Config *dhcp4_config;
64         gboolean is_default6;
65         NMIP6Config *ip6_config;
66         NMDHCP6Config *dhcp6_config;
67         gboolean is_vpn;
68         char *master;
69 } NMActiveConnectionPrivate;
70
71 enum {
72         PROP_0,
73         PROP_CONNECTION,
74         PROP_ID,
75         PROP_UUID,
76         PROP_TYPE,
77         PROP_SPECIFIC_OBJECT,
78         PROP_DEVICES,
79         PROP_STATE,
80         PROP_DEFAULT,
81         PROP_IP4_CONFIG,
82         PROP_DHCP4_CONFIG,
83         PROP_DEFAULT6,
84         PROP_IP6_CONFIG,
85         PROP_DHCP6_CONFIG,
86         PROP_VPN,
87         PROP_MASTER,
88
89         LAST_PROP
90 };
91
92 /**
93  * nm_active_connection_new:
94  * @connection: the #DBusGConnection
95  * @path: the DBus object path of the device
96  *
97  * Creates a new #NMActiveConnection.
98  *
99  * Returns: (transfer full): a new active connection
100  **/
101 GObject *
102 nm_active_connection_new (DBusGConnection *connection, const char *path)
103 {
104         g_return_val_if_fail (connection != NULL, NULL);
105         g_return_val_if_fail (path != NULL, NULL);
106
107         return g_object_new (NM_TYPE_ACTIVE_CONNECTION,
108                              NM_OBJECT_DBUS_CONNECTION, connection,
109                              NM_OBJECT_DBUS_PATH, path,
110                              NULL);
111 }
112
113 static GType
114 _nm_active_connection_type_for_path (DBusGConnection *connection,
115                                      const char *path)
116 {
117         DBusGProxy *proxy;
118         GError *error = NULL;
119         GValue value = G_VALUE_INIT;
120         GType type;
121
122         proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES);
123         if (!proxy) {
124                 g_warning ("%s: couldn't create D-Bus object proxy.", __func__);
125                 return G_TYPE_INVALID;
126         }
127
128         /* Have to create an NMVPNConnection if it's a VPN connection, otherwise
129          * a plain NMActiveConnection.
130          */
131         if (dbus_g_proxy_call (proxy,
132                                "Get", &error,
133                                G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
134                                G_TYPE_STRING, "Vpn",
135                                G_TYPE_INVALID,
136                                G_TYPE_VALUE, &value, G_TYPE_INVALID)) {
137                 if (g_value_get_boolean (&value))
138                         type = NM_TYPE_VPN_CONNECTION;
139                 else
140                         type = NM_TYPE_ACTIVE_CONNECTION;
141         } else {
142                 g_warning ("Error in getting active connection 'Vpn' property: %s",
143                            error->message);
144                 g_error_free (error);
145                 type = G_TYPE_INVALID;
146         }
147
148         g_object_unref (proxy);
149         return type;
150 }
151
152 typedef struct {
153         DBusGConnection *connection;
154         NMObjectTypeCallbackFunc callback;
155         gpointer user_data;
156 } NMActiveConnectionAsyncData;
157
158 static void
159 async_got_type (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
160 {
161         NMActiveConnectionAsyncData *async_data = user_data;
162         GValue value = G_VALUE_INIT;
163         const char *path = dbus_g_proxy_get_path (proxy);
164         GError *error = NULL;
165         GType type;
166
167         if (dbus_g_proxy_end_call (proxy, call, &error,
168                                    G_TYPE_VALUE, &value,
169                                    G_TYPE_INVALID)) {
170                 if (g_value_get_boolean (&value))
171                         type = NM_TYPE_VPN_CONNECTION;
172                 else
173                         type = NM_TYPE_ACTIVE_CONNECTION;
174         } else {
175                 g_warning ("%s: could not read properties for %s: %s", __func__, path, error->message);
176                 type = G_TYPE_INVALID;
177         }
178
179         async_data->callback (type, async_data->user_data);
180
181         g_object_unref (proxy);
182         g_slice_free (NMActiveConnectionAsyncData, async_data);
183 }
184
185 static void
186 _nm_active_connection_type_for_path_async (DBusGConnection *connection,
187                                            const char *path,
188                                            NMObjectTypeCallbackFunc callback,
189                                            gpointer user_data)
190 {
191         NMActiveConnectionAsyncData *async_data;
192         DBusGProxy *proxy;
193
194         async_data = g_slice_new (NMActiveConnectionAsyncData);
195         async_data->connection = connection;
196         async_data->callback = callback;
197         async_data->user_data = user_data;
198
199         proxy = _nm_dbus_new_proxy_for_connection (connection, path, DBUS_INTERFACE_PROPERTIES);
200         dbus_g_proxy_begin_call (proxy, "Get",
201                                  async_got_type, async_data, NULL,
202                                  G_TYPE_STRING, NM_DBUS_INTERFACE_ACTIVE_CONNECTION,
203                                  G_TYPE_STRING, "Vpn",
204                                  G_TYPE_INVALID);
205 }
206
207 /**
208  * nm_active_connection_get_connection:
209  * @connection: a #NMActiveConnection
210  *
211  * Gets the #NMConnection's DBus object path.  This is often used with
212  * nm_remote_settings_get_connection_by_path() to retrieve the
213  * #NMRemoteConnection object that describes the connection.
214  *
215  * Returns: the object path of the #NMConnection which this #NMActiveConnection
216  * is an active instance of.  This is the internal string used by the
217  * connection, and must not be modified.
218  **/
219 const char *
220 nm_active_connection_get_connection (NMActiveConnection *connection)
221 {
222         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
223
224         _nm_object_ensure_inited (NM_OBJECT (connection));
225         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->connection;
226 }
227
228 /**
229  * nm_active_connection_get_id:
230  * @connection: a #NMActiveConnection
231  *
232  * Gets the #NMConnection's ID.
233  *
234  * Returns: the ID of the #NMConnection that backs the #NMActiveConnection.
235  * This is the internal string used by the connection, and must not be modified.
236  *
237  * Since: 0.9.10
238  **/
239 const char *
240 nm_active_connection_get_id (NMActiveConnection *connection)
241 {
242         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
243
244         _nm_object_ensure_inited (NM_OBJECT (connection));
245         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->id;
246 }
247
248 /**
249  * nm_active_connection_get_uuid:
250  * @connection: a #NMActiveConnection
251  *
252  * Gets the #NMConnection's UUID.
253  *
254  * Returns: the UUID of the #NMConnection that backs the #NMActiveConnection.
255  * This is the internal string used by the connection, and must not be modified.
256  **/
257 const char *
258 nm_active_connection_get_uuid (NMActiveConnection *connection)
259 {
260         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
261
262         _nm_object_ensure_inited (NM_OBJECT (connection));
263         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->uuid;
264 }
265
266 /**
267  * nm_active_connection_get_connection_type:
268  * @connection: a #NMActiveConnection
269  *
270  * Gets the #NMConnection's type.
271  *
272  * Returns: the type of the #NMConnection that backs the #NMActiveConnection.
273  * This is the internal string used by the connection, and must not be modified.
274  *
275  * Since: 0.9.10
276  **/
277 const char *
278 nm_active_connection_get_connection_type (NMActiveConnection *connection)
279 {
280         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
281
282         _nm_object_ensure_inited (NM_OBJECT (connection));
283         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->type;
284 }
285
286 /**
287  * nm_active_connection_get_specific_object:
288  * @connection: a #NMActiveConnection
289  *
290  * Gets the "specific object" used at the activation.
291  *
292  * Returns: the specific object's DBus path. This is the internal string used by the
293  * connection, and must not be modified.
294  **/
295 const char *
296 nm_active_connection_get_specific_object (NMActiveConnection *connection)
297 {
298         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
299
300         _nm_object_ensure_inited (NM_OBJECT (connection));
301         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->specific_object;
302 }
303
304 /**
305  * nm_active_connection_get_devices:
306  * @connection: a #NMActiveConnection
307  *
308  * Gets the #NMDevices used for the active connections.
309  *
310  * Returns: (element-type NMDevice): the #GPtrArray containing #NMDevices.
311  * This is the internal copy used by the connection, and must not be modified.
312  **/
313 const GPtrArray *
314 nm_active_connection_get_devices (NMActiveConnection *connection)
315 {
316         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
317
318         _nm_object_ensure_inited (NM_OBJECT (connection));
319         return handle_ptr_array_return (NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->devices);
320 }
321
322 /**
323  * nm_active_connection_get_state:
324  * @connection: a #NMActiveConnection
325  *
326  * Gets the active connection's state.
327  *
328  * Returns: the state
329  **/
330 NMActiveConnectionState
331 nm_active_connection_get_state (NMActiveConnection *connection)
332 {
333         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NM_ACTIVE_CONNECTION_STATE_UNKNOWN);
334
335         _nm_object_ensure_inited (NM_OBJECT (connection));
336         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->state;
337 }
338
339 /**
340  * nm_active_connection_get_default:
341  * @connection: a #NMActiveConnection
342  *
343  * Whether the active connection is the default IPv4 one (that is, is used for
344  * the default IPv4 route and DNS information).
345  *
346  * Returns: %TRUE if the active connection is the default IPv4 connection
347  **/
348 gboolean
349 nm_active_connection_get_default (NMActiveConnection *connection)
350 {
351         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
352
353         _nm_object_ensure_inited (NM_OBJECT (connection));
354         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default;
355 }
356
357 /**
358  * nm_active_connection_get_ip4_config:
359  * @connection: an #NMActiveConnection
360  *
361  * Gets the current #NMIP4Config associated with the #NMActiveConnection.
362  *
363  * Returns: (transfer none): the #NMIP4Config, or %NULL if the
364  *   connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
365  *   state.
366  *
367  * Since: 0.9.10
368  **/
369 NMIP4Config *
370 nm_active_connection_get_ip4_config (NMActiveConnection *connection)
371 {
372         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
373
374         _nm_object_ensure_inited (NM_OBJECT (connection));
375         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip4_config;
376 }
377
378 /**
379  * nm_active_connection_get_dhcp4_config:
380  * @connection: an #NMActiveConnection
381  *
382  * Gets the current #NMDHCP4Config (if any) associated with the
383  * #NMActiveConnection.
384  *
385  * Returns: (transfer none): the #NMDHCP4Config, or %NULL if the
386  *   connection does not use DHCP, or is not in the
387  *   %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
388  *
389  * Since: 0.9.10
390  **/
391 NMDHCP4Config *
392 nm_active_connection_get_dhcp4_config (NMActiveConnection *connection)
393 {
394         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
395
396         _nm_object_ensure_inited (NM_OBJECT (connection));
397         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp4_config;
398 }
399
400 /**
401  * nm_active_connection_get_default6:
402  * @connection: a #NMActiveConnection
403  *
404  * Whether the active connection is the default IPv6 one (that is, is used for
405  * the default IPv6 route and DNS information).
406  *
407  * Returns: %TRUE if the active connection is the default IPv6 connection
408  **/
409 gboolean
410 nm_active_connection_get_default6 (NMActiveConnection *connection)
411 {
412         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
413
414         _nm_object_ensure_inited (NM_OBJECT (connection));
415         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_default6;
416 }
417
418 /**
419  * nm_active_connection_get_ip6_config:
420  * @connection: an #NMActiveConnection
421  *
422  * Gets the current #NMIP6Config associated with the #NMActiveConnection.
423  *
424  * Returns: (transfer none): the #NMIP6Config, or %NULL if the
425  *   connection is not in the %NM_ACTIVE_CONNECTION_STATE_ACTIVATED
426  *   state.
427  *
428  * Since: 0.9.10
429  **/
430 NMIP6Config *
431 nm_active_connection_get_ip6_config (NMActiveConnection *connection)
432 {
433         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
434
435         _nm_object_ensure_inited (NM_OBJECT (connection));
436         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->ip6_config;
437 }
438
439 /**
440  * nm_active_connection_get_dhcp6_config:
441  * @connection: an #NMActiveConnection
442  *
443  * Gets the current #NMDHCP6Config (if any) associated with the
444  * #NMActiveConnection.
445  *
446  * Returns: (transfer none): the #NMDHCP6Config, or %NULL if the
447  *   connection does not use DHCPv6, or is not in the
448  *   %NM_ACTIVE_CONNECTION_STATE_ACTIVATED state.
449  *
450  * Since: 0.9.10
451  **/
452 NMDHCP6Config *
453 nm_active_connection_get_dhcp6_config (NMActiveConnection *connection)
454 {
455         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
456
457         _nm_object_ensure_inited (NM_OBJECT (connection));
458         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->dhcp6_config;
459 }
460
461 /**
462  * nm_active_connection_get_vpn:
463  * @connection: a #NMActiveConnection
464  *
465  * Whether the active connection is a VPN connection.
466  *
467  * Returns: %TRUE if the active connection is a VPN connection
468  *
469  * Since: 0.9.10
470  **/
471 gboolean
472 nm_active_connection_get_vpn (NMActiveConnection *connection)
473 {
474         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), FALSE);
475
476         _nm_object_ensure_inited (NM_OBJECT (connection));
477         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->is_vpn;
478 }
479
480 /**
481  * nm_active_connection_get_master:
482  * @connection: a #NMActiveConnection
483  *
484  * Gets the path to the master #NMDevice of the connection.
485  *
486  * Returns: the path of the master #NMDevice of the #NMActiveConnection.
487  * This is the internal string used by the connection, and must not be modified.
488  **/
489 const char *
490 nm_active_connection_get_master (NMActiveConnection *connection)
491 {
492         g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (connection), NULL);
493
494         _nm_object_ensure_inited (NM_OBJECT (connection));
495         return NM_ACTIVE_CONNECTION_GET_PRIVATE (connection)->master;
496 }
497
498 static void
499 nm_active_connection_init (NMActiveConnection *ap)
500 {
501 }
502
503 static void
504 dispose (GObject *object)
505 {
506         NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
507
508         if (priv->devices) {
509                 g_ptr_array_set_free_func (priv->devices, g_object_unref);
510                 g_ptr_array_free (priv->devices, TRUE);
511                 priv->devices = NULL;
512         }
513
514         g_clear_object (&priv->ip4_config);
515         g_clear_object (&priv->dhcp4_config);
516         g_clear_object (&priv->ip6_config);
517         g_clear_object (&priv->dhcp6_config);
518
519         g_clear_object (&priv->proxy);
520
521         G_OBJECT_CLASS (nm_active_connection_parent_class)->dispose (object);
522 }
523
524 static void
525 finalize (GObject *object)
526 {
527         NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
528
529         g_free (priv->connection);
530         g_free (priv->id);
531         g_free (priv->uuid);
532         g_free (priv->type);
533         g_free (priv->specific_object);
534         g_free (priv->master);
535
536         G_OBJECT_CLASS (nm_active_connection_parent_class)->finalize (object);
537 }
538
539 static void
540 get_property (GObject *object,
541               guint prop_id,
542               GValue *value,
543               GParamSpec *pspec)
544 {
545         NMActiveConnection *self = NM_ACTIVE_CONNECTION (object);
546
547         _nm_object_ensure_inited (NM_OBJECT (object));
548
549         switch (prop_id) {
550         case PROP_CONNECTION:
551                 g_value_set_string (value, nm_active_connection_get_connection (self));
552                 break;
553         case PROP_ID:
554                 g_value_set_string (value, nm_active_connection_get_id (self));
555                 break;
556         case PROP_UUID:
557                 g_value_set_string (value, nm_active_connection_get_uuid (self));
558                 break;
559         case PROP_TYPE:
560                 g_value_set_string (value, nm_active_connection_get_connection_type (self));
561                 break;
562         case PROP_SPECIFIC_OBJECT:
563                 g_value_set_boxed (value, nm_active_connection_get_specific_object (self));
564                 break;
565         case PROP_DEVICES:
566                 g_value_set_boxed (value, nm_active_connection_get_devices (self));
567                 break;
568         case PROP_STATE:
569                 g_value_set_uint (value, nm_active_connection_get_state (self));
570                 break;
571         case PROP_DEFAULT:
572                 g_value_set_boolean (value, nm_active_connection_get_default (self));
573                 break;
574         case PROP_IP4_CONFIG:
575                 g_value_set_object (value, nm_active_connection_get_ip4_config (self));
576                 break;
577         case PROP_DHCP4_CONFIG:
578                 g_value_set_object (value, nm_active_connection_get_dhcp4_config (self));
579                 break;
580         case PROP_DEFAULT6:
581                 g_value_set_boolean (value, nm_active_connection_get_default6 (self));
582                 break;
583         case PROP_IP6_CONFIG:
584                 g_value_set_object (value, nm_active_connection_get_ip6_config (self));
585                 break;
586         case PROP_DHCP6_CONFIG:
587                 g_value_set_object (value, nm_active_connection_get_dhcp6_config (self));
588                 break;
589         case PROP_VPN:
590                 g_value_set_boolean (value, nm_active_connection_get_vpn (self));
591                 break;
592         case PROP_MASTER:
593                 g_value_set_string (value, nm_active_connection_get_master (self));
594                 break;
595         default:
596                 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
597                 break;
598         }
599 }
600
601 static void
602 register_properties (NMActiveConnection *connection)
603 {
604         NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (connection);
605         const NMPropertiesInfo property_info[] = {
606                 { NM_ACTIVE_CONNECTION_CONNECTION,          &priv->connection },
607                 { NM_ACTIVE_CONNECTION_ID,                  &priv->id },
608                 { NM_ACTIVE_CONNECTION_UUID,                &priv->uuid },
609                 { NM_ACTIVE_CONNECTION_TYPE,                &priv->type },
610                 { NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT,     &priv->specific_object },
611                 { NM_ACTIVE_CONNECTION_DEVICES,             &priv->devices, NULL, NM_TYPE_DEVICE },
612                 { NM_ACTIVE_CONNECTION_STATE,               &priv->state },
613                 { NM_ACTIVE_CONNECTION_DEFAULT,             &priv->is_default },
614                 { NM_ACTIVE_CONNECTION_IP4_CONFIG,          &priv->ip4_config, NULL, NM_TYPE_IP4_CONFIG },
615                 { NM_ACTIVE_CONNECTION_DHCP4_CONFIG,        &priv->dhcp4_config, NULL, NM_TYPE_DHCP4_CONFIG },
616                 { NM_ACTIVE_CONNECTION_DEFAULT6,            &priv->is_default6 },
617                 { NM_ACTIVE_CONNECTION_IP6_CONFIG,          &priv->ip6_config, NULL, NM_TYPE_IP6_CONFIG },
618                 { NM_ACTIVE_CONNECTION_DHCP6_CONFIG,        &priv->dhcp6_config, NULL, NM_TYPE_DHCP6_CONFIG },
619                 { NM_ACTIVE_CONNECTION_VPN,                 &priv->is_vpn },
620                 { NM_ACTIVE_CONNECTION_MASTER,              &priv->master },
621
622                 { NULL },
623         };
624
625         _nm_object_register_properties (NM_OBJECT (connection),
626                                         priv->proxy,
627                                         property_info);
628 }
629
630 static void
631 constructed (GObject *object)
632 {
633         NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
634
635         G_OBJECT_CLASS (nm_active_connection_parent_class)->constructed (object);
636
637         priv->proxy = _nm_object_new_proxy (NM_OBJECT (object), NULL, NM_DBUS_INTERFACE_ACTIVE_CONNECTION);
638         register_properties (NM_ACTIVE_CONNECTION (object));
639 }
640
641
642 static void
643 nm_active_connection_class_init (NMActiveConnectionClass *ap_class)
644 {
645         GObjectClass *object_class = G_OBJECT_CLASS (ap_class);
646
647         g_type_class_add_private (ap_class, sizeof (NMActiveConnectionPrivate));
648
649         /* virtual methods */
650         object_class->constructed = constructed;
651         object_class->get_property = get_property;
652         object_class->dispose = dispose;
653         object_class->finalize = finalize;
654
655         /* properties */
656
657         /**
658          * NMActiveConnection:connection:
659          *
660          * The connection's path of the active connection.
661          **/
662         g_object_class_install_property
663                 (object_class, PROP_CONNECTION,
664                  g_param_spec_string (NM_ACTIVE_CONNECTION_CONNECTION, "", "",
665                                       NULL,
666                                       G_PARAM_READABLE |
667                                       G_PARAM_STATIC_STRINGS));
668
669         /**
670          * NMActiveConnection:id:
671          *
672          * The active connection's ID
673          *
674          * Since: 0.9.10
675          **/
676         g_object_class_install_property
677                 (object_class, PROP_ID,
678                  g_param_spec_string (NM_ACTIVE_CONNECTION_ID, "", "",
679                                       NULL,
680                                       G_PARAM_READABLE |
681                                       G_PARAM_STATIC_STRINGS));
682
683         /**
684          * NMActiveConnection:uuid:
685          *
686          * The active connection's UUID
687          **/
688         g_object_class_install_property
689                 (object_class, PROP_UUID,
690                  g_param_spec_string (NM_ACTIVE_CONNECTION_UUID, "", "",
691                                       NULL,
692                                       G_PARAM_READABLE |
693                                       G_PARAM_STATIC_STRINGS));
694
695         /**
696          * NMActiveConnection:type:
697          *
698          * The active connection's type
699          *
700          * Since: 0.9.10
701          **/
702         g_object_class_install_property
703                 (object_class, PROP_TYPE,
704                  g_param_spec_string (NM_ACTIVE_CONNECTION_TYPE, "", "",
705                                       NULL,
706                                       G_PARAM_READABLE |
707                                       G_PARAM_STATIC_STRINGS));
708
709         /**
710          * NMActiveConnection:specific-object:
711          *
712          * The specific object's path of the active connection.
713          **/
714         g_object_class_install_property
715                 (object_class, PROP_SPECIFIC_OBJECT,
716                  g_param_spec_string (NM_ACTIVE_CONNECTION_SPECIFIC_OBJECT, "", "",
717                                       NULL,
718                                       G_PARAM_READABLE |
719                                       G_PARAM_STATIC_STRINGS));
720
721         /**
722          * NMActiveConnection:device:
723          *
724          * The devices (#NMDevice) of the active connection.
725          **/
726         g_object_class_install_property
727                 (object_class, PROP_DEVICES,
728                  g_param_spec_boxed (NM_ACTIVE_CONNECTION_DEVICES, "", "",
729                                      NM_TYPE_OBJECT_ARRAY,
730                                      G_PARAM_READABLE |
731                                      G_PARAM_STATIC_STRINGS));
732
733         /**
734          * NMActiveConnection:state:
735          *
736          * The state of the active connection.
737          **/
738         g_object_class_install_property
739                 (object_class, PROP_STATE,
740                  g_param_spec_uint (NM_ACTIVE_CONNECTION_STATE, "", "",
741                                     NM_ACTIVE_CONNECTION_STATE_UNKNOWN,
742                                     NM_ACTIVE_CONNECTION_STATE_DEACTIVATING,
743                                     NM_ACTIVE_CONNECTION_STATE_UNKNOWN,
744                                     G_PARAM_READABLE |
745                                     G_PARAM_STATIC_STRINGS));
746
747         /**
748          * NMActiveConnection:default:
749          *
750          * Whether the active connection is the default IPv4 one.
751          **/
752         g_object_class_install_property
753                 (object_class, PROP_DEFAULT,
754                  g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT, "", "",
755                                        FALSE,
756                                        G_PARAM_READABLE |
757                                        G_PARAM_STATIC_STRINGS));
758
759         /**
760          * NMActiveConnection:ip4-config:
761          *
762          * The #NMIP4Config of the connection.
763          *
764          * Since: 0.9.10
765          **/
766         g_object_class_install_property
767                 (object_class, PROP_IP4_CONFIG,
768                  g_param_spec_object (NM_ACTIVE_CONNECTION_IP4_CONFIG, "", "",
769                                       NM_TYPE_IP4_CONFIG,
770                                       G_PARAM_READABLE |
771                                       G_PARAM_STATIC_STRINGS));
772
773         /**
774          * NMActiveConnection:dhcp4-config:
775          *
776          * The #NMDHCP4Config of the connection.
777          *
778          * Since: 0.9.10
779          **/
780         g_object_class_install_property
781                 (object_class, PROP_DHCP4_CONFIG,
782                  g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP4_CONFIG, "", "",
783                                       NM_TYPE_DHCP4_CONFIG,
784                                       G_PARAM_READABLE |
785                                       G_PARAM_STATIC_STRINGS));
786
787         /**
788          * NMActiveConnection:default6:
789          *
790          * Whether the active connection is the default IPv6 one.
791          **/
792         g_object_class_install_property
793                 (object_class, PROP_DEFAULT6,
794                  g_param_spec_boolean (NM_ACTIVE_CONNECTION_DEFAULT6, "", "",
795                                        FALSE,
796                                        G_PARAM_READABLE |
797                                        G_PARAM_STATIC_STRINGS));
798
799         /**
800          * NMActiveConnection:ip6-config:
801          *
802          * The #NMIP6Config of the connection.
803          *
804          * Since: 0.9.10
805          **/
806         g_object_class_install_property
807                 (object_class, PROP_IP6_CONFIG,
808                  g_param_spec_object (NM_ACTIVE_CONNECTION_IP6_CONFIG, "", "",
809                                       NM_TYPE_IP6_CONFIG,
810                                       G_PARAM_READABLE |
811                                       G_PARAM_STATIC_STRINGS));
812
813         /**
814          * NMActiveConnection:dhcp6-config:
815          *
816          * The #NMDHCP6Config of the connection.
817          *
818          * Since: 0.9.10
819          **/
820         g_object_class_install_property
821                 (object_class, PROP_DHCP6_CONFIG,
822                  g_param_spec_object (NM_ACTIVE_CONNECTION_DHCP6_CONFIG, "", "",
823                                       NM_TYPE_DHCP6_CONFIG,
824                                       G_PARAM_READABLE |
825                                       G_PARAM_STATIC_STRINGS));
826
827         /**
828          * NMActiveConnection:vpn:
829          *
830          * Whether the active connection is a VPN connection.
831          *
832          * Since: 0.9.10
833          **/
834         g_object_class_install_property
835                 (object_class, PROP_VPN,
836                  g_param_spec_boolean (NM_ACTIVE_CONNECTION_VPN, "", "",
837                                        FALSE,
838                                        G_PARAM_READABLE |
839                                        G_PARAM_STATIC_STRINGS));
840
841         /**
842          * NMActiveConnection:master:
843          *
844          * The path of the master device if one exists.
845          **/
846         g_object_class_install_property
847                 (object_class, PROP_MASTER,
848                  g_param_spec_string (NM_ACTIVE_CONNECTION_MASTER, "", "",
849                                       NULL,
850                                       G_PARAM_READABLE |
851                                       G_PARAM_STATIC_STRINGS));
852 }