summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/.prev_CMakeLists.txt76
-rw-r--r--src/dbus/CMakeLists.txt30
-rw-r--r--src/dbus/Qt6DBusMacros.cmake150
-rw-r--r--src/dbus/dbus.pro88
-rw-r--r--src/dbus/dbus_minimal_p.h44
-rw-r--r--src/dbus/doc/qtdbus.qdocconf12
-rw-r--r--src/dbus/doc/snippets/CMakeLists.txt7
-rw-r--r--src/dbus/doc/snippets/cmake/examples.cmake9
-rw-r--r--src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc51
-rw-r--r--src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp51
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp79
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp53
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp53
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp51
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp51
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp55
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp51
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp51
-rw-r--r--src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp53
-rw-r--r--src/dbus/doc/snippets/snippets.pro16
-rw-r--r--src/dbus/doc/src/dbus-adaptors.qdoc44
-rw-r--r--src/dbus/doc/src/dontdocument.qdoc28
-rw-r--r--src/dbus/doc/src/includes/cmake-find-package-dbus.qdocinc5
-rw-r--r--src/dbus/doc/src/qdbusxml2cpp.qdoc28
-rw-r--r--src/dbus/doc/src/qt6-changes.qdoc44
-rw-r--r--src/dbus/doc/src/qtdbus-cmake.qdoc183
-rw-r--r--src/dbus/doc/src/qtdbus-examples.qdoc28
-rw-r--r--src/dbus/doc/src/qtdbus-index.qdoc246
-rw-r--r--src/dbus/doc/src/qtdbus-module.qdoc38
-rw-r--r--src/dbus/doc/src/qtdbus-overview.qdoc176
-rw-r--r--src/dbus/qdbus_symbols.cpp71
-rw-r--r--src/dbus/qdbus_symbols_p.h96
-rw-r--r--src/dbus/qdbusabstractadaptor.cpp87
-rw-r--r--src/dbus/qdbusabstractadaptor.h40
-rw-r--r--src/dbus/qdbusabstractadaptor_p.h43
-rw-r--r--src/dbus/qdbusabstractinterface.cpp270
-rw-r--r--src/dbus/qdbusabstractinterface.h78
-rw-r--r--src/dbus/qdbusabstractinterface_p.h43
-rw-r--r--src/dbus/qdbusargument.cpp123
-rw-r--r--src/dbus/qdbusargument.h110
-rw-r--r--src/dbus/qdbusargument_p.h103
-rw-r--r--src/dbus/qdbusconnection.cpp395
-rw-r--r--src/dbus/qdbusconnection.h49
-rw-r--r--src/dbus/qdbusconnection_p.h121
-rw-r--r--src/dbus/qdbusconnectioninterface.cpp62
-rw-r--r--src/dbus/qdbusconnectioninterface.h40
-rw-r--r--src/dbus/qdbusconnectionmanager.cpp334
-rw-r--r--src/dbus/qdbusconnectionmanager_p.h93
-rw-r--r--src/dbus/qdbuscontext.cpp40
-rw-r--r--src/dbus/qdbuscontext.h40
-rw-r--r--src/dbus/qdbuscontext_p.h40
-rw-r--r--src/dbus/qdbusdemarshaller.cpp46
-rw-r--r--src/dbus/qdbuserror.cpp56
-rw-r--r--src/dbus/qdbuserror.h50
-rw-r--r--src/dbus/qdbusextratypes.cpp61
-rw-r--r--src/dbus/qdbusextratypes.h68
-rw-r--r--src/dbus/qdbusintegrator.cpp742
-rw-r--r--src/dbus/qdbusintegrator_p.h91
-rw-r--r--src/dbus/qdbusinterface.cpp62
-rw-r--r--src/dbus/qdbusinterface.h40
-rw-r--r--src/dbus/qdbusinterface_p.h40
-rw-r--r--src/dbus/qdbusinternalfilters.cpp193
-rw-r--r--src/dbus/qdbusintrospection.cpp63
-rw-r--r--src/dbus/qdbusintrospection_p.h88
-rw-r--r--src/dbus/qdbusmarshaller.cpp142
-rw-r--r--src/dbus/qdbusmessage.cpp194
-rw-r--r--src/dbus/qdbusmessage.h55
-rw-r--r--src/dbus/qdbusmessage_p.h48
-rw-r--r--src/dbus/qdbusmetaobject.cpp256
-rw-r--r--src/dbus/qdbusmetaobject_p.h40
-rw-r--r--src/dbus/qdbusmetatype.cpp251
-rw-r--r--src/dbus/qdbusmetatype.h78
-rw-r--r--src/dbus/qdbusmetatype_p.h101
-rw-r--r--src/dbus/qdbusmisc.cpp157
-rw-r--r--src/dbus/qdbuspendingcall.cpp131
-rw-r--r--src/dbus/qdbuspendingcall.h49
-rw-r--r--src/dbus/qdbuspendingcall_p.h49
-rw-r--r--src/dbus/qdbuspendingreply.cpp93
-rw-r--r--src/dbus/qdbuspendingreply.h204
-rw-r--r--src/dbus/qdbusreply.cpp78
-rw-r--r--src/dbus/qdbusreply.h45
-rw-r--r--src/dbus/qdbusserver.cpp95
-rw-r--r--src/dbus/qdbusserver.h43
-rw-r--r--src/dbus/qdbusservicewatcher.cpp161
-rw-r--r--src/dbus/qdbusservicewatcher.h52
-rw-r--r--src/dbus/qdbusthreaddebug_p.h46
-rw-r--r--src/dbus/qdbusunixfiledescriptor.cpp42
-rw-r--r--src/dbus/qdbusunixfiledescriptor.h44
-rw-r--r--src/dbus/qdbusutil.cpp220
-rw-r--r--src/dbus/qdbusutil_p.h68
-rw-r--r--src/dbus/qdbusvirtualobject.cpp43
-rw-r--r--src/dbus/qdbusvirtualobject.h40
-rw-r--r--src/dbus/qdbusxmlgenerator.cpp187
-rw-r--r--src/dbus/qdbusxmlparser.cpp444
-rw-r--r--src/dbus/qdbusxmlparser_p.h61
-rw-r--r--src/dbus/qt_attribution.json6
-rw-r--r--src/dbus/qtdbusglobal.h59
-rw-r--r--src/dbus/qtdbusglobal_p.h40
98 files changed, 3290 insertions, 6061 deletions
diff --git a/src/dbus/.prev_CMakeLists.txt b/src/dbus/.prev_CMakeLists.txt
deleted file mode 100644
index 1136ebe19b..0000000000
--- a/src/dbus/.prev_CMakeLists.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-# Generated from dbus.pro.
-
-#####################################################################
-## DBus Module:
-#####################################################################
-
-qt_add_module(DBus
- QMAKE_MODULE_CONFIG dbusadaptors dbusinterfaces
- SOURCES
- dbus_minimal_p.h
- qdbus_symbols.cpp qdbus_symbols_p.h
- qdbusabstractadaptor.cpp qdbusabstractadaptor.h qdbusabstractadaptor_p.h
- qdbusabstractinterface.cpp qdbusabstractinterface.h qdbusabstractinterface_p.h
- qdbusargument.cpp qdbusargument.h qdbusargument_p.h
- qdbusconnection.cpp qdbusconnection.h qdbusconnection_p.h
- qdbusconnectioninterface.cpp qdbusconnectioninterface.h
- qdbusconnectionmanager_p.h
- qdbuscontext.cpp qdbuscontext.h qdbuscontext_p.h
- qdbuserror.cpp qdbuserror.h
- qdbusextratypes.cpp qdbusextratypes.h
- qdbusintegrator.cpp qdbusintegrator_p.h
- qdbusinterface.cpp qdbusinterface.h qdbusinterface_p.h
- qdbusinternalfilters.cpp
- qdbusintrospection.cpp qdbusintrospection_p.h
- qdbusmarshaller.cpp
- qdbusmessage.cpp qdbusmessage.h qdbusmessage_p.h
- qdbusmetaobject.cpp
- qdbusmetatype.cpp qdbusmetatype.h
- qdbusmisc.cpp
- qdbuspendingcall.cpp qdbuspendingcall.h qdbuspendingcall_p.h
- qdbuspendingreply.cpp qdbuspendingreply.h
- qdbusreply.cpp qdbusreply.h
- qdbusserver.cpp qdbusserver.h
- qdbusservicewatcher.cpp qdbusservicewatcher.h
- qdbusthreaddebug_p.h
- qdbusunixfiledescriptor.cpp qdbusunixfiledescriptor.h
- qdbusutil.cpp qdbusutil_p.h
- qdbusvirtualobject.cpp qdbusvirtualobject.h
- qdbusxmlgenerator.cpp
- qdbusxmlparser.cpp qdbusxmlparser_p.h
- qtdbusglobal.h qtdbusglobal_p.h
- DEFINES
- DBUS_API_SUBJECT_TO_CHANGE
- QT_NO_FOREACH
- LIBRARIES
- Qt::CorePrivate
- PUBLIC_LIBRARIES
- Qt::Core
- PRIVATE_MODULE_INTERFACE
- Qt::CorePrivate
-)
-
-#### Keys ignored in scope 1:.:.:dbus.pro:<TRUE>:
-# MODULE_CONFIG = "dbusadaptors" "dbusinterfaces"
-
-## Scopes:
-#####################################################################
-
-qt_extend_target(DBus CONDITION QT_FEATURE_dbus_linked
- DEFINES
- QT_LINKED_LIBDBUS
- LIBRARIES
- dbus-1
-)
-
-qt_extend_target(DBus CONDITION WIN32
- LIBRARIES
- advapi32
- netapi32
- user32
- ws2_32
-)
-qt_add_docs(DBus
- doc/qtdbus.qdocconf
-)
-
diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt
index ea1d7abaa1..9c3f6d23d2 100644
--- a/src/dbus/CMakeLists.txt
+++ b/src/dbus/CMakeLists.txt
@@ -1,10 +1,11 @@
-# Generated from dbus.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## DBus Module:
#####################################################################
-qt_add_module(DBus
+qt_internal_add_module(DBus
QMAKE_MODULE_CONFIG dbusadaptors dbusinterfaces
SOURCES
dbus_minimal_p.h
@@ -14,7 +15,7 @@ qt_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
@@ -24,8 +25,8 @@ qt_add_module(DBus
qdbusintrospection.cpp qdbusintrospection_p.h
qdbusmarshaller.cpp
qdbusmessage.cpp qdbusmessage.h qdbusmessage_p.h
- qdbusmetaobject.cpp
- qdbusmetatype.cpp qdbusmetatype.h
+ qdbusmetaobject.cpp qdbusmetaobject_p.h
+ qdbusmetatype.cpp qdbusmetatype.h qdbusmetatype_p.h
qdbusmisc.cpp
qdbuspendingcall.cpp qdbuspendingcall.h qdbuspendingcall_p.h
qdbuspendingreply.cpp qdbuspendingreply.h
@@ -39,41 +40,44 @@ qt_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
Qt::Core
PRIVATE_MODULE_INTERFACE
Qt::CorePrivate
+ 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:
#####################################################################
-qt_extend_target(DBus CONDITION QT_FEATURE_dbus_linked
+qt_internal_extend_target(DBus CONDITION QT_FEATURE_dbus_linked
DEFINES
QT_LINKED_LIBDBUS
LIBRARIES
dbus-1
)
-qt_extend_target(DBus CONDITION WIN32
+qt_internal_extend_target(DBus CONDITION WIN32
LIBRARIES
advapi32
netapi32
user32
ws2_32
)
-qt_add_docs(DBus
+qt_internal_add_docs(DBus
doc/qtdbus.qdocconf
)
-
diff --git a/src/dbus/Qt6DBusMacros.cmake b/src/dbus/Qt6DBusMacros.cmake
index d7bba30148..57a4a0735e 100644
--- a/src/dbus/Qt6DBusMacros.cmake
+++ b/src/dbus/Qt6DBusMacros.cmake
@@ -1,44 +1,20 @@
-#=============================================================================
# Copyright 2005-2011 Kitware, Inc.
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# * Neither the name of Kitware, Inc. nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#=============================================================================
+# Copyright (C) 2022 The Qt Company Ltd.
+# 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)
@@ -58,26 +34,36 @@ 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
)
- set_source_files_properties("${_impl}" "${_header}" PROPERTIES SKIP_AUTOMOC TRUE)
+ set_source_files_properties("${_impl}" "${_header}" PROPERTIES
+ SKIP_AUTOMOC TRUE
+ SKIP_AUTOUIC TRUE
+ )
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()
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
- function(qt_add_dbus_interface sources)
+ # All three positional arguments are mandatory and there are no optional
+ # 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 relativename)
+ if(ARGC GREATER 3)
+ message(FATAL_ERROR "Unexpected arguments: ${ARGN}")
+ endif()
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
- qt5_add_dbus_interface("${sources}" ${ARGN})
+ qt5_add_dbus_interface("${sources}" "${interface}" "${relativename}")
elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
- qt6_add_dbus_interface("${sources}" ${ARGN})
+ qt6_add_dbus_interface("${sources}" "${interface}" "${relativename}")
endif()
set("${sources}" "${${sources}}" PARENT_SCOPE)
endfunction()
@@ -143,6 +129,8 @@ endfunction()
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
function(qt_generate_dbus_interface)
+ # The versioned function's implementation doesn't preserve empty options,
+ # so we don't need to here either. Using ARGV is fine under those assumptions.
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
qt5_generate_dbus_interface(${ARGV})
elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
@@ -152,50 +140,96 @@ if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
endif()
-function(qt6_add_dbus_adaptor _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
+function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClass _optionalRelativename _optionalClassName)
get_filename_component(_infile ${_xml_file} ABSOLUTE)
- set(_optionalBasename "${ARGV4}")
- if(_optionalBasename)
- set(_basename ${_optionalBasename} )
+ set(_optionalParentClass "${ARGV3}")
+ if(_optionalParentClass)
+ set(_parentClassOption "-l")
+ set(_parentClass "${_optionalParentClass}")
+ endif()
+
+ 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} -l ${_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} -l ${_parentClass} ${_infile}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbusxml2cpp -m -a ${_relativename} -i ${_include} ${_parentClassOption} ${_parentClass} ${_infile}
DEPENDS ${_infile} ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml
VERBATIM
)
endif()
qt6_generate_moc("${_header}" "${_moc}")
- set_source_files_properties("${_impl}" "${_header}" PROPERTIES SKIP_AUTOMOC TRUE)
+ set_source_files_properties("${_impl}" "${_header}" PROPERTIES
+ SKIP_AUTOMOC TRUE
+ SKIP_AUTOUIC TRUE
+ )
macro_add_file_dependencies("${_impl}" "${_moc}")
- list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
+ list(APPEND ${_sources} "${_impl}" "${_header}")
set(${_sources} ${${_sources}} PARENT_SCOPE)
endfunction()
if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
- function(qt_add_dbus_adaptor sources)
+ function(qt_add_dbus_adaptor sources dbus_spec header)
+ # We need to preserve empty values in both positional and optional arguments.
+ # The following explicit use of ARGVx variables ensures we don't silently
+ # drop any empty values, which is especially important if there are any
+ # non-empty values after empty ones. Note that we must not try to read
+ # ARGVx variables where x >= ARGC, as that is undefined behavior.
+ # Also note that the parent_class argument is required for qt5, but is
+ # optional for qt6.
+ if(ARGC LESS 4)
+ set(parent_class "")
+ else()
+ set(parent_class "${ARGV3}")
+ endif()
+
+ if(ARGC LESS 5)
+ set(basename "")
+ else()
+ set(basename "${ARGV4}")
+ endif()
+
+ if(ARGC LESS 6)
+ set(classname "")
+ else()
+ set(classname "${ARGV5}")
+ endif()
+
if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
- qt5_add_dbus_adaptor("${sources}" ${ARGN})
+ qt5_add_dbus_adaptor(
+ "${sources}" "${dbus_spec}" "${header}"
+ "${parent_class}" "${basename}" "${classname}"
+ )
elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
- qt6_add_dbus_adaptor("${sources}" ${ARGN})
+ qt6_add_dbus_adaptor(
+ "${sources}" "${dbus_spec}" "${header}"
+ "${parent_class}" "${basename}" "${classname}"
+ )
endif()
set("${sources}" "${${sources}}" PARENT_SCOPE)
endfunction()
diff --git a/src/dbus/dbus.pro b/src/dbus/dbus.pro
deleted file mode 100644
index 2cfd7e086c..0000000000
--- a/src/dbus/dbus.pro
+++ /dev/null
@@ -1,88 +0,0 @@
-TARGET = QtDBus
-QT = core-private
-MODULE_CONFIG = dbusadaptors dbusinterfaces
-
-DEFINES += DBUS_API_SUBJECT_TO_CHANGE
-qtConfig(dbus-linked) {
- QMAKE_USE_PRIVATE += dbus
- DEFINES += QT_LINKED_LIBDBUS
-}
-
-win32 {
- QMAKE_USE_PRIVATE += \
- advapi32 \
- netapi32 \
- user32 \
- ws2_32
-}
-
-DEFINES += QT_NO_FOREACH
-
-QMAKE_DOCS = $$PWD/doc/qtdbus.qdocconf
-
-HEADERS += qtdbusglobal.h \
- qdbusargument.h \
- qdbusconnectioninterface.h \
- qdbuserror.h \
- qdbusextratypes.h \
- qdbusmessage.h \
- qdbusserver.h \
- qdbusconnection.h \
- qdbusabstractinterface.h \
- qdbusinterface.h \
- qdbusabstractadaptor.h \
- qdbusreply.h \
- qdbusmetatype.h \
- qdbuspendingcall.h \
- qdbuspendingreply.h \
- qdbuscontext.h \
- qdbusvirtualobject.h \
- qdbusservicewatcher.h \
- qdbusunixfiledescriptor.h \
- qtdbusglobal_p.h \
- qdbusconnection_p.h \
- qdbusconnectionmanager_p.h \
- qdbusmessage_p.h \
- qdbusinterface_p.h \
- qdbusxmlparser_p.h \
- qdbusabstractadaptor_p.h \
- qdbusargument_p.h \
- qdbusutil_p.h \
- qdbusabstractinterface_p.h \
- qdbuscontext_p.h \
- qdbusthreaddebug_p.h \
- qdbusintegrator_p.h \
- qdbuspendingcall_p.h \
- qdbus_symbols_p.h \
- qdbusintrospection_p.h \
- dbus_minimal_p.h
-SOURCES += qdbusconnection.cpp \
- qdbusconnectioninterface.cpp \
- qdbuserror.cpp \
- qdbusintegrator.cpp \
- qdbusmessage.cpp \
- qdbusserver.cpp \
- qdbusabstractinterface.cpp \
- qdbusinterface.cpp \
- qdbusxmlparser.cpp \
- qdbusutil.cpp \
- qdbusintrospection.cpp \
- qdbusabstractadaptor.cpp \
- qdbusinternalfilters.cpp \
- qdbusmetaobject.cpp \
- qdbusxmlgenerator.cpp \
- qdbusmisc.cpp \
- qdbusargument.cpp \
- qdbusreply.cpp \
- qdbusmetatype.cpp \
- qdbusextratypes.cpp \
- qdbusmarshaller.cpp \
- qdbuscontext.cpp \
- qdbuspendingcall.cpp \
- qdbuspendingreply.cpp \
- qdbus_symbols.cpp \
- qdbusservicewatcher.cpp \
- qdbusunixfiledescriptor.cpp \
- qdbusvirtualobject.cpp
-
-load(qt_module)
diff --git a/src/dbus/dbus_minimal_p.h b/src/dbus/dbus_minimal_p.h
index 243c8ceaba..36e7fab55d 100644
--- a/src/dbus/dbus_minimal_p.h
+++ b/src/dbus/dbus_minimal_p.h
@@ -1,41 +1,7 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2002, 2003 CodeFactory AB
+// Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: AFL-2.1 OR GPL-2.0-or-later
#ifndef DBUS_MINIMAL_P_H
#define DBUS_MINIMAL_P_H
@@ -51,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 e88f39ce86..90ee5743ff 100644
--- a/src/dbus/doc/qtdbus.qdocconf
+++ b/src/dbus/doc/qtdbus.qdocconf
@@ -2,7 +2,9 @@ include($QT_INSTALL_DOCS/global/qt-module-defaults.qdocconf)
include($QT_INSTALL_DOCS/config/exampleurl-qtbase.qdocconf)
# Name of the project which must match the outputdir. Determines the .index file
-project = QtDBus
+project = QtDBus
+description = Qt D-Bus Reference Documentation
+version = $QT_VERSION
# Directories in which to search for files to document and images.
# By default set to the root directory of the project for sources
@@ -61,6 +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"
+
+# Enforce zero documentation warnings
+warninglimit = 0
diff --git a/src/dbus/doc/snippets/CMakeLists.txt b/src/dbus/doc/snippets/CMakeLists.txt
index c9f398a22f..4b4751d4fa 100644
--- a/src/dbus/doc/snippets/CMakeLists.txt
+++ b/src/dbus/doc/snippets/CMakeLists.txt
@@ -1,4 +1,7 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
#! [cmake_use]
-find_package(Qt6 COMPONENTS DBus REQUIRED)
-target_link_libraries(mytarget Qt::DBus)
+find_package(Qt6 REQUIRED COMPONENTS DBus)
+target_link_libraries(mytarget PRIVATE Qt6::DBus)
#! [cmake_use]
diff --git a/src/dbus/doc/snippets/cmake/examples.cmake b/src/dbus/doc/snippets/cmake/examples.cmake
index cb4f86844f..2bb6b63abb 100644
--- a/src/dbus/doc/snippets/cmake/examples.cmake
+++ b/src/dbus/doc/snippets/cmake/examples.cmake
@@ -1,3 +1,6 @@
-#! [qt5_add_dbus_adaptor]
-qt5_add_dbus_adaptor(GENERATED_SOURCES org.example.chat.xml chat.h ChatMainWindow)
-#! [qt5_add_dbus_adaptor]
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#! [qt_add_dbus_adaptor]
+qt_add_dbus_adaptor(GENERATED_SOURCES org.example.chat.xml chat.h ChatMainWindow)
+#! [qt_add_dbus_adaptor]
diff --git a/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
index 5bade40a0b..61afa69790 100644
--- a/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
+++ b/src/dbus/doc/snippets/code/doc_src_introtodbus.qdoc
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// 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/doc_src_qdbusadaptors.cpp b/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp
index d5de866ae0..1cfb77db99 100644
--- a/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp
+++ b/src/dbus/doc/snippets/code/doc_src_qdbusadaptors.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QString>
#include <QDBusMessage>
#include <QDBusConnection>
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
index e8fb8c81fb..92b9dea909 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
@@ -1,58 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QString>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDBusInterface>
+using namespace Qt::StringLiterals;
+
class Abstract_DBus_Interface : public QObject
{
Q_OBJECT
@@ -81,23 +36,33 @@ void Abstract_DBus_Interface::interfaceMain()
QString value = retrieveValue();
QDBusMessage reply;
-QDBusReply<int> api = interface->call(QLatin1String("GetAPIVersion"));
+QDBusReply<int> api = interface->call("GetAPIVersion"_L1);
if (api >= 14)
- reply = interface->call(QLatin1String("ProcessWorkUnicode"), value);
+ reply = interface->call("ProcessWorkUnicode"_L1, value);
else
- reply = interface->call(QLatin1String("ProcessWork"), QLatin1String("UTF-8"), value.toUtf8());
+ reply = interface->call("ProcessWork"_L1, "UTF-8"_L1, value.toUtf8());
//! [0]
}
void Abstract_DBus_Interface::asyncCall()
{
//! [1]
-QString value = retrieveValue();
-QDBusPendingCall pcall = interface->asyncCall(QLatin1String("Process"), 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_qdbusargument.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp
index 7eb1e8b34e..5cb6ce5bb2 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QString>
#include <QDBusArgument>
@@ -242,7 +195,7 @@ QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myArray)
// Append a dictionary that associates ints to MyValue types
QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &myDict)
{
- argument.beginMap(QVariant::Int, qMetaTypeId<MyValue>());
+ argument.beginMap(QMetaType::fromType<int>(), QMetaType::fromType<MyValue>());
MyDictionary::const_iterator i;
for (i = myDict.cbegin(); i != myDict.cend(); ++i) {
argument.beginMapEntry();
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
index 901b29e205..75b4394595 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QString>
#include <QDBusConnection>
@@ -84,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_qdbusinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp
index d08ced6ece..06d654b97b 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QDBusInterface>
#include <QDBusReply>
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
index e295358b60..c9e5281cdb 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore/qlist.h>
typedef QList<QString> MyClass;
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
index d75a19b62f..67b019a67d 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QDBusPendingCall>
#include <QDBusInterface>
#include <QDBusPendingReply>
@@ -80,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/snippets/code/src_qdbus_qdbuspendingreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
index 9a37e7bb09..04f707dba8 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QDBusPendingCall>
#include <QDBusInterface>
#include <QDBusPendingReply>
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
index 30bd422d2c..2def08bdfe 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
@@ -1,52 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QDBusPendingCall>
#include <QDBusInterface>
#include <QDBusPendingReply>
diff --git a/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp b/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp
index a851e9f39f..9029fa8cf7 100644
--- a/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp
+++ b/src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp
@@ -1,55 +1,8 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:BSD$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** BSD License Usage
-** Alternatively, you may use this file under the terms of the BSD license
-** as follows:
-**
-** "Redistribution and use in source and binary forms, with or without
-** modification, are permitted provided that the following conditions are
-** met:
-** * Redistributions of source code must retain the above copyright
-** notice, this list of conditions and the following disclaimer.
-** * Redistributions in binary form must reproduce the above copyright
-** notice, this list of conditions and the following disclaimer in
-** the documentation and/or other materials provided with the
-** distribution.
-** * Neither the name of The Qt Company Ltd nor the names of its
-** contributors may be used to endorse or promote products derived
-** from this software without specific prior written permission.
-**
-**
-** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
#include <QtCore>
-#include <QtDBus>
+
static QVariant callMyDBusFunction() { return QVariant(); }
diff --git a/src/dbus/doc/snippets/snippets.pro b/src/dbus/doc/snippets/snippets.pro
index 0447c3e2d8..6c3b57fec9 100644
--- a/src/dbus/doc/snippets/snippets.pro
+++ b/src/dbus/doc/snippets/snippets.pro
@@ -1,19 +1,3 @@
#! [qmake_use]
QT += dbus
#! [qmake_use]
-TEMPLATE = lib
-
-TARGET = qtdbus_snippets
-
-QT += core dbus xml
-load(qt_common)
-
-SOURCES += code/src_qdbus_qdbusabstractinterface.cpp \
- code/src_qdbus_qdbusinterface.cpp \
- code/src_qdbus_qdbuspendingcall.cpp \
- code/src_qdbus_qdbuspendingreply.cpp \
- code/src_qdbus_qdbusreply.cpp \
- code/doc_src_qdbusadaptors.cpp \
- code/src_qdbus_qdbusargument.cpp \
- code/src_qdbus_qdbuscontext.cpp \
- code/src_qdbus_qdbusmetatype.cpp
diff --git a/src/dbus/doc/src/dbus-adaptors.qdoc b/src/dbus/doc/src/dbus-adaptors.qdoc
index d2a5ac27a8..e57cc095b9 100644
--- a/src/dbus/doc/src/dbus-adaptors.qdoc
+++ b/src/dbus/doc/src/dbus-adaptors.qdoc
@@ -1,36 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page usingadaptors.html
\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
@@ -68,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
@@ -111,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.
@@ -190,7 +166,7 @@
The delayed reply itself is requested from Qt D-Bus by calling
QDBusMessage::reply() on the original message. It then becomes the
- resposibility of the called code to eventually send a reply to the
+ responsibility of the called code to eventually send a reply to the
caller.
\warning When a caller places a method call and waits for a reply, it will
@@ -217,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/dontdocument.qdoc b/src/dbus/doc/src/dontdocument.qdoc
index bbb8acb53c..c217ca9276 100644
--- a/src/dbus/doc/src/dontdocument.qdoc
+++ b/src/dbus/doc/src/dontdocument.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\dontdocument (QTypeInfo QMetaTypeId QDBusAbstractInterfaceBase QDBusPendingReplyData QMetaTypeId2)
diff --git a/src/dbus/doc/src/includes/cmake-find-package-dbus.qdocinc b/src/dbus/doc/src/includes/cmake-find-package-dbus.qdocinc
new file mode 100644
index 0000000000..1ed1c6a8ec
--- /dev/null
+++ b/src/dbus/doc/src/includes/cmake-find-package-dbus.qdocinc
@@ -0,0 +1,5 @@
+The command is defined in the \c DBus component of the \c Qt6 package. Load the package with:
+
+\code
+find_package(Qt6 REQUIRED COMPONENTS DBus)
+\endcode
diff --git a/src/dbus/doc/src/qdbusxml2cpp.qdoc b/src/dbus/doc/src/qdbusxml2cpp.qdoc
index 1dd8a9af7a..d63453bf78 100644
--- a/src/dbus/doc/src/qdbusxml2cpp.qdoc
+++ b/src/dbus/doc/src/qdbusxml2cpp.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qdbusxml2cpp.html
diff --git a/src/dbus/doc/src/qt6-changes.qdoc b/src/dbus/doc/src/qt6-changes.qdoc
new file mode 100644
index 0000000000..80cd56c627
--- /dev/null
+++ b/src/dbus/doc/src/qt6-changes.qdoc
@@ -0,0 +1,44 @@
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \page dbus-changes-qt6.html
+ \title Changes to Qt D-Bus
+ \ingroup changes-qt-5-to-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.
+
+ We try to maintain binary and source compatibility for all the public
+ APIs in each release. But some changes were inevitable in an effort to
+ make Qt a better framework.
+
+ In this topic we summarize those changes in Qt DBus, and provide
+ guidance to handle them.
+
+ \section1 API changes
+
+ The QtDBus module has undergone some basic consolidation and
+ cleanup. There should be minimal porting effort to be able to switch to Qt6.
+
+ \section2 The QDBusMessage class
+ The QDBusMessage::call() and QDBusMessage::asyncCall() methods with a fixed
+ size of arguments have been removed in Qt6.
+
+ \section2 The QDBusArgument class
+ The QDBusArgument::operator<<() specializations for QHash, QMap and QList
+ have been unified into common specializations for associative containers.
+
+ \section2 The QDBusConnection class
+ The QDBusConnection::sender() function has been removed in Qt6.
+
+ \section2 The QDBusMessage class
+ The QDBusMessage::createErrorReply() function now takes the QString \c name
+ argument by const reference instead of taking by value.
+
+ \section2 The QDBusPendingReply class
+ QDBusPendingReply has been changed to be a variadic template class in order
+ to support more than 8 template parameters now. The template parameters
+ are the types that will be used to extract the contents of the reply's data.
+*/
diff --git a/src/dbus/doc/src/qtdbus-cmake.qdoc b/src/dbus/doc/src/qtdbus-cmake.qdoc
index de127fa9f4..86807af6e5 100644
--- a/src/dbus/doc/src/qtdbus-cmake.qdoc
+++ b/src/dbus/doc/src/qtdbus-cmake.qdoc
@@ -1,45 +1,43 @@
-/****************************************************************************
-**
-** Copyright (C) 2019 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2019 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
-\page qtdbus-cmake-qt5-add-dbus-interface.html
+\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
+
+\code
+find_package(Qt6 REQUIRED COMPONENTS DBus)
+\endcode
+
+\sa{CMake Command Reference}
+*/
+
+/*!
+\page qtdbus-cmake-qt-add-dbus-interface.html
\ingroup cmake-commands-qtdbus
-\title qt5_add_dbus_interface
+\title qt_add_dbus_interface
+\keyword qt6_add_dbus_interface
-\brief Generates C++ sources implementing an interface for a D-Bus interface
-description file.
+\summary {Generates C++ sources implementing an interface for a D-Bus interface
+description file.}
+
+\include cmake-find-package-dbus.qdocinc
+
+\cmakecommandsince 6.0
\section1 Synopsis
\badcode
-qt5_add_dbus_interface(<VAR> dbus_spec basename)
+qt_add_dbus_interface(<VAR> dbus_spec basename)
\endcode
+\versionlessCMakeCommandsNote qt6_add_dbus_interface()
+
\section1 Description
Generates C++ sources implementing an interface for a D-Bus interface description
@@ -64,7 +62,7 @@ class named after the interface name, with a namespaced alias:
\section1 Options
-Options can be set using \c set_source_file_property on the \c dbus_spec:
+Options can be set using \c set_source_files_properties on the \c dbus_spec:
\table
\header
@@ -87,20 +85,27 @@ Options can be set using \c set_source_file_property on the \c dbus_spec:
*/
/*!
-\page qtdbus-cmake-qt5-add-dbus-interfaces.html
+\page qtdbus-cmake-qt-add-dbus-interfaces.html
\ingroup cmake-commands-qtdbus
-\title qt5_add_dbus_interfaces
+\title qt_add_dbus_interfaces
+\keyword qt6_add_dbus_interfaces
-\brief Generates C++ sources implementing interfaces for D-Bus interface
-description files.
+\summary {Generates C++ sources implementing interfaces for D-Bus interface
+description files.}
+
+\include cmake-find-package-dbus.qdocinc
+
+\cmakecommandsince 6.0
\section1 Synopsis
\badcode
-qt5_add_dbus_interfaces(<VAR> dbus_spec1 [dbus_spec2 ...])
+qt_add_dbus_interfaces(<VAR> dbus_spec1 [dbus_spec2 ...])
\endcode
+\versionlessCMakeCommandsNote qt6_add_dbus_interfaces()
+
\section1 Description
Generates C++ sources implementing D-Bus interfaces defined in \c{dbus_spec1},
@@ -117,7 +122,7 @@ The generated C++ source files are named after the XML file: For the file
\section1 Options
-Options can be set using \c set_source_file_property on each of the file
+Options can be set using \c set_source_files_properties on each of the file
arguments:
\table
@@ -141,26 +146,33 @@ arguments:
*/
/*!
-\page qtdbus-cmake-qt5-generate-dbus-interface.html
+\page qtdbus-cmake-qt-generate-dbus-interface.html
\ingroup cmake-commands-qtdbus
-\title qt5_generate_dbus_interface
+\title qt_generate_dbus_interface
+\keyword qt6_generate_dbus_interface
-\brief Generates a D-Bus interface from a header file.
+\summary {Generates a D-Bus interface from a header file.}
+
+\include cmake-find-package-dbus.qdocinc
+
+\cmakecommandsince 6.0
\section1 Synopsis
\badcode
-qt5_generate_dbus_interface(header
+qt_generate_dbus_interface(header
[customName]
[OPTIONS options]
)
\endcode
+\versionlessCMakeCommandsNote qt6_generate_dbus_interface()
+
\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
@@ -173,21 +185,30 @@ arguments to the tool can be set after \c{OPTIONS}.
*/
/*!
-\page qtdbus-cmake-qt5-add-dbus-adaptor.html
+\page qtdbus-cmake-qt-add-dbus-adaptor.html
\ingroup cmake-commands-qtdbus
-\title qt5_add_dbus_adaptor
+\title qt_add_dbus_adaptor
+\keyword qt6_add_dbus_adaptor
-\brief Generates an adaptor class for a D-Bus interface.
+\summary {Generates an adaptor class for a D-Bus interface.}
+
+\include cmake-find-package-dbus.qdocinc
+
+\cmakecommandsince 6.0
\section1 Synopsis
\badcode
-qt5_add_dbus_adaptor(<VAR> dbus_spec header parent_class
- [basename]
- [classname])
+qt_add_dbus_adaptor(<VAR> dbus_spec header
+ [parent_class]
+ [basename]
+ [classname]
+)
\endcode
+\versionlessCMakeCommandsNote qt6_add_dbus_adaptor()
+
\section1 Description
Generates a C++ header file implementing an adaptor for a D-Bus interface
@@ -220,5 +241,67 @@ argument.
\section1 Examples
-\snippet cmake/examples.cmake qt5_add_dbus_adaptor
+\snippet cmake/examples.cmake qt_add_dbus_adaptor
+*/
+
+/*!
+\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:
+
+\sa{CMake Property Reference}
*/
+
+/*!
+\page cmake-source-file-property-classname.html
+\ingroup cmake-source-file-properties-qtdbus
+
+\title CLASSNAME
+\target cmake-source-file-property-CLASSNAME
+
+\summary {Overrides the default interface class name.}
+
+\cmakepropertysince 5.0
+
+When this property is set, the generated C++ class name is overridden
+with the provided property value.
+
+\sa{qt6_add_dbus_interface}{qt_add_dbus_interface}
+*/
+
+/*!
+\page cmake-source-file-property-include.html
+\ingroup cmake-source-file-properties-qtdbus
+
+\title INCLUDE
+\target cmake-source-file-property-INCLUDE
+
+\summary {Adds an include path.}
+
+\cmakepropertysince 5.0
+
+When this property is set, an #include "path" is added
+to the generated C++ file.
+
+\sa{qt6_add_dbus_interface}{qt_add_dbus_interface}
+*/
+
+/*!
+\page cmake-source-file-property-no-namespace.html
+\ingroup cmake-source-file-properties-qtdbus
+
+\title NO_NAMESPACE
+\target cmake-source-file-property-NO_NAMESPACE
+
+\summary {Disables generation of a namespaced name.}
+
+\cmakepropertysince 5.0
+
+When this property is set, the generated C++ class will not contain a namespaced alias.
+
+\sa{qt6_add_dbus_interface}{qt_add_dbus_interface}
+*/
+
diff --git a/src/dbus/doc/src/qtdbus-examples.qdoc b/src/dbus/doc/src/qtdbus-examples.qdoc
index a35207ddee..9b55e3f3f7 100644
--- a/src/dbus/doc/src/qtdbus-examples.qdoc
+++ b/src/dbus/doc/src/qtdbus-examples.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\group examples-dbus
diff --git a/src/dbus/doc/src/qtdbus-index.qdoc b/src/dbus/doc/src/qtdbus-index.qdoc
index 1023022a1d..05ca38a207 100644
--- a/src/dbus/doc/src/qtdbus-index.qdoc
+++ b/src/dbus/doc/src/qtdbus-index.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\page qtdbus-index.html
@@ -32,181 +8,62 @@
\keyword QtDBus
- \include module-use.qdocinc using qt module
- \snippet snippets/CMakeLists.txt cmake_use
-
- See also the \l[QtDoc]{Building with CMake} overview.
-
- \include module-use.qdocinc building with qmake
- \snippet snippets/snippets.pro qmake_use
-
- \section1 Introduction
-
D-Bus is an Inter-Process Communication (IPC) and Remote Procedure
Calling (RPC) mechanism originally developed for Linux to replace
existing and competing IPC solutions with one unified protocol. It
- has also been designed to allow communication between system-level
+ was also designed to allow communication between system-level
processes (such as printer and hardware driver services) and
normal user processes.
It uses a fast, binary message-passing protocol, which is suitable
for same-machine communication due to its low latency and low
overhead. Its specification is currently defined by the
- \tt{freedesktop.org} project, and is available to all parties.
+ \tt{freedesktop.org} project and is available to all parties.
- Communication in general happens through a central server
- application, called the "bus" (hence the name), but direct
+ Communication, in general, happens through a central server
+ application called the "bus" (hence the name), but direct
application-to-application communication is also possible. When
communicating on a bus, applications can query which other
applications and services are available, as well as activate one
on demand.
- \section1 The Buses
-
- D-Bus buses are used to when many-to-many communication is
- desired. In order to achieve that, a central server is launched
- before any applications can connect to the bus: this server is
- responsible for keeping track of the applications that are
- connected and for properly routing messages from their source to
- their destination.
-
- In addition, D-Bus defines two well-known buses, called the
- system bus and the session bus. These buses are special in the
- sense that they have well-defined semantics: some services are
- defined to be found in one or both of these buses.
-
- For example, an application wishing to query the list of hardware
- devices attached to the computer will probably communicate to a
- service available on the system bus, while the service providing
- opening of the user's web browser will be probably found on the
- session bus.
-
- On the system bus, one can also expect to find restrictions on
- what services each application is allowed to offer. Therefore, one
- can be reasonably certain that, if a certain service is present,
- it is being offered by a trusted application.
-
- \section1 Concepts
-
- \section2 Messages
-
- On the low level, applications communicate over D-Bus by sending
- messages to one another. Messages are used to relay the remote
- procedure calls as well as the replies and errors associated
- with them. When used over a bus, messages have a destination,
- which means they are routed only to the interested parties,
- avoiding congestion due to "swarming" or broadcasting.
-
- A special kind of message called a "signal message"
- (a concept based on Qt's \l {Signals and Slots} mechanism),
- however, does not have a pre-defined destination. Since its
- purpose is to be used in a one-to-many context, signal messages
- are designed to work over an "opt-in" mechanism.
-
- The Qt D-Bus module fully encapsulates the low-level concept of
- messages into a simpler, object-oriented approach familiar to Qt
- developers. In most cases, the developer need not worry about
- sending or receiving messages.
-
- \section2 Service Names
-
- When communicating over a bus, applications obtain what is
- called a "service name": it is how that application chooses to be
- known by other applications on the same bus. The service names
- are brokered by the D-Bus bus daemon and are used to
- route messages from one application to another. An analogous
- concept to service names are IP addresses and hostnames: a
- computer normally has one IP address and may have one or more
- hostnames associated with it, according to the services that it
- provides to the network.
-
- On the other hand, if a bus is not used, service names are also
- not used. If we compare this to a computer network again, this
- would equate to a point-to-point network: since the peer is
- known, there is no need to use hostnames to find it or its IP
- address.
-
- The format of a D-Bus service name is in fact very similar to a
- host name: it is a dot-separated sequence of letters and
- digits. The common practice is even to name one's service name
- according to the domain name of the organization that defined
- that service.
-
- For example, the D-Bus service is defined by
- \tt{freedesktop.org} and can be found on the bus under the
- service name:
-
- \snippet code/doc_src_introtodbus.qdoc 0
-
- \section2 Object Paths
-
- Like network hosts, applications provide specific services to
- other applications by exporting objects. Those objects are
- hierarchically organised, much like the parent-child
- relationship that classes derived from QObject possess. One
- difference, however, is that there is the concept of "root
- object", that all objects have as ultimate parent.
-
- If we continue our analogy with Web services, object paths
- equate to the path part of a URL:
-
- \image qurl-ftppath.png
-
- Like them, object paths in D-Bus are formed resembling path
- names on the filesystem: they are slash-separated labels, each
- consisting of letters, digits and the underscore character
- ("_"). They must always start with a slash and must not end with
- one.
-
- \section2 Interfaces
-
- Interfaces are similar to C++ abstract classes and Java's
- \c interface keyword and declare the "contract" that is
- established between caller and callee. That is, they establish
- the names of the methods, signals and properties that are
- available as well as the behavior that is expected from either
- side when communication is established.
-
- Qt uses a very similar mechanism in its \l {How to Create Qt
- Plugins}{Plugin system}: Base classes in C++ are associated
- with a unique identifier by way of the Q_DECLARE_INTERFACE()
- macro.
-
- D-Bus interface names are, in fact, named in a manner similar to
- what is suggested by the Qt Plugin System: an identifier usually
- constructed from the domain name of the entity that defined that
- interface.
-
- \section2 Cheat Sheet
-
- To facilitate remembering of the naming formats and their
- purposes, the following table can be used:
-
- \table 90%
- \header \li D-Bus Concept \li Analogy \li Name format
- \row \li Service name \li Network hostnames \li Dot-separated
- ("looks like a hostname")
- \row \li Object path \li URL path component \li Slash-separated
- ("looks like a path")
- \row \li Interface \li Plugin identifier \li Dot-separated
- \endtable
-
- \section1 Debugging
-
- When developing applications that use D-Bus, it is sometimes useful to be able
- to see information about the messages that are sent and received across the
- bus by each application.
-
- 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
- car in the following way:
-
- \snippet code/doc_src_introtodbus.qdoc QDBUS_DEBUG
-
- Information about the messages will be written to the console the application
- was launched from.
+ \section1 Using the Module
+
+ \include {module-use.qdocinc} {using the c++ api}
+
+ \include {module-use.qdocinc} {building with cmake} {DBus}
+
+ \section1 Articles and Guides
+
+ The following documents contain information about Qt's D-Bus integration
+ features and provide details about the mechanisms used to send and receive
+ type information over the bus:
+
+ \list
+ \li \l {Qt D-Bus Overview}
+ \li \l {Using Qt D-Bus Adaptors}
+ \li \l {The Qt D-Bus Type System}
+ \li \l {Qt D-Bus XML compiler (qdbusxml2cpp)}
+ \li \l{D-Bus Viewer}
+ \endlist
+
+ \section1 Examples
+
+ \list
+ \li \l{Qt D-Bus Examples}
+ \endlist
+
+ \section1 Reference
+
+ \list
+ \li \l{Qt D-Bus C++ Classes}
+ \li \l{CMake Commands in Qt6 DBus}
+ \endlist
+
+ \section1 Module Evolution
+
+ \l{Changes to Qt D-Bus} lists important changes in the module API
+ and functionality that were made for the Qt 6 series of Qt.
\section1 Licenses and Attributions
@@ -217,24 +74,9 @@
See \l{Qt Licensing} for further details.
Furthermore, Qt D-Bus in Qt \QtVersion may contain third party
- modules under following permissive licenses:
+ modules under the following permissive licenses:
\generatelist{groupsbymodule attributions-qtdbus}
-
- \section1 Further Reading
-
- The following documents contain information about Qt's D-Bus integration
- features, and provide details about the mechanisms used to send and receive
- type information over the bus:
-
- \list
- \li \l{Using Qt D-Bus Adaptors}
- \li \l{The Qt D-Bus Type System}
- \li \l{Qt D-Bus XML compiler (qdbusxml2cpp)}
- \li \l{Qt D-Bus C++ Classes}
- \li \l{Qt D-Bus Examples}
- \li \l{D-Bus Viewer}
- \endlist
*/
/*!
diff --git a/src/dbus/doc/src/qtdbus-module.qdoc b/src/dbus/doc/src/qtdbus-module.qdoc
index 60a9eec768..c89b4dc937 100644
--- a/src/dbus/doc/src/qtdbus-module.qdoc
+++ b/src/dbus/doc/src/qtdbus-module.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the documentation of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:FDL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Free Documentation License Usage
-** Alternatively, this file may be used under the terms of the GNU Free
-** Documentation License version 1.3 as published by the Free Software
-** Foundation and appearing in the file included in the packaging of
-** this file. Please review the following information to ensure
-** the GNU Free Documentation License version 1.3 requirements
-** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtDBus
@@ -32,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
@@ -43,11 +19,5 @@
services exported by those applications by placing calls and
accessing properties.
- The Qt D-Bus module provides an interface that extends the Qt \l
- {signalsandslots.html}{Signals and Slots} mechanism, allowing one
- to connect to a signal emitted remotely as well as to connect a
- local signal to remote slot.
-
- See the \l {Qt D-Bus}{D-Bus} page for detailed information on
- how to use this module.
+ The \l{Qt D-Bus} page contains information about how to use the module.
*/
diff --git a/src/dbus/doc/src/qtdbus-overview.qdoc b/src/dbus/doc/src/qtdbus-overview.qdoc
new file mode 100644
index 0000000000..6342e674fd
--- /dev/null
+++ b/src/dbus/doc/src/qtdbus-overview.qdoc
@@ -0,0 +1,176 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
+
+/*!
+ \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
+ existing and competing IPC solutions with one unified protocol. It
+ was also designed to allow communication between system-level
+ processes (such as printer and hardware driver services) and
+ normal user processes.
+
+ It uses a fast, binary message-passing protocol, which is suitable
+ for same-machine communication due to its low latency and low
+ overhead. Its specification is currently defined by the
+ \tt{freedesktop.org} project and is available to all parties.
+
+ Communication, in general, happens through a central server
+ application called the "bus" (hence the name), but direct
+ application-to-application communication is also possible. When
+ communicating on a bus, applications can query which other
+ applications and services are available, as well as activate one
+ on demand.
+
+ \section1 The Buses
+
+ D-Bus buses are used when many-to-many communication is
+ desired. In order to achieve that, a central server is launched
+ before any application can connect to the bus. This server is
+ responsible for keeping track of the applications that are
+ connected and for properly routing messages from their source to
+ their destination.
+
+ In addition, D-Bus defines two well-known buses, called the
+ system bus and the session bus. These buses are special in the
+ sense that they have well-defined semantics: some services are
+ defined to be found in one or both of these buses.
+
+ For example, an application wishing to query the list of hardware
+ devices attached to the computer will probably communicate to a
+ service available on the system bus, while the service providing
+ opening of the user's web browser will probably be found on the
+ session bus.
+
+ On the system bus, you can also expect to find restrictions on
+ what services each application is allowed to offer. Therefore, you
+ can be reasonably certain that if a certain service is present,
+ it's being offered by a trusted application.
+
+ \section1 Concepts
+
+ \section2 Messages
+
+ On the low level, applications communicate over D-Bus by sending
+ messages to one another. Messages are used to relay the remote
+ procedure calls as well as the replies and errors associated
+ with them. When used over a bus, messages have a destination,
+ which means they are routed only to the interested parties,
+ avoiding congestion due to "swarming" or broadcasting.
+
+ A special kind of message called a "signal message"
+ (a concept based on Qt's \l {Signals and Slots} mechanism),
+ however, does not have a pre-defined destination. Since its
+ purpose is to be used in a one-to-many context, signal messages
+ are designed to work over an "opt-in" mechanism.
+
+ The Qt D-Bus module fully encapsulates the low-level concept of
+ messages into a simpler, object-oriented approach familiar to Qt
+ developers. In most cases, the developer need not worry about
+ sending or receiving messages.
+
+ \section2 Service Names
+
+ When communicating over a bus, applications obtain what is
+ called a "service name": it is how that application chooses to be
+ known by other applications on the same bus. The service names
+ are brokered by the D-Bus bus daemon and are used to
+ route messages from one application to another. An analogous
+ concept to service names are IP addresses and hostnames: a
+ computer normally has one IP address and may have one or more
+ hostnames associated with it, according to the services that it
+ provides to the network.
+
+ On the other hand, if a bus is not used, service names are also
+ not used. If we compare this to a computer network again, this
+ would equate to a point-to-point network: since the peer is
+ known, there is no need to use hostnames to find it or its IP
+ address.
+
+ The format of a D-Bus service name is in fact very similar to a
+ host name: it is a dot-separated sequence of letters and
+ digits. The common practice is even to name your service name
+ according to the domain name of the organization that defined
+ that service.
+
+ For example, the D-Bus service is defined by
+ \tt{freedesktop.org} and can be found on the bus under the
+ service name:
+
+ \snippet code/doc_src_introtodbus.qdoc 0
+
+ \section2 Object Paths
+
+ Like network hosts, applications provide specific services to
+ other applications by exporting objects. Those objects are
+ hierarchically organized, much like the parent-child
+ relationship that classes derived from QObject possess. One
+ difference, however, is that there is the concept of "root
+ object", which all objects have as the ultimate parent.
+
+ If we continue our analogy with Web services, object paths
+ equate to the path part of a URL:
+
+ \image qurl-ftppath.png
+
+ Like them, object paths in D-Bus are formed resembling path
+ names on the filesystem: they are slash-separated labels, each
+ consisting of letters, digits and the underscore character
+ ("\_"). They must always start with a slash and must not end with
+ one.
+
+ \section2 Interfaces
+
+ Interfaces are similar to C++ abstract classes and Java's
+ \c interface keyword and declare the "contract" that is
+ established between caller and callee. That is, they establish
+ the names of the methods, signals, and properties that are
+ available as well as the behavior that is expected from either
+ side when communication is established.
+
+ Qt uses a very similar mechanism in its \l {How to Create Qt
+ Plugins}{Plugin system}: Base classes in C++ are associated
+ with a unique identifier by way of the Q_DECLARE_INTERFACE()
+ macro.
+
+ D-Bus interface names are, in fact, named in a manner similar to
+ what is suggested by the Qt Plugin System: an identifier usually
+ constructed from the domain name of the entity that defined that
+ interface.
+
+ \section2 Cheat Sheet
+
+ To facilitate remembering of the naming formats and their
+ purposes, the following table can be used:
+
+ \table 90%
+ \header \li D-Bus Concept \li Analogy \li Name format
+ \row \li Service name \li Network hostnames \li Dot-separated
+ ("looks like a hostname")
+ \row \li Object path \li URL path component \li Slash-separated
+ ("looks like a path")
+ \row \li Interface \li Plugin identifier \li Dot-separated
+ \endtable
+
+ \section1 Debugging
+
+ When developing applications that use D-Bus, it is sometimes useful to be able
+ to see information about the messages that are sent and received across the
+ bus by each application.
+
+ 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
+ car in the following way:
+
+ \snippet code/doc_src_introtodbus.qdoc QDBUS_DEBUG
+
+ Information about the messages will be written to the console the application
+ was launched from.
+
+*/
diff --git a/src/dbus/qdbus_symbols.cpp b/src/dbus/qdbus_symbols.cpp
index dd74307fda..9788bb98bc 100644
--- a/src/dbus/qdbus_symbols.cpp
+++ b/src/dbus/qdbus_symbols.cpp
@@ -1,44 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qglobal.h>
+// 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 "qdbus_symbols_p.h"
+#include <QtCore/qlatin1stringview.h>
#if QT_CONFIG(library)
#include <QtCore/qlibrary.h>
#include <QtCore/private/qlocking_p.h>
@@ -47,16 +12,14 @@
#ifndef QT_NO_DBUS
-extern "C" void dbus_shutdown();
-
QT_BEGIN_NAMESPACE
-void (*qdbus_resolve_me(const char *name))();
+using namespace Qt::StringLiterals;
#if !defined QT_LINKED_LIBDBUS
#if QT_CONFIG(library)
-static QLibrary *qdbus_libdbus = 0;
+Q_CONSTINIT static QLibrary *qdbus_libdbus = nullptr;
void qdbus_unloadLibDBus()
{
@@ -66,7 +29,7 @@ void qdbus_unloadLibDBus()
qdbus_libdbus->unload();
}
delete qdbus_libdbus;
- qdbus_libdbus = 0;
+ qdbus_libdbus = nullptr;
}
#endif
@@ -79,8 +42,8 @@ bool qdbus_loadLibDBus()
return false;
#endif
- static bool triedToLoadLibrary = false;
- static QBasicMutex mutex;
+ Q_CONSTINIT static bool triedToLoadLibrary = false;
+ Q_CONSTINIT static QBasicMutex mutex;
const auto locker = qt_scoped_lock(mutex);
QLibrary *&lib = qdbus_libdbus;
@@ -91,12 +54,12 @@ 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
- QLatin1String("dbus-1"),
+ "dbus-1"_L1,
#endif
- QLatin1String("libdbus-1")
+ "libdbus-1"_L1
};
lib->unload();
@@ -118,14 +81,14 @@ bool qdbus_loadLibDBus()
}
delete lib;
- lib = 0;
+ lib = nullptr;
return false;
#else
return true;
#endif
}
-void (*qdbus_resolve_conditionally(const char *name))()
+QFunctionPointer qdbus_resolve_conditionally(const char *name)
{
#if QT_CONFIG(library)
if (qdbus_loadLibDBus())
@@ -136,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 accaa4f5ed..78b7e049ef 100644
--- a/src/dbus/qdbus_symbols_p.h
+++ b/src/dbus/qdbus_symbols_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -63,6 +27,8 @@
# include "dbus_minimal_p.h"
#endif
+#include <atomic>
+
#ifdef interface
# undef interface
#endif
@@ -71,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
@@ -88,7 +54,7 @@ struct TraceDBusCall
static inline ThreadData &td()
{
- static thread_local ThreadData value;
+ Q_CONSTINIT static thread_local ThreadData value;
return value;
}
@@ -150,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 0a4a23d780..afe769fcd0 100644
--- a/src/dbus/qdbusabstractadaptor.cpp
+++ b/src/dbus/qdbusabstractadaptor.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusabstractadaptor.h"
#include "qdbusabstractadaptor_p.h"
@@ -58,14 +22,10 @@
QT_BEGIN_NAMESPACE
-static int cachedRelaySlotMethodIndex = -1;
-
int QDBusAdaptorConnector::relaySlotMethodIndex()
{
- if (cachedRelaySlotMethodIndex == -1) {
- cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()");
- Q_ASSERT(cachedRelaySlotMethodIndex != -1);
- }
+ static const int cachedRelaySlotMethodIndex = staticMetaObject.indexOfMethod("relaySlot()");
+ Q_ASSERT(cachedRelaySlotMethodIndex != 0); // 0 should be deleteLater() or destroyed()
return cachedRelaySlotMethodIndex;
}
@@ -73,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;
@@ -146,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);
}
/*!
@@ -166,7 +127,7 @@ QDBusAbstractAdaptor::~QDBusAbstractAdaptor()
Toggles automatic signal relaying from the real object (see object()).
Automatic signal relaying consists of signal-to-signal connection of the signals on the parent
- that have the exact same method signatue in both classes.
+ that have the exact same method signature in both classes.
If \a enable is set to true, connect the signals; if set to false, disconnect all signals.
*/
@@ -263,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);
}
@@ -296,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))
@@ -305,7 +263,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
realObject = realObject->parent();
// break down the parameter list
- QList<int> types;
+ QList<QMetaType> types;
QString errorMsg;
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
if (inputCount == -1) {
@@ -315,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",
@@ -324,10 +282,10 @@ 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(types.at(i), argv[i]);
+ args << QVariant(QMetaType(types.at(i)), argv[i]);
// now emit the signal with all the information
emit relaySignal(realObject, senderMetaObject, lastSignalIdx, args);
@@ -335,4 +293,7 @@ void QDBusAdaptorConnector::relay(QObject *senderObj, int lastSignalIdx, void **
QT_END_NAMESPACE
+#include "moc_qdbusabstractadaptor_p.cpp"
+#include "moc_qdbusabstractadaptor.cpp"
+
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusabstractadaptor.h b/src/dbus/qdbusabstractadaptor.h
index f86d939fae..f143056b43 100644
--- a/src/dbus/qdbusabstractadaptor.h
+++ b/src/dbus/qdbusabstractadaptor.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSABSTRACTADAPTOR_H
#define QDBUSABSTRACTADAPTOR_H
diff --git a/src/dbus/qdbusabstractadaptor_p.h b/src/dbus/qdbusabstractadaptor_p.h
index 212878c29b..f4b69799a5 100644
--- a/src/dbus/qdbusabstractadaptor_p.h
+++ b/src/dbus/qdbusabstractadaptor_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
//
// W A R N I N G
@@ -58,7 +22,6 @@
#include <QtCore/qlist.h>
#include <QtCore/qmap.h>
#include <QtCore/qobject.h>
-#include <QtCore/qreadwritelock.h>
#include <QtCore/qvariant.h>
#include "private/qobject_p.h"
@@ -103,7 +66,7 @@ public: // typedefs
inline bool operator<(const AdaptorData &other) const
{ return QByteArray(interface) < other.interface; }
inline bool operator<(const QString &other) const
- { return QLatin1String(interface) < other; }
+ { return QLatin1StringView(interface) < other; }
inline bool operator<(const QByteArray &other) const
{ return interface < other; }
};
diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp
index d603264a1e..0c6dbf1b3b 100644
--- a/src/dbus/qdbusabstractinterface.cpp
+++ b/src/dbus/qdbusabstractinterface.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusabstractinterface.h"
#include "qdbusabstractinterface_p.h"
@@ -58,6 +22,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
namespace {
// ### Qt6: change to a regular QEvent (customEvent)
// We need to use a QMetaCallEvent here because we can't override customEvent() in
@@ -113,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)
@@ -154,18 +121,17 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
if (!isValid || !canMakeCalls()) // can't make calls
return false;
- const int type = mp.userType();
+ QMetaType type = mp.metaType();
// is this metatype registered?
const char *expectedSignature = "";
- if (int(mp.userType()) != QMetaType::QVariant) {
+ if (type.id() != QMetaType::QVariant) {
expectedSignature = QDBusMetaType::typeToSignature(type);
if (expectedSignature == nullptr) {
qWarning("QDBusAbstractInterface: type %s must be registered with Qt D-Bus before it can be "
"used to read property %s.%s",
mp.typeName(), qPrintable(interface), mp.name());
- lastError = QDBusError(QDBusError::Failed,
- QLatin1String("Unregistered type %1 cannot be handled")
- .arg(QLatin1String(mp.typeName())));
+ lastError = QDBusError(QDBusError::Failed, "Unregistered type %1 cannot be handled"_L1
+ .arg(QLatin1StringView(mp.typeName())));
return false;
}
}
@@ -182,9 +148,9 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
lastError = QDBusError(reply);
return false;
}
- if (reply.signature() != QLatin1String("v")) {
- QString errmsg = QLatin1String("Invalid signature `%1' in return from call to "
- DBUS_INTERFACE_PROPERTIES);
+ if (reply.signature() != "v"_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;
}
@@ -193,42 +159,42 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
const char *foundType = nullptr;
QVariant value = qvariant_cast<QDBusVariant>(reply.arguments().at(0)).variant();
- if (value.userType() == type || type == QMetaType::QVariant
+ if (value.metaType() == type || type.id() == QMetaType::QVariant
|| (expectedSignature[0] == 'v' && expectedSignature[1] == '\0')) {
// simple match
- if (type == QMetaType::QVariant) {
+ if (type.id() == QMetaType::QVariant) {
*reinterpret_cast<QVariant*>(returnValuePtr) = value;
} else {
- QMetaType::destruct(type, returnValuePtr);
- QMetaType::construct(type, returnValuePtr, value.constData());
+ QMetaType(type).destruct(returnValuePtr);
+ QMetaType(type).construct(returnValuePtr, value.constData());
}
return true;
}
- if (value.userType() == qMetaTypeId<QDBusArgument>()) {
+ if (value.metaType() == QMetaType::fromType<QDBusArgument>()) {
QDBusArgument arg = qvariant_cast<QDBusArgument>(value);
foundType = "user type";
foundSignature = arg.currentSignature().toLatin1();
if (foundSignature == expectedSignature) {
// signatures match, we can demarshall
- return QDBusMetaType::demarshall(arg, type, returnValuePtr);
+ return QDBusMetaType::demarshall(arg, QMetaType(type), returnValuePtr);
}
} else {
foundType = value.typeName();
- foundSignature = QDBusMetaType::typeToSignature(value.userType());
+ foundSignature = QDBusMetaType::typeToSignature(value.metaType());
}
// there was an error...
- const auto errmsg = QLatin1String("Unexpected `%1' (%2) when retrieving property `%3.%4' "
- "(expected type `%5' (%6))");
+ const auto errmsg = "Unexpected '%1' (%2) when retrieving property '%3.%4' "
+ "(expected type '%5' (%6))"_L1;
lastError = QDBusError(QDBusError::InvalidSignature,
- errmsg.arg(QLatin1String(foundType),
- QLatin1String(foundSignature),
+ errmsg.arg(QLatin1StringView(foundType),
+ QLatin1StringView(foundSignature),
interface,
- QLatin1String(mp.name()),
- QLatin1String(mp.typeName()),
- QLatin1String(expectedSignature)));
+ QLatin1StringView(mp.name()),
+ QLatin1StringView(mp.typeName()),
+ QLatin1StringView(expectedSignature)));
return false;
}
@@ -257,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;
@@ -281,10 +246,10 @@ int QDBusAbstractInterfaceBase::qt_metacall(QMetaObject::Call _c, int _id, void
if (_c == QMetaObject::WriteProperty) {
QVariant value;
- if (mp.userType() == qMetaTypeId<QDBusVariant>())
+ if (mp.metaType() == QMetaType::fromType<QDBusVariant>())
value = reinterpret_cast<const QDBusVariant*>(_a[0])->variant();
else
- value = QVariant(mp.userType(), _a[0]);
+ value = QVariant(mp.metaType(), _a[0]);
status = d_func()->setProperty(mp, value) ? 1 : 0;
} else {
bool readStatus = d_func()->property(mp, _a[0]);
@@ -433,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
@@ -460,7 +462,7 @@ QDBusMessage QDBusAbstractInterface::callWithArgumentList(QDBus::CallMode mode,
QString m = method;
// split out the signature from the method
- int pos = method.indexOf(QLatin1Char('.'));
+ int pos = method.indexOf(u'.');
if (pos != -1)
m.truncate(pos);
@@ -511,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,
@@ -524,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);
}
@@ -545,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
*/
@@ -712,33 +722,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 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.
\sa callWithArgumentList()
*/
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-/*!
- \internal
-
- This function exists for binary compatibility with Qt versions < 5.14.
- Programs recompiled against Qt 5.14 will use the variadic template function
- instead.
-*/
-QDBusMessage QDBusAbstractInterface::call(const QString &method, const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8)
-{
- return call(QDBus::AutoDetect, method, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
-}
-#endif
-
/*!
\fn QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &message)
\internal
@@ -768,59 +758,6 @@ QDBusMessage QDBusAbstractInterface::call(const QString &method, const QVariant
\sa callWithArgumentList()
*/
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-/*!
- \internal
-
- This function exists for binary compatibility with Qt versions < 5.14.
- Programs recompiled against Qt 5.14 will use the variadic template function
- instead.
-*/
-QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method,
- const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8)
-{
- QList<QVariant> argList;
- int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() +
- arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid();
-
- switch (count) {
- case 8:
- argList.prepend(arg8);
- Q_FALLTHROUGH();
- case 7:
- argList.prepend(arg7);
- Q_FALLTHROUGH();
- case 6:
- argList.prepend(arg6);
- Q_FALLTHROUGH();
- case 5:
- argList.prepend(arg5);
- Q_FALLTHROUGH();
- case 4:
- argList.prepend(arg4);
- Q_FALLTHROUGH();
- case 3:
- argList.prepend(arg3);
- Q_FALLTHROUGH();
- case 2:
- argList.prepend(arg2);
- Q_FALLTHROUGH();
- case 1:
- argList.prepend(arg1);
- break;
- }
-
- return callWithArgumentList(mode, method, argList);
-}
-#endif // Qt 5
-
/*!
\fn QDBusAbstractInterface::asyncCall(const QString &message)
\internal
@@ -843,63 +780,16 @@ QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &m
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.
- \sa asyncCallWithArgumentList()
-*/
-
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
-/*!
- \internal
+ \note Method calls to local \c{QDBusServer}'s are never asynchronous
+ due to implementation limitations.
- This function exists for binary compatibility with Qt versions < 5.14.
- Programs recompiled against Qt 5.14 will use the variadic template function
- instead.
+ \sa asyncCallWithArgumentList()
*/
-QDBusPendingCall QDBusAbstractInterface::asyncCall(const QString &method, const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8)
-{
- QList<QVariant> argList;
- int count = 0 + arg1.isValid() + arg2.isValid() + arg3.isValid() + arg4.isValid() +
- arg5.isValid() + arg6.isValid() + arg7.isValid() + arg8.isValid();
-
- switch (count) {
- case 8:
- argList.prepend(arg8);
- Q_FALLTHROUGH();
- case 7:
- argList.prepend(arg7);
- Q_FALLTHROUGH();
- case 6:
- argList.prepend(arg6);
- Q_FALLTHROUGH();
- case 5:
- argList.prepend(arg5);
- Q_FALLTHROUGH();
- case 4:
- argList.prepend(arg4);
- Q_FALLTHROUGH();
- case 3:
- argList.prepend(arg3);
- Q_FALLTHROUGH();
- case 2:
- argList.prepend(arg2);
- Q_FALLTHROUGH();
- case 1:
- argList.prepend(arg1);
- break;
- }
- return asyncCallWithArgumentList(method, argList);
-}
-#endif // Qt 5
/*!
\internal
diff --git a/src/dbus/qdbusabstractinterface.h b/src/dbus/qdbusabstractinterface.h
index 4f4c7430a5..8d36fb3728 100644
--- a/src/dbus/qdbusabstractinterface.h
+++ b/src/dbus/qdbusabstractinterface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSABSTRACTINTERFACE_H
#define QDBUSABSTRACTINTERFACE_H
@@ -99,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);
@@ -123,29 +90,6 @@ public:
return doCall(mode, method, variants, sizeof...(args));
}
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- QDBusMessage call(const QString &method,
- const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8);
-
- QDBusMessage call(QDBus::CallMode mode,
- const QString &method,
- const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8);
-#endif // Qt 5
-
QDBusMessage callWithArgumentList(QDBus::CallMode mode,
const QString &method,
const QList<QVariant> &args);
@@ -169,18 +113,6 @@ public:
return doAsyncCall(method, variants, sizeof...(args));
}
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
- QDBusPendingCall asyncCall(const QString &method,
- const QVariant &arg1,
- const QVariant &arg2,
- const QVariant &arg3,
- const QVariant &arg4,
- const QVariant &arg5,
- const QVariant &arg6,
- const QVariant &arg7,
- const QVariant &arg8);
-#endif // Qt 5
-
QDBusPendingCall asyncCallWithArgumentList(const QString &method,
const QList<QVariant> &args);
diff --git a/src/dbus/qdbusabstractinterface_p.h b/src/dbus/qdbusabstractinterface_p.h
index 8e45bae88b..1bd5e96f2d 100644
--- a/src/dbus/qdbusabstractinterface_p.h
+++ b/src/dbus/qdbusabstractinterface_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -78,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 2c6be1994c..99e60244da 100644
--- a/src/dbus/qdbusargument.cpp
+++ b/src/dbus/qdbusargument.cpp
@@ -1,55 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusargument.h"
#include "qdbusargument_p.h"
#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"
@@ -58,26 +23,27 @@
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QDBusArgument)
+
QDBusArgumentPrivate::~QDBusArgumentPrivate()
{
if (message)
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
- void *null = nullptr;
- QVariant v(id, null);
+ QVariant v{type};
QDBusArgument arg(marshaller);
- QDBusMetaType::marshall(arg, v.userType(), v.constData());
+ QDBusMetaType::marshall(arg, v.metaType(), v.constData());
arg.d = nullptr;
// delete it
@@ -85,19 +51,17 @@ 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::typeName(id),
- 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::typeName(id),
- signature.constData(),
- QMetaType::typeName(QDBusMetaType::signatureToType(signature)));
+ type.name(), signature.constData(),
+ QDBusMetaType::signatureToMetaType(signature).name());
return "";
}
return signature;
@@ -107,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;
@@ -135,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
@@ -269,7 +233,7 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
*/
/*!
- \fn template<typename T> T qdbus_cast(const QDBusArgument &arg, T*)
+ \fn template<typename T> T qdbus_cast(const QDBusArgument &arg)
\relates QDBusArgument
\since 4.2
@@ -296,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
@@ -573,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();
@@ -592,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
{
@@ -711,7 +675,7 @@ const QDBusArgument &QDBusArgument::operator>>(qulonglong &arg) const
/*!
\overload
Extracts one D-Bus primitive argument of type \c{DOUBLE}
- (double-precision floating pount) from the D-Bus stream.
+ (double-precision floating point) from the D-Bus stream.
*/
const QDBusArgument &QDBusArgument::operator>>(double &arg) const
{
@@ -880,7 +844,7 @@ void QDBusArgument::endStructure()
\sa endArray(), beginStructure(), beginMap()
*/
-void QDBusArgument::beginArray(int id)
+void QDBusArgument::beginArray(QMetaType id)
{
if (QDBusArgumentPrivate::checkWrite(d))
d = d->marshaller()->beginArray(id);
@@ -902,8 +866,8 @@ void QDBusArgument::endArray()
Opens a new D-Bus map suitable for
appending elements. Maps are containers that associate one entry
(the key) to another (the value), such as Qt's QMap or QHash. The
- ids of the map's key and value meta types must be passed in \a kid
- and \a vid respectively.
+ ids of the map's key and value meta types must be passed in \a keyMetaType
+ and \a valueMetaType respectively.
This function is used usually in \c{operator<<} streaming
operators, as in the following example:
@@ -917,10 +881,10 @@ void QDBusArgument::endArray()
\sa endMap(), beginStructure(), beginArray(), beginMapEntry()
*/
-void QDBusArgument::beginMap(int kid, int vid)
+void QDBusArgument::beginMap(QMetaType keyMetaType, QMetaType valueMetaType)
{
if (QDBusArgumentPrivate::checkWrite(d))
- d = d->marshaller()->beginMap(kid, vid);
+ d = d->marshaller()->beginMap(keyMetaType, valueMetaType);
}
/*!
@@ -1108,7 +1072,7 @@ bool QDBusArgument::atEnd() const
argument (for example, by calling asVariant() in it).
For example, if the current argument is an INT32, this function
- will return a QVariant with an argument of type QVariant::Int. For
+ will return a QVariant with an argument of type QMetaType::Int. For
an array of INT32, it will return a QVariant containing a
QDBusArgument.
@@ -1206,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 cfa66d348e..70f6703d2f 100644
--- a/src/dbus/qdbusargument.h
+++ b/src/dbus/qdbusargument.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSARGUMENT_H
#define QDBUSARGUMENT_H
@@ -81,9 +45,9 @@ public:
QDBusArgument &operator=(const QDBusArgument &other);
~QDBusArgument();
- void swap(QDBusArgument &other) noexcept { qSwap(d, other.d); }
+ 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);
@@ -103,16 +67,20 @@ public:
void beginStructure();
void endStructure();
- void beginArray(int elementMetaTypeId);
+ void beginArray(int elementMetaTypeId)
+ { beginArray(QMetaType(elementMetaTypeId)); }
+ void beginArray(QMetaType elementMetaType);
void endArray();
- void beginMap(int keyMetaTypeId, int valueMetaTypeId);
+ void beginMap(int keyMetaTypeId, int valueMetaTypeId)
+ { beginMap(QMetaType(keyMetaTypeId), QMetaType(valueMetaTypeId)); }
+ void beginMap(QMetaType keyMetaType, QMetaType valueMetaType);
void endMap();
void beginMapEntry();
void endMapEntry();
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;
@@ -153,34 +121,32 @@ protected:
Q_DECLARE_SHARED(QDBusArgument)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QDBusArgument)
+QT_DECL_METATYPE_EXTERN(QDBusArgument, Q_DBUS_EXPORT)
QT_BEGIN_NAMESPACE
-// ### Qt6: remove the defaulted T * = nullptr from these two (MSVC6 work-around):
-template<typename T> inline T qdbus_cast(const QDBusArgument &arg, T * = nullptr)
+template<typename T> inline T qdbus_cast(const QDBusArgument &arg)
{
T item;
arg >> item;
return item;
}
-template<typename T> inline T qdbus_cast(const QVariant &v, T * = nullptr)
+template<typename T> inline T qdbus_cast(const QVariant &v)
{
- int id = v.userType();
- if (id == qMetaTypeId<QDBusArgument>())
+ if (v.metaType() == QMetaType::fromType<QDBusArgument>())
return qdbus_cast<T>(qvariant_cast<QDBusArgument>(v));
else
return qvariant_cast<T>(v);
}
// specialize for QVariant, allowing it to be used in place of QDBusVariant
-template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg, QVariant *)
+template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg)
{
QDBusVariant item;
arg >> item;
return item.variant();
}
-template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v, QVariant *)
+template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v)
{
return qdbus_cast<QDBusVariant>(v).variant();
}
@@ -228,8 +194,7 @@ template<template <typename> class Container, typename T,
typename = typename Container<T>::iterator>
inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<T> &list)
{
- int id = qMetaTypeId<T>();
- arg.beginArray(id);
+ arg.beginArray(QMetaType::fromType<T>());
typename Container<T>::const_iterator it = list.begin();
typename Container<T>::const_iterator end = list.end();
for ( ; it != end; ++it)
@@ -256,12 +221,9 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &l
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list)
{
- int id = qMetaTypeId<QDBusVariant>();
- arg.beginArray(id);
- QVariantList::ConstIterator it = list.constBegin();
- QVariantList::ConstIterator end = list.constEnd();
- for ( ; it != end; ++it)
- arg << QDBusVariant(*it);
+ arg.beginArray(QMetaType::fromType<QDBusVariant>());
+ for (const QVariant &value : list)
+ arg << QDBusVariant(value);
arg.endArray();
return arg;
}
@@ -271,9 +233,7 @@ template <template <typename, typename> class Container, typename Key, typename
QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true>
inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &map)
{
- int kid = qMetaTypeId<Key>();
- int vid = qMetaTypeId<T>();
- arg.beginMap(kid, vid);
+ arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>());
auto it = map.begin();
auto end = map.end();
for ( ; it != end; ++it) {
@@ -289,9 +249,7 @@ template <template <typename, typename> class Container, typename Key, typename
QtPrivate::IfAssociativeIteratorHasFirstAndSecond<typename Container<Key, T>::iterator> = true>
inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &map)
{
- int kid = qMetaTypeId<Key>();
- int vid = qMetaTypeId<T>();
- arg.beginMap(kid, vid);
+ arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>());
auto it = map.begin();
auto end = map.end();
for ( ; it != end; ++it) {
@@ -304,7 +262,7 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &ma
}
template <template <typename, typename> class Container, typename Key, typename T,
- typename = typename Container<Key, T>::iterator>
+ QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true>
inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key, T> &map)
{
arg.beginMap();
@@ -323,12 +281,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key,
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map)
{
- arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>());
- QVariantMap::ConstIterator it = map.constBegin();
- QVariantMap::ConstIterator end = map.constEnd();
- for ( ; it != end; ++it) {
+ arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>());
+ for (const auto &[key, value] : map.asKeyValueRange()) {
arg.beginMapEntry();
- arg << it.key() << QDBusVariant(it.value());
+ arg << key << QDBusVariant(value);
arg.endMapEntry();
}
arg.endMap();
@@ -337,12 +293,10 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map)
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map)
{
- arg.beginMap(QMetaType::QString, qMetaTypeId<QDBusVariant>());
- QVariantHash::ConstIterator it = map.constBegin();
- QVariantHash::ConstIterator end = map.constEnd();
- for ( ; it != end; ++it) {
+ arg.beginMap(QMetaType::fromType<QString>(), QMetaType::fromType<QDBusVariant>());
+ for (const auto &[key, value] : map.asKeyValueRange()) {
arg.beginMapEntry();
- arg << it.key() << QDBusVariant(it.value());
+ arg << key << QDBusVariant(value);
arg.endMapEntry();
}
arg.endMap();
@@ -350,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;
@@ -359,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 3553d3d151..d9a7382742 100644
--- a/src/dbus/qdbusargument_p.h
+++ b/src/dbus/qdbusargument_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSARGUMENT_P_H
#define QDBUSARGUMENT_P_H
@@ -53,6 +17,7 @@
#include <QtDBus/private/qtdbusglobal_p.h>
#include <qdbusargument.h>
+#include "qdbusconnection.h"
#include "qdbusunixfiledescriptor.h"
#include "qdbus_symbols_p.h"
@@ -69,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);
@@ -82,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);
@@ -91,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();
@@ -129,9 +99,9 @@ public:
QDBusMarshaller *beginStructure();
QDBusMarshaller *endStructure();
- QDBusMarshaller *beginArray(int id);
+ QDBusMarshaller *beginArray(QMetaType id);
QDBusMarshaller *endArray();
- QDBusMarshaller *beginMap(int kid, int vid);
+ QDBusMarshaller *beginMap(QMetaType kid, QMetaType vid);
QDBusMarshaller *endMap();
QDBusMarshaller *beginMapEntry();
QDBusMarshaller *endMapEntry();
@@ -145,24 +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();
@@ -203,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 78c596bea6..f6918b70b0 100644
--- a/src/dbus/qdbusconnection.cpp
+++ b/src/dbus/qdbusconnection.cpp
@@ -1,62 +1,19 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusconnection.h"
#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>
@@ -69,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
@@ -406,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);
}
}
@@ -465,17 +213,19 @@ QDBusConnection &QDBusConnection::operator=(const QDBusConnection &other)
}
/*!
- Opens a connection of type \a type to one of the known busses and
+ Opens a connection of type \a type to one of the known buses and
associate with it the connection name \a name. Returns a
QDBusConnection object associated with that connection.
*/
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));
}
/*!
@@ -485,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
@@ -500,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));
}
/*!
@@ -517,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);
}
/*!
@@ -538,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);
}
/*!
@@ -681,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
{
@@ -889,16 +642,16 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
return false;
- auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
+ auto pathComponents = QStringView{path}.split(u'/');
if (pathComponents.constLast().isEmpty())
pathComponents.removeLast();
QDBusWriteLocker locker(RegisterObjectAction, d);
// lower-bound search for where this object should enter in the tree
- QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator node = &d->rootNode;
+ 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
@@ -934,7 +687,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
std::lower_bound(node->children.begin(), node->children.end(), pathComponents.at(i));
if (it != node->children.end() && it->name == pathComponents.at(i)) {
// match: this node exists
- node = it;
+ node = &(*it);
// are we allowed to go deeper?
if (node->flags & ExportChildObjects) {
@@ -945,7 +698,8 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
}
} else {
// add entry
- node = node->children.insert(it, pathComponents.at(i).toString());
+ it = node->children.insert(it, pathComponents.at(i).toString());
+ node = &(*it);
}
// iterate
@@ -997,7 +751,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
return nullptr;
- auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
+ auto pathComponents = QStringView{path}.split(u'/');
if (pathComponents.constLast().isEmpty())
pathComponents.removeLast();
@@ -1007,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;
@@ -1017,7 +771,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
if (it == node->children.constEnd() || it->name != pathComponents.at(i))
break; // node not found
- node = it;
+ node = &(*it);
++i;
}
return nullptr;
@@ -1163,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));
}
/*!
@@ -1177,25 +933,12 @@ QDBusConnection QDBusConnection::sessionBus()
*/
QDBusConnection QDBusConnection::systemBus()
{
- if (_q_manager.isDestroyed())
- return QDBusConnection(nullptr);
- return QDBusConnection(_q_manager()->busConnection(SystemBus));
-}
+ auto *manager = QDBusConnectionManager::instance();
-#if QT_DEPRECATED_SINCE(5,5)
-/*!
- \deprecated
-
- Always returns a disconnected, invalid QDBusConnection object. For the old
- functionality of determining the sender connection, please use QDBusContext.
-
- \sa QDBusContext
-*/
-QDBusConnection QDBusConnection::sender()
-{
- return QDBusConnection(QString());
+ if (!manager)
+ return QDBusConnection(nullptr);
+ return QDBusConnection(manager->busConnection(SystemBus));
}
-#endif
/*!
\internal
@@ -1269,31 +1012,7 @@ QByteArray QDBusConnection::localMachineId()
QT_END_NAMESPACE
-#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
+#include "moc_qdbusconnection_p.cpp"
+#include "moc_qdbusconnection.cpp"
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusconnection.h b/src/dbus/qdbusconnection.h
index 7304f2a8a2..be8acdc4ea 100644
--- a/src/dbus/qdbusconnection.h
+++ b/src/dbus/qdbusconnection.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
#ifndef QDBUSCONNECTION_H
#define QDBUSCONNECTION_H
@@ -138,7 +102,7 @@ public:
QDBusConnection &operator=(const QDBusConnection &other);
~QDBusConnection();
- void swap(QDBusConnection &other) noexcept { qSwap(d, other.d); }
+ void swap(QDBusConnection &other) noexcept { qt_ptr_swap(d, other.d); }
bool isConnected() const;
QString baseService() const;
@@ -202,11 +166,6 @@ public:
static QDBusConnection sessionBus();
static QDBusConnection systemBus();
-#if QT_DEPRECATED_SINCE(5,5)
- static QT_DEPRECATED_X("This function no longer works, use QDBusContext instead")
- QDBusConnection sender();
-#endif
-
protected:
explicit QDBusConnection(QDBusConnectionPrivate *dd);
diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h
index 84c5aee3d7..53e6874818 100644
--- a/src/dbus/qdbusconnection_p.h
+++ b/src/dbus/qdbusconnection_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -137,7 +101,7 @@ public:
QString service, path, signature;
QObject* obj;
int midx;
- QList<int> params;
+ QList<QMetaType> params;
ArgMatchRules argumentMatch;
QByteArray matchRule;
};
@@ -151,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
@@ -167,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;
@@ -193,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();
@@ -213,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);
@@ -248,6 +212,8 @@ public:
void postEventToThread(int action, QObject *target, QEvent *event);
+ void enableDispatchDelayed(QObject *context);
+
private:
void checkThread();
bool handleError(const QDBusErrorInternal &error);
@@ -259,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<int> &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);
@@ -275,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;
@@ -290,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);
@@ -303,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;
@@ -350,18 +316,16 @@ 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<int> &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<int> &metaTypes,
+ int idx, const QList<QMetaType> &metaTypes,
const QDBusMessage &msg);
static void processFinishedCall(QDBusPendingCallPrivate *call);
@@ -374,11 +338,10 @@ public:
};
// in qdbusmisc.cpp
-extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int> &metaTypes,
- QString &errorMsg);
+extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<QMetaType> &metaTypes, QString &errorMsg);
# endif // QT_BOOTSTRAPPED
extern Q_DBUS_EXPORT int qDBusParametersForMethod(const QList<QByteArray> &parameters,
- QList<int> &metaTypes, QString &errorMsg);
+ QList<QMetaType> &metaTypes, QString &errorMsg);
extern Q_DBUS_EXPORT bool qDBusCheckAsyncTag(const char *tag);
#ifndef QT_BOOTSTRAPPED
extern bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name);
@@ -393,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/qdbusconnectioninterface.cpp b/src/dbus/qdbusconnectioninterface.cpp
index a2335a1795..0e886dcc04 100644
--- a/src/dbus/qdbusconnectioninterface.cpp
+++ b/src/dbus/qdbusconnectioninterface.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusconnectioninterface.h"
@@ -54,6 +18,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*
* Implementation of interface class QDBusConnectionInterface
*/
@@ -184,7 +150,7 @@ QDBusConnectionInterface::~QDBusConnectionInterface()
*/
QDBusReply<QString> QDBusConnectionInterface::serviceOwner(const QString &name) const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("GetNameOwner"), QList<QVariant>() << name);
+ return internalConstCall(QDBus::AutoDetect, "GetNameOwner"_L1, QList<QVariant>() << name);
}
/*!
@@ -195,7 +161,7 @@ QDBusReply<QString> QDBusConnectionInterface::serviceOwner(const QString &name)
*/
QDBusReply<QStringList> QDBusConnectionInterface::registeredServiceNames() const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("ListNames"));
+ return internalConstCall(QDBus::AutoDetect, "ListNames"_L1);
}
/*!
@@ -207,7 +173,7 @@ QDBusReply<QStringList> QDBusConnectionInterface::registeredServiceNames() const
*/
QDBusReply<QStringList> QDBusConnectionInterface::activatableServiceNames() const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("ListActivatableNames"));
+ return internalConstCall(QDBus::AutoDetect, "ListActivatableNames"_L1);
}
/*!
@@ -216,7 +182,7 @@ QDBusReply<QStringList> QDBusConnectionInterface::activatableServiceNames() cons
*/
QDBusReply<bool> QDBusConnectionInterface::isServiceRegistered(const QString &serviceName) const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("NameHasOwner"),
+ return internalConstCall(QDBus::AutoDetect, "NameHasOwner"_L1,
QList<QVariant>() << serviceName);
}
@@ -226,7 +192,7 @@ QDBusReply<bool> QDBusConnectionInterface::isServiceRegistered(const QString &se
*/
QDBusReply<uint> QDBusConnectionInterface::servicePid(const QString &serviceName) const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("GetConnectionUnixProcessID"),
+ return internalConstCall(QDBus::AutoDetect, "GetConnectionUnixProcessID"_L1,
QList<QVariant>() << serviceName);
}
@@ -236,7 +202,7 @@ QDBusReply<uint> QDBusConnectionInterface::servicePid(const QString &serviceName
*/
QDBusReply<uint> QDBusConnectionInterface::serviceUid(const QString &serviceName) const
{
- return internalConstCall(QDBus::AutoDetect, QLatin1String("GetConnectionUnixUser"),
+ return internalConstCall(QDBus::AutoDetect, "GetConnectionUnixUser"_L1,
QList<QVariant>() << serviceName);
}
@@ -245,7 +211,7 @@ QDBusReply<uint> QDBusConnectionInterface::serviceUid(const QString &serviceName
*/
QDBusReply<void> QDBusConnectionInterface::startService(const QString &name)
{
- return call(QLatin1String("StartServiceByName"), name, uint(0));
+ return call("StartServiceByName"_L1, name, uint(0));
}
/*!
@@ -290,7 +256,7 @@ QDBusConnectionInterface::registerService(const QString &serviceName,
break;
}
- QDBusMessage reply = call(QLatin1String("RequestName"), serviceName, flags);
+ QDBusMessage reply = call("RequestName"_L1, serviceName, flags);
// qDebug() << "QDBusConnectionInterface::registerService" << serviceName << "Reply:" << reply;
// convert the low-level flags to something that we can use
@@ -328,7 +294,7 @@ QDBusConnectionInterface::registerService(const QString &serviceName,
QDBusReply<bool>
QDBusConnectionInterface::unregisterService(const QString &serviceName)
{
- QDBusMessage reply = call(QLatin1String("ReleaseName"), serviceName);
+ QDBusMessage reply = call("ReleaseName"_L1, serviceName);
if (reply.type() == QDBusMessage::ReplyMessage) {
bool success = reply.arguments().at(0).toUInt() == DBUS_RELEASE_NAME_REPLY_RELEASED;
reply.setArguments(QVariantList() << success);
@@ -442,4 +408,6 @@ void QDBusConnectionInterface::disconnectNotify(const QMetaMethod &signal)
QT_END_NAMESPACE
+#include "moc_qdbusconnectioninterface.cpp"
+
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusconnectioninterface.h b/src/dbus/qdbusconnectioninterface.h
index d19e116c53..e664e4e0e7 100644
--- a/src/dbus/qdbusconnectioninterface.h
+++ b/src/dbus/qdbusconnectioninterface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSCONNECTIONINTERFACE_H
#define QDBUSCONNECTIONINTERFACE_H
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 e080abca5e..644c3c8fb1 100644
--- a/src/dbus/qdbusconnectionmanager_p.h
+++ b/src/dbus/qdbusconnectionmanager_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -61,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/qdbuscontext.cpp b/src/dbus/qdbuscontext.cpp
index de0482be70..b8cb1dc8b1 100644
--- a/src/dbus/qdbuscontext.cpp
+++ b/src/dbus/qdbuscontext.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusmessage.h"
#include "qdbusconnection.h"
diff --git a/src/dbus/qdbuscontext.h b/src/dbus/qdbuscontext.h
index fedfcbd98e..02620449e1 100644
--- a/src/dbus/qdbuscontext.h
+++ b/src/dbus/qdbuscontext.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSCONTEXT_H
#define QDBUSCONTEXT_H
diff --git a/src/dbus/qdbuscontext_p.h b/src/dbus/qdbuscontext_p.h
index 087ded8b4f..1a544b8e44 100644
--- a/src/dbus/qdbuscontext_p.h
+++ b/src/dbus/qdbuscontext_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
//
// W A R N I N G
diff --git a/src/dbus/qdbusdemarshaller.cpp b/src/dbus/qdbusdemarshaller.cpp
index c9da593ad2..ee5a6874da 100644
--- a/src/dbus/qdbusdemarshaller.cpp
+++ b/src/dbus/qdbusdemarshaller.cpp
@@ -1,46 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusargument_p.h"
#include "qdbusconnection.h"
-#include <qscopedpointer.h>
+#include <memory>
#include <stdlib.h>
@@ -426,12 +390,12 @@ QDBusDemarshaller *QDBusDemarshaller::endCommon()
QDBusArgument QDBusDemarshaller::duplicate()
{
- QScopedPointer<QDBusDemarshaller> d(new QDBusDemarshaller(capabilities));
+ std::unique_ptr<QDBusDemarshaller> d(new QDBusDemarshaller(capabilities));
d->iterator = iterator;
d->message = q_dbus_message_ref(message);
q_dbus_message_iter_next(&iterator);
- return QDBusArgumentPrivate::create(d.take());
+ return QDBusArgumentPrivate::create(d.release());
}
QT_END_NAMESPACE
diff --git a/src/dbus/qdbuserror.cpp b/src/dbus/qdbuserror.cpp
index decd345ece..49c30e5b25 100644
--- a/src/dbus/qdbuserror.cpp
+++ b/src/dbus/qdbuserror.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbuserror.h"
@@ -53,6 +17,8 @@
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QDBusError)
+
static constexpr const auto errorMessages = qOffsetStringArray(
"NoError",
"other",
@@ -210,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);
}
@@ -225,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 +204,7 @@ QDBusError::QDBusError(const QDBusMessage &qdmsg)
QDBusError::QDBusError(ErrorType error, const QString &mess)
: code(error)
{
- nm = QLatin1String(errorMessages[error]);
+ nm = QLatin1StringView(errorMessages[error]);
msg = mess;
}
@@ -272,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 {
@@ -334,7 +300,7 @@ bool QDBusError::isValid() const
*/
QString QDBusError::errorString(ErrorType error)
{
- return QLatin1String(errorMessages[error]);
+ return QLatin1StringView(errorMessages[error]);
}
#ifndef QT_NO_DEBUG_STREAM
@@ -354,12 +320,14 @@ QDebug operator<<(QDebug dbg, const QDBusError &msg)
QT_END_NAMESPACE
+#include "moc_qdbuserror.cpp"
+
#endif // QT_NO_DBUS
/*
MSVC2015 has the warning C4503 at the end of the file:
QtPrivate::StaticStringBuilder<QtPrivate::IndexesList<...> - decorated name length exceeded, name was truncated
-It is used by qOffsetStringArray in a constexpr evaulation and this code does not exist in the object file,
+It is used by qOffsetStringArray in a constexpr evaluation and this code does not exist in the object file,
but we still have the warning or even error with -WX flag
*/
QT_WARNING_DISABLE_MSVC(4503)
diff --git a/src/dbus/qdbuserror.h b/src/dbus/qdbuserror.h
index 8964f20415..292f967acb 100644
--- a/src/dbus/qdbuserror.h
+++ b/src/dbus/qdbuserror.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSERROR_H
#define QDBUSERROR_H
@@ -97,7 +61,7 @@ public:
QDBusError();
#ifndef QT_BOOTSTRAPPED
explicit QDBusError(const DBusError *error);
- /*implicit*/ QDBusError(const QDBusMessage& msg);
+ Q_IMPLICIT QDBusError(const QDBusMessage& msg);
#endif
QDBusError(ErrorType error, const QString &message);
QDBusError(const QDBusError &other);
@@ -112,9 +76,9 @@ public:
void swap(QDBusError &other) noexcept
{
- qSwap(code, other.code);
- qSwap(msg, other.msg);
- qSwap(nm, other.nm);
+ std::swap(code, other.code);
+ msg.swap(other.msg);
+ nm.swap(other.nm);
}
ErrorType type() const;
@@ -140,7 +104,7 @@ Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusError &);
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QDBusError)
+QT_DECL_METATYPE_EXTERN(QDBusError, Q_DBUS_EXPORT)
#else
QT_BEGIN_NAMESPACE
class Q_DBUS_EXPORT QDBusError {}; // dummy class for moc
diff --git a/src/dbus/qdbusextratypes.cpp b/src/dbus/qdbusextratypes.cpp
index 06fbd6062e..61f2075443 100644
--- a/src/dbus/qdbusextratypes.cpp
+++ b/src/dbus/qdbusextratypes.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusextratypes.h"
#include "qdbusutil_p.h"
@@ -44,6 +8,19 @@
QT_BEGIN_NAMESPACE
+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)) {
@@ -139,9 +116,9 @@ void QDBusSignature::doCheck()
*/
/*!
- \fn QDBusObjectPath::QDBusObjectPath(QLatin1String path)
+ \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.
*/
/*!
@@ -200,9 +177,9 @@ QDBusObjectPath::operator QVariant() const { return QVariant::fromValue(*this);
*/
/*!
- \fn QDBusSignature::QDBusSignature(QLatin1String signature)
+ \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 6b948c6895..1bc0f3086d 100644
--- a/src/dbus/qdbusextratypes.h
+++ b/src/dbus/qdbusextratypes.h
@@ -1,53 +1,14 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#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>
#include <QtCore/qstring.h>
-#if QT_DEPRECATED_SINCE(5, 6)
-#include <QtCore/qhash.h>
-#endif
#include <QtCore/qhashfunctions.h>
#ifndef QT_NO_DBUS
@@ -63,11 +24,11 @@ public:
// compiler-generated destructor is ok!
inline explicit QDBusObjectPath(const char *path);
- inline explicit QDBusObjectPath(QLatin1String path);
+ inline explicit QDBusObjectPath(QLatin1StringView path);
inline explicit QDBusObjectPath(const QString &path);
explicit QDBusObjectPath(QString &&p) : m_path(std::move(p)) { doCheck(); }
- void swap(QDBusObjectPath &other) noexcept { qSwap(m_path, other.m_path); }
+ void swap(QDBusObjectPath &other) noexcept { m_path.swap(other.m_path); }
inline void setPath(const QString &path);
@@ -85,7 +46,7 @@ inline QDBusObjectPath::QDBusObjectPath(const char *objectPath)
: m_path(QString::fromLatin1(objectPath))
{ doCheck(); }
-inline QDBusObjectPath::QDBusObjectPath(QLatin1String objectPath)
+inline QDBusObjectPath::QDBusObjectPath(QLatin1StringView objectPath)
: m_path(objectPath)
{ doCheck(); }
@@ -108,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
{
@@ -118,11 +82,11 @@ public:
// compiler-generated destructor is ok!
inline explicit QDBusSignature(const char *signature);
- inline explicit QDBusSignature(QLatin1String signature);
+ inline explicit QDBusSignature(QLatin1StringView signature);
inline explicit QDBusSignature(const QString &signature);
explicit QDBusSignature(QString &&sig) : m_signature(std::move(sig)) { doCheck(); }
- void swap(QDBusSignature &other) noexcept { qSwap(m_signature, other.m_signature); }
+ void swap(QDBusSignature &other) noexcept { m_signature.swap(other.m_signature); }
inline void setSignature(const QString &signature);
@@ -138,7 +102,7 @@ inline QDBusSignature::QDBusSignature(const char *dBusSignature)
: m_signature(QString::fromLatin1(dBusSignature))
{ doCheck(); }
-inline QDBusSignature::QDBusSignature(QLatin1String dBusSignature)
+inline QDBusSignature::QDBusSignature(QLatin1StringView dBusSignature)
: m_signature(dBusSignature)
{ doCheck(); }
@@ -172,7 +136,7 @@ public:
inline explicit QDBusVariant(const QVariant &variant);
explicit QDBusVariant(QVariant &&v) noexcept : m_variant(std::move(v)) {}
- void swap(QDBusVariant &other) noexcept { qSwap(m_variant, other.m_variant); }
+ void swap(QDBusVariant &other) noexcept { m_variant.swap(other.m_variant); }
inline void setVariant(const QVariant &variant);
@@ -192,9 +156,9 @@ inline bool operator==(const QDBusVariant &v1, const QDBusVariant &v2)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QDBusVariant)
-Q_DECLARE_METATYPE(QDBusObjectPath)
-Q_DECLARE_METATYPE(QDBusSignature)
+QT_DECL_METATYPE_EXTERN(QDBusVariant, Q_DBUS_EXPORT)
+QT_DECL_METATYPE_EXTERN(QDBusObjectPath, Q_DBUS_EXPORT)
+QT_DECL_METATYPE_EXTERN(QDBusSignature, Q_DBUS_EXPORT)
#endif // QT_NO_DBUS
#endif
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index ac55b7cb76..836562f496 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -1,48 +1,12 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusintegrator_p.h"
#include <qcoreapplication.h>
#include <qelapsedtimer.h>
-#include <qdebug.h>
+#include <qloggingcategory.h>
#include <qmetaobject.h>
#include <qobject.h>
#include <qsocketnotifier.h>
@@ -50,6 +14,7 @@
#include <qtimer.h>
#include <qthread.h>
#include <private/qlocking_p.h>
+#include <QtCore/qset.h>
#include "qdbusargument.h"
#include "qdbusconnection_p.h"
@@ -78,11 +43,17 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
+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);
-#define qDBusDebug if (::isDebugging == 0); else qDebug
+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)
{
@@ -130,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" {
@@ -153,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;
@@ -280,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();
@@ -290,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
@@ -305,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(QLatin1String("QDBusServer-") + 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"
@@ -343,27 +340,27 @@ static QByteArray buildMatchRule(const QString &service,
const QString &member, const QDBusConnectionPrivate::ArgMatchRules &argMatch, const QString & /*signature*/)
{
QString result;
- result += QLatin1String("type='signal',");
- const auto keyValue = QLatin1String("%1='%2',");
+ result += "type='signal',"_L1;
+ const auto keyValue = "%1='%2',"_L1;
if (!service.isEmpty())
- result += keyValue.arg(QLatin1String("sender"), service);
+ result += keyValue.arg("sender"_L1, service);
if (!objectPath.isEmpty())
- result += keyValue.arg(QLatin1String("path"), objectPath);
+ result += keyValue.arg("path"_L1, objectPath);
if (!interface.isEmpty())
- result += keyValue.arg(QLatin1String("interface"), interface);
+ result += keyValue.arg("interface"_L1, interface);
if (!member.isEmpty())
- result += keyValue.arg(QLatin1String("member"), member);
+ result += keyValue.arg("member"_L1, member);
// add the argument string-matching now
if (!argMatch.args.isEmpty()) {
- const QString keyValue = QLatin1String("arg%1='%2',");
- for (int i = 0; i < argMatch.args.count(); ++i)
+ const QString keyValue = "arg%1='%2',"_L1;
+ for (int i = 0; i < argMatch.args.size(); ++i)
if (!argMatch.args.at(i).isNull())
result += keyValue.arg(i).arg(argMatch.args.at(i));
}
if (!argMatch.arg0namespace.isEmpty()) {
- result += QLatin1String("arg0namespace='%1',").arg(argMatch.arg0namespace);
+ result += "arg0namespace='%1',"_L1.arg(argMatch.arg0namespace);
}
result.chop(1); // remove ending comma
@@ -374,24 +371,24 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
const QString &fullpath, int &usedLength,
QDBusConnectionPrivate::ObjectTreeNode &result)
{
- if (!fullpath.compare(QLatin1String("/")) && root->obj) {
+ if (!fullpath.compare("/"_L1) && root->obj) {
usedLength = 1;
result = *root;
return root;
}
int start = 0;
- int length = fullpath.length();
- if (fullpath.at(0) == QLatin1Char('/'))
+ int length = fullpath.size();
+ if (fullpath.at(0) == u'/')
start = 1;
// walk the object tree
- QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator node = root;
+ const QDBusConnectionPrivate::ObjectTreeNode *node = root;
while (start < length && node) {
if (node->flags & QDBusConnection::ExportChildObjects)
break;
if ((node->flags & QDBusConnectionPrivate::VirtualObject) && (node->flags & QDBusConnection::SubPath))
break;
- int end = fullpath.indexOf(QLatin1Char('/'), start);
+ int end = fullpath.indexOf(u'/', start);
end = (end == -1 ? length : end);
QStringView pathComponent = QStringView{fullpath}.mid(start, end - start);
@@ -399,7 +396,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
std::lower_bound(node->children.constBegin(), node->children.constEnd(), pathComponent);
if (it != node->children.constEnd() && it->name == pathComponent)
// match
- node = it;
+ node = &(*it);
else
node = nullptr;
@@ -422,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;
@@ -434,21 +431,18 @@ static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *ro
// we're at the correct level
return obj;
- int pos = fullpath.indexOf(QLatin1Char('/'), start);
+ int pos = fullpath.indexOf(u'/', start);
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;
@@ -465,7 +459,7 @@ static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *ro
static QDBusConnectionPrivate::ArgMatchRules matchArgsForService(const QString &service, QDBusServiceWatcher::WatchMode mode)
{
QDBusConnectionPrivate::ArgMatchRules matchArgs;
- if (service.endsWith(QLatin1Char('*'))) {
+ if (service.endsWith(u'*')) {
matchArgs.arg0namespace = service.chopped(1);
matchArgs.args << QString();
}
@@ -491,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()
@@ -506,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" {
@@ -562,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;
@@ -590,18 +588,15 @@ 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 = [](QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
-
- haystack.children.erase(std::remove_if(haystack.children.begin(), haystack.children.end(),
- isInactive),
- haystack.children.end());
+ auto isInactive = [](const QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
+ haystack.children.removeIf(isInactive);
if (needle == haystack.obj) {
haystack.obj = nullptr;
- haystack.flags = 0;
+ haystack.flags = {};
}
}
@@ -609,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
@@ -627,7 +622,7 @@ static void huntAndUnregister(const QList<QStringView> &pathComponents, int i,
if (it == end || it->name != pathComponents.at(i))
return; // node not found
- huntAndUnregister(pathComponents, i + 1, mode, it);
+ huntAndUnregister(pathComponents, i + 1, mode, &(*it));
if (!it->isActive())
node->children.erase(it);
}
@@ -637,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 + QLatin1Char('/') + 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) {
@@ -668,9 +663,10 @@ static void huntAndEmit(DBusConnection *connection, DBusMessage *msg,
}
static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
- const QString &signature_, QList<int> &metaTypes)
+ 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);
@@ -687,18 +683,20 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
if (mm.name() != name)
continue;
- int returnType = mm.returnType();
+ QMetaType returnType = mm.returnMetaType();
bool isAsync = qDBusCheckAsyncTag(mm.tag());
bool isScriptable = mm.attributes() & QMetaMethod::Scriptable;
// consistency check:
- if (isAsync && returnType != QMetaType::Void)
+ if (isAsync && returnType.id() != QMetaType::Void)
continue;
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;
@@ -729,18 +727,18 @@ static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
++i;
// make sure that the output parameters have signatures too
- if (returnType != QMetaType::UnknownType && returnType != QMetaType::Void && QDBusMetaType::typeToSignature(returnType) == nullptr)
+ if (returnType.isValid() && returnType.id() != QMetaType::Void && QDBusMetaType::typeToSignature(returnType) == nullptr)
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) {
@@ -760,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;
}
@@ -781,23 +786,22 @@ static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent
QDBusCallDeliveryEvent *QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target,
QObject *object, int idx,
- const QList<int> &metaTypes,
+ const QList<QMetaType> &metaTypes,
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
for (int i = 0; i < n; ++i)
- if (metaTypes.at(i + 1) != msg.arguments().at(i).userType() &&
- msg.arguments().at(i).userType() != qMetaTypeId<QDBusArgument>())
+ if (metaTypes.at(i + 1) != msg.arguments().at(i).metaType() &&
+ msg.arguments().at(i).metaType() != QMetaType::fromType<QDBusArgument>())
return nullptr; // no match
// we can deliver
@@ -821,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.
@@ -863,70 +868,71 @@ 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 += QLatin1Char('.');
+ 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,
- const QList<int> &metaTypes, int slotIdx)
+void QDBusConnectionPrivate::deliverCall(QObject *object, const QDBusMessage &msg,
+ const QList<QMetaType> &metaTypes, int slotIdx)
{
Q_ASSERT_X(!object || QThread::currentThread() == object->thread(),
"QDBusConnection: internal threading error",
"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.size()); // keep references to the entries
- QVariantList auxParameters;
// let's create the parameter list
// first one is the return type -- add it below
@@ -934,60 +940,59 @@ 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) {
- int id = metaTypes[i];
+ auto id = metaTypes[i];
if (id == QDBusMetaTypeId::message())
break;
- const QVariant &arg = msg.arguments().at(i - 1);
- if (arg.userType() == id)
+ 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()));
- else if (arg.userType() == qMetaTypeId<QDBusArgument>()) {
+ else if (arg.metaType() == QMetaType::fromType<QDBusArgument>()) {
// convert to what the function expects
- void *null = nullptr;
- auxParameters.append(QVariant(id, null));
+ auxParameters.append(QVariant(QMetaType(id)));
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.userType(), out.data())))
+ if (Q_UNLIKELY(!QDBusMetaType::demarshall(in, out.metaType(), out.data())))
qFatal("Internal error: demarshalling function for type '%s' (%d) failed!",
- out.typeName(), out.userType());
+ out.typeName(), out.metaType().id());
params.append(const_cast<void *>(out.constData()));
} else {
qFatal("Internal error: got invalid meta type %d (%s) "
"when trying to convert to meta type %d (%s)",
- arg.userType(), QMetaType::typeName(arg.userType()),
- id, QMetaType::typeName(id));
+ arg.metaType().id(), arg.metaType().name(),
+ id.id(), id.name());
}
}
- 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;
- void *null = nullptr;
- if (metaTypes[0] != QMetaType::Void && metaTypes[0] != QMetaType::UnknownType) {
+ if (metaTypes[0].id() != QMetaType::Void && metaTypes[0].isValid()) {
outputArgs.reserve(numMetaTypes - i + 1);
- QVariant arg(metaTypes[0], null);
+ 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);
}
for ( ; i < numMetaTypes; ++i) {
- QVariant arg(metaTypes[i], null);
+ 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:
@@ -1016,35 +1021,31 @@ void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const Q
send(msg.createReply(outputArgs));
} else {
// generate internal error
- qWarning("Internal error: Failed to deliver message");
- send(msg.createErrorReply(QDBusError::InternalError,
- QLatin1String("Failed to deliver message")));
+ qCWarning(dbusIntegration, "Internal error: Failed to deliver message");
+ send(msg.createErrorReply(QDBusError::InternalError, "Failed to deliver message"_L1));
}
}
return;
}
-extern bool qDBusInitThreads();
-
-QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
- : QObject(p),
- ref(1),
+QDBusConnectionPrivate::QDBusConnectionPrivate()
+ : ref(1),
mode(InvalidMode),
busService(nullptr),
connection(nullptr),
- rootNode(QString(QLatin1Char('/'))),
+ rootNode(QStringLiteral("/")),
anonymousAuthenticationAllowed(false),
dispatchEnabled(true),
isAuthenticated(false)
{
static const bool threads = q_dbus_threads_init_default();
- if (::isDebugging == -1)
- ::isDebugging = qEnvironmentVariableIntValue("QDBUS_DEBUG");
Q_UNUSED(threads);
+ if (::isDebugging.loadRelaxed() == -1)
+ ::isDebugging.storeRelaxed(qEnvironmentVariableIntValue("QDBUS_DEBUG"));
#ifdef QDBUS_THREAD_DEBUG
- if (::isDebugging > 1)
+ if (::isDebugging.loadRelaxed() > 1)
qdbusThreadDebug = qdbusDefaultThreadDebug;
#endif
@@ -1055,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
@@ -1074,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();
@@ -1104,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);
@@ -1137,7 +1131,11 @@ void QDBusConnectionPrivate::closeConnection()
}
}
- qDeleteAll(pendingCalls);
+ for (QDBusPendingCallPrivate *call : pendingCalls) {
+ if (!call->ref.deref())
+ delete call;
+ }
+ pendingCalls.clear();
// Disconnect all signals from signal hooks and from the object tree to
// avoid QObject::destroyed being sent to dbus daemon thread which has
@@ -1146,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()
@@ -1197,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) ;
}
}
@@ -1279,16 +1269,16 @@ void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, in
checkThread();
QDBusReadLocker locker(RelaySignalAction, this);
- QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/"), interface,
- QLatin1String(memberName));
+ QDBusMessage message = QDBusMessage::createSignal("/"_L1, interface,
+ QLatin1StringView(memberName));
QDBusMessagePrivate::setParametersValidated(message, true);
message.setArguments(args);
QDBusError error;
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;
}
@@ -1303,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<int> &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;
@@ -1362,15 +1352,15 @@ bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hoo
mname = QString::fromUtf8(normalizedName);
}
key = mname;
- key.reserve(interface.length() + 1 + mname.length());
- key += QLatin1Char(':');
+ 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 += QLatin1String( QDBusMetaType::typeToSignature( hook.params.at(i) ) );
+ hook.signature += QLatin1StringView(QDBusMetaType::typeToSignature(hook.params.at(i)));
}
hook.matchRule = buildMatchRule(service, path, interface, mname, argMatch, hook.signature);
@@ -1382,21 +1372,20 @@ void QDBusConnectionPrivate::sendError(const QDBusMessage &msg, QDBusError::Erro
if (code == QDBusError::UnknownMethod) {
QString interfaceMsg;
if (msg.interface().isEmpty())
- interfaceMsg = QLatin1String("any interface");
+ interfaceMsg = "any interface"_L1;
else
- interfaceMsg = QLatin1String("interface '%1'").arg(msg.interface());
+ interfaceMsg = "interface '%1'"_L1.arg(msg.interface());
- send(msg.createErrorReply(code,
- QLatin1String("No such method '%1' in %2 at object path '%3' "
- "(signature '%4')")
+ send(msg.createErrorReply(code, "No such method '%1' in %2 at object path '%3' "
+ "(signature '%4')"_L1
.arg(msg.member(), interfaceMsg, msg.path(), msg.signature())));
} else if (code == QDBusError::UnknownInterface) {
send(msg.createErrorReply(QDBusError::UnknownInterface,
- QLatin1String("No such interface '%1' at object path '%2'")
+ "No such interface '%1' at object path '%2'"_L1
.arg(msg.interface(), msg.path())));
} else if (code == QDBusError::UnknownObject) {
send(msg.createErrorReply(QDBusError::UnknownObject,
- QLatin1String("No such object path '%1'").arg(msg.path())));
+ "No such object path '%1'"_L1.arg(msg.path())));
}
}
@@ -1407,7 +1396,7 @@ bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node,
const QString interface = msg.interface();
if (interface.isEmpty() || interface == QDBusUtil::dbusInterfaceIntrospectable()) {
- if (msg.member() == QLatin1String("Introspect") && msg.signature().isEmpty()) {
+ if (msg.member() == "Introspect"_L1 && msg.signature().isEmpty()) {
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters introspect" << msg.d_ptr->msg;
QDBusMessage reply = msg.createReply(qDBusIntrospectObject(node, msg.path()));
send(reply);
@@ -1423,15 +1412,15 @@ bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node,
if (node.obj && (interface.isEmpty() ||
interface == QDBusUtil::dbusInterfaceProperties())) {
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters properties" << msg.d_ptr->msg;
- if (msg.member() == QLatin1String("Get") && msg.signature() == QLatin1String("ss")) {
+ if (msg.member() == "Get"_L1 && msg.signature() == "ss"_L1) {
QDBusMessage reply = qDBusPropertyGet(node, msg);
send(reply);
return true;
- } else if (msg.member() == QLatin1String("Set") && msg.signature() == QLatin1String("ssv")) {
+ } else if (msg.member() == "Set"_L1 && msg.signature() == "ssv"_L1) {
QDBusMessage reply = qDBusPropertySet(node, msg);
send(reply);
return true;
- } else if (msg.member() == QLatin1String("GetAll") && msg.signature() == QLatin1String("s")) {
+ } else if (msg.member() == "GetAll"_L1 && msg.signature() == "s"_L1) {
QDBusMessage reply = qDBusPropertyGetAll(node, msg);
send(reply);
return true;
@@ -1465,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) {
@@ -1477,25 +1466,22 @@ 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;
it = std::lower_bound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
msg.interface());
- if (it != connector->adaptors.constEnd() && msg.interface() == QLatin1String(it->interface)) {
+ if (it != connector->adaptors.constEnd() && msg.interface() == QLatin1StringView(it->interface)) {
if (!activateCall(it->adaptor, newflags, msg))
sendError(msg, QDBusError::UnknownMethod);
return;
@@ -1566,8 +1552,8 @@ void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg)
objThread = result.obj->thread();
if (!objThread) {
send(msg.createErrorReply(QDBusError::InternalError,
- QLatin1String("Object '%1' (at path '%2')"
- " has no thread. Cannot deliver message.")
+ "Object '%1' (at path '%2')"
+ " has no thread. Cannot deliver message."_L1
.arg(result.obj->objectName(), msg.path())));
return;
}
@@ -1665,8 +1651,8 @@ void QDBusConnectionPrivate::handleSignal(const QString &key, const QDBusMessage
if (arguments.size() < 1)
continue;
const QString param = arguments.at(0).toString();
- if (param != hook.argumentMatch.arg0namespace
- && !param.startsWith(hook.argumentMatch.arg0namespace + QLatin1Char('.')))
+ const QStringView ns = hook.argumentMatch.arg0namespace;
+ if (!param.startsWith(ns) || (param.size() != ns.size() && param[ns.size()] != u'.'))
continue;
}
activateSignal(hook, msg);
@@ -1683,17 +1669,17 @@ void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg)
// (but not both)
QString key = msg.member();
- key.reserve(key.length() + 1 + msg.interface().length());
- key += QLatin1Char(':');
+ 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 = QLatin1Char(':');
+ key = u':';
key += msg.interface();
handleSignal(key, msg); // third try
}
@@ -1705,10 +1691,10 @@ void QDBusConnectionPrivate::watchForDBusDisconnection()
hook.service.clear(); // org.freedesktop.DBus.Local.Disconnected uses empty service name
hook.path = QDBusUtil::dbusPathLocal();
hook.obj = this;
- hook.params << QMetaType::Void;
+ hook.params << QMetaType(QMetaType::Void);
hook.midx = staticMetaObject.indexOfSlot("handleDBusDisconnection()");
Q_ASSERT(hook.midx != -1);
- signalHooks.insert(QLatin1String("Disconnected:" DBUS_INTERFACE_LOCAL), hook);
+ signalHooks.insert("Disconnected:" DBUS_INTERFACE_LOCAL ""_L1, hook);
}
void QDBusConnectionPrivate::setServer(QDBusServer *object, DBusServer *s, const QDBusErrorInternal &error)
@@ -1778,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);
@@ -1807,7 +1793,7 @@ static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnecti
void QDBusConnectionPrivate::handleAuthentication()
{
- capabilities.storeRelaxed(connectionCapabilies(connection));
+ capabilities.storeRelaxed(::connectionCapabilities(connection));
isAuthenticated = true;
}
@@ -1842,31 +1828,31 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError
hook.service = QDBusUtil::dbusService();
hook.path.clear(); // no matching
hook.obj = this;
- hook.params << QMetaType::Void << QMetaType::QString; // both functions take a QString as parameter and return void
+ hook.params << QMetaType(QMetaType::Void) << QMetaType(QMetaType::QString); // both functions take a QString as parameter and return void
hook.midx = staticMetaObject.indexOfSlot("registerServiceNoLock(QString)");
Q_ASSERT(hook.midx != -1);
- signalHooks.insert(QLatin1String("NameAcquired:" DBUS_INTERFACE_DBUS), hook);
+ signalHooks.insert("NameAcquired:" DBUS_INTERFACE_DBUS ""_L1, hook);
hook.midx = staticMetaObject.indexOfSlot("unregisterServiceNoLock(QString)");
Q_ASSERT(hook.midx != -1);
- signalHooks.insert(QLatin1String("NameLost:" DBUS_INTERFACE_DBUS), hook);
+ signalHooks.insert("NameLost:" DBUS_INTERFACE_DBUS ""_L1, hook);
// And initialize the hook for the NameOwnerChanged signal;
// we don't use connectSignal here because the rules are added by connectSignal on a per-need basis
hook.params.clear();
hook.params.reserve(4);
- hook.params << QMetaType::Void << QMetaType::QString << QMetaType::QString << QMetaType::QString;
+ hook.params << QMetaType(QMetaType::Void) << QMetaType(QMetaType::QString) << QMetaType(QMetaType::QString) << QMetaType(QMetaType::QString);
hook.midx = staticMetaObject.indexOfSlot("serviceOwnerChangedNoLock(QString,QString,QString)");
Q_ASSERT(hook.midx != -1);
- signalHooks.insert(QLatin1String("NameOwnerChanged:" DBUS_INTERFACE_DBUS), hook);
+ signalHooks.insert("NameOwnerChanged:" DBUS_INTERFACE_DBUS ""_L1, hook);
watchForDBusDisconnection();
qDBusDebug() << this << ": connected successfully";
// schedule a dispatch:
- QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection);
+ QMetaObject::invokeMethod(this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection);
}
extern "C"{
@@ -1874,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);
}
}
@@ -1952,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;
}
@@ -1987,20 +1976,20 @@ 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)
// when in a release build, we default these to off.
// this means that we only affect code that explicitly enables the warning.
- static int mainThreadWarningAmount = -1;
- static int otherThreadWarningAmount = -1;
+ Q_CONSTINIT static int mainThreadWarningAmount = -1;
+ Q_CONSTINIT static int otherThreadWarningAmount = -1;
#else
- static int mainThreadWarningAmount = 200;
- static int otherThreadWarningAmount = 500;
+ Q_CONSTINIT static int mainThreadWarningAmount = 200;
+ Q_CONSTINIT static int otherThreadWarningAmount = 500;
#endif
- static bool initializedAmounts = false;
- static QBasicMutex initializeMutex;
+ Q_CONSTINIT static bool initializedAmounts = false;
+ Q_CONSTINIT static QBasicMutex initializeMutex;
auto locker = qt_unique_lock(initializeMutex);
if (!initializedAmounts) {
@@ -2014,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");
@@ -2023,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;
@@ -2048,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()));
}
}
@@ -2061,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
@@ -2103,9 +2090,9 @@ QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal(const QDBusMessage &mess
if (!handled) {
QString interface = message.interface();
if (interface.isEmpty())
- interface = QLatin1String("<no-interface>");
+ interface = "<no-interface>"_L1;
return QDBusMessage::createError(QDBusError::InternalError,
- QLatin1String("Internal error trying to call %1.%2 at %3 (signature '%4'")
+ "Internal error trying to call %1.%2 at %3 (signature '%4'"_L1
.arg(interface, message.member(),
message.path(), message.signature()));
}
@@ -2113,12 +2100,15 @@ 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,
- QLatin1String("local-loop message cannot have delayed replies")));
+ "local-loop message cannot have delayed replies"_L1));
}
// there is a reply
@@ -2141,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);
@@ -2166,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);
@@ -2240,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:
@@ -2330,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);
@@ -2369,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;
@@ -2423,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));
}
}
@@ -2434,10 +2459,10 @@ void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnecti
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
QList<QStringView> pathComponents;
int i;
- if (path == QLatin1String("/")) {
+ if (path == "/"_L1) {
i = 0;
} else {
- pathComponents = QStringView{path}.split(QLatin1Char('/'));
+ pathComponents = QStringView{path}.split(u'/');
i = 1;
}
@@ -2457,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,
@@ -2478,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)
@@ -2586,6 +2619,11 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa
if (mo)
return mo;
}
+ if (path.isEmpty()) {
+ error = QDBusError(QDBusError::InvalidObjectPath, "Object path cannot be empty"_L1);
+ lastError = error;
+ return nullptr;
+ }
// introspect the target object
QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
@@ -2606,7 +2644,7 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa
QString xml;
if (reply.type() == QDBusMessage::ReplyMessage) {
- if (reply.signature() == QLatin1String("s"))
+ if (reply.signature() == "s"_L1)
// fetch the XML description
xml = reply.arguments().at(0).toString();
} else {
@@ -2663,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 be6efa4027..b0c349799a 100644
--- a/src/dbus/qdbusintegrator_p.h
+++ b/src/dbus/qdbusintegrator_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -82,18 +46,34 @@ struct QDBusSlotCache
{
struct Data
{
- int flags;
int slotIdx;
- QList<int> metaTypes;
+ 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); }
@@ -105,27 +85,21 @@ class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent
{
public:
QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
- const QDBusMessage &msg, const QList<int> &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:
QDBusConnection connection; // just for refcounting
QDBusMessage message;
- QList<int> metaTypes;
+ QList<QMetaType> metaTypes;
int id;
- int flags;
};
class QDBusActivateObjectEvent: public QAbstractMetaCallEvent
@@ -153,23 +127,20 @@ 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
-Q_DECLARE_METATYPE(QDBusSlotCache)
+QT_DECL_METATYPE_EXTERN(QDBusSlotCache, Q_DBUS_EXPORT)
#endif // QT_NO_DBUS
#endif
diff --git a/src/dbus/qdbusinterface.cpp b/src/dbus/qdbusinterface.cpp
index c1b0feea37..d4da36b35c 100644
--- a/src/dbus/qdbusinterface.cpp
+++ b/src/dbus/qdbusinterface.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusinterface.h"
#include "qdbusinterface_p.h"
@@ -51,9 +15,11 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
static void copyArgument(void *to, int id, const QVariant &arg)
{
- if (id == arg.userType()) {
+ if (id == arg.metaType().id()) {
switch (id) {
case QMetaType::Bool:
*reinterpret_cast<bool *>(to) = arg.toBool();
@@ -104,13 +70,13 @@ static void copyArgument(void *to, int id, const QVariant &arg)
return;
}
- if (id == QDBusMetaTypeId::variant()) {
+ if (id == QDBusMetaTypeId::variant().id()) {
*reinterpret_cast<QDBusVariant *>(to) = qvariant_cast<QDBusVariant>(arg);
return;
- } else if (id == QDBusMetaTypeId::objectpath()) {
+ } else if (id == QDBusMetaTypeId::objectpath().id()) {
*reinterpret_cast<QDBusObjectPath *>(to) = qvariant_cast<QDBusObjectPath>(arg);
return;
- } else if (id == QDBusMetaTypeId::signature()) {
+ } else if (id == QDBusMetaTypeId::signature().id()) {
*reinterpret_cast<QDBusSignature *>(to) = qvariant_cast<QDBusSignature>(arg);
return;
}
@@ -121,14 +87,14 @@ static void copyArgument(void *to, int id, const QVariant &arg)
}
// if we got here, it's either an un-dermarshalled type or a mismatch
- if (arg.userType() != QDBusMetaTypeId::argument()) {
+ if (arg.metaType() != QDBusMetaTypeId::argument()) {
// it's a mismatch
//qWarning?
return;
}
// is this type registered?
- const char *userSignature = QDBusMetaType::typeToSignature(id);
+ const char *userSignature = QDBusMetaType::typeToSignature(QMetaType(id));
if (!userSignature || !*userSignature) {
// type not registered
//qWarning?
@@ -137,14 +103,14 @@ static void copyArgument(void *to, int id, const QVariant &arg)
// is it the same signature?
QDBusArgument dbarg = qvariant_cast<QDBusArgument>(arg);
- if (dbarg.currentSignature() != QLatin1String(userSignature)) {
+ if (dbarg.currentSignature() != QLatin1StringView(userSignature)) {
// not the same signature, another mismatch
//qWarning?
return;
}
// we can demarshall
- QDBusMetaType::demarshall(dbarg, id, to);
+ QDBusMetaType::demarshall(dbarg, QMetaType(id), to);
}
QDBusInterfacePrivate::QDBusInterfacePrivate(const QString &serv, const QString &p,
@@ -161,7 +127,7 @@ QDBusInterfacePrivate::QDBusInterfacePrivate(const QString &serv, const QString
// those are not fatal errors, so we continue working
if (!lastError.isValid())
- lastError = QDBusError(QDBusError::InternalError, QLatin1String("Unknown error"));
+ lastError = QDBusError(QDBusError::InternalError, "Unknown error"_L1);
}
}
}
@@ -289,7 +255,7 @@ int QDBusInterfacePrivate::metacall(QMetaObject::Call c, int id, void **argv)
args.reserve(inputTypesCount);
int i = 1;
for ( ; i <= inputTypesCount; ++i)
- args << QVariant(inputTypes[i], argv[i]);
+ args << QVariant(QMetaType(inputTypes[i]), argv[i]);
// make the call
QDBusMessage reply = q->callWithArgumentList(QDBus::Block, methodName, args);
diff --git a/src/dbus/qdbusinterface.h b/src/dbus/qdbusinterface.h
index c147d07d50..fc02463ac7 100644
--- a/src/dbus/qdbusinterface.h
+++ b/src/dbus/qdbusinterface.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSINTERFACE_H
#define QDBUSINTERFACE_H
diff --git a/src/dbus/qdbusinterface_p.h b/src/dbus/qdbusinterface_p.h
index b726925306..caf24e589d 100644
--- a/src/dbus/qdbusinterface_p.h
+++ b/src/dbus/qdbusinterface_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
//
// W A R N I N G
diff --git a/src/dbus/qdbusinternalfilters.cpp b/src/dbus/qdbusinternalfilters.cpp
index 74cc470596..721564ed3c 100644
--- a/src/dbus/qdbusinternalfilters.cpp
+++ b/src/dbus/qdbusinternalfilters.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusconnection_p.h"
@@ -63,9 +27,11 @@
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"
@@ -107,16 +73,13 @@ 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 += QLatin1String(" <node name=\"") + name + QLatin1String("\"/>\n");
+ retval += " <node name=\""_L1 + name + "\"/>\n"_L1;
}
return retval;
}
@@ -127,8 +90,8 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node
{
// object may be null
- QString xml_data(QLatin1String(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE));
- xml_data += QLatin1String("<node>\n");
+ QString xml_data(DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE ""_L1);
+ xml_data += "<node>\n"_L1;
if (node.obj) {
Q_ASSERT_X(QThread::currentThread() == node.obj->thread(),
@@ -150,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;
@@ -175,26 +140,23 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node
xml_data += node.treeNode->introspect(path);
}
- xml_data += QLatin1String( propertiesInterfaceXml );
+ xml_data += QLatin1StringView(propertiesInterfaceXml);
}
- xml_data += QLatin1String( introspectableInterfaceXml );
- xml_data += QLatin1String( peerInterfaceXml );
+ xml_data += QLatin1StringView(introspectableInterfaceXml);
+ xml_data += QLatin1StringView(peerInterfaceXml);
if (node.flags & QDBusConnection::ExportChildObjects) {
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 += QLatin1String(" <node name=\"") + it->name + QLatin1String("\"/>\n");
+ for (const QDBusConnectionPrivate::ObjectTreeNode &node : node.children) {
+ if (node.obj || !node.children.isEmpty())
+ xml_data += " <node name=\""_L1 + node.name + "\"/>\n"_L1;
+ }
}
- xml_data += QLatin1String("</node>\n");
+ xml_data += "</node>\n"_L1;
return xml_data;
}
@@ -203,7 +165,7 @@ QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode &node
static inline QDBusMessage interfaceNotFoundError(const QDBusMessage &msg, const QString &interface_name)
{
return msg.createErrorReply(QDBusError::UnknownInterface,
- QLatin1String("Interface %1 was not found in object %2")
+ "Interface %1 was not found in object %2"_L1
.arg(interface_name, msg.path()));
}
@@ -211,17 +173,17 @@ static inline QDBusMessage
propertyNotFoundError(const QDBusMessage &msg, const QString &interface_name, const QByteArray &property_name)
{
return msg.createErrorReply(QDBusError::UnknownProperty,
- QLatin1String("Property %1%2%3 was not found in object %4")
+ "Property %1%2%3 was not found in object %4"_L1
.arg(interface_name,
- QLatin1String(interface_name.isEmpty() ? "" : "."),
- QLatin1String(property_name),
+ interface_name.isEmpty() ? ""_L1 : "."_L1,
+ QLatin1StringView(property_name),
msg.path()));
}
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!!");
@@ -229,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 &&
@@ -238,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;
}
}
@@ -251,7 +212,7 @@ QDBusMessage qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode &node
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
it = std::lower_bound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
interface_name);
- if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
+ if (it != connector->adaptors.constEnd() && interface_name == QLatin1StringView(it->interface)) {
interfaceFound = true;
value = it->adaptor->property(property_name);
}
@@ -302,16 +263,16 @@ static QDBusMessage propertyWriteReply(const QDBusMessage &msg, const QString &i
return propertyNotFoundError(msg, interface_name, property_name);
case PropertyTypeMismatch:
return msg.createErrorReply(QDBusError::InvalidArgs,
- QLatin1String("Invalid arguments for writing to property %1%2%3")
+ "Invalid arguments for writing to property %1%2%3"_L1
.arg(interface_name,
- QLatin1String(interface_name.isEmpty() ? "" : "."),
- QLatin1String(property_name)));
+ interface_name.isEmpty() ? ""_L1 : "."_L1,
+ QLatin1StringView(property_name)));
case PropertyReadOnly:
return msg.createErrorReply(QDBusError::PropertyReadOnly,
- QLatin1String("Property %1%2%3 is read-only")
+ "Property %1%2%3 is read-only"_L1
.arg(interface_name,
- QLatin1String(interface_name.isEmpty() ? "" : "."),
- QLatin1String(property_name)));
+ interface_name.isEmpty() ? ""_L1 : "."_L1,
+ QLatin1StringView(property_name)));
case PropertyWriteFailed:
return msg.createErrorReply(QDBusError::InternalError,
QString::fromLatin1("Internal error"));
@@ -348,39 +309,38 @@ static int writeProperty(QObject *obj, const QByteArray &property_name, QVariant
// we found our property
// do we have the right type?
- int id = mp.userType();
- if (!id){
+ QMetaType id = mp.metaType();
+ if (!id.isValid()){
// type not registered or invalid / void?
qWarning("QDBusConnection: Unable to handle unregistered datatype '%s' for property '%s::%s'",
mp.typeName(), mo->className(), property_name.constData());
return PropertyWriteFailed;
}
- if (id != QMetaType::QVariant && value.userType() == QDBusMetaTypeId::argument()) {
+ if (id.id() != QMetaType::QVariant && value.metaType() == QDBusMetaTypeId::argument()) {
// we have to demarshall before writing
- void *null = nullptr;
- QVariant other(id, null);
- if (!QDBusMetaType::demarshall(qvariant_cast<QDBusArgument>(value), id, other.data())) {
- qWarning("QDBusConnection: type `%s' (%d) is not registered with QtDBus. "
+ 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. "
"Use qDBusRegisterMetaType to register it",
- mp.typeName(), id);
+ mp.typeName(), id.id());
return PropertyWriteFailed;
}
- value = other;
+ value = std::move(other);
}
- if (mp.userType() == qMetaTypeId<QDBusVariant>())
+ 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!!");
@@ -396,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);
@@ -407,7 +367,7 @@ QDBusMessage qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode &node
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
it = std::lower_bound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
interface_name);
- if (it != connector->adaptors.cend() && interface_name == QLatin1String(it->interface)) {
+ if (it != connector->adaptors.cend() && interface_name == QLatin1StringView(it->interface)) {
return propertyWriteReply(msg, interface_name, property_name,
writeProperty(it->adaptor, property_name, value));
}
@@ -436,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;
}
@@ -457,10 +415,10 @@ static QVariantMap readAllProperties(QObject *object, int flags)
continue;
// is it a registered property?
- int typeId = mp.userType();
- if (!typeId)
+ QMetaType type = mp.metaType();
+ if (!type.isValid())
continue;
- const char *signature = QDBusMetaType::typeToSignature(typeId);
+ const char *signature = QDBusMetaType::typeToSignature(type);
if (!signature)
continue;
@@ -480,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!!");
@@ -496,16 +454,17 @@ 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
QDBusAdaptorConnector::AdaptorMap::ConstIterator it;
it = std::lower_bound(connector->adaptors.constBegin(), connector->adaptors.constEnd(),
interface_name);
- if (it != connector->adaptors.constEnd() && interface_name == QLatin1String(it->interface)) {
+ if (it != connector->adaptors.constEnd() && interface_name == QLatin1StringView(it->interface)) {
interfaceFound = true;
result = readAllProperties(it->adaptor, QDBusConnection::ExportAllProperties);
}
diff --git a/src/dbus/qdbusintrospection.cpp b/src/dbus/qdbusintrospection.cpp
index 6e406f7616..04b5ab7751 100644
--- a/src/dbus/qdbusintrospection.cpp
+++ b/src/dbus/qdbusintrospection.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusintrospection_p.h"
#include "qdbusxmlparser_p.h"
@@ -57,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
@@ -333,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();
@@ -351,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();
}
@@ -370,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 9afa0a3420..766cdffb62 100644
--- a/src/dbus/qdbusintrospection_p.h
+++ b/src/dbus/qdbusintrospection_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSINTROSPECTION_P_H
#define QDBUSINTROSPECTION_P_H
@@ -54,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>
@@ -74,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;
@@ -87,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;
@@ -98,6 +94,7 @@ public:
struct Method
{
+ SourceLocation location;
QString name;
Arguments inputArgs;
Arguments outputArgs;
@@ -110,6 +107,7 @@ public:
struct Signal
{
+ SourceLocation location;
QString name;
Arguments outputArgs;
Annotations annotations;
@@ -122,6 +120,7 @@ public:
struct Property
{
enum Access { Read, Write, ReadWrite };
+ SourceLocation location;
QString name;
QString type;
Access access;
@@ -134,6 +133,7 @@ public:
struct Interface: public QSharedData
{
+ SourceLocation location;
QString name;
QString introspection;
@@ -148,6 +148,7 @@ public:
struct Object: public QSharedData
{
+ SourceLocation location;
QString service;
QString path;
@@ -156,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 c80131f41d..b2ed2586fb 100644
--- a/src/dbus/qdbusmarshaller.cpp
+++ b/src/dbus/qdbusmarshaller.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusargument_p.h"
#include "qdbusconnection.h"
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
static void qIterAppend(DBusMessageIter *it, QByteArray *ba, int type, const void *arg)
{
if (ba)
@@ -59,6 +25,16 @@ QDBusMarshaller::~QDBusMarshaller()
close();
}
+void QDBusMarshaller::unregisteredTypeError(QMetaType id)
+{
+ const char *name = id.name();
+ 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
+ .arg(QLatin1StringView(id.name())));
+}
+
inline QString QDBusMarshaller::currentSignature()
{
if (message)
@@ -133,7 +109,7 @@ inline void QDBusMarshaller::append(const QDBusObjectPath &arg)
{
QByteArray data = arg.path().toUtf8();
if (!ba && data.isEmpty()) {
- error(QLatin1String("Invalid object path passed in arguments"));
+ error("Invalid object path passed in arguments"_L1);
} else {
const char *cdata = data.constData();
if (!skipSignature)
@@ -145,7 +121,7 @@ inline void QDBusMarshaller::append(const QDBusSignature &arg)
{
QByteArray data = arg.signature().toUtf8();
if (!ba && data.isEmpty()) {
- error(QLatin1String("Invalid signature passed in arguments"));
+ error("Invalid signature passed in arguments"_L1);
} else {
const char *cdata = data.constData();
if (!skipSignature)
@@ -157,7 +133,7 @@ inline void QDBusMarshaller::append(const QDBusUnixFileDescriptor &arg)
{
int fd = arg.fileDescriptor();
if (!ba && fd == -1) {
- error(QLatin1String("Invalid file descriptor passed in arguments"));
+ error("Invalid file descriptor passed in arguments"_L1);
} else {
if (!skipSignature)
qIterAppend(&iterator, ba, DBUS_TYPE_UNIX_FD, &fd);
@@ -176,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);
}
@@ -189,10 +165,10 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
}
const QVariant &value = arg.variant();
- int id = value.userType();
- if (id == QMetaType::UnknownType) {
+ QMetaType id = value.metaType();
+ if (!id.isValid()) {
qWarning("QDBusMarshaller: cannot add a null QDBusVariant");
- error(QLatin1String("Variant containing QVariant::Invalid passed in arguments"));
+ error("Invalid QVariant passed in arguments"_L1);
return false;
}
@@ -208,11 +184,7 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
signature = QDBusMetaType::typeToSignature(id);
}
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- QMetaType::typeName(id), id);
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(QMetaType::typeName(id))));
+ unregisteredTypeError(id);
return false;
}
@@ -234,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
}
@@ -246,48 +216,38 @@ inline QDBusMarshaller *QDBusMarshaller::beginStructure()
return beginCommon(DBUS_TYPE_STRUCT, nullptr);
}
-inline QDBusMarshaller *QDBusMarshaller::beginArray(int id)
+inline QDBusMarshaller *QDBusMarshaller::beginArray(QMetaType id)
{
- const char *signature = QDBusMetaType::typeToSignature( QVariant::Type(id) );
+ const char *signature = QDBusMetaType::typeToSignature(id);
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- QMetaType::typeName(id), id);
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(QMetaType::typeName(id))));
+ unregisteredTypeError(id);
return this;
}
return beginCommon(DBUS_TYPE_ARRAY, signature);
}
-inline QDBusMarshaller *QDBusMarshaller::beginMap(int kid, int vid)
+inline QDBusMarshaller *QDBusMarshaller::beginMap(QMetaType kid, QMetaType vid)
{
- const char *ksignature = QDBusMetaType::typeToSignature( QVariant::Type(kid) );
+ const char *ksignature = QDBusMetaType::typeToSignature(kid);
if (!ksignature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- QMetaType::typeName(kid), kid);
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(QMetaType::typeName(kid))));
+ unregisteredTypeError(kid);
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.",
- QMetaType::typeName(kid), kid);
- error(QLatin1String("Type %1 passed in arguments cannot be used as a key in a map")
- .arg(QLatin1String(QMetaType::typeName(kid))));
+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;
}
- const char *vsignature = QDBusMetaType::typeToSignature( QVariant::Type(vid) );
+ const char *vsignature = QDBusMetaType::typeToSignature(vid);
if (!vsignature) {
- const char *typeName = QMetaType::typeName(vid);
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- typeName, vid);
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(typeName)));
+ unregisteredTypeError(vid);
return this;
}
@@ -383,10 +343,10 @@ void QDBusMarshaller::error(const QString &msg)
bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
{
- int id = arg.userType();
- if (id == QMetaType::UnknownType) {
+ QMetaType id = arg.metaType();
+ if (!id.isValid()) {
qWarning("QDBusMarshaller: cannot add an invalid QVariant");
- error(QLatin1String("Variant containing QVariant::Invalid passed in arguments"));
+ error("Invalid QVariant passed in arguments"_L1);
return false;
}
@@ -400,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 {
@@ -412,13 +372,9 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
return appendCrossMarshalling(&demarshaller);
}
- const char *signature = QDBusMetaType::typeToSignature( QVariant::Type(id) );
+ const char *signature = QDBusMetaType::typeToSignature(id);
if (!signature) {
- qWarning("QDBusMarshaller: type `%s' (%d) is not registered with D-BUS. "
- "Use qDBusRegisterMetaType to register it",
- QMetaType::typeName(id), id);
- error(QLatin1String("Unregistered type %1 passed in arguments")
- .arg(QLatin1String(QMetaType::typeName(id))));
+ unregisteredTypeError(id);
return false;
}
@@ -485,7 +441,7 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
case DBUS_TYPE_ARRAY:
// could be many things
// find out what kind of array it is
- switch (arg.userType()) {
+ switch (arg.metaType().id()) {
case QMetaType::QStringList:
append( arg.toStringList() );
return true;
@@ -516,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;
}
@@ -528,7 +484,7 @@ bool QDBusMarshaller::appendRegisteredType(const QVariant &arg)
{
ref.ref(); // reference up
QDBusArgument self(QDBusArgumentPrivate::create(this));
- return QDBusMetaType::marshall(self, arg.userType(), arg.constData());
+ return QDBusMetaType::marshall(self, arg.metaType(), arg.constData());
}
bool QDBusMarshaller::appendCrossMarshalling(QDBusDemarshaller *demarshaller)
@@ -536,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 01d55280d6..6ef762f225 100644
--- a/src/dbus/qdbusmessage.cpp
+++ b/src/dbus/qdbusmessage.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusmessage.h"
#include "qdbusmessage_p.h"
@@ -56,6 +20,10 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
+QT_IMPL_METATYPE_EXTERN(QDBusMessage)
+
static_assert(QDBusMessage::InvalidMessage == DBUS_MESSAGE_TYPE_INVALID);
static_assert(QDBusMessage::MethodCallMessage == DBUS_MESSAGE_TYPE_METHOD_CALL);
static_assert(QDBusMessage::ReplyMessage == DBUS_MESSAGE_TYPE_METHOD_RETURN);
@@ -68,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.
@@ -112,7 +95,7 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
QDBusError *error)
{
if (!qdbus_loadLibDBus()) {
- *error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library"));
+ *error = QDBusError(QDBusError::Failed, "Could not open lidbus-1 library"_L1);
return nullptr;
}
@@ -145,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:
@@ -158,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:
@@ -187,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)
@@ -202,7 +183,7 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
// not ok;
q_dbus_message_unref(msg);
- *error = QDBusError(QDBusError::Failed, QLatin1String("Marshalling failed: ") + marshaller.errorString);
+ *error = QDBusError(QDBusError::Failed, "Marshalling failed: "_L1 + marshaller.errorString);
return nullptr;
}
@@ -238,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 ?
@@ -246,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);
@@ -271,13 +253,11 @@ 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) {
- int id = it->userType();
+ for (const QVariant &argument : std::as_const(asSent.d_ptr->arguments)) {
+ QMetaType id = argument.metaType();
const char *signature = QDBusMetaType::typeToSignature(id);
- if ((id != QMetaType::QStringList && id != QMetaType::QByteArray &&
- qstrlen(signature) != 1) || id == qMetaTypeId<QDBusVariant>()) {
+ if ((id.id() != QMetaType::QStringList && id.id() != QMetaType::QByteArray &&
+ qstrlen(signature) != 1) || id == QMetaType::fromType<QDBusVariant>()) {
// yes, we are
// we must marshall and demarshall again so as to create QDBusArgument
// entries for the complex types
@@ -297,7 +277,7 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn,
retval.d_ptr->service = conn.baseService;
return retval;
} else {
- computedSignature += QLatin1String(signature);
+ computedSignature += QLatin1StringView(signature);
}
}
@@ -438,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;
}
@@ -480,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;
}
@@ -496,31 +469,21 @@ QDBusMessage QDBusMessage::createReply(const QVariantList &arguments) const
Constructs a new DBus message representing an error reply message,
with the given \a name and \a msg.
*/
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QDBusMessage QDBusMessage::createErrorReply(const QString &name, const QString &msg) const
-#else
-QDBusMessage QDBusMessage::createErrorReply(const QString name, const QString &msg) const
-#endif
{
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;
}
/*!
- \fn QDBusMessage QDBusMessage::createReply(const QVariant &argument) const
-
Constructs a new DBus message representing a reply, with the
given \a argument.
*/
+QDBusMessage QDBusMessage::createReply(const QVariant &argument) const
+{
+ return createReply(QList{argument});
+}
/*!
\fn QDBusMessage QDBusMessage::createErrorReply(const QDBusError &error) const
@@ -593,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;
}
@@ -655,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;
}
/*!
@@ -729,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.
- By default this flag is false and the other end is expected to
- make any authorization decisions non-interactively and promptly.
+ 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.
+
+ 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
*/
@@ -752,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
*/
@@ -774,7 +744,6 @@ bool QDBusMessage::isInteractiveAuthorizationAllowed() const
*/
void QDBusMessage::setArguments(const QList<QVariant> &arguments)
{
- // FIXME: should we detach?
d_ptr->arguments = arguments;
}
@@ -794,11 +763,16 @@ QList<QVariant> QDBusMessage::arguments() const
QDBusMessage &QDBusMessage::operator<<(const QVariant &arg)
{
- // FIXME: should we detach?
d_ptr->arguments.append(arg);
return *this;
}
+QDBusMessage::QDBusMessage(QDBusMessagePrivate &dd)
+ : d_ptr(&dd)
+{
+ d_ptr->ref.ref();
+}
+
/*!
Returns the message type.
*/
@@ -840,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 cd8f74d8bc..f6db3bc21e 100644
--- a/src/dbus/qdbusmessage.h
+++ b/src/dbus/qdbusmessage.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSMESSAGE_H
#define QDBUSMESSAGE_H
@@ -45,7 +9,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qvariant.h>
-#ifndef QT_NO_DBUS
+#if !defined(QT_NO_DBUS) && !defined(QT_BOOTSTRAPPED)
#if defined(Q_OS_WIN) && defined(interface)
# undef interface
@@ -53,7 +17,6 @@
QT_BEGIN_NAMESPACE
-
class QDBusMessagePrivate;
class Q_DBUS_EXPORT QDBusMessage
{
@@ -72,7 +35,7 @@ public:
QDBusMessage &operator=(const QDBusMessage &other);
~QDBusMessage();
- void swap(QDBusMessage &other) noexcept { qSwap(d_ptr, other.d_ptr); }
+ void swap(QDBusMessage &other) noexcept { qt_ptr_swap(d_ptr, other.d_ptr); }
static QDBusMessage createSignal(const QString &path, const QString &interface,
const QString &name);
@@ -87,14 +50,9 @@ public:
{ return createError(QDBusError::errorString(type), msg); }
QDBusMessage createReply(const QList<QVariant> &arguments = QList<QVariant>()) const;
- inline QDBusMessage createReply(const QVariant &argument) const
- { return createReply(QList<QVariant>() << argument); }
+ QDBusMessage createReply(const QVariant &argument) const;
-#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QDBusMessage createErrorReply(const QString &name, const QString &msg) const;
-#else
- QDBusMessage createErrorReply(const QString name, const QString &msg) const;
-#endif
inline QDBusMessage createErrorReply(const QDBusError &err) const
{ return createErrorReply(err.name(), err.message()); }
QDBusMessage createErrorReply(QDBusError::ErrorType type, const QString &msg) const;
@@ -126,6 +84,7 @@ public:
QDBusMessage &operator<<(const QVariant &arg);
private:
+ explicit QDBusMessage(QDBusMessagePrivate &dd);
friend class QDBusMessagePrivate;
QDBusMessagePrivate *d_ptr;
};
@@ -137,7 +96,7 @@ Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusMessage &);
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QDBusMessage)
+QT_DECL_METATYPE_EXTERN(QDBusMessage, Q_DBUS_EXPORT)
#else
class Q_DBUS_EXPORT QDBusMessage {}; // dummy class for moc
diff --git a/src/dbus/qdbusmessage_p.h b/src/dbus/qdbusmessage_p.h
index f921c33832..88ba78025e 100644
--- a/src/dbus/qdbusmessage_p.h
+++ b/src/dbus/qdbusmessage_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSMESSAGE_P_H
#define QDBUSMESSAGE_P_H
@@ -75,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 d308151984..543b185df9 100644
--- a/src/dbus/qdbusmetaobject.cpp
+++ b/src/dbus/qdbusmetaobject.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusmetaobject_p.h"
@@ -59,6 +23,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
class QDBusMetaObjectGenerator
{
public:
@@ -75,22 +41,23 @@ private:
QVarLengthArray<int, 4> inputTypes;
QVarLengthArray<int, 4> outputTypes;
QByteArray rawReturnType;
- int flags;
+ quint32 flags;
};
struct Property {
QByteArray typeName;
QByteArray signature;
int type;
- int flags;
+ quint32 flags;
};
struct Type {
int id;
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;
@@ -104,11 +71,11 @@ private:
void parseSignals();
void parseProperties();
- static int aggregateParameterCount(const QMap<QByteArray, Method> &map);
+ static qsizetype aggregateParameterCount(const MethodMap &map);
};
-static const int intsPerProperty = 2;
-static const int intsPerMethod = 2;
+static const qsizetype intsPerProperty = 2;
+static const qsizetype intsPerMethod = 2;
struct QDBusMetaObjectPrivate : public QMetaObjectPrivate
{
@@ -134,19 +101,25 @@ static int registerComplexDBusType(const QByteArray &typeName)
const QByteArray name;
QDBusRawTypeHandler(const QByteArray &name)
: QtPrivate::QMetaTypeInterface {
- 0, sizeof(void *), sizeof(void *), QMetaType::MovableType, nullptr,
- name.constData(), 0, QtPrivate::RefCount{0},
- [](QtPrivate::QMetaTypeInterface *self) {
- delete static_cast<QDBusRawTypeHandler *>(self);
- },
- nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr
+ 0, sizeof(void *), sizeof(void *), QMetaType::RelocatableType, 0, nullptr,
+ name.constData(),
+ nullptr, nullptr, nullptr, nullptr,
+ nullptr, nullptr, nullptr,
+ nullptr, nullptr, nullptr
},
name(name)
{}
};
- static QBasicMutex mutex;
- static QHash<QByteArray, QMetaType> hash;
+ Q_CONSTINIT static QBasicMutex mutex;
+ Q_CONSTINIT static struct Hash : QHash<QByteArray, QMetaType>
+ {
+ ~Hash()
+ {
+ for (QMetaType entry : *this)
+ QMetaType::unregisterMetaType(std::move(entry));
+ }
+ } hash;
QMutexLocker lock(&mutex);
QMetaType &metatype = hash[typeName];
if (!metatype.isValid())
@@ -164,18 +137,19 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
Type result;
result.id = QMetaType::UnknownType;
- int type = QDBusMetaType::signatureToType(signature);
+ int type = QDBusMetaType::signatureToMetaType(signature).id();
if (type == QMetaType::UnknownType && !qt_dbus_metaobject_skip_annotations) {
// it's not a type normally handled by our meta type system
// it must contain an annotation
QString annotationName = QString::fromLatin1("org.qtproject.QtDBus.QtTypeName");
if (id >= 0)
annotationName += QString::fromLatin1(".%1%2")
- .arg(QLatin1String(direction))
+ .arg(QLatin1StringView(direction))
.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()) {
@@ -183,17 +157,18 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
annotationName = QString::fromLatin1("com.trolltech.QtDBus.QtTypeName");
if (id >= 0)
annotationName += QString::fromLatin1(".%1%2")
- .arg(QLatin1String(direction))
+ .arg(QLatin1StringView(direction))
.arg(id);
- typeName = annotations.value(annotationName).toLatin1();
+ annotation = annotations.value(annotationName);
+ typeName = annotation.value.toLatin1();
}
if (!typeName.isEmpty()) {
// type name found
- type = QMetaType::type(typeName);
+ type = QMetaType::fromName(typeName).id();
}
- if (type == QMetaType::UnknownType || signature != QDBusMetaType::typeToSignature(type)) {
+ if (type == QMetaType::UnknownType || signature != QDBusMetaType::typeToSignature(QMetaType(type))) {
// type is still unknown or doesn't match back to the signature that it
// was expected to, so synthesize a fake type
typeName = "QDBusRawType<0x" + signature.toHex() + ">*";
@@ -214,12 +189,15 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
} else if (signature == "a{ss}") {
result.name = "QMap<QString,QString>";
type = qMetaTypeId<QMap<QString, QString> >();
+ } else if (signature == "aay") {
+ result.name = "QByteArrayList";
+ type = qMetaTypeId<QByteArrayList>();
} else {
result.name = "{D-Bus type \"" + signature + "\"}";
type = registerComplexDBusType(result.name);
}
} else {
- result.name = QMetaType::typeName(type);
+ result.name = QMetaType(type).name();
}
result.id = type;
@@ -233,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();
@@ -246,7 +221,7 @@ void QDBusMetaObjectGenerator::parseMethods()
bool ok = true;
// build the input argument list
- for (int 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);
@@ -265,7 +240,7 @@ void QDBusMetaObjectGenerator::parseMethods()
if (!ok) continue;
// build the output argument list:
- for (int 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);
@@ -291,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(QLatin1String(ANNOTATION_NO_WAIT)) == QLatin1String("true"))
+ if (m.annotations.value(ANNOTATION_NO_WAIT ""_L1).value == "true"_L1)
mm.tag = "Q_NOREPLY";
// meta method flags
@@ -309,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();
@@ -322,7 +294,7 @@ void QDBusMetaObjectGenerator::parseSignals()
bool ok = true;
// build the output argument list
- for (int 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);
@@ -342,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(')');
@@ -356,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)
@@ -385,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.
-int QDBusMetaObjectGenerator::aggregateParameterCount(const QMap<QByteArray, Method> &map)
+qsizetype QDBusMetaObjectGenerator::aggregateParameterCount(const MethodMap &map)
{
- int sum = 0;
- QMap<QByteArray, Method>::const_iterator it;
- for (it = map.constBegin(); it != map.constEnd(); ++it) {
- const Method &m = it.value();
+ qsizetype sum = 0;
+ for (const Method &m : map)
sum += m.inputTypes.size() + qMax(qsizetype(1), m.outputTypes.size());
- }
return sum;
}
@@ -402,60 +368,67 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
// with a few modifications to make it cleaner
QString className = interface;
- className.replace(QLatin1Char('.'), QLatin1String("::"));
+ className.replace(u'.', "::"_L1);
if (className.isEmpty())
- className = QLatin1String("QDBusInterface");
+ className = "QDBusInterface"_L1;
- QVarLengthArray<int> idata;
- idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int));
+ QVarLengthArray<uint> idata;
+ idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(uint));
- int methodParametersDataSize =
+ 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 == 9, "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 = signals_.count() + methods.count();
- header->methodData = idata.size();
- header->propertyCount = properties.count();
- header->propertyData = header->methodData + header->methodCount * QMetaObjectPrivate::IntsPerMethod + methodParametersDataSize;
+ header->methodCount = int(signals_.size() + methods.size());
+ header->methodData = int(idata.size());
+ header->propertyCount = int(properties.size());
+ header->propertyData = int(header->methodData + header->methodCount *
+ QMetaObjectPrivate::IntsPerMethod + methodParametersDataSize);
header->enumeratorCount = 0;
header->enumeratorData = 0;
header->constructorCount = 0;
header->constructorData = 0;
header->flags = RequiresVariantMetaObject;
- header->signalCount = signals_.count();
+ header->signalCount = signals_.size();
// These are specific to QDBusMetaObject:
- header->propertyDBusData = header->propertyData + header->propertyCount * QMetaObjectPrivate::IntsPerProperty;
- header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty;
+ header->propertyDBusData = int(header->propertyData + header->propertyCount
+ * QMetaObjectPrivate::IntsPerProperty);
+ header->methodDBusData = int(header->propertyDBusData + header->propertyCount * intsPerProperty);
- int data_size = idata.size() +
+ 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());
- int offset = header->methodData;
- int parametersOffset = offset + header->methodCount * QMetaObjectPrivate::IntsPerMethod;
- int signatureOffset = header->methodDBusData;
- int typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod;
+ qsizetype offset = header->methodData;
+ qsizetype parametersOffset = offset + header->methodCount * QMetaObjectPrivate::IntsPerMethod;
+ qsizetype signatureOffset = header->methodDBusData;
+ qsizetype typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod;
idata[typeidOffset++] = 0; // eod
- int totalMetaTypeCount = properties.count();
- for (const auto& methodContainer: {signals_, methods}) {
- for (const auto& method: methodContainer) {
- int argc = method.inputTypes.size() + qMax(qsizetype(0), method.outputTypes.size() - 1);
+ qsizetype totalMetaTypeCount = properties.size();
+ ++totalMetaTypeCount; // + 1 for metatype of dynamic metaobject
+ 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;
}
}
@@ -463,15 +436,11 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
int propertyId = 0;
// add each method:
- int currentMethodMetaTypeOffset = properties.count();
- 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;
- int argc = mm.inputTypes.size() + qMax(qsizetype(0), mm.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);
idata[offset++] = strings.enter(mm.name);
idata[offset++] = argc;
@@ -481,7 +450,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
idata[offset++] = currentMethodMetaTypeOffset;
// Parameter types
- for (int i = -1; i < argc; ++i) {
+ for (qsizetype i = -1; i < argc; ++i) {
int type;
QByteArray typeName;
if (i < 0) { // Return type
@@ -499,31 +468,31 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
Q_ASSERT(mm.outputTypes.size() > 1);
type = mm.outputTypes.at(i - mm.inputTypes.size() + 1);
// Output parameters are references; type id not available
- typeName = QMetaType::typeName(type);
+ typeName = QMetaType(type).name();
typeName.append('&');
+ type = QMetaType::UnknownType;
}
- Q_ASSERT(type != QMetaType::UnknownType);
int typeInfo;
if (!typeName.isEmpty())
typeInfo = IsUnresolvedType | strings.enter(typeName);
else
typeInfo = type;
- metaTypes[currentMethodMetaTypeOffset++] = QMetaType (type);
+ metaTypes[currentMethodMetaTypeOffset++] = QMetaType(type);
idata[parametersOffset++] = typeInfo;
}
// Parameter names
- for (int i = 0; i < argc; ++i)
+ for (qsizetype i = 0; i < argc; ++i)
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(int));
- 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(int));
- 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();
}
}
@@ -536,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;
@@ -553,6 +519,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
metaTypes[propertyId++] = QMetaType(mp.type);
}
+ metaTypes[propertyId] = QMetaType(); // we can't know our own metatype
Q_ASSERT(offset == header->propertyDBusData);
Q_ASSERT(signatureOffset == header->methodDBusData);
@@ -561,7 +528,7 @@ void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
strings.writeBlob(string_data);
uint *uint_data = new uint[idata.size()];
- memcpy(uint_data, idata.data(), idata.size() * sizeof(int));
+ memcpy(uint_data, idata.data(), idata.size() * sizeof(uint));
// put the metaobject together
obj->d.data = uint_data;
@@ -578,7 +545,7 @@ void QDBusMetaObjectGenerator::writeWithoutXml(const QString &interface)
{
// no XML definition
QString tmp(interface);
- tmp.replace(QLatin1Char('.'), QLatin1String("::"));
+ tmp.replace(u'.', "::"_L1);
QByteArray name(tmp.toLatin1());
QDBusMetaObjectPrivate *header = new QDBusMetaObjectPrivate;
@@ -617,13 +584,13 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
bool us = it.key() == interface;
QDBusMetaObject *obj = cache.value(it.key(), 0);
- if ( !obj && ( us || !interface.startsWith( QLatin1String("local.") ) ) ) {
+ if (!obj && (us || !interface.startsWith("local."_L1 ))) {
// not in cache; create
obj = new QDBusMetaObject;
QDBusMetaObjectGenerator generator(it.key(), it.value().constData());
generator.write(obj);
- if ( (obj->cached = !it.key().startsWith( QLatin1String("local.") )) )
+ if ((obj->cached = !it.key().startsWith("local."_L1)))
// cache it
cache.insert(it.key(), obj);
else if (!us)
@@ -659,7 +626,7 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
merged.properties.insert(it.value()->properties);
}
- merged.name = QLatin1String("local.Merged");
+ merged.name = "local.Merged"_L1;
merged.introspection.clear();
we = new QDBusMetaObject;
@@ -671,8 +638,7 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
// mark as an error
error = QDBusError(QDBusError::UnknownInterface,
- QLatin1String("Interface '%1' was not found")
- .arg(interface));
+ "Interface '%1' was not found"_L1.arg(interface));
return nullptr;
}
diff --git a/src/dbus/qdbusmetaobject_p.h b/src/dbus/qdbusmetaobject_p.h
index a4ed3c355c..97d16d99d0 100644
--- a/src/dbus/qdbusmetaobject_p.h
+++ b/src/dbus/qdbusmetaobject_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSMETAOBJECT_P_H
#define QDBUSMETAOBJECT_P_H
diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp
index 94317b81a3..3ae7589480 100644
--- a/src/dbus/qdbusmetatype.cpp
+++ b/src/dbus/qdbusmetatype.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusmetatype.h"
#include "qdbusmetatype_p.h"
@@ -47,6 +11,11 @@
#include <qglobal.h>
#include <qlist.h>
#include <qreadwritelock.h>
+#include <qdatetime.h>
+#include <qrect.h>
+#include <qsize.h>
+#include <qpoint.h>
+#include <qline.h>
#include "qdbusargument_p.h"
#include "qdbusutil_p.h"
@@ -77,48 +46,38 @@ public:
QDBusMetaType::DemarshallFunction demarshall;
};
-template<typename T>
-inline static void registerHelper(T * = nullptr)
-{
- void (*mf)(QDBusArgument &, const T *) = qDBusMarshallHelper<T>;
- void (*df)(const QDBusArgument &, T *) = qDBusDemarshallHelper<T>;
- QDBusMetaType::registerMarshallOperators(qMetaTypeId<T>(),
- reinterpret_cast<QDBusMetaType::MarshallFunction>(mf),
- reinterpret_cast<QDBusMetaType::DemarshallFunction>(df));
-}
-
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
- registerHelper<QDate>();
- registerHelper<QTime>();
- registerHelper<QDateTime>();
- registerHelper<QRect>();
- registerHelper<QRectF>();
- registerHelper<QSize>();
- registerHelper<QSizeF>();
- registerHelper<QPoint>();
- registerHelper<QPointF>();
- registerHelper<QLine>();
- registerHelper<QLineF>();
- registerHelper<QVariantList>();
- registerHelper<QVariantMap>();
- registerHelper<QVariantHash>();
+ qDBusRegisterMetaType<QDate>();
+ qDBusRegisterMetaType<QTime>();
+ qDBusRegisterMetaType<QDateTime>();
+ qDBusRegisterMetaType<QRect>();
+ qDBusRegisterMetaType<QRectF>();
+ qDBusRegisterMetaType<QSize>();
+ qDBusRegisterMetaType<QSizeF>();
+ qDBusRegisterMetaType<QPoint>();
+ qDBusRegisterMetaType<QPointF>();
+ qDBusRegisterMetaType<QLine>();
+ qDBusRegisterMetaType<QLineF>();
+ qDBusRegisterMetaType<QVariantList>();
+ qDBusRegisterMetaType<QVariantMap>();
+ qDBusRegisterMetaType<QVariantHash>();
qDBusRegisterMetaType<QList<bool> >();
qDBusRegisterMetaType<QList<short> >();
@@ -128,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> >();
@@ -137,8 +99,13 @@ void QDBusMetaTypeId::init()
}
}
-Q_GLOBAL_STATIC(QList<QDBusCustomTypeInfo>, customTypes)
-Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
+struct QDBusCustomTypes
+{
+ QReadWriteLock lock;
+ QHash<int, QDBusCustomTypeInfo> hash;
+};
+
+Q_GLOBAL_STATIC(QDBusCustomTypes, customTypes)
/*!
\class QDBusMetaType
@@ -162,7 +129,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
*/
/*!
- \fn int qDBusRegisterMetaType()
+ \fn template<typename T> QMetaType qDBusRegisterMetaType()
\relates QDBusArgument
\threadsafe
\since 4.2
@@ -213,41 +180,49 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
/*!
\internal
Registers the marshalling and demarshalling functions for meta
- type \a id.
+ type \a metaType.
*/
-void QDBusMetaType::registerMarshallOperators(int id, MarshallFunction mf,
+void QDBusMetaType::registerMarshallOperators(QMetaType metaType, MarshallFunction mf,
DemarshallFunction df)
{
- QList<QDBusCustomTypeInfo> *ct = customTypes();
- if (id < 0 || !mf || !df || !ct)
+ int id = metaType.id();
+ if (id < 0 || !mf || !df)
return; // error!
- QWriteLocker locker(customTypesLock());
- if (id >= ct->size())
- ct->resize(id + 1);
- 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;
}
/*!
\internal
- Executes the marshalling of type \a id (whose data is contained in
+ Executes the marshalling of type \a metaType (whose data is contained in
\a data) to the D-Bus marshalling argument \a arg. Returns \c true if
the marshalling succeeded, or false if an error occurred.
*/
-bool QDBusMetaType::marshall(QDBusArgument &arg, int id, const void *data)
+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());
- QList<QDBusCustomTypeInfo> *ct = customTypes();
- if (id >= ct->size())
+ QReadLocker locker(&ct->lock);
+
+ auto it = ct->hash.constFind(id);
+ if (it == ct->hash.cend())
return false; // non-existent
- const QDBusCustomTypeInfo &info = (*ct).at(id);
+ const QDBusCustomTypeInfo &info = *it;
if (!info.marshall) {
mf = nullptr; // make gcc happy
return false;
@@ -261,22 +236,28 @@ bool QDBusMetaType::marshall(QDBusArgument &arg, int id, const void *data)
/*!
\internal
- Executes the demarshalling of type \a id (whose data will be placed in
+ Executes the demarshalling of type \a metaType (whose data will be placed in
\a data) from the D-Bus marshalling argument \a arg. Returns \c true if
the demarshalling succeeded, or false if an error occurred.
*/
-bool QDBusMetaType::demarshall(const QDBusArgument &arg, int id, void *data)
+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());
- QList<QDBusCustomTypeInfo> *ct = customTypes();
- if (id >= ct->size())
+ QReadLocker locker(&ct->lock);
+
+ auto it = ct->hash.constFind(id);
+ if (it == ct->hash.cend())
return false; // non-existent
- const QDBusCustomTypeInfo &info = (*ct).at(id);
+ const QDBusCustomTypeInfo &info = *it;
if (!info.demarshall) {
df = nullptr; // make gcc happy
return false;
@@ -304,45 +285,45 @@ bool QDBusMetaType::demarshall(const QDBusArgument &arg, int id, void *data)
Note: this function only handles the basic D-Bus types.
\sa QDBusUtil::isValidSingleSignature(), typeToSignature(),
- QVariant::type(), QVariant::userType()
+ QVariant::metaType()
*/
-int QDBusMetaType::signatureToType(const char *signature)
+QMetaType QDBusMetaType::signatureToMetaType(const char *signature)
{
if (!signature)
- return QMetaType::UnknownType;
+ return QMetaType(QMetaType::UnknownType);
QDBusMetaTypeId::init();
switch (signature[0])
{
case DBUS_TYPE_BOOLEAN:
- return QMetaType::Bool;
+ return QMetaType(QMetaType::Bool);
case DBUS_TYPE_BYTE:
- return QMetaType::UChar;
+ return QMetaType(QMetaType::UChar);
case DBUS_TYPE_INT16:
- return QMetaType::Short;
+ return QMetaType(QMetaType::Short);
case DBUS_TYPE_UINT16:
- return QMetaType::UShort;
+ return QMetaType(QMetaType::UShort);
case DBUS_TYPE_INT32:
- return QMetaType::Int;
+ return QMetaType(QMetaType::Int);
case DBUS_TYPE_UINT32:
- return QMetaType::UInt;
+ return QMetaType(QMetaType::UInt);
case DBUS_TYPE_INT64:
- return QMetaType::LongLong;
+ return QMetaType(QMetaType::LongLong);
case DBUS_TYPE_UINT64:
- return QMetaType::ULongLong;
+ return QMetaType(QMetaType::ULongLong);
case DBUS_TYPE_DOUBLE:
- return QMetaType::Double;
+ return QMetaType(QMetaType::Double);
case DBUS_TYPE_STRING:
- return QMetaType::QString;
+ return QMetaType(QMetaType::QString);
case DBUS_TYPE_OBJECT_PATH:
return QDBusMetaTypeId::objectpath();
@@ -359,28 +340,48 @@ int QDBusMetaType::signatureToType(const char *signature)
case DBUS_TYPE_ARRAY: // special case
switch (signature[1]) {
case DBUS_TYPE_BYTE:
- return QMetaType::QByteArray;
+ return QMetaType(QMetaType::QByteArray);
case DBUS_TYPE_STRING:
- return QMetaType::QStringList;
+ return QMetaType(QMetaType::QStringList);
case DBUS_TYPE_VARIANT:
- return QMetaType::QVariantList;
+ return QMetaType(QMetaType::QVariantList);
case DBUS_TYPE_OBJECT_PATH:
- return qMetaTypeId<QList<QDBusObjectPath> >();
+ return QMetaType::fromType<QList<QDBusObjectPath> >();
case DBUS_TYPE_SIGNATURE:
- return qMetaTypeId<QList<QDBusSignature> >();
+ return QMetaType::fromType<QList<QDBusSignature> >();
}
Q_FALLTHROUGH();
default:
- return QMetaType::UnknownType;
+ return QMetaType(QMetaType::UnknownType);
}
}
/*!
+ \fn QDBusMetaType::registerCustomType(QMetaType type, const QByteArray &signature)
+ \internal
+
+ Registers the meta type \a type to be represeneted by the given D-Bus \a signature.
+
+ This is used in qdbuscpp2xml for custom types which aren't known to the C++ type system.
+*/
+void QDBusMetaType::registerCustomType(QMetaType type, const QByteArray &signature)
+{
+ auto *ct = customTypes();
+ 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
+}
+
+/*!
\fn QDBusMetaType::typeToSignature(int type)
\internal
@@ -389,12 +390,12 @@ int QDBusMetaType::signatureToType(const char *signature)
More types can be registered with the qDBusRegisterMetaType() function.
\sa QDBusUtil::isValidSingleSignature(), signatureToType(),
- QVariant::type(), QVariant::userType()
+ QVariant::metaType()
*/
-const char *QDBusMetaType::typeToSignature(int type)
+const char *QDBusMetaType::typeToSignature(QMetaType type)
{
// check if it's a static type
- switch (type)
+ switch (type.id())
{
case QMetaType::UChar:
return DBUS_TYPE_BYTE_AS_STRING;
@@ -446,13 +447,17 @@ const char *QDBusMetaType::typeToSignature(int type)
return DBUS_TYPE_UNIX_FD_AS_STRING;
// try the database
- QList<QDBusCustomTypeInfo> *ct = customTypes();
+ auto *ct = customTypes();
+ if (!ct)
+ return nullptr;
+
{
- QReadLocker locker(customTypesLock());
- if (type >= ct->size())
- return nullptr; // type not registered with us
+ QReadLocker locker(&ct->lock);
+ auto it = ct->hash.constFind(type.id());
+ if (it == ct->hash.end())
+ return nullptr;
- const QDBusCustomTypeInfo &info = (*ct).at(type);
+ const QDBusCustomTypeInfo &info = *it;
if (!info.signature.isNull())
return info.signature;
@@ -469,8 +474,8 @@ const char *QDBusMetaType::typeToSignature(int type)
QByteArray signature = QDBusArgumentPrivate::createSignature(type);
// re-acquire lock
- QWriteLocker locker(customTypesLock());
- info = &(*ct)[type];
+ QWriteLocker locker(&ct->lock);
+ info = &ct->hash[type.id()];
info->signature = signature;
}
return info->signature;
diff --git a/src/dbus/qdbusmetatype.h b/src/dbus/qdbusmetatype.h
index e241553bb4..3304a69e1e 100644
--- a/src/dbus/qdbusmetatype.h
+++ b/src/dbus/qdbusmetatype.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSMETATYPE_H
#define QDBUSMETATYPE_H
@@ -55,37 +19,25 @@ public:
typedef void (*MarshallFunction)(QDBusArgument &, const void *);
typedef void (*DemarshallFunction)(const QDBusArgument &, void *);
- static void registerMarshallOperators(int typeId, MarshallFunction, DemarshallFunction);
- static bool marshall(QDBusArgument &, int id, const void *data);
- static bool demarshall(const QDBusArgument &, int id, void *data);
+ static void registerMarshallOperators(QMetaType typeId, MarshallFunction, DemarshallFunction);
+ static bool marshall(QDBusArgument &, QMetaType id, const void *data);
+ static bool demarshall(const QDBusArgument &, QMetaType id, void *data);
- static int signatureToType(const char *signature);
- static const char *typeToSignature(int type);
-};
-
-template<typename T>
-void qDBusMarshallHelper(QDBusArgument &arg, const T *t)
-{ arg << *t; }
+ static void registerCustomType(QMetaType type, const QByteArray &signature);
-template<typename T>
-void qDBusDemarshallHelper(const QDBusArgument &arg, T *t)
-{ arg >> *t; }
+ static QMetaType signatureToMetaType(const char *signature);
+ static const char *typeToSignature(QMetaType type);
+};
template<typename T>
-int qDBusRegisterMetaType(
-#ifndef Q_QDOC
- T * /* dummy */ = nullptr
-#endif
-)
+QMetaType qDBusRegisterMetaType()
{
- void (*mf)(QDBusArgument &, const T *) = qDBusMarshallHelper<T>;
- void (*df)(const QDBusArgument &, T *) = qDBusDemarshallHelper<T>;
+ auto mf = [](QDBusArgument &arg, const void *t) { arg << *static_cast<const T *>(t); };
+ auto df = [](const QDBusArgument &arg, void *t) { arg >> *static_cast<T *>(t); };
- int id = qMetaTypeId<T>(); // make sure it's registered
- QDBusMetaType::registerMarshallOperators(id,
- reinterpret_cast<QDBusMetaType::MarshallFunction>(mf),
- reinterpret_cast<QDBusMetaType::DemarshallFunction>(df));
- return id;
+ QMetaType metaType = QMetaType::fromType<T>();
+ QDBusMetaType::registerMarshallOperators(metaType, mf, df);
+ return metaType;
}
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusmetatype_p.h b/src/dbus/qdbusmetatype_p.h
index 1aa11552df..86a59f587d 100644
--- a/src/dbus/qdbusmetatype_p.h
+++ b/src/dbus/qdbusmetatype_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSMETATYPE_P_H
#define QDBUSMETATYPE_P_H
@@ -64,47 +28,38 @@
QT_BEGIN_NAMESPACE
-struct QDBusMetaTypeId
-{
- static int message(); // QDBusMessage
- static int argument(); // QDBusArgument
- static int variant(); // QDBusVariant
- static int objectpath(); // QDBusObjectPath
- static int signature(); // QDBusSignature
- static int error(); // QDBusError
- static int unixfd(); // QDBusUnixFileDescriptor
-
- static void init();
-};
-
-inline int QDBusMetaTypeId::message()
-#ifdef QT_BOOTSTRAPPED
-{ return qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >() + 1; }
-#else
-{ return qMetaTypeId<QDBusMessage>(); }
-#endif
+namespace QDBusMetaTypeId {
+QMetaType message(); // QDBusMessage
+QMetaType argument(); // QDBusArgument
+QMetaType variant(); // QDBusVariant
+QMetaType objectpath(); // QDBusObjectPath
+QMetaType signature(); // QDBusSignature
+QMetaType error(); // QDBusError
+QMetaType unixfd(); // QDBusUnixFileDescriptor
-inline int QDBusMetaTypeId::argument()
-{ return qMetaTypeId<QDBusArgument>(); }
+Q_DBUS_EXPORT void init();
+}; // namespace QDBusMetaTypeId
-inline int QDBusMetaTypeId::variant()
-{ return qMetaTypeId<QDBusVariant>(); }
+inline QMetaType QDBusMetaTypeId::message()
+{ return QMetaType::fromType<QDBusMessage>(); }
-inline int QDBusMetaTypeId::objectpath()
-{ return qMetaTypeId<QDBusObjectPath>(); }
+inline QMetaType QDBusMetaTypeId::argument()
+{ return QMetaType::fromType<QDBusArgument>(); }
-inline int QDBusMetaTypeId::signature()
-{ return qMetaTypeId<QDBusSignature>(); }
+inline QMetaType QDBusMetaTypeId::variant()
+{ return QMetaType::fromType<QDBusVariant>(); }
-inline int QDBusMetaTypeId::error()
-#ifdef QT_BOOTSTRAPPED
-{ return qDBusRegisterMetaType<QList<QDBusUnixFileDescriptor> >() + 2; }
-#else
-{ return qMetaTypeId<QDBusError>(); }
-#endif
+inline QMetaType QDBusMetaTypeId::objectpath()
+{ return QMetaType::fromType<QDBusObjectPath>(); }
+
+inline QMetaType QDBusMetaTypeId::signature()
+{ return QMetaType::fromType<QDBusSignature>(); }
+
+inline QMetaType QDBusMetaTypeId::error()
+{ return QMetaType::fromType<QDBusError>(); }
-inline int QDBusMetaTypeId::unixfd()
-{ return qMetaTypeId<QDBusUnixFileDescriptor>(); }
+inline QMetaType QDBusMetaTypeId::unixfd()
+{ return QMetaType::fromType<QDBusUnixFileDescriptor>(); }
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusmisc.cpp b/src/dbus/qdbusmisc.cpp
index ba98184ded..635258c86d 100644
--- a/src/dbus/qdbusmisc.cpp
+++ b/src/dbus/qdbusmisc.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <string.h>
@@ -44,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"
@@ -55,6 +20,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
bool qDBusCheckAsyncTag(const char *tag)
{
static const char noReplyTag[] = "Q_NOREPLY";
@@ -78,37 +45,56 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
int idx = mo->indexOfClassInfo(QCLASSINFO_DBUS_INTERFACE);
if (idx >= mo->classInfoOffset()) {
- interface = QLatin1String(mo->classInfo(idx).value());
+ interface = QLatin1StringView(mo->classInfo(idx).value());
} else {
- interface = QLatin1String(mo->className());
- interface.replace(QLatin1String("::"), QLatin1String("."));
+ interface = QLatin1StringView(mo->className());
+ interface.replace("::"_L1, "."_L1);
- if (interface.startsWith(QLatin1String("QDBus"))) {
- interface.prepend(QLatin1String("org.qtproject.QtDBus."));
- } else if (interface.startsWith(QLatin1Char('Q')) &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
+ if (interface.startsWith("QDBus"_L1)) {
+ interface.prepend("org.qtproject.QtDBus."_L1);
+ } else if (interface.startsWith(u'Q') &&
+ interface.size() >= 2 && interface.at(1).isUpper()) {
// assume it's Qt
- interface.prepend(QLatin1String("org.qtproject.Qt."));
+ interface.prepend("org.qtproject.Qt."_L1);
} else if (!QCoreApplication::instance()||
QCoreApplication::instance()->applicationName().isEmpty()) {
- interface.prepend(QLatin1String("local."));
- } else {
- interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
+ interface.prepend("local."_L1);
+ } else {
+ QString domainName = QCoreApplication::instance()->applicationName();
const QString organizationDomain = QCoreApplication::instance()->organizationDomain();
- const auto domainName = QStringView{organizationDomain}.split(QLatin1Char('.'), Qt::SkipEmptyParts);
- if (domainName.isEmpty()) {
- interface.prepend(QLatin1String("local."));
- } 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 + QLatin1Char('.');
-
- 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;
@@ -135,56 +121,65 @@ bool qDBusInterfaceInObject(QObject *obj, const QString &interface_name)
// metaTypes.count() >= retval + 1 in all cases
//
// sig must be the normalised signature for the method
-int qDBusParametersForMethod(const QMetaMethod &mm, QList<int> &metaTypes, QString &errorMsg)
+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
-int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QList<int> &metaTypes,
+int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QList<QMetaType> &metaTypes,
QString &errorMsg)
{
QDBusMetaTypeId::init();
metaTypes.clear();
- metaTypes.append(0); // return type
+ 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 = QLatin1String("Pointers are not supported: ") + QLatin1String(type);
+ errorMsg = "Pointers are not supported: "_L1 + QLatin1StringView(type);
return -1;
}
if (type.endsWith('&')) {
QByteArray basictype = type;
- basictype.truncate(type.length() - 1);
+ basictype.truncate(type.size() - 1);
- int id = QMetaType::type(basictype);
- if (id == 0) {
- errorMsg = QLatin1String("Unregistered output type in parameter list: ") + QLatin1String(type);
+ QMetaType id = QMetaType::fromName(basictype);
+ if (!id.isValid()) {
+ errorMsg = "Unregistered output type in parameter list: "_L1 + QLatin1StringView(type);
return -1;
} else if (QDBusMetaType::typeToSignature(id) == nullptr)
return -1;
- metaTypes.append( id );
+ metaTypes.append(id);
seenMessage = true; // it cannot appear anymore anyways
continue;
}
if (seenMessage) { // && !type.endsWith('&')
- errorMsg = QLatin1String("Invalid method, non-output parameters after message or after output parameters: ") + QLatin1String(type);
+ errorMsg = "Invalid method, non-output parameters after message or after output parameters: "_L1 + QLatin1StringView(type);
return -1; // not allowed
}
if (type.startsWith("QVector<"))
type = "QList<" + type.mid(sizeof("QVector<") - 1);
- int id = QMetaType::type(type);
+ QMetaType id = QMetaType::fromName(type);
#ifdef QT_BOOTSTRAPPED
// in bootstrap mode QDBusMessage isn't included, thus we need to resolve it manually here
if (type == "QDBusMessage") {
@@ -192,15 +187,15 @@ int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QList<int>
}
#endif
- if (id == QMetaType::UnknownType) {
- errorMsg = QLatin1String("Unregistered input type in parameter list: ") + QLatin1String(type);
+ if (!id.isValid()) {
+ errorMsg = "Unregistered input type in parameter list: "_L1 + QLatin1StringView(type);
return -1;
}
if (id == QDBusMetaTypeId::message())
seenMessage = true;
else if (QDBusMetaType::typeToSignature(id) == nullptr) {
- errorMsg = QLatin1String("Type not registered with QtDBus in parameter list: ") + QLatin1String(type);
+ errorMsg = "Type not registered with QtDBus in parameter list: "_L1 + QLatin1StringView(type);
return -1;
}
diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp
index 04d8e3f6c7..f9d414d1bd 100644
--- a/src/dbus/qdbuspendingcall.cpp
+++ b/src/dbus/qdbuspendingcall.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbuspendingcall.h"
#include "qdbuspendingcall_p.h"
@@ -53,6 +17,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QDBusPendingCall
\inmodule QtDBus
@@ -128,7 +94,8 @@ QT_BEGIN_NAMESPACE
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()
@@ -157,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;
@@ -185,10 +154,10 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb
return true;
}
-void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types)
+void QDBusPendingCallPrivate::setMetaTypes(int count, const QMetaType *types)
{
if (count == 0) {
- expectedReplySignature = QLatin1String(""); // not null
+ expectedReplySignature = ""_L1; // not null
return;
}
@@ -196,10 +165,8 @@ void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types)
sig.reserve(count + count / 2);
for (int i = 0; i < count; ++i) {
const char *typeSig = QDBusMetaType::typeToSignature(types[i]);
- if (Q_UNLIKELY(!typeSig)) {
- qFatal("QDBusPendingReply: type %s is not registered with QtDBus",
- QMetaType::typeName(types[i]));
- }
+ if (Q_UNLIKELY(!typeSig))
+ qFatal("QDBusPendingReply: type %s is not registered with QtDBus", types[i].name());
sig += typeSig;
}
@@ -221,8 +188,7 @@ void QDBusPendingCallPrivate::checkReceivedSignature()
// can't use startsWith here because a null string doesn't start or end with an empty string
if (replyMessage.signature().indexOf(expectedReplySignature) != 0) {
- const auto errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", "
- "expected \"%2\"");
+ const auto errorMsg = "Unexpected reply signature: got \"%1\", expected \"%2\""_L1;
replyMessage = QDBusMessage::createError(
QDBusError::InvalidSignature,
errorMsg.arg(replyMessage.signature(), expectedReplySignature));
@@ -240,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.
@@ -258,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd)
if (dd) {
bool r = dd->ref.deref();
Q_ASSERT(r);
- Q_UNUSED(r);
}
}
@@ -310,8 +295,9 @@ QDBusPendingCall &QDBusPendingCall::operator=(const QDBusPendingCall &other)
\sa QDBusPendingReply::isFinished()
*/
+
/*!
- \fn template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isFinished() const
+ \fn template <typename... Types> bool QDBusPendingReply<Types...>::isFinished() const
Returns \c true if the pending call has finished processing and the
reply has been received. If this function returns \c true, the
@@ -340,7 +326,7 @@ void QDBusPendingCall::waitForFinished()
}
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isValid() const
+ \fn template <typename... Types> bool QDBusPendingReply<Types...>::isValid() const
Returns \c true if the reply contains a normal reply message, false
if it contains anything else.
@@ -357,7 +343,7 @@ bool QDBusPendingCall::isValid() const
}
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isError() const
+ \fn template <typename... Types> bool QDBusPendingReply<Types...>::isError() const
Returns \c true if the reply contains an error message, false if it
contains a normal method reply.
@@ -374,7 +360,7 @@ bool QDBusPendingCall::isError() const
}
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusError QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::error() const
+ \fn template <typename... Types> QDBusError QDBusPendingReply<Types...>::error() const
Retrieves the error content of the reply message, if it has
finished processing. If the reply message has not finished
@@ -395,7 +381,7 @@ QDBusError QDBusPendingCall::error() const
}
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusMessage QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::reply() const
+ \fn template <typename... Types> QDBusMessage QDBusPendingReply<Types...>::reply() const
Retrieves the reply message received for the asynchronous call
that was sent, if it has finished processing. If the pending call
@@ -445,7 +431,7 @@ bool QDBusPendingCall::setReplyCallback(QObject *target, const char *member)
\since 4.6
Creates a QDBusPendingCall object based on the error condition
\a error. The resulting pending call object will be in the
- "finished" state and QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isError() will return true.
+ "finished" state and QDBusPendingReply<Types...>::isError() will return true.
\sa fromCompletedCall()
*/
@@ -479,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);
@@ -508,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);
@@ -546,6 +519,8 @@ void QDBusPendingCallWatcher::waitForFinished()
}
QT_END_NAMESPACE
+#include "moc_qdbuspendingcall_p.cpp"
+
#endif // QT_NO_DBUS
#include "moc_qdbuspendingcall.cpp"
diff --git a/src/dbus/qdbuspendingcall.h b/src/dbus/qdbuspendingcall.h
index dd99346301..c276376223 100644
--- a/src/dbus/qdbuspendingcall.h
+++ b/src/dbus/qdbuspendingcall.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSPENDINGCALL_H
#define QDBUSPENDINGCALL_H
@@ -63,9 +27,9 @@ public:
QDBusPendingCall &operator=(QDBusPendingCall &&other) noexcept { swap(other); return *this; }
QDBusPendingCall &operator=(const QDBusPendingCall &other);
- void swap(QDBusPendingCall &other) noexcept { qSwap(d, other.d); }
+ 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();
@@ -93,7 +57,6 @@ private:
Q_DECLARE_SHARED(QDBusPendingCall)
-class QDBusPendingCallWatcherPrivate;
class Q_DBUS_EXPORT QDBusPendingCallWatcher: public QObject, public QDBusPendingCall
{
Q_OBJECT
@@ -109,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 0921d7c4f3..2795cc3ecf 100644
--- a/src/dbus/qdbuspendingcall_p.h
+++ b/src/dbus/qdbuspendingcall_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -82,7 +46,7 @@ public:
// for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync)
QPointer<QObject> receiver;
- QList<int> metaTypes;
+ QList<QMetaType> metaTypes;
int methodIdx;
// }
@@ -104,10 +68,9 @@ public:
~QDBusPendingCallPrivate();
bool setReplyCallback(QObject *target, const char *member);
void waitForFinished();
- void setMetaTypes(int count, const int *types);
+ 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.cpp b/src/dbus/qdbuspendingreply.cpp
index df37d92211..fef68579d3 100644
--- a/src/dbus/qdbuspendingreply.cpp
+++ b/src/dbus/qdbuspendingreply.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbuspendingreply.h"
#include "qdbuspendingcall_p.h"
@@ -53,16 +17,15 @@
\brief The QDBusPendingReply class contains the reply to an asynchronous method call.
- The QDBusPendingReply is a template class with up to 8 template
- parameters. Those parameters are the types that will be used to
- extract the contents of the reply's data.
+ The QDBusPendingReply is a variadic template class. The template parameters
+ are the types that will be used to extract the contents of the reply's data.
This class is similar in functionality to QDBusReply, but with two
important differences:
\list
\li QDBusReply accepts exactly one return type, whereas
- QDBusPendingReply can have from 1 to 8 types
+ QDBusPendingReply can have any number of types
\li QDBusReply only works on already completed replies, whereas
QDBusPendingReply allows one to wait for replies from pending
calls
@@ -95,7 +58,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::QDBusPendingReply()
+ \fn template<typename... Types> QDBusPendingReply<Types...>::QDBusPendingReply()
Creates an empty QDBusPendingReply object. Without assigning a
QDBusPendingCall object to this reply, QDBusPendingReply cannot do
@@ -103,7 +66,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::QDBusPendingReply(const QDBusPendingReply &other)
+ \fn template<typename... Types> QDBusPendingReply<Types...>::QDBusPendingReply(const QDBusPendingReply &other)
Creates a copy of the \a other QDBusPendingReply object. Just like
QDBusPendingCall and QDBusPendingCallWatcher, this QDBusPendingReply
@@ -112,7 +75,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::QDBusPendingReply(const QDBusPendingCall &call)
+ \fn template<typename... Types> QDBusPendingReply<Types...>::QDBusPendingReply(const QDBusPendingCall &call)
Creates a QDBusPendingReply object that will take its contents from
the \a call pending asynchronous call. This QDBusPendingReply object
@@ -120,7 +83,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::QDBusPendingReply(const QDBusMessage &message)
+ \fn template<typename... Types> QDBusPendingReply<Types...>::QDBusPendingReply(const QDBusMessage &message)
Creates a QDBusPendingReply object that will take its contents from
the message \a message. In this case, this object will be already
@@ -130,7 +93,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply &QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::operator=(const QDBusPendingReply &other)
+ \fn template<typename... Types> QDBusPendingReply &QDBusPendingReply<Types...>::operator=(const QDBusPendingReply &other)
Makes a copy of \a other and drops the reference to the current
pending call. If the current reference is to an unfinished pending
@@ -140,7 +103,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply &QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::operator=(const QDBusPendingCall &call)
+ \fn template<typename... Types> QDBusPendingReply &QDBusPendingReply<Types...>::operator=(const QDBusPendingCall &call)
Makes this object take its contents from the \a call pending call
and drops the reference to the current pending call. If the
@@ -150,7 +113,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply &QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::operator=(const QDBusMessage &message)
+ \fn template<typename... Types> QDBusPendingReply &QDBusPendingReply<Types...>::operator=(const QDBusMessage &message)
Makes this object take its contents from the \a message message
and drops the reference to the current pending call. If the
@@ -172,7 +135,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> int QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::count() const
+ \fn template<typename... Types> int QDBusPendingReply<Types...>::count() const
Return the number of arguments the reply is supposed to have. This
number matches the number of non-void template parameters in this
@@ -184,7 +147,7 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QVariant QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::argumentAt(int index) const
+ \fn template<typename... Types> QVariant QDBusPendingReply<Types...>::argumentAt(int index) const
Returns the argument at position \a index in the reply's
contents. If the reply doesn't have that many elements, this
@@ -199,9 +162,9 @@
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> T1 QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::value() const
+ \fn template<typename... Types> typename Select<0>::Type QDBusPendingReply<Types...>::value() const
- Returns the first argument in this reply, cast to type \c T1 (the
+ Returns the first argument in this reply, cast to type \c Types[0] (the
first template parameter of this class). This is equivalent to
calling argumentAt<0>().
@@ -212,14 +175,14 @@
calling thread to block until the reply is processed.
If the reply is an error reply, this function returns a default-constructed
- \c T1 object, which may be indistinguishable from a valid value. To
+ \c Types[0] object, which may be indistinguishable from a valid value. To
reliably determine whether the message was an error, use isError().
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::operator T1() const
+ \fn template<typename... Types> QDBusPendingReply<Types...>::operator typename Select<0>::Type() const
- Returns the first argument in this reply, cast to type \c T1 (the
+ Returns the first argument in this reply, cast to type \c Types[0] (the
first template parameter of this class). This is equivalent to
calling argumentAt<0>().
@@ -230,12 +193,12 @@
calling thread to block until the reply is processed.
If the reply is an error reply, this function returns a default-constructed
- \c T1 object, which may be indistinguishable from a valid value. To
+ \c Types[0] object, which may be indistinguishable from a valid value. To
reliably determine whether the message was an error, use isError().
*/
/*!
- \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> void QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::waitForFinished()
+ \fn template<typename... Types> void QDBusPendingReply<Types...>::waitForFinished()
Suspends the execution of the calling thread until the reply is
received and processed. After this function returns, isFinished()
@@ -245,27 +208,27 @@
\sa QDBusPendingCallWatcher::waitForFinished()
*/
-QDBusPendingReplyData::QDBusPendingReplyData()
+QDBusPendingReplyBase::QDBusPendingReplyBase()
: QDBusPendingCall(nullptr) // initialize base class empty
{
}
-QDBusPendingReplyData::~QDBusPendingReplyData()
+QDBusPendingReplyBase::~QDBusPendingReplyBase()
{
}
-void QDBusPendingReplyData::assign(const QDBusPendingCall &other)
+void QDBusPendingReplyBase::assign(const QDBusPendingCall &other)
{
QDBusPendingCall::operator=(other);
}
-void QDBusPendingReplyData::assign(const QDBusMessage &message)
+void QDBusPendingReplyBase::assign(const QDBusMessage &message)
{
d = new QDBusPendingCallPrivate(QDBusMessage(), nullptr); // drops the reference to the old one
d->replyMessage = message;
}
-QVariant QDBusPendingReplyData::argumentAt(int index) const
+QVariant QDBusPendingReplyBase::argumentAt(int index) const
{
if (!d)
return QVariant();
@@ -275,7 +238,7 @@ QVariant QDBusPendingReplyData::argumentAt(int index) const
return d->replyMessage.arguments().value(index);
}
-void QDBusPendingReplyData::setMetaTypes(int count, const int *types)
+void QDBusPendingReplyBase::setMetaTypes(int count, const QMetaType *types)
{
Q_ASSERT(d);
const auto locker = qt_scoped_lock(d->mutex);
diff --git a/src/dbus/qdbuspendingreply.h b/src/dbus/qdbuspendingreply.h
index 9d25115a67..580b967b3b 100644
--- a/src/dbus/qdbuspendingreply.h
+++ b/src/dbus/qdbuspendingreply.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSPENDINGREPLY_H
#define QDBUSPENDINGREPLY_H
@@ -49,92 +13,58 @@
QT_BEGIN_NAMESPACE
-class Q_DBUS_EXPORT QDBusPendingReplyData: public QDBusPendingCall
+class Q_DBUS_EXPORT QDBusPendingReplyBase : public QDBusPendingCall
{
protected:
- QDBusPendingReplyData();
- ~QDBusPendingReplyData();
+ QDBusPendingReplyBase();
+ ~QDBusPendingReplyBase();
void assign(const QDBusPendingCall &call);
void assign(const QDBusMessage &message);
QVariant argumentAt(int index) const;
- void setMetaTypes(int count, const int *metaTypes);
+ void setMetaTypes(int count, const QMetaType *metaTypes);
};
namespace QDBusPendingReplyTypes {
- template<int Index,
- typename T1, typename T2, typename T3, typename T4,
- typename T5, typename T6, typename T7, typename T8>
+ template<int Index, typename T, typename... Types>
struct Select
{
- typedef Select<Index - 1, T2, T3, T4, T5, T6, T7, T8, void> Next;
+ typedef Select<Index - 1, Types...> Next;
typedef typename Next::Type Type;
};
- template<typename T1, typename T2, typename T3, typename T4,
- typename T5, typename T6, typename T7, typename T8>
- struct Select<0, T1, T2, T3, T4, T5, T6, T7, T8>
+ template<typename T, typename... Types>
+ struct Select<0, T, Types...>
{
- typedef T1 Type;
+ typedef T Type;
};
- template<typename T1> inline int metaTypeFor(T1 * = nullptr)
- { return qMetaTypeId<T1>(); }
+ template<typename T> inline QMetaType metaTypeFor()
+ { return QMetaType::fromType<T>(); }
// specialize for QVariant, allowing it to be used in place of QDBusVariant
- template<> inline int metaTypeFor<QVariant>(QVariant *)
- { return qMetaTypeId<QDBusVariant>(); }
+ template<> inline QMetaType metaTypeFor<QVariant>()
+ { return QMetaType::fromType<QDBusVariant>(); }
+}
- template<typename T1, typename T2, typename T3, typename T4,
- typename T5, typename T6, typename T7, typename T8>
- struct ForEach
- {
- typedef ForEach<T2, T3, T4, T5, T6, T7, T8, void> Next;
- enum { Total = Next::Total + 1 };
- static inline void fillMetaTypes(int *p)
- {
- *p = metaTypeFor<T1>(nullptr);
- Next::fillMetaTypes(++p);
- }
- };
- template<>
- struct ForEach<void, void, void, void, void, void, void, void>
- {
- enum { Total = 0 };
- static inline void fillMetaTypes(int *)
- { }
- };
- struct TypeIsVoid {};
- template <typename T> struct NotVoid { typedef T Type; };
- template <> struct NotVoid<void> { typedef TypeIsVoid Type; };
-} // namespace QDBusPendingReplyTypes
-
-template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
- typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
-class QDBusPendingReply:
-#ifdef Q_CLANG_QDOC
- public QDBusPendingCall
-#else
- public QDBusPendingReplyData
-#endif
+template<typename... Types>
+class QDBusPendingReply : public QDBusPendingReplyBase
{
- typedef QDBusPendingReplyTypes::ForEach<T1, T2, T3, T4, T5, T6, T7, T8> ForEach;
- template<int Index> struct Select :
- QDBusPendingReplyTypes::Select<Index, T1, T2, T3, T4, T5, T6, T7, T8>
- {
- };
-
+ template<int Index> using Select = QDBusPendingReplyTypes::Select<Index, Types...>;
public:
- enum { Count = ForEach::Total };
+ enum { Count = std::is_same_v<typename Select<0>::Type, void> ? 0 : sizeof...(Types) };
- inline QDBusPendingReply()
- { }
+ inline constexpr int count() const { return Count; }
+
+
+ inline QDBusPendingReply() = default;
inline QDBusPendingReply(const QDBusPendingReply &other)
- : QDBusPendingReplyData(other)
+ : QDBusPendingReplyBase(other)
{ }
- inline /*implicit*/ QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
+ inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
{ *this = call; }
- inline /*implicit*/ QDBusPendingReply(const QDBusMessage &message)
+ inline Q_IMPLICIT QDBusPendingReply(const QDBusMessage &message)
{ *this = message; }
+
inline QDBusPendingReply &operator=(const QDBusPendingReply &other)
{ assign(other); return *this; }
inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
@@ -142,69 +72,101 @@ public:
inline QDBusPendingReply &operator=(const QDBusMessage &message)
{ assign(message); return *this; }
- inline int count() const { return Count; }
-
-#if defined(Q_CLANG_QDOC)
- QVariant argumentAt(int index) const;
-#else
- using QDBusPendingReplyData::argumentAt;
-#endif
-
-#ifndef Q_CLANG_QDOC
+ using QDBusPendingReplyBase::argumentAt;
template<int Index> inline
- const typename Select<Index>::Type argumentAt() const
+ typename Select<Index>::Type argumentAt() const
{
static_assert(Index >= 0 && Index < Count, "Index out of bounds");
typedef typename Select<Index>::Type ResultType;
- return qdbus_cast<ResultType>(argumentAt(Index), nullptr);
+ return qdbus_cast<ResultType>(argumentAt(Index));
}
-#endif
-#if defined(Q_CLANG_QDOC)
+#if defined(Q_QDOC)
bool isFinished() const;
void waitForFinished();
+ QVariant argumentAt(int index) const;
bool isValid() const;
bool isError() const;
QDBusError error() const;
QDBusMessage reply() const;
+#endif
- inline T1 value() const;
- inline operator T1() const;
-#else
inline typename Select<0>::Type value() const
{
return argumentAt<0>();
}
- inline operator typename QDBusPendingReplyTypes::NotVoid<T1>::Type() const
+ inline operator typename Select<0>::Type() const
{
return argumentAt<0>();
}
-#endif
private:
inline void calculateMetaTypes()
{
if (!d) return;
- int typeIds[Count > 0 ? Count : 1]; // use at least one since zero-sized arrays aren't valid
- ForEach::fillMetaTypes(typeIds);
- setMetaTypes(Count, typeIds);
+ if constexpr (Count == 0) {
+ setMetaTypes(0, nullptr);
+ } else {
+ std::array<QMetaType, Count> typeIds = { QDBusPendingReplyTypes::metaTypeFor<Types>()... };
+ setMetaTypes(Count, typeIds.data());
+ }
}
inline void assign(const QDBusPendingCall &call)
{
- QDBusPendingReplyData::assign(call);
+ QDBusPendingReplyBase::assign(call);
calculateMetaTypes();
}
inline void assign(const QDBusMessage &message)
{
- QDBusPendingReplyData::assign(message);
+ QDBusPendingReplyBase::assign(message);
calculateMetaTypes();
}
};
+template<>
+class QDBusPendingReply<> : public QDBusPendingReplyBase
+{
+public:
+ enum { Count = 0 };
+ inline int count() const { return Count; }
+
+ inline QDBusPendingReply() = default;
+ inline QDBusPendingReply(const QDBusPendingReply &other)
+ : QDBusPendingReplyBase(other)
+ { }
+ inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
+ { *this = call; }
+ inline Q_IMPLICIT QDBusPendingReply(const QDBusMessage &message)
+ { *this = message; }
+
+ inline QDBusPendingReply &operator=(const QDBusPendingReply &other)
+ { assign(other); return *this; }
+ inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
+ { assign(call); return *this; }
+ inline QDBusPendingReply &operator=(const QDBusMessage &message)
+ { assign(message); return *this; }
+
+private:
+ inline void assign(const QDBusPendingCall &call)
+ {
+ QDBusPendingReplyBase::assign(call);
+ if (d)
+ setMetaTypes(0, nullptr);
+ }
+
+ inline void assign(const QDBusMessage &message)
+ {
+ QDBusPendingReplyBase::assign(message);
+ if (d)
+ setMetaTypes(0, nullptr);
+ }
+
+};
+
QT_END_NAMESPACE
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusreply.cpp b/src/dbus/qdbusreply.cpp
index 33bfadd701..5b26250b10 100644
--- a/src/dbus/qdbusreply.cpp
+++ b/src/dbus/qdbusreply.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusreply.h"
#include "qdbusmetatype.h"
@@ -46,6 +10,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
/*!
\class QDBusReply
\inmodule QtDBus
@@ -175,7 +141,7 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \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.
@@ -203,29 +169,29 @@ void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data
return;
}
- if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
+ if (reply.arguments().size() >= 1 && reply.arguments().at(0).metaType() == data.metaType()) {
data = reply.arguments().at(0);
return;
}
- const char *expectedSignature = QDBusMetaType::typeToSignature(data.userType());
+ const char *expectedSignature = QDBusMetaType::typeToSignature(data.metaType());
const char *receivedType = nullptr;
QByteArray receivedSignature;
- if (reply.arguments().count() >= 1) {
- if (reply.arguments().at(0).userType() == QDBusMetaTypeId::argument()) {
+ 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));
receivedSignature = arg.currentSignature().toLatin1();
if (receivedSignature == expectedSignature) {
// matched. Demarshall it
- QDBusMetaType::demarshall(arg, data.userType(), data.data());
+ QDBusMetaType::demarshall(arg, data.metaType(), data.data());
return;
}
} else {
// not an argument and doesn't match?
- int type = reply.arguments().at(0).userType();
- receivedType = QMetaType::typeName(type);
+ QMetaType type = reply.arguments().at(0).metaType();
+ receivedType = type.name();
receivedSignature = QDBusMetaType::typeToSignature(type);
}
}
@@ -235,18 +201,16 @@ void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data
receivedSignature = "<empty signature>";
QString errorMsg;
if (receivedType) {
- errorMsg = QLatin1String("Unexpected reply signature: got \"%1\" (%4), "
- "expected \"%2\" (%3)")
- .arg(QLatin1String(receivedSignature),
- QLatin1String(expectedSignature),
- QLatin1String(data.typeName()),
- QLatin1String(receivedType));
+ errorMsg = "Unexpected reply signature: got \"%1\" (%4), expected \"%2\" (%3)"_L1
+ .arg(QLatin1StringView(receivedSignature),
+ QLatin1StringView(expectedSignature),
+ QLatin1StringView(data.typeName()),
+ QLatin1StringView(receivedType));
} else {
- errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", "
- "expected \"%2\" (%3)")
- .arg(QLatin1String(receivedSignature),
- QLatin1String(expectedSignature),
- QLatin1String(data.typeName()));
+ errorMsg = "Unexpected reply signature: got \"%1\", expected \"%2\" (%3)"_L1
+ .arg(QLatin1StringView(receivedSignature),
+ QLatin1StringView(expectedSignature),
+ QLatin1StringView(data.typeName()));
}
error = QDBusError(QDBusError::InvalidSignature, errorMsg);
diff --git a/src/dbus/qdbusreply.h b/src/dbus/qdbusreply.h
index f7879f2d01..df488208c8 100644
--- a/src/dbus/qdbusreply.h
+++ b/src/dbus/qdbusreply.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSREPLY_H
#define QDBUSREPLY_H
@@ -67,7 +31,7 @@ public:
inline QDBusReply(const QDBusReply &) = default;
inline QDBusReply& operator=(const QDBusMessage &reply)
{
- QVariant data(qMetaTypeId<Type>(), nullptr);
+ QVariant data(QMetaType::fromType<Type>());
qDBusReplyFill(reply, m_error, data);
m_data = qvariant_cast<Type>(data);
return *this;
@@ -131,8 +95,7 @@ private:
template<> inline QDBusReply<QVariant>&
QDBusReply<QVariant>::operator=(const QDBusMessage &reply)
{
- void *null = nullptr;
- QVariant data(qMetaTypeId<QDBusVariant>(), null);
+ QVariant data(QMetaType::fromType<QDBusVariant>());
qDBusReplyFill(reply, m_error, data);
m_data = qvariant_cast<QDBusVariant>(data).variant();
return *this;
diff --git a/src/dbus/qdbusserver.cpp b/src/dbus/qdbusserver.cpp
index eccffc3d3e..e9131a14c4 100644
--- a/src/dbus/qdbusserver.cpp
+++ b/src/dbus/qdbusserver.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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 "qdbusserver.h"
#include "qdbusconnection_p.h"
@@ -74,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);
}
/*!
@@ -85,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)
+{
}
/*!
@@ -111,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();
@@ -174,6 +127,9 @@ QString QDBusServer::address() const
*/
void QDBusServer::setAnonymousAuthenticationAllowed(bool value)
{
+ if (!d)
+ return;
+
d->anonymousAuthenticationAllowed = value;
}
@@ -186,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 668b8705b1..34985cc055 100644
--- a/src/dbus/qdbusserver.h
+++ b/src/dbus/qdbusserver.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
#ifndef QDBUSSERVER_H
#define QDBUSSERVER_H
@@ -73,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 b0bfe7254d..bf94f54f56 100644
--- a/src/dbus/qdbusservicewatcher.cpp
+++ b/src/dbus/qdbusservicewatcher.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusservicewatcher.h"
#include "qdbusconnection.h"
@@ -43,6 +7,7 @@
#include <QStringList>
+#include <private/qproperty_p.h>
#include <private/qobject_p.h>
#include <private/qdbusconnection_p.h>
@@ -59,15 +24,27 @@ public:
{
}
- QStringList servicesWatched;
+ void setWatchedServicesForwardToQ(const QStringList &list)
+ {
+ q_func()->setWatchedServices(list);
+ }
+ Q_OBJECT_COMPAT_PROPERTY(QDBusServiceWatcherPrivate, QStringList, watchedServicesData,
+ &QDBusServiceWatcherPrivate::setWatchedServicesForwardToQ)
+
QDBusConnection connection;
- QDBusServiceWatcher::WatchMode watchMode;
+ void setWatchModeForwardToQ(QDBusServiceWatcher::WatchMode mode)
+ {
+ q_func()->setWatchMode(mode);
+ }
+ Q_OBJECT_COMPAT_PROPERTY(QDBusServiceWatcherPrivate, QDBusServiceWatcher::WatchMode, watchMode,
+ &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)
@@ -80,37 +57,43 @@ void QDBusServiceWatcherPrivate::_q_serviceOwnerChanged(const QString &service,
emit q->serviceUnregistered(service);
}
-void QDBusServiceWatcherPrivate::setConnection(const QStringList &s, 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(servicesWatched))
- removeService(s);
+ for (const QString &s : oldServices)
+ removeService(s, oldMode);
}
- connection = c;
- watchMode = wm;
- servicesWatched = s;
+ 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(servicesWatched))
- 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)));
}
/*!
@@ -170,18 +153,17 @@ void QDBusServiceWatcherPrivate::removeService(const QString &service)
/*!
\property QDBusServiceWatcher::watchMode
+ \brief the current watch mode for this QDBusServiceWatcher object.
- The \c watchMode property holds the current watch mode for this
- QDBusServiceWatcher object. The default value for this property is
+ The default value for this property is
QDBusServiceWatcher::WatchForOwnershipChange.
*/
/*!
\property QDBusServiceWatcher::watchedServices
+ \brief the list of services watched.
- The \c servicesWatched property holds the list of services watched.
-
- Note that modifying this list with setServicesWatched() is an expensive
+ \note Modifying this list with setServicesWatched() is an expensive
operation. If you can, prefer to change it by way of addWatchedService()
and removeWatchedService().
*/
@@ -266,7 +248,7 @@ QDBusServiceWatcher::~QDBusServiceWatcher()
*/
QStringList QDBusServiceWatcher::watchedServices() const
{
- return d_func()->servicesWatched;
+ return d_func()->watchedServicesData;
}
/*!
@@ -276,27 +258,47 @@ QStringList QDBusServiceWatcher::watchedServices() const
watching services and adding new ones. This is an expensive operation and
should be avoided, if possible. Instead, use addWatchedService() and
removeWatchedService() if you can to manipulate entries in the list.
+
+ Removes any existing binding of watchedServices.
*/
void QDBusServiceWatcher::setWatchedServices(const QStringList &services)
{
Q_D(QDBusServiceWatcher);
- if (services == d->servicesWatched)
+ d->watchedServicesData.removeBindingUnlessInWrapper();
+ 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();
+}
+
+QBindable<QStringList> QDBusServiceWatcher::bindableWatchedServices()
+{
+ Q_D(QDBusServiceWatcher);
+ return &d->watchedServicesData;
}
/*!
Adds \a newService to the list of services to be watched by this object.
This function is more efficient than setWatchedServices() and should be
used whenever possible to add services.
+
+ Removes any existing binding of watchedServices.
*/
void QDBusServiceWatcher::addWatchedService(const QString &newService)
{
Q_D(QDBusServiceWatcher);
- if (d->servicesWatched.contains(newService))
+ d->watchedServicesData.removeBindingUnlessInWrapper();
+ auto services = d->watchedServicesData.valueBypassingBindings();
+ if (services.contains(newService))
return;
- d->addService(newService);
- d->servicesWatched << newService;
+ // re-evaluate watch mode
+ d->addService(newService, d->watchMode);
+
+ services << newService;
+ d->watchedServicesData.setValueBypassingBindings(services);
+
+ d->watchedServicesData.notify();
}
/*!
@@ -305,13 +307,24 @@ void QDBusServiceWatcher::addWatchedService(const QString &newService)
still be signals pending delivery about \a service. Those signals will
still be emitted whenever the D-Bus messages are processed.
+ Removes any existing binding of watchedServices.
+
This function returns \c true if any services were removed.
*/
bool QDBusServiceWatcher::removeWatchedService(const QString &service)
{
Q_D(QDBusServiceWatcher);
- d->removeService(service);
- return d->servicesWatched.removeOne(service);
+ d->watchedServicesData.removeBindingUnlessInWrapper();
+ 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
@@ -319,12 +332,20 @@ QDBusServiceWatcher::WatchMode QDBusServiceWatcher::watchMode() const
return d_func()->watchMode;
}
+QBindable<QDBusServiceWatcher::WatchMode> QDBusServiceWatcher::bindableWatchMode()
+{
+ return &d_func()->watchMode;
+}
+
void QDBusServiceWatcher::setWatchMode(WatchMode mode)
{
Q_D(QDBusServiceWatcher);
- if (mode == d->watchMode)
+ d->watchMode.removeBindingUnlessInWrapper();
+ if (mode == d->watchMode.valueBypassingBindings())
return;
- d->setConnection(d->servicesWatched, d->connection, mode);
+ // trigger watchedServicesData re-evaluation, but only once for the setter
+ d->setConnection(d->watchedServicesData, d->connection, mode);
+ d->watchMode.notify();
}
/*!
@@ -354,7 +375,7 @@ void QDBusServiceWatcher::setConnection(const QDBusConnection &connection)
Q_D(QDBusServiceWatcher);
if (connection.name() == d->connection.name())
return;
- d->setConnection(d->servicesWatched, connection, d->watchMode);
+ d->setConnection(d->watchedServicesData, connection, d->watchMode);
}
QT_END_NAMESPACE
diff --git a/src/dbus/qdbusservicewatcher.h b/src/dbus/qdbusservicewatcher.h
index 2c45c85cb9..71c63084b1 100644
--- a/src/dbus/qdbusservicewatcher.h
+++ b/src/dbus/qdbusservicewatcher.h
@@ -1,51 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSSERVICEWATCHER_H
#define QDBUSSERVICEWATCHER_H
+#include <QtCore/QObject>
+#include <QtCore/qcontainerfwd.h> // Q(String)List
#include <QtDBus/qtdbusglobal.h>
#if !defined(QT_NO_DBUS) && !defined(QT_NO_QOBJECT)
QT_BEGIN_NAMESPACE
+class QString;
+template<typename T>
+class QBindable;
class QDBusConnection;
@@ -53,8 +22,9 @@ class QDBusServiceWatcherPrivate;
class Q_DBUS_EXPORT QDBusServiceWatcher: public QObject
{
Q_OBJECT
- Q_PROPERTY(QStringList watchedServices READ watchedServices WRITE setWatchedServices)
- Q_PROPERTY(WatchMode watchMode READ watchMode WRITE setWatchMode)
+ Q_PROPERTY(QStringList watchedServices READ watchedServices WRITE setWatchedServices
+ BINDABLE bindableWatchedServices)
+ Q_PROPERTY(WatchMode watchMode READ watchMode WRITE setWatchMode BINDABLE bindableWatchMode)
public:
enum WatchModeFlag {
WatchForRegistration = 0x01,
@@ -73,9 +43,11 @@ public:
void setWatchedServices(const QStringList &services);
void addWatchedService(const QString &newService);
bool removeWatchedService(const QString &service);
+ QBindable<QStringList> bindableWatchedServices();
WatchMode watchMode() const;
void setWatchMode(WatchMode mode);
+ QBindable<WatchMode> bindableWatchMode();
QDBusConnection connection() const;
void setConnection(const QDBusConnection &connection);
diff --git a/src/dbus/qdbusthreaddebug_p.h b/src/dbus/qdbusthreaddebug_p.h
index ad0984e26c..a1d3a420ec 100644
--- a/src/dbus/qdbusthreaddebug_p.h
+++ b/src/dbus/qdbusthreaddebug_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
#ifndef QDBUSTHREADDEBUG_P_H
#define QDBUSTHREADDEBUG_P_H
@@ -129,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);
@@ -149,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/qdbusunixfiledescriptor.cpp b/src/dbus/qdbusunixfiledescriptor.cpp
index 87cabb93f6..943c593acb 100644
--- a/src/dbus/qdbusunixfiledescriptor.cpp
+++ b/src/dbus/qdbusunixfiledescriptor.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusunixfiledescriptor.h"
@@ -48,6 +12,8 @@ QT_BEGIN_NAMESPACE
#ifndef QT_NO_DBUS
+QT_IMPL_METATYPE_EXTERN(QDBusUnixFileDescriptor)
+
/*!
\class QDBusUnixFileDescriptor
\inmodule QtDBus
diff --git a/src/dbus/qdbusunixfiledescriptor.h b/src/dbus/qdbusunixfiledescriptor.h
index fcd73b2ec5..cbcd8b53a9 100644
--- a/src/dbus/qdbusunixfiledescriptor.h
+++ b/src/dbus/qdbusunixfiledescriptor.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSUNIXFILEDESCRIPTOR_H
@@ -64,7 +28,7 @@ public:
~QDBusUnixFileDescriptor();
void swap(QDBusUnixFileDescriptor &other) noexcept
- { qSwap(d, other.d); }
+ { d.swap(other.d); }
bool isValid() const;
@@ -85,7 +49,7 @@ Q_DECLARE_SHARED(QDBusUnixFileDescriptor)
QT_END_NAMESPACE
-Q_DECLARE_METATYPE(QDBusUnixFileDescriptor)
+QT_DECL_METATYPE_EXTERN(QDBusUnixFileDescriptor, Q_DBUS_EXPORT)
#endif // QT_NO_DBUS
#endif // QDBUSUNIXFILEDESCRIPTOR_H
diff --git a/src/dbus/qdbusutil.cpp b/src/dbus/qdbusutil.cpp
index e04910b1d1..827418c487 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusutil_p.h"
@@ -43,6 +7,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
+#include <private/qtools_p.h>
#include "qdbusargument.h"
#include "qdbusunixfiledescriptor.h"
@@ -51,28 +16,25 @@
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
@@ -80,37 +42,37 @@ static bool argToString(const QDBusArgument &arg, QString &out);
static bool variantToString(const QVariant &arg, QString &out)
{
- int argType = arg.userType();
+ int argType = arg.metaType().id();
if (argType == QMetaType::QStringList) {
- out += QLatin1Char('{');
+ out += u'{';
const QStringList list = arg.toStringList();
for (const QString &item : list)
- out += QLatin1Char('\"') + item + QLatin1String("\", ");
+ out += u'\"' + item + "\", "_L1;
if (!list.isEmpty())
out.chop(2);
- out += QLatin1Char('}');
+ out += u'}';
} else if (argType == QMetaType::QByteArray) {
- out += QLatin1Char('{');
+ out += u'{';
QByteArray list = arg.toByteArray();
- for (int i = 0; i < list.count(); ++i) {
+ for (int i = 0; i < list.size(); ++i) {
out += QString::number(list.at(i));
- out += QLatin1String(", ");
+ out += ", "_L1;
}
if (!list.isEmpty())
out.chop(2);
- out += QLatin1Char('}');
+ out += u'}';
} else if (argType == QMetaType::QVariantList) {
- out += QLatin1Char('{');
+ out += u'{';
const QList<QVariant> list = arg.toList();
for (const QVariant &item : list) {
if (!variantToString(item, out))
return false;
- out += QLatin1String(", ");
+ out += ", "_L1;
}
if (!list.isEmpty())
out.chop(2);
- out += QLatin1Char('}');
+ out += u'}';
} else if (argType == QMetaType::Char || argType == QMetaType::Short || argType == QMetaType::Int
|| argType == QMetaType::Long || argType == QMetaType::LongLong) {
out += QString::number(arg.toLongLong());
@@ -120,40 +82,40 @@ static bool variantToString(const QVariant &arg, QString &out)
} else if (argType == QMetaType::Double) {
out += QString::number(arg.toDouble());
} else if (argType == QMetaType::Bool) {
- out += QLatin1String(arg.toBool() ? "true" : "false");
+ out += arg.toBool() ? "true"_L1 : "false"_L1;
} else if (argType == qMetaTypeId<QDBusArgument>()) {
argToString(qvariant_cast<QDBusArgument>(arg), out);
} else if (argType == qMetaTypeId<QDBusObjectPath>()) {
const QString path = qvariant_cast<QDBusObjectPath>(arg).path();
- out += QLatin1String("[ObjectPath: ");
+ out += "[ObjectPath: "_L1;
out += path;
- out += QLatin1Char(']');
+ out += u']';
} else if (argType == qMetaTypeId<QDBusSignature>()) {
- out += QLatin1String("[Signature: ") + qvariant_cast<QDBusSignature>(arg).signature();
- out += QLatin1Char(']');
+ out += "[Signature: "_L1 + qvariant_cast<QDBusSignature>(arg).signature();
+ out += u']';
} else if (argType == qMetaTypeId<QDBusUnixFileDescriptor>()) {
- out += QLatin1String("[Unix FD: ");
- out += QLatin1String(qvariant_cast<QDBusUnixFileDescriptor>(arg).isValid() ? "valid" : "not valid");
- out += QLatin1Char(']');
+ out += "[Unix FD: "_L1;
+ out += qvariant_cast<QDBusUnixFileDescriptor>(arg).isValid() ? "valid"_L1 : "not valid"_L1;
+ out += u']';
} else if (argType == qMetaTypeId<QDBusVariant>()) {
const QVariant v = qvariant_cast<QDBusVariant>(arg).variant();
- out += QLatin1String("[Variant");
- int vUserType = v.userType();
- if (vUserType != qMetaTypeId<QDBusVariant>()
- && vUserType != qMetaTypeId<QDBusSignature>()
- && vUserType != qMetaTypeId<QDBusObjectPath>()
- && vUserType != qMetaTypeId<QDBusArgument>())
- out += QLatin1Char('(') + QLatin1String(v.typeName()) + QLatin1Char(')');
- out += QLatin1String(": ");
+ out += "[Variant"_L1;
+ QMetaType vUserType = v.metaType();
+ if (vUserType != QMetaType::fromType<QDBusVariant>()
+ && vUserType != QMetaType::fromType<QDBusSignature>()
+ && vUserType != QMetaType::fromType<QDBusObjectPath>()
+ && vUserType != QMetaType::fromType<QDBusArgument>())
+ out += u'(' + QLatin1StringView(v.typeName()) + u')';
+ out += ": "_L1;
if (!variantToString(v, out))
return false;
- out += QLatin1Char(']');
- } else if (arg.canConvert(QMetaType::QString)) {
- out += QLatin1Char('\"') + arg.toString() + QLatin1Char('\"');
+ out += u']';
+ } else if (arg.canConvert<QString>()) {
+ out += u'\"' + arg.toString() + u'\"';
} else {
- out += QLatin1Char('[');
- out += QLatin1String(arg.typeName());
- out += QLatin1Char(']');
+ out += u'[';
+ out += QLatin1StringView(arg.typeName());
+ out += u']';
}
return true;
@@ -167,7 +129,7 @@ bool argToString(const QDBusArgument &busArg, QString &out)
if (elementType != QDBusArgument::BasicType && elementType != QDBusArgument::VariantType
&& elementType != QDBusArgument::MapEntryType)
- out += QLatin1String("[Argument: ") + busSig + QLatin1Char(' ');
+ out += "[Argument: "_L1 + busSig + u' ';
switch (elementType) {
case QDBusArgument::BasicType:
@@ -181,33 +143,33 @@ bool argToString(const QDBusArgument &busArg, QString &out)
break;
case QDBusArgument::ArrayType:
busArg.beginArray();
- out += QLatin1Char('{');
+ out += u'{';
doIterate = true;
break;
case QDBusArgument::MapType:
busArg.beginMap();
- out += QLatin1Char('{');
+ out += u'{';
doIterate = true;
break;
case QDBusArgument::MapEntryType:
busArg.beginMapEntry();
if (!variantToString(busArg.asVariant(), out))
return false;
- out += QLatin1String(" = ");
+ out += " = "_L1;
if (!argToString(busArg, out))
return false;
busArg.endMapEntry();
break;
case QDBusArgument::UnknownType:
default:
- out += QLatin1String("<ERROR - Unknown Type>");
+ out += "<ERROR - Unknown Type>"_L1;
return false;
}
if (doIterate && !busArg.atEnd()) {
while (!busArg.atEnd()) {
if (!argToString(busArg, out))
return false;
- out += QLatin1String(", ");
+ out += ", "_L1;
}
out.chop(2);
}
@@ -222,18 +184,18 @@ bool argToString(const QDBusArgument &busArg, QString &out)
busArg.endStructure();
break;
case QDBusArgument::ArrayType:
- out += QLatin1Char('}');
+ out += u'}';
busArg.endArray();
break;
case QDBusArgument::MapType:
- out += QLatin1Char('}');
+ out += u'}';
busArg.endMap();
break;
}
if (elementType != QDBusArgument::BasicType && elementType != QDBusArgument::VariantType
&& elementType != QDBusArgument::MapEntryType)
- out += QLatin1Char(']');
+ out += u']';
return true;
}
@@ -244,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;
@@ -340,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;
@@ -348,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.
@@ -369,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(QLatin1Char('.'));
- if (parts.count() < 2)
+ const auto parts = QStringView{ifaceName}.split(u'.');
+ if (parts.size() < 2)
return false; // at least two parts
for (auto part : parts)
@@ -392,12 +362,12 @@ namespace QDBusUtil
*/
bool isValidUniqueConnectionName(QStringView connName)
{
- if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
- !connName.startsWith(QLatin1Char(':')))
+ if (connName.isEmpty() || connName.size() > DBUS_MAXIMUM_NAME_LENGTH ||
+ !connName.startsWith(u':'))
return false;
- const auto parts = connName.mid(1).split(QLatin1Char('.'));
- if (parts.count() < 1)
+ const auto parts = connName.mid(1).split(u'.');
+ if (parts.size() < 1)
return false;
for (QStringView part : parts) {
@@ -405,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;
}
@@ -414,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.
@@ -436,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(QLatin1Char(':')))
+ if (busName.startsWith(u':'))
return isValidUniqueConnectionName(busName);
- const auto parts = QStringView{busName}.split(QLatin1Char('.'));
- if (parts.count() < 1)
- return false;
-
+ const auto parts = QStringView{busName}.split(u'.');
for (QStringView part : parts) {
if (part.isEmpty())
return false;
@@ -453,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;
}
@@ -469,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.
@@ -505,22 +460,21 @@ 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)
{
- if (path == QLatin1String("/"))
+ if (path == "/"_L1)
return true;
- if (!path.startsWith(QLatin1Char('/')) || path.indexOf(QLatin1String("//")) != -1 ||
- path.endsWith(QLatin1Char('/')))
+ if (!path.startsWith(u'/') || path.indexOf("//"_L1) != -1 ||
+ path.endsWith(u'/'))
return false;
// it starts with /, so we skip the empty first part
- const auto parts = QStringView{path}.mid(1).split(QLatin1Char('/'));
+ const auto parts = QStringView{path}.mid(1).split(u'/');
for (QStringView part : parts)
if (!isValidPartOfObjectPath(part))
return false;
diff --git a/src/dbus/qdbusutil_p.h b/src/dbus/qdbusutil_p.h
index 50a2490fd0..3db9384968 100644
--- a/src/dbus/qdbusutil_p.h
+++ b/src/dbus/qdbusutil_p.h
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// 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
//
// W A R N I N G
@@ -63,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);
@@ -99,11 +63,11 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
{
if (name.isEmpty()) {
if (empty == EmptyAllowed) return true;
- *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Interface name cannot be empty"));
+ *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Interface name cannot be empty"));
return false;
}
if (isValidInterfaceName(name)) return true;
- *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Invalid interface class: %1").arg(name));
+ *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Invalid interface class: %1").arg(name));
return false;
}
@@ -111,11 +75,11 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
{
if (name.isEmpty()) {
if (empty == EmptyAllowed) return true;
- *error = QDBusError(QDBusError::InvalidService, QLatin1String("Service name cannot be empty"));
+ *error = QDBusError(QDBusError::InvalidService, QLatin1StringView("Service name cannot be empty"));
return false;
}
if (isValidBusName(name)) return true;
- *error = QDBusError(QDBusError::InvalidService, QLatin1String("Invalid service name: %1").arg(name));
+ *error = QDBusError(QDBusError::InvalidService, QLatin1StringView("Invalid service name: %1").arg(name));
return false;
}
@@ -123,11 +87,11 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
{
if (path.isEmpty()) {
if (empty == EmptyAllowed) return true;
- *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Object path cannot be empty"));
+ *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1StringView("Object path cannot be empty"));
return false;
}
if (isValidObjectPath(path)) return true;
- *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1String("Invalid object path: %1").arg(path));
+ *error = QDBusError(QDBusError::InvalidObjectPath, QLatin1StringView("Invalid object path: %1").arg(path));
return false;
}
@@ -136,12 +100,12 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
if (!nameType) nameType = "member";
if (name.isEmpty()) {
if (empty == EmptyAllowed) return true;
- *error = QDBusError(QDBusError::InvalidMember, QLatin1String(nameType) + QLatin1String(" name cannot be empty"));
+ *error = QDBusError(QDBusError::InvalidMember, QLatin1StringView(nameType) + QLatin1StringView(" name cannot be empty"));
return false;
}
if (isValidMemberName(name)) return true;
- *error = QDBusError(QDBusError::InvalidMember, QLatin1String("Invalid %1 name: %2")
- .arg(QLatin1String(nameType), name));
+ *error = QDBusError(QDBusError::InvalidMember, QLatin1StringView("Invalid %1 name: %2")
+ .arg(QLatin1StringView(nameType), name));
return false;
}
@@ -149,11 +113,11 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
{
if (name.isEmpty()) {
if (empty == EmptyAllowed) return true;
- *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Error name cannot be empty"));
+ *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Error name cannot be empty"));
return false;
}
if (isValidErrorName(name)) return true;
- *error = QDBusError(QDBusError::InvalidInterface, QLatin1String("Invalid error name: %1").arg(name));
+ *error = QDBusError(QDBusError::InvalidInterface, QLatin1StringView("Invalid error name: %1").arg(name));
return false;
}
@@ -166,7 +130,7 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
inline QString dbusInterface()
{
// it's the same string, but just be sure
- Q_ASSERT(dbusService() == QLatin1String(DBUS_INTERFACE_DBUS));
+ Q_ASSERT(dbusService() == QLatin1StringView(DBUS_INTERFACE_DBUS));
return dbusService();
}
inline QString dbusInterfaceProperties()
diff --git a/src/dbus/qdbusvirtualobject.cpp b/src/dbus/qdbusvirtualobject.cpp
index 25dd49c34d..2e5df125d2 100644
--- a/src/dbus/qdbusvirtualobject.cpp
+++ b/src/dbus/qdbusvirtualobject.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusvirtualobject.h"
@@ -60,6 +24,7 @@ QDBusVirtualObject::~QDBusVirtualObject()
QT_END_NAMESPACE
+#include "moc_qdbusvirtualobject.cpp"
/*!
\class QDBusVirtualObject
@@ -74,7 +39,7 @@ QT_END_NAMESPACE
This function needs to handle all messages to the path of the
virtual object, when the SubPath option is specified.
- The service, path, interface and methos are all part of the \a message.
+ The service, path, interface and methods are all part of the \a message.
Parameter \a connection is the connection handle.
Must return \c true when the message is handled, otherwise \c false (will generate dbus error message).
*/
diff --git a/src/dbus/qdbusvirtualobject.h b/src/dbus/qdbusvirtualobject.h
index b69e21b378..573d731d20 100644
--- a/src/dbus/qdbusvirtualobject.h
+++ b/src/dbus/qdbusvirtualobject.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSVIRTUALOBJECT_H
#define QDBUSVIRTUALOBJECT_H
diff --git a/src/dbus/qdbusxmlgenerator.cpp b/src/dbus/qdbusxmlgenerator.cpp
index 97ce3dc910..412ac18095 100644
--- a/src/dbus/qdbusxmlgenerator.cpp
+++ b/src/dbus/qdbusxmlgenerator.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include <QtCore/qmetaobject.h>
#include <QtCore/qstringlist.h>
@@ -52,6 +16,8 @@
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
extern Q_DBUS_EXPORT QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
const QMetaObject *base, int flags);
@@ -59,28 +25,28 @@ static inline QString typeNameToXml(const char *typeName)
{
// ### copied from qtextdocument.cpp
// ### move this into Qt Core at some point
- const QLatin1String plain(typeName);
+ const QLatin1StringView plain(typeName);
QString rich;
rich.reserve(int(plain.size() * 1.1));
for (int i = 0; i < plain.size(); ++i) {
- if (plain.at(i) == QLatin1Char('<'))
- rich += QLatin1String("&lt;");
- else if (plain.at(i) == QLatin1Char('>'))
- rich += QLatin1String("&gt;");
- else if (plain.at(i) == QLatin1Char('&'))
- rich += QLatin1String("&amp;");
+ if (plain.at(i) == u'<')
+ rich += "&lt;"_L1;
+ else if (plain.at(i) == u'>')
+ rich += "&gt;"_L1;
+ else if (plain.at(i) == u'&')
+ rich += "&amp;"_L1;
else
rich += plain.at(i);
}
return rich;
}
-static inline QLatin1String accessAsString(bool read, bool write)
+static inline QLatin1StringView accessAsString(bool read, bool write)
{
if (read)
- return write ? QLatin1String("readwrite") : QLatin1String("read") ;
+ return write ? "readwrite"_L1 : "read"_L1 ;
else
- return write ? QLatin1String("write") : QLatin1String("") ;
+ return write ? "write"_L1 : ""_L1 ;
}
// implement the D-Bus org.freedesktop.DBus.Introspectable interface
@@ -101,24 +67,24 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
(!mp.isScriptable() && (flags & QDBusConnection::ExportNonScriptableProperties))))
continue;
- int typeId = mp.userType();
- if (!typeId)
+ QMetaType type = mp.metaType();
+ if (!type.isValid())
continue;
- const char *signature = QDBusMetaType::typeToSignature(typeId);
+ const char *signature = QDBusMetaType::typeToSignature(type);
if (!signature)
continue;
- retval += QLatin1String(" <property name=\"%1\" type=\"%2\" access=\"%3\"")
- .arg(QLatin1String(mp.name()),
- QLatin1String(signature),
+ retval += " <property name=\"%1\" type=\"%2\" access=\"%3\""_L1
+ .arg(QLatin1StringView(mp.name()),
+ QLatin1StringView(signature),
accessAsString(mp.isReadable(), mp.isWritable()));
- if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
- const char *typeName = QMetaType::typeName(typeId);
- retval += QLatin1String(">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n")
+ if (!QDBusMetaType::signatureToMetaType(signature).isValid()) {
+ const char *typeName = type.name();
+ retval += ">\n <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"%3\"/>\n </property>\n"_L1
.arg(typeNameToXml(typeName));
} else {
- retval += QLatin1String("/>\n");
+ retval += "/>\n"_L1;
}
}
}
@@ -127,14 +93,17 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
for (int i = methodOffset; i < mo->methodCount(); ++i) {
QMetaMethod mm = mo->method(i);
- bool isSignal;
+ bool isSignal = false;
+ bool isSlot = false;
if (mm.methodType() == QMetaMethod::Signal)
// adding a signal
isSignal = true;
- else if (mm.access() == QMetaMethod::Public && (mm.methodType() == QMetaMethod::Slot || mm.methodType() == QMetaMethod::Method))
- isSignal = false;
+ else if (mm.access() == QMetaMethod::Public && mm.methodType() == QMetaMethod::Slot)
+ isSlot = true;
+ else if (mm.access() == QMetaMethod::Public && mm.methodType() == QMetaMethod::Method)
+ ; // invokable, neither signal nor slot
else
- continue; // neither signal nor public slot
+ continue; // neither signal nor public method/slot
if (isSignal && !(flags & (QDBusConnection::ExportScriptableSignals |
QDBusConnection::ExportNonScriptableSignals)))
@@ -153,36 +122,36 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
isSignal ? "signal" : "method", mm.name().constData());
// check the return type first
- int typeId = mm.returnType();
- if (typeId != QMetaType::UnknownType && typeId != QMetaType::Void) {
+ QMetaType typeId = mm.returnMetaType();
+ if (typeId.isValid() && typeId.id() != QMetaType::Void) {
const char *typeName = QDBusMetaType::typeToSignature(typeId);
if (typeName) {
- xml += QLatin1String(" <arg type=\"%1\" direction=\"out\"/>\n")
+ xml += " <arg type=\"%1\" direction=\"out\"/>\n"_L1
.arg(typeNameToXml(typeName));
// do we need to describe this argument?
- if (QDBusMetaType::signatureToType(typeName) == QMetaType::UnknownType)
- xml += QLatin1String(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n")
- .arg(typeNameToXml(QMetaType::typeName(typeId)));
+ if (!QDBusMetaType::signatureToMetaType(typeName).isValid())
+ xml += " <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"%1\"/>\n"_L1
+ .arg(typeNameToXml(QMetaType(typeId).name()));
} else {
- qWarning() << "Unsupported return type" << typeId << QMetaType::typeName(typeId) << "in method" << mm.name();
+ qWarning() << "Unsupported return type" << typeId.id() << typeId.name() << "in method" << mm.name();
continue;
}
}
- else if (typeId == QMetaType::UnknownType) {
+ else if (!typeId.isValid()) {
qWarning() << "Invalid return type in method" << mm.name();
continue; // wasn't a valid type
}
QList<QByteArray> names = mm.parameterNames();
- QList<int> types;
+ QList<QMetaType> types;
QString errorMsg;
int inputCount = qDBusParametersForMethod(mm, types, errorMsg);
if (inputCount == -1) {
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?
@@ -190,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;
@@ -199,7 +168,7 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
QString name;
if (!names.at(j - 1).isEmpty())
- name = QLatin1String("name=\"%1\" ").arg(QLatin1String(names.at(j - 1)));
+ name = "name=\"%1\" "_L1.arg(QLatin1StringView(names.at(j - 1)));
bool isOutput = isSignal || j > inputCount;
@@ -208,10 +177,10 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
qUtf16Printable(name), signature, isOutput ? "out" : "in");
// do we need to describe this argument?
- if (QDBusMetaType::signatureToType(signature) == QMetaType::UnknownType) {
- const char *typeName = QMetaType::typeName(types.at(j));
+ if (!QDBusMetaType::signatureToMetaType(signature).isValid()) {
+ const char *typeName = QMetaType(types.at(j)).name();
xml += QString::fromLatin1(" <annotation name=\"org.qtproject.QtDBus.QtTypeName.%1%2\" value=\"%3\"/>\n")
- .arg(isOutput ? QLatin1String("Out") : QLatin1String("In"))
+ .arg(isOutput ? "Out"_L1 : "In"_L1)
.arg(isOutput && !isSignal ? j - inputCount : j - 1)
.arg(typeNameToXml(typeName));
}
@@ -220,21 +189,21 @@ static QString generateInterfaceXml(const QMetaObject *mo, int flags, int method
int wantedMask;
if (isScriptable)
wantedMask = isSignal ? QDBusConnection::ExportScriptableSignals
- : QDBusConnection::ExportScriptableSlots;
+ : isSlot ? QDBusConnection::ExportScriptableSlots
+ : QDBusConnection::ExportScriptableInvokables;
else
wantedMask = isSignal ? QDBusConnection::ExportNonScriptableSignals
- : QDBusConnection::ExportNonScriptableSlots;
+ : isSlot ? QDBusConnection::ExportNonScriptableSlots
+ : QDBusConnection::ExportNonScriptableInvokables;
if ((flags & wantedMask) != wantedMask)
continue;
if (qDBusCheckAsyncTag(mm.tag()))
// add the no-reply annotation
- xml += QLatin1String(" <annotation name=\"" ANNOTATION_NO_WAIT "\""
- " value=\"true\"/>\n");
+ xml += " <annotation name=\"" ANNOTATION_NO_WAIT "\" value=\"true\"/>\n"_L1;
retval += xml;
- retval += QLatin1String(" </%1>\n")
- .arg(isSignal ? QLatin1String("signal") : QLatin1String("method"));
+ retval += " </%1>\n"_L1.arg(isSignal ? "signal"_L1 : "method"_L1);
}
return retval;
@@ -256,60 +225,10 @@ QString qDBusGenerateMetaObjectXml(QString interface, const QMetaObject *mo,
if (xml.isEmpty())
return QString(); // don't add an empty interface
- return QLatin1String(" <interface name=\"%1\">\n%2 </interface>\n")
- .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 = QLatin1String(mo->classInfo(idx).value());
- } else {
- interface = QLatin1String(mo->className());
- interface.replace(QLatin1String("::"), QLatin1String("."));
-
- if (interface.startsWith(QLatin1String("QDBus"))) {
- interface.prepend(QLatin1String("org.qtproject.QtDBus."));
- } else if (interface.startsWith(QLatin1Char('Q')) &&
- interface.length() >= 2 && interface.at(1).isUpper()) {
- // assume it's Qt
- interface.prepend(QLatin1String("org.qtproject.Qt."));
- } else if (!QCoreApplication::instance()||
- QCoreApplication::instance()->applicationName().isEmpty()) {
- interface.prepend(QLatin1String("local."));
- } else {
- interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
- QStringList domainName =
- QCoreApplication::instance()->organizationDomain().split(QLatin1Char('.'),
- Qt::SkipEmptyParts);
- if (domainName.isEmpty())
- interface.prepend(QLatin1String("local."));
- else
- for (int i = 0; i < domainName.count(); ++i)
- interface.prepend(QLatin1Char('.')).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")
+ return " <interface name=\"%1\">\n%2 </interface>\n"_L1
.arg(interface, xml);
}
-#endif
-
QT_END_NAMESPACE
#endif // QT_NO_DBUS
diff --git a/src/dbus/qdbusxmlparser.cpp b/src/dbus/qdbusxmlparser.cpp
index 94223e1574..c2e8df8be7 100644
--- a/src/dbus/qdbusxmlparser.cpp
+++ b/src/dbus/qdbusxmlparser.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusxmlparser_p.h"
#include "qdbusutil_p.h"
@@ -43,178 +7,206 @@
#include <QtCore/qmap.h>
#include <QtCore/qvariant.h>
#include <QtCore/qtextstream.h>
-#include <QtCore/qxmlstream.h>
#include <QtCore/qdebug.h>
#ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE
-Q_LOGGING_CATEGORY(dbusParser, "dbus.parser", QtWarningMsg)
+using namespace Qt::StringLiterals;
-#define qDBusParserError(...) qCDebug(dbusParser, ##__VA_ARGS__)
+Q_LOGGING_CATEGORY(dbusParser, "dbus.parser", QtWarningMsg)
-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)
{
- const QString argType = attributes.value(QLatin1String("type")).toString();
+ 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(QLatin1String("name")).toString();
+ argData.name = attributes.value("name"_L1).toString();
argData.type = argType;
- ifaceData->introspection += QLatin1String(" <arg");
- if (attributes.hasAttribute(QLatin1String("direction"))) {
- const QString direction = attributes.value(QLatin1String("direction")).toString();
- ifaceData->introspection += QLatin1String(" direction=\"") + direction + QLatin1String("\"");
+ m_currentInterface->introspection += " <arg"_L1;
+ if (attributes.hasAttribute("direction"_L1)) {
+ const QString direction = attributes.value("direction"_L1).toString();
+ m_currentInterface->introspection += " direction=\""_L1 + direction + u'"';
}
- ifaceData->introspection += QLatin1String(" type=\"") + argData.type + QLatin1String("\"");
+ m_currentInterface->introspection += " type=\""_L1 + argData.type + u'"';
if (!argData.name.isEmpty())
- ifaceData->introspection += QLatin1String(" name=\"") + argData.name + QLatin1String("\"");
- ifaceData->introspection += QLatin1String("/>\n");
+ 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() == QLatin1String("annotation"));
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "annotation"_L1);
+
+ QDBusIntrospection::Annotation annotation;
+ annotation.location = m_currentLocation;
- const QXmlStreamAttributes attributes = xml.attributes();
- const QString name = attributes.value(QLatin1String("name")).toString();
+ const QXmlStreamAttributes attributes = m_xml.attributes();
+ annotation.name = attributes.value("name"_L1).toString();
- if (!QDBusUtil::isValidInterfaceName(name)) {
- qDBusParserError("Invalid D-BUS annotation '%s' found while parsing introspection",
- qPrintable(name));
+ 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(QLatin1String("value")).toString();
- annotations.insert(name, value);
+ annotation.value = attributes.value("value"_L1).toString();
+ annotations.insert(annotation.name, annotation);
if (!interfaceAnnotation)
- ifaceData->introspection += QLatin1String(" ");
- ifaceData->introspection += QLatin1String(" <annotation value=\"") + value.toHtmlEscaped() + QLatin1String("\" name=\"") + name + QLatin1String("\"/>\n");
+ 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() == QLatin1String("property"));
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "property"_L1);
- QXmlStreamAttributes attributes = xml.attributes();
- const QString propertyName = attributes.value(QLatin1String("name")).toString();
+ 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;
}
// parse data
propertyData.name = propertyName;
- propertyData.type = attributes.value(QLatin1String("type")).toString();
+ propertyData.type = attributes.value("type"_L1).toString();
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(QLatin1String("access")).toString();
- if (access == QLatin1String("read"))
+ const QString access = attributes.value("access"_L1).toString();
+ if (access == "read"_L1)
propertyData.access = QDBusIntrospection::Property::Read;
- else if (access == QLatin1String("write"))
+ else if (access == "write"_L1)
propertyData.access = QDBusIntrospection::Property::Write;
- else if (access == QLatin1String("readwrite"))
+ 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 += QLatin1String(" <property access=\"") + access + QLatin1String("\" type=\"") + propertyData.type + QLatin1String("\" name=\"") + propertyName + QLatin1String("\"");
+ m_currentInterface->introspection += " <property access=\""_L1 + access + "\" type=\""_L1 + propertyData.type + "\" name=\""_L1 + propertyName + u'"';
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += QLatin1String("/>\n");
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += QLatin1String(">\n");
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == QLatin1String("annotation")) {
- 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 += QLatin1String(" </property>\n");
+ m_currentInterface->introspection += " </property>\n"_L1;
}
- if (!xml.isEndElement() || xml.name() != QLatin1String("property")) {
- 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() == QLatin1String("method"));
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "method"_L1);
- const QXmlStreamAttributes attributes = xml.attributes();
- const QString methodName = attributes.value(QLatin1String("name")).toString();
+ 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 += QLatin1String(" <method name=\"") + methodName + QLatin1String("\"");
+ m_currentInterface->introspection += " <method name=\""_L1 + methodName + u'"';
QDBusIntrospection::Arguments outArguments;
QDBusIntrospection::Arguments inArguments;
QDBusIntrospection::Annotations annotations;
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += QLatin1String("/>\n");
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += QLatin1String(">\n");
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == QLatin1String("annotation")) {
- parseAnnotation(xml, annotations, ifaceData);
- } else if (xml.name() == QLatin1String("arg")) {
- const QXmlStreamAttributes attributes = xml.attributes();
- const QString direction = attributes.value(QLatin1String("direction")).toString();
+ 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;
- if (!attributes.hasAttribute(QLatin1String("direction"))
- || direction == QLatin1String("in")) {
- parseArg(attributes, argument, ifaceData);
+ argument.location = m_currentLocation;
+ if (!attributes.hasAttribute("direction"_L1) || direction == "in"_L1) {
+ parseArg(attributes, argument);
inArguments << argument;
- } else if (direction == QLatin1String("out")) {
- parseArg(attributes, argument, ifaceData);
+ } else if (direction == "out"_L1) {
+ 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 += QLatin1String(" </method>\n");
+ m_currentInterface->introspection += " </method>\n"_L1;
}
methodData.inputArgs = inArguments;
@@ -224,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() == QLatin1String("signal"));
+ Q_ASSERT(m_currentInterface);
+ Q_ASSERT(m_xml.isStartElement() && m_xml.name() == "signal"_L1);
- const QXmlStreamAttributes attributes = xml.attributes();
- const QString signalName = attributes.value(QLatin1String("name")).toString();
+ 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 += QLatin1String(" <signal name=\"") + signalName + QLatin1String("\"");
+ m_currentInterface->introspection += " <signal name=\""_L1 + signalName + u'"';
QDBusIntrospection::Arguments arguments;
QDBusIntrospection::Annotations annotations;
- if (!xml.readNextStartElement()) {
- ifaceData->introspection += QLatin1String("/>\n");
+ if (!readNextStartElement()) {
+ m_currentInterface->introspection += "/>\n"_L1;
} else {
- ifaceData->introspection += QLatin1String(">\n");
+ m_currentInterface->introspection += ">\n"_L1;
do {
- if (xml.name() == QLatin1String("annotation")) {
- parseAnnotation(xml, annotations, ifaceData);
- } else if (xml.name() == QLatin1String("arg")) {
- 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;
- if (!attributes.hasAttribute(QLatin1String("direction")) ||
- attributes.value(QLatin1String("direction")) == QLatin1String("out")) {
- parseArg(attributes, argument, ifaceData);
+ argument.location = m_currentLocation;
+ if (!attributes.hasAttribute("direction"_L1) ||
+ attributes.value("direction"_L1) == "out"_L1) {
+ 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 += QLatin1String(" </signal>\n");
+ m_currentInterface->introspection += " </signal>\n"_L1;
}
signalData.outputArgs = arguments;
@@ -276,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(QLatin1String("name")).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 += QLatin1String(" <interface name=\"") + ifaceName + QLatin1String("\">\n");
+ 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() == QLatin1String("method")) {
+ 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() == QLatin1String("signal")) {
+ 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() == QLatin1String("property")) {
+ 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() == QLatin1String("annotation")) {
- 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 += QLatin1String(" </interface>");
+ 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() != QLatin1String("interface")) {
- 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(QLatin1String("name")).toString();
- const QString fullName = objData->path.endsWith(QLatin1Char('/'))
- ? (objData->path + objName)
- : QString(objData->path + QLatin1Char('/') + 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;
}
-QDBusXmlParser::QDBusXmlParser(const QString& service, const QString& path,
- const QString& xmlData)
- : m_service(service), m_path(path), m_object(new QDBusIntrospection::Object)
+void QDBusXmlParser::updateCurrentLocation()
{
-// qDBusParserError() << "parsing" << xmlData;
+ m_currentLocation =
+ QDBusIntrospection::SourceLocation{ m_xml.lineNumber(), m_xml.columnNumber() };
+}
+// Similar to m_xml.readNextElement() but sets current location to point
+// to the start element.
+bool QDBusXmlParser::readNextStartElement()
+{
+ 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() == QLatin1String("node")) {
- readNode(xml, m_object, ++nodeLevel);
- } else if (xml.name() == QLatin1String("interface")) {
- 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() == QLatin1String("node")) {
+ 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:
@@ -387,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 d089bae163..0476ba3628 100644
--- a/src/dbus/qdbusxmlparser_p.h
+++ b/src/dbus/qdbusxmlparser_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QDBUSXMLPARSER_P_H
#define QDBUSXMLPARSER_P_H
@@ -54,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
@@ -70,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."]
}
diff --git a/src/dbus/qtdbusglobal.h b/src/dbus/qtdbusglobal.h
index 7606edf740..9724c066f6 100644
--- a/src/dbus/qtdbusglobal.h
+++ b/src/dbus/qtdbusglobal.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTDBUSGLOBAL_H
#define QTDBUSGLOBAL_H
@@ -51,27 +15,10 @@
#ifdef Q_CC_MSVC
#include <QtCore/qlist.h>
#include <QtCore/qset.h>
-#if QT_DEPRECATED_SINCE(5, 5)
-#include <QtCore/qhash.h>
#endif
-#endif
-
-QT_BEGIN_NAMESPACE
#ifndef QT_NO_DBUS
-
-#ifndef QT_STATIC
-# if defined(QT_BUILD_DBUS_LIB)
-# define Q_DBUS_EXPORT Q_DECL_EXPORT
-# else
-# define Q_DBUS_EXPORT Q_DECL_IMPORT
-# endif
-#else
-# define Q_DBUS_EXPORT
-#endif
-
+#include <QtDBus/qtdbusexports.h>
#endif // QT_NO_DBUS
-QT_END_NAMESPACE
-
#endif
diff --git a/src/dbus/qtdbusglobal_p.h b/src/dbus/qtdbusglobal_p.h
index c2788f5c23..9d315de75c 100644
--- a/src/dbus/qtdbusglobal_p.h
+++ b/src/dbus/qtdbusglobal_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTDBUSGLOBAL_P_H
#define QTDBUSGLOBAL_P_H