Commit bafabdde authored by Thomas Haller's avatar Thomas Haller

libnm: implement...

libnm: implement nm_device_get_applied_connection()/nm_device_get_applied_connection_async() by using GDBusConnection directly
parent 3a66761b
......@@ -2148,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
......@@ -2241,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);
}
/**
......@@ -2280,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);
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, data->version_id);
return g_object_ref (data->connection);
NM_SET_OUT (version_id, v_version_id);
return connection;
}
/*****************************************************************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment