Commit b44d883d authored by Thomas Haller's avatar Thomas Haller

libnm: implement nm_client_check_connectivity_async() by using GDBusConnection directly

parent 9bc83ca1
...@@ -792,26 +792,6 @@ nm_client_check_connectivity (NMClient *client, ...@@ -792,26 +792,6 @@ nm_client_check_connectivity (NMClient *client,
return connectivity; return connectivity;
} }
static void
check_connectivity_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
NMConnectivityState connectivity;
GError *error = NULL;
connectivity = nm_manager_check_connectivity_finish (NM_MANAGER (object),
result, &error);
if (!error)
g_simple_async_result_set_op_res_gssize (simple, connectivity);
else
g_simple_async_result_take_error (simple, error);
g_simple_async_result_complete (simple);
g_object_unref (simple);
}
/** /**
* nm_client_check_connectivity_async: * nm_client_check_connectivity_async:
* @client: an #NMClient * @client: an #NMClient
...@@ -830,22 +810,22 @@ nm_client_check_connectivity_async (NMClient *client, ...@@ -830,22 +810,22 @@ nm_client_check_connectivity_async (NMClient *client,
GAsyncReadyCallback callback, GAsyncReadyCallback callback,
gpointer user_data) gpointer user_data)
{ {
GSimpleAsyncResult *simple;
GError *error = NULL;
g_return_if_fail (NM_IS_CLIENT (client)); g_return_if_fail (NM_IS_CLIENT (client));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
if (!_nm_client_check_nm_running (client, &error)) { _nm_object_dbus_call (client,
g_simple_async_report_take_gerror_in_idle (G_OBJECT (client), callback, user_data, error); nm_client_check_connectivity_async,
return; cancellable,
} callback,
user_data,
simple = g_simple_async_result_new (G_OBJECT (client), callback, user_data, NM_DBUS_PATH,
nm_client_check_connectivity_async); NM_DBUS_INTERFACE,
if (cancellable) "CheckConnectivity",
g_simple_async_result_set_check_cancellable (simple, cancellable); g_variant_new ("()"),
nm_manager_check_connectivity_async (NM_CLIENT_GET_PRIVATE (client)->manager, G_VARIANT_TYPE ("(u)"),
cancellable, check_connectivity_cb, simple); G_DBUS_CALL_FLAGS_NONE,
NM_DBUS_DEFAULT_TIMEOUT_MSEC,
nm_dbus_connection_call_finish_variant_strip_dbus_error_cb);
} }
/** /**
...@@ -864,16 +844,20 @@ nm_client_check_connectivity_finish (NMClient *client, ...@@ -864,16 +844,20 @@ nm_client_check_connectivity_finish (NMClient *client,
GAsyncResult *result, GAsyncResult *result,
GError **error) GError **error)
{ {
GSimpleAsyncResult *simple; gs_unref_variant GVariant *ret = NULL;
guint32 connectivity;
g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN); g_return_val_if_fail (NM_IS_CLIENT (client), NM_CONNECTIVITY_UNKNOWN);
g_return_val_if_fail (G_IS_SIMPLE_ASYNC_RESULT (result), NM_CONNECTIVITY_UNKNOWN); g_return_val_if_fail (nm_g_task_is_valid (client, result, nm_client_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN);
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 NM_CONNECTIVITY_UNKNOWN; return NM_CONNECTIVITY_UNKNOWN;
return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
g_variant_get (ret,
"(u)",
&connectivity);
return connectivity;
} }
/** /**
......
...@@ -641,74 +641,6 @@ _nm_manager_set_connectivity_hack (NMManager *manager, ...@@ -641,74 +641,6 @@ _nm_manager_set_connectivity_hack (NMManager *manager,
} }
} }
static void
check_connectivity_cb (GObject *object,
GAsyncResult *result,
gpointer user_data)
{
GSimpleAsyncResult *simple = user_data;
guint32 connectivity;
GError *error = NULL;
NMManager *manager;
NMManagerPrivate *priv;
if (nmdbus_manager_call_check_connectivity_finish (NMDBUS_MANAGER (object),
&connectivity,
result, &error)) {
g_simple_async_result_set_op_res_gssize (simple, connectivity);
manager = NM_MANAGER (g_async_result_get_source_object (G_ASYNC_RESULT (simple)));
priv = NM_MANAGER_GET_PRIVATE (manager);
if (connectivity != priv->connectivity) {
priv->connectivity = connectivity;
g_object_notify (G_OBJECT (manager), NM_MANAGER_CONNECTIVITY);
}
} 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_manager_check_connectivity_async (NMManager *manager,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMManagerPrivate *priv;
GSimpleAsyncResult *simple;
g_return_if_fail (NM_IS_MANAGER (manager));
priv = NM_MANAGER_GET_PRIVATE (manager);
simple = g_simple_async_result_new (G_OBJECT (manager), callback, user_data,
nm_manager_check_connectivity_async);
if (cancellable)
g_simple_async_result_set_check_cancellable (simple, cancellable);
nmdbus_manager_call_check_connectivity (priv->proxy,
cancellable,
check_connectivity_cb, simple);
}
NMConnectivityState
nm_manager_check_connectivity_finish (NMManager *manager,
GAsyncResult *result,
GError **error)
{
GSimpleAsyncResult *simple;
g_return_val_if_fail (g_simple_async_result_is_valid (result, G_OBJECT (manager), nm_manager_check_connectivity_async), NM_CONNECTIVITY_UNKNOWN);
simple = G_SIMPLE_ASYNC_RESULT (result);
if (g_simple_async_result_propagate_error (simple, error))
return NM_CONNECTIVITY_UNKNOWN;
return (NMConnectivityState) g_simple_async_result_get_op_res_gssize (simple);
}
/*****************************************************************************/ /*****************************************************************************/
/* Devices */ /* Devices */
/*****************************************************************************/ /*****************************************************************************/
......
...@@ -121,14 +121,6 @@ NMConnectivityState nm_manager_get_connectivity (NMManager *manager); ...@@ -121,14 +121,6 @@ NMConnectivityState nm_manager_get_connectivity (NMManager *manager);
void _nm_manager_set_connectivity_hack (NMManager *manager, void _nm_manager_set_connectivity_hack (NMManager *manager,
guint32 connectivity); guint32 connectivity);
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);
/* Devices */ /* Devices */
const GPtrArray *nm_manager_get_devices (NMManager *manager); const GPtrArray *nm_manager_get_devices (NMManager *manager);
......
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