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 struct GDBusArgInfo GDBusArgInfo;
35 typedef struct GDBusMethodTable GDBusMethodTable;
36 typedef struct GDBusSignalTable GDBusSignalTable;
37 typedef struct GDBusPropertyTable GDBusPropertyTable;
38 typedef struct GDBusSecurityTable GDBusSecurityTable;
40 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
43 typedef void (* GDBusMessageFunction) (DBusConnection *connection,
44 DBusMessage *message, void *user_data);
46 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
47 DBusMessage *message, void *user_data);
49 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
52 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
55 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
58 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
59 GDBusWatchFunction function,
60 void *user_data, DBusFreeFunction destroy);
62 typedef void (* GDBusDestroyFunction) (void *user_data);
64 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
65 DBusMessage *message, void *user_data);
67 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
68 DBusMessageIter *iter, void *data);
70 typedef guint32 GDBusPendingPropertySet;
72 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
73 DBusMessageIter *value, GDBusPendingPropertySet id,
76 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
79 typedef guint32 GDBusPendingReply;
81 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
84 GDBusPendingReply pending);
87 G_DBUS_FLAG_ENABLE_EXPERIMENTAL = (1 << 0),
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),
97 enum GDBusSignalFlags {
98 G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
99 G_DBUS_SIGNAL_FLAG_EXPERIMENTAL = (1 << 1),
102 enum GDBusPropertyFlags {
103 G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
104 G_DBUS_PROPERTY_FLAG_EXPERIMENTAL = (1 << 1),
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),
113 enum GDbusPropertyChangedFlags {
114 G_DBUS_PROPERTY_CHANGED_FLAG_FLUSH = (1 << 0),
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;
123 struct GDBusArgInfo {
125 const char *signature;
128 struct GDBusMethodTable {
130 GDBusMethodFunction function;
131 GDBusMethodFlags flags;
132 unsigned int privilege;
133 const GDBusArgInfo *in_args;
134 const GDBusArgInfo *out_args;
137 struct GDBusSignalTable {
139 GDBusSignalFlags flags;
140 const GDBusArgInfo *args;
143 struct GDBusPropertyTable {
146 GDBusPropertyGetter get;
147 GDBusPropertySetter set;
148 GDBusPropertyExists exists;
149 GDBusPropertyFlags flags;
152 struct GDBusSecurityTable {
153 unsigned int privilege;
155 GDBusSecurityFlags flags;
156 GDBusSecurityFunction function;
159 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
161 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
163 .in_args = _in_args, \
164 .out_args = _out_args, \
165 .function = _function
167 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
169 .in_args = _in_args, \
170 .out_args = _out_args, \
171 .function = _function, \
172 .flags = G_DBUS_METHOD_FLAG_ASYNC
174 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
176 .in_args = _in_args, \
177 .out_args = _out_args, \
178 .function = _function, \
179 .flags = G_DBUS_METHOD_FLAG_DEPRECATED
181 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
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
188 #define GDBUS_EXPERIMENTAL_METHOD(_name, _in_args, _out_args, _function) \
190 .in_args = _in_args, \
191 .out_args = _out_args, \
192 .function = _function, \
193 .flags = G_DBUS_METHOD_FLAG_EXPERIMENTAL
195 #define GDBUS_EXPERIMENTAL_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
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
202 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
204 .in_args = _in_args, \
205 .out_args = _out_args, \
206 .function = _function, \
207 .flags = G_DBUS_METHOD_FLAG_NOREPLY
209 #define GDBUS_SIGNAL(_name, _args) \
213 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
216 .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
218 #define GDBUS_EXPERIMENTAL_SIGNAL(_name, _args) \
221 .flags = G_DBUS_SIGNAL_FLAG_EXPERIMENTAL
223 void g_dbus_set_flags(int flags);
224 int g_dbus_get_flags(void);
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,
232 GDBusDestroyFunction destroy);
233 gboolean g_dbus_unregister_interface(DBusConnection *connection,
234 const char *path, const char *name);
236 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
237 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
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);
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);
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);
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);
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);
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,
308 void g_dbus_emit_property_changed_full(DBusConnection *connection,
309 const char *path, const char *interface,
311 GDbusPropertyChangedFlags flags);
312 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
313 const char *interface, DBusMessageIter *iter);
315 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
316 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
318 typedef struct GDBusClient GDBusClient;
319 typedef struct GDBusProxy GDBusProxy;
321 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
322 const char *interface);
324 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
325 void g_dbus_proxy_unref(GDBusProxy *proxy);
327 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
328 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
330 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
331 DBusMessageIter *iter);
333 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
335 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
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);
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);
349 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
350 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
352 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
353 GDBusSetupFunction setup,
354 GDBusReturnFunction function, void *user_data,
355 GDBusDestroyFunction destroy);
357 #if !defined TIZEN_EXT
358 typedef void (* GDBusClientFunction) (GDBusClient *client, void *user_data);
360 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
361 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
362 DBusMessageIter *iter, void *user_data);
364 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
365 GDBusPropertyFunction function, void *user_data);
367 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
368 GDBusProxyFunction destroy, void *user_data);
370 GDBusClient *g_dbus_client_new(DBusConnection *connection,
371 const char *service, const char *path);
372 GDBusClient *g_dbus_client_new_full(DBusConnection *connection,
375 const char *root_path);
377 GDBusClient *g_dbus_client_ref(GDBusClient *client);
378 void g_dbus_client_unref(GDBusClient *client);
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);
390 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
391 GDBusProxyFunction proxy_added,
392 GDBusProxyFunction proxy_removed,
393 GDBusPropertyFunction property_changed,
400 #endif /* __GDBUS_H */