device: Combine two if statements with identical outcome
[framework/connectivity/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 void (* GDBusWatchFunction) (DBusConnection *connection,
35                                                         void *user_data);
36
37 typedef gboolean (* GDBusSignalFunction) (DBusConnection *connection,
38                                         DBusMessage *message, void *user_data);
39
40 DBusConnection *g_dbus_setup_bus(DBusBusType type, const char *name,
41                                                         DBusError *error);
42
43 DBusConnection *g_dbus_setup_private(DBusBusType type, const char *name,
44                                                         DBusError *error);
45
46 gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
47                                                         DBusError *error);
48
49 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
50                                 GDBusWatchFunction function,
51                                 void *user_data, DBusFreeFunction destroy);
52
53 typedef void (* GDBusDestroyFunction) (void *user_data);
54
55 typedef DBusMessage * (* GDBusMethodFunction) (DBusConnection *connection,
56                                         DBusMessage *message, void *user_data);
57
58 typedef guint32 GDBusPendingReply;
59
60 typedef void (* GDBusSecurityFunction) (DBusConnection *connection,
61                                                 const char *action,
62                                                 gboolean interaction,
63                                                 GDBusPendingReply pending);
64
65 typedef enum {
66         G_DBUS_METHOD_FLAG_DEPRECATED = (1 << 0),
67         G_DBUS_METHOD_FLAG_NOREPLY    = (1 << 1),
68         G_DBUS_METHOD_FLAG_ASYNC      = (1 << 2),
69 } GDBusMethodFlags;
70
71 typedef enum {
72         G_DBUS_SIGNAL_FLAG_DEPRECATED = (1 << 0),
73 } GDBusSignalFlags;
74
75 typedef enum {
76         G_DBUS_PROPERTY_FLAG_DEPRECATED = (1 << 0),
77 } GDBusPropertyFlags;
78
79 typedef enum {
80         G_DBUS_SECURITY_FLAG_DEPRECATED        = (1 << 0),
81         G_DBUS_SECURITY_FLAG_BUILTIN           = (1 << 1),
82         G_DBUS_SECURITY_FLAG_ALLOW_INTERACTION = (1 << 2),
83 } GDBusSecurityFlags;
84
85 typedef struct {
86         const char *name;
87         const char *signature;
88 } GDBusArgInfo;
89
90 typedef struct {
91         const char *name;
92         GDBusMethodFunction function;
93         GDBusMethodFlags flags;
94         unsigned int privilege;
95         const GDBusArgInfo *in_args;
96         const GDBusArgInfo *out_args;
97 } GDBusMethodTable;
98
99 typedef struct {
100         const char *name;
101         GDBusSignalFlags flags;
102         const GDBusArgInfo *args;
103 } GDBusSignalTable;
104
105 typedef struct {
106         const char *name;
107         const char *type;
108         GDBusPropertyFlags flags;
109 } GDBusPropertyTable;
110
111 typedef struct {
112         unsigned int privilege;
113         const char *action;
114         GDBusSecurityFlags flags;
115         GDBusSecurityFunction function;
116 } GDBusSecurityTable;
117
118 #define GDBUS_ARGS(args...) (const GDBusArgInfo[]) { args, { } }
119
120 #define GDBUS_METHOD(_name, _in_args, _out_args, _function) \
121         .name = _name, \
122         .in_args = _in_args, \
123         .out_args = _out_args, \
124         .function = _function
125
126 #define GDBUS_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
127         .name = _name, \
128         .in_args = _in_args, \
129         .out_args = _out_args, \
130         .function = _function, \
131         .flags = G_DBUS_METHOD_FLAG_ASYNC
132
133 #define GDBUS_DEPRECATED_METHOD(_name, _in_args, _out_args, _function) \
134         .name = _name, \
135         .in_args = _in_args, \
136         .out_args = _out_args, \
137         .function = _function, \
138         .flags = G_DBUS_METHOD_FLAG_DEPRECATED
139
140 #define GDBUS_DEPRECATED_ASYNC_METHOD(_name, _in_args, _out_args, _function) \
141         .name = _name, \
142         .in_args = _in_args, \
143         .out_args = _out_args, \
144         .function = _function, \
145         .flags = G_DBUS_METHOD_FLAG_ASYNC | G_DBUS_METHOD_FLAG_DEPRECATED
146
147 #define GDBUS_NOREPLY_METHOD(_name, _in_args, _out_args, _function) \
148         .name = _name, \
149         .in_args = _in_args, \
150         .out_args = _out_args, \
151         .function = _function, \
152         .flags = G_DBUS_METHOD_FLAG_NOREPLY
153
154 #define GDBUS_SIGNAL(_name, _args) \
155         .name = _name, \
156         .args = _args
157
158 #define GDBUS_DEPRECATED_SIGNAL(_name, _args) \
159         .name = _name, \
160         .args = _args, \
161         .flags = G_DBUS_SIGNAL_FLAG_DEPRECATED
162
163 gboolean g_dbus_register_interface(DBusConnection *connection,
164                                         const char *path, const char *name,
165                                         const GDBusMethodTable *methods,
166                                         const GDBusSignalTable *signals,
167                                         const GDBusPropertyTable *properties,
168                                         void *user_data,
169                                         GDBusDestroyFunction destroy);
170 gboolean g_dbus_unregister_interface(DBusConnection *connection,
171                                         const char *path, const char *name);
172
173 gboolean g_dbus_register_security(const GDBusSecurityTable *security);
174 gboolean g_dbus_unregister_security(const GDBusSecurityTable *security);
175
176 void g_dbus_pending_success(DBusConnection *connection,
177                                         GDBusPendingReply pending);
178 void g_dbus_pending_error(DBusConnection *connection,
179                                 GDBusPendingReply pending,
180                                 const char *name, const char *format, ...)
181                                         __attribute__((format(printf, 4, 5)));
182 void g_dbus_pending_error_valist(DBusConnection *connection,
183                                 GDBusPendingReply pending, const char *name,
184                                         const char *format, va_list args);
185
186 DBusMessage *g_dbus_create_error(DBusMessage *message, const char *name,
187                                                 const char *format, ...)
188                                         __attribute__((format(printf, 3, 4)));
189 DBusMessage *g_dbus_create_error_valist(DBusMessage *message, const char *name,
190                                         const char *format, va_list args);
191 DBusMessage *g_dbus_create_reply(DBusMessage *message, int type, ...);
192 DBusMessage *g_dbus_create_reply_valist(DBusMessage *message,
193                                                 int type, va_list args);
194
195 gboolean g_dbus_send_message(DBusConnection *connection, DBusMessage *message);
196 gboolean g_dbus_send_reply(DBusConnection *connection,
197                                 DBusMessage *message, int type, ...);
198 gboolean g_dbus_send_reply_valist(DBusConnection *connection,
199                                 DBusMessage *message, int type, va_list args);
200
201 gboolean g_dbus_emit_signal(DBusConnection *connection,
202                                 const char *path, const char *interface,
203                                 const char *name, int type, ...);
204 gboolean g_dbus_emit_signal_valist(DBusConnection *connection,
205                                 const char *path, const char *interface,
206                                 const char *name, int type, va_list args);
207
208 guint g_dbus_add_service_watch(DBusConnection *connection, const char *name,
209                                 GDBusWatchFunction connect,
210                                 GDBusWatchFunction disconnect,
211                                 void *user_data, GDBusDestroyFunction destroy);
212 guint g_dbus_add_disconnect_watch(DBusConnection *connection, const char *name,
213                                 GDBusWatchFunction function,
214                                 void *user_data, GDBusDestroyFunction destroy);
215 guint g_dbus_add_signal_watch(DBusConnection *connection,
216                                 const char *sender, const char *path,
217                                 const char *interface, const char *member,
218                                 GDBusSignalFunction function, void *user_data,
219                                 GDBusDestroyFunction destroy);
220 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
221 void g_dbus_remove_all_watches(DBusConnection *connection);
222
223 #ifdef __cplusplus
224 }
225 #endif
226
227 #endif /* __GDBUS_H */