ba4962113af95893f4fd6a06b5716efe2a2e02b0
[platform/upstream/neard.git] / gdbus / gdbus.h
1 /*
2  *
3  *  D-Bus helper library
4  *
5  *  Copyright (C) 2004-2011  Marcel Holtmann <marcel@holtmann.org>
6  *
7  *
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.
12  *
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.
17  *
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
21  *
22  */
23
24 #ifndef __GDBUS_H
25 #define __GDBUS_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <dbus/dbus.h>
32 #include <glib.h>
33
34 typedef enum GDBusMethodFlags GDBusMethodFlags;
35 typedef enum GDBusSignalFlags GDBusSignalFlags;
36 typedef enum GDBusPropertyFlags GDBusPropertyFlags;
37 typedef enum GDBusSecurityFlags GDBusSecurityFlags;
38
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;
44
45 typedef void (* GDBusWatchFunction) (DBusConnection *connection,
46                                                         void *user_data);
47
48 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
49                                         DBusMessage *message, void *user_data);
50
51 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
52                                                         DBusError *error);
53
54 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
55                                                         DBusError *error);
56
57 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
58                                                         DBusError *error);
59
60 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
61                                 GDBusWatchFunction function,
62                                 void *user_data, DBusFreeFunction destroy);
63
64 typedef void (* GDBusDestroyFunction) (void *user_data);
65
66 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
67                                         DBusMessage *message, void *user_data);
68
69 typedef gboolean (*GDBusPropertyGetter)(const GDBusPropertyTable *property,
70                                         DBusMessageIter *iter, void *data);
71
72 typedef guint32 GDBusPendingPropertySet;
73
74 typedef void (*GDBusPropertySetter)(const GDBusPropertyTable *property,
75                         DBusMessageIter *value, GDBusPendingPropertySet id,
76                         void *data);
77
78 typedef gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
79                                                                 void *data);
80
81 typedef guint32 GDBusPendingReply;
82
83 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
84                                                 const char *action,
85                                                 gboolean interaction,
86                                                 GDBusPendingReply pending);
87
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),
92 };
93
94 enum GDBusSignalFlags {
95         G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
96 };
97
98 enum GDBusPropertyFlags {
99         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
100 };
101
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),
106 };
107
108 struct GDBusArgInfo {
109         const char *name;
110         const char *signature;
111 };
112
113 struct GDBusMethodTable {
114         const char *name;
115         GDBusMethodFunction function;
116         GDBusMethodFlags flags;
117         unsigned int privilege;
118         const GDBusArgInfo *in_args;
119         const GDBusArgInfo *out_args;
120 };
121
122 struct GDBusSignalTable {
123         const char *name;
124         GDBusSignalFlags flags;
125         const GDBusArgInfo *args;
126 };
127
128 struct GDBusPropertyTable {
129         const char *name;
130         const char *type;
131         GDBusPropertyGetter get;
132         GDBusPropertySetter set;
133         GDBusPropertyExists exists;
134         GDBusPropertyFlags flags;
135 };
136
137 struct GDBusSecurityTable {
138         unsigned int privilege;
139         const char *action;
140         GDBusSecurityFlags flags;
141         GDBusSecurityFunction function;
142 };
143
144 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
145
146 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
147         .name = _name, \
148         .in_args = _in_args, \
149         .out_args = _out_args, \
150         .function = _function
151
152 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
153         .name = _name, \
154         .in_args = _in_args, \
155         .out_args = _out_args, \
156         .function = _function, \
157         .flags = G_DBUS_METHOD_FLAG_ASYNC
158
159 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
160         .name = _name, \
161         .in_args = _in_args, \
162         .out_args = _out_args, \
163         .function = _function, \
164         .flags = G_DBUS_METHOD_FLAG_DEPRECATED
165
166 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
167         .name = _name, \
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
172
173 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
174         .name = _name, \
175         .in_args = _in_args, \
176         .out_args = _out_args, \
177         .function = _function, \
178         .flags = G_DBUS_METHOD_FLAG_NOREPLY
179
180 #define GDBUS_SIGNAL(_name, _args) \
181         .name = _name, \
182         .args = _args
183
184 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
185         .name = _name, \
186         .args = _args, \
187         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
188
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,
194                                         void *user_data,
195                                         GDBusDestroyFunction destroy);
196 gboolean g_dbus_unregister_interface(DBusConnection *connection,
197                                         const char *path, const char *name);
198
199 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
200 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
201
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);
211
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);
220
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);
226
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);
233
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);
248
249 void g_dbus_pending_property_success(GDBusPendingPropertySet id);
250 void g_dbus_pending_property_error_valist(GDBusPendingReply id,
251                         const char *name, const char *format, va_list args);
252 void g_dbus_pending_property_error(GDBusPendingReply id, const char *name,
253                                                 const char *format, ...);
254 void g_dbus_emit_property_changed(DBusConnection *connection,
255                                 const char *path, const char *interface,
256                                 const char *name);
257 gboolean g_dbus_get_properties(DBusConnection *connection, const char *path,
258                                 const char *interface, DBusMessageIter *iter);
259
260 #ifdef __cplusplus
261 }
262 #endif
263
264 #endif /* __GDBUS_H */