about summary refs log tree commit diff
path: root/shared/nm-glib-aux/nm-dbus-aux.h
diff options
context:
space:
mode:
Diffstat (limited to 'shared/nm-glib-aux/nm-dbus-aux.h')
-rw-r--r--shared/nm-glib-aux/nm-dbus-aux.h152
1 files changed, 129 insertions, 23 deletions
diff --git a/shared/nm-glib-aux/nm-dbus-aux.h b/shared/nm-glib-aux/nm-dbus-aux.h
index 271a7d9c..840e23c2 100644
--- a/shared/nm-glib-aux/nm-dbus-aux.h
+++ b/shared/nm-glib-aux/nm-dbus-aux.h
@@ -1,21 +1,6 @@
-/* NetworkManager -- Network link manager
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * (C) Copyright 2019 Red Hat, Inc.
+// SPDX-License-Identifier: LGPL-2.1+
+/*
+ * Copyright (C) 2019 Red Hat, Inc.
  */
 
 #ifndef __NM_DBUS_AUX_H__
@@ -42,6 +27,12 @@ nm_clear_g_dbus_connection_signal (GDBusConnection *dbus_connection,
 
 /*****************************************************************************/
 
+typedef void (*NMDBusConnectionCallDefaultCb) (GVariant *result,
+                                               GError *error,
+                                               gpointer user_data);
+
+/*****************************************************************************/
+
 static inline void
 nm_dbus_connection_call_start_service_by_name (GDBusConnection *dbus_connection,
                                                const char *name,
@@ -91,11 +82,126 @@ typedef void (*NMDBusConnectionCallGetNameOwnerCb) (const char *name_owner,
                                                     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);
+                                             const char *service_name,
+                                             int timeout_msec,
+                                             GCancellable *cancellable,
+                                             NMDBusConnectionCallGetNameOwnerCb callback,
+                                             gpointer user_data);
+
+static inline guint
+nm_dbus_connection_signal_subscribe_properties_changed (GDBusConnection *dbus_connection,
+                                                        const char *bus_name,
+                                                        const char *object_path,
+                                                        const char *interface_name,
+                                                        GDBusSignalCallback callback,
+                                                        gpointer user_data,
+                                                        GDestroyNotify user_data_free_func)
+
+{
+	nm_assert (bus_name);
+
+	/* it seems that using a non-unique name causes problems that we get signals
+	 * also from unrelated senders. Usually, you are anyway monitoring the name-owner,
+	 * so you should have the unique name at hand.
+	 *
+	 * If not, investigate this, ensure that it works, and lift this restriction. */
+	nm_assert (g_dbus_is_unique_name (bus_name));
+
+	return g_dbus_connection_signal_subscribe (dbus_connection,
+	                                           bus_name,
+	                                           DBUS_INTERFACE_PROPERTIES,
+	                                           "PropertiesChanged",
+	                                           object_path,
+	                                           interface_name,
+	                                           G_DBUS_SIGNAL_FLAGS_NONE,
+	                                           callback,
+	                                           user_data,
+	                                           user_data_free_func);
+}
+
+void nm_dbus_connection_call_get_all (GDBusConnection *dbus_connection,
+                                      const char *bus_name,
+                                      const char *object_path,
+                                      const char *interface_name,
+                                      int timeout_msec,
+                                      GCancellable *cancellable,
+                                      NMDBusConnectionCallDefaultCb callback,
+                                      gpointer user_data);
+
+/*****************************************************************************/
+
+static inline guint
+nm_dbus_connection_signal_subscribe_object_manager_plain (GDBusConnection *dbus_connection,
+                                                          const char *service_name,
+                                                          const char *object_path,
+                                                          const char *signal_name,
+                                                          GDBusSignalCallback callback,
+                                                          gpointer user_data,
+                                                          GDestroyNotify user_data_free_func)
+{
+	return g_dbus_connection_signal_subscribe (dbus_connection,
+	                                           service_name,
+	                                           DBUS_INTERFACE_OBJECT_MANAGER,
+	                                           signal_name,
+	                                           object_path,
+	                                           NULL,
+	                                           G_DBUS_SIGNAL_FLAGS_NONE,
+	                                           callback,
+	                                           user_data,
+	                                           user_data_free_func);
+}
+
+typedef void (*NMDBusConnectionSignalObjectMangerCb) (const char *object_path,
+                                                      GVariant *added_interfaces_and_properties,
+                                                      const char *const*removed_interfaces,
+                                                      gpointer user_data);
+
+guint nm_dbus_connection_signal_subscribe_object_manager (GDBusConnection *dbus_connection,
+                                                          const char *service_name,
+                                                          const char *object_path,
+                                                          NMDBusConnectionSignalObjectMangerCb callback,
+                                                          gpointer user_data,
+                                                          GDestroyNotify user_data_free_func);
+
+void nm_dbus_connection_call_get_managed_objects (GDBusConnection *dbus_connection,
+                                                  const char *bus_name,
+                                                  const char *object_path,
+                                                  GDBusCallFlags flags,
+                                                  int timeout_msec,
+                                                  GCancellable *cancellable,
+                                                  NMDBusConnectionCallDefaultCb callback,
+                                                  gpointer user_data);
+
+/*****************************************************************************/
+
+void nm_dbus_connection_call_finish_void_cb (GObject *source,
+                                             GAsyncResult *result,
+                                             gpointer user_data);
+
+void nm_dbus_connection_call_finish_void_strip_dbus_error_cb (GObject *source,
+                                                              GAsyncResult *result,
+                                                              gpointer user_data);
+
+void nm_dbus_connection_call_finish_variant_cb (GObject *source,
+                                                GAsyncResult *result,
+                                                gpointer user_data);
+
+void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb (GObject *source,
+                                                                 GAsyncResult *result,
+                                                                 gpointer user_data);
+
+/*****************************************************************************/
+
+gboolean _nm_dbus_error_is (GError *error, ...) G_GNUC_NULL_TERMINATED;
+
+#define nm_dbus_error_is(error, ...) \
+	({ \
+		GError *const _error = (error); \
+		\
+		_error && _nm_dbus_error_is (_error, __VA_ARGS__, NULL); \
+	})
+
+#define NM_DBUS_ERROR_NAME_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
 
 /*****************************************************************************/