gdbus: Introduce G_DBUS_METHOD_FLAG_EXPERIMENTAL
[platform/upstream/neard.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 };
105
106 enum GDBusPropertyFlags {
107         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
108 };
109
110 enum GDBusSecurityFlags {
111         G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
112         G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
113         G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
114 };
115
116 struct GDBusArgInfo {
117         const char *name;
118         const char *signature;
119 };
120
121 struct GDBusMethodTable {
122         const char *name;
123         GDBusMethodFunction function;
124         GDBusMethodFlags flags;
125         unsigned int privilege;
126         const GDBusArgInfo *in_args;
127         const GDBusArgInfo *out_args;
128 };
129
130 struct GDBusSignalTable {
131         const char *name;
132         GDBusSignalFlags flags;
133         const GDBusArgInfo *args;
134 };
135
136 struct GDBusPropertyTable {
137         const char *name;
138         const char *type;
139         GDBusPropertyGetter get;
140         GDBusPropertySetter set;
141         GDBusPropertyExists exists;
142         GDBusPropertyFlags flags;
143 };
144
145 struct GDBusSecurityTable {
146         unsigned int privilege;
147         const char *action;
148         GDBusSecurityFlags flags;
149         GDBusSecurityFunction function;
150 };
151
152 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
153
154 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
155         .name = _name, \
156         .in_args = _in_args, \
157         .out_args = _out_args, \
158         .function = _function
159
160 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
161         .name = _name, \
162         .in_args = _in_args, \
163         .out_args = _out_args, \
164         .function = _function, \
165         .flags = G_DBUS_METHOD_FLAG_ASYNC
166
167 #define GDBUS_DEPRECATED_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_DEPRECATED
173
174 #define GDBUS_DEPRECATED_ASYNC_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_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
180
181 #define GDBUS_EXPERIMENTAL_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_EXPERIMENTAL
187
188 #define GDBUS_EXPERIMENTAL_ASYNC_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_ASYNC | G_DBUS_METHOD_FLAG_EXPERIMENTAL
194
195 #define GDBUS_NOREPLY_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_NOREPLY
201
202 #define GDBUS_SIGNAL(_name, _args) \
203         .name = _name, \
204         .args = _args
205
206 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
207         .name = _name, \
208         .args = _args, \
209         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
210
211 void g_dbus_set_flags(int flags);
212
213 gboolean g_dbus_register_interface(DBusConnection *connection,
214                                         const char *path, const char *name,
215                                         const GDBusMethodTable *methods,
216                                         const GDBusSignalTable *signals,
217                                         const GDBusPropertyTable *properties,
218                                         void *user_data,
219                                         GDBusDestroyFunction destroy);
220 gboolean g_dbus_unregister_interface(DBusConnection *connection,
221                                         const char *path, const char *name);
222
223 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
224 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
225
226 void g_dbus_pending_success(DBusConnection *connection,
227                                         GDBusPendingReply pending);
228 void g_dbus_pending_error(DBusConnection *connection,
229                                 GDBusPendingReply pending,
230                                 const char *name, const char *format, ...)
231                                         __attribute__((format(printf, 4, 5)));
232 void g_dbus_pending_error_valist(DBusConnection *connection,
233                                 GDBusPendingReply pending, const char *name,
234                                         const char *format, va_list args);
235
236 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
237                                                 const char *format, ...)
238                                         __attribute__((format(printf, 3, 4)));
239 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
240                                         const char *format, va_list args);
241 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
242 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
243                                                 int type, va_list args);
244
245 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
246 gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
247                                 const char *name, const char *format, ...)
248                                          __attribute__((format(printf, 4, 5)));
249 gboolean g_dbus_send_error_valist(DBusConnection *connection,
250                                         DBusMessage *message, const char *name,
251                                         const char *format, va_list args);
252 gboolean g_dbus_send_reply(DBusConnection *connection,
253                                 DBusMessage *message, int type, ...);
254 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
255                                 DBusMessage *message, int type, va_list args);
256
257 gboolean g_dbus_emit_signal(DBusConnection *connection,
258                                 const char *path, const char *interface,
259                                 const char *name, int type, ...);
260 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
261                                 const char *path, const char *interface,
262                                 const char *name, int type, va_list args);
263
264 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
265                                 GDBusWatchFunction connect,
266                                 GDBusWatchFunction disconnect,
267                                 void *user_data, GDBusDestroyFunction destroy);
268 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
269                                 GDBusWatchFunction function,
270                                 void *user_data, GDBusDestroyFunction destroy);
271 guint g_dbus_add_signal_watch(DBusConnection *connection,
272                                 const char *sender, const char *path,
273                                 const char *interface, const char *member,
274                                 GDBusSignalFunction function, void *user_data,
275                                 GDBusDestroyFunction destroy);
276 guint g_dbus_add_properties_watch(DBusConnection *connection,
277                                 const char *sender, const char *path,
278                                 const char *interface,
279                                 GDBusSignalFunction function, void *user_data,
280                                 GDBusDestroyFunction destroy);
281 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
282 void g_dbus_remove_all_watches(DBusConnection *connection);
283
284 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
285 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
286                         const char *name, const char *format, va_list args);
287 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
288                                                 const char *format, ...);
289 void g_dbus_emit_property_changed(DBusConnection *connection,
290                                 const char *path, const char *interface,
291                                 const char *name);
292 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
293                                 const char *interface, DBusMessageIter *iter);
294
295 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
296 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
297
298 typedef struct GDBusClient GDBusClient;
299 typedef struct GDBusProxy GDBusProxy;
300
301 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
302                                                         const char *interface);
303
304 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
305 void g_dbus_proxy_unref(GDBusProxy *proxy);
306
307 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
308 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
309
310 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
311                                                         DBusMessageIter *iter);
312
313 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
314
315 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
316
317 gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
318                                 const char *name, int type, const void *value,
319                                 GDBusResultFunction function, void *user_data,
320                                 GDBusDestroyFunction destroy);
321
322 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
323 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
324
325 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
326                                 GDBusSetupFunction setup,
327                                 GDBusReturnFunction function, void *user_data,
328                                 GDBusDestroyFunction destroy);
329
330 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
331 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
332                                         DBusMessageIter *iter, void *user_data);
333
334 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
335                         GDBusPropertyFunction function, void *user_data);
336
337 GDBusClient *g_dbus_client_new(DBusConnection *connection,
338                                         const char *service, const char *path);
339
340 GDBusClient *g_dbus_client_ref(GDBusClient *client);
341 void g_dbus_client_unref(GDBusClient *client);
342
343 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
344                                 GDBusWatchFunction function, void *user_data);
345 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
346                                 GDBusWatchFunction function, void *user_data);
347 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
348                                 GDBusMessageFunction function, void *user_data);
349
350 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
351                                         GDBusProxyFunction proxy_added,
352                                         GDBusProxyFunction proxy_removed,
353                                         GDBusPropertyFunction property_changed,
354                                         void *user_data);
355
356 #ifdef __cplusplus
357 }
358 #endif
359
360 #endif /* __GDBUS_H */