summaryrefslogtreecommitdiff
path: root/ell/dbus.h
blob: cbfb0b0884a7c3b11caf58e52fd415237ef826c2 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
 *
 *  Embedded Linux library
 *
 *  Copyright (C) 2011-2014  Intel Corporation. All rights reserved.
 *
 *  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.1 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 St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __ELL_DBUS_H
#define __ELL_DBUS_H

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdarg.h>

#ifdef __cplusplus
extern "C" {
#endif

#define L_DBUS_INTERFACE_DBUS		"org.freedesktop.DBus"
#define L_DBUS_INTERFACE_INTROSPECTABLE	"org.freedesktop.DBus.Introspectable"
#define L_DBUS_INTERFACE_PROPERTIES	"org.freedesktop.DBus.Properties"
#define L_DBUS_INTERFACE_OBJECT_MANAGER	"org.freedesktop.DBus.ObjectManager"

enum l_dbus_bus {
	L_DBUS_SYSTEM_BUS,
	L_DBUS_SESSION_BUS,
};

enum l_dbus_match_type {
	L_DBUS_MATCH_NONE = 0,
	L_DBUS_MATCH_TYPE,
	L_DBUS_MATCH_SENDER,
	L_DBUS_MATCH_PATH,
	L_DBUS_MATCH_INTERFACE,
	L_DBUS_MATCH_MEMBER,
	L_DBUS_MATCH_ARG0,
};

#define L_DBUS_MATCH_ARGUMENT(i)	(L_DBUS_MATCH_ARG0 + (i))

struct l_dbus;
struct l_dbus_interface;
struct l_dbus_message_builder;

typedef void (*l_dbus_ready_func_t) (void *user_data);
typedef void (*l_dbus_disconnect_func_t) (void *user_data);

typedef void (*l_dbus_debug_func_t) (const char *str, void *user_data);
typedef void (*l_dbus_destroy_func_t) (void *user_data);
typedef void (*l_dbus_interface_setup_func_t) (struct l_dbus_interface *);

typedef void (*l_dbus_watch_func_t) (struct l_dbus *dbus, void *user_data);

typedef void (*l_dbus_name_acquire_func_t) (struct l_dbus *dbus, bool success,
						bool queued, void *user_data);

struct l_dbus *l_dbus_new(const char *address);
struct l_dbus *l_dbus_new_default(enum l_dbus_bus bus);
void l_dbus_destroy(struct l_dbus *dbus);

bool l_dbus_set_ready_handler(struct l_dbus *dbus, l_dbus_ready_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);
bool l_dbus_set_disconnect_handler(struct l_dbus *dbus,
				l_dbus_disconnect_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);

bool l_dbus_set_debug(struct l_dbus *dbus, l_dbus_debug_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);

struct l_dbus_message;

struct l_dbus_message_iter {
	struct l_dbus_message *message;
	const char *sig_start;
	uint8_t sig_len;
	uint8_t sig_pos;
	const void *data;
	size_t len;
	size_t pos;
	char container_type;
	const void *offsets;
};

struct l_dbus_message *l_dbus_message_new_method_call(struct l_dbus *dbus,
							const char *destination,
							const char *path,
							const char *interface,
							const char *method);

struct l_dbus_message *l_dbus_message_new_signal(struct l_dbus *dbus,
							const char *path,
							const char *interface,
							const char *name);

struct l_dbus_message *l_dbus_message_new_method_return(
					struct l_dbus_message *method_call);

struct l_dbus_message *l_dbus_message_new_error_valist(
					struct l_dbus_message *method_call,
					const char *name,
					const char *format, va_list args);
struct l_dbus_message *l_dbus_message_new_error(
					struct l_dbus_message *method_call,
					const char *name,
					const char *format, ...)
					__attribute__((format(printf, 3, 4)));

struct l_dbus_message *l_dbus_message_ref(struct l_dbus_message *message);
void l_dbus_message_unref(struct l_dbus_message *message);

const char *l_dbus_message_get_path(struct l_dbus_message *message);
const char *l_dbus_message_get_interface(struct l_dbus_message *message);
const char *l_dbus_message_get_member(struct l_dbus_message *message);
const char *l_dbus_message_get_destination(struct l_dbus_message *message);
const char *l_dbus_message_get_sender(struct l_dbus_message *message);
const char *l_dbus_message_get_signature(struct l_dbus_message *message);

bool l_dbus_message_set_no_reply(struct l_dbus_message *message, bool on);
bool l_dbus_message_get_no_reply(struct l_dbus_message *message);

bool l_dbus_message_set_no_autostart(struct l_dbus_message *message, bool on);
bool l_dbus_message_get_no_autostart(struct l_dbus_message *message);

typedef void (*l_dbus_message_func_t) (struct l_dbus_message *message,
							void *user_data);

uint32_t l_dbus_send_with_reply(struct l_dbus *dbus,
				struct l_dbus_message *message,
				l_dbus_message_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);
uint32_t l_dbus_send(struct l_dbus *dbus,
				struct l_dbus_message *message);
bool l_dbus_cancel(struct l_dbus *dbus, uint32_t serial);

unsigned int l_dbus_register(struct l_dbus *dbus,
				l_dbus_message_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);
bool l_dbus_unregister(struct l_dbus *dbus, unsigned int id);

uint32_t l_dbus_method_call(struct l_dbus *dbus,
				const char *destination, const char *path,
				const char *interface, const char *method,
				l_dbus_message_func_t setup,
				l_dbus_message_func_t function,
				void *user_data, l_dbus_destroy_func_t destroy);

bool l_dbus_message_is_error(struct l_dbus_message *message);
bool l_dbus_message_get_error(struct l_dbus_message *message,
					const char **name, const char **text);
bool l_dbus_message_get_arguments(struct l_dbus_message *message,
						const char *signature, ...);
bool l_dbus_message_get_arguments_valist(struct l_dbus_message *message,
					const char *signature, va_list args);

bool l_dbus_message_iter_next_entry(struct l_dbus_message_iter *iter, ...);
bool l_dbus_message_iter_get_variant(struct l_dbus_message_iter *iter,
						const char *signature, ...);
bool l_dbus_message_iter_get_fixed_array(struct l_dbus_message_iter *iter,
						void *out, uint32_t *n_elem);

bool l_dbus_message_set_arguments(struct l_dbus_message *message,
						const char *signature, ...);
bool l_dbus_message_set_arguments_valist(struct l_dbus_message *message,
					 const char *signature, va_list args);

struct l_dbus_message_builder *l_dbus_message_builder_new(
						struct l_dbus_message *message);
void l_dbus_message_builder_destroy(struct l_dbus_message_builder *builder);

bool l_dbus_message_builder_append_basic(struct l_dbus_message_builder *builder,
					char type, const void *value);

bool l_dbus_message_builder_enter_container(
					struct l_dbus_message_builder *builder,
					char container_type,
					const char *signature);
bool l_dbus_message_builder_leave_container(
					struct l_dbus_message_builder *builder,
					char container_type);

bool l_dbus_message_builder_enter_struct(struct l_dbus_message_builder *builder,
						const char *signature);
bool l_dbus_message_builder_leave_struct(
					struct l_dbus_message_builder *builder);

bool l_dbus_message_builder_enter_dict(struct l_dbus_message_builder *builder,
					const char *signature);
bool l_dbus_message_builder_leave_dict(struct l_dbus_message_builder *builder);

bool l_dbus_message_builder_enter_array(struct l_dbus_message_builder *builder,
					const char *signature);
bool l_dbus_message_builder_leave_array(struct l_dbus_message_builder *builder);

bool l_dbus_message_builder_enter_variant(
					struct l_dbus_message_builder *builder,
					const char *signature);
bool l_dbus_message_builder_leave_variant(
					struct l_dbus_message_builder *builder);

bool l_dbus_message_builder_append_from_iter(
					struct l_dbus_message_builder *builder,
					struct l_dbus_message_iter *from);

bool l_dbus_message_builder_append_from_valist(
					struct l_dbus_message_builder *builder,
					const char *signature, va_list args);

struct l_dbus_message *l_dbus_message_builder_finalize(
					struct l_dbus_message_builder *builder);

bool l_dbus_register_interface(struct l_dbus *dbus, const char *interface,
				l_dbus_interface_setup_func_t setup_func,
				l_dbus_destroy_func_t destroy,
				bool handle_old_style_properties);
bool l_dbus_unregister_interface(struct l_dbus *dbus, const char *interface);

bool l_dbus_register_object(struct l_dbus *dbus, const char *path,
				void *user_data, l_dbus_destroy_func_t destroy,
				...);
bool l_dbus_unregister_object(struct l_dbus *dbus, const char *object);

bool l_dbus_object_add_interface(struct l_dbus *dbus, const char *object,
					const char *interface, void *user_data);
bool l_dbus_object_remove_interface(struct l_dbus *dbus, const char *object,
					const char *interface);
void *l_dbus_object_get_data(struct l_dbus *dbus, const char *object,
				const char *interface);

bool l_dbus_object_manager_enable(struct l_dbus *dbus, const char *root);

unsigned int l_dbus_add_service_watch(struct l_dbus *dbus,
					const char *name,
					l_dbus_watch_func_t connect_func,
					l_dbus_watch_func_t disconnect_func,
					void *user_data,
					l_dbus_destroy_func_t destroy);

unsigned int l_dbus_add_disconnect_watch(struct l_dbus *dbus,
					const char *name,
					l_dbus_watch_func_t disconnect_func,
					void *user_data,
					l_dbus_destroy_func_t destroy);
bool l_dbus_remove_watch(struct l_dbus *dbus, unsigned int id);

unsigned int l_dbus_add_signal_watch(struct l_dbus *dbus,
					const char *sender,
					const char *path,
					const char *interface,
					const char *member, ...);
bool l_dbus_remove_signal_watch(struct l_dbus *dbus, unsigned int id);

uint32_t l_dbus_name_acquire(struct l_dbus *dbus, const char *name,
				bool allow_replacement, bool replace_existing,
				bool queue, l_dbus_name_acquire_func_t callback,
				void *user_data);

#ifdef __cplusplus
}
#endif

#endif /* __ELL_DBUS_H */