b2e78c4ad5306a6f5d3db4e6afde137a8cf93835
[platform/upstream/connman.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 gboolean (*GDBusPropertyExists)(const GDBusPropertyTable *property,
73                                                                 void *data);
74
75 typedef guint32 GDBusPendingReply;
76
77 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
78                                                 const char *action,
79                                                 gboolean interaction,
80                                                 GDBusPendingReply pending);
81
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),
86 };
87
88 enum GDBusSignalFlags {
89         G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
90 };
91
92 enum GDBusPropertyFlags {
93         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
94 };
95
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),
100 };
101
102 struct GDBusArgInfo {
103         const char *name;
104         const char *signature;
105 };
106
107 struct GDBusMethodTable {
108         const char *name;
109         GDBusMethodFunction function;
110         GDBusMethodFlags flags;
111         unsigned int privilege;
112         const GDBusArgInfo *in_args;
113         const GDBusArgInfo *out_args;
114 };
115
116 struct GDBusSignalTable {
117         const char *name;
118         GDBusSignalFlags flags;
119         const GDBusArgInfo *args;
120 };
121
122 struct GDBusPropertyTable {
123         const char *name;
124         const char *type;
125         GDBusPropertyGetter get;
126         GDBusPropertyExists exists;
127         GDBusPropertyFlags flags;
128 };
129
130 struct GDBusSecurityTable {
131         unsigned int privilege;
132         const char *action;
133         GDBusSecurityFlags flags;
134         GDBusSecurityFunction function;
135 };
136
137 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
138
139 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
140         .name = _name, \
141         .in_args = _in_args, \
142         .out_args = _out_args, \
143         .function = _function
144
145 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
146         .name = _name, \
147         .in_args = _in_args, \
148         .out_args = _out_args, \
149         .function = _function, \
150         .flags = G_DBUS_METHOD_FLAG_ASYNC
151
152 #define GDBUS_DEPRECATED_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_DEPRECATED
158
159 #define GDBUS_DEPRECATED_ASYNC_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_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
165
166 #define GDBUS_NOREPLY_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_NOREPLY
172
173 #define GDBUS_SIGNAL(_name, _args) \
174         .name = _name, \
175         .args = _args
176
177 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
178         .name = _name, \
179         .args = _args, \
180         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
181
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,
187                                         void *user_data,
188                                         GDBusDestroyFunction destroy);
189 gboolean g_dbus_unregister_interface(DBusConnection *connection,
190                                         const char *path, const char *name);
191
192 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
193 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
194
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);
204
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);
213
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);
219
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);
226
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);
241
242 #ifdef __cplusplus
243 }
244 #endif
245
246 #endif /* __GDBUS_H */