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 gboolean (* GDBusSignalFunction) (DBusConnection *connection,
49 DBusMessage *message, void *user_data);
51 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
54 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
57 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
60 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
61 GDBusWatchFunction function,
62 void *user_data, DBusFreeFunction destroy);
64 typedef void (* GDBusDestroyFunction) (void *user_data);
66 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
67 DBusMessage *message, void *user_data);
69 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
70 DBusMessageIter *iter, void *data);
72 typedef guint32 GDBusPendingPropertySet;
74 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
75 DBusMessageIter *value, GDBusPendingPropertySet id,
78 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
81 typedef guint32 GDBusPendingReply;
83 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
86 GDBusPendingReply pending);
88 enum GDBusMethodFlags {
89 G_DBUS_METHOD_FLAG_DEPRECATED = (1 << 0),
90 G_DBUS_METHOD_FLAG_NOREPLY = (1 << 1),
91 G_DBUS_METHOD_FLAG_ASYNC = (1 << 2),
94 enum GDBusSignalFlags {
95 G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
98 enum GDBusPropertyFlags {
99 G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
102 enum GDBusSecurityFlags {
103 G_DBUS_SECURITY_FLAG_DEPRECATED = (1 << 0),
104 G_DBUS_SECURITY_FLAG_BUILTIN = (1 << 1),
105 G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
108 struct GDBusArgInfo {
110 const char *signature;
113 struct GDBusMethodTable {
115 GDBusMethodFunction function;
116 GDBusMethodFlags flags;
117 unsigned int privilege;
118 const GDBusArgInfo *in_args;
119 const GDBusArgInfo *out_args;
122 struct GDBusSignalTable {
124 GDBusSignalFlags flags;
125 const GDBusArgInfo *args;
128 struct GDBusPropertyTable {
131 GDBusPropertyGetter get;
132 GDBusPropertySetter set;
133 GDBusPropertyExists exists;
134 GDBusPropertyFlags flags;
137 struct GDBusSecurityTable {
138 unsigned int privilege;
140 GDBusSecurityFlags flags;
141 GDBusSecurityFunction function;
144 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
146 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
148 .in_args = _in_args, \
149 .out_args = _out_args, \
150 .function = _function
152 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
154 .in_args = _in_args, \
155 .out_args = _out_args, \
156 .function = _function, \
157 .flags = G_DBUS_METHOD_FLAG_ASYNC
159 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
161 .in_args = _in_args, \
162 .out_args = _out_args, \
163 .function = _function, \
164 .flags = G_DBUS_METHOD_FLAG_DEPRECATED
166 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
168 .in_args = _in_args, \
169 .out_args = _out_args, \
170 .function = _function, \
171 .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
173 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
175 .in_args = _in_args, \
176 .out_args = _out_args, \
177 .function = _function, \
178 .flags = G_DBUS_METHOD_FLAG_NOREPLY
180 #define GDBUS_SIGNAL(_name, _args) \
184 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
187 .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
189 gboolean g_dbus_register_interface(DBusConnection *connection,
190 const char *path, const char *name,
191 const GDBusMethodTable *methods,
192 const GDBusSignalTable *signals,
193 const GDBusPropertyTable *properties,
195 GDBusDestroyFunction destroy);
196 gboolean g_dbus_unregister_interface(DBusConnection *connection,
197 const char *path, const char *name);
199 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
200 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
202 void g_dbus_pending_success(DBusConnection *connection,
203 GDBusPendingReply pending);
204 void g_dbus_pending_error(DBusConnection *connection,
205 GDBusPendingReply pending,
206 const char *name, const char *format, ...)
207 __attribute__((format(printf, 4, 5)));
208 void g_dbus_pending_error_valist(DBusConnection *connection,
209 GDBusPendingReply pending, const char *name,
210 const char *format, va_list args);
212 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
213 const char *format, ...)
214 __attribute__((format(printf, 3, 4)));
215 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
216 const char *format, va_list args);
217 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
218 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
219 int type, va_list args);
221 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
222 gboolean g_dbus_send_reply(DBusConnection *connection,
223 DBusMessage *message, int type, ...);
224 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
225 DBusMessage *message, int type, va_list args);
227 gboolean g_dbus_emit_signal(DBusConnection *connection,
228 const char *path, const char *interface,
229 const char *name, int type, ...);
230 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
231 const char *path, const char *interface,
232 const char *name, int type, va_list args);
234 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
235 GDBusWatchFunction connect,
236 GDBusWatchFunction disconnect,
237 void *user_data, GDBusDestroyFunction destroy);
238 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
239 GDBusWatchFunction function,
240 void *user_data, GDBusDestroyFunction destroy);
241 guint g_dbus_add_signal_watch(DBusConnection *connection,
242 const char *sender, const char *path,
243 const char *interface, const char *member,
244 GDBusSignalFunction function, void *user_data,
245 GDBusDestroyFunction destroy);
246 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
247 void g_dbus_remove_all_watches(DBusConnection *connection);
249 void g_dbus_pending_property_success(DBusConnection *connection,
250 GDBusPendingPropertySet id);
251 void g_dbus_pending_property_error_valist(DBusConnection *connection,
252 GDBusPendingReply id, const char *name,
253 const char *format, va_list args);
254 void g_dbus_pending_property_error(DBusConnection *connection,
255 GDBusPendingReply id, const char *name,
256 const char *format, ...);
257 void g_dbus_emit_property_changed(DBusConnection *connection,
258 const char *path, const char *interface,
265 #endif /* __GDBUS_H */