device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm / nm-client.h
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 - 2008 Novell, Inc.
19  * Copyright 2007 - 2014 Red Hat, Inc.
20  */
21
22 #ifndef __NM_CLIENT_H__
23 #define __NM_CLIENT_H__
24
25 #if !defined (__NETWORKMANAGER_H_INSIDE__) && !defined (NETWORKMANAGER_COMPILATION)
26 #error "Only <NetworkManager.h> can be included directly."
27 #endif
28
29 #include <nm-types.h>
30
31 G_BEGIN_DECLS
32
33 #define NM_TYPE_CLIENT            (nm_client_get_type ())
34 #define NM_CLIENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CLIENT, NMClient))
35 #define NM_CLIENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CLIENT, NMClientClass))
36 #define NM_IS_CLIENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CLIENT))
37 #define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CLIENT))
38 #define NM_CLIENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass))
39
40 #define NM_CLIENT_VERSION "version"
41 #define NM_CLIENT_STATE "state"
42 #define NM_CLIENT_STARTUP "startup"
43 #define NM_CLIENT_NM_RUNNING "nm-running"
44 #define NM_CLIENT_NETWORKING_ENABLED "networking-enabled"
45 #define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled"
46 #define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
47 #define NM_CLIENT_WWAN_ENABLED "wwan-enabled"
48 #define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
49 #define NM_CLIENT_WIMAX_ENABLED "wimax-enabled"
50 #define NM_CLIENT_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
51 #define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections"
52 #define NM_CLIENT_CONNECTIVITY "connectivity"
53 #define NM_CLIENT_PRIMARY_CONNECTION "primary-connection"
54 #define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection"
55 #define NM_CLIENT_DEVICES "devices"
56 #define NM_CLIENT_ALL_DEVICES "all-devices"
57 #define NM_CLIENT_CONNECTIONS "connections"
58 #define NM_CLIENT_HOSTNAME "hostname"
59 #define NM_CLIENT_CAN_MODIFY "can-modify"
60 #define NM_CLIENT_METERED "metered"
61
62 #define NM_CLIENT_DEVICE_ADDED "device-added"
63 #define NM_CLIENT_DEVICE_REMOVED "device-removed"
64 #define NM_CLIENT_ANY_DEVICE_ADDED "any-device-added"
65 #define NM_CLIENT_ANY_DEVICE_REMOVED "any-device-removed"
66 #define NM_CLIENT_PERMISSION_CHANGED "permission-changed"
67 #define NM_CLIENT_CONNECTION_ADDED "connection-added"
68 #define NM_CLIENT_CONNECTION_REMOVED "connection-removed"
69
70 /**
71  * NMClientPermission:
72  * @NM_CLIENT_PERMISSION_NONE: unknown or no permission
73  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK: controls whether networking
74  *  can be globally enabled or disabled
75  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI: controls whether Wi-Fi can be
76  *  globally enabled or disabled
77  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN: controls whether WWAN (3G) can be
78  *  globally enabled or disabled
79  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX: controls whether WiMAX can be
80  *  globally enabled or disabled
81  * @NM_CLIENT_PERMISSION_SLEEP_WAKE: controls whether the client can ask
82  *  NetworkManager to sleep and wake
83  * @NM_CLIENT_PERMISSION_NETWORK_CONTROL: controls whether networking connections
84  *  can be started, stopped, and changed
85  * @NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED: controls whether a password
86  *  protected Wi-Fi hotspot can be created
87  * @NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN: controls whether an open Wi-Fi hotspot
88  *  can be created
89  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM: controls whether connections
90  *  that are available to all users can be modified
91  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN: controls whether connections
92  *  owned by the current user can be modified
93  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME: controls whether the
94  *  persistent hostname can be changed
95  * @NM_CLIENT_PERMISSION_LAST: a reserved boundary value
96  *
97  * #NMClientPermission values indicate various permissions that NetworkManager
98  * clients can obtain to perform certain tasks on behalf of the current user.
99  **/
100 typedef enum {
101         NM_CLIENT_PERMISSION_NONE = 0,
102         NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK = 1,
103         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI = 2,
104         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN = 3,
105         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX = 4,
106         NM_CLIENT_PERMISSION_SLEEP_WAKE = 5,
107         NM_CLIENT_PERMISSION_NETWORK_CONTROL = 6,
108         NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED = 7,
109         NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN = 8,
110         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM = 9,
111         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN = 10,
112         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME = 11,
113
114         NM_CLIENT_PERMISSION_LAST = NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME
115 } NMClientPermission;
116
117 /**
118  * NMClientPermissionResult:
119  * @NM_CLIENT_PERMISSION_RESULT_UNKNOWN: unknown or no authorization
120  * @NM_CLIENT_PERMISSION_RESULT_YES: the permission is available
121  * @NM_CLIENT_PERMISSION_RESULT_AUTH: authorization is necessary before the
122  *  permission is available
123  * @NM_CLIENT_PERMISSION_RESULT_NO: permission to perform the operation is
124  *  denied by system policy
125  *
126  * #NMClientPermissionResult values indicate what authorizations and permissions
127  * the user requires to obtain a given #NMClientPermission
128  **/
129 typedef enum {
130         NM_CLIENT_PERMISSION_RESULT_UNKNOWN = 0,
131         NM_CLIENT_PERMISSION_RESULT_YES,
132         NM_CLIENT_PERMISSION_RESULT_AUTH,
133         NM_CLIENT_PERMISSION_RESULT_NO
134 } NMClientPermissionResult;
135
136 /**
137  * NMClientError:
138  * @NM_CLIENT_ERROR_FAILED: unknown or unclassified error
139  * @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
140  *   failed because NetworkManager is not running
141  * @NM_CLIENT_ERROR_OBJECT_CREATION_FAILED: NetworkManager claimed that an
142  *   operation succeeded, but the object that was allegedly created (eg,
143  *   #NMRemoteConnection, #NMActiveConnection) was apparently destroyed before
144  *   #NMClient could create a representation of it.
145  *
146  * Describes errors that may result from operations involving a #NMClient.
147  *
148  * D-Bus operations may also return errors from other domains, including
149  * #NMManagerError, #NMSettingsError, #NMAgentManagerError, and #NMConnectionError.
150  **/
151 typedef enum {
152         NM_CLIENT_ERROR_FAILED = 0,
153         NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
154         NM_CLIENT_ERROR_OBJECT_CREATION_FAILED,
155 } NMClientError;
156
157 #define NM_CLIENT_ERROR nm_client_error_quark ()
158 GQuark nm_client_error_quark (void);
159
160 struct _NMClient {
161         GObject parent;
162 };
163
164 typedef struct {
165         GObjectClass parent;
166
167         /* Signals */
168         void (*device_added) (NMClient *client, NMDevice *device);
169         void (*device_removed) (NMClient *client, NMDevice *device);
170         void (*any_device_added) (NMClient *client, NMDevice *device);
171         void (*any_device_removed) (NMClient *client, NMDevice *device);
172         void (*permission_changed) (NMClient *client,
173                                     NMClientPermission permission,
174                                     NMClientPermissionResult result);
175         void (*connection_added)   (NMClient *client, NMRemoteConnection *connection);
176         void (*connection_removed) (NMClient *client, NMRemoteConnection *connection);
177
178         /*< private >*/
179         gpointer padding[6];
180 } NMClientClass;
181
182 GType nm_client_get_type (void);
183
184 NMClient *nm_client_new (GCancellable  *cancellable,
185                          GError       **error);
186
187 void      nm_client_new_async  (GCancellable         *cancellable,
188                                 GAsyncReadyCallback   callback,
189                                 gpointer              user_data);
190 NMClient *nm_client_new_finish (GAsyncResult         *result,
191                                 GError              **error);
192
193 const char *nm_client_get_version    (NMClient *client);
194 NMState     nm_client_get_state      (NMClient *client);
195 gboolean    nm_client_get_startup    (NMClient *client);
196 gboolean    nm_client_get_nm_running (NMClient *client);
197
198 gboolean nm_client_networking_get_enabled (NMClient *client);
199 gboolean nm_client_networking_set_enabled (NMClient *client,
200                                            gboolean enabled,
201                                            GError **error);
202
203 gboolean nm_client_wireless_get_enabled (NMClient *client);
204 void     nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
205 gboolean nm_client_wireless_hardware_get_enabled (NMClient *client);
206
207 gboolean nm_client_wwan_get_enabled (NMClient *client);
208 void     nm_client_wwan_set_enabled (NMClient *client, gboolean enabled);
209 gboolean nm_client_wwan_hardware_get_enabled (NMClient *client);
210
211 gboolean nm_client_wimax_get_enabled (NMClient *client);
212 void     nm_client_wimax_set_enabled (NMClient *client, gboolean enabled);
213 gboolean nm_client_wimax_hardware_get_enabled (NMClient *client);
214
215 gboolean nm_client_get_logging (NMClient *client,
216                                 char **level,
217                                 char **domains,
218                                 GError **error);
219 gboolean nm_client_set_logging (NMClient *client,
220                                 const char *level,
221                                 const char *domains,
222                                 GError **error);
223
224 NMClientPermissionResult nm_client_get_permission_result (NMClient *client,
225                                                           NMClientPermission permission);
226
227 NMConnectivityState nm_client_get_connectivity          (NMClient *client);
228
229 NMConnectivityState nm_client_check_connectivity        (NMClient *client,
230                                                          GCancellable *cancellable,
231                                                          GError **error);
232 void                nm_client_check_connectivity_async  (NMClient *client,
233                                                          GCancellable *cancellable,
234                                                          GAsyncReadyCallback callback,
235                                                          gpointer user_data);
236 NMConnectivityState nm_client_check_connectivity_finish (NMClient *client,
237                                                          GAsyncResult *result,
238                                                          GError **error);
239
240 gboolean nm_client_save_hostname        (NMClient *client,
241                                          const char *hostname,
242                                          GCancellable *cancellable,
243                                          GError **error);
244 void     nm_client_save_hostname_async  (NMClient *client,
245                                          const char *hostname,
246                                          GCancellable *cancellable,
247                                          GAsyncReadyCallback callback,
248                                          gpointer user_data);
249 gboolean nm_client_save_hostname_finish (NMClient *client,
250                                          GAsyncResult *result,
251                                          GError **error);
252
253 /* Devices */
254
255 const GPtrArray *nm_client_get_devices    (NMClient *client);
256 NM_AVAILABLE_IN_1_2
257 const GPtrArray *nm_client_get_all_devices(NMClient *client);
258 NMDevice *nm_client_get_device_by_path    (NMClient *client, const char *object_path);
259 NMDevice *nm_client_get_device_by_iface   (NMClient *client, const char *iface);
260
261 /* Active Connections */
262
263 const GPtrArray *nm_client_get_active_connections (NMClient *client);
264
265 NMActiveConnection *nm_client_get_primary_connection (NMClient *client);
266 NMActiveConnection *nm_client_get_activating_connection (NMClient *client);
267
268 void                nm_client_activate_connection_async  (NMClient *client,
269                                                           NMConnection *connection,
270                                                           NMDevice *device,
271                                                           const char *specific_object,
272                                                           GCancellable *cancellable,
273                                                           GAsyncReadyCallback callback,
274                                                           gpointer user_data);
275 NMActiveConnection *nm_client_activate_connection_finish (NMClient *client,
276                                                           GAsyncResult *result,
277                                                           GError **error);
278
279 void                nm_client_add_and_activate_connection_async  (NMClient *client,
280                                                                   NMConnection *partial,
281                                                                   NMDevice *device,
282                                                                   const char *specific_object,
283                                                                   GCancellable *cancellable,
284                                                                   GAsyncReadyCallback callback,
285                                                                   gpointer user_data);
286 NMActiveConnection *nm_client_add_and_activate_connection_finish (NMClient *client,
287                                                                   GAsyncResult *result,
288                                                                   GError **error);
289
290 gboolean nm_client_deactivate_connection        (NMClient *client,
291                                                  NMActiveConnection *active,
292                                                  GCancellable *cancellable,
293                                                  GError **error);
294 void     nm_client_deactivate_connection_async  (NMClient *client,
295                                                  NMActiveConnection *active,
296                                                  GCancellable *cancellable,
297                                                  GAsyncReadyCallback callback,
298                                                  gpointer user_data);
299 gboolean nm_client_deactivate_connection_finish (NMClient *client,
300                                                  GAsyncResult *result,
301                                                  GError **error);
302
303 /* Connections */
304
305 const GPtrArray    *nm_client_get_connections        (NMClient *client);
306
307 NMRemoteConnection *nm_client_get_connection_by_id   (NMClient *client, const char *id);
308 NMRemoteConnection *nm_client_get_connection_by_path (NMClient *client, const char *path);
309 NMRemoteConnection *nm_client_get_connection_by_uuid (NMClient *client, const char *uuid);
310
311 void                nm_client_add_connection_async  (NMClient *client,
312                                                      NMConnection *connection,
313                                                      gboolean save_to_disk,
314                                                      GCancellable *cancellable,
315                                                      GAsyncReadyCallback callback,
316                                                      gpointer user_data);
317 NMRemoteConnection *nm_client_add_connection_finish (NMClient *client,
318                                                      GAsyncResult *result,
319                                                      GError **error);
320
321 gboolean nm_client_load_connections        (NMClient *client,
322                                             char **filenames,
323                                             char ***failures,
324                                             GCancellable *cancellable,
325                                             GError **error);
326 void     nm_client_load_connections_async  (NMClient *client,
327                                             char **filenames,
328                                             GCancellable *cancellable,
329                                             GAsyncReadyCallback callback,
330                                             gpointer user_data);
331 gboolean nm_client_load_connections_finish (NMClient *client,
332                                             char ***failures,
333                                             GAsyncResult *result,
334                                             GError **error);
335
336 gboolean nm_client_reload_connections        (NMClient *client,
337                                               GCancellable *cancellable,
338                                               GError **error);
339 void     nm_client_reload_connections_async  (NMClient *client,
340                                               GCancellable *cancellable,
341                                               GAsyncReadyCallback callback,
342                                               gpointer user_data);
343 gboolean nm_client_reload_connections_finish (NMClient *client,
344                                               GAsyncResult *result,
345                                               GError **error);
346
347 G_END_DECLS
348
349 #endif /* __NM_CLIENT_H__ */