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