summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/CMakeLists.txt18
-rw-r--r--src/dbus/Qt6DBusMacros.cmake58
-rw-r--r--src/dbus/dbus_minimal_p.h6
-rw-r--r--src/dbus/doc/qtdbus.qdocconf7
-rw-r--r--src/dbus/doc/snippets/CMakeLists.txt2
-rw-r--r--src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc2
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp20
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp2
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp4
-rw-r--r--src/dbus/doc/src/dbus-adaptors.qdoc14
-rw-r--r--src/dbus/doc/src/qt6-changes.qdoc2
-rw-r--r--src/dbus/doc/src/qtdbus-cmake.qdoc18
-rw-r--r--src/dbus/doc/src/qtdbus-module.qdoc2
-rw-r--r--src/dbus/doc/src/qtdbus-overview.qdoc3
-rw-r--r--src/dbus/qdbus_symbols.cpp13
-rw-r--r--src/dbus/qdbus_symbols_p.h52
-rw-r--r--src/dbus/qdbusabstractadaptor.cpp36
-rw-r--r--src/dbus/qdbusabstractinterface.cpp60
-rw-r--r--src/dbus/qdbusabstractinterface.h3
-rw-r--r--src/dbus/qdbusabstractinterface_p.h1
-rw-r--r--src/dbus/qdbusargument.cpp60
-rw-r--r--src/dbus/qdbusargument.h26
-rw-r--r--src/dbus/qdbusargument_p.h58
-rw-r--r--src/dbus/qdbusconnection.cpp323
-rw-r--r--src/dbus/qdbusconnection_p.h70
-rw-r--r--src/dbus/qdbusconnectionmanager.cpp334
-rw-r--r--src/dbus/qdbusconnectionmanager_p.h51
-rw-r--r--src/dbus/qdbuserror.cpp6
-rw-r--r--src/dbus/qdbusextratypes.cpp13
-rw-r--r--src/dbus/qdbusextratypes.h5
-rw-r--r--src/dbus/qdbusintegrator.cpp513
-rw-r--r--src/dbus/qdbusintegrator_p.h43
-rw-r--r--src/dbus/qdbusinternalfilters.cpp88
-rw-r--r--src/dbus/qdbusintrospection.cpp23
-rw-r--r--src/dbus/qdbusintrospection_p.h48
-rw-r--r--src/dbus/qdbusmarshaller.cpp21
-rw-r--r--src/dbus/qdbusmessage.cpp126
-rw-r--r--src/dbus/qdbusmessage.h1
-rw-r--r--src/dbus/qdbusmessage_p.h8
-rw-r--r--src/dbus/qdbusmetaobject.cpp110
-rw-r--r--src/dbus/qdbusmetatype.cpp90
-rw-r--r--src/dbus/qdbusmetatype_p.h23
-rw-r--r--src/dbus/qdbusmisc.cpp73
-rw-r--r--src/dbus/qdbuspendingcall.cpp59
-rw-r--r--src/dbus/qdbuspendingcall.h7
-rw-r--r--src/dbus/qdbuspendingcall_p.h3
-rw-r--r--src/dbus/qdbuspendingreply.h2
-rw-r--r--src/dbus/qdbusreply.cpp6
-rw-r--r--src/dbus/qdbusserver.cpp53
-rw-r--r--src/dbus/qdbusserver.h1
-rw-r--r--src/dbus/qdbusservicewatcher.cpp77
-rw-r--r--src/dbus/qdbusthreaddebug_p.h4
-rw-r--r--src/dbus/qdbusutil.cpp78
-rw-r--r--src/dbus/qdbusutil_p.h2
-rw-r--r--src/dbus/qdbusxmlgenerator.cpp54
-rw-r--r--src/dbus/qdbusxmlparser.cpp367
-rw-r--r--src/dbus/qdbusxmlparser_p.h21
-rw-r--r--src/dbus/qt_attribution.json6
58 files changed, 1777 insertions, 1399 deletions
diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt
index a9634e0f96..9c3f6d23d2 100644
--- a/src/dbus/CMakeLists.txt
+++ b/src/dbus/CMakeLists.txt
@@ -1,7 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
-
-# Generated from dbus.pro.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## DBus Module:
@@ -17,7 +15,7 @@ qt_internal_add_module(DBus
qdbusargument.cpp qdbusargument.h qdbusargument_p.h
qdbusconnection.cpp qdbusconnection.h qdbusconnection_p.h
qdbusconnectioninterface.cpp qdbusconnectioninterface.h
- qdbusconnectionmanager_p.h
+ qdbusconnectionmanager.cpp qdbusconnectionmanager_p.h
qdbuscontext.cpp qdbuscontext.h qdbuscontext_p.h
qdbuserror.cpp qdbuserror.h
qdbusextratypes.cpp qdbusextratypes.h
@@ -42,9 +40,14 @@ qt_internal_add_module(DBus
qdbusxmlgenerator.cpp
qdbusxmlparser.cpp qdbusxmlparser_p.h
qtdbusglobal.h qtdbusglobal_p.h
+ NO_UNITY_BUILD_SOURCES
+ qdbusconnectionmanager.cpp # qt_windows.h clashing with "interface"
DEFINES
DBUS_API_SUBJECT_TO_CHANGE
+ QT_NO_CONTEXTLESS_CONNECT
QT_NO_FOREACH
+ QT_NO_QPAIR
+ QT_USE_NODISCARD_FILE_OPEN
LIBRARIES
Qt::CorePrivate
PUBLIC_LIBRARIES
@@ -54,11 +57,9 @@ qt_internal_add_module(DBus
GENERATE_CPP_EXPORTS
)
+# This file is included by qdbusargument.cpp
set_source_files_properties(qdbusmarshaller.cpp
- PROPERTIES HEADER_FILE_ONLY ON) # special case: This file is included by qdbusargument.cpp
-
-#### Keys ignored in scope 1:.:.:dbus.pro:<TRUE>:
-# MODULE_CONFIG = "dbusadaptors" "dbusinterfaces"
+ PROPERTIES HEADER_FILE_ONLY ON)
## Scopes:
#####################################################################
@@ -80,4 +81,3 @@ qt_internal_extend_target(DBus CONDITION WIN32
qt_internal_add_docs(DBus
doc/qtdbus.qdocconf
)
-
diff --git a/src/dbus/Qt6DBusMacros.cmake b/src/dbus/Qt6DBusMacros.cmake
index df5bdd6d29..57a4a0735e 100644
--- a/src/dbus/Qt6DBusMacros.cmake
+++ b/src/dbus/Qt6DBusMacros.cmake
@@ -1,16 +1,20 @@
# Copyright 2005-2011 Kitware, Inc.
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+# SPDX-License-Identifier: BSD-3-Clause
include(MacroAddFileDependencies)
-include(CMakeParseArguments)
-
-function(qt6_add_dbus_interface _sources _interface _basename)
+function(qt6_add_dbus_interface _sources _interface _relativename)
get_filename_component(_infile ${_interface} ABSOLUTE)
- set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
- set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
- set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
+ get_filename_component(_basepath ${_relativename} DIRECTORY)
+ get_filename_component(_basename ${_relativename} NAME)
+ set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.h")
+ set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.cpp")
+ if(_basepath)
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/moc_${_basename}.cpp")
+ else()
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp")
+ endif()
get_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
if(_nonamespace)
@@ -30,7 +34,7 @@ function(qt6_add_dbus_interface _sources _interface _basename)
endif()
add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp ${_params} -p ${_basename} ${_infile}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp ${_params} -p ${_relativename} ${_infile}
DEPENDS ${_infile} ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml
VERBATIM
)
@@ -42,7 +46,7 @@ function(qt6_add_dbus_interface _sources _interface _basename)
qt6_generate_moc("${_header}" "${_moc}")
- list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
+ list(APPEND ${_sources} "${_impl}" "${_header}")
macro_add_file_dependencies("${_impl}" "${_moc}")
set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()
@@ -52,14 +56,14 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
# arguments, so we can preserve them exactly. As an added bonus, if the
# caller doesn't provide enough arguments, they will get an error message
# for their call site instead of here in the wrapper.
- function(qt_add_dbus_interface sources interface basename)
+ function(qt_add_dbus_interface sources interface relativename)
if(ARGC GREATER 3)
message(FATAL_ERROR "Unexpected arguments: ${ARGN}")
endif()
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
- qt5_add_dbus_interface("${sources}" "${interface}" "${basename}")
+ qt5_add_dbus_interface("${sources}" "${interface}" "${relativename}")
elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
- qt6_add_dbus_interface("${sources}" "${interface}" "${basename}")
+ qt6_add_dbus_interface("${sources}" "${interface}" "${relativename}")
endif()
set("${sources}" "${${sources}}" PARENT_SCOPE)
endfunction()
@@ -136,7 +140,7 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
endif()
-function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClass _optionalBasename _optionalClassName)
+function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClass _optionalRelativename _optionalClassName)
get_filename_component(_infile ${_xml_file} ABSOLUTE)
set(_optionalParentClass "${ARGV3}")
@@ -145,28 +149,34 @@ function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClas
set(_parentClass "${_optionalParentClass}")
endif()
- set(_optionalBasename "${ARGV4}")
- if(_optionalBasename)
- set(_basename ${_optionalBasename} )
+ set(_optionalRelativename "${ARGV4}")
+ if(_optionalRelativename)
+ set(_relativename ${_optionalRelativename})
else()
- string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
- string(TOLOWER ${_basename} _basename)
+ string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _relativename ${_infile})
+ string(TOLOWER ${_relativename} _relativename)
endif()
+ get_filename_component(_basepath ${_relativename} DIRECTORY)
+ get_filename_component(_basename ${_relativename} NAME)
set(_optionalClassName "${ARGV5}")
- set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.h")
- set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.cpp")
- set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basename}.moc")
+ set(_header "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.h")
+ set(_impl "${CMAKE_CURRENT_BINARY_DIR}/${_relativename}.cpp")
+ if(_basepath)
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/${_basepath}/moc_${_basename}.cpp")
+ else()
+ set(_moc "${CMAKE_CURRENT_BINARY_DIR}/moc_${_basename}.cpp")
+ endif()
if(_optionalClassName)
add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp -m -a ${_basename} -c ${_optionalClassName} -i ${_include} ${_parentClassOption} ${_parentClass} ${_infile}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp -m -a ${_relativename} -c ${_optionalClassName} -i ${_include} ${_parentClassOption} ${_parentClass} ${_infile}
DEPENDS ${_infile} ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml
VERBATIM
)
else()
add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp -m -a ${_basename} -i ${_include} ${_parentClassOption} ${_parentClass} ${_infile}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp -m -a ${_relativename} -i ${_include} ${_parentClassOption} ${_parentClass} ${_infile}
DEPENDS ${_infile} ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml
VERBATIM
)
@@ -179,7 +189,7 @@ function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClas
)
macro_add_file_dependencies("${_impl}" "${_moc}")
- list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
+ list(APPEND ${_sources} "${_impl}" "${_header}")
set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()
diff --git a/src/dbus/dbus_minimal_p.h b/src/dbus/dbus_minimal_p.h
index 270ff8a4ed..36e7fab55d 100644
--- a/src/dbus/dbus_minimal_p.h
+++ b/src/dbus/dbus_minimal_p.h
@@ -1,5 +1,7 @@
+// Copyright (C) 2002, 2003 CodeFactory AB
+// Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
// Copyright (C) 2016 Intel Corporation.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
#ifndef DBUS_MINIMAL_P_H
#define DBUS_MINIMAL_P_H
@@ -15,6 +17,8 @@
// We mean it.
//
+// These structures are not ours, so ELFVERSION:stop
+
extern "C" {
// Equivalent to dbus-arch-deps.h (generated from dbus-arch-deps.h.in)
diff --git a/src/dbus/doc/qtdbus.qdocconf b/src/dbus/doc/qtdbus.qdocconf
index b23c5fb121..90ee5743ff 100644
--- a/src/dbus/doc/qtdbus.qdocconf
+++ b/src/dbus/doc/qtdbus.qdocconf
@@ -63,9 +63,8 @@ qhp.QtDBus.subprojects.examples.selectors = fake:example
navigation.landingpage = "Qt D-Bus"
navigation.cppclassespage = "Qt D-Bus C++ Classes"
-manifestmeta.thumbnail.names = "QtDBus/D-Bus List Names Example" \
- "QtDBus/D-Bus Ping Pong Example" \
- "QtDBus/D-Bus Complex Ping Pong Example"
+manifestmeta.thumbnail.names = "QtDBus/D-Bus Ping Pong" \
+ "QtDBus/D-Bus Complex Ping Pong"
-# Fail the documentation build if there are more warnings than the limit
+# Enforce zero documentation warnings
warninglimit = 0
diff --git a/src/dbus/doc/snippets/CMakeLists.txt b/src/dbus/doc/snippets/CMakeLists.txt
index 8a196103d9..4b4751d4fa 100644
--- a/src/dbus/doc/snippets/CMakeLists.txt
+++ b/src/dbus/doc/snippets/CMakeLists.txt
@@ -1,5 +1,5 @@
# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#! [cmake_use]
find_package(Qt6 REQUIRED COMPONENTS DBus)
diff --git a/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
index d39151354a..61afa69790 100644
--- a/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
+++ b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
@@ -1,5 +1,5 @@
// Copyright (C) 2016 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
//! [0]
org.freedesktop.DBus
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
index 5348d18ba3..92b9dea909 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
@@ -47,12 +47,22 @@ else
void Abstract_DBus_Interface::asyncCall()
{
//! [1]
-QString value = retrieveValue();
-QDBusPendingCall pcall = interface->asyncCall("Process"_L1, value);
+QDBusPendingCall pcall = interface->asyncCall("GetAPIVersion"_L1);
+auto watcher = new QDBusPendingCallWatcher(pcall, this);
-QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall);
+QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
+ [&](QDBusPendingCallWatcher *w) {
+ QString value = retrieveValue();
+ QDBusPendingReply<int> reply(*w);
+ QDBusPendingCall pcall;
+ if (reply.argumentAt<0>() >= 14)
+ pcall = interface->asyncCall("ProcessWorkUnicode"_L1, value);
+ else
+ pcall = interface->asyncCall("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8());
-QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
- this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
+ w = new QDBusPendingCallWatcher(pcall);
+ QObject::connect(w, &QDBusPendingCallWatcher::finished, this,
+ &Abstract_DBus_Interface::callFinishedSlot);
+});
//! [1]
}
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
index 9e4e26cb4e..75b4394595 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
@@ -37,7 +37,7 @@ QString MyObject::methodWithDelayedReply()
conn = connection();
msg = message();
setDelayedReply(true);
- QMetaObject::invokeMethod(this, "process", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, &MyObject::process, Qt::QueuedConnection);
return QString();
}
//! [0]
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
index c44337ade2..67b019a67d 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
@@ -33,8 +33,8 @@ void DBus_PendingCall_Interface::callInterfaceMain()
QDBusPendingCall async = iface->asyncCall("RemoteMethod", value1, value2);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this);
- QObject::connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)),
- this, SLOT(callFinishedSlot(QDBusPendingCallWatcher*)));
+ QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this,
+ &DBus_PendingCall_Interface::callFinishedSlot);
//! [0]
}
diff --git a/src/dbus/doc/src/dbus-adaptors.qdoc b/src/dbus/doc/src/dbus-adaptors.qdoc
index 3dbedbbcce..e57cc095b9 100644
--- a/src/dbus/doc/src/dbus-adaptors.qdoc
+++ b/src/dbus/doc/src/dbus-adaptors.qdoc
@@ -6,7 +6,7 @@
\title Using Qt D-Bus Adaptors
\brief How to create and use DBus adaptors in Qt.
- \ingroup best-practices
+ \ingroup how-to
Adaptors are special classes that are attached to any QObject-derived class
and provide the interface to the external world using D-Bus. Adaptors are
@@ -44,7 +44,7 @@
\li \l{Declaring Slots in D-Bus Adaptors}
\li \l{Declaring Signals in D-Bus Adaptors}
\li \l{The Qt D-Bus Type System}
- \li In the \l{D-Bus Complex Ping Pong Example}, \c complexpong.h and
+ \li In the \l{D-Bus Complex Ping Pong} example, \c complexpong.h and
\c complexpong.cpp show an implementation of QDBusAbstractAdaptor.
\endlist
@@ -87,15 +87,15 @@
Asynchronous slots are marked by the keyword \l Q_NOREPLY in the method
signature, before the \c void return type and the slot name. The \c quit()
- slot in the \l {D-Bus Complex Ping Pong Example} is an example of this.
+ slot in the \l {D-Bus Complex Ping Pong} example is an example of this.
\section1 Input-Only Slots
Input-only slots are normal slots that take parameters passed by value or
by constant reference. However, unlike asynchronous slots, the caller is
usually waiting for completion of the callee before resuming operation.
- Therefore, non-asynchronous slots should not block or should state it its
- documentation that they may do so.
+ Therefore, non-asynchronous slots should not block or should explicitly
+ state it will block in its documentation that they may do so.
Input-only slots have no special marking in their signature, except that
they take only parameters passed by value or by constant reference.
@@ -193,8 +193,8 @@
However, signals must still be emitted. The easiest way to emit an adaptor
signal is to connect another signal to it, so that Qt's signals and slots
mechanism automatically emits the adaptor signal, too. This can be done in
- the adaptor's constructor, as you can see in the \l {D-Bus Complex Ping
- Pong Example}.
+ the adaptor's constructor, as you can see in the \l {D-Bus Complex Ping Pong}
+ example.
The QDBusAbstractAdaptor::setAutoRelaySignals() convenience function can also
be used to make and break connections between signals in the real object and
diff --git a/src/dbus/doc/src/qt6-changes.qdoc b/src/dbus/doc/src/qt6-changes.qdoc
index c9e73a187a..80cd56c627 100644
--- a/src/dbus/doc/src/qt6-changes.qdoc
+++ b/src/dbus/doc/src/qt6-changes.qdoc
@@ -5,7 +5,7 @@
\page dbus-changes-qt6.html
\title Changes to Qt D-Bus
\ingroup changes-qt-5-to-6
- \brief Migrate Qt DBus to Qt 6.
+ \brief Minimal porting effort to be able to switch to Qt 6.
Qt 6 is a result of the conscious effort to make the framework more
efficient and easy to use.
diff --git a/src/dbus/doc/src/qtdbus-cmake.qdoc b/src/dbus/doc/src/qtdbus-cmake.qdoc
index 227642bfb7..86807af6e5 100644
--- a/src/dbus/doc/src/qtdbus-cmake.qdoc
+++ b/src/dbus/doc/src/qtdbus-cmake.qdoc
@@ -4,6 +4,7 @@
/*!
\group cmake-commands-qtdbus
\title CMake Commands in Qt6 DBus
+\brief Lists CMake commands defined in Qt6::DBus.
The following CMake commands are defined when Qt6::DBus is loaded, for instance
with
@@ -20,7 +21,7 @@ find_package(Qt6 REQUIRED COMPONENTS DBus)
\ingroup cmake-commands-qtdbus
\title qt_add_dbus_interface
-\target qt6_add_dbus_interface
+\keyword qt6_add_dbus_interface
\summary {Generates C++ sources implementing an interface for a D-Bus interface
description file.}
@@ -88,7 +89,7 @@ Options can be set using \c set_source_files_properties on the \c dbus_spec:
\ingroup cmake-commands-qtdbus
\title qt_add_dbus_interfaces
-\target qt6_add_dbus_interfaces
+\keyword qt6_add_dbus_interfaces
\summary {Generates C++ sources implementing interfaces for D-Bus interface
description files.}
@@ -149,7 +150,7 @@ arguments:
\ingroup cmake-commands-qtdbus
\title qt_generate_dbus_interface
-\target qt6_generate_dbus_interface
+\keyword qt6_generate_dbus_interface
\summary {Generates a D-Bus interface from a header file.}
@@ -171,7 +172,7 @@ qt_generate_dbus_interface(header
\section1 Description
Parses the C++ source or header file containing a QObject-derived class
-declaration and generates a file containing the D-BUS Introspection XML.
+declaration and generates a file containing the D-Bus Introspection XML.
By default, the generated XML file is stored in the current binary directory,
and has the same base name as the header. You can specify a different name or
@@ -188,7 +189,7 @@ arguments to the tool can be set after \c{OPTIONS}.
\ingroup cmake-commands-qtdbus
\title qt_add_dbus_adaptor
-\target qt6_add_dbus_adaptor
+\keyword qt6_add_dbus_adaptor
\summary {Generates an adaptor class for a D-Bus interface.}
@@ -246,6 +247,7 @@ argument.
/*!
\group cmake-source-file-properties-qtdbus
\title CMake Source File Properties in Qt6 DBus
+\brief Lists CMake file properties used in Qt6::DBus.
\l{CMake Commands in Qt6 DBus}{CMake Commands} know about the following CMake
source file properties:
@@ -254,7 +256,7 @@ source file properties:
*/
/*!
-\page cmake-source-file-property-CLASSNAME.html
+\page cmake-source-file-property-classname.html
\ingroup cmake-source-file-properties-qtdbus
\title CLASSNAME
@@ -271,7 +273,7 @@ with the provided property value.
*/
/*!
-\page cmake-source-file-property-INCLUDE.html
+\page cmake-source-file-property-include.html
\ingroup cmake-source-file-properties-qtdbus
\title INCLUDE
@@ -288,7 +290,7 @@ to the generated C++ file.
*/
/*!
-\page cmake-source-file-property-NO_NAMESPACE.html
+\page cmake-source-file-property-no-namespace.html
\ingroup cmake-source-file-properties-qtdbus
\title NO_NAMESPACE
diff --git a/src/dbus/doc/src/qtdbus-module.qdoc b/src/dbus/doc/src/qtdbus-module.qdoc
index 03bba6d952..c89b4dc937 100644
--- a/src/dbus/doc/src/qtdbus-module.qdoc
+++ b/src/dbus/doc/src/qtdbus-module.qdoc
@@ -8,7 +8,7 @@
to perform Inter-Process Communication using the \l{Qt D-Bus}{D-Bus} protocol.
\ingroup modules
- \qtcmakepackage Dbus
+ \qtcmakepackage DBus
\qtvariable dbus
\keyword The QDBus compiler
diff --git a/src/dbus/doc/src/qtdbus-overview.qdoc b/src/dbus/doc/src/qtdbus-overview.qdoc
index b40caf24a6..6342e674fd 100644
--- a/src/dbus/doc/src/qtdbus-overview.qdoc
+++ b/src/dbus/doc/src/qtdbus-overview.qdoc
@@ -5,6 +5,7 @@
\page qtdbus-overview.html
\title Qt D-Bus Overview
\brief Provides insight into the Qt Qt D-Bus module.
+ \ingroup explanations-networkingandconnectivity
D-Bus is an Inter-Process Communication (IPC) and Remote Procedure
Calling (RPC) mechanism originally developed for Linux to replace
@@ -164,7 +165,7 @@
This feature can be enabled on a per-application basis by setting the
\c QDBUS_DEBUG environment variable before running each application.
For example, we can enable debugging only for the car in the
- \l{D-Bus Remote Controlled Car Example} by running the controller and the
+ \l{D-Bus Remote Controlled Car} example by running the controller and the
car in the following way:
\snippet code/doc_src_introtodbus.qdoc QDBUS_DEBUG
diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp
index 9b1ccfd7c1..9788bb98bc 100644
--- a/src/dbus/qdbus_symbols.cpp
+++ b/src/dbus/qdbus_symbols.cpp
@@ -2,7 +2,8 @@
// Copyright (C) 2016 Intel Corporation.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
-#include <QtCore/qglobal.h>
+#include "qdbus_symbols_p.h"
+#include <QtCore/qlatin1stringview.h>
#if QT_CONFIG(library)
#include <QtCore/qlibrary.h>
#include <QtCore/private/qlocking_p.h>
@@ -11,14 +12,10 @@
#ifndef QT_NO_DBUS
-extern "C" void dbus_shutdown();
-
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
-void (*qdbus_resolve_me(const char *name))();
-
#if !defined QT_LINKED_LIBDBUS
#if QT_CONFIG(library)
@@ -57,7 +54,7 @@ bool qdbus_loadLibDBus()
lib->setLoadHints(QLibrary::ExportExternalSymbolsHint); // make libdbus symbols available for apps that need more advanced control over the dbus
triedToLoadLibrary = true;
- static int majorversions[] = { 3, 2, -1 };
+ static constexpr int majorversions[] = { 3, 2, -1 };
const QString baseNames[] = {
#ifdef Q_OS_WIN
"dbus-1"_L1,
@@ -91,7 +88,7 @@ bool qdbus_loadLibDBus()
#endif
}
-void (*qdbus_resolve_conditionally(const char *name))()
+QFunctionPointer qdbus_resolve_conditionally(const char *name)
{
#if QT_CONFIG(library)
if (qdbus_loadLibDBus())
@@ -102,7 +99,7 @@ void (*qdbus_resolve_conditionally(const char *name))()
return nullptr;
}
-void (*qdbus_resolve_me(const char *name))()
+QFunctionPointer qdbus_resolve_me(const char *name)
{
#if QT_CONFIG(library)
if (Q_UNLIKELY(!qdbus_loadLibDBus()))
diff --git a/src/dbus/qdbus_symbols_p.h b/src/dbus/qdbus_symbols_p.h
index e3008be761..78b7e049ef 100644
--- a/src/dbus/qdbus_symbols_p.h
+++ b/src/dbus/qdbus_symbols_p.h
@@ -27,6 +27,8 @@
# include "dbus_minimal_p.h"
#endif
+#include <atomic>
+
#ifdef interface
# undef interface
#endif
@@ -35,8 +37,8 @@ QT_BEGIN_NAMESPACE
#if !defined QT_LINKED_LIBDBUS
-void (*qdbus_resolve_conditionally(const char *name))(); // doesn't print a warning
-void (*qdbus_resolve_me(const char *name))(); // prints a warning
+QFunctionPointer qdbus_resolve_conditionally(const char *name); // doesn't print a warning
+QFunctionPointer qdbus_resolve_me(const char *name); // prints a warning
bool qdbus_loadLibDBus();
//# define TRACE_DBUS_CALLS
@@ -114,28 +116,34 @@ template <> struct TraceReturn<void> { typedef void Type; };
# define DEBUGRET(ret)
# endif
-# define DEFINEFUNC(ret, func, args, argcall, funcret) \
- typedef ret (* _q_PTR_##func) args; \
- static inline ret q_##func args \
- { \
- static _q_PTR_##func ptr; \
- DEBUGCALL(#func, argcall); \
- if (!ptr) \
- ptr = (_q_PTR_##func) qdbus_resolve_me(#func); \
- funcret DEBUGRET(ret) ptr argcall; \
+# define DEFINEFUNC(ret, func, args, argcall, funcret) \
+ static inline ret q_##func args \
+ { \
+ using func_ptr = ret (*) args; \
+ static std::atomic<func_ptr> atomic_ptr; \
+ func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \
+ DEBUGCALL(#func, argcall); \
+ if (!ptr) { \
+ ptr = reinterpret_cast<func_ptr>(qdbus_resolve_me(#func)); \
+ atomic_ptr.store(ptr, std::memory_order_relaxed); \
+ } \
+ funcret DEBUGRET(ret) ptr argcall; \
}
-# define DEFINEFUNC_CONDITIONALLY(ret, func, args, argcall, funcret, failret) \
- typedef ret (* _q_PTR_##func) args; \
- static inline ret q_##func args \
- { \
- static _q_PTR_##func ptr; \
- DEBUGCALL(#func, argcall); \
- if (!ptr) \
- ptr = (_q_PTR_##func) qdbus_resolve_conditionally(#func); \
- if (!ptr) \
- failret; \
- funcret DEBUGRET(ret) ptr argcall; \
+# define DEFINEFUNC_CONDITIONALLY(ret, func, args, argcall, funcret, failret) \
+ static inline ret q_##func args \
+ { \
+ using func_ptr = ret (*) args; \
+ static std::atomic<func_ptr> atomic_ptr; \
+ func_ptr ptr = atomic_ptr.load(std::memory_order_relaxed); \
+ DEBUGCALL(#func, argcall); \
+ if (!ptr) { \
+ ptr = reinterpret_cast<func_ptr>(qdbus_resolve_conditionally(#func)); \
+ atomic_ptr.store(ptr, std::memory_order_relaxed); \
+ } \
+ if (!ptr) \
+ failret; \
+ funcret DEBUGRET(ret) ptr argcall; \
}
#else // defined QT_LINKED_LIBDBUS
diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp
index a2afc01e9d..afe769fcd0 100644
--- a/src/dbus/qdbusabstractadaptor.cpp
+++ b/src/dbus/qdbusabstractadaptor.cpp
@@ -22,14 +22,10 @@
QT_BEGIN_NAMESPACE
-static int cachedRelaySlotMethodIndex = 0;
-
int QDBusAdaptorConnector::relaySlotMethodIndex()
{
- if (cachedRelaySlotMethodIndex == 0) {
- cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()");
- Q_ASSERT(cachedRelaySlotMethodIndex != 0); // 0 should be deleteLater() or destroyed()
- }
+ static const int cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()");
+ Q_ASSERT(cachedRelaySlotMethodIndex != 0); // 0 should be deleteLater() or destroyed()
return cachedRelaySlotMethodIndex;
}
@@ -37,11 +33,9 @@ QDBusAdaptorConnector *qDBusFindAdaptorConnector(QObject *obj)
{
if (!obj)
return nullptr;
- const QObjectList &children = obj->children();
- QObjectList::ConstIterator it = children.constBegin();
- QObjectList::ConstIterator end = children.constEnd();
- for ( ; it != end; ++it) {
- QDBusAdaptorConnector *connector = qobject_cast<QDBusAdaptorConnector *>(*it);
+
+ for (QObject *child : std::as_const(obj->children())) {
+ QDBusAdaptorConnector *connector = qobject_cast<QDBusAdaptorConnector *>(child);
if (connector) {
connector->polish();
return connector;
@@ -110,10 +104,13 @@ void QDBusAbstractAdaptorPrivate::saveIntrospectionXml(QDBusAbstractAdaptor *ada
QDBusAbstractAdaptor::QDBusAbstractAdaptor(QObject* obj)
: QObject(*new QDBusAbstractAdaptorPrivate, obj)
{
+
+ Q_ASSERT_X(obj, Q_FUNC_INFO, "Expected non-null parent");
+
QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(obj);
connector->waitingForPolish = true;
- QMetaObject::invokeMethod(connector, "polish", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(connector, &QDBusAdaptorConnector::polish, Qt::QueuedConnection);
}
/*!
@@ -227,11 +224,8 @@ void QDBusAdaptorConnector::polish()
return; // avoid working multiple times if multiple adaptors were added
waitingForPolish = false;
- const QObjectList &objs = parent()->children();
- QObjectList::ConstIterator it = objs.constBegin();
- QObjectList::ConstIterator end = objs.constEnd();
- for ( ; it != end; ++it) {
- QDBusAbstractAdaptor *adaptor = qobject_cast<QDBusAbstractAdaptor *>(*it);
+ for (QObject *child : std::as_const(parent()->children())) {
+ QDBusAbstractAdaptor *adaptor = qobject_cast<QDBusAbstractAdaptor *>(child);
if (adaptor)
addAdaptor(adaptor);
}
@@ -260,8 +254,8 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
// QObject signal (destroyed(QObject *)) -- ignore
return;
- const QMetaObject *senderMetaObject = senderObj->metaObject();
- QMetaMethod mm = senderMetaObject->method(lastSignalIdx);
+ QMetaMethod mm = senderObj->metaObject()->method(lastSignalIdx);
+ const QMetaObject *senderMetaObject = mm.enclosingMetaObject();
QObject *realObject = senderObj;
if (qobject_cast<QDBusAbstractAdaptor *>(senderObj))
@@ -279,7 +273,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
qPrintable(errorMsg));
return;
}
- if (inputCount + 1 != types.count() ||
+ if (inputCount + 1 != types.size() ||
types.at(inputCount) == QDBusMetaTypeId::message()) {
// invalid signal signature
qWarning("QDBusAbstractAdaptor: Cannot relay signal %s::%s",
@@ -288,7 +282,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
}
QVariantList args;
- const int numTypes = types.count();
+ const int numTypes = types.size();
args.reserve(numTypes - 1);
for (int i = 1; i < numTypes; ++i)
args << QVariant(QMetaType(types.at(i)), argv[i]);
diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp
index 363ec83cce..0c6dbf1b3b 100644
--- a/src/dbus/qdbusabstractinterface.cpp
+++ b/src/dbus/qdbusabstractinterface.cpp
@@ -79,6 +79,7 @@ QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv
lastError(checkIfValid(serv, p, iface, isDynamic, (connectionPrivate() &&
connectionPrivate()->mode == QDBusConnectionPrivate::PeerMode))),
timeout(-1),
+ interactiveAuthorizationAllowed(false),
isValid(!lastError.isValid())
{
if (!isValid)
@@ -148,8 +149,8 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
return false;
}
if (reply.signature() != "v"_L1) {
- QString errmsg = "Invalid signature `%1' in return from call to "
- DBUS_INTERFACE_PROPERTIES ""_L1;
+ QString errmsg =
+ "Invalid signature '%1' in return from call to " DBUS_INTERFACE_PROPERTIES ""_L1;
lastError = QDBusError(QDBusError::InvalidSignature, std::move(errmsg).arg(reply.signature()));
return false;
}
@@ -185,8 +186,8 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
}
// there was an error...
- const auto errmsg = "Unexpected `%1' (%2) when retrieving property `%3.%4' "
- "(expected type `%5' (%6))"_L1;
+ const auto errmsg = "Unexpected '%1' (%2) when retrieving property '%3.%4' "
+ "(expected type '%5' (%6))"_L1;
lastError = QDBusError(QDBusError::InvalidSignature,
errmsg.arg(QLatin1StringView(foundType),
QLatin1StringView(foundSignature),
@@ -222,7 +223,6 @@ void QDBusAbstractInterfacePrivate::_q_serviceOwnerChanged(const QString &name,
const QString &newOwner)
{
Q_UNUSED(oldOwner);
- Q_UNUSED(name);
//qDebug() << "QDBusAbstractInterfacePrivate serviceOwnerChanged" << name << oldOwner << newOwner;
Q_ASSERT(name == service);
currentOwner = newOwner;
@@ -398,6 +398,43 @@ int QDBusAbstractInterface::timeout() const
}
/*!
+ Configures whether, for asynchronous calls, the caller
+ is prepared to wait for interactive authorization.
+
+ If \a enable is set to \c true, the D-Bus messages generated for
+ asynchronous calls via this interface will set the
+ \c ALLOW_INTERACTIVE_AUTHORIZATION flag.
+
+ This flag is only useful when unprivileged code calls a more privileged
+ method call, and an authorization framework is deployed that allows
+ possibly interactive authorization.
+
+ The default is \c false.
+
+ \since 6.7
+ \sa QDBusMessage::setInteractiveAuthorizationAllowed()
+*/
+void QDBusAbstractInterface::setInteractiveAuthorizationAllowed(bool enable)
+{
+ d_func()->interactiveAuthorizationAllowed = enable;
+}
+
+/*!
+ Returns whether, for asynchronous calls, the caller
+ is prepared to wait for interactive authorization.
+
+ The default is \c false.
+
+ \since 6.7
+ \sa setInteractiveAuthorizationAllowed(),
+ QDBusMessage::setInteractiveAuthorizationAllowed()
+*/
+bool QDBusAbstractInterface::isInteractiveAuthorizationAllowed() const
+{
+ return d_func()->interactiveAuthorizationAllowed;
+}
+
+/*!
Places a call to the remote method specified by \a method on this interface, using \a args as
arguments. This function returns the message that was received as a reply, which can be a normal
QDBusMessage::ReplyMessage (indicating success) or QDBusMessage::ErrorMessage (if the call
@@ -476,6 +513,9 @@ QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode,
Normally, you should place calls using asyncCall().
+ \note Method calls to objects registered by the application itself are never
+ asynchronous due to implementation limitations.
+
\threadsafe
*/
QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString& method,
@@ -489,6 +529,8 @@ QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString
QDBusMessage msg = QDBusMessage::createMethodCall(service(), path(), interface(), method);
QDBusMessagePrivate::setParametersValidated(msg, true);
msg.setArguments(args);
+ if (d->interactiveAuthorizationAllowed)
+ msg.setInteractiveAuthorizationAllowed(true);
return d->connection.asyncCall(msg, d->timeout);
}
@@ -510,6 +552,9 @@ QDBusPendingCall QDBusAbstractInterface::asyncCallWithArgumentList(const QString
parameter as its last or only parameter. The \a errorMethod must
have a QDBusError as its only parameter.
+ \note Method calls to objects registered by the application itself are never
+ asynchronous due to implementation limitations.
+
\since 4.3
\sa QDBusError, QDBusMessage
*/
@@ -677,6 +722,7 @@ void QDBusAbstractInterface::internalPropSet(const char *propname, const QVarian
This example illustrates function calling with 0, 1 and 2 parameters and illustrates different
parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one
Unicode string, the second call to \c "ProcessWork" will contain one string and one byte array).
+ See asyncCall() for the same example in non-blocking (asynchronous) calls.
\note Before Qt 5.14, this function accepted a maximum of just eight (8) arguments.
@@ -734,9 +780,13 @@ void QDBusAbstractInterface::internalPropSet(const char *propname, const QVarian
This example illustrates function calling with 0, 1 and 2 parameters and illustrates different
parameter types passed in each (the first call to \c "ProcessWorkUnicode" will contain one
Unicode string, the second call to \c "ProcessWork" will contain one string and one byte array).
+ See call() for the same example in blocking (synchronous) calls.
\note Before Qt 5.14, this function accepted a maximum of just eight (8) arguments.
+ \note Method calls to local \c{QDBusServer}'s are never asynchronous
+ due to implementation limitations.
+
\sa asyncCallWithArgumentList()
*/
diff --git a/src/dbus/qdbusabstractinterface.h b/src/dbus/qdbusabstractinterface.h
index a87b377b0c..8d36fb3728 100644
--- a/src/dbus/qdbusabstractinterface.h
+++ b/src/dbus/qdbusabstractinterface.h
@@ -63,6 +63,9 @@ public:
void setTimeout(int timeout);
int timeout() const;
+ void setInteractiveAuthorizationAllowed(bool enable);
+ bool isInteractiveAuthorizationAllowed() const;
+
QDBusMessage call(const QString &method)
{
return doCall(QDBus::AutoDetect, method, nullptr, 0);
diff --git a/src/dbus/qdbusabstractinterface_p.h b/src/dbus/qdbusabstractinterface_p.h
index 531be7471c..1bd5e96f2d 100644
--- a/src/dbus/qdbusabstractinterface_p.h
+++ b/src/dbus/qdbusabstractinterface_p.h
@@ -42,6 +42,7 @@ public:
QString interface;
mutable QDBusError lastError;
int timeout;
+ bool interactiveAuthorizationAllowed;
// this is set during creation and never changed
// it can't be const because QDBusInterfacePrivate has one more check
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp
index 86ce83b324..99e60244da 100644
--- a/src/dbus/qdbusargument.cpp
+++ b/src/dbus/qdbusargument.cpp
@@ -6,14 +6,15 @@
#include <qatomic.h>
#include <qbytearray.h>
+#include <qdatetime.h>
+#include <qline.h>
#include <qlist.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
-#include <qvariant.h>
-#include <qdatetime.h>
#include <qrect.h>
-#include <qline.h>
+#include <qtimezone.h>
+#include <qvariant.h>
#include "qdbusmetatype_p.h"
#include "qdbusutil_p.h"
@@ -30,17 +31,17 @@ QDBusArgumentPrivate::~QDBusArgumentPrivate()
q_dbus_message_unref(message);
}
-QByteArray QDBusArgumentPrivate::createSignature(int id)
+QByteArray QDBusArgumentPrivate::createSignature(QMetaType type)
{
if (!qdbus_loadLibDBus())
return "";
QByteArray signature;
- QDBusMarshaller *marshaller = new QDBusMarshaller(0);
+ QDBusMarshaller *marshaller = new QDBusMarshaller;
marshaller->ba = &signature;
// run it
- QVariant v{QMetaType(id)};
+ QVariant v{type};
QDBusArgument arg(marshaller);
QDBusMetaType::marshall(arg, v.metaType(), v.constData());
arg.d = nullptr;
@@ -50,18 +51,16 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
delete marshaller;
if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) {
- qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' "
+ qWarning("QDBusMarshaller: type '%s' produces invalid D-Bus signature '%s' "
"(Did you forget to call beginStructure() ?)",
- QMetaType(id).name(),
- signature.isEmpty() ? "<empty>" : signature.constData());
+ type.name(), signature.isEmpty() ? "<empty>" : signature.constData());
return "";
} else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
(signature.at(0) == DBUS_TYPE_ARRAY && (signature.at(1) == DBUS_TYPE_BYTE ||
signature.at(1) == DBUS_TYPE_STRING))) {
- qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) "
+ qWarning("QDBusMarshaller: type '%s' attempts to redefine basic D-Bus type '%s' (%s) "
"(Did you forget to call beginStructure() ?)",
- QMetaType(id).name(),
- signature.constData(),
+ type.name(), signature.constData(),
QDBusMetaType::signatureToMetaType(signature).name());
return "";
}
@@ -72,7 +71,7 @@ bool QDBusArgumentPrivate::checkWrite(QDBusArgumentPrivate *&d)
{
if (!d)
return false;
- if (d->direction == Marshalling) {
+ if (d->direction == Direction::Marshalling) {
if (!d->marshaller()->ok)
return false;
@@ -100,7 +99,7 @@ bool QDBusArgumentPrivate::checkRead(QDBusArgumentPrivate *d)
{
if (!d)
return false;
- if (d->direction == Demarshalling)
+ if (d->direction == Direction::Demarshalling)
return true;
#ifdef QT_DEBUG
@@ -261,7 +260,7 @@ QDBusArgument::QDBusArgument()
return;
}
- QDBusMarshaller *dd = new QDBusMarshaller(0);
+ QDBusMarshaller *dd = new QDBusMarshaller;
d = dd;
// create a new message with any type, we won't sent it anyways
@@ -538,7 +537,7 @@ QString QDBusArgument::currentSignature() const
{
if (!d)
return QString();
- if (d->direction == QDBusArgumentPrivate::Demarshalling)
+ if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling)
return d->demarshaller()->currentSignature();
else
return d->marshaller()->currentSignature();
@@ -557,14 +556,14 @@ QDBusArgument::ElementType QDBusArgument::currentType() const
{
if (!d)
return UnknownType;
- if (d->direction == QDBusArgumentPrivate::Demarshalling)
+ if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling)
return d->demarshaller()->currentType();
return UnknownType;
}
/*!
- Extracts one D-BUS primitive argument of type \c{BYTE} from the
- D-BUS stream and puts it into \a arg.
+ Extracts one D-Bus primitive argument of type \c{BYTE} from the
+ D-Bus stream and puts it into \a arg.
*/
const QDBusArgument &QDBusArgument::operator>>(uchar &arg) const
{
@@ -1171,12 +1170,33 @@ const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt)
a >> date >> time >> timespec;
a.endStructure();
- dt = QDateTime(date, time, Qt::TimeSpec(timespec));
+ switch (Qt::TimeSpec(timespec)) {
+ case Qt::TimeZone:
+ qWarning("Restoring zoned date-time without zone info");
+ Q_FALLTHROUGH(); // Treat as local time.
+ case Qt::LocalTime:
+ dt = QDateTime(date, time);
+ break;
+ case Qt::OffsetFromUTC:
+ qWarning("Restoring date-time without its offset");
+ Q_FALLTHROUGH(); // Use zero offset
+ case Qt::UTC:
+ dt = QDateTime(date, time, QTimeZone::UTC);
+ break;
+ }
return a;
}
QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt)
{
+ // TODO: Only viable for UTC and LocalTime
+ if (Q_UNLIKELY(dt.timeSpec() != Qt::UTC && dt.timeSpec() != Qt::LocalTime)) {
+ qWarning() << "Serializing a date-time with unsupported time-spec" << dt.timeSpec();
+ // Coerce to a supported timespec. When a time-zone is the current
+ // system zone, local time is suitable; so map all time-zones to local,
+ // plain offsets to UTC.
+ return a << (dt.timeSpec() == Qt::OffsetFromUTC ? dt.toUTC() : dt.toLocalTime());
+ }
a.beginStructure();
a << dt.date() << dt.time() << int(dt.timeSpec());
a.endStructure();
diff --git a/src/dbus/qdbusargument.h b/src/dbus/qdbusargument.h
index 475c47f442..70f6703d2f 100644
--- a/src/dbus/qdbusargument.h
+++ b/src/dbus/qdbusargument.h
@@ -47,7 +47,7 @@ public:
void swap(QDBusArgument &other) noexcept { qt_ptr_swap(d, other.d); }
- // used for marshalling (Qt -> D-BUS)
+ // used for marshalling (Qt -> D-Bus)
QDBusArgument &operator<<(uchar arg);
QDBusArgument &operator<<(bool arg);
QDBusArgument &operator<<(short arg);
@@ -80,7 +80,7 @@ public:
void appendVariant(const QVariant &v);
- // used for de-marshalling (D-BUS -> Qt)
+ // used for de-marshalling (D-Bus -> Qt)
QString currentSignature() const;
ElementType currentType() const;
@@ -222,10 +222,8 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &l
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list)
{
arg.beginArray(QMetaType::fromType<QDBusVariant>());
- QVariantList::ConstIterator it = list.constBegin();
- QVariantList::ConstIterator end = list.constEnd();
- for ( ; it != end; ++it)
- arg << QDBusVariant(*it);
+ for (const QVariant &value : list)
+ arg << QDBusVariant(value);
arg.endArray();
return arg;
}
@@ -284,11 +282,9 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key,
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map)
{
arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>());
- QVariantMap::ConstIterator it = map.constBegin();
- QVariantMap::ConstIterator end = map.constEnd();
- for ( ; it != end; ++it) {
+ for (const auto &[key, value] : map.asKeyValueRange()) {
arg.beginMapEntry();
- arg << it.key() << QDBusVariant(it.value());
+ arg << key << QDBusVariant(value);
arg.endMapEntry();
}
arg.endMap();
@@ -298,11 +294,9 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map)
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map)
{
arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>());
- QVariantHash::ConstIterator it = map.constBegin();
- QVariantHash::ConstIterator end = map.constEnd();
- for ( ; it != end; ++it) {
+ for (const auto &[key, value] : map.asKeyValueRange()) {
arg.beginMapEntry();
- arg << it.key() << QDBusVariant(it.value());
+ arg << key << QDBusVariant(value);
arg.endMapEntry();
}
arg.endMap();
@@ -310,7 +304,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map)
}
template <typename T1, typename T2>
-inline QDBusArgument &operator<<(QDBusArgument &arg, const QPair<T1, T2> &pair)
+inline QDBusArgument &operator<<(QDBusArgument &arg, const std::pair<T1, T2> &pair)
{
arg.beginStructure();
arg << pair.first << pair.second;
@@ -319,7 +313,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QPair<T1, T2> &pair)
}
template <typename T1, typename T2>
-inline const QDBusArgument &operator>>(const QDBusArgument &arg, QPair<T1, T2> &pair)
+inline const QDBusArgument &operator>>(const QDBusArgument &arg, std::pair<T1, T2> &pair)
{
arg.beginStructure();
arg >> pair.first >> pair.second;
diff --git a/src/dbus/qdbusargument_p.h b/src/dbus/qdbusargument_p.h
index 540692cb9e..d9a7382742 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -17,6 +17,7 @@
#include <QtDBus/private/qtdbusglobal_p.h>
#include <qdbusargument.h>
+#include "qdbusconnection.h"
#include "qdbusunixfiledescriptor.h"
#include "qdbus_symbols_p.h"
@@ -33,10 +34,10 @@ class QDBusMarshaller;
class QDBusDemarshaller;
class QDBusArgumentPrivate
{
+ Q_DISABLE_COPY_MOVE(QDBusArgumentPrivate)
public:
- inline QDBusArgumentPrivate(int flags = 0)
- : message(nullptr), ref(1), capabilities(flags)
- { }
+ enum class Direction { Marshalling, Demarshalling };
+
virtual ~QDBusArgumentPrivate();
static bool checkRead(QDBusArgumentPrivate *d);
@@ -46,7 +47,7 @@ public:
QDBusMarshaller *marshaller();
QDBusDemarshaller *demarshaller();
- static QByteArray createSignature(int id);
+ static QByteArray createSignature(QMetaType type);
static inline QDBusArgument create(QDBusArgumentPrivate *d)
{
QDBusArgument q(d);
@@ -55,21 +56,26 @@ public:
static inline QDBusArgumentPrivate *d(QDBusArgument &q)
{ return q.d; }
-public:
- DBusMessage *message;
- QAtomicInt ref;
- int capabilities;
- enum Direction {
- Marshalling,
- Demarshalling
- } direction;
+ DBusMessage *message = nullptr;
+ QAtomicInt ref = 1;
+ QDBusConnection::ConnectionCapabilities capabilities;
+ Direction direction;
+
+protected:
+ explicit QDBusArgumentPrivate(Direction direction,
+ QDBusConnection::ConnectionCapabilities flags = {})
+ : capabilities(flags), direction(direction)
+ {
+ }
};
-class QDBusMarshaller: public QDBusArgumentPrivate
+class QDBusMarshaller final : public QDBusArgumentPrivate
{
public:
- QDBusMarshaller(int flags) : QDBusArgumentPrivate(flags), parent(nullptr), ba(nullptr), closeCode(0), ok(true), skipSignature(false)
- { direction = Marshalling; }
+ explicit QDBusMarshaller(QDBusConnection::ConnectionCapabilities flags = {})
+ : QDBusArgumentPrivate(Direction::Marshalling, flags)
+ {
+ }
~QDBusMarshaller();
QString currentSignature();
@@ -109,25 +115,26 @@ public:
bool appendRegisteredType(const QVariant &arg);
bool appendCrossMarshalling(QDBusDemarshaller *arg);
-public:
DBusMessageIter iterator;
- QDBusMarshaller *parent;
- QByteArray *ba;
+ QDBusMarshaller *parent = nullptr;
+ QByteArray *ba = nullptr;
QString errorString;
- char closeCode;
- bool ok;
- bool skipSignature;
+ char closeCode = 0;
+ bool ok = true;
+ bool skipSignature = false;
private:
Q_DECL_COLD_FUNCTION void unregisteredTypeError(QMetaType t);
Q_DISABLE_COPY_MOVE(QDBusMarshaller)
};
-class QDBusDemarshaller: public QDBusArgumentPrivate
+class QDBusDemarshaller final : public QDBusArgumentPrivate
{
public:
- inline QDBusDemarshaller(int flags) : QDBusArgumentPrivate(flags), parent(nullptr)
- { direction = Demarshalling; }
+ explicit QDBusDemarshaller(QDBusConnection::ConnectionCapabilities flags = {})
+ : QDBusArgumentPrivate(Direction::Demarshalling, flags)
+ {
+ }
~QDBusDemarshaller();
QString currentSignature();
@@ -168,9 +175,8 @@ public:
QDBusArgument::ElementType currentType();
bool isCurrentTypeStringLike();
-public:
DBusMessageIter iterator;
- QDBusDemarshaller *parent;
+ QDBusDemarshaller *parent = nullptr;
private:
Q_DISABLE_COPY_MOVE(QDBusDemarshaller)
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp
index 893125baa0..f6918b70b0 100644
--- a/src/dbus/qdbusconnection.cpp
+++ b/src/dbus/qdbusconnection.cpp
@@ -6,21 +6,14 @@
#include "qdbusconnection_p.h"
#include <qdebug.h>
-#include <qcoreapplication.h>
#include <qstringlist.h>
-#include <qtimer.h>
-#include <qthread.h>
-#include <QtCore/private/qlocking_p.h>
#include "qdbusconnectioninterface.h"
#include "qdbuserror.h"
#include "qdbusmessage.h"
-#include "qdbusmessage_p.h"
-#include "qdbusinterface_p.h"
#include "qdbusutil_p.h"
#include "qdbusconnectionmanager_p.h"
#include "qdbuspendingcall_p.h"
-
#include "qdbusthreaddebug_p.h"
#include <algorithm>
@@ -33,219 +26,6 @@
QT_BEGIN_NAMESPACE
-#ifdef Q_OS_WIN
-static void preventDllUnload();
-#endif
-
-Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager)
-
-QDBusConnectionPrivate *QDBusConnectionManager::busConnection(QDBusConnection::BusType type)
-{
- static_assert(int(QDBusConnection::SessionBus) + int(QDBusConnection::SystemBus) == 1);
- Q_ASSERT(type == QDBusConnection::SessionBus || type == QDBusConnection::SystemBus);
-
- if (!qdbus_loadLibDBus())
- return nullptr;
-
- // we'll start in suspended delivery mode if we're in the main thread
- // (the event loop will resume delivery)
- bool suspendedDelivery = qApp && qApp->thread() == QThread::currentThread();
-
- const auto locker = qt_scoped_lock(defaultBusMutex);
- if (defaultBuses[type])
- return defaultBuses[type];
-
- QString name = QStringLiteral("qt_default_session_bus");
- if (type == QDBusConnection::SystemBus)
- name = QStringLiteral("qt_default_system_bus");
- return defaultBuses[type] = connectToBus(type, name, suspendedDelivery);
-}
-
-QDBusConnectionPrivate *QDBusConnectionManager::connection(const QString &name) const
-{
- return connectionHash.value(name, nullptr);
-}
-
-void QDBusConnectionManager::removeConnection(const QString &name)
-{
- QDBusConnectionPrivate *d = nullptr;
- d = connectionHash.take(name);
- if (d && !d->ref.deref())
- d->deleteLater();
-
- // Static objects may be keeping the connection open.
- // However, it is harmless to have outstanding references to a connection that is
- // closing as long as those references will be soon dropped without being used.
-
- // ### Output a warning if connections are being used after they have been removed.
-}
-
-QDBusConnectionManager::QDBusConnectionManager()
-{
- connect(this, &QDBusConnectionManager::connectionRequested,
- this, &QDBusConnectionManager::executeConnectionRequest, Qt::BlockingQueuedConnection);
- connect(this, &QDBusConnectionManager::serverRequested,
- this, &QDBusConnectionManager::createServer, Qt::BlockingQueuedConnection);
- moveToThread(this); // ugly, don't do this in other projects
-
-#ifdef Q_OS_WIN
- // prevent the library from being unloaded on Windows. See comments in the function.
- preventDllUnload();
-#endif
- defaultBuses[0] = defaultBuses[1] = nullptr;
- start();
-}
-
-QDBusConnectionManager::~QDBusConnectionManager()
-{
- quit();
- wait();
-}
-
-QDBusConnectionManager* QDBusConnectionManager::instance()
-{
- return _q_manager();
-}
-
-Q_DBUS_EXPORT void qDBusBindToApplication();
-void qDBusBindToApplication()
-{
-}
-
-void QDBusConnectionManager::setConnection(const QString &name, QDBusConnectionPrivate *c)
-{
- connectionHash[name] = c;
- c->name = name;
-}
-
-void QDBusConnectionManager::run()
-{
- exec();
-
- // cleanup:
- const auto locker = qt_scoped_lock(mutex);
- for (QHash<QString, QDBusConnectionPrivate *>::const_iterator it = connectionHash.constBegin();
- it != connectionHash.constEnd(); ++it) {
- QDBusConnectionPrivate *d = it.value();
- if (!d->ref.deref()) {
- delete d;
- } else {
- d->closeConnection();
- d->moveToThread(nullptr); // allow it to be deleted in another thread
- }
- }
- connectionHash.clear();
-
- // allow deletion from any thread without warning
- moveToThread(nullptr);
-}
-
-QDBusConnectionPrivate *QDBusConnectionManager::connectToBus(QDBusConnection::BusType type, const QString &name,
- bool suspendedDelivery)
-{
- ConnectionRequestData data;
- data.type = ConnectionRequestData::ConnectToStandardBus;
- data.busType = type;
- data.name = &name;
- data.suspendedDelivery = suspendedDelivery;
-
- emit connectionRequested(&data);
- if (suspendedDelivery && data.result->connection) {
- data.result->ref.ref();
- QDBusConnectionDispatchEnabler *o = new QDBusConnectionDispatchEnabler(data.result);
- QTimer::singleShot(0, o, SLOT(execute()));
- o->moveToThread(qApp->thread()); // qApp was checked in the caller
- }
- return data.result;
-}
-
-QDBusConnectionPrivate *QDBusConnectionManager::connectToBus(const QString &address, const QString &name)
-{
- ConnectionRequestData data;
- data.type = ConnectionRequestData::ConnectToBusByAddress;
- data.busAddress = &address;
- data.name = &name;
- data.suspendedDelivery = false;
-
- emit connectionRequested(&data);
- return data.result;
-}
-
-QDBusConnectionPrivate *QDBusConnectionManager::connectToPeer(const QString &address, const QString &name)
-{
- ConnectionRequestData data;
- data.type = ConnectionRequestData::ConnectToPeerByAddress;
- data.busAddress = &address;
- data.name = &name;
- data.suspendedDelivery = false;
-
- emit connectionRequested(&data);
- return data.result;
-}
-
-void QDBusConnectionManager::executeConnectionRequest(QDBusConnectionManager::ConnectionRequestData *data)
-{
- const auto locker = qt_scoped_lock(mutex);
- const QString &name = *data->name;
- QDBusConnectionPrivate *&d = data->result;
-
- // check if the connection exists by name
- d = connection(name);
- if (d || name.isEmpty())
- return;
-
- d = new QDBusConnectionPrivate;
- DBusConnection *c = nullptr;
- QDBusErrorInternal error;
- switch (data->type) {
- case ConnectionRequestData::ConnectToStandardBus:
- switch (data->busType) {
- case QDBusConnection::SystemBus:
- c = q_dbus_bus_get_private(DBUS_BUS_SYSTEM, error);
- break;
- case QDBusConnection::SessionBus:
- c = q_dbus_bus_get_private(DBUS_BUS_SESSION, error);
- break;
- case QDBusConnection::ActivationBus:
- c = q_dbus_bus_get_private(DBUS_BUS_STARTER, error);
- break;
- }
- break;
-
- case ConnectionRequestData::ConnectToBusByAddress:
- case ConnectionRequestData::ConnectToPeerByAddress:
- c = q_dbus_connection_open_private(data->busAddress->toUtf8().constData(), error);
- if (c && data->type == ConnectionRequestData::ConnectToBusByAddress) {
- // register on the bus
- if (!q_dbus_bus_register(c, error)) {
- q_dbus_connection_unref(c);
- c = nullptr;
- }
- }
- break;
- }
-
- setConnection(name, d);
- if (data->type == ConnectionRequestData::ConnectToPeerByAddress) {
- d->setPeer(c, error);
- } else {
- // create the bus service
- // will lock in QDBusConnectionPrivate::connectRelay()
- d->setConnection(c, error);
- d->createBusService();
- if (c && data->suspendedDelivery)
- d->setDispatchEnabled(false);
- }
-}
-
-void QDBusConnectionManager::createServer(const QString &address, void *server)
-{
- QDBusErrorInternal error;
- QDBusConnectionPrivate *d = new QDBusConnectionPrivate;
- d->setServer(static_cast<QDBusServer *>(server),
- q_dbus_server_listen(address.toUtf8().constData(), error), error);
-}
-
/*!
\class QDBusConnection
\inmodule QtDBus
@@ -370,13 +150,17 @@ void QDBusConnectionManager::createServer(const QString &address, void *server)
*/
QDBusConnection::QDBusConnection(const QString &name)
{
- if (name.isEmpty() || _q_manager.isDestroyed()) {
+ if (name.isEmpty()) {
+ d = nullptr;
+ return;
+ }
+
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager) {
d = nullptr;
} else {
- const auto locker = qt_scoped_lock(_q_manager()->mutex);
- d = _q_manager()->connection(name);
- if (d)
- d->ref.ref();
+ d = manager->existingConnection(name);
}
}
@@ -435,11 +219,13 @@ QDBusConnection &QDBusConnection::operator=(const QDBusConnection &other)
*/
QDBusConnection QDBusConnection::connectToBus(BusType type, const QString &name)
{
- if (_q_manager.isDestroyed() || !qdbus_loadLibDBus()) {
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager || !qdbus_loadLibDBus()) {
QDBusConnectionPrivate *d = nullptr;
return QDBusConnection(d);
}
- return QDBusConnection(_q_manager()->connectToBus(type, name, false));
+ return QDBusConnection(manager->connectToBus(type, name, false));
}
/*!
@@ -449,11 +235,13 @@ QDBusConnection QDBusConnection::connectToBus(BusType type, const QString &name)
QDBusConnection QDBusConnection::connectToBus(const QString &address,
const QString &name)
{
- if (_q_manager.isDestroyed() || !qdbus_loadLibDBus()) {
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager || !qdbus_loadLibDBus()) {
QDBusConnectionPrivate *d = nullptr;
return QDBusConnection(d);
}
- return QDBusConnection(_q_manager()->connectToBus(address, name));
+ return QDBusConnection(manager->connectToBus(address, name));
}
/*!
\since 4.8
@@ -464,11 +252,13 @@ QDBusConnection QDBusConnection::connectToBus(const QString &address,
QDBusConnection QDBusConnection::connectToPeer(const QString &address,
const QString &name)
{
- if (_q_manager.isDestroyed() || !qdbus_loadLibDBus()) {
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager || !qdbus_loadLibDBus()) {
QDBusConnectionPrivate *d = nullptr;
return QDBusConnection(d);
}
- return QDBusConnection(_q_manager()->connectToPeer(address, name));
+ return QDBusConnection(manager->connectToPeer(address, name));
}
/*!
@@ -481,13 +271,11 @@ QDBusConnection QDBusConnection::connectToPeer(const QString &address,
*/
void QDBusConnection::disconnectFromBus(const QString &name)
{
- if (_q_manager()) {
- const auto locker = qt_scoped_lock(_q_manager()->mutex);
- QDBusConnectionPrivate *d = _q_manager()->connection(name);
- if (d && d->mode != QDBusConnectionPrivate::ClientMode)
- return;
- _q_manager()->removeConnection(name);
- }
+ auto *manager = QDBusConnectionManager::instance();
+ if (!manager)
+ return;
+
+ manager->disconnectFrom(name, QDBusConnectionPrivate::ClientMode);
}
/*!
@@ -502,13 +290,11 @@ void QDBusConnection::disconnectFromBus(const QString &name)
*/
void QDBusConnection::disconnectFromPeer(const QString &name)
{
- if (_q_manager()) {
- const auto locker = qt_scoped_lock(_q_manager()->mutex);
- QDBusConnectionPrivate *d = _q_manager()->connection(name);
- if (d && d->mode != QDBusConnectionPrivate::PeerMode)
- return;
- _q_manager()->removeConnection(name);
- }
+ auto *manager = QDBusConnectionManager::instance();
+ if (!manager)
+ return;
+
+ manager->disconnectFrom(name, QDBusConnectionPrivate::PeerMode);
}
/*!
@@ -645,6 +431,9 @@ QDBusMessage QDBusConnection::call(const QDBusMessage &message, QDBus::CallMode
See the QDBusInterface::asyncCall() function for a more friendly way
of placing calls.
+
+ \note Method calls to objects registered by the application itself are never
+ asynchronous due to implementation limitations.
*/
QDBusPendingCall QDBusConnection::asyncCall(const QDBusMessage &message, int timeout) const
{
@@ -862,7 +651,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
QDBusConnectionPrivate::ObjectTreeNode *node = &d->rootNode;
int i = 1;
while (node) {
- if (pathComponents.count() == i) {
+ if (pathComponents.size() == i) {
// this node exists
// consider it free if there's no object here and the user is not trying to
// replace the object sub-tree
@@ -972,7 +761,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
int i = 1;
while (node) {
- if (pathComponents.count() == i)
+ if (pathComponents.size() == i)
return node->obj;
if ((node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath))
return node->obj;
@@ -1128,9 +917,11 @@ bool QDBusConnection::unregisterService(const QString &serviceName)
*/
QDBusConnection QDBusConnection::sessionBus()
{
- if (_q_manager.isDestroyed())
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager)
return QDBusConnection(nullptr);
- return QDBusConnection(_q_manager()->busConnection(SessionBus));
+ return QDBusConnection(manager->busConnection(SessionBus));
}
/*!
@@ -1142,9 +933,11 @@ QDBusConnection QDBusConnection::sessionBus()
*/
QDBusConnection QDBusConnection::systemBus()
{
- if (_q_manager.isDestroyed())
+ auto *manager = QDBusConnectionManager::instance();
+
+ if (!manager)
return QDBusConnection(nullptr);
- return QDBusConnection(_q_manager()->busConnection(SystemBus));
+ return QDBusConnection(manager->busConnection(SystemBus));
}
/*!
@@ -1221,33 +1014,5 @@ QT_END_NAMESPACE
#include "moc_qdbusconnection_p.cpp"
#include "moc_qdbusconnection.cpp"
-#include "moc_qdbusconnectionmanager_p.cpp"
-
-#ifdef Q_OS_WIN
-# include <qt_windows.h>
-
-QT_BEGIN_NAMESPACE
-static void preventDllUnload()
-{
- // Thread termination is really wacky on Windows. For some reason we don't
- // understand, exiting from the thread may try to unload the DLL. Since the
- // QDBusConnectionManager thread runs until the DLL is unloaded, we've got
- // a deadlock: the main thread is waiting for the manager thread to exit,
- // but the manager thread is attempting to acquire a lock to unload the DLL.
- //
- // We work around the issue by preventing the unload from happening in the
- // first place.
- //
- // For this trick, see
- // https://blogs.msdn.microsoft.com/oldnewthing/20131105-00/?p=2733
-
- static HMODULE self;
- GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
- GET_MODULE_HANDLE_EX_FLAG_PIN,
- reinterpret_cast<const wchar_t *>(&self), // any address in this DLL
- &self);
-}
-QT_END_NAMESPACE
-#endif
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h
index 99c1687661..53e6874818 100644
--- a/src/dbus/qdbusconnection_p.h
+++ b/src/dbus/qdbusconnection_p.h
@@ -115,9 +115,11 @@ public:
{
typedef QList<ObjectTreeNode> DataList;
- inline ObjectTreeNode() : obj(nullptr), flags(0) { }
+ inline ObjectTreeNode() : obj(nullptr) { }
inline ObjectTreeNode(const QString &n) // intentionally implicit
- : name(n), obj(nullptr), flags(0) { }
+ : name(n), obj(nullptr)
+ {
+ }
inline bool operator<(const QString &other) const
{ return name < other; }
inline bool operator<(QStringView other) const
@@ -131,12 +133,11 @@ public:
QObject *obj;
QDBusVirtualObject *treeNode;
};
- int flags;
+ QDBusConnection::RegisterOptions flags;
DataList children;
};
-public:
// typedefs
typedef QMultiHash<qintptr, Watcher> WatcherHash;
typedef QHash<int, DBusTimeout *> TimeoutHash;
@@ -157,9 +158,8 @@ public:
};
typedef QHash<QString, WatchedServiceData> WatchedServicesHash;
-public:
// public methods are entry points from other objects
- explicit QDBusConnectionPrivate(QObject *parent = nullptr);
+ QDBusConnectionPrivate();
~QDBusConnectionPrivate();
void createBusService();
@@ -177,7 +177,7 @@ public:
QObject *obj, const char *member);
bool send(const QDBusMessage &message);
- QDBusMessage sendWithReply(const QDBusMessage &message, int mode, int timeout = -1);
+ QDBusMessage sendWithReply(const QDBusMessage &message, QDBus::CallMode mode, int timeout = -1);
QDBusMessage sendWithReplyLocal(const QDBusMessage &message);
QDBusPendingCallPrivate *sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
const char *returnMethod, const char *errorMethod,int timeout = -1);
@@ -212,6 +212,8 @@ public:
void postEventToThread(int action, QObject *target, QEvent *event);
+ void enableDispatchDelayed(QObject *context);
+
private:
void checkThread();
bool handleError(const QDBusErrorInternal &error);
@@ -223,12 +225,13 @@ private:
void activateSignal(const SignalHook& hook, const QDBusMessage &msg);
void activateObject(ObjectTreeNode &node, const QDBusMessage &msg, int pathStartPos);
bool activateInternalFilters(const ObjectTreeNode &node, const QDBusMessage &msg);
- bool activateCall(QObject *object, int flags, const QDBusMessage &msg);
+ bool activateCall(QObject *object, QDBusConnection::RegisterOptions flags,
+ const QDBusMessage &msg);
void sendInternal(QDBusPendingCallPrivate *pcall, void *msg, int timeout);
void sendError(const QDBusMessage &msg, QDBusError::ErrorType code);
- void deliverCall(QObject *object, int flags, const QDBusMessage &msg,
- const QList<QMetaType> &metaTypes, int slotIdx);
+ void deliverCall(QObject *object, const QDBusMessage &msg, const QList<QMetaType> &metaTypes,
+ int slotIdx);
SignalHookHash::Iterator removeSignalHookNoLock(SignalHookHash::Iterator it);
void collectAllObjects(ObjectTreeNode &node, QSet<QObject *> &set);
@@ -239,10 +242,14 @@ private:
void watchForDBusDisconnection();
- void _q_newConnection(QDBusConnectionPrivate *newConnection);
-
void handleAuthentication();
+ bool addSignalHook(const QString &key, const SignalHook &hook);
+ bool removeSignalHook(const QString &key, const SignalHook &hook);
+
+ bool addSignalHookImpl(const QString &key, const SignalHook &hook);
+ bool removeSignalHookImpl(const QString &key, const SignalHook &hook);
+
protected:
void timerEvent(QTimerEvent *e) override;
@@ -254,8 +261,6 @@ public slots:
void socketWrite(qintptr);
void objectDestroyed(QObject *o);
void relaySignal(QObject *obj, const QMetaObject *, int signalId, const QVariantList &args);
- bool addSignalHook(const QString &key, const SignalHook &hook);
- bool removeSignalHook(const QString &key, const SignalHook &hook);
private slots:
void serviceOwnerChangedNoLock(const QString &name, const QString &oldOwner, const QString &newOwner);
@@ -267,11 +272,8 @@ signals:
void dispatchStatusChanged();
void spyHooksFinished(const QDBusMessage &msg);
void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout = -1);
- bool signalNeedsConnecting(const QString &key, const QDBusConnectionPrivate::SignalHook &hook);
- bool signalNeedsDisconnecting(const QString &key, const QDBusConnectionPrivate::SignalHook &hook);
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message);
- void newServerConnection(QDBusConnectionPrivate *newConnection);
public:
QAtomicInt ref;
@@ -314,16 +316,14 @@ public:
bool dispatchEnabled; // protected by the dispatch lock, not the main lock
bool isAuthenticated;
-public:
// static methods
- static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> &params);
+ static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<QMetaType> &params,
+ QString &errorMsg);
static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
- const QString &service,
- const QString &path, const QString &interface, const QString &name,
- const ArgMatchRules &argMatch,
- QObject *receiver, const char *signal, int minMIdx,
- bool buildSignature);
- static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);
+ const QString &service, const QString &path, const QString &interface,
+ const QString &name, const ArgMatchRules &argMatch, QObject *receiver,
+ const char *signal, int minMIdx, bool buildSignature,
+ QString &errorMsg);
static QDBusCallDeliveryEvent *prepareReply(QDBusConnectionPrivate *target, QObject *object,
int idx, const QList<QMetaType> &metaTypes,
const QDBusMessage &msg);
@@ -356,26 +356,6 @@ extern QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNod
extern QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg);
-// can be replaced with a lambda in Qt 5.7
-class QDBusConnectionDispatchEnabler : public QObject
-{
- Q_OBJECT
- QDBusConnectionPrivate *con;
-public:
- QDBusConnectionDispatchEnabler(QDBusConnectionPrivate *con) : con(con) {}
-
-public slots:
- void execute()
- {
- // This call cannot race with something disabling dispatch only because dispatch is
- // never re-disabled from Qt code on an in-use connection once it has been enabled.
- QMetaObject::invokeMethod(con, "setDispatchEnabled", Qt::QueuedConnection, Q_ARG(bool, true));
- if (!con->ref.deref())
- con->deleteLater();
- deleteLater();
- }
-};
-
#endif // QT_BOOTSTRAPPED
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusconnectionmanager.cpp b/src/dbus/qdbusconnectionmanager.cpp
new file mode 100644
index 0000000000..ce52c9fa63
--- /dev/null
+++ b/src/dbus/qdbusconnectionmanager.cpp
@@ -0,0 +1,334 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+
+#include "qdbusconnectionmanager_p.h"
+
+#include <qcoreapplication.h>
+#include <qthread.h>
+#include <qstringlist.h>
+#include <QtCore/private/qlocking_p.h>
+
+#include "qdbuserror.h"
+#include "qdbuspendingcall_p.h"
+#include "qdbusmetatype_p.h"
+
+#ifndef QT_NO_DBUS
+
+QT_BEGIN_NAMESPACE
+
+#ifdef Q_OS_WIN
+static void preventDllUnload();
+#endif
+
+Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager)
+
+QDBusConnectionPrivate *QDBusConnectionManager::busConnection(QDBusConnection::BusType type)
+{
+ static_assert(int(QDBusConnection::SessionBus) + int(QDBusConnection::SystemBus) == 1);
+ Q_ASSERT(type == QDBusConnection::SessionBus || type == QDBusConnection::SystemBus);
+
+ if (!qdbus_loadLibDBus())
+ return nullptr;
+
+ // we'll start in suspended delivery mode if we're in the main thread
+ // (the event loop will resume delivery)
+ bool suspendedDelivery = qApp && qApp->thread() == QThread::currentThread();
+
+ const auto locker = qt_scoped_lock(defaultBusMutex);
+ if (defaultBuses[type])
+ return defaultBuses[type];
+
+ QString name = QStringLiteral("qt_default_session_bus");
+ if (type == QDBusConnection::SystemBus)
+ name = QStringLiteral("qt_default_system_bus");
+ return defaultBuses[type] = connectToBus(type, name, suspendedDelivery);
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::connection(const QString &name) const
+{
+ return connectionHash.value(name, nullptr);
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::existingConnection(const QString &name) const
+{
+ const auto locker = qt_scoped_lock(mutex);
+ auto *conn = connection(name);
+ if (conn)
+ conn->ref.ref();
+ return conn;
+}
+
+void QDBusConnectionManager::removeConnection(const QString &name)
+{
+ QDBusConnectionPrivate *d = nullptr;
+ d = connectionHash.take(name);
+ if (d && !d->ref.deref())
+ d->deleteLater();
+
+ // Static objects may be keeping the connection open.
+ // However, it is harmless to have outstanding references to a connection that is
+ // closing as long as those references will be soon dropped without being used.
+
+ // ### Output a warning if connections are being used after they have been removed.
+}
+
+void QDBusConnectionManager::removeConnections(const QStringList &names)
+{
+ const auto locker = qt_scoped_lock(mutex);
+
+ for (const auto &name : names)
+ removeConnection(name);
+}
+
+void QDBusConnectionManager::disconnectFrom(const QString &name,
+ QDBusConnectionPrivate::ConnectionMode mode)
+{
+ const auto locker = qt_scoped_lock(mutex);
+
+ QDBusConnectionPrivate *d = connection(name);
+ if (d && d->mode != mode)
+ return;
+ removeConnection(name);
+}
+
+QDBusConnectionManager::QDBusConnectionManager()
+{
+ // Ensure that the custom metatype registry is created before the instance
+ // of this class. This will ensure that the registry is not destroyed before
+ // the connection manager at application exit (see also QTBUG-58732). This
+ // works with compilers that use mechanism similar to atexit() to call
+ // destructurs for global statics.
+ QDBusMetaTypeId::init();
+
+ moveToThread(this); // ugly, don't do this in other projects
+
+#ifdef Q_OS_WIN
+ // prevent the library from being unloaded on Windows. See comments in the function.
+ preventDllUnload();
+#endif
+ defaultBuses[0] = defaultBuses[1] = nullptr;
+ start();
+}
+
+QDBusConnectionManager::~QDBusConnectionManager()
+{
+ quit();
+ wait();
+}
+
+QDBusConnectionManager* QDBusConnectionManager::instance()
+{
+ return _q_manager();
+}
+
+Q_DBUS_EXPORT void qDBusBindToApplication();
+void qDBusBindToApplication()
+{
+}
+
+void QDBusConnectionManager::setConnection(const QString &name, QDBusConnectionPrivate *c)
+{
+ connectionHash[name] = c;
+ c->name = name;
+}
+
+void QDBusConnectionManager::addConnection(const QString &name, QDBusConnectionPrivate *c)
+{
+ const auto locker = qt_scoped_lock(mutex);
+ setConnection(name, c);
+}
+
+void QDBusConnectionManager::run()
+{
+ exec();
+
+ // cleanup:
+ const auto locker = qt_scoped_lock(mutex);
+ for (QDBusConnectionPrivate *d : std::as_const(connectionHash)) {
+ if (!d->ref.deref()) {
+ delete d;
+ } else {
+ d->closeConnection();
+ d->moveToThread(nullptr); // allow it to be deleted in another thread
+ }
+ }
+ connectionHash.clear();
+
+ // allow deletion from any thread without warning
+ moveToThread(nullptr);
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::connectToBus(QDBusConnection::BusType type, const QString &name,
+ bool suspendedDelivery)
+{
+ QDBusConnectionPrivate *result = nullptr;
+
+ QMetaObject::invokeMethod(this, &QDBusConnectionManager::doConnectToStandardBus,
+ Qt::BlockingQueuedConnection, qReturnArg(result), type, name,
+ suspendedDelivery);
+
+ if (suspendedDelivery && result && result->connection)
+ result->enableDispatchDelayed(qApp); // qApp was checked in the caller
+
+ return result;
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::connectToBus(const QString &address, const QString &name)
+{
+ QDBusConnectionPrivate *result = nullptr;
+
+ QMetaObject::invokeMethod(this, &QDBusConnectionManager::doConnectToBus,
+ Qt::BlockingQueuedConnection, qReturnArg(result), address, name);
+
+ return result;
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::connectToPeer(const QString &address, const QString &name)
+{
+ QDBusConnectionPrivate *result = nullptr;
+
+ QMetaObject::invokeMethod(this, &QDBusConnectionManager::doConnectToPeer,
+ Qt::BlockingQueuedConnection, qReturnArg(result), address, name);
+
+ return result;
+}
+
+QDBusConnectionPrivate *
+QDBusConnectionManager::doConnectToStandardBus(QDBusConnection::BusType type, const QString &name,
+ bool suspendedDelivery)
+{
+ const auto locker = qt_scoped_lock(mutex);
+
+ // check if the connection exists by name
+ QDBusConnectionPrivate *d = connection(name);
+ if (d || name.isEmpty())
+ return d;
+
+ d = new QDBusConnectionPrivate;
+ DBusConnection *c = nullptr;
+ QDBusErrorInternal error;
+
+ switch (type) {
+ case QDBusConnection::SystemBus:
+ c = q_dbus_bus_get_private(DBUS_BUS_SYSTEM, error);
+ break;
+ case QDBusConnection::SessionBus:
+ c = q_dbus_bus_get_private(DBUS_BUS_SESSION, error);
+ break;
+ case QDBusConnection::ActivationBus:
+ c = q_dbus_bus_get_private(DBUS_BUS_STARTER, error);
+ break;
+ }
+
+ setConnection(name, d);
+
+ // create the bus service
+ // will lock in QDBusConnectionPrivate::connectRelay()
+ d->setConnection(c, error);
+ d->createBusService();
+ if (c && suspendedDelivery)
+ d->setDispatchEnabled(false);
+
+ return d;
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::doConnectToBus(const QString &address,
+ const QString &name)
+{
+ const auto locker = qt_scoped_lock(mutex);
+
+ // check if the connection exists by name
+ QDBusConnectionPrivate *d = connection(name);
+ if (d || name.isEmpty())
+ return d;
+
+ d = new QDBusConnectionPrivate;
+ QDBusErrorInternal error;
+
+ DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
+ if (c) {
+ // register on the bus
+ if (!q_dbus_bus_register(c, error)) {
+ q_dbus_connection_close(c);
+ q_dbus_connection_unref(c);
+ c = nullptr;
+ }
+ }
+
+ setConnection(name, d);
+
+ // create the bus service
+ // will lock in QDBusConnectionPrivate::connectRelay()
+ d->setConnection(c, error);
+ d->createBusService();
+
+ return d;
+}
+
+QDBusConnectionPrivate *QDBusConnectionManager::doConnectToPeer(const QString &address,
+ const QString &name)
+{
+ const auto locker = qt_scoped_lock(mutex);
+
+ // check if the connection exists by name
+ QDBusConnectionPrivate *d = connection(name);
+ if (d || name.isEmpty())
+ return d;
+
+ d = new QDBusConnectionPrivate;
+ QDBusErrorInternal error;
+
+ DBusConnection *c = q_dbus_connection_open_private(address.toUtf8().constData(), error);
+
+ setConnection(name, d);
+ d->setPeer(c, error);
+
+ return d;
+}
+
+void QDBusConnectionManager::createServer(const QString &address, QDBusServer *server)
+{
+ QMetaObject::invokeMethod(
+ this,
+ [&address, server] {
+ QDBusErrorInternal error;
+ QDBusConnectionPrivate *d = new QDBusConnectionPrivate;
+ d->setServer(server, q_dbus_server_listen(address.toUtf8().constData(), error),
+ error);
+ },
+ Qt::BlockingQueuedConnection);
+}
+
+QT_END_NAMESPACE
+
+#include "moc_qdbusconnectionmanager_p.cpp"
+
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+
+QT_BEGIN_NAMESPACE
+static void preventDllUnload()
+{
+ // Thread termination is really wacky on Windows. For some reason we don't
+ // understand, exiting from the thread may try to unload the DLL. Since the
+ // QDBusConnectionManager thread runs until the DLL is unloaded, we've got
+ // a deadlock: the main thread is waiting for the manager thread to exit,
+ // but the manager thread is attempting to acquire a lock to unload the DLL.
+ //
+ // We work around the issue by preventing the unload from happening in the
+ // first place.
+ //
+ // For this trick, see the blog post titled "What is the point of FreeLibraryAndExitThread?"
+ // https://devblogs.microsoft.com/oldnewthing/20131105-00/?p=2733
+
+ static HMODULE self;
+ GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
+ GET_MODULE_HANDLE_EX_FLAG_PIN,
+ reinterpret_cast<const wchar_t *>(&self), // any address in this DLL
+ &self);
+}
+QT_END_NAMESPACE
+#endif
+
+#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusconnectionmanager_p.h b/src/dbus/qdbusconnectionmanager_p.h
index f6a153945a..644c3c8fb1 100644
--- a/src/dbus/qdbusconnectionmanager_p.h
+++ b/src/dbus/qdbusconnectionmanager_p.h
@@ -25,63 +25,46 @@
QT_BEGIN_NAMESPACE
+class QDBusServer;
+
class QDBusConnectionManager : public QDaemonThread
{
Q_OBJECT
- struct ConnectionRequestData;
public:
QDBusConnectionManager();
~QDBusConnectionManager();
static QDBusConnectionManager* instance();
QDBusConnectionPrivate *busConnection(QDBusConnection::BusType type);
- QDBusConnectionPrivate *connection(const QString &name) const;
- void removeConnection(const QString &name);
- void setConnection(const QString &name, QDBusConnectionPrivate *c);
+ QDBusConnectionPrivate *existingConnection(const QString &name) const;
+
+ void removeConnections(const QStringList &names);
+ void disconnectFrom(const QString &name, QDBusConnectionPrivate::ConnectionMode mode);
+ void addConnection(const QString &name, QDBusConnectionPrivate *c);
+
QDBusConnectionPrivate *connectToBus(QDBusConnection::BusType type, const QString &name, bool suspendedDelivery);
QDBusConnectionPrivate *connectToBus(const QString &address, const QString &name);
QDBusConnectionPrivate *connectToPeer(const QString &address, const QString &name);
- mutable QMutex mutex;
-
-signals:
- void connectionRequested(ConnectionRequestData *);
- void serverRequested(const QString &address, void *server);
+ void createServer(const QString &address, QDBusServer *server);
protected:
void run() override;
private:
- void executeConnectionRequest(ConnectionRequestData *data);
- void createServer(const QString &address, void *server);
+ QDBusConnectionPrivate *doConnectToStandardBus(QDBusConnection::BusType type,
+ const QString &name, bool suspendedDelivery);
+ QDBusConnectionPrivate *doConnectToBus(const QString &address, const QString &name);
+ QDBusConnectionPrivate *doConnectToPeer(const QString &address, const QString &name);
+ mutable QMutex mutex;
QHash<QString, QDBusConnectionPrivate *> connectionHash;
+ QDBusConnectionPrivate *connection(const QString &name) const;
+ void removeConnection(const QString &name);
+ void setConnection(const QString &name, QDBusConnectionPrivate *c);
QMutex defaultBusMutex;
QDBusConnectionPrivate *defaultBuses[2];
-
- mutable QMutex senderMutex;
- QString senderName; // internal; will probably change
-};
-
-// TODO: move into own header and use Q_MOC_INCLUDE
-struct QDBusConnectionManager::ConnectionRequestData
-{
- enum RequestType {
- ConnectToStandardBus,
- ConnectToBusByAddress,
- ConnectToPeerByAddress
- } type;
-
- union {
- QDBusConnection::BusType busType;
- const QString *busAddress;
- };
- const QString *name;
-
- QDBusConnectionPrivate *result;
-
- bool suspendedDelivery;
};
QT_END_NAMESPACE
diff --git a/src/dbus/qdbuserror.cpp b/src/dbus/qdbuserror.cpp
index 13feb4c159..49c30e5b25 100644
--- a/src/dbus/qdbuserror.cpp
+++ b/src/dbus/qdbuserror.cpp
@@ -176,7 +176,7 @@ QDBusError::QDBusError(const DBusError *error)
if (!error || !q_dbus_error_is_set(error))
return;
- code = ::get(error->name);
+ code = get(error->name);
msg = QString::fromUtf8(error->message);
nm = QString::fromUtf8(error->name);
}
@@ -191,7 +191,7 @@ QDBusError::QDBusError(const QDBusMessage &qdmsg)
if (qdmsg.type() != QDBusMessage::ErrorMessage)
return;
- code = ::get(qdmsg.errorName().toUtf8().constData());
+ code = get(qdmsg.errorName().toUtf8().constData());
nm = qdmsg.errorName();
msg = qdmsg.errorMessage();
}
@@ -238,7 +238,7 @@ QDBusError &QDBusError::operator=(const QDBusError &other)
QDBusError &QDBusError::operator=(const QDBusMessage &qdmsg)
{
if (qdmsg.type() == QDBusMessage::ErrorMessage) {
- code = ::get(qdmsg.errorName().toUtf8().constData());
+ code = get(qdmsg.errorName().toUtf8().constData());
nm = qdmsg.errorName();
msg = qdmsg.errorMessage();
} else {
diff --git a/src/dbus/qdbusextratypes.cpp b/src/dbus/qdbusextratypes.cpp
index baa33289be..61f2075443 100644
--- a/src/dbus/qdbusextratypes.cpp
+++ b/src/dbus/qdbusextratypes.cpp
@@ -12,6 +12,15 @@ QT_IMPL_METATYPE_EXTERN(QDBusVariant)
QT_IMPL_METATYPE_EXTERN(QDBusObjectPath)
QT_IMPL_METATYPE_EXTERN(QDBusSignature)
+#ifndef QT_NO_DEBUG_STREAM
+QDebug operator<<(QDebug dbg, const QDBusObjectPath &path)
+{
+ QDebugStateSaver saver(dbg);
+ dbg.nospace() << "QDBusObjectPath(" << path.path() << ')';
+ return dbg;
+}
+#endif
+
void QDBusObjectPath::doCheck()
{
if (!QDBusUtil::isValidObjectPath(m_path)) {
@@ -109,7 +118,7 @@ void QDBusSignature::doCheck()
/*!
\fn QDBusObjectPath::QDBusObjectPath(QLatin1StringView path)
- Constructs a new object path from the given \a path.
+ Constructs a new object path from the Latin-1 string viewed by \a path.
*/
/*!
@@ -170,7 +179,7 @@ QDBusObjectPath::operator QVariant() const { return QVariant::fromValue(*this);
/*!
\fn QDBusSignature::QDBusSignature(QLatin1StringView signature)
- Constructs a new signature from the given \a signature.
+ Constructs a new signature from the Latin-1 string viewed by \a signature.
*/
/*!
diff --git a/src/dbus/qdbusextratypes.h b/src/dbus/qdbusextratypes.h
index 03d151f16d..1bc0f3086d 100644
--- a/src/dbus/qdbusextratypes.h
+++ b/src/dbus/qdbusextratypes.h
@@ -4,7 +4,7 @@
#ifndef QDBUSEXTRATYPES_H
#define QDBUSEXTRATYPES_H
-// define some useful types for D-BUS
+// define some useful types for D-Bus
#include <QtDBus/qtdbusglobal.h>
#include <QtCore/qvariant.h>
@@ -69,6 +69,9 @@ inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
inline size_t qHash(const QDBusObjectPath &objectPath, size_t seed = 0)
{ return qHash(objectPath.path(), seed); }
+#ifndef QT_NO_DEBUG_STREAM
+Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusObjectPath &);
+#endif
class Q_DBUS_EXPORT QDBusSignature
{
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index e9b4bd0b1d..836562f496 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -6,7 +6,7 @@
#include <qcoreapplication.h>
#include <qelapsedtimer.h>
-#include <qdebug.h>
+#include <qloggingcategory.h>
#include <qmetaobject.h>
#include <qobject.h>
#include <qsocketnotifier.h>
@@ -50,7 +50,9 @@ QT_IMPL_METATYPE_EXTERN(QDBusSlotCache)
// used with dbus_server_allocate_data_slot
static dbus_int32_t server_slot = -1;
-static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1);
+Q_LOGGING_CATEGORY(dbusIntegration, "qt.dbus.integration", QtWarningMsg)
+
+Q_CONSTINIT static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1);
#define qDBusDebug if (::isDebugging.loadRelaxed() == 0); else qDebug
static inline QDebug operator<<(QDebug dbg, const QThread *th)
@@ -99,7 +101,34 @@ void qdbusDefaultThreadDebug(int action, int condition, QDBusConnectionPrivate *
qdbusThreadDebugFunc qdbusThreadDebug = nullptr;
#endif
-typedef QVarLengthArray<QDBusSpyCallEvent::Hook, 4> QDBusSpyHookList;
+class QDBusSpyHookList
+{
+public:
+ void add(QDBusSpyCallEvent::Hook hook)
+ {
+ const auto locker = qt_scoped_lock(lock);
+ list.append(hook);
+ }
+
+ void invoke(const QDBusMessage &msg)
+ {
+ // Create a copy of the hook list here, so that the hooks can be called
+ // without holding the lock.
+ QList<QDBusSpyCallEvent::Hook> hookListCopy;
+ {
+ const auto locker = qt_scoped_lock(lock);
+ hookListCopy = list;
+ }
+
+ for (auto hook : std::as_const(hookListCopy))
+ hook(msg);
+ }
+
+private:
+ QBasicMutex lock;
+ QList<QDBusSpyCallEvent::Hook> list;
+};
+
Q_GLOBAL_STATIC(QDBusSpyHookList, qDBusSpyHookList)
extern "C" {
@@ -122,8 +151,8 @@ static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data)
Q_ASSERT(d->timeouts.key(timeout, 0) == 0);
- int timerId = d->startTimer(q_dbus_timeout_get_interval(timeout));
- Q_ASSERT_X(timerId, "QDBusConnection", "Failed to start a timer");
+ using namespace std::chrono_literals;
+ int timerId = d->startTimer(q_dbus_timeout_get_interval(timeout) * 1ms); // no overflow possible
if (!timerId)
return false;
@@ -249,7 +278,6 @@ static void qDBusToggleWatch(DBusWatch *watch, void *data)
static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchStatus new_status, void *data)
{
Q_ASSERT(connection);
- Q_UNUSED(connection);
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data);
if (new_status == DBUS_DISPATCH_DATA_REMAINS)
emit d->dispatchStatusChanged();
@@ -259,11 +287,11 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v
{
// ### We may want to separate the server from the QDBusConnectionPrivate
Q_ASSERT(server);
- Q_UNUSED(server);
Q_ASSERT(connection);
Q_ASSERT(data);
- if (!QDBusConnectionManager::instance())
+ auto *manager = QDBusConnectionManager::instance();
+ if (!manager)
return;
// keep the connection alive
@@ -274,35 +302,35 @@ static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, v
if (serverConnection->anonymousAuthenticationAllowed)
q_dbus_connection_set_allow_anonymous(connection, true);
- QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate(serverConnection->parent());
- const auto locker = qt_scoped_lock(QDBusConnectionManager::instance()->mutex);
- QDBusConnectionManager::instance()->setConnection("QDBusServer-"_L1 + QString::number(reinterpret_cast<qulonglong>(newConnection), 16), newConnection);
- serverConnection->serverConnectionNames << newConnection->name;
+ QDBusConnectionPrivate *newConnection = new QDBusConnectionPrivate;
+
+ manager->addConnection(
+ "QDBusServer-"_L1 + QString::number(reinterpret_cast<qulonglong>(newConnection), 16),
+ newConnection);
+ {
+ QWriteLocker locker(&serverConnection->lock);
+ serverConnection->serverConnectionNames << newConnection->name;
+ }
// setPeer does the error handling for us
QDBusErrorInternal error;
newConnection->setPeer(connection, error);
newConnection->setDispatchEnabled(false);
+ QReadLocker serverLock(&serverConnection->lock);
+ if (!serverConnection->serverObject)
+ return;
+
// this is a queued connection and will resume in the QDBusServer's thread
- emit serverConnection->newServerConnection(newConnection);
+ QMetaObject::invokeMethod(serverConnection->serverObject, &QDBusServer::newConnection,
+ Qt::QueuedConnection, QDBusConnectionPrivate::q(newConnection));
// we've disabled dispatching of events, so now we post an event to the
// QDBusServer's thread in order to enable it after the
// QDBusServer::newConnection() signal has been received by the
// application's code
- newConnection->ref.ref();
- QReadLocker serverLock(&serverConnection->lock);
- QDBusConnectionDispatchEnabler *o = new QDBusConnectionDispatchEnabler(newConnection);
- QTimer::singleShot(0, o, SLOT(execute()));
- if (serverConnection->serverObject)
- o->moveToThread(serverConnection->serverObject->thread());
-}
-void QDBusConnectionPrivate::_q_newConnection(QDBusConnectionPrivate *newConnection)
-{
- Q_ASSERT(mode == ServerMode);
- emit serverObject->newConnection(QDBusConnectionPrivate::q(newConnection));
+ newConnection->enableDispatchDelayed(serverConnection->serverObject);
}
} // extern "C"
@@ -327,7 +355,7 @@ static QByteArray buildMatchRule(const QString &service,
// add the argument string-matching now
if (!argMatch.args.isEmpty()) {
const QString keyValue = "arg%1='%2',"_L1;
- for (int i = 0; i < argMatch.args.count(); ++i)
+ for (int i = 0; i < argMatch.args.size(); ++i)
if (!argMatch.args.at(i).isNull())
result += keyValue.arg(i).arg(argMatch.args.at(i));
}
@@ -349,7 +377,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
return root;
}
int start = 0;
- int length = fullpath.length();
+ int length = fullpath.size();
if (fullpath.at(0) == u'/')
start = 1;
@@ -391,7 +419,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
const QString &fullpath, int start)
{
- int length = fullpath.length();
+ int length = fullpath.size();
// any object in the tree can tell us to switch to its own object tree:
const QDBusConnectionPrivate::ObjectTreeNode *node = root;
@@ -407,17 +435,14 @@ static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *ro
pos = (pos == -1 ? length : pos);
auto pathComponent = QStringView{fullpath}.mid(start, pos - start);
- const QObjectList children = obj->children();
-
// find a child with the proper name
QObject *next = nullptr;
- QObjectList::ConstIterator it = children.constBegin();
- QObjectList::ConstIterator end = children.constEnd();
- for ( ; it != end; ++it)
- if ((*it)->objectName() == pathComponent) {
- next = *it;
+ for (QObject *child : std::as_const(obj->children())) {
+ if (child->objectName() == pathComponent) {
+ next = child;
break;
}
+ }
if (!next)
break;
@@ -460,7 +485,11 @@ static QDBusConnectionPrivate::ArgMatchRules matchArgsForService(const QString &
extern Q_DBUS_EXPORT void qDBusAddSpyHook(QDBusSpyCallEvent::Hook);
void qDBusAddSpyHook(QDBusSpyCallEvent::Hook hook)
{
- qDBusSpyHookList()->append(hook);
+ auto *hooks = qDBusSpyHookList();
+ if (!hooks)
+ return;
+
+ hooks->add(hook);
}
QDBusSpyCallEvent::~QDBusSpyCallEvent()
@@ -475,14 +504,15 @@ QDBusSpyCallEvent::~QDBusSpyCallEvent()
void QDBusSpyCallEvent::placeMetaCall(QObject *)
{
- invokeSpyHooks(msg, hooks, hookCount);
+ invokeSpyHooks(msg);
}
-inline void QDBusSpyCallEvent::invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount)
+inline void QDBusSpyCallEvent::invokeSpyHooks(const QDBusMessage &msg)
{
- // call the spy hook list
- for (int i = 0; i < hookCount; ++i)
- hooks[i](msg);
+ if (!qDBusSpyHookList.exists())
+ return;
+
+ qDBusSpyHookList->invoke(msg);
}
extern "C" {
@@ -531,15 +561,14 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg)
// a) if it's a local message, we're in the caller's thread, so invoke the filter directly
// b) if it's an external message, post to the main thread
if (Q_UNLIKELY(qDBusSpyHookList.exists()) && qApp) {
- const QDBusSpyHookList &list = *qDBusSpyHookList;
if (isLocal) {
Q_ASSERT(QThread::currentThread() != thread());
qDBusDebug() << this << "invoking message spies directly";
- QDBusSpyCallEvent::invokeSpyHooks(amsg, list.constData(), list.size());
+ QDBusSpyCallEvent::invokeSpyHooks(amsg);
} else {
qDBusDebug() << this << "invoking message spies via event";
- QCoreApplication::postEvent(qApp, new QDBusSpyCallEvent(this, QDBusConnection(this),
- amsg, list.constData(), list.size()));
+ QCoreApplication::postEvent(
+ qApp, new QDBusSpyCallEvent(this, QDBusConnection(this), amsg));
// we'll be called back, so return
return true;
@@ -559,7 +588,7 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg)
static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack)
{
- for (auto &node : haystack.children)
+ for (QDBusConnectionPrivate::ObjectTreeNode &node : haystack.children)
huntAndDestroy(needle, node);
auto isInactive = [](const QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
@@ -567,7 +596,7 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo
if (needle == haystack.obj) {
haystack.obj = nullptr;
- haystack.flags = 0;
+ haystack.flags = {};
}
}
@@ -575,10 +604,10 @@ static void huntAndUnregister(const QList<QStringView> &pathComponents, int i,
QDBusConnection::UnregisterMode mode,
QDBusConnectionPrivate::ObjectTreeNode *node)
{
- if (pathComponents.count() == i) {
+ if (pathComponents.size() == i) {
// found it
node->obj = nullptr;
- node->flags = 0;
+ node->flags = {};
if (mode == QDBusConnection::UnregisterTree) {
// clear the sub-tree as well
@@ -603,11 +632,11 @@ static void huntAndEmit(DBusConnection *connection, DBusMessage *msg,
QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack,
bool isScriptable, bool isAdaptor, const QString &path = QString())
{
- QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = haystack.children.constBegin();
- QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end = haystack.children.constEnd();
- for ( ; it != end; ++it) {
- if (it->isActive())
- huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + u'/' + it->name);
+ for (const QDBusConnectionPrivate::ObjectTreeNode &node : std::as_const(haystack.children)) {
+ if (node.isActive()) {
+ huntAndEmit(connection, msg, needle, node, isScriptable, isAdaptor,
+ path + u'/' + node.name);
+ }
}
if (needle == haystack.obj) {
@@ -637,6 +666,7 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
const QString &signature_, QList<QMetaType> &metaTypes)
{
QByteArray msgSignature = signature_.toLatin1();
+ QString parametersErrorMsg;
for (int idx = mo->methodCount() - 1 ; idx >= QObject::staticMetaObject.methodCount(); --idx) {
QMetaMethod mm = mo->method(idx);
@@ -663,8 +693,10 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
QString errorMsg;
int inputCount = qDBusParametersForMethod(mm, metaTypes, errorMsg);
- if (inputCount == -1)
+ if (inputCount == -1) {
+ parametersErrorMsg = errorMsg;
continue; // problem parsing
+ }
metaTypes[0] = returnType;
bool hasMessage = false;
@@ -699,14 +731,14 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
continue;
bool ok = true;
- for (int j = i; ok && j < metaTypes.count(); ++j)
+ for (int j = i; ok && j < metaTypes.size(); ++j)
if (QDBusMetaType::typeToSignature(metaTypes.at(i)) == nullptr)
ok = false;
if (!ok)
continue;
// consistency check:
- if (isAsync && metaTypes.count() > i + 1)
+ if (isAsync && metaTypes.size() > i + 1)
continue;
if (mm.methodType() == QMetaMethod::Slot) {
@@ -726,6 +758,13 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
}
// no slot matched
+ if (!parametersErrorMsg.isEmpty()) {
+ qCWarning(dbusIntegration, "QDBusConnection: couldn't handle call to %s: %ls",
+ name.constData(), qUtf16Printable(parametersErrorMsg));
+ } else {
+ qCWarning(dbusIntegration, "QDBusConnection: couldn't handle call to %s, no slot matched",
+ name.constData());
+ }
return -1;
}
@@ -751,13 +790,12 @@ QDBusCallDeliveryEvent *QDBusConnectionPrivate::prepareReply(QDBusConnectionPriv
const QDBusMessage &msg)
{
Q_ASSERT(object);
- Q_UNUSED(object);
- int n = metaTypes.count() - 1;
+ int n = metaTypes.size() - 1;
if (metaTypes[n] == QDBusMetaTypeId::message())
--n;
- if (msg.arguments().count() < n)
+ if (msg.arguments().size() < n)
return nullptr; // too few arguments
// check that types match
@@ -787,14 +825,15 @@ void QDBusConnectionPrivate::activateSignal(const QDBusConnectionPrivate::Signal
if (call == DIRECT_DELIVERY) {
// short-circuit delivery
Q_ASSERT(this == hook.obj);
- deliverCall(this, 0, msg, hook.params, hook.midx);
+ deliverCall(this, msg, hook.params, hook.midx);
return;
}
if (call)
postEventToThread(ActivateSignalAction, hook.obj, call);
}
-bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBusMessage &msg)
+bool QDBusConnectionPrivate::activateCall(QObject *object, QDBusConnection::RegisterOptions flags,
+ const QDBusMessage &msg)
{
// This is called by QDBusConnectionPrivate::handleObjectCall to place a call
// to a slot on the object.
@@ -829,60 +868,59 @@ bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBu
qvariant_cast<QDBusSlotCache>(object->property(cachePropertyName));
QString cacheKey = msg.member(), signature = msg.signature();
if (!signature.isEmpty()) {
- cacheKey.reserve(cacheKey.length() + 1 + signature.length());
+ cacheKey.reserve(cacheKey.size() + 1 + signature.size());
cacheKey += u'.';
cacheKey += signature;
}
- QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(cacheKey);
- while (cacheIt != slotCache.hash.constEnd() && cacheIt->flags != flags &&
- cacheIt.key() == cacheKey)
- ++cacheIt;
- if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey)
- {
+ QDBusSlotCache::Key compoundKey{ std::move(cacheKey), flags };
+ QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(compoundKey);
+ if (cacheIt == slotCache.hash.constEnd()) {
// not cached, analyze the meta object
const QMetaObject *mo = object->metaObject();
QByteArray memberName = msg.member().toUtf8();
// find a slot that matches according to the rules above
QDBusSlotCache::Data slotData;
- slotData.flags = flags;
slotData.slotIdx = ::findSlot(mo, memberName, flags, msg.signature(), slotData.metaTypes);
if (slotData.slotIdx == -1) {
// ### this is where we want to add the connection as an arg too
// try with no parameters, but with a QDBusMessage
slotData.slotIdx = ::findSlot(mo, memberName, flags, QString(), slotData.metaTypes);
- if (slotData.metaTypes.count() != 2 ||
+ if (slotData.metaTypes.size() != 2 ||
slotData.metaTypes.at(1) != QDBusMetaTypeId::message()) {
// not found
// save the negative lookup
slotData.slotIdx = -1;
slotData.metaTypes.clear();
- slotCache.hash.insert(cacheKey, slotData);
+ slotCache.hash.insert(compoundKey, slotData);
object->setProperty(cachePropertyName, QVariant::fromValue(slotCache));
+
+ qCWarning(dbusIntegration).nospace() << "Could not find slot " << mo->className()
+ << "::" << memberName.constData();
return false;
}
}
// save to the cache
- slotCache.hash.insert(cacheKey, slotData);
+ slotCache.hash.insert(compoundKey, slotData);
object->setProperty(cachePropertyName, QVariant::fromValue(slotCache));
// found the slot to be called
- deliverCall(object, flags, msg, slotData.metaTypes, slotData.slotIdx);
+ deliverCall(object, msg, slotData.metaTypes, slotData.slotIdx);
return true;
} else if (cacheIt->slotIdx == -1) {
// negative cache
return false;
} else {
// use the cache
- deliverCall(object, flags, msg, cacheIt->metaTypes, cacheIt->slotIdx);
+ deliverCall(object, msg, cacheIt->metaTypes, cacheIt->slotIdx);
return true;
}
return false;
}
-void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const QDBusMessage &msg,
+void QDBusConnectionPrivate::deliverCall(QObject *object, const QDBusMessage &msg,
const QList<QMetaType> &metaTypes, int slotIdx)
{
Q_ASSERT_X(!object || QThread::currentThread() == object->thread(),
@@ -890,10 +928,10 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
"function called for an object that is in another thread!!");
QVarLengthArray<void *, 10> params;
- params.reserve(metaTypes.count());
+ params.reserve(metaTypes.size());
QVarLengthArray<QVariant, 10> auxParameters; // we cannot allow reallocation here, since we
- auxParameters.reserve(metaTypes.count()); // keep references to the entries
+ auxParameters.reserve(metaTypes.size()); // keep references to the entries
// let's create the parameter list
@@ -902,13 +940,14 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
// add the input parameters
int i;
- int pCount = qMin(msg.arguments().count(), metaTypes.count() - 1);
+ int pCount = qMin(msg.arguments().size(), metaTypes.size() - 1);
for (i = 1; i <= pCount; ++i) {
auto id = metaTypes[i];
if (id == QDBusMetaTypeId::message())
break;
- const QVariant &arg = msg.arguments().at(i - 1);
+ const QList<QVariant> args = msg.arguments();
+ const QVariant &arg = args.at(i - 1);
if (arg.metaType() == id)
// no conversion needed
params.append(const_cast<void *>(arg.constData()));
@@ -918,7 +957,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
const QDBusArgument &in =
*reinterpret_cast<const QDBusArgument *>(arg.constData());
- QVariant &out = auxParameters[auxParameters.count() - 1];
+ QVariant &out = auxParameters[auxParameters.size() - 1];
if (Q_UNLIKELY(!QDBusMetaType::demarshall(in, out.metaType(), out.data())))
qFatal("Internal error: demarshalling function for type '%s' (%d) failed!",
@@ -933,19 +972,19 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
}
}
- if (metaTypes.count() > i && metaTypes[i] == QDBusMetaTypeId::message()) {
+ if (metaTypes.size() > i && metaTypes[i] == QDBusMetaTypeId::message()) {
params.append(const_cast<void*>(static_cast<const void*>(&msg)));
++i;
}
// output arguments
- const int numMetaTypes = metaTypes.count();
+ const int numMetaTypes = metaTypes.size();
QVariantList outputArgs;
if (metaTypes[0].id() != QMetaType::Void && metaTypes[0].isValid()) {
outputArgs.reserve(numMetaTypes - i + 1);
QVariant arg{QMetaType(metaTypes[0])};
outputArgs.append( arg );
- params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData());
+ params[0] = const_cast<void*>(outputArgs.at( outputArgs.size() - 1 ).constData());
} else {
outputArgs.reserve(numMetaTypes - i);
}
@@ -953,7 +992,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
for ( ; i < numMetaTypes; ++i) {
QVariant arg{QMetaType(metaTypes[i])};
outputArgs.append( arg );
- params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()));
+ params.append(const_cast<void*>(outputArgs.at( outputArgs.size() - 1 ).constData()));
}
// make call:
@@ -982,7 +1021,7 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
send(msg.createReply(outputArgs));
} else {
// generate internal error
- qWarning("Internal error: Failed to deliver message");
+ qCWarning(dbusIntegration, "Internal error: Failed to deliver message");
send(msg.createErrorReply(QDBusError::InternalError, "Failed to deliver message"_L1));
}
}
@@ -990,11 +1029,8 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
return;
}
-extern bool qDBusInitThreads();
-
-QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
- : QObject(p),
- ref(1),
+QDBusConnectionPrivate::QDBusConnectionPrivate()
+ : ref(1),
mode(InvalidMode),
busService(nullptr),
connection(nullptr),
@@ -1020,12 +1056,8 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
this, &QDBusConnectionPrivate::handleObjectCall, Qt::QueuedConnection);
connect(this, &QDBusConnectionPrivate::messageNeedsSending,
this, &QDBusConnectionPrivate::sendInternal);
- connect(this, &QDBusConnectionPrivate::signalNeedsConnecting,
- this, &QDBusConnectionPrivate::addSignalHook, Qt::BlockingQueuedConnection);
- connect(this, &QDBusConnectionPrivate::signalNeedsDisconnecting,
- this, &QDBusConnectionPrivate::removeSignalHook, Qt::BlockingQueuedConnection);
- rootNode.flags = 0;
+ rootNode.flags = {};
// prepopulate watchedServices:
// we know that the owner of org.freedesktop.DBus is itself
@@ -1039,9 +1071,10 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
QDBusConnectionPrivate::~QDBusConnectionPrivate()
{
if (thread() && thread() != QThread::currentThread())
- qWarning("QDBusConnection(name=\"%s\")'s last reference in not in its creation thread! "
- "Timer and socket errors will follow and the program will probably crash",
- qPrintable(name));
+ qCWarning(dbusIntegration,
+ "QDBusConnection(name=\"%s\")'s last reference in not in its creation thread! "
+ "Timer and socket errors will follow and the program will probably crash",
+ qPrintable(name));
auto lastMode = mode; // reset on connection close
closeConnection();
@@ -1069,12 +1102,8 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate()
void QDBusConnectionPrivate::collectAllObjects(QDBusConnectionPrivate::ObjectTreeNode &haystack,
QSet<QObject *> &set)
{
- QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = haystack.children.begin();
-
- while (it != haystack.children.end()) {
- collectAllObjects(*it, set);
- it++;
- }
+ for (ObjectTreeNode &child : haystack.children)
+ collectAllObjects(child, set);
if (haystack.obj)
set.insert(haystack.obj);
@@ -1102,11 +1131,9 @@ void QDBusConnectionPrivate::closeConnection()
}
}
- for (auto it = pendingCalls.begin(); it != pendingCalls.end(); ++it) {
- auto call = *it;
- if (!call->ref.deref()) {
+ for (QDBusPendingCallPrivate *call : pendingCalls) {
+ if (!call->ref.deref())
delete call;
- }
}
pendingCalls.clear();
@@ -1117,18 +1144,12 @@ void QDBusConnectionPrivate::closeConnection()
// dangling pointer.
QSet<QObject *> allObjects;
collectAllObjects(rootNode, allObjects);
- SignalHookHash::const_iterator sit = signalHooks.constBegin();
- while (sit != signalHooks.constEnd()) {
- allObjects.insert(sit.value().obj);
- ++sit;
- }
+ for (const SignalHook &signalHook : std::as_const(signalHooks))
+ allObjects.insert(signalHook.obj);
// now disconnect ourselves
- QSet<QObject *>::const_iterator oit = allObjects.constBegin();
- while (oit != allObjects.constEnd()) {
- (*oit)->disconnect(this);
- ++oit;
- }
+ for (QObject *obj : std::as_const(allObjects))
+ obj->disconnect(this);
}
void QDBusConnectionPrivate::handleDBusDisconnection()
@@ -1168,17 +1189,15 @@ void QDBusConnectionPrivate::timerEvent(QTimerEvent *e)
void QDBusConnectionPrivate::doDispatch()
{
if (mode == ClientMode || mode == PeerMode) {
- while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) ;
if (dispatchEnabled && !pendingMessages.isEmpty()) {
// dispatch previously queued messages
- PendingMessageList::Iterator it = pendingMessages.begin();
- PendingMessageList::Iterator end = pendingMessages.end();
- for ( ; it != end; ++it) {
- qDBusDebug() << this << "dequeueing message" << *it;
- handleMessage(std::move(*it));
+ for (QDBusMessage &message : pendingMessages) {
+ qDBusDebug() << this << "dequeueing message" << message;
+ handleMessage(std::move(message));
}
pendingMessages.clear();
}
+ while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) ;
}
}
@@ -1258,8 +1277,8 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
DBusMessage *msg =
QDBusMessagePrivate::toDBusMessage(message, connectionCapabilities(), &error);
if (!msg) {
- qWarning("QDBusConnection: Could not emit signal %s.%s: %s", qPrintable(interface), memberName.constData(),
- qPrintable(error.message()));
+ qCWarning(dbusIntegration, "QDBusConnection: Could not emit signal %s.%s: %s",
+ qPrintable(interface), memberName.constData(), qPrintable(error.message()));
lastError = error;
return;
}
@@ -1274,46 +1293,46 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
void QDBusConnectionPrivate::serviceOwnerChangedNoLock(const QString &name,
const QString &oldOwner, const QString &newOwner)
{
- Q_UNUSED(oldOwner);
// QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this);
WatchedServicesHash::Iterator it = watchedServices.find(name);
if (it == watchedServices.end())
return;
if (oldOwner != it->owner)
- qWarning("QDBusConnection: name '%s' had owner '%s' but we thought it was '%s'",
- qPrintable(name), qPrintable(oldOwner), qPrintable(it->owner));
+ qCWarning(dbusIntegration,
+ "QDBusConnection: name '%s' had owner '%s' but we thought it was '%s'",
+ qPrintable(name), qPrintable(oldOwner), qPrintable(it->owner));
qDBusDebug() << this << "Updating name" << name << "from" << oldOwner << "to" << newOwner;
it->owner = newOwner;
}
int QDBusConnectionPrivate::findSlot(QObject *obj, const QByteArray &normalizedName,
- QList<QMetaType> &params)
+ QList<QMetaType> &params, QString &errorMsg)
{
+ errorMsg.clear();
int midx = obj->metaObject()->indexOfMethod(normalizedName);
if (midx == -1)
return -1;
- QString errorMsg;
int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params, errorMsg);
- if ( inputCount == -1 || inputCount + 1 != params.count() )
- return -1; // failed to parse or invalid arguments or output arguments
+ if (inputCount == -1 || inputCount + 1 != params.size())
+ return -1;
return midx;
}
bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
- const QString &service,
- const QString &path, const QString &interface, const QString &name,
- const ArgMatchRules &argMatch,
- QObject *receiver, const char *signal, int minMIdx,
- bool buildSignature)
+ const QString &service, const QString &path,
+ const QString &interface, const QString &name,
+ const ArgMatchRules &argMatch, QObject *receiver,
+ const char *signal, int minMIdx, bool buildSignature,
+ QString &errorMsg)
{
QByteArray normalizedName = signal + 1;
- hook.midx = findSlot(receiver, signal + 1, hook.params);
+ hook.midx = findSlot(receiver, signal + 1, hook.params, errorMsg);
if (hook.midx == -1) {
normalizedName = QMetaObject::normalizedSignature(signal + 1);
- hook.midx = findSlot(receiver, normalizedName, hook.params);
+ hook.midx = findSlot(receiver, normalizedName, hook.params, errorMsg);
}
if (hook.midx < minMIdx) {
return false;
@@ -1333,13 +1352,13 @@ bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hoo
mname = QString::fromUtf8(normalizedName);
}
key = mname;
- key.reserve(interface.length() + 1 + mname.length());
+ key.reserve(interface.size() + 1 + mname.size());
key += u':';
key += interface;
if (buildSignature) {
hook.signature.clear();
- for (int i = 1; i < hook.params.count(); ++i)
+ for (int i = 1; i < hook.params.size(); ++i)
if (hook.params.at(i) != QDBusMetaTypeId::message())
hook.signature += QLatin1StringView(QDBusMetaType::typeToSignature(hook.params.at(i)));
}
@@ -1435,7 +1454,7 @@ void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMes
}
}
- if (pathStartPos != msg.path().length()) {
+ if (pathStartPos != msg.path().size()) {
node.flags &= ~QDBusConnection::ExportAllSignals;
node.obj = findChildObject(&node, msg.path(), pathStartPos);
if (!node.obj) {
@@ -1447,19 +1466,16 @@ void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMes
QDBusAdaptorConnector *connector;
if (node.flags & QDBusConnection::ExportAdaptors &&
(connector = qDBusFindAdaptorConnector(node.obj))) {
- int newflags = node.flags | QDBusConnection::ExportAllSlots;
+ auto newflags = node.flags | QDBusConnection::ExportAllSlots;
if (msg.interface().isEmpty()) {
// place the call in all interfaces
// let the first one that handles it to work
- QDBusAdaptorConnector::AdaptorMap::ConstIterator it =
- connector->adaptors.constBegin();
- QDBusAdaptorConnector::AdaptorMap::ConstIterator end =
- connector->adaptors.constEnd();
-
- for ( ; it != end; ++it)
- if (activateCall(it->adaptor, newflags, msg))
+ for (const QDBusAdaptorConnector::AdaptorData &adaptorData :
+ std::as_const(connector->adaptors)) {
+ if (activateCall(adaptorData.adaptor, newflags, msg))
return;
+ }
} else {
// check if we have an interface matching the name that was asked:
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
@@ -1653,14 +1669,14 @@ void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg)
// (but not both)
QString key = msg.member();
- key.reserve(key.length() + 1 + msg.interface().length());
+ key.reserve(key.size() + 1 + msg.interface().size());
key += u':';
key += msg.interface();
- QDBusReadLocker locker(HandleSignalAction, this);
+ QDBusWriteLocker locker(HandleSignalAction, this);
handleSignal(key, msg); // one try
- key.truncate(msg.member().length() + 1); // keep the ':'
+ key.truncate(msg.member().size() + 1); // keep the ':'
handleSignal(key, msg); // second try
key = u':';
@@ -1748,10 +1764,10 @@ void QDBusConnectionPrivate::setPeer(DBusConnection *c, const QDBusErrorInternal
watchForDBusDisconnection();
- QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection);
}
-static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnection *connection)
+static QDBusConnection::ConnectionCapabilities connectionCapabilities(DBusConnection *connection)
{
QDBusConnection::ConnectionCapabilities result;
typedef dbus_bool_t (*can_send_type_t)(DBusConnection *, int);
@@ -1777,7 +1793,7 @@ static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnecti
void QDBusConnectionPrivate::handleAuthentication()
{
- capabilities.storeRelaxed(connectionCapabilies(connection));
+ capabilities.storeRelaxed(::connectionCapabilities(connection));
isAuthenticated = true;
}
@@ -1836,7 +1852,7 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError
qDBusDebug() << this << ": connected successfully";
// schedule a dispatch:
- QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection);
}
extern "C"{
@@ -1844,7 +1860,6 @@ static void qDBusResultReceived(DBusPendingCall *pending, void *user_data)
{
QDBusPendingCallPrivate *call = reinterpret_cast<QDBusPendingCallPrivate *>(user_data);
Q_ASSERT(call->pending == pending);
- Q_UNUSED(pending);
QDBusConnectionPrivate::processFinishedCall(call);
}
}
@@ -1922,22 +1937,26 @@ bool QDBusConnectionPrivate::send(const QDBusMessage& message)
QDBusMessagePrivate::toDBusMessage(message, connectionCapabilities(), &error);
if (!msg) {
if (message.type() == QDBusMessage::MethodCallMessage)
- qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
- qPrintable(message.service()), qPrintable(message.path()),
- qPrintable(message.interface()), qPrintable(message.member()),
- qPrintable(error.message()));
+ qCWarning(dbusIntegration,
+ "QDBusConnection: error: could not send message to service \"%s\" path "
+ "\"%s\" interface \"%s\" member \"%s\": %s",
+ qPrintable(message.service()), qPrintable(message.path()),
+ qPrintable(message.interface()), qPrintable(message.member()),
+ qPrintable(error.message()));
else if (message.type() == QDBusMessage::SignalMessage)
- qWarning("QDBusConnection: error: could not send signal to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
- qPrintable(message.service()),
- qPrintable(message.path()), qPrintable(message.interface()),
- qPrintable(message.member()),
- qPrintable(error.message()));
+ qCWarning(dbusIntegration,
+ "QDBusConnection: error: could not send signal to service \"%s\" path \"%s\" "
+ "interface \"%s\" member \"%s\": %s",
+ qPrintable(message.service()), qPrintable(message.path()),
+ qPrintable(message.interface()), qPrintable(message.member()),
+ qPrintable(error.message()));
else
- qWarning("QDBusConnection: error: could not send %s message to service \"%s\": %s",
- message.type() == QDBusMessage::ReplyMessage ? "reply" :
- message.type() == QDBusMessage::ErrorMessage ? "error" :
- "invalid", qPrintable(message.service()),
- qPrintable(error.message()));
+ qCWarning(dbusIntegration,
+ "QDBusConnection: error: could not send %s message to service \"%s\": %s",
+ message.type() == QDBusMessage::ReplyMessage ? "reply"
+ : message.type() == QDBusMessage::ErrorMessage ? "error"
+ : "invalid",
+ qPrintable(message.service()), qPrintable(error.message()));
lastError = error;
return false;
}
@@ -1957,7 +1976,7 @@ bool QDBusConnectionPrivate::send(const QDBusMessage& message)
class QDBusBlockingCallWatcher
{
public:
- QDBusBlockingCallWatcher(const QDBusMessage &message)
+ Q_NODISCARD_CTOR QDBusBlockingCallWatcher(const QDBusMessage &message)
: m_message(message), m_maxCallTimeoutMs(0)
{
#if defined(QT_NO_DEBUG)
@@ -1984,7 +2003,10 @@ public:
if (ok)
mainThreadWarningAmount = tmp;
else
- qWarning("QDBusBlockingCallWatcher: Q_DBUS_BLOCKING_CALL_MAIN_THREAD_WARNING_MS must be an integer; value ignored");
+ qCWarning(
+ dbusIntegration,
+ "QDBusBlockingCallWatcher: Q_DBUS_BLOCKING_CALL_MAIN_THREAD_WARNING_MS "
+ "must be an integer; value ignored");
}
env = qgetenv("Q_DBUS_BLOCKING_CALL_OTHER_THREAD_WARNING_MS");
@@ -1993,7 +2015,10 @@ public:
if (ok)
otherThreadWarningAmount = tmp;
else
- qWarning("QDBusBlockingCallWatcher: Q_DBUS_BLOCKING_CALL_OTHER_THREAD_WARNING_MS must be an integer; value ignored");
+ qCWarning(dbusIntegration,
+ "QDBusBlockingCallWatcher: "
+ "Q_DBUS_BLOCKING_CALL_OTHER_THREAD_WARNING_MS must be an integer; "
+ "value ignored");
}
initializedAmounts = true;
@@ -2018,10 +2043,13 @@ public:
return; // disabled
if (m_callTimer.elapsed() >= m_maxCallTimeoutMs) {
- qWarning("QDBusConnection: warning: blocking call took a long time (%d ms, max for this thread is %d ms) to service \"%s\" path \"%s\" interface \"%s\" member \"%s\"",
- int(m_callTimer.elapsed()), m_maxCallTimeoutMs,
- qPrintable(m_message.service()), qPrintable(m_message.path()),
- qPrintable(m_message.interface()), qPrintable(m_message.member()));
+ qCWarning(
+ dbusIntegration,
+ "QDBusConnection: warning: blocking call took a long time (%d ms, max for this "
+ "thread is %d ms) to service \"%s\" path \"%s\" interface \"%s\" member \"%s\"",
+ int(m_callTimer.elapsed()), m_maxCallTimeoutMs, qPrintable(m_message.service()),
+ qPrintable(m_message.path()), qPrintable(m_message.interface()),
+ qPrintable(m_message.member()));
}
}
@@ -2031,29 +2059,18 @@ private:
QElapsedTimer m_callTimer;
};
-
QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message,
- int sendMode, int timeout)
+ QDBus::CallMode mode, int timeout)
{
QDBusBlockingCallWatcher watcher(message);
QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, nullptr, nullptr, nullptr, timeout);
Q_ASSERT(pcall);
- if (pcall->replyMessage.type() == QDBusMessage::InvalidMessage) {
- // need to wait for the reply
- if (sendMode == QDBus::BlockWithGui) {
- pcall->watcherHelper = new QDBusPendingCallWatcherHelper;
- QEventLoop loop;
- loop.connect(pcall->watcherHelper, &QDBusPendingCallWatcherHelper::reply, &loop, &QEventLoop::quit);
- loop.connect(pcall->watcherHelper, &QDBusPendingCallWatcherHelper::error, &loop, &QEventLoop::quit);
-
- // enter the event loop and wait for a reply
- loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);
- } else {
- pcall->waitForFinished();
- }
- }
+ if (mode == QDBus::BlockWithGui)
+ pcall->waitForFinishedWithGui();
+ else
+ pcall->waitForFinished();
QDBusMessage reply = pcall->replyMessage;
lastError = QDBusError(reply); // set or clear error
@@ -2083,9 +2100,12 @@ QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal(const QDBusMessage &mess
// if the message was handled, there might be a reply
QDBusMessage localReplyMsg = QDBusMessagePrivate::makeLocalReply(*this, localCallMsg);
if (localReplyMsg.type() == QDBusMessage::InvalidMessage) {
- qWarning("QDBusConnection: cannot call local method '%s' at object %s (with signature '%s') "
- "on blocking mode", qPrintable(message.member()), qPrintable(message.path()),
- qPrintable(message.signature()));
+ qCWarning(
+ dbusIntegration,
+ "QDBusConnection: cannot call local method '%s' at object %s (with signature '%s') "
+ "on blocking mode",
+ qPrintable(message.member()), qPrintable(message.path()),
+ qPrintable(message.signature()));
return QDBusMessage::createError(
QDBusError(QDBusError::InternalError,
"local-loop message cannot have delayed replies"_L1));
@@ -2111,6 +2131,7 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
pcall->setReplyCallback(receiver, returnMethod);
if (errorMethod) {
+ Q_ASSERT(!pcall->watcherHelper);
pcall->watcherHelper = new QDBusPendingCallWatcherHelper;
connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod,
Qt::QueuedConnection);
@@ -2136,10 +2157,12 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
DBusMessage *msg =
QDBusMessagePrivate::toDBusMessage(message, connectionCapabilities(), &error);
if (!msg) {
- qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s",
- qPrintable(message.service()), qPrintable(message.path()),
- qPrintable(message.interface()), qPrintable(message.member()),
- qPrintable(error.message()));
+ qCWarning(dbusIntegration,
+ "QDBusConnection: error: could not send message to service \"%s\" path \"%s\" "
+ "interface \"%s\" member \"%s\": %s",
+ qPrintable(message.service()), qPrintable(message.path()),
+ qPrintable(message.interface()), qPrintable(message.member()),
+ qPrintable(error.message()));
pcall->replyMessage = QDBusMessage::createError(error);
lastError = error;
processFinishedCall(pcall);
@@ -2210,15 +2233,30 @@ bool QDBusConnectionPrivate::connectSignal(const QString &service,
QString key;
hook.signature = signature;
- if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
+ QString errorMsg;
+ if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
+ false, errorMsg)) {
+ qCWarning(dbusIntegration)
+ << "Could not connect" << interface << "to" << slot + 1 << ":" << qPrintable(errorMsg);
return false; // don't connect
+ }
Q_ASSERT(thread() != QThread::currentThread());
- return emit signalNeedsConnecting(key, hook);
+ return addSignalHook(key, hook);
}
bool QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook &hook)
{
+ bool result = false;
+
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::addSignalHookImpl,
+ Qt::BlockingQueuedConnection, qReturnArg(result), key, hook);
+
+ return result;
+}
+
+bool QDBusConnectionPrivate::addSignalHookImpl(const QString &key, const SignalHook &hook)
+{
QDBusWriteLocker locker(ConnectAction, this);
// avoid duplicating:
@@ -2300,15 +2338,30 @@ bool QDBusConnectionPrivate::disconnectSignal(const QString &service,
name2.detach();
hook.signature = signature;
- if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false))
+ QString errorMsg;
+ if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0,
+ false, errorMsg)) {
+ qCWarning(dbusIntegration)
+ << "Could not disconnect" << interface << "to" << slot + 1 << ":" << qPrintable(errorMsg);
return false; // don't disconnect
+ }
Q_ASSERT(thread() != QThread::currentThread());
- return emit signalNeedsDisconnecting(key, hook);
+ return removeSignalHook(key, hook);
}
bool QDBusConnectionPrivate::removeSignalHook(const QString &key, const SignalHook &hook)
{
+ bool result = false;
+
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::removeSignalHookImpl,
+ Qt::BlockingQueuedConnection, qReturnArg(result), key, hook);
+
+ return result;
+}
+
+bool QDBusConnectionPrivate::removeSignalHookImpl(const QString &key, const SignalHook &hook)
+{
// remove it from our list:
QDBusWriteLocker locker(ConnectAction, this);
QDBusConnectionPrivate::SignalHookHash::Iterator it = signalHooks.find(key);
@@ -2339,7 +2392,9 @@ QDBusConnectionPrivate::removeSignalHookNoLock(SignalHookHash::Iterator it)
bool erase = false;
MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule);
if (i == matchRefCounts.end()) {
- qWarning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!");
+ qCWarning(dbusIntegration,
+ "QDBusConnectionPrivate::disconnectSignal: MatchRule not found in "
+ "matchRefCounts!!");
} else {
if (i.value() == 1) {
erase = true;
@@ -2393,8 +2448,8 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
connector->connectAllSignals(node->obj);
}
- connect(connector, SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
- this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)),
+ connect(connector, &QDBusAdaptorConnector::relaySignal, this,
+ &QDBusConnectionPrivate::relaySignal,
Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection));
}
}
@@ -2427,12 +2482,16 @@ void QDBusConnectionPrivate::connectRelay(const QString &service,
QByteArray sig;
sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature());
+ QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
- QDBusAbstractInterface::staticMetaObject.methodCount(), true))
+ QDBusAbstractInterface::staticMetaObject.methodCount(), true, errorMsg)) {
+ qCWarning(dbusIntegration)
+ << "Could not connect" << interface << "to" << signal.name() << ":" << qPrintable(errorMsg);
return; // don't connect
+ }
Q_ASSERT(thread() != QThread::currentThread());
- emit signalNeedsConnecting(key, hook);
+ addSignalHook(key, hook);
}
void QDBusConnectionPrivate::disconnectRelay(const QString &service,
@@ -2448,12 +2507,16 @@ void QDBusConnectionPrivate::disconnectRelay(const QString &service,
QByteArray sig;
sig.append(QSIGNAL_CODE + '0');
sig.append(signal.methodSignature());
+ QString errorMsg;
if (!prepareHook(hook, key, service, path, interface, QString(), ArgMatchRules(), receiver, sig,
- QDBusAbstractInterface::staticMetaObject.methodCount(), true))
+ QDBusAbstractInterface::staticMetaObject.methodCount(), true, errorMsg)) {
+ qCWarning(dbusIntegration) << "Could not disconnect" << interface << "to"
+ << signal.methodSignature() << ":" << qPrintable(errorMsg);
return; // don't disconnect
+ }
Q_ASSERT(thread() != QThread::currentThread());
- emit signalNeedsDisconnecting(key, hook);
+ removeSignalHook(key, hook);
}
bool QDBusConnectionPrivate::shouldWatchService(const QString &service)
@@ -2638,6 +2701,28 @@ void QDBusConnectionPrivate::postEventToThread(int action, QObject *object, QEve
QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterPost, this);
}
+/*
+ * Enable dispatch of D-Bus events for this connection, but only after
+ * context's thread's event loop has started and processed any already
+ * pending events. The event dispatch is then enabled in the DBus aux thread.
+ */
+void QDBusConnectionPrivate::enableDispatchDelayed(QObject *context)
+{
+ ref.ref();
+ QMetaObject::invokeMethod(
+ context,
+ [this]() {
+ // This call cannot race with something disabling dispatch only
+ // because dispatch is never re-disabled from Qt code on an
+ // in-use connection once it has been enabled.
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::setDispatchEnabled,
+ Qt::QueuedConnection, true);
+ if (!ref.deref())
+ deleteLater();
+ },
+ Qt::QueuedConnection);
+}
+
QT_END_NAMESPACE
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusintegrator_p.h b/src/dbus/qdbusintegrator_p.h
index 275735b5d5..b0c349799a 100644
--- a/src/dbus/qdbusintegrator_p.h
+++ b/src/dbus/qdbusintegrator_p.h
@@ -46,18 +46,34 @@ struct QDBusSlotCache
{
struct Data
{
- int flags;
int slotIdx;
QList<QMetaType> metaTypes;
void swap(Data &other) noexcept
{
- qSwap(flags, other.flags);
qSwap(slotIdx, other.slotIdx);
qSwap(metaTypes, other.metaTypes);
}
};
- typedef QMultiHash<QString, Data> Hash;
+
+ struct Key
+ {
+ QString memberWithSignature;
+ QDBusConnection::RegisterOptions flags;
+
+ friend bool operator==(const Key &lhs, const Key &rhs) noexcept
+ {
+ return lhs.memberWithSignature == rhs.memberWithSignature && lhs.flags == rhs.flags;
+ }
+
+ friend size_t qHash(const QDBusSlotCache::Key &key, size_t seed = 0) noexcept
+ {
+ return qHashMulti(seed, key.memberWithSignature, key.flags);
+ }
+ };
+
+ using Hash = QHash<Key, Data>;
+
Hash hash;
void swap(QDBusSlotCache &other) noexcept { qSwap(hash, other.hash); }
@@ -69,19 +85,14 @@ class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent
{
public:
QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
- const QDBusMessage &msg, const QList<QMetaType> &types, int f = 0)
- : QAbstractMetaCallEvent(sender, -1),
- connection(c),
- message(msg),
- metaTypes(types),
- id(id),
- flags(f)
+ const QDBusMessage &msg, const QList<QMetaType> &types)
+ : QAbstractMetaCallEvent(sender, -1), connection(c), message(msg), metaTypes(types), id(id)
{
}
void placeMetaCall(QObject *object) override
{
- QDBusConnectionPrivate::d(connection)->deliverCall(object, flags, message, metaTypes, id);
+ QDBusConnectionPrivate::d(connection)->deliverCall(object, message, metaTypes, id);
}
private:
@@ -89,7 +100,6 @@ private:
QDBusMessage message;
QList<QMetaType> metaTypes;
int id;
- int flags;
};
class QDBusActivateObjectEvent: public QAbstractMetaCallEvent
@@ -117,18 +127,15 @@ class QDBusSpyCallEvent : public QAbstractMetaCallEvent
{
public:
typedef void (*Hook)(const QDBusMessage&);
- QDBusSpyCallEvent(QDBusConnectionPrivate *cp, const QDBusConnection &c, const QDBusMessage &msg,
- const Hook *hooks, int count)
- : QAbstractMetaCallEvent(cp, 0), conn(c), msg(msg), hooks(hooks), hookCount(count)
+ QDBusSpyCallEvent(QDBusConnectionPrivate *cp, const QDBusConnection &c, const QDBusMessage &msg)
+ : QAbstractMetaCallEvent(cp, 0), conn(c), msg(msg)
{}
~QDBusSpyCallEvent() override;
void placeMetaCall(QObject *) override;
- static inline void invokeSpyHooks(const QDBusMessage &msg, const Hook *hooks, int hookCount);
+ static inline void invokeSpyHooks(const QDBusMessage &msg);
QDBusConnection conn; // keeps the refcount in QDBusConnectionPrivate up
QDBusMessage msg;
- const Hook *hooks;
- int hookCount;
};
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusinternalfilters.cpp b/src/dbus/qdbusinternalfilters.cpp
index 11813de537..721564ed3c 100644
--- a/src/dbus/qdbusinternalfilters.cpp
+++ b/src/dbus/qdbusinternalfilters.cpp
@@ -30,8 +30,8 @@ QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
// defined in qdbusxmlgenerator.cpp
-extern QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
- const QMetaObject *base, int flags);
+extern Q_DBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
+ const QMetaObject *base, int flags);
static const char introspectableInterfaceXml[] =
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
@@ -73,14 +73,11 @@ static const char peerInterfaceXml[] =
" </method>\n"
" </interface>\n";
-static QString generateSubObjectXml(QObject *object)
+static QString generateSubObjectXml(const QObject *object)
{
QString retval;
- const QObjectList &objs = object->children();
- QObjectList::ConstIterator it = objs.constBegin();
- QObjectList::ConstIterator end = objs.constEnd();
- for ( ; it != end; ++it) {
- QString name = (*it)->objectName();
+ for (const QObject *child : object->children()) {
+ QString name = child->objectName();
if (!name.isEmpty() && QDBusUtil::isValidPartOfObjectPath(name))
retval += " <node name=\""_L1 + name + "\"/>\n"_L1;
}
@@ -116,20 +113,22 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node
(connector = qDBusFindAdaptorConnector(node.obj))) {
// trasverse every adaptor in this object
- QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin();
- QDBusAdaptorConnector::AdaptorMap::ConstIterator end = connector->adaptors.constEnd();
- for ( ; it != end; ++it) {
+ for (const QDBusAdaptorConnector::AdaptorData &adaptorData :
+ std::as_const(connector->adaptors)) {
// add the interface:
- QString ifaceXml = QDBusAbstractAdaptorPrivate::retrieveIntrospectionXml(it->adaptor);
+ QString ifaceXml =
+ QDBusAbstractAdaptorPrivate::retrieveIntrospectionXml(adaptorData.adaptor);
if (ifaceXml.isEmpty()) {
// add the interface's contents:
- ifaceXml += qDBusGenerateMetaObjectXml(QString::fromLatin1(it->interface),
- it->adaptor->metaObject(),
- &QDBusAbstractAdaptor::staticMetaObject,
- QDBusConnection::ExportScriptableContents
- | QDBusConnection::ExportNonScriptableContents);
-
- QDBusAbstractAdaptorPrivate::saveIntrospectionXml(it->adaptor, ifaceXml);
+ ifaceXml += qDBusGenerateMetaObjectXml(
+ QString::fromLatin1(adaptorData.interface),
+ adaptorData.adaptor->metaObject(),
+ &QDBusAbstractAdaptor::staticMetaObject,
+ QDBusConnection::ExportScriptableContents
+ | QDBusConnection::ExportNonScriptableContents);
+
+ QDBusAbstractAdaptorPrivate::saveIntrospectionXml(adaptorData.adaptor,
+ ifaceXml);
}
xml_data += ifaceXml;
@@ -151,13 +150,10 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node
xml_data += generateSubObjectXml(node.obj);
} else {
// generate from the object tree
- QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
- node.children.constBegin();
- QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end =
- node.children.constEnd();
- for ( ; it != end; ++it)
- if (it->obj || !it->children.isEmpty())
- xml_data += " <node name=\""_L1 + it->name + "\"/>\n"_L1;
+ for (const QDBusConnectionPrivate::ObjectTreeNode &node : node.children) {
+ if (node.obj || !node.children.isEmpty())
+ xml_data += " <node name=\""_L1 + node.name + "\"/>\n"_L1;
+ }
}
xml_data += "</node>\n"_L1;
@@ -187,7 +183,7 @@ propertyNotFoundError(const QDBusMessage &msg, const QString &interface_name, co
QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg)
{
- Q_ASSERT(msg.arguments().count() == 2);
+ Q_ASSERT(msg.arguments().size() == 2);
Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
"QDBusConnection: internal threading error",
"function called for an object that is in another thread!!");
@@ -195,7 +191,7 @@ QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node
QString interface_name = msg.arguments().at(0).toString();
QByteArray property_name = msg.arguments().at(1).toString().toUtf8();
- QDBusAdaptorConnector *connector;
+ const QDBusAdaptorConnector *connector;
QVariant value;
bool interfaceFound = false;
if (node.flags & QDBusConnection::ExportAdaptors &&
@@ -204,12 +200,11 @@ QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node
// find the class that implements interface_name or try until we've found the property
// in case of an empty interface
if (interface_name.isEmpty()) {
- for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(),
- end = connector->adaptors.constEnd(); it != end; ++it) {
- const QMetaObject *mo = it->adaptor->metaObject();
+ for (const QDBusAdaptorConnector::AdaptorData &adaptorData : connector->adaptors) {
+ const QMetaObject *mo = adaptorData.adaptor->metaObject();
int pidx = mo->indexOfProperty(property_name);
if (pidx != -1) {
- value = mo->property(pidx).read(it->adaptor);
+ value = mo->property(pidx).read(adaptorData.adaptor);
break;
}
}
@@ -326,26 +321,26 @@ static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant
// we have to demarshall before writing
QVariant other{QMetaType(id)};
if (!QDBusMetaType::demarshall(qvariant_cast<QDBusArgument>(value), other.metaType(), other.data())) {
- qWarning("QDBusConnection: type `%s' (%d) is not registered with QtDBus. "
+ qWarning("QDBusConnection: type '%s' (%d) is not registered with QtDBus. "
"Use qDBusRegisterMetaType to register it",
mp.typeName(), id.id());
return PropertyWriteFailed;
}
- value = other;
+ value = std::move(other);
}
if (mp.metaType() == QMetaType::fromType<QDBusVariant>())
value = QVariant::fromValue(QDBusVariant(value));
// the property type here should match
- return mp.write(obj, value) ? PropertyWriteSuccess : PropertyWriteFailed;
+ return mp.write(obj, std::move(value)) ? PropertyWriteSuccess : PropertyWriteFailed;
}
QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg)
{
- Q_ASSERT(msg.arguments().count() == 3);
+ Q_ASSERT(msg.arguments().size() == 3);
Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
"QDBusConnection: internal threading error",
"function called for an object that is in another thread!!");
@@ -361,9 +356,9 @@ QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node
// find the class that implements interface_name or try until we've found the property
// in case of an empty interface
if (interface_name.isEmpty()) {
- for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(),
- end = connector->adaptors.constEnd(); it != end; ++it) {
- int status = writeProperty(it->adaptor, property_name, value);
+ for (const QDBusAdaptorConnector::AdaptorData &adaptorData :
+ std::as_const(connector->adaptors)) {
+ int status = writeProperty(adaptorData.adaptor, property_name, value);
if (status == PropertyNotFound)
continue;
return propertyWriteReply(msg, interface_name, property_name, status);
@@ -401,10 +396,8 @@ QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node
// unite two QVariantMaps, but don't generate duplicate keys
static QVariantMap &operator+=(QVariantMap &lhs, const QVariantMap &rhs)
{
- QVariantMap::ConstIterator it = rhs.constBegin(),
- end = rhs.constEnd();
- for ( ; it != end; ++it)
- lhs.insert(it.key(), it.value());
+ for (const auto &[key, value] : rhs.asKeyValueRange())
+ lhs.insert(key, value);
return lhs;
}
@@ -445,7 +438,7 @@ static QVariantMap readAllProperties(QObject *object, int flags)
QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &node,
const QDBusMessage &msg)
{
- Q_ASSERT(msg.arguments().count() == 1);
+ Q_ASSERT(msg.arguments().size() == 1);
Q_ASSERT_X(!node.obj || QThread::currentThread() == node.obj->thread(),
"QDBusConnection: internal threading error",
"function called for an object that is in another thread!!");
@@ -461,9 +454,10 @@ QDBusMessage qDBusPropertyGetAll(const QDBusConnectionPrivate::ObjectTreeNode &n
if (interface_name.isEmpty()) {
// iterate over all interfaces
- for (QDBusAdaptorConnector::AdaptorMap::ConstIterator it = connector->adaptors.constBegin(),
- end = connector->adaptors.constEnd(); it != end; ++it) {
- result += readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties);
+ for (const QDBusAdaptorConnector::AdaptorData &adaptorData :
+ std::as_const(connector->adaptors)) {
+ result += readAllProperties(adaptorData.adaptor,
+ QDBusConnection::ExportAllProperties);
}
} else {
// find the class that implements interface_name
diff --git a/src/dbus/qdbusintrospection.cpp b/src/dbus/qdbusintrospection.cpp
index 3f8766636f..04b5ab7751 100644
--- a/src/dbus/qdbusintrospection.cpp
+++ b/src/dbus/qdbusintrospection.cpp
@@ -21,6 +21,9 @@ QT_BEGIN_NAMESPACE
But they may prove useful if the XML data was obtained through other means (like parsing a file).
*/
+QDBusIntrospection::DiagnosticsReporter::~DiagnosticsReporter()
+ = default;
+
/*!
\class QDBusIntrospection::Argument
\inmodule QtDBus
@@ -297,11 +300,11 @@ QT_BEGIN_NAMESPACE
If there are multiple interfaces in this XML data, it is undefined which one will be
returned.
*/
-QDBusIntrospection::Interface
-QDBusIntrospection::parseInterface(const QString &xml)
+QDBusIntrospection::Interface QDBusIntrospection::parseInterface(const QString &xml,
+ DiagnosticsReporter *reporter)
{
// be lazy
- Interfaces ifs = parseInterfaces(xml);
+ Interfaces ifs = parseInterfaces(xml, reporter);
if (ifs.isEmpty())
return Interface();
@@ -315,11 +318,11 @@ QDBusIntrospection::parseInterface(const QString &xml)
If the first element tag in this document fragment is \<node\>, the interfaces parsed will
be those found as child elements of the \<node\> tag.
*/
-QDBusIntrospection::Interfaces
-QDBusIntrospection::parseInterfaces(const QString &xml)
+QDBusIntrospection::Interfaces QDBusIntrospection::parseInterfaces(const QString &xml,
+ DiagnosticsReporter *reporter)
{
QString null;
- QDBusXmlParser parser(null, null, xml);
+ QDBusXmlParser parser(null, null, xml, reporter);
return parser.interfaces();
}
@@ -334,10 +337,12 @@ QDBusIntrospection::parseInterfaces(const QString &xml)
This function does not parse the interfaces contained in the node, nor sub-object's contents.
It will only list their names.
*/
-QDBusIntrospection::Object
-QDBusIntrospection::parseObject(const QString &xml, const QString &service, const QString &path)
+QDBusIntrospection::Object QDBusIntrospection::parseObject(const QString &xml,
+ const QString &service,
+ const QString &path,
+ DiagnosticsReporter *reporter)
{
- QDBusXmlParser parser(service, path, xml);
+ QDBusXmlParser parser(service, path, xml, reporter);
QSharedDataPointer<QDBusIntrospection::Object> retval = parser.object();
if (!retval)
return QDBusIntrospection::Object();
diff --git a/src/dbus/qdbusintrospection_p.h b/src/dbus/qdbusintrospection_p.h
index 0dd7f70579..766cdffb62 100644
--- a/src/dbus/qdbusintrospection_p.h
+++ b/src/dbus/qdbusintrospection_p.h
@@ -18,7 +18,6 @@
#include <QtDBus/private/qtdbusglobal_p.h>
#include <QtCore/qlist.h>
#include <QtCore/qmap.h>
-#include <QtCore/qpair.h>
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
#include <QtCore/qstringlist.h>
@@ -38,9 +37,10 @@ public:
struct Interface;
struct Object;
struct ObjectTree;
+ struct Annotation;
// typedefs
- typedef QMap<QString, QString> Annotations;
+ typedef QMap<QString, Annotation> Annotations;
typedef QList<Argument> Arguments;
typedef QMultiMap<QString, Method> Methods;
typedef QMultiMap<QString, Signal> Signals;
@@ -51,8 +51,40 @@ public:
public:
// the structs
+ // Line and column numbers have the same meaning as in QXmlStreamReader.
+ struct SourceLocation
+ {
+ qint64 lineNumber = 1;
+ qint64 columnNumber = 0;
+ };
+
+ class Q_DBUS_EXPORT DiagnosticsReporter
+ {
+ Q_DISABLE_COPY_MOVE(DiagnosticsReporter)
+ public:
+ DiagnosticsReporter() = default;
+ virtual ~DiagnosticsReporter();
+ virtual void warning(const SourceLocation &location, const char *msg, ...)
+ Q_ATTRIBUTE_FORMAT_PRINTF(3, 4) = 0;
+ virtual void error(const SourceLocation &location, const char *msg, ...)
+ Q_ATTRIBUTE_FORMAT_PRINTF(3, 4) = 0;
+ };
+
+ struct Annotation
+ {
+ SourceLocation location;
+ QString name;
+ QString value;
+
+ inline bool operator==(const Annotation &other) const
+ {
+ return name == other.name && value == other.value;
+ }
+ };
+
struct Argument
{
+ SourceLocation location;
QString type;
QString name;
@@ -62,6 +94,7 @@ public:
struct Method
{
+ SourceLocation location;
QString name;
Arguments inputArgs;
Arguments outputArgs;
@@ -74,6 +107,7 @@ public:
struct Signal
{
+ SourceLocation location;
QString name;
Arguments outputArgs;
Annotations annotations;
@@ -86,6 +120,7 @@ public:
struct Property
{
enum Access { Read, Write, ReadWrite };
+ SourceLocation location;
QString name;
QString type;
Access access;
@@ -98,6 +133,7 @@ public:
struct Interface: public QSharedData
{
+ SourceLocation location;
QString name;
QString introspection;
@@ -112,6 +148,7 @@ public:
struct Object: public QSharedData
{
+ SourceLocation location;
QString service;
QString path;
@@ -120,10 +157,11 @@ public:
};
public:
- static Interface parseInterface(const QString &xml);
- static Interfaces parseInterfaces(const QString &xml);
+ static Interface parseInterface(const QString &xml, DiagnosticsReporter *reporter = nullptr);
+ static Interfaces parseInterfaces(const QString &xml, DiagnosticsReporter *reporter = nullptr);
static Object parseObject(const QString &xml, const QString &service = QString(),
- const QString &path = QString());
+ const QString &path = QString(),
+ DiagnosticsReporter *reporter = nullptr);
private:
QDBusIntrospection();
diff --git a/src/dbus/qdbusmarshaller.cpp b/src/dbus/qdbusmarshaller.cpp
index 58575a3d94..b2ed2586fb 100644
--- a/src/dbus/qdbusmarshaller.cpp
+++ b/src/dbus/qdbusmarshaller.cpp
@@ -28,7 +28,7 @@ QDBusMarshaller::~QDBusMarshaller()
void QDBusMarshaller::unregisteredTypeError(QMetaType id)
{
const char *name = id.name();
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
+ qWarning("QDBusMarshaller: type '%s' (%d) is not registered with D-Bus. "
"Use qDBusRegisterMetaType to register it",
name ? name : "", id.id());
error("Unregistered type %1 passed in arguments"_L1
@@ -152,7 +152,7 @@ inline void QDBusMarshaller::append(const QByteArray &arg)
DBusMessageIter subiterator;
q_dbus_message_iter_open_container(&iterator, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING,
&subiterator);
- q_dbus_message_iter_append_fixed_array(&subiterator, DBUS_TYPE_BYTE, &cdata, arg.length());
+ q_dbus_message_iter_append_fixed_array(&subiterator, DBUS_TYPE_BYTE, &cdata, arg.size());
q_dbus_message_iter_close_container(&iterator, &subiterator);
}
@@ -206,10 +206,8 @@ inline void QDBusMarshaller::append(const QStringList &arg)
QDBusMarshaller sub(capabilities);
open(sub, DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING);
- QStringList::ConstIterator it = arg.constBegin();
- QStringList::ConstIterator end = arg.constEnd();
- for ( ; it != end; ++it)
- sub.append(*it);
+ for (const QString &s : arg)
+ sub.append(s);
// don't call sub.close(): it auto-closes
}
@@ -237,8 +235,11 @@ inline QDBusMarshaller *QDBusMarshaller::beginMap(QMetaType kid, QMetaType vid)
return this;
}
if (ksignature[1] != 0 || !QDBusUtil::isValidBasicType(*ksignature)) {
- qWarning("QDBusMarshaller: type '%s' (%d) cannot be used as the key type in a D-BUS map.",
+QT_WARNING_PUSH
+QT_WARNING_DISABLE_GCC("-Wformat-overflow")
+ qWarning("QDBusMarshaller: type '%s' (%d) cannot be used as the key type in a D-Bus map.",
kid.name(), kid.id());
+QT_WARNING_POP
error("Type %1 passed in arguments cannot be used as a key in a map"_L1
.arg(QLatin1StringView(kid.name())));
return this;
@@ -359,7 +360,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
QDBusDemarshaller demarshaller(capabilities);
demarshaller.message = q_dbus_message_ref(d->message);
- if (d->direction == Demarshalling) {
+ if (d->direction == Direction::Demarshalling) {
// it's demarshalling; just copy
demarshaller.iterator = static_cast<QDBusDemarshaller *>(d)->iterator;
} else {
@@ -471,7 +472,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
Q_FALLTHROUGH();
default:
- qWarning("QDBusMarshaller::appendVariantInternal: Found unknown D-BUS type '%s'",
+ qWarning("QDBusMarshaller::appendVariantInternal: Found unknown D-Bus type '%s'",
signature);
return false;
}
@@ -491,7 +492,7 @@ bool QDBusMarshaller::appendCrossMarshalling(QDBusDemarshaller *demarshaller)
int code = q_dbus_message_iter_get_arg_type(&demarshaller->iterator);
if (QDBusUtil::isValidBasicType(code)) {
// easy: just append
- // do exactly like the D-BUS docs suggest
+ // do exactly like the D-Bus docs suggest
// (see apidocs for q_dbus_message_iter_get_basic)
qlonglong value;
diff --git a/src/dbus/qdbusmessage.cpp b/src/dbus/qdbusmessage.cpp
index fb3f8600e1..6ef762f225 100644
--- a/src/dbus/qdbusmessage.cpp
+++ b/src/dbus/qdbusmessage.cpp
@@ -36,22 +36,37 @@ static inline const char *data(const QByteArray &arr)
}
QDBusMessagePrivate::QDBusMessagePrivate()
- : msg(nullptr), reply(nullptr), localReply(nullptr), ref(1), type(QDBusMessage::InvalidMessage),
- delayedReply(false), localMessage(false),
- parametersValidated(false), autoStartService(true),
- interactiveAuthorizationAllowed(false)
+ : localReply(nullptr), ref(1), type(QDBusMessage::InvalidMessage),
+ delayedReply(false), parametersValidated(false),
+ localMessage(false), autoStartService(true),
+ interactiveAuthorizationAllowed(false), isReplyRequired(false)
{
}
QDBusMessagePrivate::~QDBusMessagePrivate()
{
- if (msg)
- q_dbus_message_unref(msg);
- if (reply)
- q_dbus_message_unref(reply);
delete localReply;
}
+void QDBusMessagePrivate::createResponseLink(const QDBusMessagePrivate *call)
+{
+ if (Q_UNLIKELY(call->type != QDBusMessage::MethodCallMessage)) {
+ qWarning("QDBusMessage: replying to a message that isn't a method call");
+ return;
+ }
+
+ if (call->localMessage) {
+ localMessage = true;
+ call->localReply = new QDBusMessage(*this); // keep an internal copy
+ } else {
+ serial = call->serial;
+ service = call->service;
+ }
+
+ // the reply must have a serial or be a local-loop optimization
+ Q_ASSERT(serial || localMessage);
+}
+
/*!
\since 4.3
Returns the human-readable message associated with the error that was received.
@@ -113,8 +128,8 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
case QDBusMessage::ReplyMessage:
msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_METHOD_RETURN);
if (!d_ptr->localMessage) {
- q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply));
- q_dbus_message_set_reply_serial(msg, q_dbus_message_get_serial(d_ptr->reply));
+ q_dbus_message_set_destination(msg, data(d_ptr->service.toUtf8()));
+ q_dbus_message_set_reply_serial(msg, d_ptr->serial);
}
break;
case QDBusMessage::ErrorMessage:
@@ -126,8 +141,8 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
msg = q_dbus_message_new(DBUS_MESSAGE_TYPE_ERROR);
q_dbus_message_set_error_name(msg, d_ptr->name.toUtf8());
if (!d_ptr->localMessage) {
- q_dbus_message_set_destination(msg, q_dbus_message_get_sender(d_ptr->reply));
- q_dbus_message_set_reply_serial(msg, q_dbus_message_get_serial(d_ptr->reply));
+ q_dbus_message_set_destination(msg, data(d_ptr->service.toUtf8()));
+ q_dbus_message_set_reply_serial(msg, d_ptr->serial);
}
break;
case QDBusMessage::SignalMessage:
@@ -155,14 +170,12 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
d_ptr->parametersValidated = true;
QDBusMarshaller marshaller(capabilities);
- QVariantList::ConstIterator it = d_ptr->arguments.constBegin();
- QVariantList::ConstIterator cend = d_ptr->arguments.constEnd();
q_dbus_message_iter_init_append(msg, &marshaller.iterator);
if (!d_ptr->message.isEmpty())
// prepend the error message
marshaller.append(d_ptr->message);
- for ( ; it != cend; ++it)
- marshaller.appendVariantInternal(*it);
+ for (const QVariant &argument : std::as_const(d_ptr->arguments))
+ marshaller.appendVariantInternal(argument);
// check if everything is ok
if (marshaller.ok)
@@ -206,6 +219,7 @@ QDBusMessage QDBusMessagePrivate::fromDBusMessage(DBusMessage *dmsg, QDBusConnec
return message;
message.d_ptr->type = QDBusMessage::MessageType(q_dbus_message_get_type(dmsg));
+ message.d_ptr->serial = q_dbus_message_get_serial(dmsg);
message.d_ptr->path = QString::fromUtf8(q_dbus_message_get_path(dmsg));
message.d_ptr->interface = QString::fromUtf8(q_dbus_message_get_interface(dmsg));
message.d_ptr->name = message.d_ptr->type == DBUS_MESSAGE_TYPE_ERROR ?
@@ -214,7 +228,7 @@ QDBusMessage QDBusMessagePrivate::fromDBusMessage(DBusMessage *dmsg, QDBusConnec
message.d_ptr->service = QString::fromUtf8(q_dbus_message_get_sender(dmsg));
message.d_ptr->signature = QString::fromUtf8(q_dbus_message_get_signature(dmsg));
message.d_ptr->interactiveAuthorizationAllowed = q_dbus_message_get_allow_interactive_authorization(dmsg);
- message.d_ptr->msg = q_dbus_message_ref(dmsg);
+ message.d_ptr->isReplyRequired = !q_dbus_message_get_no_reply(dmsg);
QDBusDemarshaller demarshaller(capabilities);
demarshaller.message = q_dbus_message_ref(dmsg);
@@ -239,10 +253,8 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn,
// determine if we are carrying any complex types
QString computedSignature;
- QVariantList::ConstIterator it = asSent.d_ptr->arguments.constBegin();
- QVariantList::ConstIterator end = asSent.d_ptr->arguments.constEnd();
- for ( ; it != end; ++it) {
- QMetaType id = it->metaType();
+ for (const QVariant &argument : std::as_const(asSent.d_ptr->arguments)) {
+ QMetaType id = argument.metaType();
const char *signature = QDBusMetaType::typeToSignature(id);
if ((id.id() != QMetaType::QStringList && id.id() != QMetaType::QByteArray &&
qstrlen(signature) != 1) || id == QMetaType::fromType<QDBusVariant>()) {
@@ -406,6 +418,7 @@ QDBusMessage QDBusMessage::createMethodCall(const QString &service, const QStrin
message.d_ptr->path = path;
message.d_ptr->interface = interface;
message.d_ptr->name = method;
+ message.d_ptr->isReplyRequired = true;
return message;
}
@@ -448,15 +461,7 @@ QDBusMessage QDBusMessage::createReply(const QVariantList &arguments) const
QDBusMessage reply;
reply.setArguments(arguments);
reply.d_ptr->type = ReplyMessage;
- if (d_ptr->msg)
- reply.d_ptr->reply = q_dbus_message_ref(d_ptr->msg);
- if (d_ptr->localMessage) {
- reply.d_ptr->localMessage = true;
- d_ptr->localReply = new QDBusMessage(reply); // keep an internal copy
- }
-
- // the reply must have a msg or be a local-loop optimization
- Q_ASSERT(reply.d_ptr->reply || reply.d_ptr->localMessage);
+ reply.d_ptr->createResponseLink(d_ptr);
return reply;
}
@@ -467,15 +472,7 @@ QDBusMessage QDBusMessage::createReply(const QVariantList &arguments) const
QDBusMessage QDBusMessage::createErrorReply(const QString &name, const QString &msg) const
{
QDBusMessage reply = QDBusMessage::createError(name, msg);
- if (d_ptr->msg)
- reply.d_ptr->reply = q_dbus_message_ref(d_ptr->msg);
- if (d_ptr->localMessage) {
- reply.d_ptr->localMessage = true;
- d_ptr->localReply = new QDBusMessage(reply); // keep an internal copy
- }
-
- // the reply must have a msg or be a local-loop optimization
- Q_ASSERT(reply.d_ptr->reply || reply.d_ptr->localMessage);
+ reply.d_ptr->createResponseLink(d_ptr);
return reply;
}
@@ -559,6 +556,8 @@ QDBusMessage &QDBusMessage::operator=(const QDBusMessage &other)
*/
QString QDBusMessage::service() const
{
+ if (d_ptr->type == ErrorMessage || d_ptr->type == ReplyMessage)
+ return QString(); // d_ptr->service holds the destination
return d_ptr->service;
}
@@ -621,9 +620,9 @@ bool QDBusMessage::isReplyRequired() const
if (d_ptr->type != QDBusMessage::MethodCallMessage)
return false;
- if (!d_ptr->msg)
- return d_ptr->localMessage; // if it's a local message, reply is required
- return !q_dbus_message_get_no_reply(d_ptr->msg);
+ if (d_ptr->localMessage) // if it's a local message, reply is required
+ return true;
+ return d_ptr->isReplyRequired;
}
/*!
@@ -695,20 +694,26 @@ bool QDBusMessage::autoStartService() const
}
/*!
- Sets the interactive authorization flag to \a enable.
- This flag only makes sense for method call messages, where it
- tells the D-Bus server that the caller of the method is prepared
- to wait for interactive authorization to take place (for instance
- via Polkit) before the actual method is processed.
+ Enables or disables the \c ALLOW_INTERACTIVE_AUTHORIZATION flag
+ in a message.
+
+ This flag only makes sense for method call messages
+ (\l QDBusMessage::MethodCallMessage). If \a enable
+ is set to \c true, the flag indicates to the callee that the
+ caller of the method is prepared to wait for interactive authorization
+ to take place (for instance via Polkit) before the actual method
+ is processed.
- By default this flag is false and the other end is expected to
- make any authorization decisions non-interactively and promptly.
+ If \a enable is set to \c false, the flag is not
+ set, meaning that the other end is expected to make any authorization
+ decisions non-interactively and promptly. This is the default.
The \c org.freedesktop.DBus.Error.InteractiveAuthorizationRequired
error indicates that authorization failed, but could have succeeded
if this flag had been set.
- \sa isInteractiveAuthorizationAllowed()
+ \sa isInteractiveAuthorizationAllowed(),
+ QDBusAbstractInterface::setInteractiveAuthorizationAllowed()
\since 5.12
*/
@@ -718,12 +723,11 @@ void QDBusMessage::setInteractiveAuthorizationAllowed(bool enable)
}
/*!
- Returns the interactive authorization allowed flag, as set by
- setInteractiveAuthorizationAllowed(). By default this flag
- is false and the other end is expected to make any authorization
- decisions non-interactively and promptly.
+ Returns whether the message has the
+ \c ALLOW_INTERACTIVE_AUTHORIZATION flag set.
- \sa setInteractiveAuthorizationAllowed()
+ \sa setInteractiveAuthorizationAllowed(),
+ QDBusAbstractInterface::isInteractiveAuthorizationAllowed()
\since 5.12
*/
@@ -763,6 +767,12 @@ QDBusMessage &QDBusMessage::operator<<(const QVariant &arg)
return *this;
}
+QDBusMessage::QDBusMessage(QDBusMessagePrivate &dd)
+ : d_ptr(&dd)
+{
+ d_ptr->ref.ref();
+}
+
/*!
Returns the message type.
*/
@@ -804,12 +814,10 @@ static QDebug operator<<(QDebug dbg, QDBusMessage::MessageType t)
static void debugVariantList(QDebug dbg, const QVariantList &list)
{
bool first = true;
- QVariantList::ConstIterator it = list.constBegin();
- QVariantList::ConstIterator end = list.constEnd();
- for ( ; it != end; ++it) {
+ for (const QVariant &elem : list) {
if (!first)
dbg.nospace() << ", ";
- dbg.nospace() << qPrintable(QDBusUtil::argumentToString(*it));
+ dbg.nospace() << qPrintable(QDBusUtil::argumentToString(elem));
first = false;
}
}
diff --git a/src/dbus/qdbusmessage.h b/src/dbus/qdbusmessage.h
index 644a1170e3..f6db3bc21e 100644
--- a/src/dbus/qdbusmessage.h
+++ b/src/dbus/qdbusmessage.h
@@ -84,6 +84,7 @@ public:
QDBusMessage &operator<<(const QVariant &arg);
private:
+ explicit QDBusMessage(QDBusMessagePrivate &dd);
friend class QDBusMessagePrivate;
QDBusMessagePrivate *d_ptr;
};
diff --git a/src/dbus/qdbusmessage_p.h b/src/dbus/qdbusmessage_p.h
index cca1b4bd19..88ba78025e 100644
--- a/src/dbus/qdbusmessage_p.h
+++ b/src/dbus/qdbusmessage_p.h
@@ -39,20 +39,22 @@ public:
// the following parameters are "const": they are not changed after the constructors
// the parametersValidated member below controls whether they've been validated already
+ // (service is also used to store the destination of reply-type messages)
QString service, path, interface, name, message, signature;
- DBusMessage *msg;
- DBusMessage *reply;
mutable QDBusMessage *localReply;
QAtomicInt ref;
QDBusMessage::MessageType type;
+ uint32_t serial; // if type == MethodCall; the incoming serial; if type == Reply or Error, the serial we're replying to
mutable uint delayedReply : 1;
- uint localMessage : 1;
mutable uint parametersValidated : 1;
+ uint localMessage : 1;
uint autoStartService : 1;
uint interactiveAuthorizationAllowed : 1;
+ uint isReplyRequired : 1;
+ void createResponseLink(const QDBusMessagePrivate *call);
static void setParametersValidated(QDBusMessage &msg, bool enable)
{ msg.d_ptr->parametersValidated = enable; }
diff --git a/src/dbus/qdbusmetaobject.cpp b/src/dbus/qdbusmetaobject.cpp
index c7ae280295..543b185df9 100644
--- a/src/dbus/qdbusmetaobject.cpp
+++ b/src/dbus/qdbusmetaobject.cpp
@@ -55,8 +55,9 @@ private:
QByteArray name;
};
- QMap<QByteArray, Method> signals_;
- QMap<QByteArray, Method> methods;
+ using MethodMap = QMap<QByteArray, Method>;
+ MethodMap signals_;
+ MethodMap methods;
QMap<QByteArray, Property> properties;
const QDBusIntrospection::Interface *data;
@@ -70,7 +71,7 @@ private:
void parseSignals();
void parseProperties();
- static qsizetype aggregateParameterCount(const QMap<QByteArray, Method> &map);
+ static qsizetype aggregateParameterCount(const MethodMap &map);
};
static const qsizetype intsPerProperty = 2;
@@ -147,7 +148,8 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
.arg(id);
// extract from annotations:
- QByteArray typeName = annotations.value(annotationName).toLatin1();
+ auto annotation = annotations.value(annotationName);
+ QByteArray typeName = annotation.value.toLatin1();
// verify that it's a valid one
if (typeName.isEmpty()) {
@@ -157,7 +159,8 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
annotationName += QString::fromLatin1(".%1%2")
.arg(QLatin1StringView(direction))
.arg(id);
- typeName = annotations.value(annotationName).toLatin1();
+ annotation = annotations.value(annotationName);
+ typeName = annotation.value.toLatin1();
}
if (!typeName.isEmpty()) {
@@ -208,10 +211,7 @@ void QDBusMetaObjectGenerator::parseMethods()
// Add cloned methods when the remote object has return types
//
- QDBusIntrospection::Methods::ConstIterator method_it = data->methods.constBegin();
- QDBusIntrospection::Methods::ConstIterator method_end = data->methods.constEnd();
- for ( ; method_it != method_end; ++method_it) {
- const QDBusIntrospection::Method &m = *method_it;
+ for (const QDBusIntrospection::Method &m : std::as_const(data->methods)) {
Method mm;
mm.name = m.name.toLatin1();
@@ -221,7 +221,7 @@ void QDBusMetaObjectGenerator::parseMethods()
bool ok = true;
// build the input argument list
- for (qsizetype i = 0; i < m.inputArgs.count(); ++i) {
+ for (qsizetype i = 0; i < m.inputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = m.inputArgs.at(i);
Type type = findType(arg.type.toLatin1(), m.annotations, "In", i);
@@ -240,7 +240,7 @@ void QDBusMetaObjectGenerator::parseMethods()
if (!ok) continue;
// build the output argument list:
- for (qsizetype i = 0; i < m.outputArgs.count(); ++i) {
+ for (qsizetype i = 0; i < m.outputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = m.outputArgs.at(i);
Type type = findType(arg.type.toLatin1(), m.annotations, "Out", i);
@@ -266,12 +266,12 @@ void QDBusMetaObjectGenerator::parseMethods()
// convert the last commas:
if (!mm.parameterNames.isEmpty())
- prototype[prototype.length() - 1] = ')';
+ prototype[prototype.size() - 1] = ')';
else
prototype.append(')');
// check the async tag
- if (m.annotations.value(ANNOTATION_NO_WAIT ""_L1) == "true"_L1)
+ if (m.annotations.value(ANNOTATION_NO_WAIT ""_L1).value == "true"_L1)
mm.tag = "Q_NOREPLY";
// meta method flags
@@ -284,10 +284,7 @@ void QDBusMetaObjectGenerator::parseMethods()
void QDBusMetaObjectGenerator::parseSignals()
{
- QDBusIntrospection::Signals::ConstIterator signal_it = data->signals_.constBegin();
- QDBusIntrospection::Signals::ConstIterator signal_end = data->signals_.constEnd();
- for ( ; signal_it != signal_end; ++signal_it) {
- const QDBusIntrospection::Signal &s = *signal_it;
+ for (const QDBusIntrospection::Signal &s : std::as_const(data->signals_)) {
Method mm;
mm.name = s.name.toLatin1();
@@ -297,7 +294,7 @@ void QDBusMetaObjectGenerator::parseSignals()
bool ok = true;
// build the output argument list
- for (qsizetype i = 0; i < s.outputArgs.count(); ++i) {
+ for (qsizetype i = 0; i < s.outputArgs.size(); ++i) {
const QDBusIntrospection::Argument &arg = s.outputArgs.at(i);
Type type = findType(arg.type.toLatin1(), s.annotations, "Out", i);
@@ -317,7 +314,7 @@ void QDBusMetaObjectGenerator::parseSignals()
// convert the last commas:
if (!mm.parameterNames.isEmpty())
- prototype[prototype.length() - 1] = ')';
+ prototype[prototype.size() - 1] = ')';
else
prototype.append(')');
@@ -331,10 +328,7 @@ void QDBusMetaObjectGenerator::parseSignals()
void QDBusMetaObjectGenerator::parseProperties()
{
- QDBusIntrospection::Properties::ConstIterator prop_it = data->properties.constBegin();
- QDBusIntrospection::Properties::ConstIterator prop_end = data->properties.constEnd();
- for ( ; prop_it != prop_end; ++prop_it) {
- const QDBusIntrospection::Property &p = *prop_it;
+ for (const QDBusIntrospection::Property &p : std::as_const(data->properties)) {
Property mp;
Type type = findType(p.type.toLatin1(), p.annotations);
if (type.id == QMetaType::UnknownType)
@@ -360,14 +354,11 @@ void QDBusMetaObjectGenerator::parseProperties()
// Returns the sum of all parameters (including return type) for the given
// \a map of methods. This is needed for calculating the size of the methods'
// parameter type/name meta-data.
-qsizetype QDBusMetaObjectGenerator::aggregateParameterCount(const QMap<QByteArray, Method> &map)
+qsizetype QDBusMetaObjectGenerator::aggregateParameterCount(const MethodMap &map)
{
qsizetype sum = 0;
- QMap<QByteArray, Method>::const_iterator it;
- for (it = map.constBegin(); it != map.constEnd(); ++it) {
- const Method &m = it.value();
+ for (const Method &m : map)
sum += m.inputTypes.size() + qMax(qsizetype(1), m.outputTypes.size());
- }
return sum;
}
@@ -387,18 +378,18 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
qsizetype methodParametersDataSize =
((aggregateParameterCount(signals_)
+ aggregateParameterCount(methods)) * 2) // types and parameter names
- - signals_.count() // return "parameters" don't have names
- - methods.count(); // ditto
+ - signals_.size() // return "parameters" don't have names
+ - methods.size(); // ditto
QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(idata.data());
- static_assert(QMetaObjectPrivate::OutputRevision == 10, "QtDBus meta-object generator should generate the same version as moc");
+ static_assert(QMetaObjectPrivate::OutputRevision == 12, "QtDBus meta-object generator should generate the same version as moc");
header->revision = QMetaObjectPrivate::OutputRevision;
header->className = 0;
header->classInfoCount = 0;
header->classInfoData = 0;
- header->methodCount = int(signals_.count() + methods.count());
+ header->methodCount = int(signals_.size() + methods.size());
header->methodData = int(idata.size());
- header->propertyCount = int(properties.count());
+ header->propertyCount = int(properties.size());
header->propertyData = int(header->methodData + header->methodCount *
QMetaObjectPrivate::IntsPerMethod + methodParametersDataSize);
header->enumeratorCount = 0;
@@ -406,7 +397,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
header->constructorCount = 0;
header->constructorData = 0;
header->flags = RequiresVariantMetaObject;
- header->signalCount = signals_.count();
+ header->signalCount = signals_.size();
// These are specific to QDBusMetaObject:
header->propertyDBusData = int(header->propertyData + header->propertyCount
* QMetaObjectPrivate::IntsPerProperty);
@@ -415,10 +406,14 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
qsizetype data_size = idata.size() +
(header->methodCount * (QMetaObjectPrivate::IntsPerMethod+intsPerMethod)) + methodParametersDataSize +
(header->propertyCount * (QMetaObjectPrivate::IntsPerProperty+intsPerProperty));
- for (const Method &mm : qAsConst(signals_))
- data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count();
- for (const Method &mm : qAsConst(methods))
- data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count();
+
+ // Signals must be added before other methods, to match moc.
+ std::array<std::reference_wrapper<const MethodMap>, 2> methodMaps = { signals_, methods };
+
+ for (const auto &methodMap : methodMaps) {
+ for (const Method &mm : methodMap.get())
+ data_size += 2 + mm.inputTypes.size() + mm.outputTypes.size();
+ }
idata.resize(data_size + 1);
QMetaStringTable strings(className.toLatin1());
@@ -429,11 +424,11 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
qsizetype typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod;
idata[typeidOffset++] = 0; // eod
- qsizetype totalMetaTypeCount = properties.count();
+ qsizetype totalMetaTypeCount = properties.size();
++totalMetaTypeCount; // + 1 for metatype of dynamic metaobject
- for (const auto& methodContainer: {signals_, methods}) {
- for (const auto& method: methodContainer) {
- qsizetype argc = method.inputTypes.size() + qMax(qsizetype(0), method.outputTypes.size() - 1);
+ for (const auto &methodMap : methodMaps) {
+ for (const Method &mm : methodMap.get()) {
+ qsizetype argc = mm.inputTypes.size() + qMax(qsizetype(0), mm.outputTypes.size() - 1);
totalMetaTypeCount += argc + 1;
}
}
@@ -441,14 +436,10 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
int propertyId = 0;
// add each method:
- qsizetype currentMethodMetaTypeOffset = properties.count() + 1;
- for (int x = 0; x < 2; ++x) {
- // Signals must be added before other methods, to match moc.
- QMap<QByteArray, Method> &map = (x == 0) ? signals_ : methods;
- for (QMap<QByteArray, Method>::ConstIterator it = map.constBegin();
- it != map.constEnd(); ++it) {
- const Method &mm = it.value();
+ qsizetype currentMethodMetaTypeOffset = properties.size() + 1;
+ for (const auto &methodMap : methodMaps) {
+ for (const Method &mm : methodMap.get()) {
qsizetype argc = mm.inputTypes.size() + qMax(qsizetype(0), mm.outputTypes.size() - 1);
idata[offset++] = strings.enter(mm.name);
@@ -486,7 +477,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
typeInfo = IsUnresolvedType | strings.enter(typeName);
else
typeInfo = type;
- metaTypes[currentMethodMetaTypeOffset++] = QMetaType (type);
+ metaTypes[currentMethodMetaTypeOffset++] = QMetaType(type);
idata[parametersOffset++] = typeInfo;
}
// Parameter names
@@ -494,14 +485,14 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
idata[parametersOffset++] = strings.enter(mm.parameterNames.at(i));
idata[signatureOffset++] = typeidOffset;
- idata[typeidOffset++] = mm.inputTypes.count();
- memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(uint));
- typeidOffset += mm.inputTypes.count();
+ idata[typeidOffset++] = mm.inputTypes.size();
+ memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.size() * sizeof(uint));
+ typeidOffset += mm.inputTypes.size();
idata[signatureOffset++] = typeidOffset;
- idata[typeidOffset++] = mm.outputTypes.count();
- memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(uint));
- typeidOffset += mm.outputTypes.count();
+ idata[typeidOffset++] = mm.outputTypes.size();
+ memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.size() * sizeof(uint));
+ typeidOffset += mm.outputTypes.size();
}
}
@@ -514,12 +505,9 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
// add each property
signatureOffset = header->propertyDBusData;
- for (QMap<QByteArray, Property>::ConstIterator it = properties.constBegin();
- it != properties.constEnd(); ++it) {
- const Property &mp = it.value();
-
+ for (const auto &[name, mp] : std::as_const(properties).asKeyValueRange()) {
// form is name, typeinfo, flags
- idata[offset++] = strings.enter(it.key()); // name
+ idata[offset++] = strings.enter(name);
Q_ASSERT(mp.type != QMetaType::UnknownType);
idata[offset++] = mp.type;
idata[offset++] = mp.flags;
diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp
index 6f710bab87..3ae7589480 100644
--- a/src/dbus/qdbusmetatype.cpp
+++ b/src/dbus/qdbusmetatype.cpp
@@ -48,19 +48,19 @@ public:
void QDBusMetaTypeId::init()
{
- static QBasicAtomicInt initialized = Q_BASIC_ATOMIC_INITIALIZER(false);
+ Q_CONSTINIT static QBasicAtomicInt initialized = Q_BASIC_ATOMIC_INITIALIZER(false);
// reentrancy is not a problem since everything else is locked on their own
// set the guard variable at the end
if (!initialized.loadRelaxed()) {
- // register our types with Qt Core (calling qMetaTypeId<T>() does this implicitly)
- (void)message();
- (void)argument();
- (void)variant();
- (void)objectpath();
- (void)signature();
- (void)error();
- (void)unixfd();
+ // register our types with Qt Core
+ message().registerType();
+ argument().registerType();
+ variant().registerType();
+ objectpath().registerType();
+ signature().registerType();
+ error().registerType();
+ unixfd().registerType();
#ifndef QDBUS_NO_SPECIALTYPES
// and register Qt Core's with us
@@ -87,6 +87,9 @@ void QDBusMetaTypeId::init()
qDBusRegisterMetaType<QList<qlonglong> >();
qDBusRegisterMetaType<QList<qulonglong> >();
qDBusRegisterMetaType<QList<double> >();
+
+ // plus lists of our own types
+ qDBusRegisterMetaType<QList<QDBusVariant> >();
qDBusRegisterMetaType<QList<QDBusObjectPath> >();
qDBusRegisterMetaType<QList<QDBusSignature> >();
qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >();
@@ -96,9 +99,13 @@ void QDBusMetaTypeId::init()
}
}
-using QDBusCustomTypeHash = QHash<int, QDBusCustomTypeInfo>;
-Q_GLOBAL_STATIC(QDBusCustomTypeHash, customTypes)
-Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
+struct QDBusCustomTypes
+{
+ QReadWriteLock lock;
+ QHash<int, QDBusCustomTypeInfo> hash;
+};
+
+Q_GLOBAL_STATIC(QDBusCustomTypes, customTypes)
/*!
\class QDBusMetaType
@@ -122,7 +129,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
*/
/*!
- \fn int qDBusRegisterMetaType()
+ \fn template<typename T> QMetaType qDBusRegisterMetaType()
\relates QDBusArgument
\threadsafe
\since 4.2
@@ -179,12 +186,15 @@ void QDBusMetaType::registerMarshallOperators(QMetaType metaType, MarshallFuncti
DemarshallFunction df)
{
int id = metaType.id();
- auto *ct = customTypes();
- if (id < 0 || !mf || !df || !ct)
+ if (id < 0 || !mf || !df)
return; // error!
- QWriteLocker locker(customTypesLock());
- QDBusCustomTypeInfo &info = (*ct)[id];
+ auto *ct = customTypes();
+ if (!ct)
+ return;
+
+ QWriteLocker locker(&ct->lock);
+ QDBusCustomTypeInfo &info = ct->hash[id];
info.marshall = mf;
info.demarshall = df;
}
@@ -197,15 +207,19 @@ void QDBusMetaType::registerMarshallOperators(QMetaType metaType, MarshallFuncti
*/
bool QDBusMetaType::marshall(QDBusArgument &arg, QMetaType metaType, const void *data)
{
+ auto *ct = customTypes();
+ if (!ct)
+ return false;
+
int id = metaType.id();
QDBusMetaTypeId::init();
MarshallFunction mf;
{
- QReadLocker locker(customTypesLock());
- auto *ct = customTypes();
- auto it = ct->constFind(id);
- if (it == ct->cend())
+ QReadLocker locker(&ct->lock);
+
+ auto it = ct->hash.constFind(id);
+ if (it == ct->hash.cend())
return false; // non-existent
const QDBusCustomTypeInfo &info = *it;
@@ -228,15 +242,19 @@ bool QDBusMetaType::marshall(QDBusArgument &arg, QMetaType metaType, const void
*/
bool QDBusMetaType::demarshall(const QDBusArgument &arg, QMetaType metaType, void *data)
{
+ auto *ct = customTypes();
+ if (!ct)
+ return false;
+
int id = metaType.id();
QDBusMetaTypeId::init();
DemarshallFunction df;
{
- QReadLocker locker(customTypesLock());
- auto *ct = customTypes();
- auto it = ct->constFind(id);
- if (it == ct->cend())
+ QReadLocker locker(&ct->lock);
+
+ auto it = ct->hash.constFind(id);
+ if (it == ct->hash.cend())
return false; // non-existent
const QDBusCustomTypeInfo &info = *it;
@@ -354,8 +372,11 @@ QMetaType QDBusMetaType::signatureToMetaType(const char *signature)
void QDBusMetaType::registerCustomType(QMetaType type, const QByteArray &signature)
{
auto *ct = customTypes();
- QWriteLocker locker(customTypesLock());
- auto &info = (*ct)[type.id()];
+ if (!ct)
+ return;
+
+ QWriteLocker locker(&ct->lock);
+ auto &info = ct->hash[type.id()];
info.signature = signature;
// note how marshall/demarshall are not set, the type is never used at runtime
}
@@ -427,10 +448,13 @@ const char *QDBusMetaType::typeToSignature(QMetaType type)
// try the database
auto *ct = customTypes();
+ if (!ct)
+ return nullptr;
+
{
- QReadLocker locker(customTypesLock());
- auto it = ct->constFind(type.id());
- if (it == ct->end())
+ QReadLocker locker(&ct->lock);
+ auto it = ct->hash.constFind(type.id());
+ if (it == ct->hash.end())
return nullptr;
const QDBusCustomTypeInfo &info = *it;
@@ -447,11 +471,11 @@ const char *QDBusMetaType::typeToSignature(QMetaType type)
{
// createSignature will never return a null QByteArray
// if there was an error, it'll return ""
- QByteArray signature = QDBusArgumentPrivate::createSignature(type.id());
+ QByteArray signature = QDBusArgumentPrivate::createSignature(type);
// re-acquire lock
- QWriteLocker locker(customTypesLock());
- info = &(*ct)[type.id()];
+ QWriteLocker locker(&ct->lock);
+ info = &ct->hash[type.id()];
info->signature = signature;
}
return info->signature;
diff --git a/src/dbus/qdbusmetatype_p.h b/src/dbus/qdbusmetatype_p.h
index fdae803553..86a59f587d 100644
--- a/src/dbus/qdbusmetatype_p.h
+++ b/src/dbus/qdbusmetatype_p.h
@@ -28,18 +28,17 @@
QT_BEGIN_NAMESPACE
-struct QDBusMetaTypeId
-{
- static QMetaType message(); // QDBusMessage
- static QMetaType argument(); // QDBusArgument
- static QMetaType variant(); // QDBusVariant
- static QMetaType objectpath(); // QDBusObjectPath
- static QMetaType signature(); // QDBusSignature
- static QMetaType error(); // QDBusError
- static QMetaType unixfd(); // QDBusUnixFileDescriptor
-
- static void init();
-};
+namespace QDBusMetaTypeId {
+QMetaType message(); // QDBusMessage
+QMetaType argument(); // QDBusArgument
+QMetaType variant(); // QDBusVariant
+QMetaType objectpath(); // QDBusObjectPath
+QMetaType signature(); // QDBusSignature
+QMetaType error(); // QDBusError
+QMetaType unixfd(); // QDBusUnixFileDescriptor
+
+Q_DBUS_EXPORT void init();
+}; // namespace QDBusMetaTypeId
inline QMetaType QDBusMetaTypeId::message()
{ return QMetaType::fromType<QDBusMessage>(); }
diff --git a/src/dbus/qdbusmisc.cpp b/src/dbus/qdbusmisc.cpp
index b4cdb7ed8f..635258c86d 100644
--- a/src/dbus/qdbusmisc.cpp
+++ b/src/dbus/qdbusmisc.cpp
@@ -8,6 +8,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qvariant.h>
+#include <private/qurl_p.h>
#include "qdbusutil_p.h"
#include "qdbusconnection_p.h"
@@ -52,29 +53,48 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
if (interface.startsWith("QDBus"_L1)) {
interface.prepend("org.qtproject.QtDBus."_L1);
} else if (interface.startsWith(u'Q') &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
+ interface.size() >= 2 && interface.at(1).isUpper()) {
// assume it's Qt
interface.prepend("org.qtproject.Qt."_L1);
} else if (!QCoreApplication::instance()||
QCoreApplication::instance()->applicationName().isEmpty()) {
interface.prepend("local."_L1);
- } else {
- interface.prepend(u'.').prepend(QCoreApplication::instance()->applicationName());
+ } else {
+ QString domainName = QCoreApplication::instance()->applicationName();
const QString organizationDomain = QCoreApplication::instance()->organizationDomain();
- const auto domainName = QStringView{organizationDomain}.split(u'.', Qt::SkipEmptyParts);
- if (domainName.isEmpty()) {
- interface.prepend("local."_L1);
- } else {
- QString composedDomain;
- // + 1 for additional dot, e.g. organizationDomain equals "example.com",
- // then composedDomain will be equal "com.example."
- composedDomain.reserve(organizationDomain.size() + 1);
- for (auto it = domainName.rbegin(), end = domainName.rend(); it != end; ++it)
- composedDomain += *it + u'.';
-
- interface.prepend(composedDomain);
+ if (organizationDomain.isEmpty())
+ domainName.append(".local"_L1);
+ else
+ domainName.append(u'.').append(organizationDomain);
+
+ // Domain names used to produce interface names should be IDN-encoded.
+ QString encodedDomainName = qt_ACE_do(domainName, ToAceOnly, ForbidLeadingDot);
+ if (encodedDomainName.isEmpty()) {
+ interface.prepend("local."_L1);
+ return interface;
}
- }
+
+ // Hyphens are not allowed in interface names and should be replaced
+ // by underscores.
+ encodedDomainName.replace(u'-', u'_');
+
+ auto nameParts = QStringView{ encodedDomainName }.split(u'.', Qt::SkipEmptyParts);
+
+ QString composedDomain;
+ // + 1 for additional dot, e.g. domainName equals "App.example.com",
+ // then composedDomain will be equal "com.example.App."
+ composedDomain.reserve(encodedDomainName.size() + nameParts.size() + 1);
+ for (auto it = nameParts.rbegin(), end = nameParts.rend(); it != end; ++it) {
+ // An interface name cannot start with a digit, and cannot
+ // contain digits immediately following a period. Prefix such
+ // digits with underscores.
+ if (it->first().isDigit())
+ composedDomain += u'_';
+ composedDomain += *it + u'.';
+ }
+
+ interface.prepend(composedDomain);
+ }
}
return interface;
@@ -103,7 +123,19 @@ bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
// sig must be the normalised signature for the method
int qDBusParametersForMethod(const QMetaMethod &mm, QList<QMetaType> &metaTypes, QString &errorMsg)
{
- return qDBusParametersForMethod(mm.parameterTypes(), metaTypes, errorMsg);
+ QList<QByteArray> parameterTypes;
+ parameterTypes.reserve(mm.parameterCount());
+
+ // Not using QMetaMethod::parameterTypes() since we call QMetaType::fromName below
+ // where we need any typedefs resolved already.
+ for (int i = 0; i < mm.parameterCount(); ++i) {
+ QByteArray typeName = mm.parameterMetaType(i).name();
+ if (typeName.isEmpty())
+ typeName = mm.parameterTypeName(i);
+ parameterTypes.append(typeName);
+ }
+
+ return qDBusParametersForMethod(parameterTypes, metaTypes, errorMsg);
}
#endif // QT_BOOTSTRAPPED
@@ -117,10 +149,7 @@ int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QList<QMet
metaTypes.append(QMetaType()); // return type
int inputCount = 0;
bool seenMessage = false;
- QList<QByteArray>::ConstIterator it = parameterTypes.constBegin();
- QList<QByteArray>::ConstIterator end = parameterTypes.constEnd();
- for ( ; it != end; ++it) {
- QByteArray type = *it;
+ for (QByteArray type : parameterTypes) {
if (type.endsWith('*')) {
errorMsg = "Pointers are not supported: "_L1 + QLatin1StringView(type);
return -1;
@@ -128,7 +157,7 @@ int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QList<QMet
if (type.endsWith('&')) {
QByteArray basictype = type;
- basictype.truncate(type.length() - 1);
+ basictype.truncate(type.size() - 1);
QMetaType id = QMetaType::fromName(basictype);
if (!id.isValid()) {
diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp
index 814cfa06b2..f9d414d1bd 100644
--- a/src/dbus/qdbuspendingcall.cpp
+++ b/src/dbus/qdbuspendingcall.cpp
@@ -94,7 +94,8 @@ using namespace Qt::StringLiterals;
void QDBusPendingCallWatcherHelper::add(QDBusPendingCallWatcher *watcher)
{
- connect(this, SIGNAL(finished()), watcher, SLOT(_q_finished()), Qt::QueuedConnection);
+ connect(this, &QDBusPendingCallWatcherHelper::finished, watcher,
+ [watcher] { Q_EMIT watcher->finished(watcher); }, Qt::QueuedConnection);
}
QDBusPendingCallPrivate::~QDBusPendingCallPrivate()
@@ -123,22 +124,24 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb
return false;
}
- methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes);
+ QString errorMsg;
+ methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes, errorMsg);
if (methodIdx == -1) {
QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1);
- methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes);
+ methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes, errorMsg);
}
if (methodIdx == -1) {
// would not be able to deliver a reply
- qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)",
- target->metaObject()->className(),
- member + 1, qPrintable(target->objectName()));
+ qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s) "
+ "because %s",
+ target->metaObject()->className(), member + 1, qPrintable(target->objectName()),
+ qPrintable(errorMsg));
return false;
}
// success
// construct the expected signature
- int count = metaTypes.count() - 1;
+ int count = metaTypes.size() - 1;
if (count == 1 && metaTypes.at(1) == QDBusMetaTypeId::message()) {
// wildcard slot, can receive anything, so don't set the signature
return true;
@@ -203,6 +206,26 @@ void QDBusPendingCallPrivate::waitForFinished()
waitForFinishedCondition.wait(&mutex);
}
+void QDBusPendingCallPrivate::waitForFinishedWithGui()
+{
+ QEventLoop loop;
+
+ {
+ const auto locker = qt_scoped_lock(mutex);
+ if (replyMessage.type() != QDBusMessage::InvalidMessage)
+ return; // already finished
+
+ Q_ASSERT(!watcherHelper);
+ watcherHelper = new QDBusPendingCallWatcherHelper;
+ loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::reply, &loop,
+ &QEventLoop::quit);
+ loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::error, &loop,
+ &QEventLoop::quit);
+ }
+
+ loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);
+}
+
/*!
Creates a copy of the \a other pending asynchronous call. Note
that both objects will refer to the same pending call.
@@ -221,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd)
if (dd) {
bool r = dd->ref.deref();
Q_ASSERT(r);
- Q_UNUSED(r);
}
}
@@ -443,28 +465,13 @@ QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg)
return QDBusPendingCall(d);
}
-
-class QDBusPendingCallWatcherPrivate: public QObjectPrivate
-{
-public:
- void _q_finished();
-
- Q_DECLARE_PUBLIC(QDBusPendingCallWatcher)
-};
-
-inline void QDBusPendingCallWatcherPrivate::_q_finished()
-{
- Q_Q(QDBusPendingCallWatcher);
- emit q->finished(q);
-}
-
/*!
Creates a QDBusPendingCallWatcher object to watch for replies on the
asynchronous pending call \a call and sets this object's parent
to \a parent.
*/
QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent)
- : QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call)
+ : QObject(parent), QDBusPendingCall(call)
{
if (d) { // QDBusPendingCall::d
const auto locker = qt_scoped_lock(d->mutex);
@@ -472,7 +479,9 @@ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, Q
d->watcherHelper = new QDBusPendingCallWatcherHelper;
if (d->replyMessage.type() != QDBusMessage::InvalidMessage) {
// cause a signal emission anyways
- QMetaObject::invokeMethod(d->watcherHelper, "finished", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(d->watcherHelper,
+ &QDBusPendingCallWatcherHelper::finished,
+ Qt::QueuedConnection);
}
}
d->watcherHelper->add(this);
diff --git a/src/dbus/qdbuspendingcall.h b/src/dbus/qdbuspendingcall.h
index c227186e94..c276376223 100644
--- a/src/dbus/qdbuspendingcall.h
+++ b/src/dbus/qdbuspendingcall.h
@@ -29,7 +29,7 @@ public:
void swap(QDBusPendingCall &other) noexcept { d.swap(other.d); }
-#ifndef Q_CLANG_QDOC
+#ifndef Q_QDOC
// pretend that they aren't here
bool isFinished() const;
void waitForFinished();
@@ -57,7 +57,6 @@ private:
Q_DECLARE_SHARED(QDBusPendingCall)
-class QDBusPendingCallWatcherPrivate;
class Q_DBUS_EXPORT QDBusPendingCallWatcher: public QObject, public QDBusPendingCall
{
Q_OBJECT
@@ -73,10 +72,6 @@ public:
Q_SIGNALS:
void finished(QDBusPendingCallWatcher *self = nullptr);
-
-private:
- Q_DECLARE_PRIVATE(QDBusPendingCallWatcher)
- Q_PRIVATE_SLOT(d_func(), void _q_finished())
};
QT_END_NAMESPACE
diff --git a/src/dbus/qdbuspendingcall_p.h b/src/dbus/qdbuspendingcall_p.h
index 2ba802ad85..2795cc3ecf 100644
--- a/src/dbus/qdbuspendingcall_p.h
+++ b/src/dbus/qdbuspendingcall_p.h
@@ -68,10 +68,9 @@ public:
~QDBusPendingCallPrivate();
bool setReplyCallback(QObject *target, const char *member);
void waitForFinished();
+ void waitForFinishedWithGui();
void setMetaTypes(int count, const QMetaType *types);
void checkReceivedSignature();
-
- static QDBusPendingCall fromMessage(const QDBusMessage &msg);
};
class QDBusPendingCallWatcherHelper: public QObject
diff --git a/src/dbus/qdbuspendingreply.h b/src/dbus/qdbuspendingreply.h
index 12444c6c0c..580b967b3b 100644
--- a/src/dbus/qdbuspendingreply.h
+++ b/src/dbus/qdbuspendingreply.h
@@ -81,7 +81,7 @@ public:
return qdbus_cast<ResultType>(argumentAt(Index));
}
-#if defined(Q_CLANG_QDOC)
+#if defined(Q_QDOC)
bool isFinished() const;
void waitForFinished();
QVariant argumentAt(int index) const;
diff --git a/src/dbus/qdbusreply.cpp b/src/dbus/qdbusreply.cpp
index 5fa42d40b5..5b26250b10 100644
--- a/src/dbus/qdbusreply.cpp
+++ b/src/dbus/qdbusreply.cpp
@@ -141,7 +141,7 @@ using namespace Qt::StringLiterals;
*/
/*!
- \fn template <typename T> QDBusReply<T>::value() const
+ \fn template <typename T> Type QDBusReply<T>::value() const
Returns the remote function's calls return value. If the remote call returned with an error,
the return value of this function is undefined and may be undistinguishable from a valid return
value.
@@ -169,7 +169,7 @@ void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data
return;
}
- if (reply.arguments().count() >= 1 && reply.arguments().at(0).metaType() == data.metaType()) {
+ if (reply.arguments().size() >= 1 && reply.arguments().at(0).metaType() == data.metaType()) {
data = reply.arguments().at(0);
return;
}
@@ -178,7 +178,7 @@ void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data
const char *receivedType = nullptr;
QByteArray receivedSignature;
- if (reply.arguments().count() >= 1) {
+ if (reply.arguments().size() >= 1) {
if (reply.arguments().at(0).metaType() == QDBusMetaTypeId::argument()) {
// compare signatures instead
QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));
diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp
index ebff0b559c..e9131a14c4 100644
--- a/src/dbus/qdbusserver.cpp
+++ b/src/dbus/qdbusserver.cpp
@@ -38,9 +38,8 @@ QDBusServer::QDBusServer(const QString &address, QObject *parent)
if (!instance)
return;
- emit instance->serverRequested(address, this);
- QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)),
- this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection);
+ instance->createServer(address, this);
+ Q_ASSERT(d != nullptr);
}
/*!
@@ -49,25 +48,15 @@ QDBusServer::QDBusServer(const QString &address, QObject *parent)
localhost (elsewhere).
*/
QDBusServer::QDBusServer(QObject *parent)
- : QObject(parent), d(nullptr)
-{
+ : QDBusServer(
#ifdef Q_OS_UNIX
- // Use Unix sockets on Unix systems only
- const QString address = QStringLiteral("unix:tmpdir=/tmp");
+ // Use Unix sockets on Unix systems only
+ QStringLiteral("unix:tmpdir=/tmp"),
#else
- const QString address = QStringLiteral("tcp:");
+ QStringLiteral("tcp:"),
#endif
-
- if (!qdbus_loadLibDBus())
- return;
-
- QDBusConnectionManager *instance = QDBusConnectionManager::instance();
- if (!instance)
- return;
-
- emit instance->serverRequested(address, this);
- QObject::connect(d, SIGNAL(newServerConnection(QDBusConnectionPrivate*)),
- this, SLOT(_q_newConnection(QDBusConnectionPrivate*)), Qt::QueuedConnection);
+ parent)
+{
}
/*!
@@ -75,17 +64,17 @@ QDBusServer::QDBusServer(QObject *parent)
*/
QDBusServer::~QDBusServer()
{
- QMutex *managerMutex = nullptr;
- if (QDBusConnectionManager::instance())
- managerMutex = &QDBusConnectionManager::instance()->mutex;
- QMutexLocker locker(managerMutex);
+ if (!d)
+ return;
+
+ auto manager = QDBusConnectionManager::instance();
+ if (!manager)
+ return;
+
QWriteLocker writeLocker(&d->lock);
- if (QDBusConnectionManager::instance()) {
- for (const QString &name : qAsConst(d->serverConnectionNames))
- QDBusConnectionManager::instance()->removeConnection(name);
- d->serverConnectionNames.clear();
- locker.unlock();
- }
+ manager->removeConnections(d->serverConnectionNames);
+ d->serverConnectionNames.clear();
+
d->serverObject = nullptr;
d->ref.storeRelaxed(0);
d->deleteLater();
@@ -138,6 +127,9 @@ QString QDBusServer::address() const
*/
void QDBusServer::setAnonymousAuthenticationAllowed(bool value)
{
+ if (!d)
+ return;
+
d->anonymousAuthenticationAllowed = value;
}
@@ -150,6 +142,9 @@ void QDBusServer::setAnonymousAuthenticationAllowed(bool value)
*/
bool QDBusServer::isAnonymousAuthenticationAllowed() const
{
+ if (!d)
+ return false;
+
return d->anonymousAuthenticationAllowed;
}
diff --git a/src/dbus/qdbusserver.h b/src/dbus/qdbusserver.h
index b482314319..34985cc055 100644
--- a/src/dbus/qdbusserver.h
+++ b/src/dbus/qdbusserver.h
@@ -37,7 +37,6 @@ Q_SIGNALS:
private:
Q_DISABLE_COPY(QDBusServer)
- Q_PRIVATE_SLOT(d, void _q_newConnection(QDBusConnectionPrivate*))
QDBusConnectionPrivate *d;
friend class QDBusConnectionPrivate;
};
diff --git a/src/dbus/qdbusservicewatcher.cpp b/src/dbus/qdbusservicewatcher.cpp
index 835a7cd3ac..bf94f54f56 100644
--- a/src/dbus/qdbusservicewatcher.cpp
+++ b/src/dbus/qdbusservicewatcher.cpp
@@ -40,10 +40,11 @@ public:
&QDBusServiceWatcherPrivate::setWatchModeForwardToQ)
void _q_serviceOwnerChanged(const QString &, const QString &, const QString &);
- void setConnection(const QStringList &services, const QDBusConnection &c, QDBusServiceWatcher::WatchMode watchMode);
+ void setConnection(const QStringList &newServices, const QDBusConnection &newConnection,
+ QDBusServiceWatcher::WatchMode newMode);
- void addService(const QString &service);
- void removeService(const QString &service);
+ void addService(const QString &service, QDBusServiceWatcher::WatchMode mode);
+ void removeService(const QString &service, QDBusServiceWatcher::WatchMode mode);
};
void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(const QString &service, const QString &oldOwner, const QString &newOwner)
@@ -56,39 +57,43 @@ void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(const QString &service,
emit q->serviceUnregistered(service);
}
-void QDBusServiceWatcherPrivate::setConnection(const QStringList &services,
- const QDBusConnection &c,
- QDBusServiceWatcher::WatchMode wm)
+void QDBusServiceWatcherPrivate::setConnection(const QStringList &newServices,
+ const QDBusConnection &newConnection,
+ QDBusServiceWatcher::WatchMode newMode)
{
+ const QStringList oldServices = watchedServicesData.valueBypassingBindings();
+ const QDBusServiceWatcher::WatchMode oldMode = watchMode.valueBypassingBindings();
if (connection.isConnected()) {
// remove older rules
- for (const QString &s : qAsConst(watchedServicesData.value()))
- removeService(s);
+ for (const QString &s : oldServices)
+ removeService(s, oldMode);
}
- connection = c;
- watchMode.setValueBypassingBindings(wm); // caller has to call notify()
- watchedServicesData.setValueBypassingBindings(services); // caller has to call notify()
+ connection = newConnection;
+ watchMode.setValueBypassingBindings(newMode); // caller has to call notify()
+ watchedServicesData.setValueBypassingBindings(newServices); // caller has to call notify()
if (connection.isConnected()) {
// add new rules
- for (const QString &s : qAsConst(watchedServicesData.value()))
- addService(s);
+ for (const QString &s : newServices)
+ addService(s, newMode);
}
}
-void QDBusServiceWatcherPrivate::addService(const QString &service)
+void QDBusServiceWatcherPrivate::addService(const QString &service,
+ QDBusServiceWatcher::WatchMode mode)
{
QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
if (d && d->shouldWatchService(service))
- d->watchService(service, watchMode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ d->watchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
}
-void QDBusServiceWatcherPrivate::removeService(const QString &service)
+void QDBusServiceWatcherPrivate::removeService(const QString &service,
+ QDBusServiceWatcher::WatchMode mode)
{
QDBusConnectionPrivate *d = QDBusConnectionPrivate::d(connection);
if (d && d->shouldWatchService(service))
- d->unwatchService(service, watchMode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
+ d->unwatchService(service, mode, q_func(), SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
}
/*!
@@ -260,8 +265,9 @@ void QDBusServiceWatcher::setWatchedServices(const QStringList &services)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- if (services == d->watchedServicesData)
+ if (services == d->watchedServicesData.valueBypassingBindings())
return;
+ // trigger watchMode re-evaluation, but only once for the setter
d->setConnection(services, d->connection, d->watchMode);
d->watchedServicesData.notify();
}
@@ -283,13 +289,14 @@ void QDBusServiceWatcher::addWatchedService(const QString &newService)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- if (d->watchedServicesData.value().contains(newService))
+ auto services = d->watchedServicesData.valueBypassingBindings();
+ if (services.contains(newService))
return;
- d->addService(newService);
+ // re-evaluate watch mode
+ d->addService(newService, d->watchMode);
- auto templist = d->watchedServicesData.valueBypassingBindings();
- templist << newService;
- d->watchedServicesData.setValueBypassingBindings(templist);
+ services << newService;
+ d->watchedServicesData.setValueBypassingBindings(services);
d->watchedServicesData.notify();
}
@@ -308,17 +315,16 @@ bool QDBusServiceWatcher::removeWatchedService(const QString &service)
{
Q_D(QDBusServiceWatcher);
d->watchedServicesData.removeBindingUnlessInWrapper();
- d->removeService(service);
- auto tempList = d->watchedServicesData.value();
- bool result = tempList.removeOne(service);
- if (result) {
- d->watchedServicesData.setValueBypassingBindings(tempList);
- d->watchedServicesData.notify();
- return true;
- } else {
- // nothing changed
- return false;
- }
+ auto tempList = d->watchedServicesData.valueBypassingBindings();
+ const bool result = tempList.removeOne(service);
+ if (!result)
+ return false; // nothing changed
+
+ // re-evaluate watch mode
+ d->removeService(service, d->watchMode);
+ d->watchedServicesData.setValueBypassingBindings(tempList);
+ d->watchedServicesData.notify();
+ return true;
}
QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode() const
@@ -335,8 +341,9 @@ void QDBusServiceWatcher::setWatchMode(WatchMode mode)
{
Q_D(QDBusServiceWatcher);
d->watchMode.removeBindingUnlessInWrapper();
- if (mode == d->watchMode.value())
+ if (mode == d->watchMode.valueBypassingBindings())
return;
+ // trigger watchedServicesData re-evaluation, but only once for the setter
d->setConnection(d->watchedServicesData, d->connection, mode);
d->watchMode.notify();
}
diff --git a/src/dbus/qdbusthreaddebug_p.h b/src/dbus/qdbusthreaddebug_p.h
index 73be3d7517..a1d3a420ec 100644
--- a/src/dbus/qdbusthreaddebug_p.h
+++ b/src/dbus/qdbusthreaddebug_p.h
@@ -93,7 +93,7 @@ struct QDBusReadLocker: QDBusLockerBase
{
QDBusConnectionPrivate *self;
ThreadAction action;
- inline QDBusReadLocker(ThreadAction a, QDBusConnectionPrivate *s)
+ Q_NODISCARD_CTOR QDBusReadLocker(ThreadAction a, QDBusConnectionPrivate *s)
: self(s), action(a)
{
reportThreadAction(action, BeforeLock, self);
@@ -113,7 +113,7 @@ struct QDBusWriteLocker: QDBusLockerBase
{
QDBusConnectionPrivate *self;
ThreadAction action;
- inline QDBusWriteLocker(ThreadAction a, QDBusConnectionPrivate *s)
+ Q_NODISCARD_CTOR QDBusWriteLocker(ThreadAction a, QDBusConnectionPrivate *s)
: self(s), action(a)
{
reportThreadAction(action, BeforeLock, self);
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp
index 4770d25e99..827418c487 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -7,6 +7,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
+#include <private/qtools_p.h>
#include "qdbusargument.h"
#include "qdbusunixfiledescriptor.h"
@@ -16,29 +17,24 @@
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
+using namespace QtMiscUtils;
static inline bool isValidCharacterNoDash(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
- || (u == '_');
+ return isAsciiLetterOrNumber(u) || (u == '_');
}
static inline bool isValidCharacter(QChar c)
{
ushort u = c.unicode();
- return (u >= 'a' && u <= 'z')
- || (u >= 'A' && u <= 'Z')
- || (u >= '0' && u <= '9')
+ return isAsciiLetterOrNumber(u)
|| (u == '_') || (u == '-');
}
static inline bool isValidNumber(QChar c)
{
- ushort u = c.unicode();
- return (u >= '0' && u <= '9');
+ return (isAsciiDigit(c.toLatin1()));
}
#ifndef QT_BOOTSTRAPPED
@@ -59,7 +55,7 @@ static bool variantToString(const QVariant &arg, QString &out)
} else if (argType == QMetaType::QByteArray) {
out += u'{';
QByteArray list = arg.toByteArray();
- for (int i = 0; i < list.length(); ++i) {
+ for (int i = 0; i < list.size(); ++i) {
out += QString::number(list.at(i));
out += ", "_L1;
}
@@ -210,6 +206,21 @@ static const char oneLetterTypes[] = "vsogybnqiuxtdh";
static const char basicTypes[] = "sogybnqiuxtdh";
static const char fixedTypes[] = "ybnqiuxtdh";
+/*
+ D-Bus signature grammar (in ABNF), as of 0.42 (2023-08-21):
+ https://dbus.freedesktop.org/doc/dbus-specification.html#type-system
+
+ <signature> = *<single-complete-type>
+ <single-complete-type> = <basic-type> / <variant> / <struct> / <array>
+ <fixed-type> = "y" / "b" / "n" / "q" / "i" / "u" / "x" / "t" / "d" / "h"
+ <variable-length-type> = "s" / "o" / "g"
+ <basic-type> = <variable-length-type> / <fixed-type>
+ <variant> = "v"
+ <struct> = "(" 1*<single-complete-type> ")"
+ <array> = "a" ( <single-complete-type> / <dict-entry> )
+ <dict-entry> = "{" <basic-type> <single-complete-type> "}"
+*/
+
static bool isBasicType(int c)
{
return c != DBUS_TYPE_INVALID && strchr(basicTypes, c) != nullptr;
@@ -306,7 +317,7 @@ namespace QDBusUtil
return false; // can't be valid if it's empty
const QChar *c = part.data();
- for (int i = 0; i < part.length(); ++i)
+ for (int i = 0; i < part.size(); ++i)
if (!isValidCharacterNoDash(c[i]))
return false;
@@ -314,13 +325,6 @@ namespace QDBusUtil
}
/*!
- \internal
- \fn bool isValidPartOfObjectPath(const QString &part)
-
- \overload
- */
-
- /*!
\fn bool isValidInterfaceName(const QString &ifaceName)
Returns \c true if this is \a ifaceName is a valid interface name.
@@ -335,11 +339,11 @@ namespace QDBusUtil
*/
bool isValidInterfaceName(const QString& ifaceName)
{
- if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
+ if (ifaceName.isEmpty() || ifaceName.size() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
const auto parts = QStringView{ifaceName}.split(u'.');
- if (parts.count() < 2)
+ if (parts.size() < 2)
return false; // at least two parts
for (auto part : parts)
@@ -358,12 +362,12 @@ namespace QDBusUtil
*/
bool isValidUniqueConnectionName(QStringView connName)
{
- if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
+ if (connName.isEmpty() || connName.size() > DBUS_MAXIMUM_NAME_LENGTH ||
!connName.startsWith(u':'))
return false;
const auto parts = connName.mid(1).split(u'.');
- if (parts.count() < 1)
+ if (parts.size() < 1)
return false;
for (QStringView part : parts) {
@@ -371,7 +375,7 @@ namespace QDBusUtil
return false;
const QChar* c = part.data();
- for (int j = 0; j < part.length(); ++j)
+ for (int j = 0; j < part.size(); ++j)
if (!isValidCharacter(c[j]))
return false;
}
@@ -380,12 +384,6 @@ namespace QDBusUtil
}
/*!
- \fn bool isValidUniqueConnectionName(const QString &connName)
-
- \overload
- */
-
- /*!
\fn bool isValidBusName(const QString &busName)
Returns \c true if \a busName is a valid bus name.
@@ -402,16 +400,13 @@ namespace QDBusUtil
*/
bool isValidBusName(const QString &busName)
{
- if (busName.isEmpty() || busName.length() > DBUS_MAXIMUM_NAME_LENGTH)
+ if (busName.isEmpty() || busName.size() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
if (busName.startsWith(u':'))
return isValidUniqueConnectionName(busName);
const auto parts = QStringView{busName}.split(u'.');
- if (parts.count() < 1)
- return false;
-
for (QStringView part : parts) {
if (part.isEmpty())
return false;
@@ -419,7 +414,7 @@ namespace QDBusUtil
const QChar *c = part.data();
if (isValidNumber(c[0]))
return false;
- for (int j = 0; j < part.length(); ++j)
+ for (int j = 0; j < part.size(); ++j)
if (!isValidCharacter(c[j]))
return false;
}
@@ -435,25 +430,19 @@ namespace QDBusUtil
*/
bool isValidMemberName(QStringView memberName)
{
- if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
+ if (memberName.isEmpty() || memberName.size() > DBUS_MAXIMUM_NAME_LENGTH)
return false;
const QChar* c = memberName.data();
if (isValidNumber(c[0]))
return false;
- for (int j = 0; j < memberName.length(); ++j)
+ for (int j = 0; j < memberName.size(); ++j)
if (!isValidCharacterNoDash(c[j]))
return false;
return true;
}
/*!
- \fn bool isValidMemberName(const QString &memberName)
-
- \overload
- */
-
- /*!
\fn bool isValidErrorName(const QString &errorName)
Returns \c true if \a errorName is a valid error name. Valid error names are valid interface
names and vice-versa, so this function is actually an alias for isValidInterfaceName.
@@ -471,9 +460,8 @@ namespace QDBusUtil
\list
\li start with the slash character ("/")
\li do not end in a slash, unless the path is just the initial slash
- \li do not contain any two slashes in sequence
- \li contain slash-separated parts, each of which is composed of ASCII letters, digits and
- underscores ("_")
+ \li contain slash-separated parts, each of which is not empty, and composed
+ only of ASCII letters, digits and underscores ("_").
\endlist
*/
bool isValidObjectPath(const QString &path)
diff --git a/src/dbus/qdbusutil_p.h b/src/dbus/qdbusutil_p.h
index 4df6f9ccba..3db9384968 100644
--- a/src/dbus/qdbusutil_p.h
+++ b/src/dbus/qdbusutil_p.h
@@ -27,7 +27,7 @@
QT_BEGIN_NAMESPACE
-#define Q_DBUS_NO_EXPORT // force findclasslist.pl looking into this namespace
+#define Q_DBUS_NO_EXPORT // force syncqt looking into this namespace
namespace Q_DBUS_NO_EXPORT QDBusUtil
{
Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
diff --git a/src/dbus/qdbusxmlgenerator.cpp b/src/dbus/qdbusxmlgenerator.cpp
index f3a583dc22..412ac18095 100644
--- a/src/dbus/qdbusxmlgenerator.cpp
+++ b/src/dbus/qdbusxmlgenerator.cpp
@@ -151,7 +151,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
qWarning() << "Skipped method" << mm.name() << ":" << qPrintable(errorMsg);
continue; // invalid form
}
- if (isSignal && inputCount + 1 != types.count())
+ if (isSignal && inputCount + 1 != types.size())
continue; // signal with output arguments?
if (isSignal && types.at(inputCount) == QDBusMetaTypeId::message())
continue; // signal with QDBusMessage argument?
@@ -159,7 +159,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
continue; // cloned signal?
int j;
- for (j = 1; j < types.count(); ++j) {
+ for (j = 1; j < types.size(); ++j) {
// input parameter for a slot or output for a signal
if (types.at(j) == QDBusMetaTypeId::message()) {
isScriptable = true;
@@ -228,56 +228,6 @@ QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
return " <interface name=\"%1\">\n%2 </interface>\n"_L1
.arg(interface, xml);
}
-#if 0
-QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo, const QMetaObject *base,
- int flags)
-{
- if (interface.isEmpty()) {
- // generate the interface name from the meta object
- int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
- if (idx >= mo->classInfoOffset()) {
- interface = QLatin1StringView(mo->classInfo(idx).value());
- } else {
- interface = QLatin1StringView(mo->className());
- interface.replace("::"_L1, "."_L1);
-
- if (interface.startsWith("QDBus"_L1)) {
- interface.prepend("org.qtproject.QtDBus."_L1);
- } else if (interface.startsWith(u'Q') &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
- // assume it's Qt
- interface.prepend("org.qtproject.Qt."_L1);
- } else if (!QCoreApplication::instance()||
- QCoreApplication::instance()->applicationName().isEmpty()) {
- interface.prepend("local."_L1);
- } else {
- interface.prepend(u'.').prepend(QCoreApplication::instance()->applicationName());
- QStringList domainName =
- QCoreApplication::instance()->organizationDomain().split(u'.',
- Qt::SkipEmptyParts);
- if (domainName.isEmpty())
- interface.prepend("local."_L1);
- else
- for (int i = 0; i < domainName.count(); ++i)
- interface.prepend(u'.').prepend(domainName.at(i));
- }
- }
- }
-
- QString xml;
- int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTROSPECTION);
- if (idx >= mo->classInfoOffset())
- return QString::fromUtf8(mo->classInfo(idx).value());
- else
- xml = generateInterfaceXml(mo, flags, base->methodCount(), base->propertyCount());
-
- if (xml.isEmpty())
- return QString(); // don't add an empty interface
- return QString::fromLatin1(" <interface name=\"%1\">\n%2 </interface>\n")
- .arg(interface, xml);
-}
-
-#endif
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusxmlparser.cpp b/src/dbus/qdbusxmlparser.cpp
index 509ca6e77c..c2e8df8be7 100644
--- a/src/dbus/qdbusxmlparser.cpp
+++ b/src/dbus/qdbusxmlparser.cpp
@@ -7,7 +7,6 @@
#include <QtCore/qmap.h>
#include <QtCore/qvariant.h>
#include <QtCore/qtextstream.h>
-#include <QtCore/qxmlstream.h>
#include <QtCore/qdebug.h>
#ifndef QT_NO_DBUS
@@ -18,67 +17,89 @@ using namespace Qt::StringLiterals;
Q_LOGGING_CATEGORY(dbusParser, "dbus.parser", QtWarningMsg)
-#define qDBusParserError(...) qCDebug(dbusParser, ##__VA_ARGS__)
-
-static bool parseArg(const QXmlStreamAttributes &attributes, QDBusIntrospection::Argument &argData,
- QDBusIntrospection::Interface *ifaceData)
+#define qDBusParserWarning(format, ...) \
+ do { \
+ if (m_reporter) \
+ m_reporter->warning(m_currentLocation, format "\n", ##__VA_ARGS__); \
+ else \
+ qCDebug(dbusParser, "Warning: " format, ##__VA_ARGS__); \
+ } while (0)
+
+#define qDBusParserError(format, ...) \
+ do { \
+ if (m_reporter) \
+ m_reporter->error(m_currentLocation, format "\n", ##__VA_ARGS__); \
+ else \
+ qCDebug(dbusParser, "Error: " format, ##__VA_ARGS__); \
+ } while (0)
+
+bool QDBusXmlParser::parseArg(const QXmlStreamAttributes &attributes,
+ QDBusIntrospection::Argument &argData)
{
+ Q_ASSERT(m_currentInterface);
+
const QString argType = attributes.value("type"_L1).toString();
bool ok = QDBusUtil::isValidSingleSignature(argType);
if (!ok) {
- qDBusParserError("Invalid D-BUS type signature '%s' found while parsing introspection",
- qPrintable(argType));
+ qDBusParserError("Invalid D-Bus type signature '%s' found while parsing introspection",
+ qPrintable(argType));
}
argData.name = attributes.value("name"_L1).toString();
argData.type = argType;
- ifaceData->introspection += " <arg"_L1;
+ m_currentInterface->introspection += " <arg"_L1;
if (attributes.hasAttribute("direction"_L1)) {
const QString direction = attributes.value("direction"_L1).toString();
- ifaceData->introspection += " direction=\""_L1 + direction + u'"';
+ m_currentInterface->introspection += " direction=\""_L1 + direction + u'"';
}
- ifaceData->introspection += " type=\""_L1 + argData.type + u'"';
+ m_currentInterface->introspection += " type=\""_L1 + argData.type + u'"';
if (!argData.name.isEmpty())
- ifaceData->introspection += " name=\""_L1 + argData.name + u'"';
- ifaceData->introspection += "/>\n"_L1;
+ m_currentInterface->introspection += " name=\""_L1 + argData.name + u'"';
+ m_currentInterface->introspection += "/>\n"_L1;
return ok;
}
-static bool parseAnnotation(const QXmlStreamReader &xml, QDBusIntrospection::Annotations &annotations,
- QDBusIntrospection::Interface *ifaceData, bool interfaceAnnotation = false)
+bool QDBusXmlParser::parseAnnotation(QDBusIntrospection::Annotations &annotations,
+ bool interfaceAnnotation)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == "annotation"_L1);
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "annotation"_L1);
- const QXmlStreamAttributes attributes = xml.attributes();
- const QString name = attributes.value("name"_L1).toString();
+ QDBusIntrospection::Annotation annotation;
+ annotation.location = m_currentLocation;
- if (!QDBusUtil::isValidInterfaceName(name)) {
- qDBusParserError("Invalid D-BUS annotation '%s' found while parsing introspection",
- qPrintable(name));
+ const QXmlStreamAttributes attributes = m_xml.attributes();
+ annotation.name = attributes.value("name"_L1).toString();
+
+ if (!QDBusUtil::isValidInterfaceName(annotation.name)) {
+ qDBusParserError("Invalid D-Bus annotation '%s' found while parsing introspection",
+ qPrintable(annotation.name));
return false;
}
- const QString value = attributes.value("value"_L1).toString();
- annotations.insert(name, value);
+ annotation.value = attributes.value("value"_L1).toString();
+ annotations.insert(annotation.name, annotation);
if (!interfaceAnnotation)
- ifaceData->introspection += " "_L1;
- ifaceData->introspection += " <annotation value=\""_L1 + value.toHtmlEscaped() + "\" name=\""_L1 + name + "\"/>\n"_L1;
+ m_currentInterface->introspection += " "_L1;
+ m_currentInterface->introspection += " <annotation value=\""_L1
+ + annotation.value.toHtmlEscaped() + "\" name=\""_L1 + annotation.name + "\"/>\n"_L1;
return true;
}
-static bool parseProperty(QXmlStreamReader &xml, QDBusIntrospection::Property &propertyData,
- QDBusIntrospection::Interface *ifaceData)
+bool QDBusXmlParser::parseProperty(QDBusIntrospection::Property &propertyData)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == "property"_L1);
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "property"_L1);
- QXmlStreamAttributes attributes = xml.attributes();
+ QXmlStreamAttributes attributes = m_xml.attributes();
const QString propertyName = attributes.value("name"_L1).toString();
if (!QDBusUtil::isValidMemberName(propertyName)) {
- qDBusParserError("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
- qPrintable(propertyName), qPrintable(ifaceData->name));
- xml.skipCurrentElement();
+ qDBusParserWarning("Invalid D-Bus member name '%s' found in interface '%s' while parsing "
+ "introspection",
+ qPrintable(propertyName), qPrintable(m_currentInterface->name));
+ m_xml.skipCurrentElement();
return false;
}
@@ -88,9 +109,10 @@ static bool parseProperty(QXmlStreamReader &xml, QDBusIntrospection::Property &p
if (!QDBusUtil::isValidSingleSignature(propertyData.type)) {
// cannot be!
- qDBusParserError("Invalid D-BUS type signature '%s' found in property '%s.%s' while parsing introspection",
- qPrintable(propertyData.type), qPrintable(ifaceData->name),
- qPrintable(propertyName));
+ qDBusParserError("Invalid D-Bus type signature '%s' found in property '%s.%s' while "
+ "parsing introspection",
+ qPrintable(propertyData.type), qPrintable(m_currentInterface->name),
+ qPrintable(propertyName));
}
const QString access = attributes.value("access"_L1).toString();
@@ -101,85 +123,90 @@ static bool parseProperty(QXmlStreamReader &xml, QDBusIntrospection::Property &p
else if (access == "readwrite"_L1)
propertyData.access = QDBusIntrospection::Property::ReadWrite;
else {
- qDBusParserError("Invalid D-BUS property access '%s' found in property '%s.%s' while parsing introspection",
- qPrintable(access), qPrintable(ifaceData->name),
- qPrintable(propertyName));
+ qDBusParserError("Invalid D-Bus property access '%s' found in property '%s.%s' while "
+ "parsing introspection",
+ qPrintable(access), qPrintable(m_currentInterface->name),
+ qPrintable(propertyName));
return false; // invalid one!
}
- ifaceData->introspection += " <property access=\""_L1 + access + "\" type=\""_L1 + propertyData.type + "\" name=\""_L1 + propertyName + u'"';
+ m_currentInterface->introspection += " <property access=\""_L1 + access + "\" type=\""_L1 + propertyData.type + "\" name=\""_L1 + propertyName + u'"';
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += "/>\n"_L1;
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += ">\n"_L1;
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == "annotation"_L1) {
- parseAnnotation(xml, propertyData.annotations, ifaceData);
- } else if (xml.prefix().isEmpty()) {
- qDBusParserError() << "Unknown element" << xml.name() << "while checking for annotations";
+ if (m_xml.name() == "annotation"_L1) {
+ parseAnnotation(propertyData.annotations);
+ } else if (m_xml.prefix().isEmpty()) {
+ qDBusParserWarning("Unknown element '%s' while checking for annotations",
+ qPrintable(m_xml.name().toString()));
}
- xml.skipCurrentElement();
- } while (xml.readNextStartElement());
+ m_xml.skipCurrentElement();
+ } while (readNextStartElement());
- ifaceData->introspection += " </property>\n"_L1;
+ m_currentInterface->introspection += " </property>\n"_L1;
}
- if (!xml.isEndElement() || xml.name() != "property"_L1) {
- qDBusParserError() << "Invalid property specification" << xml.tokenString() << xml.name();
+ if (!m_xml.isEndElement() || m_xml.name() != "property"_L1) {
+ qDBusParserError("Invalid property specification: '%s'", qPrintable(m_xml.tokenString()));
return false;
}
return true;
}
-static bool parseMethod(QXmlStreamReader &xml, QDBusIntrospection::Method &methodData,
- QDBusIntrospection::Interface *ifaceData)
+bool QDBusXmlParser::parseMethod(QDBusIntrospection::Method &methodData)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == "method"_L1);
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "method"_L1);
- const QXmlStreamAttributes attributes = xml.attributes();
+ const QXmlStreamAttributes attributes = m_xml.attributes();
const QString methodName = attributes.value("name"_L1).toString();
if (!QDBusUtil::isValidMemberName(methodName)) {
- qDBusParserError("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
- qPrintable(methodName), qPrintable(ifaceData->name));
+ qDBusParserError("Invalid D-Bus member name '%s' found in interface '%s' while parsing "
+ "introspection",
+ qPrintable(methodName), qPrintable(m_currentInterface->name));
return false;
}
methodData.name = methodName;
- ifaceData->introspection += " <method name=\""_L1 + methodName + u'"';
+ m_currentInterface->introspection += " <method name=\""_L1 + methodName + u'"';
QDBusIntrospection::Arguments outArguments;
QDBusIntrospection::Arguments inArguments;
QDBusIntrospection::Annotations annotations;
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += "/>\n"_L1;
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += ">\n"_L1;
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == "annotation"_L1) {
- parseAnnotation(xml, annotations, ifaceData);
- } else if (xml.name() == "arg"_L1) {
- const QXmlStreamAttributes attributes = xml.attributes();
+ if (m_xml.name() == "annotation"_L1) {
+ parseAnnotation(annotations);
+ } else if (m_xml.name() == "arg"_L1) {
+ const QXmlStreamAttributes attributes = m_xml.attributes();
const QString direction = attributes.value("direction"_L1).toString();
QDBusIntrospection::Argument argument;
+ argument.location = m_currentLocation;
if (!attributes.hasAttribute("direction"_L1) || direction == "in"_L1) {
- parseArg(attributes, argument, ifaceData);
+ parseArg(attributes, argument);
inArguments << argument;
} else if (direction == "out"_L1) {
- parseArg(attributes, argument, ifaceData);
+ parseArg(attributes, argument);
outArguments << argument;
}
- } else if (xml.prefix().isEmpty()) {
- qDBusParserError() << "Unknown element" << xml.name() << "while checking for method arguments";
+ } else if (m_xml.prefix().isEmpty()) {
+ qDBusParserWarning("Unknown element '%s' while checking for method arguments",
+ qPrintable(m_xml.name().toString()));
}
- xml.skipCurrentElement();
- } while (xml.readNextStartElement());
+ m_xml.skipCurrentElement();
+ } while (readNextStartElement());
- ifaceData->introspection += " </method>\n"_L1;
+ m_currentInterface->introspection += " </method>\n"_L1;
}
methodData.inputArgs = inArguments;
@@ -189,50 +216,52 @@ static bool parseMethod(QXmlStreamReader &xml, QDBusIntrospection::Method &metho
return true;
}
-
-static bool parseSignal(QXmlStreamReader &xml, QDBusIntrospection::Signal &signalData,
- QDBusIntrospection::Interface *ifaceData)
+bool QDBusXmlParser::parseSignal(QDBusIntrospection::Signal &signalData)
{
- Q_ASSERT(xml.isStartElement() && xml.name() == "signal"_L1);
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "signal"_L1);
- const QXmlStreamAttributes attributes = xml.attributes();
+ const QXmlStreamAttributes attributes = m_xml.attributes();
const QString signalName = attributes.value("name"_L1).toString();
if (!QDBusUtil::isValidMemberName(signalName)) {
- qDBusParserError("Invalid D-BUS member name '%s' found in interface '%s' while parsing introspection",
- qPrintable(signalName), qPrintable(ifaceData->name));
+ qDBusParserError("Invalid D-Bus member name '%s' found in interface '%s' while parsing "
+ "introspection",
+ qPrintable(signalName), qPrintable(m_currentInterface->name));
return false;
}
signalData.name = signalName;
- ifaceData->introspection += " <signal name=\""_L1 + signalName + u'"';
+ m_currentInterface->introspection += " <signal name=\""_L1 + signalName + u'"';
QDBusIntrospection::Arguments arguments;
QDBusIntrospection::Annotations annotations;
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += "/>\n"_L1;
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += ">\n"_L1;
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == "annotation"_L1) {
- parseAnnotation(xml, annotations, ifaceData);
- } else if (xml.name() == "arg"_L1) {
- const QXmlStreamAttributes attributes = xml.attributes();
+ if (m_xml.name() == "annotation"_L1) {
+ parseAnnotation(annotations);
+ } else if (m_xml.name() == "arg"_L1) {
+ const QXmlStreamAttributes attributes = m_xml.attributes();
QDBusIntrospection::Argument argument;
+ argument.location = m_currentLocation;
if (!attributes.hasAttribute("direction"_L1) ||
attributes.value("direction"_L1) == "out"_L1) {
- parseArg(attributes, argument, ifaceData);
+ parseArg(attributes, argument);
arguments << argument;
}
} else {
- qDBusParserError() << "Unknown element" << xml.name() << "while checking for signal arguments";
+ qDBusParserWarning("Unknown element '%s' while checking for signal arguments",
+ qPrintable(m_xml.name().toString()));
}
- xml.skipCurrentElement();
- } while (xml.readNextStartElement());
+ m_xml.skipCurrentElement();
+ } while (readNextStartElement());
- ifaceData->introspection += " </signal>\n"_L1;
+ m_currentInterface->introspection += " </signal>\n"_L1;
}
signalData.outputArgs = arguments;
@@ -241,105 +270,142 @@ static bool parseSignal(QXmlStreamReader &xml, QDBusIntrospection::Signal &signa
return true;
}
-static void readInterface(QXmlStreamReader &xml, QDBusIntrospection::Object *objData,
- QDBusIntrospection::Interfaces *interfaces)
+void QDBusXmlParser::readInterface()
{
- const QString ifaceName = xml.attributes().value("name"_L1).toString();
+ Q_ASSERT(!m_currentInterface);
+
+ const QString ifaceName = m_xml.attributes().value("name"_L1).toString();
if (!QDBusUtil::isValidInterfaceName(ifaceName)) {
- qDBusParserError("Invalid D-BUS interface name '%s' found while parsing introspection",
- qPrintable(ifaceName));
+ qDBusParserError("Invalid D-Bus interface name '%s' found while parsing introspection",
+ qPrintable(ifaceName));
return;
}
- objData->interfaces.append(ifaceName);
+ m_object->interfaces.append(ifaceName);
- QDBusIntrospection::Interface *ifaceData = new QDBusIntrospection::Interface;
- ifaceData->name = ifaceName;
- ifaceData->introspection += " <interface name=\""_L1 + ifaceName + "\">\n"_L1;
+ m_currentInterface = std::make_unique<QDBusIntrospection::Interface>();
+ m_currentInterface->location = m_currentLocation;
+ m_currentInterface->name = ifaceName;
+ m_currentInterface->introspection += " <interface name=\""_L1 + ifaceName + "\">\n"_L1;
- while (xml.readNextStartElement()) {
- if (xml.name() == "method"_L1) {
+ while (readNextStartElement()) {
+ if (m_xml.name() == "method"_L1) {
QDBusIntrospection::Method methodData;
- if (parseMethod(xml, methodData, ifaceData))
- ifaceData->methods.insert(methodData.name, methodData);
- } else if (xml.name() == "signal"_L1) {
+ methodData.location = m_currentLocation;
+ if (parseMethod(methodData))
+ m_currentInterface->methods.insert(methodData.name, methodData);
+ } else if (m_xml.name() == "signal"_L1) {
QDBusIntrospection::Signal signalData;
- if (parseSignal(xml, signalData, ifaceData))
- ifaceData->signals_.insert(signalData.name, signalData);
- } else if (xml.name() == "property"_L1) {
+ signalData.location = m_currentLocation;
+ if (parseSignal(signalData))
+ m_currentInterface->signals_.insert(signalData.name, signalData);
+ } else if (m_xml.name() == "property"_L1) {
QDBusIntrospection::Property propertyData;
- if (parseProperty(xml, propertyData, ifaceData))
- ifaceData->properties.insert(propertyData.name, propertyData);
- } else if (xml.name() == "annotation"_L1) {
- parseAnnotation(xml, ifaceData->annotations, ifaceData, true);
- xml.skipCurrentElement(); // skip over annotation object
+ propertyData.location = m_currentLocation;
+ if (parseProperty(propertyData))
+ m_currentInterface->properties.insert(propertyData.name, propertyData);
+ } else if (m_xml.name() == "annotation"_L1) {
+ parseAnnotation(m_currentInterface->annotations, true);
+ m_xml.skipCurrentElement(); // skip over annotation object
} else {
- if (xml.prefix().isEmpty()) {
- qDBusParserError() << "Unknown element while parsing interface" << xml.name();
+ if (m_xml.prefix().isEmpty()) {
+ qDBusParserWarning("Unknown element '%s' while parsing interface",
+ qPrintable(m_xml.name().toString()));
}
- xml.skipCurrentElement();
+ m_xml.skipCurrentElement();
}
}
- ifaceData->introspection += " </interface>"_L1;
+ m_currentInterface->introspection += " </interface>"_L1;
- interfaces->insert(ifaceName, QSharedDataPointer<QDBusIntrospection::Interface>(ifaceData));
+ m_interfaces.insert(
+ ifaceName,
+ QSharedDataPointer<QDBusIntrospection::Interface>(m_currentInterface.release()));
- if (!xml.isEndElement() || xml.name() != "interface"_L1) {
- qDBusParserError() << "Invalid Interface specification";
+ if (!m_xml.isEndElement() || m_xml.name() != "interface"_L1) {
+ qDBusParserError("Invalid Interface specification");
}
}
-static void readNode(const QXmlStreamReader &xml, QDBusIntrospection::Object *objData, int nodeLevel)
+void QDBusXmlParser::readNode(int nodeLevel)
{
- const QString objName = xml.attributes().value("name"_L1).toString();
- const QString fullName = objData->path.endsWith(u'/')
- ? (objData->path + objName)
- : QString(objData->path + u'/' + objName);
+ const QString objName = m_xml.attributes().value("name"_L1).toString();
+ QString fullName = m_object->path;
+ if (!(fullName.endsWith(u'/') || (nodeLevel == 0 && objName.startsWith(u'/'))))
+ fullName.append(u'/');
+ fullName += objName;
+
if (!QDBusUtil::isValidObjectPath(fullName)) {
- qDBusParserError("Invalid D-BUS object path '%s' found while parsing introspection",
- qPrintable(fullName));
+ qDBusParserError("Invalid D-Bus object path '%s' found while parsing introspection",
+ qPrintable(fullName));
return;
}
if (nodeLevel > 0)
- objData->childObjects.append(objName);
+ m_object->childObjects.append(objName);
+ else
+ m_object->location = m_currentLocation;
+}
+
+void QDBusXmlParser::updateCurrentLocation()
+{
+ m_currentLocation =
+ QDBusIntrospection::SourceLocation{ m_xml.lineNumber(), m_xml.columnNumber() };
}
-QDBusXmlParser::QDBusXmlParser(const QString& service, const QString& path,
- const QString& xmlData)
- : m_service(service), m_path(path), m_object(new QDBusIntrospection::Object)
+// Similar to m_xml.readNextElement() but sets current location to point
+// to the start element.
+bool QDBusXmlParser::readNextStartElement()
{
-// qDBusParserError() << "parsing" << xmlData;
+ updateCurrentLocation();
+
+ while (m_xml.readNext() != QXmlStreamReader::Invalid) {
+ if (m_xml.isEndElement())
+ return false;
+ else if (m_xml.isStartElement())
+ return true;
+ updateCurrentLocation();
+ }
+ return false;
+}
+QDBusXmlParser::QDBusXmlParser(const QString &service, const QString &path, const QString &xmlData,
+ QDBusIntrospection::DiagnosticsReporter *reporter)
+ : m_service(service),
+ m_path(path),
+ m_object(new QDBusIntrospection::Object),
+ m_xml(xmlData),
+ m_reporter(reporter)
+{
m_object->service = m_service;
m_object->path = m_path;
- QXmlStreamReader xml(xmlData);
-
int nodeLevel = -1;
- while (!xml.atEnd()) {
- xml.readNext();
+ while (!m_xml.atEnd()) {
+ updateCurrentLocation();
+ m_xml.readNext();
- switch (xml.tokenType()) {
+ switch (m_xml.tokenType()) {
case QXmlStreamReader::StartElement:
- if (xml.name() == "node"_L1) {
- readNode(xml, m_object, ++nodeLevel);
- } else if (xml.name() == "interface"_L1) {
- readInterface(xml, m_object, &m_interfaces);
+ if (m_xml.name() == "node"_L1) {
+ readNode(++nodeLevel);
+ } else if (m_xml.name() == "interface"_L1) {
+ readInterface();
} else {
- if (xml.prefix().isEmpty()) {
- qDBusParserError() << "skipping unknown element" << xml.name();
+ if (m_xml.prefix().isEmpty()) {
+ qDBusParserWarning("Skipping unknown element '%s'",
+ qPrintable(m_xml.name().toString()));
}
- xml.skipCurrentElement();
+ m_xml.skipCurrentElement();
}
break;
case QXmlStreamReader::EndElement:
- if (xml.name() == "node"_L1) {
+ if (m_xml.name() == "node"_L1) {
--nodeLevel;
} else {
- qDBusParserError() << "Invalid Node declaration" << xml.name();
+ qDBusParserError("Invalid node declaration '%s'",
+ qPrintable(m_xml.name().toString()));
}
break;
case QXmlStreamReader::StartDocument:
@@ -352,18 +418,17 @@ QDBusXmlParser::QDBusXmlParser(const QString& service, const QString& path,
break;
case QXmlStreamReader::Characters:
// ignore whitespace
- if (xml.isWhitespace())
+ if (m_xml.isWhitespace())
break;
Q_FALLTHROUGH();
default:
- qDBusParserError() << "unknown token" << xml.name() << xml.tokenString();
+ qDBusParserError("Unknown token: '%s'", qPrintable(m_xml.tokenString()));
break;
}
}
- if (xml.hasError()) {
- qDBusParserError() << "xml error" << xml.errorString() << "doc" << xmlData;
- }
+ if (m_xml.hasError())
+ qDBusParserError("XML error: %s", qPrintable(m_xml.errorString()));
}
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusxmlparser_p.h b/src/dbus/qdbusxmlparser_p.h
index db3b289a2a..0476ba3628 100644
--- a/src/dbus/qdbusxmlparser_p.h
+++ b/src/dbus/qdbusxmlparser_p.h
@@ -18,6 +18,7 @@
#include <QtDBus/private/qtdbusglobal_p.h>
#include <QtCore/qloggingcategory.h>
#include <QtCore/qmap.h>
+#include <QtCore/qxmlstream.h>
#include "qdbusintrospection_p.h"
#ifndef QT_NO_DBUS
@@ -34,14 +35,30 @@ class QDBusXmlParser
QString m_service;
QString m_path;
QSharedDataPointer<QDBusIntrospection::Object> m_object;
+ std::unique_ptr<QDBusIntrospection::Interface> m_currentInterface;
QDBusIntrospection::Interfaces m_interfaces;
+ QXmlStreamReader m_xml;
+ QDBusIntrospection::SourceLocation m_currentLocation;
+ QDBusIntrospection::DiagnosticsReporter *m_reporter;
public:
- QDBusXmlParser(const QString& service, const QString& path,
- const QString& xmlData);
+ QDBusXmlParser(const QString &service, const QString &path, const QString &xmlData,
+ QDBusIntrospection::DiagnosticsReporter *reporter = nullptr);
inline QDBusIntrospection::Interfaces interfaces() const { return m_interfaces; }
inline QSharedDataPointer<QDBusIntrospection::Object> object() const { return m_object; }
+
+private:
+ void readNode(int nodeLevel);
+ void readInterface();
+ bool parseSignal(QDBusIntrospection::Signal &signalData);
+ bool parseMethod(QDBusIntrospection::Method &methodData);
+ bool parseProperty(QDBusIntrospection::Property &propertyData);
+ bool parseAnnotation(QDBusIntrospection::Annotations &annotations,
+ bool interfaceAnnotation = false);
+ bool parseArg(const QXmlStreamAttributes &attributes, QDBusIntrospection::Argument &argData);
+ bool readNextStartElement();
+ void updateCurrentLocation();
};
QT_END_NAMESPACE
diff --git a/src/dbus/qt_attribution.json b/src/dbus/qt_attribution.json
index 6cfe6ab2af..a4c4446862 100644
--- a/src/dbus/qt_attribution.json
+++ b/src/dbus/qt_attribution.json
@@ -11,8 +11,8 @@
"LicenseId": "AFL-2.1 OR GPL-2.0-or-later",
"License": "Academic Free License v2.1, or GNU General Public License v2.0 or later",
"LicenseFile": "LIBDBUS-1-LICENSE.txt",
- "Files": "Fragments from various upstream files, see comments in ...",
+ "Comment": "Fragments from various upstream files, see comments in ...",
"Files": "dbus_minimal_p.h",
- "Copyright": "Copyright (C) 2002, 2003 CodeFactory AB
-Copyright (C) 2004, 2005 Red Hat, Inc."
+ "Copyright": ["Copyright (C) 2002, 2003 CodeFactory AB",
+ "Copyright (C) 2004, 2005 Red Hat, Inc."]
}