551c306afbcbdc34cbbd8a35acd45b6a5d89b551
[platform/upstream/connman.git] / gdbus / gdbus.h
1 /*
2  *
3  *  D-Bus helper library
4  *
5  *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifndef __GDBUS_H
25 #define __GDBUS_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <dbus/dbus.h>
32 #include <glib.h>
33
34 typedef enum GDBusMethodFlags GDBusMethodFlags;
35 typedef enum GDBusSignalFlags GDBusSignalFlags;
36 typedef enum GDBusPropertyFlags GDBusPropertyFlags;
37 typedef enum GDBusSecurityFlags GDBusSecurityFlags;
38
39 typedef struct GDBusArgInfo GDBusArgInfo;
40 typedef struct GDBusMethodTable GDBusMethodTable;
41 typedef struct GDBusSignalTable GDBusSignalTable;
42 typedef struct GDBusPropertyTable GDBusPropertyTable;
43 typedef struct GDBusSecurityTable GDBusSecurityTable;
44
45 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
46                                                         void *user_data);
47
48 typedef void (* GDBusMessageFunction) (DBusConnection *connection,
49                                          DBusMessage *message, void *user_data);
50
51 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
52                                         DBusMessage *message, void *user_data);
53
54 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
55                                                         DBusError *error);
56
57 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
58                                                         DBusError *error);
59
60 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
61                                                         DBusError *error);
62
63 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
64                                 GDBusWatchFunction function,
65                                 void *user_data, DBusFreeFunction destroy);
66
67 typedef void (* GDBusDestroyFunction) (void *user_data);
68
69 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
70                                         DBusMessage *message, void *user_data);
71
72 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
73                                         DBusMessageIter *iter, void *data);
74
75 typedef guint32 GDBusPendingPropertySet;
76
77 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
78                         DBusMessageIter *value, GDBusPendingPropertySet id,
79                         void *data);
80
81 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
82                                                                 void *data);
83
84 typedef guint32 GDBusPendingReply;
85
86 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
87                                                 const char *action,
88                                                 gboolean interaction,
89                                                 GDBusPendingReply pending);
90
91 enum GDBusFlags {
92         G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
93 };
94
95 enum GDBusMethodFlags {
96         G_DBUS_METHOD_FLAG_DEPRECATED   = (1 << 0),
97         G_DBUS_METHOD_FLAG_NOREPLY      = (1 << 1),
98         G_DBUS_METHOD_FLAG_ASYNC        = (1 << 2),
99         G_DBUS_METHOD_FLAG_EXPERIMENTAL = (1 << 3),
100 };
101
102 enum GDBusSignalFlags {
103         G_DBUS_SIGNAL_FLAG_DEPRECATED   = (1 << 0),
104         G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
105 };
106
107 enum GDBusPropertyFlags {
108         G_DBUS_PROPERTY_FLAG_DEPRECATED   = (1 << 0),
109         G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
110 };
111
112 enum GDBusSecurityFlags {
113         G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
114         G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
115         G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
116 };
117
118 struct GDBusArgInfo {
119         const char *name;
120         const char *signature;
121 };
122
123 struct GDBusMethodTable {
124         const char *name;
125         GDBusMethodFunction function;
126         GDBusMethodFlags flags;
127         unsigned int privilege;
128         const GDBusArgInfo *in_args;
129         const GDBusArgInfo *out_args;
130 };
131
132 struct GDBusSignalTable {
133         const char *name;
134         GDBusSignalFlags flags;
135         const GDBusArgInfo *args;
136 };
137
138 struct GDBusPropertyTable {
139         const char *name;
140         const char *type;
141         GDBusPropertyGetter get;
142         GDBusPropertySetter set;
143         GDBusPropertyExists exists;
144         GDBusPropertyFlags flags;
145 };
146
147 struct GDBusSecurityTable {
148         unsigned int privilege;
149         const char *action;
150         GDBusSecurityFlags flags;
151         GDBusSecurityFunction function;
152 };
153
154 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
155
156 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
157         .name = _name, \
158         .in_args = _in_args, \
159         .out_args = _out_args, \
160         .function = _function
161
162 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
163         .name = _name, \
164         .in_args = _in_args, \
165         .out_args = _out_args, \
166         .function = _function, \
167         .flags = G_DBUS_METHOD_FLAG_ASYNC
168
169 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
170         .name = _name, \
171         .in_args = _in_args, \
172         .out_args = _out_args, \
173         .function = _function, \
174         .flags = G_DBUS_METHOD_FLAG_DEPRECATED
175
176 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
177         .name = _name, \
178         .in_args = _in_args, \
179         .out_args = _out_args, \
180         .function = _function, \
181         .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
182
183 #define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
184         .name = _name, \
185         .in_args = _in_args, \
186         .out_args = _out_args, \
187         .function = _function, \
188         .flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
189
190 #define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
191         .name = _name, \
192         .in_args = _in_args, \
193         .out_args = _out_args, \
194         .function = _function, \
195         .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_EXPERIMENTAL
196
197 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
198         .name = _name, \
199         .in_args = _in_args, \
200         .out_args = _out_args, \
201         .function = _function, \
202         .flags = G_DBUS_METHOD_FLAG_NOREPLY
203
204 #define GDBUS_SIGNAL(_name, _args) \
205         .name = _name, \
206         .args = _args
207
208 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
209         .name = _name, \
210         .args = _args, \
211         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
212
213 #define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
214         .name = _name, \
215         .args = _args, \
216         .flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
217
218 void g_dbus_set_flags(int flags);
219
220 gboolean g_dbus_register_interface(DBusConnection *connection,
221                                         const char *path, const char *name,
222                                         const GDBusMethodTable *methods,
223                                         const GDBusSignalTable *signals,
224                                         const GDBusPropertyTable *properties,
225                                         void *user_data,
226                                         GDBusDestroyFunction destroy);
227 gboolean g_dbus_unregister_interface(DBusConnection *connection,
228                                         const char *path, const char *name);
229
230 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
231 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
232
233 void g_dbus_pending_success(DBusConnection *connection,
234                                         GDBusPendingReply pending);
235 void g_dbus_pending_error(DBusConnection *connection,
236                                 GDBusPendingReply pending,
237                                 const char *name, const char *format, ...)
238                                         __attribute__((format(printf, 4, 5)));
239 void g_dbus_pending_error_valist(DBusConnection *connection,
240                                 GDBusPendingReply pending, const char *name,
241                                         const char *format, va_list args);
242
243 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
244                                                 const char *format, ...)
245                                         __attribute__((format(printf, 3, 4)));
246 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
247                                         const char *format, va_list args);
248 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
249 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
250                                                 int type, va_list args);
251
252 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
253 gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
254                                         DBusMessage *message,
255                                         DBusPendingCall **call, int timeout);
256 gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
257                                 const char *name, const char *format, ...)
258                                          __attribute__((format(printf, 4, 5)));
259 gboolean g_dbus_send_error_valist(DBusConnection *connection,
260                                         DBusMessage *message, const char *name,
261                                         const char *format, va_list args);
262 gboolean g_dbus_send_reply(DBusConnection *connection,
263                                 DBusMessage *message, int type, ...);
264 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
265                                 DBusMessage *message, int type, va_list args);
266
267 gboolean g_dbus_emit_signal(DBusConnection *connection,
268                                 const char *path, const char *interface,
269                                 const char *name, int type, ...);
270 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
271                                 const char *path, const char *interface,
272                                 const char *name, int type, va_list args);
273
274 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
275                                 GDBusWatchFunction connect,
276                                 GDBusWatchFunction disconnect,
277                                 void *user_data, GDBusDestroyFunction destroy);
278 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
279                                 GDBusWatchFunction function,
280                                 void *user_data, GDBusDestroyFunction destroy);
281 guint g_dbus_add_signal_watch(DBusConnection *connection,
282                                 const char *sender, const char *path,
283                                 const char *interface, const char *member,
284                                 GDBusSignalFunction function, void *user_data,
285                                 GDBusDestroyFunction destroy);
286 guint g_dbus_add_properties_watch(DBusConnection *connection,
287                                 const char *sender, const char *path,
288                                 const char *interface,
289                                 GDBusSignalFunction function, void *user_data,
290                                 GDBusDestroyFunction destroy);
291 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
292 void g_dbus_remove_all_watches(DBusConnection *connection);
293
294 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
295 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
296                         const char *name, const char *format, va_list args);
297 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
298                                                 const char *format, ...);
299 void g_dbus_emit_property_changed(DBusConnection *connection,
300                                 const char *path, const char *interface,
301                                 const char *name);
302 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
303                                 const char *interface, DBusMessageIter *iter);
304
305 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
306 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
307
308 typedef struct GDBusClient GDBusClient;
309 typedef struct GDBusProxy GDBusProxy;
310
311 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
312                                                         const char *interface);
313
314 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
315 void g_dbus_proxy_unref(GDBusProxy *proxy);
316
317 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
318 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
319
320 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
321                                                         DBusMessageIter *iter);
322
323 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
324
325 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
326
327 gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
328                                 const char *name, int type, const void *value,
329                                 GDBusResultFunction function, void *user_data,
330                                 GDBusDestroyFunction destroy);
331
332 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
333                                 const char *name, int type, const void *value,
334                                 size_t size, GDBusResultFunction function,
335                                 void *user_data, GDBusDestroyFunction destroy);
336
337 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
338 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
339
340 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
341                                 GDBusSetupFunction setup,
342                                 GDBusReturnFunction function, void *user_data,
343                                 GDBusDestroyFunction destroy);
344
345 typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
346 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
347 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
348                                         DBusMessageIter *iter, void *user_data);
349
350 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
351                         GDBusPropertyFunction function, void *user_data);
352
353 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
354                         GDBusProxyFunction destroy, void *user_data);
355
356 GDBusClient *g_dbus_client_new(DBusConnection *connection,
357                                         const char *service, const char *path);
358
359 GDBusClient *g_dbus_client_ref(GDBusClient *client);
360 void g_dbus_client_unref(GDBusClient *client);
361
362 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
363                                 GDBusWatchFunction function, void *user_data);
364 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
365                                 GDBusWatchFunction function, void *user_data);
366 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
367                                 GDBusMessageFunction function, void *user_data);
368 gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
369                                 GDBusClientFunction ready, void *user_data);
370 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
371                                         GDBusProxyFunction proxy_added,
372                                         GDBusProxyFunction proxy_removed,
373                                         GDBusPropertyFunction property_changed,
374                                         void *user_data);
375
376 #ifdef __cplusplus
377 }
378 #endif
379
380 #endif /* __GDBUS_H */