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 gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
75 typedef guint32 GDBusPendingReply;
77 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
80 GDBusPendingReply pending);
82 enum GDBusMethodFlags {
83 G_DBUS_METHOD_FLAG_DEPRECATED = (1 << 0),
84 G_DBUS_METHOD_FLAG_NOREPLY = (1 << 1),
85 G_DBUS_METHOD_FLAG_ASYNC = (1 << 2),
88 enum GDBusSignalFlags {
89 G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
92 enum GDBusPropertyFlags {
93 G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
96 enum GDBusSecurityFlags {
97 G_DBUS_SECURITY_FLAG_DEPRECATED = (1 << 0),
98 G_DBUS_SECURITY_FLAG_BUILTIN = (1 << 1),
99 G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
102 struct GDBusArgInfo {
104 const char *signature;
107 struct GDBusMethodTable {
109 GDBusMethodFunction function;
110 GDBusMethodFlags flags;
111 unsigned int privilege;
112 const GDBusArgInfo *in_args;
113 const GDBusArgInfo *out_args;
116 struct GDBusSignalTable {
118 GDBusSignalFlags flags;
119 const GDBusArgInfo *args;
122 struct GDBusPropertyTable {
125 GDBusPropertyGetter get;
126 GDBusPropertyExists exists;
127 GDBusPropertyFlags flags;
130 struct GDBusSecurityTable {
131 unsigned int privilege;
133 GDBusSecurityFlags flags;
134 GDBusSecurityFunction function;
137 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
139 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
141 .in_args = _in_args, \
142 .out_args = _out_args, \
143 .function = _function
145 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
147 .in_args = _in_args, \
148 .out_args = _out_args, \
149 .function = _function, \
150 .flags = G_DBUS_METHOD_FLAG_ASYNC
152 #define GDBUS_DEPRECATED_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_DEPRECATED
159 #define GDBUS_DEPRECATED_ASYNC_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_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
166 #define GDBUS_NOREPLY_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_NOREPLY
173 #define GDBUS_SIGNAL(_name, _args) \
177 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
180 .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
182 gboolean g_dbus_register_interface(DBusConnection *connection,
183 const char *path, const char *name,
184 const GDBusMethodTable *methods,
185 const GDBusSignalTable *signals,
186 const GDBusPropertyTable *properties,
188 GDBusDestroyFunction destroy);
189 gboolean g_dbus_unregister_interface(DBusConnection *connection,
190 const char *path, const char *name);
192 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
193 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
195 void g_dbus_pending_success(DBusConnection *connection,
196 GDBusPendingReply pending);
197 void g_dbus_pending_error(DBusConnection *connection,
198 GDBusPendingReply pending,
199 const char *name, const char *format, ...)
200 __attribute__((format(printf, 4, 5)));
201 void g_dbus_pending_error_valist(DBusConnection *connection,
202 GDBusPendingReply pending, const char *name,
203 const char *format, va_list args);
205 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
206 const char *format, ...)
207 __attribute__((format(printf, 3, 4)));
208 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
209 const char *format, va_list args);
210 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
211 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
212 int type, va_list args);
214 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
215 gboolean g_dbus_send_reply(DBusConnection *connection,
216 DBusMessage *message, int type, ...);
217 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
218 DBusMessage *message, int type, va_list args);
220 gboolean g_dbus_emit_signal(DBusConnection *connection,
221 const char *path, const char *interface,
222 const char *name, int type, ...);
223 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
224 const char *path, const char *interface,
225 const char *name, int type, va_list args);
227 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
228 GDBusWatchFunction connect,
229 GDBusWatchFunction disconnect,
230 void *user_data, GDBusDestroyFunction destroy);
231 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
232 GDBusWatchFunction function,
233 void *user_data, GDBusDestroyFunction destroy);
234 guint g_dbus_add_signal_watch(DBusConnection *connection,
235 const char *sender, const char *path,
236 const char *interface, const char *member,
237 GDBusSignalFunction function, void *user_data,
238 GDBusDestroyFunction destroy);
239 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
240 void g_dbus_remove_all_watches(DBusConnection *connection);
246 #endif /* __GDBUS_H */