device: renew dhcp leases on awake for software devices
[NetworkManager.git] / src / nm-connection-provider.c
1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program 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
11  * GNU General Public License for more details:
12  *
13  * Copyright (C) 2012 Red Hat, Inc.
14  */
15
16 #include "nm-default.h"
17
18 #include "nm-connection-provider.h"
19 #include "nm-utils.h"
20
21 G_DEFINE_INTERFACE (NMConnectionProvider, nm_connection_provider, G_TYPE_OBJECT)
22
23 GSList *
24 nm_connection_provider_get_best_connections (NMConnectionProvider *self,
25                                              guint max_requested,
26                                              const char *ctype1,
27                                              const char *ctype2,
28                                              NMConnectionFilterFunc func,
29                                              gpointer func_data)
30 {
31         g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
32
33         if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections)
34                 return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_best_connections (self, max_requested, ctype1, ctype2, func, func_data);
35         return NULL;
36 }
37
38 const GSList *
39 nm_connection_provider_get_connections (NMConnectionProvider *self)
40 {
41         g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
42
43         if (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections)
44                 return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connections (self);
45         return NULL;
46 }
47
48 /**
49  * nm_connection_provider_add_connection:
50  * @self: the #NMConnectionProvider
51  * @connection: the source connection to create a new #NMSettingsConnection from
52  * @save_to_disk: %TRUE to save the connection to disk immediately, %FALSE to
53  * not save to disk
54  * @error: on return, a location to store any errors that may occur
55  *
56  * Creates a new #NMSettingsConnection for the given source @connection.  
57  * The plugin owns the returned object and the caller must reference the object
58  * to continue using it.
59  *
60  * Returns: the new #NMSettingsConnection or %NULL
61  */
62 NMConnection *
63 nm_connection_provider_add_connection (NMConnectionProvider *self,
64                                        NMConnection *connection,
65                                        gboolean save_to_disk,
66                                        GError **error)
67 {
68         g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
69
70         g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection);
71         return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->add_connection (self, connection, save_to_disk, error);
72 }
73
74 /**
75  * nm_connection_provider_get_connection_by_uuid:
76  * @self: the #NMConnectionProvider
77  * @uuid: the UUID to search for
78  *
79  * Returns: the connection with the given @uuid, or %NULL
80  */
81 NMConnection *
82 nm_connection_provider_get_connection_by_uuid (NMConnectionProvider *self,
83                                                const char *uuid)
84 {
85         g_return_val_if_fail (NM_IS_CONNECTION_PROVIDER (self), NULL);
86         g_return_val_if_fail (uuid != NULL, NULL);
87         g_return_val_if_fail (nm_utils_is_uuid (uuid), NULL);
88
89         g_assert (NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid);
90         return NM_CONNECTION_PROVIDER_GET_INTERFACE (self)->get_connection_by_uuid (self, uuid);
91 }
92
93 /*****************************************************************************/
94
95 static void
96 nm_connection_provider_default_init (NMConnectionProviderInterface *g_iface)
97 {
98         GType iface_type = G_TYPE_FROM_INTERFACE (g_iface);
99         static gboolean initialized = FALSE;
100
101         if (initialized)
102                 return;
103         initialized = TRUE;
104
105         /* Signals */
106         g_signal_new (NM_CP_SIGNAL_CONNECTION_ADDED,
107                       iface_type,
108                       G_SIGNAL_RUN_FIRST,
109                       G_STRUCT_OFFSET (NMConnectionProviderInterface, connection_added),
110                       NULL, NULL,
111                       g_cclosure_marshal_VOID__OBJECT,
112                       G_TYPE_NONE, 1, G_TYPE_OBJECT);
113
114         g_signal_new (NM_CP_SIGNAL_CONNECTION_UPDATED,
115                       iface_type,
116                       G_SIGNAL_RUN_FIRST,
117                       G_STRUCT_OFFSET (NMConnectionProviderInterface, connection_updated),
118                       NULL, NULL,
119                       g_cclosure_marshal_VOID__OBJECT,
120                       G_TYPE_NONE, 1, G_TYPE_OBJECT);
121
122         g_signal_new (NM_CP_SIGNAL_CONNECTION_REMOVED,
123                       iface_type,
124                       G_SIGNAL_RUN_FIRST,
125                       G_STRUCT_OFFSET (NMConnectionProviderInterface, connection_removed),
126                       NULL, NULL,
127                       g_cclosure_marshal_VOID__OBJECT,
128                       G_TYPE_NONE, 1, G_TYPE_OBJECT);
129 }