device: renew dhcp leases on awake for software devices
[NetworkManager.git] / libnm-glib / 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 - 2012 Red Hat, Inc.
20  */
21
22 #ifndef NM_CLIENT_H
23 #define NM_CLIENT_H
24
25 #include <glib.h>
26 #include <glib-object.h>
27 #include <gio/gio.h>
28 #include <dbus/dbus-glib.h>
29 #include <NetworkManager.h>
30 #include "nm-object.h"
31 #include "nm-device.h"
32 #include "nm-active-connection.h"
33 #include "nm-vpn-connection.h"
34
35 G_BEGIN_DECLS
36
37 #define NM_TYPE_CLIENT            (nm_client_get_type ())
38 #define NM_CLIENT(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_CLIENT, NMClient))
39 #define NM_CLIENT_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_CLIENT, NMClientClass))
40 #define NM_IS_CLIENT(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_CLIENT))
41 #define NM_IS_CLIENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_CLIENT))
42 #define NM_CLIENT_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_CLIENT, NMClientClass))
43
44 #define NM_CLIENT_VERSION "version"
45 #define NM_CLIENT_STATE "state"
46 #define NM_CLIENT_STARTUP "startup"
47 #define NM_CLIENT_MANAGER_RUNNING "manager-running"
48 #define NM_CLIENT_NETWORKING_ENABLED "networking-enabled"
49 #define NM_CLIENT_WIRELESS_ENABLED "wireless-enabled"
50 #define NM_CLIENT_WIRELESS_HARDWARE_ENABLED "wireless-hardware-enabled"
51 #define NM_CLIENT_WWAN_ENABLED "wwan-enabled"
52 #define NM_CLIENT_WWAN_HARDWARE_ENABLED "wwan-hardware-enabled"
53 #define NM_CLIENT_WIMAX_ENABLED "wimax-enabled"
54 #define NM_CLIENT_WIMAX_HARDWARE_ENABLED "wimax-hardware-enabled"
55 #define NM_CLIENT_ACTIVE_CONNECTIONS "active-connections"
56 #define NM_CLIENT_CONNECTIVITY "connectivity"
57 #define NM_CLIENT_PRIMARY_CONNECTION "primary-connection"
58 #define NM_CLIENT_ACTIVATING_CONNECTION "activating-connection"
59 #define NM_CLIENT_DEVICES "devices"
60 #define NM_CLIENT_ALL_DEVICES "all-devices"
61
62 /**
63  * NMClientPermission:
64  * @NM_CLIENT_PERMISSION_NONE: unknown or no permission
65  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK: controls whether networking
66  *  can be globally enabled or disabled
67  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI: controls whether Wi-Fi can be
68  *  globally enabled or disabled
69  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN: controls whether WWAN (3G) can be
70  *  globally enabled or disabled
71  * @NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX: controls whether WiMAX can be
72  *  globally enabled or disabled
73  * @NM_CLIENT_PERMISSION_SLEEP_WAKE: controls whether the client can ask
74  *  NetworkManager to sleep and wake
75  * @NM_CLIENT_PERMISSION_NETWORK_CONTROL: controls whether networking connections
76  *  can be started, stopped, and changed
77  * @NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED: controls whether a password
78  *  protected Wi-Fi hotspot can be created
79  * @NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN: controls whether an open Wi-Fi hotspot
80  *  can be created
81  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM: controls whether connections
82  *  that are available to all users can be modified
83  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN: controls whether connections
84  *  owned by the current user can be modified
85  * @NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME: controls whether the
86  *  persistent hostname can be changed
87  * @NM_CLIENT_PERMISSION_LAST: a reserved boundary value
88  *
89  * #NMClientPermission values indicate various permissions that NetworkManager
90  * clients can obtain to perform certain tasks on behalf of the current user.
91  **/
92 typedef enum {
93         NM_CLIENT_PERMISSION_NONE = 0,
94         NM_CLIENT_PERMISSION_ENABLE_DISABLE_NETWORK = 1,
95         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIFI = 2,
96         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WWAN = 3,
97         NM_CLIENT_PERMISSION_ENABLE_DISABLE_WIMAX = 4,
98         NM_CLIENT_PERMISSION_SLEEP_WAKE = 5,
99         NM_CLIENT_PERMISSION_NETWORK_CONTROL = 6,
100         NM_CLIENT_PERMISSION_WIFI_SHARE_PROTECTED = 7,
101         NM_CLIENT_PERMISSION_WIFI_SHARE_OPEN = 8,
102         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_SYSTEM = 9,
103         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_OWN = 10,
104         NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME = 11,
105
106         NM_CLIENT_PERMISSION_LAST = NM_CLIENT_PERMISSION_SETTINGS_MODIFY_HOSTNAME
107 } NMClientPermission;
108
109 /**
110  * NMClientPermissionResult:
111  * @NM_CLIENT_PERMISSION_RESULT_UNKNOWN: unknown or no authorization
112  * @NM_CLIENT_PERMISSION_RESULT_YES: the permission is available
113  * @NM_CLIENT_PERMISSION_RESULT_AUTH: authorization is necessary before the
114  *  permission is available
115  * @NM_CLIENT_PERMISSION_RESULT_NO: permission to perform the operation is
116  *  denied by system policy
117  *
118  * #NMClientPermissionResult values indicate what authorizations and permissions
119  * the user requires to obtain a given #NMClientPermission
120  **/
121 typedef enum {
122         NM_CLIENT_PERMISSION_RESULT_UNKNOWN = 0,
123         NM_CLIENT_PERMISSION_RESULT_YES,
124         NM_CLIENT_PERMISSION_RESULT_AUTH,
125         NM_CLIENT_PERMISSION_RESULT_NO
126 } NMClientPermissionResult;
127
128 /**
129  * NMClientError:
130  * @NM_CLIENT_ERROR_UNKNOWN: unknown or unclassified error
131  * @NM_CLIENT_ERROR_MANAGER_NOT_RUNNING: an operation that requires NetworkManager
132  *   failed because NetworkManager is not running
133  *
134  * Describes errors that may result from operations involving a #NMClient.
135  **/
136 typedef enum {
137         NM_CLIENT_ERROR_UNKNOWN = 0,            /*< nick=UnknownError >*/
138         NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,    /*< nick=ManagerNotRunning >*/
139 } NMClientError;
140
141 #define NM_CLIENT_ERROR nm_client_error_quark ()
142 NM_AVAILABLE_IN_0_9_10
143 GQuark nm_client_error_quark (void);
144
145 typedef struct {
146         NMObject parent;
147 } NMClient;
148
149 typedef struct {
150         NMObjectClass parent;
151
152         /* Signals */
153         void (*device_added) (NMClient *client, NMDevice *device);
154         void (*device_removed) (NMClient *client, NMDevice *device);
155         void (*permission_changed) (NMClient *client,
156                                     NMClientPermission permission,
157                                     NMClientPermissionResult result);
158
159         /* Padding for future expansion */
160         void (*_reserved1) (void);
161         void (*_reserved2) (void);
162         void (*_reserved3) (void);
163         void (*_reserved4) (void);
164         void (*_reserved5) (void);
165         void (*_reserved6) (void);
166 } NMClientClass;
167
168 GType nm_client_get_type (void);
169
170 NMClient *nm_client_new (void);
171
172 void      nm_client_new_async  (GCancellable         *cancellable,
173                                 GAsyncReadyCallback   callback,
174                                 gpointer              user_data);
175 NMClient *nm_client_new_finish (GAsyncResult         *result,
176                                 GError              **error);
177
178 const GPtrArray *nm_client_get_devices    (NMClient *client);
179 NM_AVAILABLE_IN_1_2
180 const GPtrArray *nm_client_get_all_devices(NMClient *client);
181 NMDevice *nm_client_get_device_by_path    (NMClient *client, const char *object_path);
182 NMDevice *nm_client_get_device_by_iface   (NMClient *client, const char *iface);
183
184 typedef void (*NMClientActivateFn) (NMClient *client,
185                                     NMActiveConnection *active_connection,
186                                     GError *error,
187                                     gpointer user_data);
188
189 void nm_client_activate_connection (NMClient *client,
190                                     NMConnection *connection,
191                                     NMDevice *device,
192                                     const char *specific_object,
193                                     NMClientActivateFn callback,
194                                     gpointer user_data);
195
196 typedef void (*NMClientAddActivateFn) (NMClient *client,
197                                        NMActiveConnection *connection,
198                                        const char *new_connection_path,
199                                        GError *error,
200                                        gpointer user_data);
201
202 void nm_client_add_and_activate_connection (NMClient *client,
203                                             NMConnection *partial,
204                                             NMDevice *device,
205                                             const char *specific_object,
206                                             NMClientAddActivateFn callback,
207                                             gpointer user_data);
208
209 void nm_client_deactivate_connection (NMClient *client, NMActiveConnection *active);
210
211 gboolean  nm_client_networking_get_enabled (NMClient *client);
212 void      nm_client_networking_set_enabled (NMClient *client, gboolean enabled);
213
214 gboolean  nm_client_wireless_get_enabled (NMClient *client);
215 void      nm_client_wireless_set_enabled (NMClient *client, gboolean enabled);
216 gboolean  nm_client_wireless_hardware_get_enabled (NMClient *client);
217
218 gboolean  nm_client_wwan_get_enabled (NMClient *client);
219 void      nm_client_wwan_set_enabled (NMClient *client, gboolean enabled);
220 gboolean  nm_client_wwan_hardware_get_enabled (NMClient *client);
221
222 gboolean  nm_client_wimax_get_enabled (NMClient *client);
223 void      nm_client_wimax_set_enabled (NMClient *client, gboolean enabled);
224 gboolean  nm_client_wimax_hardware_get_enabled (NMClient *client);
225
226 const char *nm_client_get_version        (NMClient *client);
227 NMState   nm_client_get_state            (NMClient *client);
228 NM_AVAILABLE_IN_0_9_10
229 gboolean  nm_client_get_startup          (NMClient *client);
230 gboolean  nm_client_get_manager_running  (NMClient *client);
231 const GPtrArray *nm_client_get_active_connections (NMClient *client);
232 void      nm_client_sleep                (NMClient *client, gboolean sleep_);
233
234 NMClientPermissionResult nm_client_get_permission_result (NMClient *client,
235                                                           NMClientPermission permission);
236
237 gboolean nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error);
238 gboolean nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error);
239
240 NMConnectivityState nm_client_get_connectivity          (NMClient *client);
241
242 NMConnectivityState nm_client_check_connectivity        (NMClient *client,
243                                                          GCancellable *cancellable,
244                                                          GError **error);
245 void                nm_client_check_connectivity_async  (NMClient *client,
246                                                          GCancellable *cancellable,
247                                                          GAsyncReadyCallback callback,
248                                                          gpointer user_data);
249 NMConnectivityState nm_client_check_connectivity_finish (NMClient *client,
250                                                          GAsyncResult *result,
251                                                          GError **error);
252
253 NMActiveConnection *nm_client_get_primary_connection (NMClient *client);
254 NMActiveConnection *nm_client_get_activating_connection (NMClient *client);
255
256 G_END_DECLS
257
258 #endif /* NM_CLIENT_H */