1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // Copyright (C) 2016 Intel Corporation. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
4 | |
5 | // |
6 | // W A R N I N G |
7 | // ------------- |
8 | // |
9 | // This file is not part of the public API. This header file may |
10 | // change from version to version without notice, or even be |
11 | // removed. |
12 | // |
13 | // We mean it. |
14 | // |
15 | // |
16 | |
17 | #ifndef QDBUS_SYMBOLS_P_H |
18 | #define QDBUS_SYMBOLS_P_H |
19 | |
20 | #include <QtDBus/private/qtdbusglobal_p.h> |
21 | |
22 | #ifndef QT_NO_DBUS |
23 | |
24 | #ifdef QT_LINKED_LIBDBUS |
25 | # include <dbus/dbus.h> |
26 | #else |
27 | # include "dbus_minimal_p.h" |
28 | #endif |
29 | |
30 | #include <atomic> |
31 | |
32 | #ifdef interface |
33 | # undef interface |
34 | #endif |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | #if !defined QT_LINKED_LIBDBUS |
39 | |
40 | QFunctionPointer qdbus_resolve_conditionally(const char *name); // doesn't print a warning |
41 | QFunctionPointer qdbus_resolve_me(const char *name); // prints a warning |
42 | bool qdbus_loadLibDBus(); |
43 | |
44 | //# define TRACE_DBUS_CALLS |
45 | # ifdef TRACE_DBUS_CALLS |
46 | namespace QtDBusCallTracing { |
47 | struct TraceDBusCall |
48 | { |
49 | struct ThreadData { |
50 | TraceDBusCall *ptr; |
51 | int level; |
52 | bool finishedPrinted; |
53 | }; |
54 | |
55 | static inline ThreadData &td() |
56 | { |
57 | Q_CONSTINIT static thread_local ThreadData value; |
58 | return value; |
59 | } |
60 | |
61 | ThreadData savedData; |
62 | QDebug s; |
63 | TraceDBusCall(QDebug s, const char *fname) |
64 | : savedData(td()), s(s.nospace() << QByteArray(savedData.level * 3, ' ').constData() << fname) |
65 | { |
66 | if (savedData.ptr && !savedData.finishedPrinted) { |
67 | savedData.ptr->s << " ...unfinished" ; |
68 | savedData.ptr->s = qDebug().nospace() << QByteArray(savedData.level * 3 - 3, ' ').constData(); |
69 | savedData.finishedPrinted = true; |
70 | } |
71 | ThreadData &data = td(); |
72 | data.ptr = this; |
73 | data.level++; |
74 | data.finishedPrinted = false; |
75 | } |
76 | ~TraceDBusCall() |
77 | { |
78 | td() = savedData; |
79 | } |
80 | |
81 | void operator()() { s << ")" ; } |
82 | template <typename... Args> void operator()(const char *arg1, Args &&... args) |
83 | { |
84 | s << '"' << arg1 << '"'; |
85 | if (sizeof...(args)) |
86 | s << ", " ; |
87 | operator()(args...); |
88 | } |
89 | template <typename Arg1, typename... Args> void operator()(Arg1 &&arg1, Args &&... args) |
90 | { |
91 | s << arg1; |
92 | if (sizeof...(args)) |
93 | s << ", " ; |
94 | operator()(args...); |
95 | } |
96 | }; |
97 | template <typename T> T operator,(TraceDBusCall &&tc, T &&ret) |
98 | { |
99 | tc.s << " = " << ret; |
100 | return ret; |
101 | } |
102 | inline const char *operator,(TraceDBusCall &&tc, const char *ret) |
103 | { |
104 | tc.s << " = \"" << ret << '"'; |
105 | return ret; |
106 | } |
107 | |
108 | template <typename T> struct TraceReturn { typedef TraceDBusCall Type; }; |
109 | template <> struct TraceReturn<void> { typedef void Type; }; |
110 | } |
111 | |
112 | # define DEBUGCALL(name, argcall) QtDBusCallTracing::TraceDBusCall tc(qDebug(), name "("); tc argcall |
113 | # define DEBUGRET(ret) (QtDBusCallTracing::TraceReturn<ret>::Type) tc , |
114 | # else |
115 | # define DEBUGCALL(name, argcall) |
116 | # define DEBUGRET(ret) |
117 | # endif |
118 | |
119 | # define DEFINEFUNC(ret, func, args, argcall, funcret) \ |
120 | static inline ret q_##func args \ |
121 | { \ |
122 | using func_ptr = ret (*) args; \ |
123 | static std::atomic<func_ptr> atomic_ptr; \ |
124 | func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \ |
125 | DEBUGCALL(#func, argcall); \ |
126 | if (!ptr) { \ |
127 | ptr = reinterpret_cast<func_ptr>(qdbus_resolve_me(#func)); \ |
128 | atomic_ptr.store(ptr, std::memory_order_relaxed); \ |
129 | } \ |
130 | funcret DEBUGRET(ret) ptr argcall; \ |
131 | } |
132 | |
133 | # define DEFINEFUNC_CONDITIONALLY(ret, func, args, argcall, funcret, failret) \ |
134 | static inline ret q_##func args \ |
135 | { \ |
136 | using func_ptr = ret (*) args; \ |
137 | static std::atomic<func_ptr> atomic_ptr; \ |
138 | func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \ |
139 | DEBUGCALL(#func, argcall); \ |
140 | if (!ptr) { \ |
141 | ptr = reinterpret_cast<func_ptr>(qdbus_resolve_conditionally(#func)); \ |
142 | atomic_ptr.store(ptr, std::memory_order_relaxed); \ |
143 | } \ |
144 | if (!ptr) \ |
145 | failret; \ |
146 | funcret DEBUGRET(ret) ptr argcall; \ |
147 | } |
148 | |
149 | #else // defined QT_LINKED_LIBDBUS |
150 | |
151 | inline bool qdbus_loadLibDBus() { return true; } |
152 | |
153 | # define DEFINEFUNC(ret, func, args, argcall, funcret) \ |
154 | static inline ret q_##func args { funcret func argcall; } |
155 | |
156 | #endif // defined QT_LINKED_LIBDBUS |
157 | |
158 | /* dbus-bus.h */ |
159 | DEFINEFUNC(void, dbus_bus_add_match, (DBusConnection *connection, |
160 | const char *rule, |
161 | DBusError *error), |
162 | (connection, rule, error), ) |
163 | DEFINEFUNC(void, dbus_bus_remove_match, (DBusConnection *connection, |
164 | const char *rule, |
165 | DBusError *error), |
166 | (connection, rule, error), ) |
167 | DEFINEFUNC(dbus_bool_t, dbus_bus_register,(DBusConnection *connection, |
168 | DBusError *error), |
169 | (connection, error), return) |
170 | DEFINEFUNC(DBusConnection *, dbus_bus_get_private, (DBusBusType type, |
171 | DBusError *error), |
172 | (type, error), return) |
173 | DEFINEFUNC(const char*, dbus_bus_get_unique_name, (DBusConnection *connection), |
174 | (connection), return) |
175 | |
176 | /* dbus-connection.h */ |
177 | DEFINEFUNC(dbus_bool_t , dbus_connection_add_filter, (DBusConnection *connection, |
178 | DBusHandleMessageFunction function, |
179 | void *user_data, |
180 | DBusFreeFunction free_data_function), |
181 | (connection, function, user_data, free_data_function), return) |
182 | DEFINEFUNC(void , dbus_connection_close, (DBusConnection *connection), |
183 | (connection), return) |
184 | DEFINEFUNC(DBusDispatchStatus , dbus_connection_dispatch, (DBusConnection *connection), |
185 | (connection), return) |
186 | DEFINEFUNC(DBusDispatchStatus , dbus_connection_get_dispatch_status, (DBusConnection *connection), |
187 | (connection), return) |
188 | DEFINEFUNC(dbus_bool_t, dbus_connection_get_is_authenticated, (DBusConnection * connection), |
189 | (connection), return ) |
190 | DEFINEFUNC(dbus_bool_t , dbus_connection_get_is_connected, (DBusConnection *connection), |
191 | (connection), return) |
192 | DEFINEFUNC(DBusConnection* , dbus_connection_open_private, (const char *address, |
193 | DBusError *error), |
194 | (address, error), return) |
195 | DEFINEFUNC(DBusConnection* , dbus_connection_ref, (DBusConnection *connection), |
196 | (connection), return) |
197 | DEFINEFUNC(dbus_bool_t , dbus_connection_send, (DBusConnection *connection, |
198 | DBusMessage *message, |
199 | dbus_uint32_t *client_serial), |
200 | (connection, message, client_serial), return) |
201 | DEFINEFUNC(dbus_bool_t , dbus_connection_send_with_reply, (DBusConnection *connection, |
202 | DBusMessage *message, |
203 | DBusPendingCall **pending_return, |
204 | int timeout_milliseconds), |
205 | (connection, message, pending_return, timeout_milliseconds), return) |
206 | DEFINEFUNC(void , dbus_connection_set_exit_on_disconnect, (DBusConnection *connection, |
207 | dbus_bool_t exit_on_disconnect), |
208 | (connection, exit_on_disconnect), ) |
209 | DEFINEFUNC(dbus_bool_t , dbus_connection_set_timeout_functions, (DBusConnection *connection, |
210 | DBusAddTimeoutFunction add_function, |
211 | DBusRemoveTimeoutFunction remove_function, |
212 | DBusTimeoutToggledFunction toggled_function, |
213 | void *data, |
214 | DBusFreeFunction free_data_function), |
215 | (connection, add_function, remove_function, toggled_function, data, free_data_function), return) |
216 | DEFINEFUNC(dbus_bool_t , dbus_connection_set_watch_functions, (DBusConnection *connection, |
217 | DBusAddWatchFunction add_function, |
218 | DBusRemoveWatchFunction remove_function, |
219 | DBusWatchToggledFunction toggled_function, |
220 | void *data, |
221 | DBusFreeFunction free_data_function), |
222 | (connection, add_function, remove_function, toggled_function, data, free_data_function), return) |
223 | DEFINEFUNC(void , dbus_connection_set_wakeup_main_function, (DBusConnection *connection, |
224 | DBusWakeupMainFunction wakeup_main_function, |
225 | void *data, |
226 | DBusFreeFunction free_data_function), |
227 | (connection, wakeup_main_function, data, free_data_function), ) |
228 | DEFINEFUNC(void , dbus_connection_set_dispatch_status_function, (DBusConnection *connection, |
229 | DBusDispatchStatusFunction function, |
230 | void *data, |
231 | DBusFreeFunction free_data_function), |
232 | (connection, function, data, free_data_function), ) |
233 | |
234 | DEFINEFUNC(void , dbus_connection_unref, (DBusConnection *connection), |
235 | (connection), ) |
236 | DEFINEFUNC(dbus_bool_t , dbus_timeout_get_enabled, (DBusTimeout *timeout), |
237 | (timeout), return) |
238 | DEFINEFUNC(int , dbus_timeout_get_interval, (DBusTimeout *timeout), |
239 | (timeout), return) |
240 | DEFINEFUNC(dbus_bool_t , dbus_timeout_handle, (DBusTimeout *timeout), |
241 | (timeout), return) |
242 | |
243 | DEFINEFUNC(dbus_bool_t , dbus_watch_get_enabled, (DBusWatch *watch), |
244 | (watch), return) |
245 | DEFINEFUNC(int , dbus_watch_get_unix_fd, (DBusWatch *watch), |
246 | (watch), return) |
247 | DEFINEFUNC(unsigned int , dbus_watch_get_flags, (DBusWatch *watch), |
248 | (watch), return) |
249 | DEFINEFUNC(dbus_bool_t , dbus_watch_handle, (DBusWatch *watch, |
250 | unsigned int flags), |
251 | (watch, flags), return) |
252 | DEFINEFUNC(void , dbus_connection_set_allow_anonymous, (DBusConnection *connection, |
253 | dbus_bool_t value), |
254 | (connection, value), return) |
255 | |
256 | /* dbus-errors.h */ |
257 | DEFINEFUNC(void , dbus_error_free, (DBusError *error), |
258 | (error), ) |
259 | DEFINEFUNC(void , dbus_error_init, (DBusError *error), |
260 | (error), ) |
261 | DEFINEFUNC(dbus_bool_t , dbus_error_is_set, (const DBusError *error), |
262 | (error), return) |
263 | |
264 | /* dbus-memory.h */ |
265 | DEFINEFUNC(void , dbus_free, (void *memory), (memory), ) |
266 | |
267 | /* dbus-message.h */ |
268 | DEFINEFUNC(DBusMessage* , dbus_message_copy, (const DBusMessage *message), |
269 | (message), return) |
270 | DEFINEFUNC(dbus_bool_t , dbus_message_get_auto_start, (DBusMessage *message), |
271 | (message), return) |
272 | DEFINEFUNC(const char* , dbus_message_get_error_name, (DBusMessage *message), |
273 | (message), return) |
274 | DEFINEFUNC(const char* , dbus_message_get_interface, (DBusMessage *message), |
275 | (message), return) |
276 | DEFINEFUNC(const char* , dbus_message_get_member, (DBusMessage *message), |
277 | (message), return) |
278 | DEFINEFUNC(dbus_bool_t , dbus_message_get_no_reply, (DBusMessage *message), |
279 | (message), return) |
280 | DEFINEFUNC(const char* , dbus_message_get_path, (DBusMessage *message), |
281 | (message), return) |
282 | DEFINEFUNC(const char* , dbus_message_get_sender, (DBusMessage *message), |
283 | (message), return) |
284 | DEFINEFUNC(dbus_uint32_t , dbus_message_get_serial, (DBusMessage *message), |
285 | (message), return) |
286 | DEFINEFUNC(const char* , dbus_message_get_signature, (DBusMessage *message), |
287 | (message), return) |
288 | DEFINEFUNC(int , dbus_message_get_type, (DBusMessage *message), |
289 | (message), return) |
290 | |
291 | #if !defined QT_LINKED_LIBDBUS |
292 | |
293 | DEFINEFUNC_CONDITIONALLY(dbus_bool_t , dbus_message_get_allow_interactive_authorization, (DBusMessage *message), |
294 | (message), return, return false) |
295 | |
296 | #else // defined QT_LINKED_LIBDBUS |
297 | |
298 | static inline dbus_bool_t q_dbus_message_get_allow_interactive_authorization(DBusMessage *message) |
299 | { |
300 | #ifdef DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION |
301 | return dbus_message_get_allow_interactive_authorization(message); |
302 | #else |
303 | Q_UNUSED(message); |
304 | return false; |
305 | #endif |
306 | } |
307 | |
308 | #endif // defined QT_LINKED_LIBDBUS |
309 | |
310 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_append_basic, (DBusMessageIter *iter, |
311 | int type, |
312 | const void *value), |
313 | (iter, type, value), return) |
314 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_append_fixed_array, (DBusMessageIter *iter, |
315 | int element_type, |
316 | const void *value, |
317 | int n_elements), |
318 | (iter, element_type, value, n_elements), return) |
319 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_close_container, (DBusMessageIter *iter, |
320 | DBusMessageIter *sub), |
321 | (iter, sub), return) |
322 | DEFINEFUNC(int , dbus_message_iter_get_arg_type, (DBusMessageIter *iter), |
323 | (iter), return) |
324 | DEFINEFUNC(void , dbus_message_iter_get_basic, (DBusMessageIter *iter, |
325 | void *value), |
326 | (iter, value), ) |
327 | DEFINEFUNC(int , dbus_message_iter_get_element_type, (DBusMessageIter *iter), |
328 | (iter), return) |
329 | DEFINEFUNC(void , dbus_message_iter_get_fixed_array, (DBusMessageIter *iter, |
330 | void *value, |
331 | int *n_elements), |
332 | (iter, value, n_elements), return) |
333 | DEFINEFUNC(char* , dbus_message_iter_get_signature, (DBusMessageIter *iter), |
334 | (iter), return) |
335 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_init, (DBusMessage *message, |
336 | DBusMessageIter *iter), |
337 | (message, iter), return) |
338 | DEFINEFUNC(void , dbus_message_iter_init_append, (DBusMessage *message, |
339 | DBusMessageIter *iter), |
340 | (message, iter), return) |
341 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_next, (DBusMessageIter *iter), |
342 | (iter), return) |
343 | DEFINEFUNC(dbus_bool_t , dbus_message_iter_open_container, (DBusMessageIter *iter, |
344 | int type, |
345 | const char *contained_signature, |
346 | DBusMessageIter *sub), |
347 | (iter, type, contained_signature, sub), return) |
348 | DEFINEFUNC(void , dbus_message_iter_recurse, (DBusMessageIter *iter, |
349 | DBusMessageIter *sub), |
350 | (iter, sub), ) |
351 | DEFINEFUNC(DBusMessage* , dbus_message_new, (int message_type), |
352 | (message_type), return) |
353 | DEFINEFUNC(DBusMessage* , dbus_message_new_method_call, (const char *bus_name, |
354 | const char *path, |
355 | const char *interface, |
356 | const char *method), |
357 | (bus_name, path, interface, method), return) |
358 | DEFINEFUNC(DBusMessage* , dbus_message_new_signal, (const char *path, |
359 | const char *interface, |
360 | const char *name), |
361 | (path, interface, name), return) |
362 | DEFINEFUNC(DBusMessage* , dbus_message_ref, (DBusMessage *message), |
363 | (message), return) |
364 | DEFINEFUNC(void , dbus_message_set_auto_start, (DBusMessage *message, |
365 | dbus_bool_t auto_start), |
366 | (message, auto_start), return) |
367 | DEFINEFUNC(dbus_bool_t , dbus_message_set_destination, (DBusMessage *message, |
368 | const char *destination), |
369 | (message, destination), return) |
370 | DEFINEFUNC(dbus_bool_t , dbus_message_set_error_name, (DBusMessage *message, |
371 | const char *name), |
372 | (message, name), return) |
373 | DEFINEFUNC(void , dbus_message_set_no_reply, (DBusMessage *message, |
374 | dbus_bool_t no_reply), |
375 | (message, no_reply), return) |
376 | DEFINEFUNC(dbus_bool_t , dbus_message_set_path, (DBusMessage *message, |
377 | const char *object_path), |
378 | (message, object_path), return) |
379 | DEFINEFUNC(dbus_bool_t , dbus_message_set_reply_serial, (DBusMessage *message, |
380 | dbus_uint32_t reply_serial), |
381 | (message, reply_serial), return) |
382 | DEFINEFUNC(dbus_bool_t , dbus_message_set_sender, (DBusMessage *message, |
383 | const char *sender), |
384 | (message, sender), return) |
385 | DEFINEFUNC(void , dbus_message_unref, (DBusMessage *message), |
386 | (message), ) |
387 | |
388 | #if !defined QT_LINKED_LIBDBUS |
389 | |
390 | DEFINEFUNC_CONDITIONALLY(void, dbus_message_set_allow_interactive_authorization, |
391 | (DBusMessage *message, dbus_bool_t allow), (message, allow), return, return) |
392 | |
393 | |
394 | #else // defined QT_LINKED_LIBDBUS |
395 | |
396 | static inline void q_dbus_message_set_allow_interactive_authorization(DBusMessage *message, dbus_bool_t allow) |
397 | { |
398 | #ifdef DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION |
399 | dbus_message_set_allow_interactive_authorization(message, allow); |
400 | #else |
401 | Q_UNUSED(message); |
402 | Q_UNUSED(allow); |
403 | #endif |
404 | } |
405 | |
406 | #endif // defined QT_LINKED_LIBDBUS |
407 | |
408 | /* dbus-misc.h */ |
409 | DEFINEFUNC(char* , dbus_get_local_machine_id , (void), (), return) |
410 | |
411 | DEFINEFUNC(void , dbus_get_version , (int *major_version, int *minor_version, int *micro_version) |
412 | , (major_version, minor_version, micro_version) |
413 | , return) |
414 | |
415 | |
416 | /* dbus-pending-call.h */ |
417 | DEFINEFUNC(dbus_bool_t , dbus_pending_call_set_notify, (DBusPendingCall *pending, |
418 | DBusPendingCallNotifyFunction function, |
419 | void *user_data, |
420 | DBusFreeFunction free_user_data), |
421 | (pending, function, user_data, free_user_data), return) |
422 | DEFINEFUNC(void , dbus_pending_call_block, (DBusPendingCall *pending), |
423 | (pending), ) |
424 | DEFINEFUNC(void , dbus_pending_call_cancel, (DBusPendingCall *pending), |
425 | (pending), ) |
426 | DEFINEFUNC(dbus_bool_t , dbus_pending_call_get_completed, (DBusPendingCall *pending), |
427 | (pending), return) |
428 | DEFINEFUNC(DBusMessage* , dbus_pending_call_steal_reply, (DBusPendingCall *pending), |
429 | (pending), return) |
430 | DEFINEFUNC(void , dbus_pending_call_unref, (DBusPendingCall *pending), |
431 | (pending), return) |
432 | |
433 | /* dbus-server.h */ |
434 | DEFINEFUNC(dbus_bool_t , dbus_server_allocate_data_slot, (dbus_int32_t *slot_p), |
435 | (slot_p), return) |
436 | DEFINEFUNC(void , dbus_server_free_data_slot, (dbus_int32_t *slot_p), |
437 | (slot_p), return) |
438 | DEFINEFUNC(void , dbus_server_disconnect, (DBusServer *server), |
439 | (server), ) |
440 | DEFINEFUNC(char* , dbus_server_get_address, (DBusServer *server), |
441 | (server), return) |
442 | DEFINEFUNC(dbus_bool_t , dbus_server_get_is_connected, (DBusServer *server), |
443 | (server), return) |
444 | DEFINEFUNC(DBusServer* , dbus_server_listen, (const char *address, |
445 | DBusError *error), |
446 | (address, error), return) |
447 | DEFINEFUNC(dbus_bool_t , dbus_server_set_data, (DBusServer *server, |
448 | int slot, |
449 | void *data, |
450 | DBusFreeFunction free_data_func), |
451 | (server, slot, data, free_data_func), return) |
452 | DEFINEFUNC(void , dbus_server_set_new_connection_function, (DBusServer *server, |
453 | DBusNewConnectionFunction function, |
454 | void *data, |
455 | DBusFreeFunction free_data_function), |
456 | (server, function, data, free_data_function), ) |
457 | DEFINEFUNC(dbus_bool_t , dbus_server_set_timeout_functions, (DBusServer *server, |
458 | DBusAddTimeoutFunction add_function, |
459 | DBusRemoveTimeoutFunction remove_function, |
460 | DBusTimeoutToggledFunction toggled_function, |
461 | void *data, |
462 | DBusFreeFunction free_data_function), |
463 | (server, add_function, remove_function, toggled_function, data, free_data_function), return) |
464 | DEFINEFUNC(dbus_bool_t , dbus_server_set_watch_functions, (DBusServer *server, |
465 | DBusAddWatchFunction add_function, |
466 | DBusRemoveWatchFunction remove_function, |
467 | DBusWatchToggledFunction toggled_function, |
468 | void *data, |
469 | DBusFreeFunction free_data_function), |
470 | (server, add_function, remove_function, toggled_function, data, free_data_function), return) |
471 | DEFINEFUNC(void , dbus_server_unref, (DBusServer *server), |
472 | (server), ) |
473 | |
474 | /* dbus-thread.h */ |
475 | DEFINEFUNC(dbus_bool_t , dbus_threads_init_default, (), (), return) |
476 | |
477 | QT_END_NAMESPACE |
478 | |
479 | #endif // QT_NO_DBUS |
480 | #endif // QDBUS_SYMBOLS_P_H |
481 | |