summaryrefslogtreecommitdiff
path: root/shared/nm-glib-aux/nm-dbus-aux.h
blob: 6200da023e4dd5d9dd807375e966a3dd71e47a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-License-Identifier: LGPL-2.1+
/* NetworkManager -- Network link manager
 *
 * (C) Copyright 2019 Red Hat, Inc.
 */

#ifndef __NM_DBUS_AUX_H__
#define __NM_DBUS_AUX_H__

#include "nm-std-aux/nm-dbus-compat.h"

/*****************************************************************************/

static inline gboolean
nm_clear_g_dbus_connection_signal (GDBusConnection *dbus_connection,
                                   guint *id)
{
	guint v;

	if (   id
	    && (v = *id)) {
		*id = 0;
		g_dbus_connection_signal_unsubscribe (dbus_connection, v);
		return TRUE;
	}
	return FALSE;
}

/*****************************************************************************/

static inline void
nm_dbus_connection_call_start_service_by_name (GDBusConnection *dbus_connection,
                                               const char *name,
                                               int timeout_msec,
                                               GCancellable *cancellable,
                                               GAsyncReadyCallback  callback,
                                               gpointer user_data)
{
	g_dbus_connection_call (dbus_connection,
	                        DBUS_SERVICE_DBUS,
	                        DBUS_PATH_DBUS,
	                        DBUS_INTERFACE_DBUS,
	                        "StartServiceByName",
	                        g_variant_new ("(su)", name, 0u),
	                        G_VARIANT_TYPE ("(u)"),
	                        G_DBUS_CALL_FLAGS_NONE,
	                        timeout_msec,
	                        cancellable,
	                        callback,
	                        user_data);
}

/*****************************************************************************/

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__ */