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 70 QT_BEGIN_NAMESPACE 71 72 #if !defined QT_LINKED_LIBDBUS 73 74 void (*qdbus_resolve_conditionally(const char *name))(); // doesn't print a warning 75 void (*qdbus_resolve_me(const char *name))(); // prints a warning 76 bool qdbus_loadLibDBus(); 77 78 //# define TRACE_DBUS_CALLS 79 # ifdef TRACE_DBUS_CALLS 80 namespace QtDBusCallTracing { 81 struct TraceDBusCall 82 { 83 struct ThreadData { 84 TraceDBusCall *ptr; 85 int level; 86 bool finishedPrinted; 87 }; 88 tdTraceDBusCall89 static inline ThreadData &td() 90 { 91 static thread_local ThreadData value; 92 return value; 93 } 94 95 ThreadData savedData; 96 QDebug s; TraceDBusCallTraceDBusCall97 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 } ~TraceDBusCallTraceDBusCall110 ~TraceDBusCall() 111 { 112 td() = savedData; 113 } 114 operatorTraceDBusCall115 void operator()() { s << ")"; } operatorTraceDBusCall116 template <typename... Args> void operator()(const char *arg1, Args &&... args) 117 { 118 s << '"' << arg1 << '"'; 119 if (sizeof...(args)) 120 s << ", "; 121 operator()(args...); 122 } operatorTraceDBusCall123 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 }; 131 template <typename T> T operator,(TraceDBusCall &&tc, T &&ret) 132 { 133 tc.s << " = " << ret; 134 return ret; 135 } 136 inline const char *operator,(TraceDBusCall &&tc, const char *ret) 137 { 138 tc.s << " = \"" << ret << '"'; 139 return ret; 140 } 141 142 template <typename T> struct TraceReturn { typedef TraceDBusCall Type; }; 143 template <> 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 179 inline 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 */ 187 DEFINEFUNC(void, dbus_bus_add_match, (DBusConnection *connection, 188 const char *rule, 189 DBusError *error), 190 (connection, rule, error), ) 191 DEFINEFUNC(void, dbus_bus_remove_match, (DBusConnection *connection, 192 const char *rule, 193 DBusError *error), 194 (connection, rule, error), ) 195 DEFINEFUNC(dbus_bool_t, dbus_bus_register,(DBusConnection *connection, 196 DBusError *error), 197 (connection, error), return) 198 DEFINEFUNC(DBusConnection *, dbus_bus_get_private, (DBusBusType type, 199 DBusError *error), 200 (type, error), return) 201 DEFINEFUNC(const char*, dbus_bus_get_unique_name, (DBusConnection *connection), 202 (connection), return) 203 204 /* dbus-connection.h */ 205 DEFINEFUNC(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) 210 DEFINEFUNC(void , dbus_connection_close, (DBusConnection *connection), 211 (connection), return) 212 DEFINEFUNC(DBusDispatchStatus , dbus_connection_dispatch, (DBusConnection *connection), 213 (connection), return) 214 DEFINEFUNC(DBusDispatchStatus , dbus_connection_get_dispatch_status, (DBusConnection *connection), 215 (connection), return) 216 DEFINEFUNC(dbus_bool_t, dbus_connection_get_is_authenticated, (DBusConnection * connection), 217 (connection), return ) 218 DEFINEFUNC(dbus_bool_t , dbus_connection_get_is_connected, (DBusConnection *connection), 219 (connection), return) 220 DEFINEFUNC(DBusConnection* , dbus_connection_open_private, (const char *address, 221 DBusError *error), 222 (address, error), return) 223 DEFINEFUNC(DBusConnection* , dbus_connection_ref, (DBusConnection *connection), 224 (connection), return) 225 DEFINEFUNC(dbus_bool_t , dbus_connection_send, (DBusConnection *connection, 226 DBusMessage *message, 227 dbus_uint32_t *client_serial), 228 (connection, message, client_serial), return) 229 DEFINEFUNC(dbus_bool_t , dbus_connection_send_with_reply, (DBusConnection *connection, 230 DBusMessage *message, 231 DBusPendingCall **pending_return, 232 int timeout_milliseconds), 233 (connection, message, pending_return, timeout_milliseconds), return) 234 DEFINEFUNC(void , dbus_connection_set_exit_on_disconnect, (DBusConnection *connection, 235 dbus_bool_t exit_on_disconnect), 236 (connection, exit_on_disconnect), ) 237 DEFINEFUNC(dbus_bool_t , dbus_connection_set_timeout_functions, (DBusConnection *connection, 238 DBusAddTimeoutFunction add_function, 239 DBusRemoveTimeoutFunction remove_function, 240 DBusTimeoutToggledFunction toggled_function, 241 void *data, 242 DBusFreeFunction free_data_function), 243 (connection, add_function, remove_function, toggled_function, data, free_data_function), return) 244 DEFINEFUNC(dbus_bool_t , dbus_connection_set_watch_functions, (DBusConnection *connection, 245 DBusAddWatchFunction add_function, 246 DBusRemoveWatchFunction remove_function, 247 DBusWatchToggledFunction toggled_function, 248 void *data, 249 DBusFreeFunction free_data_function), 250 (connection, add_function, remove_function, toggled_function, data, free_data_function), return) 251 DEFINEFUNC(void , dbus_connection_set_wakeup_main_function, (DBusConnection *connection, 252 DBusWakeupMainFunction wakeup_main_function, 253 void *data, 254 DBusFreeFunction free_data_function), 255 (connection, wakeup_main_function, data, free_data_function), ) 256 DEFINEFUNC(void , dbus_connection_set_dispatch_status_function, (DBusConnection *connection, 257 DBusDispatchStatusFunction function, 258 void *data, 259 DBusFreeFunction free_data_function), 260 (connection, function, data, free_data_function), ) 261 262 DEFINEFUNC(void , dbus_connection_unref, (DBusConnection *connection), 263 (connection), ) 264 DEFINEFUNC(dbus_bool_t , dbus_timeout_get_enabled, (DBusTimeout *timeout), 265 (timeout), return) 266 DEFINEFUNC(int , dbus_timeout_get_interval, (DBusTimeout *timeout), 267 (timeout), return) 268 DEFINEFUNC(dbus_bool_t , dbus_timeout_handle, (DBusTimeout *timeout), 269 (timeout), return) 270 271 DEFINEFUNC(dbus_bool_t , dbus_watch_get_enabled, (DBusWatch *watch), 272 (watch), return) 273 DEFINEFUNC(int , dbus_watch_get_unix_fd, (DBusWatch *watch), 274 (watch), return) 275 DEFINEFUNC(unsigned int , dbus_watch_get_flags, (DBusWatch *watch), 276 (watch), return) 277 DEFINEFUNC(dbus_bool_t , dbus_watch_handle, (DBusWatch *watch, 278 unsigned int flags), 279 (watch, flags), return) 280 DEFINEFUNC(void , dbus_connection_set_allow_anonymous, (DBusConnection *connection, 281 dbus_bool_t value), 282 (connection, value), return) 283 284 /* dbus-errors.h */ 285 DEFINEFUNC(void , dbus_error_free, (DBusError *error), 286 (error), ) 287 DEFINEFUNC(void , dbus_error_init, (DBusError *error), 288 (error), ) 289 DEFINEFUNC(dbus_bool_t , dbus_error_is_set, (const DBusError *error), 290 (error), return) 291 292 /* dbus-memory.h */ 293 DEFINEFUNC(void , dbus_free, (void *memory), (memory), ) 294 295 /* dbus-message.h */ 296 DEFINEFUNC(DBusMessage* , dbus_message_copy, (const DBusMessage *message), 297 (message), return) 298 DEFINEFUNC(dbus_bool_t , dbus_message_get_auto_start, (DBusMessage *message), 299 (message), return) 300 DEFINEFUNC(const char* , dbus_message_get_error_name, (DBusMessage *message), 301 (message), return) 302 DEFINEFUNC(const char* , dbus_message_get_interface, (DBusMessage *message), 303 (message), return) 304 DEFINEFUNC(const char* , dbus_message_get_member, (DBusMessage *message), 305 (message), return) 306 DEFINEFUNC(dbus_bool_t , dbus_message_get_no_reply, (DBusMessage *message), 307 (message), return) 308 DEFINEFUNC(const char* , dbus_message_get_path, (DBusMessage *message), 309 (message), return) 310 DEFINEFUNC(const char* , dbus_message_get_sender, (DBusMessage *message), 311 (message), return) 312 DEFINEFUNC(dbus_uint32_t , dbus_message_get_serial, (DBusMessage *message), 313 (message), return) 314 DEFINEFUNC(const char* , dbus_message_get_signature, (DBusMessage *message), 315 (message), return) 316 DEFINEFUNC(int , dbus_message_get_type, (DBusMessage *message), 317 (message), return) 318 319 #if !defined QT_LINKED_LIBDBUS 320 321 DEFINEFUNC_CONDITIONALLY(dbus_bool_t , dbus_message_get_allow_interactive_authorization, (DBusMessage *message), 322 (message), return, return false) 323 324 #else // defined QT_LINKED_LIBDBUS 325 326 static inline dbus_bool_t q_dbus_message_get_allow_interactive_authorization(DBusMessage *message) 327 { 328 #ifdef DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 329 return dbus_message_get_allow_interactive_authorization(message); 330 #else 331 Q_UNUSED(message); 332 return false; 333 #endif 334 } 335 336 #endif // defined QT_LINKED_LIBDBUS 337 338 DEFINEFUNC(dbus_bool_t , dbus_message_iter_append_basic, (DBusMessageIter *iter, 339 int type, 340 const void *value), 341 (iter, type, value), return) 342 DEFINEFUNC(dbus_bool_t , dbus_message_iter_append_fixed_array, (DBusMessageIter *iter, 343 int element_type, 344 const void *value, 345 int n_elements), 346 (iter, element_type, value, n_elements), return) 347 DEFINEFUNC(dbus_bool_t , dbus_message_iter_close_container, (DBusMessageIter *iter, 348 DBusMessageIter *sub), 349 (iter, sub), return) 350 DEFINEFUNC(int , dbus_message_iter_get_arg_type, (DBusMessageIter *iter), 351 (iter), return) 352 DEFINEFUNC(void , dbus_message_iter_get_basic, (DBusMessageIter *iter, 353 void *value), 354 (iter, value), ) 355 DEFINEFUNC(int , dbus_message_iter_get_element_type, (DBusMessageIter *iter), 356 (iter), return) 357 DEFINEFUNC(void , dbus_message_iter_get_fixed_array, (DBusMessageIter *iter, 358 void *value, 359 int *n_elements), 360 (iter, value, n_elements), return) 361 DEFINEFUNC(char* , dbus_message_iter_get_signature, (DBusMessageIter *iter), 362 (iter), return) 363 DEFINEFUNC(dbus_bool_t , dbus_message_iter_init, (DBusMessage *message, 364 DBusMessageIter *iter), 365 (message, iter), return) 366 DEFINEFUNC(void , dbus_message_iter_init_append, (DBusMessage *message, 367 DBusMessageIter *iter), 368 (message, iter), return) 369 DEFINEFUNC(dbus_bool_t , dbus_message_iter_next, (DBusMessageIter *iter), 370 (iter), return) 371 DEFINEFUNC(dbus_bool_t , dbus_message_iter_open_container, (DBusMessageIter *iter, 372 int type, 373 const char *contained_signature, 374 DBusMessageIter *sub), 375 (iter, type, contained_signature, sub), return) 376 DEFINEFUNC(void , dbus_message_iter_recurse, (DBusMessageIter *iter, 377 DBusMessageIter *sub), 378 (iter, sub), ) 379 DEFINEFUNC(DBusMessage* , dbus_message_new, (int message_type), 380 (message_type), return) 381 DEFINEFUNC(DBusMessage* , dbus_message_new_method_call, (const char *bus_name, 382 const char *path, 383 const char *interface, 384 const char *method), 385 (bus_name, path, interface, method), return) 386 DEFINEFUNC(DBusMessage* , dbus_message_new_signal, (const char *path, 387 const char *interface, 388 const char *name), 389 (path, interface, name), return) 390 DEFINEFUNC(DBusMessage* , dbus_message_ref, (DBusMessage *message), 391 (message), return) 392 DEFINEFUNC(void , dbus_message_set_auto_start, (DBusMessage *message, 393 dbus_bool_t auto_start), 394 (message, auto_start), return) 395 DEFINEFUNC(dbus_bool_t , dbus_message_set_destination, (DBusMessage *message, 396 const char *destination), 397 (message, destination), return) 398 DEFINEFUNC(dbus_bool_t , dbus_message_set_error_name, (DBusMessage *message, 399 const char *name), 400 (message, name), return) 401 DEFINEFUNC(void , dbus_message_set_no_reply, (DBusMessage *message, 402 dbus_bool_t no_reply), 403 (message, no_reply), return) 404 DEFINEFUNC(dbus_bool_t , dbus_message_set_path, (DBusMessage *message, 405 const char *object_path), 406 (message, object_path), return) 407 DEFINEFUNC(dbus_bool_t , dbus_message_set_reply_serial, (DBusMessage *message, 408 dbus_uint32_t reply_serial), 409 (message, reply_serial), return) 410 DEFINEFUNC(dbus_bool_t , dbus_message_set_sender, (DBusMessage *message, 411 const char *sender), 412 (message, sender), return) 413 DEFINEFUNC(void , dbus_message_unref, (DBusMessage *message), 414 (message), ) 415 416 #if !defined QT_LINKED_LIBDBUS 417 418 DEFINEFUNC_CONDITIONALLY(void, dbus_message_set_allow_interactive_authorization, 419 (DBusMessage *message, dbus_bool_t allow), (message, allow), return, return) 420 421 422 #else // defined QT_LINKED_LIBDBUS 423 424 static inline void q_dbus_message_set_allow_interactive_authorization(DBusMessage *message, dbus_bool_t allow) 425 { 426 #ifdef DBUS_HEADER_FLAG_ALLOW_INTERACTIVE_AUTHORIZATION 427 dbus_message_set_allow_interactive_authorization(message, allow); 428 #else 429 Q_UNUSED(message); 430 Q_UNUSED(allow); 431 #endif 432 } 433 434 #endif // defined QT_LINKED_LIBDBUS 435 436 /* dbus-misc.h */ 437 DEFINEFUNC(char* , dbus_get_local_machine_id , (void), (), return) 438 439 DEFINEFUNC(void , dbus_get_version , (int *major_version, int *minor_version, int *micro_version) 440 , (major_version, minor_version, micro_version) 441 , return) 442 443 444 /* dbus-pending-call.h */ 445 DEFINEFUNC(dbus_bool_t , dbus_pending_call_set_notify, (DBusPendingCall *pending, 446 DBusPendingCallNotifyFunction function, 447 void *user_data, 448 DBusFreeFunction free_user_data), 449 (pending, function, user_data, free_user_data), return) 450 DEFINEFUNC(void , dbus_pending_call_block, (DBusPendingCall *pending), 451 (pending), ) 452 DEFINEFUNC(void , dbus_pending_call_cancel, (DBusPendingCall *pending), 453 (pending), ) 454 DEFINEFUNC(dbus_bool_t , dbus_pending_call_get_completed, (DBusPendingCall *pending), 455 (pending), return) 456 DEFINEFUNC(DBusMessage* , dbus_pending_call_steal_reply, (DBusPendingCall *pending), 457 (pending), return) 458 DEFINEFUNC(void , dbus_pending_call_unref, (DBusPendingCall *pending), 459 (pending), return) 460 461 /* dbus-server.h */ 462 DEFINEFUNC(dbus_bool_t , dbus_server_allocate_data_slot, (dbus_int32_t *slot_p), 463 (slot_p), return) 464 DEFINEFUNC(void , dbus_server_free_data_slot, (dbus_int32_t *slot_p), 465 (slot_p), return) 466 DEFINEFUNC(void , dbus_server_disconnect, (DBusServer *server), 467 (server), ) 468 DEFINEFUNC(char* , dbus_server_get_address, (DBusServer *server), 469 (server), return) 470 DEFINEFUNC(dbus_bool_t , dbus_server_get_is_connected, (DBusServer *server), 471 (server), return) 472 DEFINEFUNC(DBusServer* , dbus_server_listen, (const char *address, 473 DBusError *error), 474 (address, error), return) 475 DEFINEFUNC(dbus_bool_t , dbus_server_set_data, (DBusServer *server, 476 int slot, 477 void *data, 478 DBusFreeFunction free_data_func), 479 (server, slot, data, free_data_func), return) 480 DEFINEFUNC(void , dbus_server_set_new_connection_function, (DBusServer *server, 481 DBusNewConnectionFunction function, 482 void *data, 483 DBusFreeFunction free_data_function), 484 (server, function, data, free_data_function), ) 485 DEFINEFUNC(dbus_bool_t , dbus_server_set_timeout_functions, (DBusServer *server, 486 DBusAddTimeoutFunction add_function, 487 DBusRemoveTimeoutFunction remove_function, 488 DBusTimeoutToggledFunction toggled_function, 489 void *data, 490 DBusFreeFunction free_data_function), 491 (server, add_function, remove_function, toggled_function, data, free_data_function), return) 492 DEFINEFUNC(dbus_bool_t , dbus_server_set_watch_functions, (DBusServer *server, 493 DBusAddWatchFunction add_function, 494 DBusRemoveWatchFunction remove_function, 495 DBusWatchToggledFunction toggled_function, 496 void *data, 497 DBusFreeFunction free_data_function), 498 (server, add_function, remove_function, toggled_function, data, free_data_function), return) 499 DEFINEFUNC(void , dbus_server_unref, (DBusServer *server), 500 (server), ) 501 502 /* dbus-thread.h */ 503 DEFINEFUNC(dbus_bool_t , dbus_threads_init_default, (), (), return) 504 505 QT_END_NAMESPACE 506 507 #endif // QT_NO_DBUS 508 #endif // QDBUS_SYMBOLS_P_H 509