Debian Codegraph @

lib/cui-dbus.h

raw symbols SCIP
1 /*
2 * cui library
3 *
4 * Copyright (C) 2011-2012 Intel Corporation. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 2.1,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 */
20
21 #ifndef __CUI_DBUS_H__
22 #define __CUI_DBUS_H__
23
24 #include <dbus/dbus.h>
25 #include <stdbool.h>
26
27 #ifndef DBUS_TIMEOUT_USE_DEFAULT
28 #define DBUS_TIMEOUT_USE_DEFAULT (-1)
29 #endif
30
31 /*
32 * Used for cui_dbus_append_dict_entry_dict,
33 * and cui_dbus_get_dict_entry.
34 * It should not be used anywhere else.
35 */
36 enum cui_dbus_entry {
37 CUI_DBUS_ENTRY_BASIC = 0,
38 CUI_DBUS_ENTRY_ARRAY = 1,
39 CUI_DBUS_ENTRY_FIXED_ARRAY = 2,
40 CUI_DBUS_ENTRY_DICT = 3,
41 };
42
43 typedef void (*cui_dbus_property_f) (DBusMessageIter *iter,
44 void *user_data);
45 typedef bool (*cui_dbus_foreach_callback_f) (DBusMessageIter *iter,
46 void *user_data);
47
48 static inline
49 bool cui_dbus_open_dict(DBusMessageIter *iter, DBusMessageIter *dict) {
50 return dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
51 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
52 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
53 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, dict);
54 }
55
56 void cui_dbus_append_dict(DBusMessageIter *iter,
57 const char *key_name,
58 cui_dbus_property_f property_function,
59 void *user_data);
60
61 void cui_dbus_append_basic(DBusMessageIter *iter,
62 const char *key_name,
63 int dbus_type,
64 void *value);
65
66 void cui_dbus_append_array(DBusMessageIter *iter,
67 const char *key_name,
68 int dbus_type,
69 cui_dbus_property_f property_function,
70 void *user_data);
71
72 void cui_dbus_append_fixed_array(DBusMessageIter *iter,
73 const char *key_name,
74 int dbus_type,
75 int length,
76 void *value);
77
78 /* Use preferably the inline functions below this one */
79 void cui_dbus_append_dict_entry(DBusMessageIter *dict,
80 const char *key_name,
81 enum cui_dbus_entry entry_type,
82 int dbus_type,
83 int length,
84 cui_dbus_property_f property_function,
85 void *user_data);
86
87 static inline
88 void cui_dbus_append_dict_entry_basic(DBusMessageIter *dict,
89 const char *key_name,
90 int dbus_type,
91 void *value)
92 {
93 cui_dbus_append_dict_entry(dict, key_name,
94 CUI_DBUS_ENTRY_BASIC, dbus_type, 0, NULL, value);
95 }
96
97 static inline
98 void cui_dbus_append_dict_entry_array(DBusMessageIter *dict,
99 const char *key_name,
100 int dbus_type,
101 cui_dbus_property_f property_function,
102 void *user_data)
103 {
104 cui_dbus_append_dict_entry(dict, key_name,
105 CUI_DBUS_ENTRY_ARRAY, dbus_type, 0,
106 property_function, user_data);
107 }
108
109 static inline
110 void cui_dbus_append_dict_entry_fixed_array(DBusMessageIter *dict,
111 const char *key_name,
112 int dbus_type,
113 int length,
114 void *value)
115 {
116 cui_dbus_append_dict_entry(dict, key_name,
117 CUI_DBUS_ENTRY_FIXED_ARRAY, dbus_type,
118 length, NULL, value);
119 }
120
121 static inline
122 void cui_dbus_append_dict_entry_dict(DBusMessageIter *dict,
123 const char *key_name,
124 cui_dbus_property_f property_function,
125 void *user_data)
126 {
127 cui_dbus_append_dict_entry(dict, key_name,
128 CUI_DBUS_ENTRY_DICT, 0, 0,
129 property_function, user_data);
130 }
131
132 int cui_dbus_get_basic(DBusMessageIter *iter,
133 int dbus_type,
134 void *destination);
135
136 int cui_dbus_get_basic_variant(DBusMessageIter *iter,
137 int dbus_type,
138 void *destination);
139
140 int cui_dbus_get_array(DBusMessageIter *iter,
141 int dbus_type,
142 int *length,
143 void *destination);
144
145 int cui_dbus_get_fixed_array(DBusMessageIter *iter,
146 int *length,
147 void *destination);
148
149
150 int cui_dbus_foreach_dict_entry(DBusMessageIter *iter,
151 cui_dbus_foreach_callback_f callback,
152 void *user_data);
153
154
155 /* Use preferably the inline functions below this one */
156 int cui_dbus_get_dict_entry(DBusMessageIter *iter,
157 const char *key_name,
158 enum cui_dbus_entry entry_type,
159 int dbus_type,
160 int *length,
161 void *destination);
162
163 static inline
164 int cui_dbus_get_dict_entry_basic(DBusMessageIter *iter,
165 const char *key_name,
166 int dbus_type,
167 void *destination)
168 {
169 return cui_dbus_get_dict_entry(iter, key_name,
170 CUI_DBUS_ENTRY_BASIC,
171 dbus_type, NULL, destination);
172 }
173
174 static inline
175 int cui_dbus_get_dict_entry_array(DBusMessageIter *iter,
176 const char *key_name,
177 int dbus_type,
178 int *length,
179 void *destination)
180 {
181 return cui_dbus_get_dict_entry(iter, key_name,
182 CUI_DBUS_ENTRY_ARRAY,
183 dbus_type, length, destination);
184 }
185
186 static inline
187 int cui_dbus_get_dict_entry_fixed_array(DBusMessageIter *iter,
188 const char *key_name,
189 int dbus_type,
190 int *length,
191 void *destination)
192 {
193 return cui_dbus_get_dict_entry(iter, key_name,
194 CUI_DBUS_ENTRY_FIXED_ARRAY,
195 dbus_type, length, destination);
196 }
197
198 static inline
199 int cui_dbus_get_dict_entry_dict(DBusMessageIter *iter,
200 const char *key_name,
201 DBusMessageIter *dict)
202 {
203 return cui_dbus_get_dict_entry(iter, key_name,
204 CUI_DBUS_ENTRY_DICT,
205 DBUS_TYPE_INVALID, NULL, dict);
206 }
207
208 /* Use preferably the inline functions below this one */
209 int cui_dbus_get_struct_entry(DBusMessageIter *iter,
210 unsigned int position,
211 enum cui_dbus_entry entry_type,
212 int dbus_type,
213 int *length,
214 void *destination);
215
216 static inline
217 int cui_dbus_get_struct_entry_basic(DBusMessageIter *iter,
218 unsigned int position,
219 int dbus_type,
220 void *destination)
221 {
222 return cui_dbus_get_struct_entry(iter, position,
223 CUI_DBUS_ENTRY_BASIC,
224 dbus_type, NULL, destination);
225 }
226
227 static inline
228 int cui_dbus_get_struct_entry_array(DBusMessageIter *iter,
229 unsigned int position,
230 int dbus_type,
231 int *length,
232 void *destination)
233 {
234 return cui_dbus_get_struct_entry(iter, position,
235 CUI_DBUS_ENTRY_ARRAY,
236 dbus_type, length, destination);
237 }
238
239 static inline
240 int cui_dbus_get_struct_entry_fixed_array(DBusMessageIter *iter,
241 unsigned int position,
242 int dbus_type,
243 int *length,
244 void *destination)
245 {
246 return cui_dbus_get_struct_entry(iter, position,
247 CUI_DBUS_ENTRY_FIXED_ARRAY,
248 dbus_type, length, destination);
249 }
250
251 static inline
252 int cui_dbus_get_struct_entry_dict(DBusMessageIter *iter,
253 unsigned int position,
254 DBusMessageIter *dict)
255 {
256 return cui_dbus_get_struct_entry(iter, position,
257 CUI_DBUS_ENTRY_DICT,
258 DBUS_TYPE_INVALID, NULL, dict);
259 }
260
261 static inline dbus_bool_t cui_dbus_is_service_running(DBusConnection *dbus_cnx,
262 const char *dbus_service_name)
263 {
264 if (dbus_bus_name_has_owner(dbus_cnx,
265 dbus_service_name, NULL) == FALSE)
266 return FALSE;
267
268 return TRUE;
269 }
270
271 #endif /* __CUI_DBUS_H__ */