5 * Copyright (C) 2004-2011 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
31 #include <dbus/dbus.h>
34 typedef enum GDBusMethodFlags GDBusMethodFlags;
35 typedef enum GDBusSignalFlags GDBusSignalFlags;
36 typedef enum GDBusPropertyFlags GDBusPropertyFlags;
37 typedef enum GDBusSecurityFlags GDBusSecurityFlags;
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;
45 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
48 typedef void (* GDBusMessageFunction) (DBusConnection *connection,
49 DBusMessage *message, void *user_data);
51 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
52 DBusMessage *message, void *user_data);
54 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
57 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
60 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
63 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
64 GDBusWatchFunction function,
65 void *user_data, DBusFreeFunction destroy);
67 typedef void (* GDBusDestroyFunction) (void *user_data);
69 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
70 DBusMessage *message, void *user_data);
72 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
73 DBusMessageIter *iter, void *data);
75 typedef guint32 GDBusPendingPropertySet;
77 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
78 DBusMessageIter *value, GDBusPendingPropertySet id,
81 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
84 typedef guint32 GDBusPendingReply;
86 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
89 GDBusPendingReply pending);
92 G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
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),
102 enum GDBusSignalFlags {
103 G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
104 G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
107 enum GDBusPropertyFlags {
108 G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
109 G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
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),
118 struct GDBusArgInfo {
120 const char *signature;
123 struct GDBusMethodTable {
125 GDBusMethodFunction function;
126 GDBusMethodFlags flags;
127 unsigned int privilege;
128 const GDBusArgInfo *in_args;
129 const GDBusArgInfo *out_args;
132 struct GDBusSignalTable {
134 GDBusSignalFlags flags;
135 const GDBusArgInfo *args;
138 struct GDBusPropertyTable {
141 GDBusPropertyGetter get;
142 GDBusPropertySetter set;
143 GDBusPropertyExists exists;
144 GDBusPropertyFlags flags;
147 struct GDBusSecurityTable {
148 unsigned int privilege;
150 GDBusSecurityFlags flags;
151 GDBusSecurityFunction function;
154 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
156 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
158 .in_args = _in_args, \
159 .out_args = _out_args, \
160 .function = _function
162 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
164 .in_args = _in_args, \
165 .out_args = _out_args, \
166 .function = _function, \
167 .flags = G_DBUS_METHOD_FLAG_ASYNC
169 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
171 .in_args = _in_args, \
172 .out_args = _out_args, \
173 .function = _function, \
174 .flags = G_DBUS_METHOD_FLAG_DEPRECATED
176 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
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
183 #define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
185 .in_args = _in_args, \
186 .out_args = _out_args, \
187 .function = _function, \
188 .flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
190 #define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
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
197 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
199 .in_args = _in_args, \
200 .out_args = _out_args, \
201 .function = _function, \
202 .flags = G_DBUS_METHOD_FLAG_NOREPLY
204 #define GDBUS_SIGNAL(_name, _args) \
208 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
211 .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
213 #define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
216 .flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
218 void g_dbus_set_flags(int flags);
219 int g_dbus_get_flags(void);
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,
227 GDBusDestroyFunction destroy);
228 gboolean g_dbus_unregister_interface(DBusConnection *connection,
229 const char *path, const char *name);
231 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
232 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
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);
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);
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);
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);
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);
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,
303 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
304 const char *interface, DBusMessageIter *iter);
306 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
307 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
309 typedef struct GDBusClient GDBusClient;
310 typedef struct GDBusProxy GDBusProxy;
312 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
313 const char *interface);
315 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
316 void g_dbus_proxy_unref(GDBusProxy *proxy);
318 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
319 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
321 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
322 DBusMessageIter *iter);
324 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
326 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
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);
333 #if !defined TIZEN_EXT
334 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
335 const char *name, int type, const void *value,
336 size_t size, GDBusResultFunction function,
337 void *user_data, GDBusDestroyFunction destroy);
340 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
341 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
343 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
344 GDBusSetupFunction setup,
345 GDBusReturnFunction function, void *user_data,
346 GDBusDestroyFunction destroy);
348 #if !defined TIZEN_EXT
349 typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
351 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
352 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
353 DBusMessageIter *iter, void *user_data);
355 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
356 GDBusPropertyFunction function, void *user_data);
358 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
359 GDBusProxyFunction destroy, void *user_data);
361 GDBusClient *g_dbus_client_new(DBusConnection *connection,
362 const char *service, const char *path);
363 GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
366 const char *root_path);
368 GDBusClient *g_dbus_client_ref(GDBusClient *client);
369 void g_dbus_client_unref(GDBusClient *client);
371 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
372 GDBusWatchFunction function, void *user_data);
373 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
374 GDBusWatchFunction function, void *user_data);
375 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
376 GDBusMessageFunction function, void *user_data);
377 #if !defined TIZEN_EXT
378 gboolean g_dbus_client_set_ready_watch(GDBusClient *client,
379 GDBusClientFunction ready, void *user_data);
381 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
382 GDBusProxyFunction proxy_added,
383 GDBusProxyFunction proxy_removed,
384 GDBusPropertyFunction property_changed,
391 #endif /* __GDBUS_H */