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