mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 07:50:17 +01:00
shared: add nm_dbus_connection_signal_subscribe_name_owner_changed() helper
... and nm_dbus_connection_call_get_name_owner(). We are going to use GDBusConnection more instead of GDBusProxy. Hence, these two functions are the standard repertoire and used over and over. Their arguments are complicated enough to warrant a small helper.
This commit is contained in:
parent
655e6bb1e3
commit
8ffa75685e
2 changed files with 80 additions and 0 deletions
|
|
@ -22,3 +22,48 @@
|
|||
|
||||
#include "nm-dbus-aux.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
_nm_dbus_connection_call_get_name_owner_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
gs_unref_variant GVariant *ret = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
const char *owner = NULL;
|
||||
gpointer orig_user_data;
|
||||
NMDBusConnectionCallGetNameOwnerCb callback;
|
||||
|
||||
nm_utils_user_data_unpack (user_data, &orig_user_data, &callback);
|
||||
|
||||
ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source), res, &error);
|
||||
if (ret)
|
||||
g_variant_get (ret, "(&s)", &owner);
|
||||
|
||||
callback (owner, error, orig_user_data);
|
||||
}
|
||||
|
||||
void
|
||||
nm_dbus_connection_call_get_name_owner (GDBusConnection *dbus_connection,
|
||||
const char *service_name,
|
||||
int timeout_msec,
|
||||
GCancellable *cancellable,
|
||||
NMDBusConnectionCallGetNameOwnerCb callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
nm_assert (callback);
|
||||
|
||||
g_dbus_connection_call (dbus_connection,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_PATH_DBUS,
|
||||
DBUS_INTERFACE_DBUS,
|
||||
"GetNameOwner",
|
||||
g_variant_new ("(s)", service_name),
|
||||
G_VARIANT_TYPE ("(s)"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
timeout_msec,
|
||||
cancellable,
|
||||
_nm_dbus_connection_call_get_name_owner_cb,
|
||||
nm_utils_user_data_pack (user_data, callback));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,41 @@
|
|||
#ifndef __NM_DBUS_AUX_H__
|
||||
#define __NM_DBUS_AUX_H__
|
||||
|
||||
#include "nm-std-aux/nm-dbus-compat.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint
|
||||
nm_dbus_connection_signal_subscribe_name_owner_changed (GDBusConnection *dbus_connection,
|
||||
const char *service_name,
|
||||
GDBusSignalCallback callback,
|
||||
gpointer user_data,
|
||||
GDestroyNotify user_data_free_func)
|
||||
|
||||
{
|
||||
return g_dbus_connection_signal_subscribe (dbus_connection,
|
||||
DBUS_SERVICE_DBUS,
|
||||
DBUS_INTERFACE_DBUS,
|
||||
"NameOwnerChanged",
|
||||
DBUS_PATH_DBUS,
|
||||
service_name,
|
||||
G_DBUS_SIGNAL_FLAGS_NONE,
|
||||
callback,
|
||||
user_data,
|
||||
user_data_free_func);
|
||||
}
|
||||
|
||||
typedef void (*NMDBusConnectionCallGetNameOwnerCb) (const char *name_owner,
|
||||
GError *error,
|
||||
gpointer user_data);
|
||||
|
||||
void nm_dbus_connection_call_get_name_owner (GDBusConnection *dbus_connection,
|
||||
const char *service_name,
|
||||
int timeout_msec,
|
||||
GCancellable *cancellable,
|
||||
NMDBusConnectionCallGetNameOwnerCb callback,
|
||||
gpointer user_data);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#endif /* __NM_DBUS_AUX_H__ */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue