libnm: merge branch 'th/libnm-no-dbus-codegen-1'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/299
This commit is contained in:
Thomas Haller 2019-10-16 18:02:42 +02:00
commit 198591a694
20 changed files with 1980 additions and 2765 deletions

View file

@ -1296,8 +1296,7 @@ nmc_do_cmd (NmCli *nmc, const NMCCommand cmds[], const char *cmd, int argc, char
const NMCCommand *c;
gs_unref_object GTask *task = NULL;
task = g_task_new (NULL, NULL, command_done, nmc);
g_task_set_source_tag (task, nmc_do_cmd);
task = nm_g_task_new (NULL, NULL, nmc_do_cmd, command_done, nmc);
g_task_set_task_data (task, nmc, NULL);
if (argc == 0 && nmc->complete) {

View file

@ -102,6 +102,7 @@
LoadConnections:
@filenames: Array of paths to on-disk connection profiles in directories monitored by NetworkManager.
@status: Success or failure of the operation as a whole. True if NetworkManager at least tried to load the indicated connections, even if it did not succeed. False if an error occurred before trying to load the connections (eg, permission denied).
Note that before 1.20, NetworkManager had a bug and this @status value was wrong. It is better to assume success if the method does not return with a D-Bus error. On top of that, you can look at @failures to know whether any of the requested files failed.
@failures: Paths of connection files that could not be loaded.
Loads or reloads the indicated connections from disk. You should call this
@ -119,7 +120,7 @@
<!--
ReloadConnections:
@status: Success or failure.
@status: This always returns %TRUE.
Tells NetworkManager to reload all connection files from disk, including
noticing any added or deleted connection files. By default, connections

File diff suppressed because it is too large Load diff

View file

@ -277,10 +277,13 @@ void nm_client_connectivity_check_set_enabled (NMClient *client,
NM_AVAILABLE_IN_1_20
const char *nm_client_connectivity_check_get_uri (NMClient *client);
_NM_DEPRECATED_SYNC_METHOD
gboolean nm_client_get_logging (NMClient *client,
char **level,
char **domains,
GError **error);
_NM_DEPRECATED_SYNC_METHOD
gboolean nm_client_set_logging (NMClient *client,
const char *level,
const char *domains,

View file

@ -12,6 +12,8 @@
#include "nm-std-aux/nm-dbus-compat.h"
#define NM_DBUS_DEFAULT_TIMEOUT_MSEC 25000
GBusType _nm_dbus_bus_type (void);
void _nm_dbus_proxy_replace_match (GDBusProxy *proxy);

View file

@ -7,6 +7,7 @@
#include "nm-device-wifi-p2p.h"
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-setting-connection.h"
#include "nm-setting-wifi-p2p.h"
#include "nm-utils.h"
@ -19,11 +20,6 @@
/*****************************************************************************/
typedef struct {
NMDeviceWifiP2P *device;
GSimpleAsyncResult *simple;
} RequestScanInfo;
NM_GOBJECT_PROPERTIES_DEFINE_BASE (
PROP_HW_ADDRESS,
PROP_PEERS,
@ -142,23 +138,6 @@ nm_device_wifi_p2p_get_peer_by_path (NMDeviceWifiP2P *device,
return peer;
}
static void
start_find_finished_cb (GObject *obj,
GAsyncResult *res,
gpointer user_data)
{
NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj;
gs_unref_object GTask *task = G_TASK (user_data);
GError *error = NULL;
gboolean success;
success = nmdbus_device_wifi_p2p_call_start_find_finish (proxy, res, &error);
if (!success)
g_task_return_error (task, error);
else
g_task_return_boolean (task, TRUE);
}
/**
* nm_device_wifi_p2p_start_find:
* @device: a #NMDeviceWifiP2P
@ -177,26 +156,32 @@ start_find_finished_cb (GObject *obj,
* Since: 1.16
**/
void
nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device,
GVariant *options,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
nm_device_wifi_p2p_start_find (NMDeviceWifiP2P *device,
GVariant *options,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device);
GTask *task;
g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device));
task = g_task_new (device, cancellable, callback, user_data);
g_return_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
nmdbus_device_wifi_p2p_call_start_find (priv->proxy,
options,
cancellable,
start_find_finished_cb,
task);
_nm_object_dbus_call (device,
nm_device_wifi_p2p_start_find,
cancellable,
callback,
user_data,
NM_DBUS_PATH,
NM_DBUS_INTERFACE,
"StartFind",
g_variant_new ("(@a{sv})", options),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_cb);
}
/**
@ -216,26 +201,12 @@ nm_device_wifi_p2p_start_find_finish (NMDeviceWifiP2P *device,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_p2p_start_find), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
stop_find_finished_cb (GObject *obj,
GAsyncResult *res,
gpointer user_data)
{
NMDBusDeviceWifiP2P *proxy = (NMDBusDeviceWifiP2P*) obj;
gs_unref_object GTask *task = G_TASK (user_data);
GError *error = NULL;
gboolean success;
success = nmdbus_device_wifi_p2p_call_stop_find_finish (proxy, res, &error);
if (!success)
g_task_return_error (task, error);
else
g_task_return_boolean (task, TRUE);
}
/**
* nm_device_wifi_p2p_stop_find:
* @device: a #NMDeviceWifiP2P
@ -253,17 +224,22 @@ nm_device_wifi_p2p_stop_find (NMDeviceWifiP2P *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (device);
GTask *task;
g_return_if_fail (NM_IS_DEVICE_WIFI_P2P (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (device, cancellable, callback, user_data);
nmdbus_device_wifi_p2p_call_stop_find (priv->proxy,
cancellable,
stop_find_finished_cb,
task);
_nm_object_dbus_call (device,
nm_device_wifi_p2p_stop_find,
cancellable,
callback,
user_data,
NM_DBUS_PATH,
NM_DBUS_INTERFACE,
"StopFind",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_cb);
}
/**
@ -283,6 +259,9 @@ nm_device_wifi_p2p_stop_find_finish (NMDeviceWifiP2P *device,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (NM_IS_DEVICE_WIFI_P2P (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_p2p_stop_find), FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}

View file

@ -8,6 +8,7 @@
#include "nm-device-wifi.h"
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-setting-connection.h"
#include "nm-setting-wireless.h"
#include "nm-setting-wireless-security.h"
@ -26,11 +27,6 @@ G_DEFINE_TYPE (NMDeviceWifi, nm_device_wifi, NM_TYPE_DEVICE)
void _nm_device_wifi_set_wireless_enabled (NMDeviceWifi *device, gboolean enabled);
static void state_changed_cb (NMDevice *device, GParamSpec *pspec, gpointer user_data);
typedef struct {
NMDeviceWifi *device;
GSimpleAsyncResult *simple;
} RequestScanInfo;
typedef struct {
NMDBusDeviceWifi *proxy;
@ -42,8 +38,6 @@ typedef struct {
NMDeviceWifiCapabilities wireless_caps;
GPtrArray *aps;
gint64 last_scan;
RequestScanInfo *scan_info;
} NMDeviceWifiPrivate;
enum {
@ -273,52 +267,6 @@ nm_device_wifi_get_last_scan (NMDeviceWifi *device)
return NM_DEVICE_WIFI_GET_PRIVATE (device)->last_scan;
}
static GVariant *
prepare_scan_options (GVariant *options)
{
GVariant *variant;
GVariantIter iter;
GVariantBuilder builder;
char *key;
GVariant *value;
if (!options)
variant = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
else {
g_variant_builder_init (&builder, G_VARIANT_TYPE_VARDICT);
g_variant_iter_init (&iter, options);
while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
{
// FIXME: verify options here?
g_variant_builder_add (&builder, "{sv}", key, value);
}
variant = g_variant_builder_end (&builder);
}
return variant;
}
static gboolean
_device_wifi_request_scan (NMDeviceWifi *device,
GVariant *options,
GCancellable *cancellable,
GError **error)
{
gboolean ret;
GVariant *variant;
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
variant = prepare_scan_options (options);
ret = nmdbus_device_wifi_call_request_scan_sync (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
variant,
cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
/**
* nm_device_wifi_request_scan:
* @device: a #NMDeviceWifi
@ -339,7 +287,7 @@ nm_device_wifi_request_scan (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error)
{
return _device_wifi_request_scan (device, NULL, cancellable, error);
return nm_device_wifi_request_scan_options (device, NULL, cancellable, error);
}
/**
@ -370,76 +318,30 @@ nm_device_wifi_request_scan_options (NMDeviceWifi *device,
GCancellable *cancellable,
GError **error)
{
return _device_wifi_request_scan (device, options, cancellable, error);
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
g_return_val_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
return _nm_object_dbus_call_sync_void (device,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"RequestScan",
g_variant_new ("(@a{sv})", options),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
NM_BACKPORT_SYMBOL (libnm_1_0_6, gboolean, nm_device_wifi_request_scan_options,
(NMDeviceWifi *device, GVariant *options, GCancellable *cancellable, GError **error),
(device, options, cancellable, error));
static void
request_scan_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
RequestScanInfo *info = user_data;
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (info->device);
GError *error = NULL;
priv->scan_info = NULL;
if (nmdbus_device_wifi_call_request_scan_finish (NMDBUS_DEVICE_WIFI (source),
result, &error))
g_simple_async_result_set_op_res_gboolean (info->simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (info->simple, error);
}
g_simple_async_result_complete (info->simple);
g_object_unref (info->simple);
g_slice_free (RequestScanInfo, info);
}
static void
_device_wifi_request_scan_async (NMDeviceWifi *device,
GVariant *options,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (device);
RequestScanInfo *info;
GSimpleAsyncResult *simple;
GVariant *variant;
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_wifi_request_scan_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
/* If a scan is in progress, just return */
if (priv->scan_info) {
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
g_simple_async_result_complete_in_idle (simple);
g_object_unref (simple);
return;
}
info = g_slice_new0 (RequestScanInfo);
info->device = device;
info->simple = simple;
variant = prepare_scan_options (options);
priv->scan_info = info;
nmdbus_device_wifi_call_request_scan (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy,
variant,
cancellable, request_scan_cb, info);
}
/**
* nm_device_wifi_request_scan_async:
* @device: a #NMDeviceWifi
@ -457,7 +359,7 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
_device_wifi_request_scan_async (device, NULL, cancellable, callback, user_data);
nm_device_wifi_request_scan_options_async (device, NULL, cancellable, callback, user_data);
}
/**
@ -476,6 +378,8 @@ nm_device_wifi_request_scan_async (NMDeviceWifi *device,
* D-Bus call. Valid options inside the dictionary are:
* 'ssids' => array of SSIDs (saay)
*
* To complete the request call nm_device_wifi_request_scan_finish().
*
* Since: 1.2
**/
void
@ -485,7 +389,26 @@ nm_device_wifi_request_scan_options_async (NMDeviceWifi *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
_device_wifi_request_scan_async (device, options, cancellable, callback, user_data);
g_return_if_fail (NM_IS_DEVICE_WIFI (device));
g_return_if_fail (!options || g_variant_is_of_type (options, G_VARIANT_TYPE_VARDICT));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
if (!options)
options = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
_nm_object_dbus_call (device,
nm_device_wifi_request_scan_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_WIFI_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE_WIRELESS,
"RequestScan",
g_variant_new ("(@a{sv})", options),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
NM_BACKPORT_SYMBOL (libnm_1_0_6, void, nm_device_wifi_request_scan_options_async,
@ -498,7 +421,8 @@ NM_BACKPORT_SYMBOL (libnm_1_0_6, void, nm_device_wifi_request_scan_options_async
* @result: the result passed to the #GAsyncReadyCallback
* @error: location for a #GError, or %NULL
*
* Gets the result of a call to nm_device_wifi_request_scan_async().
* Gets the result of a call to nm_device_wifi_request_scan_async() and
* nm_device_wifi_request_scan_options_async().
*
* Returns: %TRUE on success, %FALSE on error, in which case @error will be
* set.
@ -508,15 +432,10 @@ nm_device_wifi_request_scan_finish (NMDeviceWifi *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_DEVICE_WIFI (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_wifi_request_scan_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_wifi_request_scan_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
static void

View file

@ -10,6 +10,7 @@
#include <libudev.h>
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-libnm-utils.h"
#include "nm-dbus-interface.h"
#include "nm-active-connection.h"
@ -2009,40 +2010,31 @@ nm_device_reapply (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
GVariant *dict = NULL;
gboolean ret;
GVariant *arg_connection = NULL;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (!connection || NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
if (connection)
dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
if (!dict)
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
arg_connection = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
if (!arg_connection)
arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
ret = nmdbus_device_call_reapply_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
dict, version_id, flags, cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
device_reapply_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_device_call_reapply_finish (NMDBUS_DEVICE (proxy), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return _nm_object_dbus_call_sync_void (device,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Reapply",
g_variant_new ("(@a{sa{sv}}tu)",
arg_connection,
version_id,
flags),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
/**
@ -2073,24 +2065,33 @@ nm_device_reapply_async (NMDevice *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
GVariant *dict = NULL;
GSimpleAsyncResult *simple;
GVariant *arg_connection = NULL;
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!connection || NM_IS_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
if (connection)
dict = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
if (!dict)
dict = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
arg_connection = nm_connection_to_dbus (connection, NM_CONNECTION_SERIALIZE_ALL);
if (!arg_connection)
arg_connection = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_reapply_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_device_call_reapply (NM_DEVICE_GET_PRIVATE (device)->proxy,
dict, version_id, flags, cancellable,
device_reapply_cb, simple);
_nm_object_dbus_call (device,
nm_device_reapply_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Reapply",
g_variant_new ("(@a{sa{sv}}tu)",
arg_connection,
version_id,
flags),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
/**
@ -2111,15 +2112,10 @@ nm_device_reapply_finish (NMDevice *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_reapply_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_reapply_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
/*****************************************************************************/
@ -2152,80 +2148,42 @@ nm_device_get_applied_connection (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
gs_unref_variant GVariant *dict = NULL;
guint64 my_version_id;
gboolean success;
gs_unref_variant GVariant *ret = NULL;
gs_unref_variant GVariant *v_connection = NULL;
guint64 v_version_id;
NMConnection *connection;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
g_return_val_if_fail (!error || !*error, NULL);
success = nmdbus_device_call_get_applied_connection_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
flags, &dict, &my_version_id, cancellable, error);
if (!success) {
if (error && *error)
g_dbus_error_strip_remote_error (*error);
ret = _nm_object_dbus_call_sync (device,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"GetAppliedConnection",
g_variant_new ("(u)", flags),
G_VARIANT_TYPE ("(a{sa{sv}}t)"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
if (!ret)
return NULL;
}
connection = _nm_simple_connection_new_from_dbus (dict, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error);
g_variant_get (ret,
"(@a{sa{sv}}t)",
&v_connection,
&v_version_id);
connection = _nm_simple_connection_new_from_dbus (v_connection, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error);
if (!connection)
return NULL;
NM_SET_OUT (version_id, my_version_id);
NM_SET_OUT (version_id, v_version_id);
return connection;
}
typedef struct {
NMConnection *connection;
guint64 version_id;
} GetAppliedConnectionData;
static void
device_get_applied_connection_data_free (gpointer user_data)
{
GetAppliedConnectionData *data = user_data;
g_return_if_fail (data);
g_object_unref (data->connection);
g_slice_free (GetAppliedConnectionData, data);
}
static void
device_get_applied_connection_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
gs_unref_object GSimpleAsyncResult *simple = user_data;
gs_unref_variant GVariant *dict = NULL;
guint64 my_version_id;
GError *error = NULL;
NMConnection *connection;
GetAppliedConnectionData *data;
if (!nmdbus_device_call_get_applied_connection_finish (NMDBUS_DEVICE (proxy), &dict, &my_version_id, result, &error)) {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
goto out;
}
connection = _nm_simple_connection_new_from_dbus (dict, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, &error);
if (!connection) {
g_simple_async_result_take_error (simple, error);
goto out;
}
data = g_slice_new (GetAppliedConnectionData);
data->connection = connection;
data->version_id = my_version_id;
g_simple_async_result_set_op_res_gpointer (simple, data, device_get_applied_connection_data_free);
out:
g_simple_async_result_complete (simple);
}
/**
* nm_device_get_applied_connection_async:
* @device: a #NMDevice
@ -2245,19 +2203,22 @@ nm_device_get_applied_connection_async (NMDevice *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_get_applied_connection_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_device_call_get_applied_connection (NM_DEVICE_GET_PRIVATE (device)->proxy,
flags, cancellable,
device_get_applied_connection_cb, simple);
_nm_object_dbus_call (device,
nm_device_get_applied_connection_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"GetAppliedConnection",
g_variant_new ("(u)", flags),
G_VARIANT_TYPE ("(a{sa{sv}}t)"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb);
}
/**
@ -2284,23 +2245,30 @@ nm_device_get_applied_connection_finish (NMDevice *device,
guint64 *version_id,
GError **error)
{
GSimpleAsyncResult *simple;
GetAppliedConnectionData *data;
gs_unref_variant GVariant *ret = NULL;
gs_unref_variant GVariant *v_connection = NULL;
guint64 v_version_id;
NMConnection *connection;
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_get_applied_connection_async), NULL);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_get_applied_connection_async), NULL);
g_return_val_if_fail (!error || !*error, NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
ret = g_task_propagate_pointer (G_TASK (result), error);
if (!ret)
return NULL;
data = g_simple_async_result_get_op_res_gpointer (simple);
g_return_val_if_fail (data, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (data->connection), NULL);
g_variant_get (ret,
"(@a{sa{sv}}t)",
&v_connection,
&v_version_id);
NM_SET_OUT (version_id, data->version_id);
return g_object_ref (data->connection);
connection = _nm_simple_connection_new_from_dbus (v_connection, NM_SETTING_PARSE_FLAGS_BEST_EFFORT, error);
if (!connection)
return NULL;
NM_SET_OUT (version_id, v_version_id);
return connection;
}
/*****************************************************************************/
@ -2324,34 +2292,20 @@ nm_device_disconnect (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
gboolean ret;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
ret = nmdbus_device_call_disconnect_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
device_disconnect_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_device_call_disconnect_finish (NMDBUS_DEVICE (proxy), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return _nm_object_dbus_call_sync_void (device,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Disconnect",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
/**
@ -2371,18 +2325,22 @@ nm_device_disconnect_async (NMDevice *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_disconnect_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_device_call_disconnect (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable,
device_disconnect_cb, simple);
_nm_object_dbus_call (device,
nm_device_disconnect_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Disconnect",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
/**
@ -2401,15 +2359,10 @@ nm_device_disconnect_finish (NMDevice *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_disconnect_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_disconnect_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
/**
@ -2430,34 +2383,20 @@ nm_device_delete (NMDevice *device,
GCancellable *cancellable,
GError **error)
{
gboolean ret;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
g_return_val_if_fail (!error || !*error, FALSE);
ret = nmdbus_device_call_delete_sync (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
device_delete_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_device_call_delete_finish (NMDBUS_DEVICE (proxy), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return _nm_object_dbus_call_sync_void (device,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Delete",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
/**
@ -2476,18 +2415,22 @@ nm_device_delete_async (NMDevice *device,
GAsyncReadyCallback callback,
gpointer user_data)
{
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_DEVICE (device));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
simple = g_simple_async_result_new (G_OBJECT (device), callback, user_data,
nm_device_delete_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_device_call_delete (NM_DEVICE_GET_PRIVATE (device)->proxy,
cancellable,
device_delete_cb, simple);
_nm_object_dbus_call (device,
nm_device_delete_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_DEVICE_GET_PRIVATE (device)->proxy)),
NM_DBUS_INTERFACE_DEVICE,
"Disconnect",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
/**
@ -2506,15 +2449,10 @@ nm_device_delete_finish (NMDevice *device,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_DEVICE (device), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, device, nm_device_delete_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (device), nm_device_delete_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
/**

File diff suppressed because it is too large Load diff

View file

@ -84,8 +84,9 @@ gboolean nm_manager_get_startup (NMManager *manager);
gboolean nm_manager_networking_get_enabled (NMManager *manager);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_manager_networking_set_enabled (NMManager *manager,
gboolean enabled,
gboolean _nm_manager_networking_set_enabled (GDBusConnection *dbus_connection,
const char *name_owner,
gboolean enable,
GError **error);
gboolean nm_manager_wireless_get_enabled (NMManager *manager);
@ -112,31 +113,13 @@ void nm_manager_connectivity_check_set_enabled (NMManager *manager,
const char *nm_manager_connectivity_check_get_uri (NMManager *manager);
gboolean nm_manager_get_logging (NMManager *manager,
char **level,
char **domains,
GError **error);
gboolean nm_manager_set_logging (NMManager *manager,
const char *level,
const char *domains,
GError **error);
NMClientPermissionResult nm_manager_get_permission_result (NMManager *manager,
NMClientPermission permission);
NMConnectivityState nm_manager_get_connectivity (NMManager *manager);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
NMConnectivityState nm_manager_check_connectivity (NMManager *manager,
GCancellable *cancellable,
GError **error);
void nm_manager_check_connectivity_async (NMManager *manager,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMConnectivityState nm_manager_check_connectivity_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void _nm_manager_set_connectivity_hack (NMManager *manager,
guint32 connectivity);
/* Devices */
@ -152,81 +135,17 @@ const GPtrArray *nm_manager_get_active_connections (NMManager *manager);
NMActiveConnection *nm_manager_get_primary_connection (NMManager *manager);
NMActiveConnection *nm_manager_get_activating_connection (NMManager *manager);
void nm_manager_activate_connection_async (NMManager *manager,
NMConnection *connection,
NMDevice *device,
const char *specific_object,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMActiveConnection *nm_manager_activate_connection_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_add_and_activate_connection_async (NMManager *manager,
NMConnection *partial,
NMDevice *device,
const char *specific_object,
GVariant *options,
gboolean force_v2,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMActiveConnection *nm_manager_add_and_activate_connection_finish (NMManager *manager,
GAsyncResult *result,
GVariant **out_result,
GError **error);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_manager_deactivate_connection (NMManager *manager,
NMActiveConnection *active,
GCancellable *cancellable,
GError **error);
void nm_manager_deactivate_connection_async (NMManager *manager,
NMActiveConnection *active,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_manager_deactivate_connection_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_wait_for_active_connection (NMManager *self,
const char *active_path,
const char *connection_path,
GVariant *add_and_activate_output_take,
GTask *task_take);
const GPtrArray *nm_manager_get_checkpoints (NMManager *manager);
void nm_manager_checkpoint_create (NMManager *manager,
const GPtrArray *devices,
guint32 rollback_timeout,
NMCheckpointCreateFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
NMCheckpoint *nm_manager_checkpoint_create_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_destroy (NMManager *manager,
const char *checkpoint_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_manager_checkpoint_destroy_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_rollback (NMManager *manager,
void nm_manager_wait_for_checkpoint (NMManager *self,
const char *checkpoint_path,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GHashTable *nm_manager_checkpoint_rollback_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
void nm_manager_checkpoint_adjust_rollback_timeout (NMManager *manager,
const char *checkpoint_path,
guint32 add_timeout,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_manager_checkpoint_adjust_rollback_timeout_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
GTask *task_take);
/*****************************************************************************/
@ -240,15 +159,9 @@ _NMActivateResult *_nm_activate_result_new (NMActiveConnection *active,
void _nm_activate_result_free (_NMActivateResult *result);
NM_AUTO_DEFINE_FCN0 (_NMActivateResult *, _nm_auto_free_activate_result, _nm_activate_result_free)
#define nm_auto_free_activate_result nm_auto(_nm_auto_free_activate_result)
/*****************************************************************************/
void nm_manager_reload (NMManager *manager,
NMManagerReloadFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_manager_reload_finish (NMManager *manager,
GAsyncResult *result,
GError **error);
#endif /* __NM_MANAGER_H__ */

View file

@ -34,7 +34,50 @@ GDBusObjectManager *_nm_object_get_dbus_object_manager (NMObject *object);
GQuark _nm_object_obj_nm_quark (void);
/* DBus property accessors */
GDBusConnection *_nm_object_get_dbus_connection (gpointer self);
const char *_nm_object_get_dbus_name_owner (gpointer self);
GDBusConnection *_nm_client_get_dbus_connection (NMClient *client);
const char *_nm_client_get_dbus_name_owner (NMClient *client);
void _nm_object_dbus_call (gpointer self,
gpointer source_tag,
GCancellable *cancellable,
GAsyncReadyCallback user_callback,
gpointer user_callback_data,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
GAsyncReadyCallback internal_callback);
GVariant *_nm_object_dbus_call_sync (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
gboolean _nm_object_dbus_call_sync_void (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error);
void _nm_object_set_property (NMObject *object,
const char *interface,
@ -45,6 +88,9 @@ void _nm_object_set_property (NMObject *object,
GDBusProxy *_nm_object_get_proxy (NMObject *object,
const char *interface);
GError *_nm_object_new_error_nm_not_running (void);
void _nm_object_set_error_nm_not_running (GError **error);
struct udev;
void _nm_device_set_udev (NMDevice *device, struct udev *udev);

View file

@ -69,6 +69,8 @@ typedef struct {
CList pending; /* ordered list of pending property updates. */
GPtrArray *proxies;
char *name_owner_cached;
} NMObjectPrivate;
enum {
@ -127,6 +129,211 @@ _nm_object_get_proxy (NMObject *object,
return G_DBUS_PROXY (proxy);
}
/*****************************************************************************/
GDBusConnection *
_nm_object_get_dbus_connection (gpointer self)
{
NMObjectPrivate *priv;
nm_assert (NM_IS_OBJECT (self));
priv = NM_OBJECT_GET_PRIVATE (self);
return g_dbus_object_manager_client_get_connection (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager));
}
const char *
_nm_object_get_dbus_name_owner (gpointer self)
{
NMObjectPrivate *priv;
nm_assert (NM_IS_OBJECT (self));
priv = NM_OBJECT_GET_PRIVATE (self);
nm_clear_g_free (&priv->name_owner_cached);
priv->name_owner_cached = g_dbus_object_manager_client_get_name_owner (G_DBUS_OBJECT_MANAGER_CLIENT (priv->object_manager));
return priv->name_owner_cached;
}
static gboolean
_get_dbus_params (gpointer self,
GDBusConnection **out_dbus_connection,
const char **out_name_owner)
{
const char *name_owner;
GDBusConnection *dbus_connection = NULL;
if (NM_IS_OBJECT (self)) {
name_owner = _nm_object_get_dbus_name_owner (self);
if (name_owner)
dbus_connection = _nm_object_get_dbus_connection (self);
} else {
nm_assert (NM_IS_CLIENT (self));
name_owner = _nm_client_get_dbus_name_owner (self);
if (name_owner)
dbus_connection = _nm_client_get_dbus_connection (self);
}
*out_dbus_connection = dbus_connection;
*out_name_owner = name_owner;
return !!name_owner;
}
void
_nm_object_dbus_call (gpointer self,
gpointer source_tag,
GCancellable *cancellable,
GAsyncReadyCallback user_callback,
gpointer user_callback_data,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
GAsyncReadyCallback internal_callback)
{
gs_unref_object GTask *task = NULL;
const char *name_owner;
GDBusConnection *dbus_connection;
nm_assert (G_IS_OBJECT (self));
nm_assert (source_tag);
nm_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
nm_assert (internal_callback);
nm_assert (object_path);
nm_assert (interface_name);
nm_assert (method_name);
nm_assert (parameters);
nm_assert (reply_type);
task = nm_g_task_new (self, cancellable, source_tag, user_callback, user_callback_data);
if (!_get_dbus_params (self, &dbus_connection, &name_owner)) {
nm_g_variant_unref_floating (parameters);
g_task_return_error (task, _nm_object_new_error_nm_not_running ());
return;
}
g_dbus_connection_call (dbus_connection,
name_owner,
object_path,
interface_name,
method_name,
parameters,
reply_type,
flags,
timeout_msec,
cancellable,
internal_callback,
g_steal_pointer (&task));
}
GVariant *
_nm_object_dbus_call_sync (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
const GVariantType *reply_type,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error)
{
gs_unref_variant GVariant *ret = NULL;
GDBusConnection *dbus_connection;
const char *name_owner;
nm_assert (G_IS_OBJECT (self));
nm_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
nm_assert (!error || !*error);
nm_assert (object_path);
nm_assert (interface_name);
nm_assert (method_name);
nm_assert (parameters);
nm_assert (reply_type);
if (!_get_dbus_params (self, &dbus_connection, &name_owner)) {
nm_g_variant_unref_floating (parameters);
_nm_object_set_error_nm_not_running (error);
return NULL;
}
ret = g_dbus_connection_call_sync (dbus_connection,
name_owner,
object_path,
interface_name,
method_name,
parameters,
reply_type,
flags,
timeout_msec,
cancellable,
error);
if (!ret) {
if (error && strip_dbus_error)
g_dbus_error_strip_remote_error (*error);
return NULL;
}
return g_steal_pointer (&ret);
}
gboolean
_nm_object_dbus_call_sync_void (gpointer self,
GCancellable *cancellable,
const char *object_path,
const char *interface_name,
const char *method_name,
GVariant *parameters,
GDBusCallFlags flags,
int timeout_msec,
gboolean strip_dbus_error,
GError **error)
{
gs_unref_variant GVariant *ret = NULL;
ret = _nm_object_dbus_call_sync (self,
cancellable,
object_path,
interface_name,
method_name,
parameters,
G_VARIANT_TYPE ("()"),
flags,
timeout_msec,
strip_dbus_error,
error);
return !!ret;
}
/*****************************************************************************/
GError *
_nm_object_new_error_nm_not_running (void)
{
return g_error_new_literal (NM_CLIENT_ERROR,
NM_CLIENT_ERROR_MANAGER_NOT_RUNNING,
"NetworkManager is not running");
}
void
_nm_object_set_error_nm_not_running (GError **error)
{
if (error) {
if (*error)
g_return_if_reached ();
*error = _nm_object_new_error_nm_not_running ();
}
}
/*****************************************************************************/
typedef enum {
NOTIFY_SIGNAL_PENDING_NONE,
NOTIFY_SIGNAL_PENDING_ADDED,
@ -1251,6 +1458,8 @@ finalize (GObject *object)
g_slist_free_full (priv->property_tables, (GDestroyNotify) g_hash_table_destroy);
g_free (priv->name_owner_cached);
G_OBJECT_CLASS (nm_object_parent_class)->finalize (object);
}

View file

@ -8,6 +8,7 @@
#include "nm-remote-connection.h"
#include "nm-glib-aux/nm-dbus-aux.h"
#include "nm-dbus-interface.h"
#include "nm-utils.h"
#include "nm-setting-connection.h"
@ -62,28 +63,6 @@ typedef struct {
/*****************************************************************************/
static void
update2_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
GVariant *v;
if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
&v,
result,
&error)) {
g_simple_async_result_set_op_res_gpointer (simple,
v,
(GDestroyNotify) g_variant_unref);
} else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/**
* nm_remote_connection_update2:
* @connection: the #NMRemoteConnection
@ -107,37 +86,32 @@ nm_remote_connection_update2 (NMRemoteConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
GVariantBuilder builder;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!settings || g_variant_is_of_type (settings, NM_VARIANT_TYPE_CONNECTION));
g_return_if_fail (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}")));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
if (!settings)
settings = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
if (!args)
args = g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_update2);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
if (!settings) {
g_variant_builder_init (&builder, NM_VARIANT_TYPE_CONNECTION);
settings = g_variant_builder_end (&builder);
}
if (!args) {
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
args = g_variant_builder_end (&builder);
}
nmdbus_settings_connection_call_update2 (priv->proxy,
settings,
flags,
args,
cancellable,
update2_cb,
simple);
_nm_object_dbus_call (connection,
nm_remote_connection_update2,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Update2",
g_variant_new ("(@a{sa{sv}}u@a{sv})",
settings,
(guint32) flags,
args),
G_VARIANT_TYPE ("(a{sv})"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb);
}
/**
@ -148,7 +122,7 @@ nm_remote_connection_update2 (NMRemoteConnection *connection,
*
* Gets the result of a call to nm_remote_connection_commit_changes_async().
*
* Returns: on success, a #GVariant of type "a{sv}" with the result. On failure,
* Returns: (transfer full): on success, a #GVariant of type "a{sv}" with the result. On failure,
* %NULL.
**/
GVariant *
@ -156,15 +130,21 @@ nm_remote_connection_update2_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
gs_unref_variant GVariant *ret = NULL;
GVariant *v_result;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_update2), FALSE);
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL);
g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_update2), NULL);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
ret = g_task_propagate_pointer (G_TASK (result), error);
if (!ret)
return NULL;
else
return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
g_variant_get (ret,
"(@a{sv})",
&v_result);
return v_result;
}
/*****************************************************************************/
@ -190,49 +170,32 @@ nm_remote_connection_commit_changes (NMRemoteConnection *connection,
GCancellable *cancellable,
GError **error)
{
NMRemoteConnectionPrivate *priv;
gs_unref_variant GVariant *result = NULL;
gboolean ret;
GVariantBuilder args;
gs_unref_variant GVariant *ret = NULL;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
ret = _nm_object_dbus_call_sync (connection,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Update2",
g_variant_new ("(@a{sa{sv}}u@a{sv})",
nm_connection_to_dbus (NM_CONNECTION (connection),
NM_CONNECTION_SERIALIZE_ALL),
(guint32) ( save_to_disk
? NM_SETTINGS_UPDATE2_FLAG_TO_DISK
: NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY),
g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0)),
G_VARIANT_TYPE ("(a{sv})"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
if (!ret)
return FALSE;
g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}"));
ret = nmdbus_settings_connection_call_update2_sync (priv->proxy,
nm_connection_to_dbus (NM_CONNECTION (connection),
NM_CONNECTION_SERIALIZE_ALL),
save_to_disk
? NM_SETTINGS_UPDATE2_FLAG_TO_DISK
: NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY,
g_variant_builder_end (&args),
&result,
cancellable,
error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
update_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
gs_unref_variant GVariant *v = NULL;
if (nmdbus_settings_connection_call_update2_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
&v,
result,
&error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return TRUE;
}
/**
@ -255,30 +218,19 @@ nm_remote_connection_commit_changes_async (NMRemoteConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
GVariantBuilder args;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_commit_changes_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
g_variant_builder_init (&args, G_VARIANT_TYPE ("a{sv}"));
nmdbus_settings_connection_call_update2 (priv->proxy,
nm_connection_to_dbus (NM_CONNECTION (connection),
NM_CONNECTION_SERIALIZE_ALL),
save_to_disk
? NM_SETTINGS_UPDATE2_FLAG_TO_DISK
: NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY,
g_variant_builder_end (&args),
cancellable,
update_cb,
simple);
nm_remote_connection_update2 (connection,
nm_connection_to_dbus (NM_CONNECTION (connection),
NM_CONNECTION_SERIALIZE_ALL),
save_to_disk
? NM_SETTINGS_UPDATE2_FLAG_TO_DISK
: NM_SETTINGS_UPDATE2_FLAG_IN_MEMORY,
NULL,
cancellable,
callback,
user_data);
}
/**
@ -296,15 +248,10 @@ nm_remote_connection_commit_changes_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
gs_unref_variant GVariant *v_result = NULL;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_commit_changes_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
v_result = nm_remote_connection_update2_finish (connection, result, error);
return !!v_result;
}
/*****************************************************************************/
@ -327,34 +274,19 @@ nm_remote_connection_save (NMRemoteConnection *connection,
GCancellable *cancellable,
GError **error)
{
NMRemoteConnectionPrivate *priv;
gboolean ret;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), FALSE);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
ret = nmdbus_settings_connection_call_save_sync (priv->proxy, cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
save_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_settings_connection_call_save_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return _nm_object_dbus_call_sync_void (connection,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Save",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
/**
@ -373,18 +305,22 @@ nm_remote_connection_save_async (NMRemoteConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_save_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_connection_call_save (priv->proxy, cancellable, save_cb, simple);
_nm_object_dbus_call (connection,
nm_remote_connection_save_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Save",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
/**
@ -402,15 +338,10 @@ nm_remote_connection_save_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_save_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_save_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
/*****************************************************************************/
@ -432,34 +363,18 @@ nm_remote_connection_delete (NMRemoteConnection *connection,
GCancellable *cancellable,
GError **error)
{
NMRemoteConnectionPrivate *priv;
gboolean ret;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
ret = nmdbus_settings_connection_call_delete_sync (priv->proxy, cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
delete_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_settings_connection_call_delete_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return _nm_object_dbus_call_sync_void (connection,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Delete",
g_variant_new ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
}
/**
@ -477,18 +392,22 @@ nm_remote_connection_delete_async (NMRemoteConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_delete_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_connection_call_delete (priv->proxy, cancellable, delete_cb, simple);
_nm_object_dbus_call (connection,
nm_remote_connection_delete_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"Delete",
g_variant_new ("()"),
G_VARIANT_TYPE ("()"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_void_strip_dbus_error_cb);
}
/**
@ -506,15 +425,10 @@ nm_remote_connection_delete_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), FALSE);
g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_delete_async), FALSE);
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_delete_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
return g_task_propagate_boolean (G_TASK (result), error);
}
/**
@ -527,7 +441,7 @@ nm_remote_connection_delete_finish (NMRemoteConnection *connection,
* Request the connection's secrets. Note that this is a blocking D-Bus call,
* not a simple property accessor.
*
* Returns: a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing
* Returns: (transfer full): a #GVariant of type %NM_VARIANT_TYPE_CONNECTION containing
* @connection's secrets, or %NULL on error.
*
* Deprecated: 1.22, use nm_remote_connection_get_secrets_async() or GDBusConnection
@ -538,42 +452,32 @@ nm_remote_connection_get_secrets (NMRemoteConnection *connection,
GCancellable *cancellable,
GError **error)
{
NMRemoteConnectionPrivate *priv;
gs_unref_variant GVariant *ret = NULL;
GVariant *secrets;
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL);
g_return_val_if_fail (setting_name, NULL);
g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
if (nmdbus_settings_connection_call_get_secrets_sync (priv->proxy,
setting_name,
&secrets,
cancellable, error))
return secrets;
else {
if (error && *error)
g_dbus_error_strip_remote_error (*error);
ret = _nm_object_dbus_call_sync (connection,
cancellable,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"GetSecrets",
g_variant_new ("(s)", setting_name),
G_VARIANT_TYPE ("(a{sa{sv}})"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
TRUE,
error);
if (!ret)
return NULL;
}
}
static void
get_secrets_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GVariant *secrets = NULL;
GError *error = NULL;
g_variant_get (ret,
"(@a{sa{sv}})",
&secrets);
if (nmdbus_settings_connection_call_get_secrets_finish (NMDBUS_SETTINGS_CONNECTION (proxy),
&secrets, result, &error))
g_simple_async_result_set_op_res_gpointer (simple, secrets, (GDestroyNotify) g_variant_unref);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
return secrets;
}
/**
@ -593,22 +497,23 @@ nm_remote_connection_get_secrets_async (NMRemoteConnection *connection,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteConnectionPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_CONNECTION (connection));
g_return_if_fail (setting_name);
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
priv = NM_REMOTE_CONNECTION_GET_PRIVATE (connection);
simple = g_simple_async_result_new (G_OBJECT (connection), callback, user_data,
nm_remote_connection_get_secrets_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_connection_call_get_secrets (priv->proxy,
setting_name,
cancellable,
get_secrets_cb, simple);
_nm_object_dbus_call (connection,
nm_remote_connection_get_secrets_async,
cancellable,
callback,
user_data,
g_dbus_proxy_get_object_path (G_DBUS_PROXY (NM_REMOTE_CONNECTION_GET_PRIVATE (connection)->proxy)),
NM_DBUS_INTERFACE_SETTINGS_CONNECTION,
"GetSecrets",
g_variant_new ("(s)", setting_name),
G_VARIANT_TYPE ("(a{sa{sv}})"),
G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb);
}
/**
@ -627,15 +532,21 @@ nm_remote_connection_get_secrets_finish (NMRemoteConnection *connection,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
gs_unref_variant GVariant *ret = NULL;
GVariant *secrets;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (connection), nm_remote_connection_get_secrets_async), FALSE);
g_return_val_if_fail (NM_IS_REMOTE_CONNECTION (connection), NULL);
g_return_val_if_fail (nm_g_task_is_valid (result, connection, nm_remote_connection_get_secrets_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
ret = g_task_propagate_pointer (G_TASK (result), error);
if (!ret)
return NULL;
else
return g_variant_ref (g_simple_async_result_get_op_res_gpointer (simple));
g_variant_get (ret,
"(@a{sa{sv}})",
&secrets);
return secrets;
}
/**

View file

@ -59,24 +59,20 @@ static guint signals[LAST_SIGNAL] = { 0 };
typedef struct {
CList add_lst;
NMRemoteSettings *self;
NMRemoteSettingAddConnection2Callback callback;
gpointer user_data;
GCancellable *cancellable;
char *path;
GVariant *results;
GTask *task;
char *connection_path;
GVariant *extra_results;
gulong cancellable_id;
NMSettingsAddConnection2Flags flags;
bool ignore_out_result:1;
} AddConnectionInfo;
static AddConnectionInfo *
_add_connection_info_find (NMRemoteSettings *self, const char *path)
_add_connection_info_find (NMRemoteSettings *self, const char *connection_path)
{
NMRemoteSettingsPrivate *priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
AddConnectionInfo *info;
c_list_for_each_entry (info, &priv->add_lst_head, add_lst) {
if (nm_streq0 (info->path, path))
if (nm_streq (info->connection_path, connection_path))
return info;
}
return NULL;
@ -91,38 +87,31 @@ _add_connection_info_complete (AddConnectionInfo *info,
c_list_unlink_stale (&info->add_lst);
nm_clear_g_signal_handler (info->cancellable, &info->cancellable_id);
nm_clear_g_signal_handler (g_task_get_cancellable (info->task), &info->cancellable_id);
if ( info->cancellable
&& !nm_utils_error_is_cancelled (error_take, FALSE)) {
GError *error2 = NULL;
if (error_take)
g_task_return_error (info->task, error_take);
else {
NMAddConnectionResultData *result_info;
if (g_cancellable_set_error_if_cancelled (info->cancellable, &error2)) {
g_clear_error (&error_take);
error_take = error2;
connection = NULL;
}
result_info = g_slice_new (NMAddConnectionResultData);
*result_info = (NMAddConnectionResultData) {
.connection = g_object_ref (connection),
.extra_results = g_steal_pointer (&info->extra_results),
};
g_task_return_pointer (info->task, result_info, (GDestroyNotify) nm_add_connection_result_data_free);
}
info->callback (info->self,
connection,
connection ? info->results : NULL,
error_take,
info->user_data);
g_clear_error (&error_take);
g_object_unref (info->task);
g_object_unref (info->self);
nm_g_object_unref (info->cancellable);
nm_clear_g_free (&info->path);
nm_g_variant_unref (info->results);
g_free (info->connection_path);
nm_g_variant_unref (info->extra_results);
nm_g_slice_free (info);
}
static void
_add_connection_info_cancelled (GCancellable *cancellable,
AddConnectionInfo *info)
_wait_for_connection_cancelled_cb (GCancellable *cancellable,
AddConnectionInfo *info)
{
_add_connection_info_complete (info,
NULL,
@ -246,8 +235,12 @@ connection_added (NMRemoteSettings *self,
else
g_signal_stop_emission (self, signals[CONNECTION_ADDED], 0);
/* FIXME: this doesn't look right. Why does it not care about whether the
* connection is visible? Anyway, this will be reworked. */
path = nm_connection_get_path (NM_CONNECTION (remote));
info = _add_connection_info_find (self, path);
info = path
? _add_connection_info_find (self, path)
: NULL;
if (info)
_add_connection_info_complete (info, remote, NULL);
}
@ -278,51 +271,42 @@ nm_remote_settings_get_connections (NMRemoteSettings *settings)
return NM_REMOTE_SETTINGS_GET_PRIVATE (settings)->visible_connections;
}
static void
add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
void
nm_remote_settings_wait_for_connection (NMRemoteSettings *self,
const char *connection_path,
GVariant *extra_results_take,
GTask *task_take)
{
AddConnectionInfo *info = user_data;
GError *error = NULL;
NMRemoteSettingsPrivate *priv;
gs_unref_object GTask *task = task_take;
gs_unref_variant GVariant *extra_results = extra_results_take;
GCancellable *cancellable;
AddConnectionInfo *info;
if ( info->ignore_out_result
&& info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) {
nmdbus_settings_call_add_connection_finish (NMDBUS_SETTINGS (proxy),
&info->path,
result,
&error);
} else if ( info->ignore_out_result
&& info->flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) {
nmdbus_settings_call_add_connection_unsaved_finish (NMDBUS_SETTINGS (proxy),
&info->path,
result,
&error);
} else {
nmdbus_settings_call_add_connection2_finish (NMDBUS_SETTINGS (proxy),
&info->path,
&info->results,
result,
&error);
if (info->ignore_out_result) {
/* despite we have the result, the caller didn't ask for it.
* Through it away, so we consistently don't return a result. */
nm_clear_pointer (&info->results, g_variant_unref);
}
}
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
if (error) {
g_dbus_error_strip_remote_error (error);
_add_connection_info_complete (info, NULL, error);
return;
}
/* FIXME: there is no timeout for how long we wait. But this entire
* code will be reworked, also that we have a suitable GMainContext
* where we can schedule the timeout (we shouldn't use g_main_context_default()). */
info = g_slice_new (AddConnectionInfo);
*info = (AddConnectionInfo) {
.self = g_object_ref (self),
.connection_path = g_strdup (connection_path),
.task = g_steal_pointer (&task),
.extra_results = g_steal_pointer (&extra_results),
};
c_list_link_tail (&priv->add_lst_head, &info->add_lst);
cancellable = g_task_get_cancellable (info->task);
/* On success, we still have to wait until the connection is fully
* initialized before calling the callback.
*/
if (info->cancellable) {
if (cancellable) {
gulong id;
id = g_cancellable_connect (info->cancellable,
G_CALLBACK (_add_connection_info_cancelled),
id = g_cancellable_connect (cancellable,
G_CALLBACK (_wait_for_connection_cancelled_cb),
info,
NULL);
if (id == 0) {
@ -331,318 +315,10 @@ add_connection_done (GObject *proxy, GAsyncResult *result, gpointer user_data)
} else
info->cancellable_id = id;
}
}
void
nm_remote_settings_add_connection2 (NMRemoteSettings *self,
GVariant *settings,
NMSettingsAddConnection2Flags flags,
GVariant *args,
gboolean ignore_out_result,
GCancellable *cancellable,
NMRemoteSettingAddConnection2Callback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
AddConnectionInfo *info;
nm_assert (NM_IS_REMOTE_SETTINGS (self));
nm_assert (g_variant_is_of_type (settings, G_VARIANT_TYPE ("a{sa{sv}}")));
nm_assert (!args || g_variant_is_of_type (args, G_VARIANT_TYPE ("a{sv}")));
nm_assert (callback);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (self);
info = g_slice_new (AddConnectionInfo);
*info = (AddConnectionInfo) {
.self = g_object_ref (self),
.cancellable = nm_g_object_ref (cancellable),
.flags = flags,
.ignore_out_result = ignore_out_result,
.callback = callback,
.user_data = user_data,
};
c_list_link_tail (&priv->add_lst_head, &info->add_lst);
/* Although AddConnection2() being capable to handle also AddConnection() and
* AddConnectionUnsaved() variants, we prefer to use the old D-Bus methods when
* they are sufficient. The reason is that libnm should avoid hard dependencies
* on 1.20 API whenever possible. */
if ( ignore_out_result
&& flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_TO_DISK) {
nmdbus_settings_call_add_connection (priv->proxy,
settings,
cancellable,
add_connection_done,
info);
} else if ( ignore_out_result
&& flags == NM_SETTINGS_ADD_CONNECTION2_FLAG_IN_MEMORY) {
nmdbus_settings_call_add_connection_unsaved (priv->proxy,
settings,
cancellable,
add_connection_done,
info);
} else {
nmdbus_settings_call_add_connection2 (priv->proxy,
settings,
flags,
args
?: g_variant_new_array (G_VARIANT_TYPE ("{sv}"), NULL, 0),
cancellable,
add_connection_done,
info);
}
}
gboolean
nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames,
char ***failures,
GCancellable *cancellable,
GError **error)
{
NMRemoteSettingsPrivate *priv;
gboolean success;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
g_return_val_if_fail (filenames != NULL, FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!nmdbus_settings_call_load_connections_sync (priv->proxy,
(const char * const *) filenames,
&success,
failures,
cancellable, error)) {
if (error && *error)
g_dbus_error_strip_remote_error (*error);
success = FALSE;
}
return success;
}
static void
load_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
gboolean success;
char **failures = NULL;
if (nmdbus_settings_call_load_connections_finish (NMDBUS_SETTINGS (proxy),
&success, &failures,
result, &error))
g_simple_async_result_set_op_res_gpointer (simple, failures, (GDestroyNotify) g_strfreev);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
void
nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
g_return_if_fail (filenames != NULL);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_load_connections_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_call_load_connections (priv->proxy,
(const char * const *) filenames,
cancellable, load_connections_cb, simple);
}
gboolean
nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
char ***failures,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_load_connections_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else {
*failures = g_strdupv (g_simple_async_result_get_op_res_gpointer (simple));
return TRUE;
}
}
gboolean
nm_remote_settings_reload_connections (NMRemoteSettings *settings,
GCancellable *cancellable,
GError **error)
{
NMRemoteSettingsPrivate *priv;
gboolean success;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
if (!nmdbus_settings_call_reload_connections_sync (priv->proxy, &success,
cancellable, error)) {
if (error && *error)
g_dbus_error_strip_remote_error (*error);
success = FALSE;
}
return success;
}
static void
reload_connections_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
gboolean success;
GError *error = NULL;
if (nmdbus_settings_call_reload_connections_finish (NMDBUS_SETTINGS (proxy),
&success,
result, &error))
g_simple_async_result_set_op_res_gboolean (simple, success);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
void
nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_reload_connections_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_call_reload_connections (priv->proxy, cancellable,
reload_connections_cb, simple);
}
gboolean
nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_reload_connections_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
}
gboolean
nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname,
GCancellable *cancellable,
GError **error)
{
NMRemoteSettingsPrivate *priv;
gboolean ret;
g_return_val_if_fail (NM_IS_REMOTE_SETTINGS (settings), FALSE);
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
ret = nmdbus_settings_call_save_hostname_sync (priv->proxy,
hostname ?: "",
cancellable, error);
if (error && *error)
g_dbus_error_strip_remote_error (*error);
return ret;
}
static void
save_hostname_cb (GObject *proxy,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
GError *error = NULL;
if (nmdbus_settings_call_save_hostname_finish (NMDBUS_SETTINGS (proxy), result, &error))
g_simple_async_result_set_op_res_gboolean (simple, TRUE);
else {
g_dbus_error_strip_remote_error (error);
g_simple_async_result_take_error (simple, error);
}
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
void
nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
const char *hostname,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMRemoteSettingsPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_REMOTE_SETTINGS (settings));
priv = NM_REMOTE_SETTINGS_GET_PRIVATE (settings);
simple = g_simple_async_result_new (G_OBJECT (settings), callback, user_data,
nm_remote_settings_save_hostname_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_settings_call_save_hostname (priv->proxy,
hostname ?: "",
cancellable, save_hostname_cb, simple);
}
gboolean
nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (settings), nm_remote_settings_save_hostname_async), FALSE);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return FALSE;
else
return g_simple_async_result_get_op_res_gboolean (simple);
/* FIXME: OK, we just assume the the connection is here, and that we are bound
* to get the suitable signal when the connection is fully initalized (or failed).
* Obviously, that needs reworking. */
}
/*****************************************************************************/

View file

@ -60,64 +60,19 @@ NMRemoteConnection *nm_remote_settings_get_connection_by_path (NMRemoteSettings
NMRemoteConnection *nm_remote_settings_get_connection_by_uuid (NMRemoteSettings *settings,
const char *uuid);
typedef void (*NMRemoteSettingAddConnection2Callback) (NMRemoteSettings *self,
NMRemoteConnection *connection,
GVariant *results,
GError *error,
gpointer user_data);
typedef struct {
NMRemoteConnection *connection;
GVariant *extra_results;
} NMAddConnectionResultData;
void nm_remote_settings_add_connection2 (NMRemoteSettings *self,
GVariant *settings,
NMSettingsAddConnection2Flags flags,
GVariant *args,
gboolean ignore_out_result,
GCancellable *cancellable,
NMRemoteSettingAddConnection2Callback callback,
gpointer user_data);
void nm_add_connection_result_data_free (NMAddConnectionResultData *result_data);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_remote_settings_load_connections (NMRemoteSettings *settings,
char **filenames,
char ***failures,
GCancellable *cancellable,
GError **error);
NM_AUTO_DEFINE_FCN0 (NMAddConnectionResultData *, _nm_auto_free_add_connection_result_data, nm_add_connection_result_data_free)
#define nm_auto_free_add_connection_result_data nm_auto (_nm_auto_free_add_connection_result_data)
void nm_remote_settings_load_connections_async (NMRemoteSettings *settings,
char **filenames,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_load_connections_finish (NMRemoteSettings *settings,
char ***failures,
GAsyncResult *result,
GError **error);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_remote_settings_reload_connections (NMRemoteSettings *settings,
GCancellable *cancellable,
GError **error);
void nm_remote_settings_reload_connections_async (NMRemoteSettings *settings,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_reload_connections_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error);
_NM_DEPRECATED_SYNC_METHOD_INTERNAL
gboolean nm_remote_settings_save_hostname (NMRemoteSettings *settings,
const char *hostname,
GCancellable *cancellable,
GError **error);
void nm_remote_settings_save_hostname_async (NMRemoteSettings *settings,
const char *hostname,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_remote_settings_save_hostname_finish (NMRemoteSettings *settings,
GAsyncResult *result,
GError **error);
void nm_remote_settings_wait_for_connection (NMRemoteSettings *settings,
const char *connection_path,
GVariant *extra_results_take,
GTask *task_take);
#endif /* __NM_REMOTE_SETTINGS_H__ */

View file

@ -1188,7 +1188,7 @@ activate_failed_cb (GObject *object,
NMActiveConnection *ac;
GError *error = NULL;
ac = nm_client_activate_connection_finish (client, result, &error);
ac = nm_client_add_and_activate_connection_finish (client, result, &error);
g_assert (ac == NULL);
g_assert_error (error, NM_CLIENT_ERROR, NM_CLIENT_ERROR_OBJECT_CREATION_FAILED);
g_clear_error (&error);

View file

@ -244,3 +244,100 @@ nm_dbus_connection_call_get_managed_objects (GDBusConnection *dbus_connection,
_nm_dbus_connection_call_get_managed_objects_cb,
nm_utils_user_data_pack (user_data, callback));
}
/*****************************************************************************/
static void
_call_finish_cb (GObject *source,
GAsyncResult *result,
gpointer user_data,
gboolean return_void,
gboolean strip_dbus_error)
{
gs_unref_object GTask *task = user_data;
gs_unref_variant GVariant *ret = NULL;
GError *error = NULL;
nm_assert (G_IS_DBUS_CONNECTION (source));
nm_assert (G_IS_TASK (user_data));
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), result, &error);
if (!ret) {
if (strip_dbus_error)
g_dbus_error_strip_remote_error (error);
g_task_return_error (task, error);
return;
}
if (!return_void) {
nm_assert (!g_variant_is_of_type (ret, G_VARIANT_TYPE ("()")));
g_task_return_pointer (task, g_steal_pointer (&ret), (GDestroyNotify) g_variant_unref);
} else {
nm_assert (g_variant_is_of_type (ret, G_VARIANT_TYPE ("()")));
g_task_return_boolean (task, TRUE);
}
}
/**
* nm_dbus_connection_call_finish_void_cb:
*
* A default callback to pass as callback to g_dbus_connection_call().
*
* - user_data must be a GTask, whose reference will be consumed by the
* callback.
* - the return GVariant must be a empty tuple "()".
* - the GTask is returned either with error or TRUE boolean.
*/
void
nm_dbus_connection_call_finish_void_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
_call_finish_cb (source, result, user_data, TRUE, FALSE);
}
/**
* nm_dbus_connection_call_finish_void_strip_dbus_error_cb:
*
* Like nm_dbus_connection_call_finish_void_cb(). The difference
* is that on error this will first call g_dbus_error_strip_remote_error() on the error.
*/
void
nm_dbus_connection_call_finish_void_strip_dbus_error_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
_call_finish_cb (source, result, user_data, TRUE, TRUE);
}
/**
* nm_dbus_connection_call_finish_variant_cb:
*
* A default callback to pass as callback to g_dbus_connection_call().
*
* - user_data must be a GTask, whose reference will be consumed by the
* callback.
* - the return GVariant must not be an empty tuple "()".
* - the GTask is returned either with error or with a pointer containing the GVariant.
*/
void
nm_dbus_connection_call_finish_variant_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
_call_finish_cb (source, result, user_data, FALSE, FALSE);
}
/**
* nm_dbus_connection_call_finish_variant_strip_dbus_error_cb:
*
* Like nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(). The difference
* is that on error this will first call g_dbus_error_strip_remote_error() on the error.
*/
void
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source,
GAsyncResult *result,
gpointer user_data)
{
_call_finish_cb (source, result, user_data, FALSE, TRUE);
}

View file

@ -174,4 +174,22 @@ void nm_dbus_connection_call_get_managed_objects (GDBusConnection *dbus_connecti
/*****************************************************************************/
void nm_dbus_connection_call_finish_void_cb (GObject *source,
GAsyncResult *result,
gpointer user_data);
void nm_dbus_connection_call_finish_void_strip_dbus_error_cb (GObject *source,
GAsyncResult *result,
gpointer user_data);
void nm_dbus_connection_call_finish_variant_cb (GObject *source,
GAsyncResult *result,
gpointer user_data);
void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source,
GAsyncResult *result,
gpointer user_data);
/*****************************************************************************/
#endif /* __NM_DBUS_AUX_H__ */

View file

@ -1256,4 +1256,30 @@ guint8 *nm_utils_hexstr2bin_alloc (const char *hexstr,
gsize required_len,
gsize *out_len);
/*****************************************************************************/
static inline GTask *
nm_g_task_new (gpointer source_object,
GCancellable *cancellable,
gpointer source_tag,
GAsyncReadyCallback callback,
gpointer callback_data)
{
GTask *task;
task = g_task_new (source_object, cancellable, callback, callback_data);
if (source_tag)
g_task_set_source_tag (task, source_tag);
return task;
}
static inline gboolean
nm_g_task_is_valid (gpointer task,
gpointer source_object,
gpointer source_tag)
{
return g_task_is_valid (task, source_object)
&& g_task_get_source_tag (task) == source_tag;
}
#endif /* __NM_SHARED_UTILS_H__ */

View file

@ -2821,6 +2821,7 @@ impl_settings_reload_connections (NMDBusObject *obj,
nm_audit_log_connection_op (NM_AUDIT_OP_CONNS_RELOAD, NULL, TRUE, NULL, invocation, NULL);
/* We MUST return %TRUE here, otherwise older libnm versions might misbehave. */
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(b)", TRUE));
}