DA: Fix crash issue
[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 struct GDBusArgInfo GDBusArgInfo;
35 typedef struct GDBusMethodTable GDBusMethodTable;
36 typedef struct GDBusSignalTable GDBusSignalTable;
37 typedef struct GDBusPropertyTable GDBusPropertyTable;
38 typedef struct GDBusSecurityTable GDBusSecurityTable;
39
40 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
41                                                         void *user_data);
42
43 typedef void (* GDBusMessageFunction) (DBusConnection *connection,
44                                          DBusMessage *message, void *user_data);
45
46 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
47                                         DBusMessage *message, void *user_data);
48
49 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
50                                                         DBusError *error);
51
52 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
53                                                         DBusError *error);
54
55 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
56                                                         DBusError *error);
57
58 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
59                                 GDBusWatchFunction function,
60                                 void *user_data, DBusFreeFunction destroy);
61
62 typedef void (* GDBusDestroyFunction) (void *user_data);
63
64 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
65                                         DBusMessage *message, void *user_data);
66
67 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
68                                         DBusMessageIter *iter, void *data);
69
70 typedef guint32 GDBusPendingPropertySet;
71
72 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
73                         DBusMessageIter *value, GDBusPendingPropertySet id,
74                         void *data);
75
76 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
77                                                                 void *data);
78
79 typedef guint32 GDBusPendingReply;
80
81 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
82                                                 const char *action,
83                                                 gboolean interaction,
84                                                 GDBusPendingReply pending);
85
86 enum GDBusFlags {
87         G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
88 };
89
90 enum GDBusMethodFlags {
91         G_DBUS_METHOD_FLAG_DEPRECATED   = (1 << 0),
92         G_DBUS_METHOD_FLAG_NOREPLY      = (1 << 1),
93         G_DBUS_METHOD_FLAG_ASYNC        = (1 << 2),
94         G_DBUS_METHOD_FLAG_EXPERIMENTAL = (1 << 3),
95 };
96
97 enum GDBusSignalFlags {
98         G_DBUS_SIGNAL_FLAG_DEPRECATED   = (1 << 0),
99         G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
100 };
101
102 enum GDBusPropertyFlags {
103         G_DBUS_PROPERTY_FLAG_DEPRECATED   = (1 << 0),
104         G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
105 };
106
107 enum GDBusSecurityFlags {
108         G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
109         G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
110         G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
111 };
112
113 enum GDbusPropertyChangedFlags {
114         G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH = (1 << 0),
115 };
116
117 typedef enum GDBusMethodFlags GDBusMethodFlags;
118 typedef enum GDBusSignalFlags GDBusSignalFlags;
119 typedef enum GDBusPropertyFlags GDBusPropertyFlags;
120 typedef enum GDBusSecurityFlags GDBusSecurityFlags;
121 typedef enum GDbusPropertyChangedFlags GDbusPropertyChangedFlags;
122
123 struct GDBusArgInfo {
124         const char *name;
125         const char *signature;
126 };
127
128 struct GDBusMethodTable {
129         const char *name;
130         GDBusMethodFunction function;
131         GDBusMethodFlags flags;
132         unsigned int privilege;
133         const GDBusArgInfo *in_args;
134         const GDBusArgInfo *out_args;
135 };
136
137 struct GDBusSignalTable {
138         const char *name;
139         GDBusSignalFlags flags;
140         const GDBusArgInfo *args;
141 };
142
143 struct GDBusPropertyTable {
144         const char *name;
145         const char *type;
146         GDBusPropertyGetter get;
147         GDBusPropertySetter set;
148         GDBusPropertyExists exists;
149         GDBusPropertyFlags flags;
150 };
151
152 struct GDBusSecurityTable {
153         unsigned int privilege;
154         const char *action;
155         GDBusSecurityFlags flags;
156         GDBusSecurityFunction function;
157 };
158
159 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
160
161 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
162         .name = _name, \
163         .in_args = _in_args, \
164         .out_args = _out_args, \
165         .function = _function
166
167 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
168         .name = _name, \
169         .in_args = _in_args, \
170         .out_args = _out_args, \
171         .function = _function, \
172         .flags = G_DBUS_METHOD_FLAG_ASYNC
173
174 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
175         .name = _name, \
176         .in_args = _in_args, \
177         .out_args = _out_args, \
178         .function = _function, \
179         .flags = G_DBUS_METHOD_FLAG_DEPRECATED
180
181 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
182         .name = _name, \
183         .in_args = _in_args, \
184         .out_args = _out_args, \
185         .function = _function, \
186         .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
187
188 #define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
189         .name = _name, \
190         .in_args = _in_args, \
191         .out_args = _out_args, \
192         .function = _function, \
193         .flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
194
195 #define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
196         .name = _name, \
197         .in_args = _in_args, \
198         .out_args = _out_args, \
199         .function = _function, \
200         .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_EXPERIMENTAL
201
202 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
203         .name = _name, \
204         .in_args = _in_args, \
205         .out_args = _out_args, \
206         .function = _function, \
207         .flags = G_DBUS_METHOD_FLAG_NOREPLY
208
209 #define GDBUS_SIGNAL(_name, _args) \
210         .name = _name, \
211         .args = _args
212
213 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
214         .name = _name, \
215         .args = _args, \
216         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
217
218 #define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
219         .name = _name, \
220         .args = _args, \
221         .flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
222
223 void g_dbus_set_flags(int flags);
224 int g_dbus_get_flags(void);
225
226 gboolean g_dbus_register_interface(DBusConnection *connection,
227                                         const char *path, const char *name,
228                                         const GDBusMethodTable *methods,
229                                         const GDBusSignalTable *signals,
230                                         const GDBusPropertyTable *properties,
231                                         void *user_data,
232                                         GDBusDestroyFunction destroy);
233 gboolean g_dbus_unregister_interface(DBusConnection *connection,
234                                         const char *path, const char *name);
235
236 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
237 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
238
239 void g_dbus_pending_success(DBusConnection *connection,
240                                         GDBusPendingReply pending);
241 void g_dbus_pending_error(DBusConnection *connection,
242                                 GDBusPendingReply pending,
243                                 const char *name, const char *format, ...)
244                                         __attribute__((format(printf, 4, 5)));
245 void g_dbus_pending_error_valist(DBusConnection *connection,
246                                 GDBusPendingReply pending, const char *name,
247                                         const char *format, va_list args);
248
249 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
250                                                 const char *format, ...)
251                                         __attribute__((format(printf, 3, 4)));
252 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
253                                         const char *format, va_list args);
254 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
255 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
256                                                 int type, va_list args);
257
258 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
259 gboolean g_dbus_send_message_with_reply(DBusConnection *connection,
260                                         DBusMessage *message,
261                                         DBusPendingCall **call, int timeout);
262 gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
263                                 const char *name, const char *format, ...)
264                                          __attribute__((format(printf, 4, 5)));
265 gboolean g_dbus_send_error_valist(DBusConnection *connection,
266                                         DBusMessage *message, const char *name,
267                                         const char *format, va_list args);
268 gboolean g_dbus_send_reply(DBusConnection *connection,
269                                 DBusMessage *message, int type, ...);
270 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
271                                 DBusMessage *message, int type, va_list args);
272
273 gboolean g_dbus_emit_signal(DBusConnection *connection,
274                                 const char *path, const char *interface,
275                                 const char *name, int type, ...);
276 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
277                                 const char *path, const char *interface,
278                                 const char *name, int type, va_list args);
279
280 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
281                                 GDBusWatchFunction connect,
282                                 GDBusWatchFunction disconnect,
283                                 void *user_data, GDBusDestroyFunction destroy);
284 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
285                                 GDBusWatchFunction function,
286                                 void *user_data, GDBusDestroyFunction destroy);
287 guint g_dbus_add_signal_watch(DBusConnection *connection,
288                                 const char *sender, const char *path,
289                                 const char *interface, const char *member,
290                                 GDBusSignalFunction function, void *user_data,
291                                 GDBusDestroyFunction destroy);
292 guint g_dbus_add_properties_watch(DBusConnection *connection,
293                                 const char *sender, const char *path,
294                                 const char *interface,
295                                 GDBusSignalFunction function, void *user_data,
296                                 GDBusDestroyFunction destroy);
297 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
298 void g_dbus_remove_all_watches(DBusConnection *connection);
299
300 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
301 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
302                         const char *name, const char *format, va_list args);
303 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
304                                                 const char *format, ...);
305 void g_dbus_emit_property_changed(DBusConnection *connection,
306                                 const char *path, const char *interface,
307                                 const char *name);
308 void g_dbus_emit_property_changed_full(DBusConnection *connection,
309                                 const char *path, const char *interface,
310                                 const char *name,
311                                 GDbusPropertyChangedFlags flags);
312 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
313                                 const char *interface, DBusMessageIter *iter);
314
315 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
316 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
317
318 typedef struct GDBusClient GDBusClient;
319 typedef struct GDBusProxy GDBusProxy;
320
321 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
322                                                         const char *interface);
323
324 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
325 void g_dbus_proxy_unref(GDBusProxy *proxy);
326
327 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
328 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
329
330 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
331                                                         DBusMessageIter *iter);
332
333 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
334
335 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
336
337 gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
338                                 const char *name, int type, const void *value,
339                                 GDBusResultFunction function, void *user_data,
340                                 GDBusDestroyFunction destroy);
341
342 #if !defined TIZEN_EXT
343 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
344                                 const char *name, int type, const void *value,
345                                 size_t size, GDBusResultFunction function,
346                                 void *user_data, GDBusDestroyFunction destroy);
347 #endif
348
349 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
350 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
351
352 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
353                                 GDBusSetupFunction setup,
354                                 GDBusReturnFunction function, void *user_data,
355                                 GDBusDestroyFunction destroy);
356
357 #if !defined TIZEN_EXT
358 typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
359 #endif
360 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
361 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
362                                         DBusMessageIter *iter, void *user_data);
363
364 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
365                         GDBusPropertyFunction function, void *user_data);
366
367 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
368                         GDBusProxyFunction destroy, void *user_data);
369
370 GDBusClient *g_dbus_client_new(DBusConnection *connection,
371                                         const char *service, const char *path);
372 GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
373                                                         const char *service,
374                                                         const char *path,
375                                                         const char *root_path);
376
377 GDBusClient *g_dbus_client_ref(GDBusClient *client);
378 void g_dbus_client_unref(GDBusClient *client);
379
380 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
381                                 GDBusWatchFunction function, void *user_data);
382 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
383                                 GDBusWatchFunction function, void *user_data);
384 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
385                                 GDBusMessageFunction function, void *user_data);
386 #if !defined TIZEN_EXT
387 gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
388                                 GDBusClientFunction ready, void *user_data);
389 #endif
390 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
391                                         GDBusProxyFunction proxy_added,
392                                         GDBusProxyFunction proxy_removed,
393                                         GDBusPropertyFunction property_changed,
394                                         void *user_data);
395
396 #ifdef __cplusplus
397 }
398 #endif
399
400 #endif /* __GDBUS_H */