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);
220 gboolean g_dbus_register_interface(DBusConnection *connection,
221 const char *path, const char *name,
222 const GDBusMethodTable *methods,
223 const GDBusSignalTable *signals,
224 const GDBusPropertyTable *properties,
226 GDBusDestroyFunction destroy);
227 gboolean g_dbus_unregister_interface(DBusConnection *connection,
228 const char *path, const char *name);
230 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
231 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
233 void g_dbus_pending_success(DBusConnection *connection,
234 GDBusPendingReply pending);
235 void g_dbus_pending_error(DBusConnection *connection,
236 GDBusPendingReply pending,
237 const char *name, const char *format, ...)
238 __attribute__((format(printf, 4, 5)));
239 void g_dbus_pending_error_valist(DBusConnection *connection,
240 GDBusPendingReply pending, const char *name,
241 const char *format, va_list args);
243 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
244 const char *format, ...)
245 __attribute__((format(printf, 3, 4)));
246 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
247 const char *format, va_list args);
248 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
249 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
250 int type, va_list args);
252 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
253 gboolean g_dbus_send_error(DBusConnection *connection, DBusMessage *message,
254 const char *name, const char *format, ...)
255 __attribute__((format(printf, 4, 5)));
256 gboolean g_dbus_send_error_valist(DBusConnection *connection,
257 DBusMessage *message, const char *name,
258 const char *format, va_list args);
259 gboolean g_dbus_send_reply(DBusConnection *connection,
260 DBusMessage *message, int type, ...);
261 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
262 DBusMessage *message, int type, va_list args);
264 gboolean g_dbus_emit_signal(DBusConnection *connection,
265 const char *path, const char *interface,
266 const char *name, int type, ...);
267 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
268 const char *path, const char *interface,
269 const char *name, int type, va_list args);
271 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
272 GDBusWatchFunction connect,
273 GDBusWatchFunction disconnect,
274 void *user_data, GDBusDestroyFunction destroy);
275 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
276 GDBusWatchFunction function,
277 void *user_data, GDBusDestroyFunction destroy);
278 guint g_dbus_add_signal_watch(DBusConnection *connection,
279 const char *sender, const char *path,
280 const char *interface, const char *member,
281 GDBusSignalFunction function, void *user_data,
282 GDBusDestroyFunction destroy);
283 guint g_dbus_add_properties_watch(DBusConnection *connection,
284 const char *sender, const char *path,
285 const char *interface,
286 GDBusSignalFunction function, void *user_data,
287 GDBusDestroyFunction destroy);
288 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
289 void g_dbus_remove_all_watches(DBusConnection *connection);
291 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
292 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
293 const char *name, const char *format, va_list args);
294 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
295 const char *format, ...);
296 void g_dbus_emit_property_changed(DBusConnection *connection,
297 const char *path, const char *interface,
299 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
300 const char *interface, DBusMessageIter *iter);
302 gboolean g_dbus_attach_object_manager(DBusConnection *connection);
303 gboolean g_dbus_detach_object_manager(DBusConnection *connection);
305 typedef struct GDBusClient GDBusClient;
306 typedef struct GDBusProxy GDBusProxy;
308 GDBusProxy *g_dbus_proxy_new(GDBusClient *client, const char *path,
309 const char *interface);
311 GDBusProxy *g_dbus_proxy_ref(GDBusProxy *proxy);
312 void g_dbus_proxy_unref(GDBusProxy *proxy);
314 const char *g_dbus_proxy_get_path(GDBusProxy *proxy);
315 const char *g_dbus_proxy_get_interface(GDBusProxy *proxy);
317 gboolean g_dbus_proxy_get_property(GDBusProxy *proxy, const char *name,
318 DBusMessageIter *iter);
320 gboolean g_dbus_proxy_refresh_property(GDBusProxy *proxy, const char *name);
322 typedef void (* GDBusResultFunction) (const DBusError *error, void *user_data);
324 gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
325 const char *name, int type, const void *value,
326 GDBusResultFunction function, void *user_data,
327 GDBusDestroyFunction destroy);
329 typedef void (* GDBusSetupFunction) (DBusMessageIter *iter, void *user_data);
330 typedef void (* GDBusReturnFunction) (DBusMessage *message, void *user_data);
332 gboolean g_dbus_proxy_method_call(GDBusProxy *proxy, const char *method,
333 GDBusSetupFunction setup,
334 GDBusReturnFunction function, void *user_data,
335 GDBusDestroyFunction destroy);
337 typedef void (* GDBusProxyFunction) (GDBusProxy *proxy, void *user_data);
338 typedef void (* GDBusPropertyFunction) (GDBusProxy *proxy, const char *name,
339 DBusMessageIter *iter, void *user_data);
341 gboolean g_dbus_proxy_set_property_watch(GDBusProxy *proxy,
342 GDBusPropertyFunction function, void *user_data);
344 gboolean g_dbus_proxy_set_removed_watch(GDBusProxy *proxy,
345 GDBusProxyFunction destroy, void *user_data);
347 GDBusClient *g_dbus_client_new(DBusConnection *connection,
348 const char *service, const char *path);
350 GDBusClient *g_dbus_client_ref(GDBusClient *client);
351 void g_dbus_client_unref(GDBusClient *client);
353 gboolean g_dbus_client_set_connect_watch(GDBusClient *client,
354 GDBusWatchFunction function, void *user_data);
355 gboolean g_dbus_client_set_disconnect_watch(GDBusClient *client,
356 GDBusWatchFunction function, void *user_data);
357 gboolean g_dbus_client_set_signal_watch(GDBusClient *client,
358 GDBusMessageFunction function, void *user_data);
360 gboolean g_dbus_client_set_proxy_handlers(GDBusClient *client,
361 GDBusProxyFunction proxy_added,
362 GDBusProxyFunction proxy_removed,
363 GDBusPropertyFunction property_changed,
370 #endif /* __GDBUS_H */