summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-04 11:21:23 +0200
committerThomas Haller <thaller@redhat.com>2019-05-12 09:56:36 +0200
commit8ffa75685e9fd60c6797255db7d1ef4fb68aad78 (patch)
treec2994ecfc59382250c19b3733e28f68bade45c80
parent655e6bb1e320f1ac86b4c92e5d7822ead29c257f (diff)
downloadNetworkManager-8ffa75685e9fd60c6797255db7d1ef4fb68aad78.tar.gz
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.
-rw-r--r--shared/nm-glib-aux/nm-dbus-aux.c45
-rw-r--r--shared/nm-glib-aux/nm-dbus-aux.h35
2 files changed, 80 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-dbus-aux.c b/shared/nm-glib-aux/nm-dbus-aux.c
index 02b466aab2..083c4feec7 100644
--- a/shared/nm-glib-aux/nm-dbus-aux.c
+++ b/shared/nm-glib-aux/nm-dbus-aux.c
@@ -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));
+}
diff --git a/shared/nm-glib-aux/nm-dbus-aux.h b/shared/nm-glib-aux/nm-dbus-aux.h
index f0cdc19768..c888351b69 100644
--- a/shared/nm-glib-aux/nm-dbus-aux.h
+++ b/shared/nm-glib-aux/nm-dbus-aux.h
@@ -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__ */