|
Packit Service |
87a54e |
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
Packit |
5756e2 |
/*
|
|
Packit |
5756e2 |
* Copyright (C) 2019 Red Hat, Inc.
|
|
Packit |
5756e2 |
*/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#ifndef __NM_DBUS_AUX_H__
|
|
Packit |
5756e2 |
#define __NM_DBUS_AUX_H__
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#include "nm-std-aux/nm-dbus-compat.h"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline gboolean
|
|
Packit Service |
a1bd4f |
nm_clear_g_dbus_connection_signal(GDBusConnection *dbus_connection, guint *id)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
guint v;
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
if (id && (v = *id)) {
|
|
Packit Service |
a1bd4f |
*id = 0;
|
|
Packit Service |
a1bd4f |
g_dbus_connection_signal_unsubscribe(dbus_connection, v);
|
|
Packit Service |
a1bd4f |
return TRUE;
|
|
Packit Service |
a1bd4f |
}
|
|
Packit Service |
a1bd4f |
return FALSE;
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef void (*NMDBusConnectionCallDefaultCb)(GVariant *result, GError *error, gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline void
|
|
Packit Service |
a1bd4f |
nm_dbus_connection_call_start_service_by_name(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * name,
|
|
Packit Service |
a1bd4f |
int timeout_msec,
|
|
Packit Service |
a1bd4f |
GCancellable * cancellable,
|
|
Packit Service |
a1bd4f |
GAsyncReadyCallback callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
g_dbus_connection_call(dbus_connection,
|
|
Packit Service |
a1bd4f |
DBUS_SERVICE_DBUS,
|
|
Packit Service |
a1bd4f |
DBUS_PATH_DBUS,
|
|
Packit Service |
a1bd4f |
DBUS_INTERFACE_DBUS,
|
|
Packit Service |
a1bd4f |
"StartServiceByName",
|
|
Packit Service |
a1bd4f |
g_variant_new("(su)", name, 0u),
|
|
Packit Service |
a1bd4f |
G_VARIANT_TYPE("(u)"),
|
|
Packit Service |
a1bd4f |
G_DBUS_CALL_FLAGS_NONE,
|
|
Packit Service |
a1bd4f |
timeout_msec,
|
|
Packit Service |
a1bd4f |
cancellable,
|
|
Packit Service |
a1bd4f |
callback,
|
|
Packit Service |
a1bd4f |
user_data);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline guint
|
|
Packit Service |
a1bd4f |
nm_dbus_connection_signal_subscribe_name_owner_changed(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * service_name,
|
|
Packit Service |
a1bd4f |
GDBusSignalCallback callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data,
|
|
Packit Service |
a1bd4f |
GDestroyNotify user_data_free_func)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return g_dbus_connection_signal_subscribe(dbus_connection,
|
|
Packit Service |
a1bd4f |
DBUS_SERVICE_DBUS,
|
|
Packit Service |
a1bd4f |
DBUS_INTERFACE_DBUS,
|
|
Packit Service |
a1bd4f |
"NameOwnerChanged",
|
|
Packit Service |
a1bd4f |
DBUS_PATH_DBUS,
|
|
Packit Service |
a1bd4f |
service_name,
|
|
Packit Service |
a1bd4f |
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
Packit Service |
a1bd4f |
callback,
|
|
Packit Service |
a1bd4f |
user_data,
|
|
Packit Service |
a1bd4f |
user_data_free_func);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
typedef void (*NMDBusConnectionCallGetNameOwnerCb)(const char *name_owner,
|
|
Packit Service |
a1bd4f |
GError * error,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_get_name_owner(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * service_name,
|
|
Packit Service |
a1bd4f |
int timeout_msec,
|
|
Packit Service |
a1bd4f |
GCancellable * cancellable,
|
|
Packit Service |
a1bd4f |
NMDBusConnectionCallGetNameOwnerCb callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline guint
|
|
Packit Service |
a1bd4f |
nm_dbus_connection_signal_subscribe_properties_changed(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * bus_name,
|
|
Packit Service |
a1bd4f |
const char * object_path,
|
|
Packit Service |
a1bd4f |
const char * interface_name,
|
|
Packit Service |
a1bd4f |
GDBusSignalCallback callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data,
|
|
Packit Service |
a1bd4f |
GDestroyNotify user_data_free_func)
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
nm_assert(bus_name);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
/* it seems that using a non-unique name causes problems that we get signals
|
|
Packit Service |
a1bd4f |
* also from unrelated senders. Usually, you are anyway monitoring the name-owner,
|
|
Packit Service |
a1bd4f |
* so you should have the unique name at hand.
|
|
Packit Service |
a1bd4f |
*
|
|
Packit Service |
a1bd4f |
* If not, investigate this, ensure that it works, and lift this restriction. */
|
|
Packit Service |
a1bd4f |
nm_assert(g_dbus_is_unique_name(bus_name));
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
return g_dbus_connection_signal_subscribe(dbus_connection,
|
|
Packit Service |
a1bd4f |
bus_name,
|
|
Packit Service |
a1bd4f |
DBUS_INTERFACE_PROPERTIES,
|
|
Packit Service |
a1bd4f |
"PropertiesChanged",
|
|
Packit Service |
a1bd4f |
object_path,
|
|
Packit Service |
a1bd4f |
interface_name,
|
|
Packit Service |
a1bd4f |
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
Packit Service |
a1bd4f |
callback,
|
|
Packit Service |
a1bd4f |
user_data,
|
|
Packit Service |
a1bd4f |
user_data_free_func);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_get_all(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * bus_name,
|
|
Packit Service |
a1bd4f |
const char * object_path,
|
|
Packit Service |
a1bd4f |
const char * interface_name,
|
|
Packit Service |
a1bd4f |
int timeout_msec,
|
|
Packit Service |
a1bd4f |
GCancellable * cancellable,
|
|
Packit Service |
a1bd4f |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit Service |
a1bd4f |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_set(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * bus_name,
|
|
Packit Service |
a1bd4f |
const char * object_path,
|
|
Packit Service |
a1bd4f |
const char * interface_name,
|
|
Packit Service |
a1bd4f |
const char * property_name,
|
|
Packit Service |
a1bd4f |
GVariant * value,
|
|
Packit Service |
a1bd4f |
int timeout_msec,
|
|
Packit Service |
a1bd4f |
GCancellable * cancellable,
|
|
Packit Service |
a1bd4f |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
static inline guint
|
|
Packit Service |
a1bd4f |
nm_dbus_connection_signal_subscribe_object_manager(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * service_name,
|
|
Packit Service |
a1bd4f |
const char * object_path,
|
|
Packit Service |
a1bd4f |
const char * signal_name,
|
|
Packit Service |
a1bd4f |
GDBusSignalCallback callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data,
|
|
Packit Service |
a1bd4f |
GDestroyNotify user_data_free_func)
|
|
Packit |
5756e2 |
{
|
|
Packit Service |
a1bd4f |
return g_dbus_connection_signal_subscribe(dbus_connection,
|
|
Packit Service |
a1bd4f |
service_name,
|
|
Packit Service |
a1bd4f |
DBUS_INTERFACE_OBJECT_MANAGER,
|
|
Packit Service |
a1bd4f |
signal_name,
|
|
Packit Service |
a1bd4f |
object_path,
|
|
Packit Service |
a1bd4f |
NULL,
|
|
Packit Service |
a1bd4f |
G_DBUS_SIGNAL_FLAGS_NONE,
|
|
Packit Service |
a1bd4f |
callback,
|
|
Packit Service |
a1bd4f |
user_data,
|
|
Packit Service |
a1bd4f |
user_data_free_func);
|
|
Packit |
5756e2 |
}
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_get_managed_objects(GDBusConnection * dbus_connection,
|
|
Packit Service |
a1bd4f |
const char * bus_name,
|
|
Packit Service |
a1bd4f |
const char * object_path,
|
|
Packit Service |
a1bd4f |
GDBusCallFlags flags,
|
|
Packit Service |
a1bd4f |
int timeout_msec,
|
|
Packit Service |
a1bd4f |
GCancellable * cancellable,
|
|
Packit Service |
a1bd4f |
NMDBusConnectionCallDefaultCb callback,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void
|
|
Packit Service |
a1bd4f |
nm_dbus_connection_call_finish_void_cb(GObject *source, GAsyncResult *result, gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_finish_void_strip_dbus_error_cb(GObject * source,
|
|
Packit Service |
a1bd4f |
GAsyncResult *result,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_finish_variant_cb(GObject * source,
|
|
Packit Service |
a1bd4f |
GAsyncResult *result,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
void nm_dbus_connection_call_finish_variant_strip_dbus_error_cb(GObject * source,
|
|
Packit Service |
a1bd4f |
GAsyncResult *result,
|
|
Packit Service |
a1bd4f |
gpointer user_data);
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
gboolean _nm_dbus_error_is(GError *error, ...) G_GNUC_NULL_TERMINATED;
|
|
Packit |
5756e2 |
|
|
Packit Service |
a1bd4f |
#define nm_dbus_error_is(error, ...) \
|
|
Packit Service |
a1bd4f |
({ \
|
|
Packit Service |
a1bd4f |
GError *const _error = (error); \
|
|
Packit Service |
a1bd4f |
\
|
|
Packit Service |
a1bd4f |
_error &&_nm_dbus_error_is(_error, __VA_ARGS__, NULL); \
|
|
Packit Service |
a1bd4f |
})
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#define NM_DBUS_ERROR_NAME_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
/*****************************************************************************/
|
|
Packit |
5756e2 |
|
|
Packit |
5756e2 |
#endif /* __NM_DBUS_AUX_H__ */
|