Base Code merged to SPIN 2.4
[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 int g_dbus_get_flags(void);
220
221 gboolean g_dbus_register_interface(DBusConnection *connection,
222                                         const char *path, const char *name,
223                                         const GDBusMethodTable *methods,
224                                         const GDBusSignalTable *signals,
225                                         const GDBusPropertyTable *properties,
226                                         void *user_data,
227                                         GDBusDestroyFunction destroy);
228 gboolean g_dbus_unregister_interface(DBusConnection *connection,
229                                         const char *path, const char *name);
230
231 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
232 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
233
234 void g_dbus_pending_success(DBusConnection *connection,
235                                         GDBusPendingReply pending);
236 void g_dbus_pending_error(DBusConnection *connection,
237                                 GDBusPendingReply pending,
238                                 const char *name, const char *format, ...)
239                                         __attribute__((format(printf, 4, 5)));
240 void g_dbus_pending_error_valist(DBusConnection *connection,
241                                 GDBusPendingReply pending, const char *name,
242                                         const char *format, va_list args);
243
244 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
245                                                 const char *format, ...)
246                                         __attribute__((format(printf, 3, 4)));
247 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
248                                         const char *format, va_list args);
249 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
250 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
251                                                 int type, va_list args);
252
253 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
254 gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
255                                         DBusMessage *message,
256                                         DBusPendingCall **call, int timeout);
257 gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
258                                 const char *name, const char *format, ...)
259                                          __attribute__((format(printf, 4, 5)));
260 gboolean g_dbus_send_error_valist(DBusConnection *connection,
261                                         DBusMessage *message, const char *name,
262                                         const char *format, va_list args);
263 gboolean g_dbus_send_reply(DBusConnection *connection,
264                                 DBusMessage *message, int type, ...);
265 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
266                                 DBusMessage *message, int type, va_list args);
267
268 gboolean g_dbus_emit_signal(DBusConnection *connection,
269                                 const char *path, const char *interface,
270                                 const char *name, int type, ...);
271 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
272                                 const char *path, const char *interface,
273                                 const char *name, int type, va_list args);
274
275 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
276                                 GDBusWatchFunction connect,
277                                 GDBusWatchFunction disconnect,
278                                 void *user_data, GDBusDestroyFunction destroy);
279 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
280                                 GDBusWatchFunction function,
281                                 void *user_data, GDBusDestroyFunction destroy);
282 guint g_dbus_add_signal_watch(DBusConnection *connection,
283                                 const char *sender, const char *path,
284                                 const char *interface, const char *member,
285                                 GDBusSignalFunction function, void *user_data,
286                                 GDBusDestroyFunction destroy);
287 guint g_dbus_add_properties_watch(DBusConnection *connection,
288                                 const char *sender, const char *path,
289                                 const char *interface,
290                                 GDBusSignalFunction function, void *user_data,
291                                 GDBusDestroyFunction destroy);
292 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
293 void g_dbus_remove_all_watches(DBusConnection *connection);
294
295 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
296 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
297                         const char *name, const char *format, va_list args);
298 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
299                                                 const char *format, ...);
300 void g_dbus_emit_property_changed(DBusConnection *connection,
301                                 const char *path, const char *interface,
302                                 const char *name);
303 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
304                                 const char *interface, DBusMessageIter *iter);
305
306 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
307 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
308
309 typedef struct GDBusClient GDBusClient;
310 typedef struct GDBusProxy GDBusProxy;
311
312 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
313                                                         const char *interface);
314
315 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
316 void g_dbus_proxy_unref(GDBusProxy *proxy);
317
318 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
319 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
320
321 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
322                                                         DBusMessageIter *iter);
323
324 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
325
326 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
327
328 gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
329                                 const char *name, int type, const void *value,
330                                 GDBusResultFunction function, void *user_data,
331                                 GDBusDestroyFunction destroy);
332
333 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
334                                 const char *name, int type, const void *value,
335                                 size_t size, GDBusResultFunction function,
336                                 void *user_data, GDBusDestroyFunction destroy);
337
338 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
339 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
340
341 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
342                                 GDBusSetupFunction setup,
343                                 GDBusReturnFunction function, void *user_data,
344                                 GDBusDestroyFunction destroy);
345
346 typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
347 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
348 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
349                                         DBusMessageIter *iter, void *user_data);
350
351 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
352                         GDBusPropertyFunction function, void *user_data);
353
354 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
355                         GDBusProxyFunction destroy, void *user_data);
356
357 GDBusClient *g_dbus_client_new(DBusConnection *connection,
358                                         const char *service, const char *path);
359 GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
360                                                         const char *service,
361                                                         const char *path,
362                                                         const char *root_path);
363
364 GDBusClient *g_dbus_client_ref(GDBusClient *client);
365 void g_dbus_client_unref(GDBusClient *client);
366
367 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
368                                 GDBusWatchFunction function, void *user_data);
369 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
370                                 GDBusWatchFunction function, void *user_data);
371 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
372                                 GDBusMessageFunction function, void *user_data);
373 gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
374                                 GDBusClientFunction ready, void *user_data);
375 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
376                                         GDBusProxyFunction proxy_added,
377                                         GDBusProxyFunction proxy_removed,
378                                         GDBusPropertyFunction property_changed,
379                                         void *user_data);
380
381 #ifdef __cplusplus
382 }
383 #endif
384
385 #endif /* __GDBUS_H */