mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-02 12:20:12 +01:00
glib-aux: add nm_dbus_connection_call_blocking() helper
This commit is contained in:
parent
dc2e0d30bb
commit
864bfb4052
2 changed files with 49 additions and 0 deletions
|
|
@ -453,3 +453,40 @@ nm_g_bus_get_blocking(GCancellable *cancellable, GError **error)
|
|||
|
||||
return g_steal_pointer(&dbus_connection);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void
|
||||
nm_dbus_connection_call_blocking_callback(GObject *source, GAsyncResult *res, gpointer user_data)
|
||||
{
|
||||
NMDBusConnectionCallBlockingData *data = user_data;
|
||||
|
||||
nm_assert(data);
|
||||
nm_assert(!data->result);
|
||||
nm_assert(!data->error);
|
||||
|
||||
data->result = g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &data->error);
|
||||
}
|
||||
|
||||
GVariant *
|
||||
nm_dbus_connection_call_blocking(NMDBusConnectionCallBlockingData *data, GError **error)
|
||||
{
|
||||
GMainContext *main_context = g_main_context_get_thread_default();
|
||||
gs_free_error GError *local_error = NULL;
|
||||
gs_unref_variant GVariant *result = NULL;
|
||||
|
||||
nm_assert(data);
|
||||
|
||||
while (!data->result && !data->error)
|
||||
g_main_context_iteration(main_context, TRUE);
|
||||
|
||||
local_error = g_steal_pointer(&data->error);
|
||||
result = g_steal_pointer(&data->result);
|
||||
|
||||
if (!result) {
|
||||
g_propagate_error(error, g_steal_pointer(&local_error));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return g_steal_pointer(&result);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -240,4 +240,16 @@ gboolean _nm_dbus_error_is(GError *error, ...) G_GNUC_NULL_TERMINATED;
|
|||
|
||||
GDBusConnection *nm_g_bus_get_blocking(GCancellable *cancellable, GError **error);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
typedef struct {
|
||||
GVariant *result;
|
||||
GError * error;
|
||||
} NMDBusConnectionCallBlockingData;
|
||||
|
||||
void
|
||||
nm_dbus_connection_call_blocking_callback(GObject *source, GAsyncResult *res, gpointer user_data);
|
||||
|
||||
GVariant *nm_dbus_connection_call_blocking(NMDBusConnectionCallBlockingData *data, GError **error);
|
||||
|
||||
#endif /* __NM_DBUS_AUX_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue