1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
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.
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.
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.
18 * Copyright 2007 - 2008 Novell, Inc.
19 * Copyright 2007 - 2014 Red Hat, Inc.
22 #include "nm-default.h"
27 #include "nm-client.h"
28 #include "nm-manager.h"
29 #include "nm-remote-settings.h"
30 #include "nm-device-ethernet.h"
31 #include "nm-device-wifi.h"
32 #include "nm-device-private.h"
33 #include "nm-core-internal.h"
34 #include "nm-active-connection.h"
35 #include "nm-vpn-connection.h"
36 #include "nm-remote-connection.h"
37 #include "nm-object-cache.h"
38 #include "nm-dbus-helpers.h"
40 void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
42 static void nm_client_initable_iface_init (GInitableIface *iface);
43 static void nm_client_async_initable_iface_init (GAsyncInitableIface *iface);
45 G_DEFINE_TYPE_WITH_CODE (NMClient, nm_client, G_TYPE_OBJECT,
46 G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, nm_client_initable_iface_init);
47 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, nm_client_async_initable_iface_init);
50 #define NM_CLIENT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_CLIENT, NMClientPrivate))
54 NMRemoteSettings *settings;
63 PROP_NETWORKING_ENABLED,
64 PROP_WIRELESS_ENABLED,
65 PROP_WIRELESS_HARDWARE_ENABLED,
67 PROP_WWAN_HARDWARE_ENABLED,
69 PROP_WIMAX_HARDWARE_ENABLED,
70 PROP_ACTIVE_CONNECTIONS,
72 PROP_PRIMARY_CONNECTION,
73 PROP_ACTIVATING_CONNECTION,
96 static guint signals[LAST_SIGNAL] = { 0 };
98 /**********************************************************************/
101 * nm_client_error_quark:
103 * Registers an error quark for #NMClient if necessary.
105 * Returns: the error quark used for #NMClient errors.
108 nm_client_error_quark (void)
112 if (G_UNLIKELY (!quark))
113 quark = g_quark_from_static_string ("nm-client-error-quark");
117 /**********************************************************************/
120 nm_client_init (NMClient *client)
125 _nm_client_check_nm_running (NMClient *client, GError **error)
127 if (nm_client_get_nm_running (client))
130 g_set_error_literal (error,
132 NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
133 "NetworkManager is not running");
139 * nm_client_get_version:
140 * @client: a #NMClient
142 * Gets NetworkManager version.
144 * Returns: string with the version (or %NULL if NetworkManager is not running)
147 nm_client_get_version (NMClient *client)
149 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
151 return nm_manager_get_version (NM_CLIENT_GET_PRIVATE (client)->manager);
155 * nm_client_get_state:
156 * @client: a #NMClient
158 * Gets the current daemon state.
160 * Returns: the current %NMState
163 nm_client_get_state (NMClient *client)
165 g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
167 return nm_manager_get_state (NM_CLIENT_GET_PRIVATE (client)->manager);
171 * nm_client_get_startup:
172 * @client: a #NMClient
174 * Tests whether the daemon is still in the process of activating
175 * connections at startup.
177 * Returns: whether the daemon is still starting up
180 nm_client_get_startup (NMClient *client)
182 g_return_val_if_fail (NM_IS_CLIENT (client), NM_STATE_UNKNOWN);
184 return nm_manager_get_startup (NM_CLIENT_GET_PRIVATE (client)->manager);
188 * nm_client_get_nm_running:
189 * @client: a #NMClient
191 * Determines whether the daemon is running.
193 * Returns: %TRUE if the daemon is running
196 nm_client_get_nm_running (NMClient *client)
198 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
200 return nm_manager_get_nm_running (NM_CLIENT_GET_PRIVATE (client)->manager);
204 * nm_client_networking_get_enabled:
205 * @client: a #NMClient
207 * Whether networking is enabled or disabled.
209 * Returns: %TRUE if networking is enabled, %FALSE if networking is disabled
212 nm_client_networking_get_enabled (NMClient *client)
214 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
216 return nm_manager_networking_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
220 * nm_client_networking_set_enabled:
221 * @client: a #NMClient
222 * @enabled: %TRUE to set networking enabled, %FALSE to set networking disabled
223 * @error: (allow-none): return location for a #GError, or %NULL
225 * Enables or disables networking. When networking is disabled, all controlled
226 * interfaces are disconnected and deactivated. When networking is enabled,
227 * all controlled interfaces are available for activation.
229 * Returns: %TRUE on success, %FALSE otherwise
232 nm_client_networking_set_enabled (NMClient *client, gboolean enable, GError **error)
234 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
236 if (!_nm_client_check_nm_running (client, error))
239 return nm_manager_networking_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager,
244 * nm_client_wireless_get_enabled:
245 * @client: a #NMClient
247 * Determines whether the wireless is enabled.
249 * Returns: %TRUE if wireless is enabled
252 nm_client_wireless_get_enabled (NMClient *client)
254 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
256 return nm_manager_wireless_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
260 * nm_client_wireless_set_enabled:
261 * @client: a #NMClient
262 * @enabled: %TRUE to enable wireless
264 * Enables or disables wireless devices.
267 nm_client_wireless_set_enabled (NMClient *client, gboolean enabled)
269 g_return_if_fail (NM_IS_CLIENT (client));
271 if (!_nm_client_check_nm_running (client, NULL))
274 nm_manager_wireless_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
278 * nm_client_wireless_hardware_get_enabled:
279 * @client: a #NMClient
281 * Determines whether the wireless hardware is enabled.
283 * Returns: %TRUE if the wireless hardware is enabled
286 nm_client_wireless_hardware_get_enabled (NMClient *client)
288 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
290 return nm_manager_wireless_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
294 * nm_client_wwan_get_enabled:
295 * @client: a #NMClient
297 * Determines whether WWAN is enabled.
299 * Returns: %TRUE if WWAN is enabled
302 nm_client_wwan_get_enabled (NMClient *client)
304 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
306 return nm_manager_wwan_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
310 * nm_client_wwan_set_enabled:
311 * @client: a #NMClient
312 * @enabled: %TRUE to enable WWAN
314 * Enables or disables WWAN devices.
317 nm_client_wwan_set_enabled (NMClient *client, gboolean enabled)
319 g_return_if_fail (NM_IS_CLIENT (client));
321 if (!_nm_client_check_nm_running (client, NULL))
324 nm_manager_wwan_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
328 * nm_client_wwan_hardware_get_enabled:
329 * @client: a #NMClient
331 * Determines whether the WWAN hardware is enabled.
333 * Returns: %TRUE if the WWAN hardware is enabled
336 nm_client_wwan_hardware_get_enabled (NMClient *client)
338 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
340 return nm_manager_wwan_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
344 * nm_client_wimax_get_enabled:
345 * @client: a #NMClient
347 * Determines whether WiMAX is enabled.
349 * Returns: %TRUE if WiMAX is enabled
352 nm_client_wimax_get_enabled (NMClient *client)
354 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
356 return nm_manager_wimax_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
360 * nm_client_wimax_set_enabled:
361 * @client: a #NMClient
362 * @enabled: %TRUE to enable WiMAX
364 * Enables or disables WiMAX devices.
367 nm_client_wimax_set_enabled (NMClient *client, gboolean enabled)
369 g_return_if_fail (NM_IS_CLIENT (client));
371 if (!_nm_client_check_nm_running (client, NULL))
374 nm_manager_wimax_set_enabled (NM_CLIENT_GET_PRIVATE (client)->manager, enabled);
378 * nm_client_wimax_hardware_get_enabled:
379 * @client: a #NMClient
381 * Determines whether the WiMAX hardware is enabled.
383 * Returns: %TRUE if the WiMAX hardware is enabled
386 nm_client_wimax_hardware_get_enabled (NMClient *client)
388 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
390 return nm_manager_wimax_hardware_get_enabled (NM_CLIENT_GET_PRIVATE (client)->manager);
394 * nm_client_get_logging:
395 * @client: a #NMClient
396 * @level: (allow-none): return location for logging level string
397 * @domains: (allow-none): return location for log domains string. The string is
398 * a list of domains separated by ","
399 * @error: (allow-none): return location for a #GError, or %NULL
401 * Gets NetworkManager current logging level and domains.
403 * Returns: %TRUE on success, %FALSE otherwise
406 nm_client_get_logging (NMClient *client, char **level, char **domains, GError **error)
408 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
409 g_return_val_if_fail (level == NULL || *level == NULL, FALSE);
410 g_return_val_if_fail (domains == NULL || *domains == NULL, FALSE);
411 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
413 if (!_nm_client_check_nm_running (client, error))
416 return nm_manager_get_logging (NM_CLIENT_GET_PRIVATE (client)->manager,
417 level, domains, error);
421 * nm_client_set_logging:
422 * @client: a #NMClient
423 * @level: (allow-none): logging level to set (%NULL or an empty string for no change)
424 * @domains: (allow-none): logging domains to set. The string should be a list of log
425 * domains separated by ",". (%NULL or an empty string for no change)
426 * @error: (allow-none): return location for a #GError, or %NULL
428 * Sets NetworkManager logging level and/or domains.
430 * Returns: %TRUE on success, %FALSE otherwise
433 nm_client_set_logging (NMClient *client, const char *level, const char *domains, GError **error)
435 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
436 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
438 if (!_nm_client_check_nm_running (client, error))
441 return nm_manager_set_logging (NM_CLIENT_GET_PRIVATE (client)->manager,
442 level, domains, error);
446 * nm_client_get_permission_result:
447 * @client: a #NMClient
448 * @permission: the permission for which to return the result, one of #NMClientPermission
450 * Requests the result of a specific permission, which indicates whether the
451 * client can or cannot perform the action the permission represents
453 * Returns: the permission's result, one of #NMClientPermissionResult
455 NMClientPermissionResult
456 nm_client_get_permission_result (NMClient *client, NMClientPermission permission)
458 g_return_val_if_fail (NM_IS_CLIENT (client), NM_CLIENT_PERMISSION_RESULT_UNKNOWN);
460 return nm_manager_get_permission_result (NM_CLIENT_GET_PRIVATE (client)->manager, permission);
464 * nm_client_get_connectivity:
465 * @client: an #NMClient
467 * Gets the current network connectivity state. Contrast
468 * nm_client_check_connectivity() and
469 * nm_client_check_connectivity_async(), which re-check the
470 * connectivity state first before returning any information.
472 * Returns: the current connectivity state
475 nm_client_get_connectivity (NMClient *client)
477 g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
479 return nm_manager_get_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager);
483 * nm_client_check_connectivity:
484 * @client: an #NMClient
485 * @cancellable: a #GCancellable
486 * @error: return location for a #GError
488 * Updates the network connectivity state and returns the (new)
489 * current state. Contrast nm_client_get_connectivity(), which returns
490 * the most recent known state without re-checking.
492 * This is a blocking call; use nm_client_check_connectivity_async()
493 * if you do not want to block.
495 * Returns: the (new) current connectivity state
498 nm_client_check_connectivity (NMClient *client,
499 GCancellable *cancellable,
502 g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
504 if (!_nm_client_check_nm_running (client, error))
505 return NM_CONNECTIVITY_UNKNOWN;
507 return nm_manager_check_connectivity (NM_CLIENT_GET_PRIVATE (client)->manager,
512 check_connectivity_cb (GObject *object,
513 GAsyncResult *result,
516 GSimpleAsyncResult *simple = user_data;
517 NMConnectivityState connectivity;
518 GError *error = NULL;
520 connectivity = nm_manager_check_connectivity_finish (NM_MANAGER (object),
523 g_simple_async_result_set_op_res_gssize (simple, connectivity);
525 g_simple_async_result_take_error (simple, error);
527 g_simple_async_result_complete (simple);
528 g_object_unref (simple);
532 * nm_client_check_connectivity_async:
533 * @client: an #NMClient
534 * @cancellable: a #GCancellable
535 * @callback: callback to call with the result
536 * @user_data: data for @callback.
538 * Asynchronously updates the network connectivity state and invokes
539 * @callback when complete. Contrast nm_client_get_connectivity(),
540 * which (immediately) returns the most recent known state without
541 * re-checking, and nm_client_check_connectivity(), which blocks.
544 nm_client_check_connectivity_async (NMClient *client,
545 GCancellable *cancellable,
546 GAsyncReadyCallback callback,
549 GSimpleAsyncResult *simple;
550 GError *error = NULL;
552 g_return_if_fail (NM_IS_CLIENT (client));
554 if (!_nm_client_check_nm_running (client, &error)) {
555 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
559 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
560 nm_client_check_connectivity_async);
561 nm_manager_check_connectivity_async (NM_CLIENT_GET_PRIVATE (client)->manager,
562 cancellable, check_connectivity_cb, simple);
566 * nm_client_check_connectivity_finish:
567 * @client: an #NMClient
568 * @result: the #GAsyncResult
569 * @error: return location for a #GError
571 * Retrieves the result of an nm_client_check_connectivity_async()
574 * Returns: the (new) current connectivity state
577 nm_client_check_connectivity_finish (NMClient *client,
578 GAsyncResult *result,
581 GSimpleAsyncResult *simple;
583 g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
584 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NM_CONNECTIVITY_UNKNOWN);
586 simple = G_SIMPLE_ASYNC_RESULT (result);
588 if (g_simple_async_result_propagate_error (simple, error))
589 return NM_CONNECTIVITY_UNKNOWN;
590 return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
595 * nm_client_save_hostname:
596 * @client: the %NMClient
597 * @hostname: (allow-none): the new persistent hostname to set, or %NULL to
598 * clear any existing persistent hostname
599 * @cancellable: a #GCancellable, or %NULL
600 * @error: return location for #GError
602 * Requests that the machine's persistent hostname be set to the specified value
605 * Returns: %TRUE if the request was successful, %FALSE if it failed
608 nm_client_save_hostname (NMClient *client,
609 const char *hostname,
610 GCancellable *cancellable,
613 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
615 return nm_remote_settings_save_hostname (NM_CLIENT_GET_PRIVATE (client)->settings,
616 hostname, cancellable, error);
620 save_hostname_cb (GObject *object,
621 GAsyncResult *result,
624 GSimpleAsyncResult *simple = user_data;
625 GError *error = NULL;
627 if (nm_remote_settings_save_hostname_finish (NM_REMOTE_SETTINGS (object), result, &error))
628 g_simple_async_result_set_op_res_gboolean (simple, TRUE);
630 g_simple_async_result_take_error (simple, error);
632 g_simple_async_result_complete (simple);
633 g_object_unref (simple);
637 * nm_client_save_hostname_async:
638 * @client: the %NMClient
639 * @hostname: (allow-none): the new persistent hostname to set, or %NULL to
640 * clear any existing persistent hostname
641 * @cancellable: a #GCancellable, or %NULL
642 * @callback: (scope async): callback to be called when the operation completes
643 * @user_data: (closure): caller-specific data passed to @callback
645 * Requests that the machine's persistent hostname be set to the specified value
649 nm_client_save_hostname_async (NMClient *client,
650 const char *hostname,
651 GCancellable *cancellable,
652 GAsyncReadyCallback callback,
655 GSimpleAsyncResult *simple;
656 GError *error = NULL;
658 g_return_if_fail (NM_IS_CLIENT (client));
660 if (!_nm_client_check_nm_running (client, &error)) {
661 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
665 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
666 nm_client_save_hostname_async);
667 nm_remote_settings_save_hostname_async (NM_CLIENT_GET_PRIVATE (client)->settings,
669 cancellable, save_hostname_cb, simple);
673 * nm_client_save_hostname_finish:
674 * @client: the %NMClient
675 * @result: the result passed to the #GAsyncReadyCallback
676 * @error: return location for #GError
678 * Gets the result of an nm_client_save_hostname_async() call.
680 * Returns: %TRUE if the request was successful, %FALSE if it failed
683 nm_client_save_hostname_finish (NMClient *client,
684 GAsyncResult *result,
687 GSimpleAsyncResult *simple;
689 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
690 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
692 simple = G_SIMPLE_ASYNC_RESULT (result);
693 if (g_simple_async_result_propagate_error (simple, error))
696 return g_simple_async_result_get_op_res_gboolean (simple);
699 /****************************************************************/
701 /****************************************************************/
704 * nm_client_get_devices:
705 * @client: a #NMClient
707 * Gets all the known network devices. Use nm_device_get_type() or the
708 * <literal>NM_IS_DEVICE_XXXX</literal> functions to determine what kind of
709 * device member of the returned array is, and then you may use device-specific
710 * methods such as nm_device_ethernet_get_hw_address().
712 * Returns: (transfer none) (element-type NMDevice): a #GPtrArray
713 * containing all the #NMDevices. The returned array is owned by the
714 * #NMClient object and should not be modified.
717 nm_client_get_devices (NMClient *client)
719 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
721 return nm_manager_get_devices (NM_CLIENT_GET_PRIVATE (client)->manager);
725 * nm_client_get_all_devices:
726 * @client: a #NMClient
728 * Gets both real devices and device placeholders (eg, software devices which
729 * do not currently exist, but could be created automatically by NetworkManager
730 * if one of their NMDevice::ActivatableConnections was activated). Use
731 * nm_device_is_real() to determine whether each device is a real device or
734 * Use nm_device_get_type() or the NM_IS_DEVICE_XXXX() functions to determine
735 * what kind of device each member of the returned array is, and then you may
736 * use device-specific methods such as nm_device_ethernet_get_hw_address().
738 * Returns: (transfer none) (element-type NMDevice): a #GPtrArray
739 * containing all the #NMDevices. The returned array is owned by the
740 * #NMClient object and should not be modified.
745 nm_client_get_all_devices (NMClient *client)
747 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
749 return nm_manager_get_all_devices (NM_CLIENT_GET_PRIVATE (client)->manager);
753 * nm_client_get_device_by_path:
754 * @client: a #NMClient
755 * @object_path: the object path to search for
757 * Gets a #NMDevice from a #NMClient.
759 * Returns: (transfer none): the #NMDevice for the given @object_path or %NULL if none is found.
762 nm_client_get_device_by_path (NMClient *client, const char *object_path)
764 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
765 g_return_val_if_fail (object_path, NULL);
767 return nm_manager_get_device_by_path (NM_CLIENT_GET_PRIVATE (client)->manager, object_path);
771 * nm_client_get_device_by_iface:
772 * @client: a #NMClient
773 * @iface: the interface name to search for
775 * Gets a #NMDevice from a #NMClient.
777 * Returns: (transfer none): the #NMDevice for the given @iface or %NULL if none is found.
780 nm_client_get_device_by_iface (NMClient *client, const char *iface)
782 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
783 g_return_val_if_fail (iface, NULL);
785 return nm_manager_get_device_by_iface (NM_CLIENT_GET_PRIVATE (client)->manager, iface);
788 /****************************************************************/
789 /* Active Connections */
790 /****************************************************************/
793 * nm_client_get_active_connections:
794 * @client: a #NMClient
796 * Gets the active connections.
798 * Returns: (transfer none) (element-type NMActiveConnection): a #GPtrArray
799 * containing all the active #NMActiveConnections.
800 * The returned array is owned by the client and should not be modified.
803 nm_client_get_active_connections (NMClient *client)
805 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
807 return nm_manager_get_active_connections (NM_CLIENT_GET_PRIVATE (client)->manager);
811 * nm_client_get_primary_connection:
812 * @client: an #NMClient
814 * Gets the #NMActiveConnection corresponding to the primary active
817 * In particular, when there is no VPN active, or the VPN does not
818 * have the default route, this returns the active connection that has
819 * the default route. If there is a VPN active with the default route,
820 * then this function returns the active connection that contains the
821 * route to the VPN endpoint.
823 * If there is no default route, or the default route is over a
824 * non-NetworkManager-recognized device, this will return %NULL.
826 * Returns: (transfer none): the appropriate #NMActiveConnection, if
830 nm_client_get_primary_connection (NMClient *client)
832 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
834 return nm_manager_get_primary_connection (NM_CLIENT_GET_PRIVATE (client)->manager);
838 * nm_client_get_activating_connection:
839 * @client: an #NMClient
841 * Gets the #NMActiveConnection corresponding to a
842 * currently-activating connection that is expected to become the new
843 * #NMClient:primary-connection upon successful activation.
845 * Returns: (transfer none): the appropriate #NMActiveConnection, if
849 nm_client_get_activating_connection (NMClient *client)
851 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
853 return nm_manager_get_activating_connection (NM_CLIENT_GET_PRIVATE (client)->manager);
857 activate_cb (GObject *object,
858 GAsyncResult *result,
861 GSimpleAsyncResult *simple = user_data;
862 NMActiveConnection *ac;
863 GError *error = NULL;
865 ac = nm_manager_activate_connection_finish (NM_MANAGER (object), result, &error);
867 g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref);
869 g_simple_async_result_take_error (simple, error);
871 g_simple_async_result_complete (simple);
872 g_object_unref (simple);
876 * nm_client_activate_connection_async:
877 * @client: a #NMClient
878 * @connection: (allow-none): an #NMConnection
879 * @device: (allow-none): the #NMDevice
880 * @specific_object: (allow-none): the object path of a connection-type-specific
881 * object this activation should use. This parameter is currently ignored for
882 * wired and mobile broadband connections, and the value of %NULL should be used
883 * (ie, no specific object). For Wi-Fi or WiMAX connections, pass the object
884 * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can
885 * get using nm_object_get_path(), and which will be used to complete the
886 * details of the newly added connection.
887 * @cancellable: a #GCancellable, or %NULL
888 * @callback: callback to be called when the activation has started
889 * @user_data: caller-specific data passed to @callback
891 * Asynchronously starts a connection to a particular network using the
892 * configuration settings from @connection and the network device @device.
893 * Certain connection types also take a "specific object" which is the object
894 * path of a connection- specific object, like an #NMAccessPoint for Wi-Fi
895 * connections, or an #NMWimaxNsp for WiMAX connections, to which you wish to
896 * connect. If the specific object is not given, NetworkManager can, in some
897 * cases, automatically determine which network to connect to given the settings
900 * If @connection is not given for a device-based activation, NetworkManager
901 * picks the best available connection for the device and activates it.
903 * Note that the callback is invoked when NetworkManager has started activating
904 * the new connection, not when it finishes. You can used the returned
905 * #NMActiveConnection object (in particular, #NMActiveConnection:state) to
906 * track the activation to its completion.
909 nm_client_activate_connection_async (NMClient *client,
910 NMConnection *connection,
912 const char *specific_object,
913 GCancellable *cancellable,
914 GAsyncReadyCallback callback,
917 GSimpleAsyncResult *simple;
918 GError *error = NULL;
920 g_return_if_fail (NM_IS_CLIENT (client));
922 g_return_if_fail (NM_IS_DEVICE (device));
924 g_return_if_fail (NM_IS_CONNECTION (connection));
926 if (!_nm_client_check_nm_running (client, &error)) {
927 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
931 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
932 nm_client_activate_connection_async);
933 nm_manager_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
934 connection, device, specific_object,
935 cancellable, activate_cb, simple);
939 * nm_client_activate_connection_finish:
940 * @client: an #NMClient
941 * @result: the result passed to the #GAsyncReadyCallback
942 * @error: location for a #GError, or %NULL
944 * Gets the result of a call to nm_client_activate_connection_async().
946 * Returns: (transfer full): the new #NMActiveConnection on success, %NULL on
947 * failure, in which case @error will be set.
950 nm_client_activate_connection_finish (NMClient *client,
951 GAsyncResult *result,
954 GSimpleAsyncResult *simple;
956 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
957 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
959 simple = G_SIMPLE_ASYNC_RESULT (result);
960 if (g_simple_async_result_propagate_error (simple, error))
963 return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
967 add_activate_cb (GObject *object,
968 GAsyncResult *result,
971 GSimpleAsyncResult *simple = user_data;
972 NMActiveConnection *ac;
973 GError *error = NULL;
975 ac = nm_manager_add_and_activate_connection_finish (NM_MANAGER (object), result, &error);
977 g_simple_async_result_set_op_res_gpointer (simple, ac, g_object_unref);
979 g_simple_async_result_take_error (simple, error);
981 g_simple_async_result_complete (simple);
982 g_object_unref (simple);
986 * nm_client_add_and_activate_connection_async:
987 * @client: a #NMClient
988 * @partial: (allow-none): an #NMConnection to add; the connection may be
989 * partially filled (or even %NULL) and will be completed by NetworkManager
990 * using the given @device and @specific_object before being added
991 * @device: the #NMDevice
992 * @specific_object: (allow-none): the object path of a connection-type-specific
993 * object this activation should use. This parameter is currently ignored for
994 * wired and mobile broadband connections, and the value of %NULL should be used
995 * (ie, no specific object). For Wi-Fi or WiMAX connections, pass the object
996 * path of a #NMAccessPoint or #NMWimaxNsp owned by @device, which you can
997 * get using nm_object_get_path(), and which will be used to complete the
998 * details of the newly added connection.
999 * @cancellable: a #GCancellable, or %NULL
1000 * @callback: callback to be called when the activation has started
1001 * @user_data: caller-specific data passed to @callback
1003 * Adds a new connection using the given details (if any) as a template,
1004 * automatically filling in missing settings with the capabilities of the given
1005 * device and specific object. The new connection is then asynchronously
1006 * activated as with nm_client_activate_connection_async(). Cannot be used for
1007 * VPN connections at this time.
1009 * Note that the callback is invoked when NetworkManager has started activating
1010 * the new connection, not when it finishes. You can used the returned
1011 * #NMActiveConnection object (in particular, #NMActiveConnection:state) to
1012 * track the activation to its completion.
1015 nm_client_add_and_activate_connection_async (NMClient *client,
1016 NMConnection *partial,
1018 const char *specific_object,
1019 GCancellable *cancellable,
1020 GAsyncReadyCallback callback,
1023 GSimpleAsyncResult *simple;
1024 GError *error = NULL;
1026 g_return_if_fail (NM_IS_CLIENT (client));
1027 g_return_if_fail (NM_IS_DEVICE (device));
1029 g_return_if_fail (NM_IS_CONNECTION (partial));
1031 if (!_nm_client_check_nm_running (client, &error)) {
1032 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
1036 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
1037 nm_client_add_and_activate_connection_async);
1038 nm_manager_add_and_activate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
1039 partial, device, specific_object,
1040 cancellable, add_activate_cb, simple);
1044 * nm_client_add_and_activate_connection_finish:
1045 * @client: an #NMClient
1046 * @result: the result passed to the #GAsyncReadyCallback
1047 * @error: location for a #GError, or %NULL
1049 * Gets the result of a call to nm_client_add_and_activate_connection_async().
1051 * You can call nm_active_connection_get_connection() on the returned
1052 * #NMActiveConnection to find the path of the created #NMConnection.
1054 * Returns: (transfer full): the new #NMActiveConnection on success, %NULL on
1055 * failure, in which case @error will be set.
1057 NMActiveConnection *
1058 nm_client_add_and_activate_connection_finish (NMClient *client,
1059 GAsyncResult *result,
1062 GSimpleAsyncResult *simple;
1064 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1065 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
1067 simple = G_SIMPLE_ASYNC_RESULT (result);
1068 if (g_simple_async_result_propagate_error (simple, error))
1071 return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
1075 * nm_client_deactivate_connection:
1076 * @client: a #NMClient
1077 * @active: the #NMActiveConnection to deactivate
1078 * @cancellable: a #GCancellable, or %NULL
1079 * @error: location for a #GError, or %NULL
1081 * Deactivates an active #NMActiveConnection.
1083 * Returns: success or failure
1086 nm_client_deactivate_connection (NMClient *client,
1087 NMActiveConnection *active,
1088 GCancellable *cancellable,
1091 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1092 g_return_val_if_fail (NM_IS_ACTIVE_CONNECTION (active), FALSE);
1094 if (!_nm_client_check_nm_running (client, NULL))
1097 return nm_manager_deactivate_connection (NM_CLIENT_GET_PRIVATE (client)->manager,
1098 active, cancellable, error);
1102 deactivated_cb (GObject *object,
1103 GAsyncResult *result,
1106 GSimpleAsyncResult *simple = user_data;
1107 GError *error = NULL;
1109 if (nm_manager_deactivate_connection_finish (NM_MANAGER (object), result, &error))
1110 g_simple_async_result_set_op_res_gboolean (simple, TRUE);
1112 g_simple_async_result_take_error (simple, error);
1113 g_simple_async_result_complete (simple);
1114 g_object_unref (simple);
1118 * nm_client_deactivate_connection_async:
1119 * @client: a #NMClient
1120 * @active: the #NMActiveConnection to deactivate
1121 * @cancellable: a #GCancellable, or %NULL
1122 * @callback: callback to be called when the deactivation has completed
1123 * @user_data: caller-specific data passed to @callback
1125 * Asynchronously deactivates an active #NMActiveConnection.
1128 nm_client_deactivate_connection_async (NMClient *client,
1129 NMActiveConnection *active,
1130 GCancellable *cancellable,
1131 GAsyncReadyCallback callback,
1134 GSimpleAsyncResult *simple;
1136 g_return_if_fail (NM_IS_CLIENT (client));
1137 g_return_if_fail (NM_IS_ACTIVE_CONNECTION (active));
1139 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
1140 nm_client_deactivate_connection_async);
1142 if (!_nm_client_check_nm_running (client, NULL)) {
1143 g_simple_async_result_set_op_res_gboolean (simple, TRUE);
1144 g_simple_async_result_complete_in_idle (simple);
1145 g_object_unref (simple);
1149 nm_manager_deactivate_connection_async (NM_CLIENT_GET_PRIVATE (client)->manager,
1151 cancellable, deactivated_cb, simple);
1155 * nm_client_deactivate_connection_finish:
1156 * @client: a #NMClient
1157 * @result: the result passed to the #GAsyncReadyCallback
1158 * @error: location for a #GError, or %NULL
1160 * Gets the result of a call to nm_client_deactivate_connection_async().
1162 * Returns: success or failure
1165 nm_client_deactivate_connection_finish (NMClient *client,
1166 GAsyncResult *result,
1169 GSimpleAsyncResult *simple;
1171 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1172 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
1174 simple = G_SIMPLE_ASYNC_RESULT (result);
1175 if (g_simple_async_result_propagate_error (simple, error))
1178 return g_simple_async_result_get_op_res_gboolean (simple);
1181 /****************************************************************/
1183 /****************************************************************/
1186 * nm_client_get_connections:
1187 * @client: the %NMClient
1189 * Returns: (transfer none) (element-type NMRemoteConnection): an array
1190 * containing all connections provided by the remote settings service. The
1191 * returned array is owned by the #NMClient object and should not be modified.
1194 nm_client_get_connections (NMClient *client)
1196 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1198 return nm_remote_settings_get_connections (NM_CLIENT_GET_PRIVATE (client)->settings);
1202 * nm_client_get_connection_by_id:
1203 * @client: the %NMClient
1204 * @id: the id of the remote connection
1206 * Returns the first matching %NMRemoteConnection matching a given @id.
1208 * Returns: (transfer none): the remote connection object on success, or %NULL if no
1209 * matching object was found.
1211 NMRemoteConnection *
1212 nm_client_get_connection_by_id (NMClient *client, const char *id)
1214 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1215 g_return_val_if_fail (id != NULL, NULL);
1217 return nm_remote_settings_get_connection_by_id (NM_CLIENT_GET_PRIVATE (client)->settings, id);
1221 * nm_client_get_connection_by_path:
1222 * @client: the %NMClient
1223 * @path: the D-Bus object path of the remote connection
1225 * Returns the %NMRemoteConnection representing the connection at @path.
1227 * Returns: (transfer none): the remote connection object on success, or %NULL if the object was
1230 NMRemoteConnection *
1231 nm_client_get_connection_by_path (NMClient *client, const char *path)
1233 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1234 g_return_val_if_fail (path != NULL, NULL);
1236 return nm_remote_settings_get_connection_by_path (NM_CLIENT_GET_PRIVATE (client)->settings, path);
1240 * nm_client_get_connection_by_uuid:
1241 * @client: the %NMClient
1242 * @uuid: the UUID of the remote connection
1244 * Returns the %NMRemoteConnection identified by @uuid.
1246 * Returns: (transfer none): the remote connection object on success, or %NULL if the object was
1249 NMRemoteConnection *
1250 nm_client_get_connection_by_uuid (NMClient *client, const char *uuid)
1252 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1253 g_return_val_if_fail (uuid != NULL, NULL);
1255 return nm_remote_settings_get_connection_by_uuid (NM_CLIENT_GET_PRIVATE (client)->settings, uuid);
1259 add_connection_cb (GObject *object,
1260 GAsyncResult *result,
1263 GSimpleAsyncResult *simple = user_data;
1264 NMRemoteConnection *conn;
1265 GError *error = NULL;
1267 conn = nm_remote_settings_add_connection_finish (NM_REMOTE_SETTINGS (object), result, &error);
1269 g_simple_async_result_set_op_res_gpointer (simple, conn, g_object_unref);
1271 g_simple_async_result_take_error (simple, error);
1273 g_simple_async_result_complete (simple);
1274 g_object_unref (simple);
1278 * nm_client_add_connection_async:
1279 * @client: the %NMClient
1280 * @connection: the connection to add. Note that this object's settings will be
1281 * added, not the object itself
1282 * @save_to_disk: whether to immediately save the connection to disk
1283 * @cancellable: a #GCancellable, or %NULL
1284 * @callback: (scope async): callback to be called when the add operation completes
1285 * @user_data: (closure): caller-specific data passed to @callback
1287 * Requests that the remote settings service add the given settings to a new
1288 * connection. If @save_to_disk is %TRUE, the connection is immediately written
1289 * to disk; otherwise it is initially only stored in memory, but may be saved
1290 * later by calling the connection's nm_remote_connection_commit_changes()
1293 * @connection is untouched by this function and only serves as a template of
1294 * the settings to add. The #NMRemoteConnection object that represents what
1295 * NetworkManager actually added is returned to @callback when the addition
1296 * operation is complete.
1298 * Note that the #NMRemoteConnection returned in @callback may not contain
1299 * identical settings to @connection as NetworkManager may perform automatic
1300 * completion and/or normalization of connection properties.
1303 nm_client_add_connection_async (NMClient *client,
1304 NMConnection *connection,
1305 gboolean save_to_disk,
1306 GCancellable *cancellable,
1307 GAsyncReadyCallback callback,
1310 GSimpleAsyncResult *simple;
1311 GError *error = NULL;
1313 g_return_if_fail (NM_IS_CLIENT (client));
1314 g_return_if_fail (NM_IS_CONNECTION (connection));
1316 if (!_nm_client_check_nm_running (client, &error)) {
1317 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
1321 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
1322 nm_client_add_connection_async);
1323 nm_remote_settings_add_connection_async (NM_CLIENT_GET_PRIVATE (client)->settings,
1324 connection, save_to_disk,
1325 cancellable, add_connection_cb, simple);
1329 * nm_client_add_connection_finish:
1330 * @client: an #NMClient
1331 * @result: the result passed to the #GAsyncReadyCallback
1332 * @error: location for a #GError, or %NULL
1334 * Gets the result of a call to nm_client_add_connection_async().
1336 * Returns: (transfer full): the new #NMRemoteConnection on success, %NULL on
1337 * failure, in which case @error will be set.
1339 NMRemoteConnection *
1340 nm_client_add_connection_finish (NMClient *client,
1341 GAsyncResult *result,
1344 GSimpleAsyncResult *simple;
1346 g_return_val_if_fail (NM_IS_CLIENT (client), NULL);
1347 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NULL);
1349 simple = G_SIMPLE_ASYNC_RESULT (result);
1350 if (g_simple_async_result_propagate_error (simple, error))
1353 return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
1357 * nm_client_load_connections:
1358 * @client: the %NMClient
1359 * @filenames: %NULL-terminated array of filenames to load
1360 * @failures: (out) (transfer full): on return, a %NULL-terminated array of
1361 * filenames that failed to load
1362 * @cancellable: a #GCancellable, or %NULL
1363 * @error: return location for #GError
1365 * Requests that the remote settings service load or reload the given files,
1366 * adding or updating the connections described within.
1368 * The changes to the indicated files will not yet be reflected in
1369 * @client's connections array when the function returns.
1371 * If all of the indicated files were successfully loaded, the
1372 * function will return %TRUE, and @failures will be set to %NULL. If
1373 * NetworkManager tried to load the files, but some (or all) failed,
1374 * then @failures will be set to a %NULL-terminated array of the
1375 * filenames that failed to load.
1377 * Returns: %TRUE if NetworkManager at least tried to load @filenames,
1378 * %FALSE if an error occurred (eg, permission denied).
1381 nm_client_load_connections (NMClient *client,
1384 GCancellable *cancellable,
1387 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1388 g_return_val_if_fail (filenames != NULL, FALSE);
1390 if (!_nm_client_check_nm_running (client, error))
1393 return nm_remote_settings_load_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
1394 filenames, failures,
1395 cancellable, error);
1399 load_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
1401 GSimpleAsyncResult *simple = user_data;
1402 GError *error = NULL;
1403 char **failures = NULL;
1405 if (nm_remote_settings_load_connections_finish (NM_REMOTE_SETTINGS (object),
1406 &failures, result, &error))
1407 g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev);
1409 g_simple_async_result_take_error (simple, error);
1411 g_simple_async_result_complete (simple);
1412 g_object_unref (simple);
1416 * nm_client_load_connections_async:
1417 * @client: the %NMClient
1418 * @filenames: %NULL-terminated array of filenames to load
1419 * @cancellable: a #GCancellable, or %NULL
1420 * @callback: (scope async): callback to be called when the operation completes
1421 * @user_data: (closure): caller-specific data passed to @callback
1423 * Requests that the remote settings service asynchronously load or reload the
1424 * given files, adding or updating the connections described within.
1426 * See nm_client_load_connections() for more details.
1429 nm_client_load_connections_async (NMClient *client,
1431 GCancellable *cancellable,
1432 GAsyncReadyCallback callback,
1435 GSimpleAsyncResult *simple;
1436 GError *error = NULL;
1438 g_return_if_fail (NM_IS_CLIENT (client));
1439 g_return_if_fail (filenames != NULL);
1441 if (!_nm_client_check_nm_running (client, &error)) {
1442 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
1446 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
1447 nm_client_load_connections_async);
1448 nm_remote_settings_load_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings,
1450 cancellable, load_connections_cb, simple);
1454 * nm_client_load_connections_finish:
1455 * @client: the %NMClient
1456 * @failures: (out) (transfer full): on return, a %NULL-terminated array of
1457 * filenames that failed to load
1458 * @result: the result passed to the #GAsyncReadyCallback
1459 * @error: location for a #GError, or %NULL
1461 * Gets the result of an nm_client_load_connections_async() call.
1463 * See nm_client_load_connections() for more details.
1465 * Returns: %TRUE if NetworkManager at least tried to load @filenames,
1466 * %FALSE if an error occurred (eg, permission denied).
1469 nm_client_load_connections_finish (NMClient *client,
1471 GAsyncResult *result,
1474 GSimpleAsyncResult *simple;
1476 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1477 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
1479 simple = G_SIMPLE_ASYNC_RESULT (result);
1480 if (g_simple_async_result_propagate_error (simple, error))
1484 *failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple));
1490 * nm_client_reload_connections:
1491 * @client: the #NMClient
1492 * @cancellable: a #GCancellable, or %NULL
1493 * @error: return location for #GError
1495 * Requests that the remote settings service reload all connection
1496 * files from disk, adding, updating, and removing connections until
1497 * the in-memory state matches the on-disk state.
1499 * Return value: %TRUE on success, %FALSE on failure
1502 nm_client_reload_connections (NMClient *client,
1503 GCancellable *cancellable,
1506 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1508 if (!_nm_client_check_nm_running (client, error))
1511 return nm_remote_settings_reload_connections (NM_CLIENT_GET_PRIVATE (client)->settings,
1512 cancellable, error);
1516 reload_connections_cb (GObject *object, GAsyncResult *result, gpointer user_data)
1518 GSimpleAsyncResult *simple = user_data;
1519 GError *error = NULL;
1521 if (nm_remote_settings_reload_connections_finish (NM_REMOTE_SETTINGS (object),
1523 g_simple_async_result_set_op_res_gboolean (simple, TRUE);
1525 g_simple_async_result_take_error (simple, error);
1527 g_simple_async_result_complete (simple);
1528 g_object_unref (simple);
1532 * nm_client_reload_connections_async:
1533 * @client: the #NMClient
1534 * @cancellable: a #GCancellable, or %NULL
1535 * @callback: (scope async): callback to be called when the reload operation completes
1536 * @user_data: (closure): caller-specific data passed to @callback
1538 * Requests that the remote settings service begin reloading all connection
1539 * files from disk, adding, updating, and removing connections until the
1540 * in-memory state matches the on-disk state.
1543 nm_client_reload_connections_async (NMClient *client,
1544 GCancellable *cancellable,
1545 GAsyncReadyCallback callback,
1548 GSimpleAsyncResult *simple;
1549 GError *error = NULL;
1551 g_return_if_fail (NM_IS_CLIENT (client));
1553 if (!_nm_client_check_nm_running (client, &error)) {
1554 g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error);
1558 simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data,
1559 nm_client_reload_connections_async);
1560 nm_remote_settings_reload_connections_async (NM_CLIENT_GET_PRIVATE (client)->settings,
1561 cancellable, reload_connections_cb, simple);
1565 * nm_client_reload_connections_finish:
1566 * @client: the #NMClient
1567 * @result: the result passed to the #GAsyncReadyCallback
1568 * @error: return location for #GError
1570 * Gets the result of an nm_client_reload_connections_async() call.
1572 * Return value: %TRUE on success, %FALSE on failure
1575 nm_client_reload_connections_finish (NMClient *client,
1576 GAsyncResult *result,
1579 GSimpleAsyncResult *simple;
1581 g_return_val_if_fail (NM_IS_CLIENT (client), FALSE);
1582 g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), FALSE);
1584 simple = G_SIMPLE_ASYNC_RESULT (result);
1585 if (g_simple_async_result_propagate_error (simple, error))
1588 return g_simple_async_result_get_op_res_gboolean (simple);
1591 /****************************************************************/
1595 * @cancellable: a #GCancellable, or %NULL
1596 * @error: location for a #GError, or %NULL
1598 * Creates a new #NMClient.
1600 * Note that this will do blocking D-Bus calls to initialize the
1601 * client. You can use nm_client_new_async() if you want to avoid
1604 * Returns: a new #NMClient or NULL on an error
1607 nm_client_new (GCancellable *cancellable,
1610 return g_initable_new (NM_TYPE_CLIENT, cancellable, error,
1615 client_inited (GObject *source, GAsyncResult *result, gpointer user_data)
1617 GSimpleAsyncResult *simple = user_data;
1618 GError *error = NULL;
1620 if (!g_async_initable_new_finish (G_ASYNC_INITABLE (source), result, &error))
1621 g_simple_async_result_take_error (simple, error);
1623 g_simple_async_result_set_op_res_gpointer (simple, source, g_object_unref);
1624 g_simple_async_result_complete (simple);
1625 g_object_unref (simple);
1629 * nm_client_new_async:
1630 * @cancellable: a #GCancellable, or %NULL
1631 * @callback: callback to call when the client is created
1632 * @user_data: data for @callback
1634 * Creates a new #NMClient and begins asynchronously initializing it.
1635 * @callback will be called when it is done; use
1636 * nm_client_new_finish() to get the result. Note that on an error,
1637 * the callback can be invoked with two first parameters as NULL.
1640 nm_client_new_async (GCancellable *cancellable,
1641 GAsyncReadyCallback callback,
1644 GSimpleAsyncResult *simple;
1646 simple = g_simple_async_result_new (NULL, callback, user_data, nm_client_new_async);
1648 g_async_initable_new_async (NM_TYPE_CLIENT, G_PRIORITY_DEFAULT,
1649 cancellable, client_inited, simple,
1654 * nm_client_new_finish:
1655 * @result: a #GAsyncResult
1656 * @error: location for a #GError, or %NULL
1658 * Gets the result of an nm_client_new_async() call.
1660 * Returns: a new #NMClient, or %NULL on error
1663 nm_client_new_finish (GAsyncResult *result, GError **error)
1665 GSimpleAsyncResult *simple;
1667 g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL, nm_client_new_async), NULL);
1668 g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
1670 simple = G_SIMPLE_ASYNC_RESULT (result);
1671 if (g_simple_async_result_propagate_error (simple, error))
1674 return g_object_ref (g_simple_async_result_get_op_res_gpointer (simple));
1678 subobject_notify (GObject *object,
1682 if (!g_str_has_suffix (pspec->name, "-internal"))
1683 g_object_notify (client, pspec->name);
1687 manager_device_added (NMManager *manager,
1691 g_signal_emit (client, signals[DEVICE_ADDED], 0, device);
1695 manager_device_removed (NMManager *manager,
1699 g_signal_emit (client, signals[DEVICE_REMOVED], 0, device);
1703 manager_any_device_added (NMManager *manager,
1707 g_signal_emit (client, signals[ANY_DEVICE_ADDED], 0, device);
1711 manager_any_device_removed (NMManager *manager,
1715 g_signal_emit (client, signals[ANY_DEVICE_REMOVED], 0, device);
1719 manager_permission_changed (NMManager *manager,
1720 NMClientPermission permission,
1721 NMClientPermissionResult result,
1724 g_signal_emit (client, signals[PERMISSION_CHANGED], 0, permission, result);
1728 settings_connection_added (NMRemoteSettings *manager,
1729 NMRemoteConnection *connection,
1732 g_signal_emit (client, signals[CONNECTION_ADDED], 0, connection);
1735 settings_connection_removed (NMRemoteSettings *manager,
1736 NMRemoteConnection *connection,
1739 g_signal_emit (client, signals[CONNECTION_REMOVED], 0, connection);
1743 constructed (GObject *object)
1745 NMClient *client = NM_CLIENT (object);
1746 NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
1748 priv->manager = g_object_new (NM_TYPE_MANAGER,
1749 NM_OBJECT_PATH, NM_DBUS_PATH,
1751 g_signal_connect (priv->manager, "notify",
1752 G_CALLBACK (subobject_notify), client);
1753 g_signal_connect (priv->manager, "device-added",
1754 G_CALLBACK (manager_device_added), client);
1755 g_signal_connect (priv->manager, "device-removed",
1756 G_CALLBACK (manager_device_removed), client);
1757 g_signal_connect (priv->manager, "any-device-added",
1758 G_CALLBACK (manager_any_device_added), client);
1759 g_signal_connect (priv->manager, "any-device-removed",
1760 G_CALLBACK (manager_any_device_removed), client);
1761 g_signal_connect (priv->manager, "permission-changed",
1762 G_CALLBACK (manager_permission_changed), client);
1764 priv->settings = g_object_new (NM_TYPE_REMOTE_SETTINGS,
1765 NM_OBJECT_PATH, NM_DBUS_PATH_SETTINGS,
1767 g_signal_connect (priv->settings, "notify",
1768 G_CALLBACK (subobject_notify), client);
1769 g_signal_connect (priv->settings, "connection-added",
1770 G_CALLBACK (settings_connection_added), client);
1771 g_signal_connect (priv->settings, "connection-removed",
1772 G_CALLBACK (settings_connection_removed), client);
1774 G_OBJECT_CLASS (nm_client_parent_class)->constructed (object);
1778 init_sync (GInitable *initable, GCancellable *cancellable, GError **error)
1780 NMClient *client = NM_CLIENT (initable);
1781 NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (client);
1783 if (!g_initable_init (G_INITABLE (priv->manager), cancellable, error))
1785 if (!g_initable_init (G_INITABLE (priv->settings), cancellable, error))
1793 GCancellable *cancellable;
1794 GSimpleAsyncResult *result;
1795 gboolean manager_inited;
1796 gboolean settings_inited;
1800 init_async_complete (NMClientInitData *init_data)
1802 g_simple_async_result_complete (init_data->result);
1803 g_object_unref (init_data->result);
1804 g_clear_object (&init_data->cancellable);
1805 g_slice_free (NMClientInitData, init_data);
1809 init_async_inited_manager (GObject *object, GAsyncResult *result, gpointer user_data)
1811 NMClientInitData *init_data = user_data;
1812 GError *error = NULL;
1814 if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error))
1815 g_simple_async_result_take_error (init_data->result, error);
1817 init_data->manager_inited = TRUE;
1818 if (init_data->settings_inited)
1819 init_async_complete (init_data);
1823 init_async_inited_settings (GObject *object, GAsyncResult *result, gpointer user_data)
1825 NMClientInitData *init_data = user_data;
1826 GError *error = NULL;
1828 if (!g_async_initable_init_finish (G_ASYNC_INITABLE (object), result, &error))
1829 g_simple_async_result_take_error (init_data->result, error);
1831 init_data->settings_inited = TRUE;
1832 if (init_data->manager_inited)
1833 init_async_complete (init_data);
1837 init_async (GAsyncInitable *initable, int io_priority,
1838 GCancellable *cancellable, GAsyncReadyCallback callback,
1841 NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (initable);
1842 NMClientInitData *init_data;
1844 init_data = g_slice_new0 (NMClientInitData);
1845 init_data->client = NM_CLIENT (initable);
1846 init_data->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
1847 init_data->result = g_simple_async_result_new (G_OBJECT (initable), callback,
1848 user_data, init_async);
1849 g_simple_async_result_set_op_res_gboolean (init_data->result, TRUE);
1851 g_async_initable_init_async (G_ASYNC_INITABLE (priv->manager),
1852 G_PRIORITY_DEFAULT, init_data->cancellable,
1853 init_async_inited_manager, init_data);
1854 g_async_initable_init_async (G_ASYNC_INITABLE (priv->settings),
1855 G_PRIORITY_DEFAULT, init_data->cancellable,
1856 init_async_inited_settings, init_data);
1860 init_finish (GAsyncInitable *initable, GAsyncResult *result, GError **error)
1862 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (result);
1864 if (g_simple_async_result_propagate_error (simple, error))
1871 dispose (GObject *object)
1873 NMClientPrivate *priv = NM_CLIENT_GET_PRIVATE (object);
1875 if (priv->manager) {
1876 g_signal_handlers_disconnect_by_data (priv->manager, object);
1877 g_clear_object (&priv->manager);
1879 if (priv->settings) {
1880 g_signal_handlers_disconnect_by_data (priv->settings, object);
1881 g_clear_object (&priv->settings);
1884 G_OBJECT_CLASS (nm_client_parent_class)->dispose (object);
1888 set_property (GObject *object, guint prop_id,
1889 const GValue *value, GParamSpec *pspec)
1892 case PROP_NETWORKING_ENABLED:
1893 case PROP_WIRELESS_ENABLED:
1894 case PROP_WWAN_ENABLED:
1895 case PROP_WIMAX_ENABLED:
1896 g_object_set_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager),
1897 pspec->name, value);
1900 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1906 get_property (GObject *object, guint prop_id,
1907 GValue *value, GParamSpec *pspec)
1913 case PROP_NM_RUNNING:
1914 case PROP_NETWORKING_ENABLED:
1915 case PROP_WIRELESS_ENABLED:
1916 case PROP_WIRELESS_HARDWARE_ENABLED:
1917 case PROP_WWAN_ENABLED:
1918 case PROP_WWAN_HARDWARE_ENABLED:
1919 case PROP_WIMAX_ENABLED:
1920 case PROP_WIMAX_HARDWARE_ENABLED:
1921 case PROP_ACTIVE_CONNECTIONS:
1922 case PROP_CONNECTIVITY:
1923 case PROP_PRIMARY_CONNECTION:
1924 case PROP_ACTIVATING_CONNECTION:
1927 case PROP_ALL_DEVICES:
1928 g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->manager),
1929 pspec->name, value);
1931 case PROP_CONNECTIONS:
1933 case PROP_CAN_MODIFY:
1934 g_object_get_property (G_OBJECT (NM_CLIENT_GET_PRIVATE (object)->settings),
1935 pspec->name, value);
1938 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1944 nm_client_class_init (NMClientClass *client_class)
1946 GObjectClass *object_class = G_OBJECT_CLASS (client_class);
1948 g_type_class_add_private (client_class, sizeof (NMClientPrivate));
1950 /* virtual methods */
1951 object_class->constructed = constructed;
1952 object_class->set_property = set_property;
1953 object_class->get_property = get_property;
1954 object_class->dispose = dispose;
1961 * The NetworkManager version.
1963 g_object_class_install_property
1964 (object_class, PROP_VERSION,
1965 g_param_spec_string (NM_CLIENT_VERSION, "", "",
1968 G_PARAM_STATIC_STRINGS));
1973 * The current daemon state.
1975 g_object_class_install_property
1976 (object_class, PROP_STATE,
1977 g_param_spec_enum (NM_CLIENT_STATE, "", "",
1981 G_PARAM_STATIC_STRINGS));
1986 * Whether the daemon is still starting up.
1988 g_object_class_install_property
1989 (object_class, PROP_STARTUP,
1990 g_param_spec_boolean (NM_CLIENT_STARTUP, "", "",
1993 G_PARAM_STATIC_STRINGS));
1996 * NMClient:nm-running:
1998 * Whether the daemon is running.
2000 g_object_class_install_property
2001 (object_class, PROP_NM_RUNNING,
2002 g_param_spec_boolean (NM_CLIENT_NM_RUNNING, "", "",
2005 G_PARAM_STATIC_STRINGS));
2008 * NMClient:networking-enabled:
2010 * Whether networking is enabled.
2012 g_object_class_install_property
2013 (object_class, PROP_NETWORKING_ENABLED,
2014 g_param_spec_boolean (NM_CLIENT_NETWORKING_ENABLED, "", "",
2017 G_PARAM_STATIC_STRINGS));
2020 * NMClient:wireless-enabled:
2022 * Whether wireless is enabled.
2024 g_object_class_install_property
2025 (object_class, PROP_WIRELESS_ENABLED,
2026 g_param_spec_boolean (NM_CLIENT_WIRELESS_ENABLED, "", "",
2029 G_PARAM_STATIC_STRINGS));
2032 * NMClient:wireless-hardware-enabled:
2034 * Whether the wireless hardware is enabled.
2036 g_object_class_install_property
2037 (object_class, PROP_WIRELESS_HARDWARE_ENABLED,
2038 g_param_spec_boolean (NM_CLIENT_WIRELESS_HARDWARE_ENABLED, "", "",
2041 G_PARAM_STATIC_STRINGS));
2044 * NMClient:wwan-enabled:
2046 * Whether WWAN functionality is enabled.
2048 g_object_class_install_property
2049 (object_class, PROP_WWAN_ENABLED,
2050 g_param_spec_boolean (NM_CLIENT_WWAN_ENABLED, "", "",
2053 G_PARAM_STATIC_STRINGS));
2056 * NMClient:wwan-hardware-enabled:
2058 * Whether the WWAN hardware is enabled.
2060 g_object_class_install_property
2061 (object_class, PROP_WWAN_HARDWARE_ENABLED,
2062 g_param_spec_boolean (NM_CLIENT_WWAN_HARDWARE_ENABLED, "", "",
2065 G_PARAM_STATIC_STRINGS));
2068 * NMClient:wimax-enabled:
2070 * Whether WiMAX functionality is enabled.
2072 g_object_class_install_property
2073 (object_class, PROP_WIMAX_ENABLED,
2074 g_param_spec_boolean (NM_CLIENT_WIMAX_ENABLED, "", "",
2077 G_PARAM_STATIC_STRINGS));
2080 * NMClient:wimax-hardware-enabled:
2082 * Whether the WiMAX hardware is enabled.
2084 g_object_class_install_property
2085 (object_class, PROP_WIMAX_HARDWARE_ENABLED,
2086 g_param_spec_boolean (NM_CLIENT_WIMAX_HARDWARE_ENABLED, "", "",
2089 G_PARAM_STATIC_STRINGS));
2092 * NMClient:active-connections:
2094 * The active connections.
2096 * Element-type: NMActiveConnection
2098 g_object_class_install_property
2099 (object_class, PROP_ACTIVE_CONNECTIONS,
2100 g_param_spec_boxed (NM_CLIENT_ACTIVE_CONNECTIONS, "", "",
2103 G_PARAM_STATIC_STRINGS));
2106 * NMClient:connectivity:
2108 * The network connectivity state.
2110 g_object_class_install_property
2111 (object_class, PROP_CONNECTIVITY,
2112 g_param_spec_enum (NM_CLIENT_CONNECTIVITY, "", "",
2113 NM_TYPE_CONNECTIVITY_STATE,
2114 NM_CONNECTIVITY_UNKNOWN,
2116 G_PARAM_STATIC_STRINGS));
2119 * NMClient:primary-connection:
2121 * The #NMActiveConnection of the device with the default route;
2122 * see nm_client_get_primary_connection() for more details.
2124 g_object_class_install_property
2125 (object_class, PROP_PRIMARY_CONNECTION,
2126 g_param_spec_object (NM_CLIENT_PRIMARY_CONNECTION, "", "",
2127 NM_TYPE_ACTIVE_CONNECTION,
2129 G_PARAM_STATIC_STRINGS));
2132 * NMClient:activating-connection:
2134 * The #NMActiveConnection of the activating connection that is
2135 * likely to become the new #NMClient:primary-connection.
2137 g_object_class_install_property
2138 (object_class, PROP_ACTIVATING_CONNECTION,
2139 g_param_spec_object (NM_CLIENT_ACTIVATING_CONNECTION, "", "",
2140 NM_TYPE_ACTIVE_CONNECTION,
2142 G_PARAM_STATIC_STRINGS));
2147 * List of real network devices. Does not include placeholder devices.
2149 * Element-type: NMDevice
2151 g_object_class_install_property
2152 (object_class, PROP_DEVICES,
2153 g_param_spec_boxed (NM_CLIENT_DEVICES, "", "",
2156 G_PARAM_STATIC_STRINGS));
2159 * NMClient:all-devices:
2161 * List of both real devices and device placeholders.
2163 * Element-type: NMDevice
2166 g_object_class_install_property
2167 (object_class, PROP_ALL_DEVICES,
2168 g_param_spec_boxed (NM_CLIENT_ALL_DEVICES, "", "",
2171 G_PARAM_STATIC_STRINGS));
2174 * NMClient:connections:
2176 * The list of configured connections that are available to the user. (Note
2177 * that this differs from the underlying D-Bus property, which may also
2178 * contain the object paths of connections that the user does not have
2179 * permission to read the details of.)
2181 * Element-type: NMRemoteConnection
2183 g_object_class_install_property
2184 (object_class, PROP_CONNECTIONS,
2185 g_param_spec_boxed (NM_CLIENT_CONNECTIONS, "", "",
2188 G_PARAM_STATIC_STRINGS));
2191 * NMClient:hostname:
2193 * The machine hostname stored in persistent configuration. This can be
2194 * modified by calling nm_client_save_hostname().
2196 g_object_class_install_property
2197 (object_class, PROP_HOSTNAME,
2198 g_param_spec_string (NM_CLIENT_HOSTNAME, "", "",
2201 G_PARAM_STATIC_STRINGS));
2204 * NMClient:can-modify:
2206 * If %TRUE, adding and modifying connections is supported.
2208 g_object_class_install_property
2209 (object_class, PROP_CAN_MODIFY,
2210 g_param_spec_boolean (NM_CLIENT_CAN_MODIFY, "", "",
2213 G_PARAM_STATIC_STRINGS));
2218 * Whether the connectivity is metered.
2222 g_object_class_install_property
2223 (object_class, PROP_METERED,
2224 g_param_spec_uint (NM_CLIENT_METERED, "", "",
2225 0, G_MAXUINT32, NM_METERED_UNKNOWN,
2227 G_PARAM_STATIC_STRINGS));
2232 * NMClient::device-added:
2233 * @client: the client that received the signal
2234 * @device: (type NMDevice): the new device
2236 * Notifies that a #NMDevice is added. This signal is not emitted for
2237 * placeholder devices.
2239 signals[DEVICE_ADDED] =
2240 g_signal_new (NM_CLIENT_DEVICE_ADDED,
2241 G_OBJECT_CLASS_TYPE (object_class),
2243 G_STRUCT_OFFSET (NMClientClass, device_added),
2249 * NMClient::device-removed:
2250 * @client: the client that received the signal
2251 * @device: (type NMDevice): the removed device
2253 * Notifies that a #NMDevice is removed. This signal is not emitted for
2254 * placeholder devices.
2256 signals[DEVICE_REMOVED] =
2257 g_signal_new (NM_CLIENT_DEVICE_REMOVED,
2258 G_OBJECT_CLASS_TYPE (object_class),
2260 G_STRUCT_OFFSET (NMClientClass, device_removed),
2266 * NMClient::any-device-added:
2267 * @client: the client that received the signal
2268 * @device: (type NMDevice): the new device
2270 * Notifies that a #NMDevice is added. This signal is emitted for both
2271 * regular devices and placeholder devices.
2273 signals[ANY_DEVICE_ADDED] =
2274 g_signal_new (NM_CLIENT_ANY_DEVICE_ADDED,
2275 G_OBJECT_CLASS_TYPE (object_class),
2277 G_STRUCT_OFFSET (NMClientClass, any_device_added),
2283 * NMClient::any-device-removed:
2284 * @client: the client that received the signal
2285 * @device: (type NMDevice): the removed device
2287 * Notifies that a #NMDevice is removed. This signal is emitted for both
2288 * regular devices and placeholder devices.
2290 signals[ANY_DEVICE_REMOVED] =
2291 g_signal_new (NM_CLIENT_ANY_DEVICE_REMOVED,
2292 G_OBJECT_CLASS_TYPE (object_class),
2294 G_STRUCT_OFFSET (NMClientClass, any_device_removed),
2300 * NMClient::permission-changed:
2301 * @client: the client that received the signal
2302 * @permission: a permission from #NMClientPermission
2303 * @result: the permission's result, one of #NMClientPermissionResult
2305 * Notifies that a permission has changed
2307 signals[PERMISSION_CHANGED] =
2308 g_signal_new (NM_CLIENT_PERMISSION_CHANGED,
2309 G_OBJECT_CLASS_TYPE (object_class),
2311 0, NULL, NULL, NULL,
2312 G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT);
2314 * NMClient::connection-added:
2315 * @client: the settings object that received the signal
2316 * @connection: the new connection
2318 * Notifies that a #NMConnection has been added.
2320 signals[CONNECTION_ADDED] =
2321 g_signal_new (NM_CLIENT_CONNECTION_ADDED,
2322 G_OBJECT_CLASS_TYPE (object_class),
2324 G_STRUCT_OFFSET (NMClientClass, connection_added),
2327 NM_TYPE_REMOTE_CONNECTION);
2330 * NMClient::connection-removed:
2331 * @client: the settings object that received the signal
2332 * @connection: the removed connection
2334 * Notifies that a #NMConnection has been removed.
2336 signals[CONNECTION_REMOVED] =
2337 g_signal_new (NM_CLIENT_CONNECTION_REMOVED,
2338 G_OBJECT_CLASS_TYPE (object_class),
2340 G_STRUCT_OFFSET (NMClientClass, connection_removed),
2343 NM_TYPE_REMOTE_CONNECTION);
2347 nm_client_initable_iface_init (GInitableIface *iface)
2349 iface->init = init_sync;
2353 nm_client_async_initable_iface_init (GAsyncInitableIface *iface)
2355 iface->init_async = init_async;
2356 iface->init_finish = init_finish;