summaryrefslogtreecommitdiffstats
path: root/src/dbus
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus')
-rw-r--r--src/dbus/CMakeLists.txt83
-rw-r--r--src/dbus/Qt5DBusConfigExtras.cmake.in33
-rw-r--r--src/dbus/Qt5DBusMacros.cmake154
-rw-r--r--src/dbus/Qt6DBusMacros.cmake236
-rw-r--r--src/dbus/dbus.pro88
-rw-r--r--src/dbus/dbus_minimal_p.h44
-rw-r--r--src/dbus/doc/qtdbus.qdocconf19
-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.cpp59
-rw-r--r--src/dbus/doc/snippets/code/doc_src_qtdbus.cpp53
-rw-r--r--src/dbus/doc/snippets/code/doc_src_qtdbus.pro3
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp112
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp249
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp63
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp56
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp62
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp84
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp88
-rw-r--r--src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp79
-rw-r--r--src/dbus/doc/snippets/qdbusextratypes/qdbusextratypes.cpp53
-rw-r--r--src/dbus/doc/snippets/snippets.pro3
-rw-r--r--src/dbus/doc/src/dbus-adaptors.qdoc47
-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.qdoc243
-rw-r--r--src/dbus/doc/src/qtdbus-module.qdoc53
-rw-r--r--src/dbus/doc/src/qtdbus-overview.qdoc176
-rw-r--r--src/dbus/qdbus_symbols.cpp75
-rw-r--r--src/dbus/qdbus_symbols_p.h98
-rw-r--r--src/dbus/qdbusabstractadaptor.cpp91
-rw-r--r--src/dbus/qdbusabstractadaptor.h40
-rw-r--r--src/dbus/qdbusabstractadaptor_p.h49
-rw-r--r--src/dbus/qdbusabstractinterface.cpp282
-rw-r--r--src/dbus/qdbusabstractinterface.h78
-rw-r--r--src/dbus/qdbusabstractinterface_p.h43
-rw-r--r--src/dbus/qdbusargument.cpp146
-rw-r--r--src/dbus/qdbusargument.h204
-rw-r--r--src/dbus/qdbusargument_p.h103
-rw-r--r--src/dbus/qdbusconnection.cpp441
-rw-r--r--src/dbus/qdbusconnection.h53
-rw-r--r--src/dbus/qdbusconnection_p.h149
-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.h73
-rw-r--r--src/dbus/qdbuscontext.cpp44
-rw-r--r--src/dbus/qdbuscontext.h40
-rw-r--r--src/dbus/qdbuscontext_p.h40
-rw-r--r--src/dbus/qdbusdemarshaller.cpp48
-rw-r--r--src/dbus/qdbuserror.cpp56
-rw-r--r--src/dbus/qdbuserror.h57
-rw-r--r--src/dbus/qdbusextratypes.cpp61
-rw-r--r--src/dbus/qdbusextratypes.h78
-rw-r--r--src/dbus/qdbusintegrator.cpp883
-rw-r--r--src/dbus/qdbusintegrator_p.h89
-rw-r--r--src/dbus/qdbusinterface.cpp102
-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.h96
-rw-r--r--src/dbus/qdbusmarshaller.cpp154
-rw-r--r--src/dbus/qdbusmessage.cpp234
-rw-r--r--src/dbus/qdbusmessage.h59
-rw-r--r--src/dbus/qdbusmessage_p.h48
-rw-r--r--src/dbus/qdbusmetaobject.cpp334
-rw-r--r--src/dbus/qdbusmetaobject_p.h41
-rw-r--r--src/dbus/qdbusmetatype.cpp295
-rw-r--r--src/dbus/qdbusmetatype.h78
-rw-r--r--src/dbus/qdbusmetatype_p.h101
-rw-r--r--src/dbus/qdbusmisc.cpp171
-rw-r--r--src/dbus/qdbuspendingcall.cpp142
-rw-r--r--src/dbus/qdbuspendingcall.h49
-rw-r--r--src/dbus/qdbuspendingcall_p.h55
-rw-r--r--src/dbus/qdbuspendingreply.cpp100
-rw-r--r--src/dbus/qdbuspendingreply.h206
-rw-r--r--src/dbus/qdbusreply.cpp87
-rw-r--r--src/dbus/qdbusreply.h48
-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.cpp46
-rw-r--r--src/dbus/qdbusunixfiledescriptor.h44
-rw-r--r--src/dbus/qdbusutil.cpp272
-rw-r--r--src/dbus/qdbusutil_p.h77
-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.json8
-rw-r--r--src/dbus/qtdbusglobal.h60
-rw-r--r--src/dbus/qtdbusglobal_p.h40
101 files changed, 4184 insertions, 6551 deletions
diff --git a/src/dbus/CMakeLists.txt b/src/dbus/CMakeLists.txt
new file mode 100644
index 0000000000..9c3f6d23d2
--- /dev/null
+++ b/src/dbus/CMakeLists.txt
@@ -0,0 +1,83 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+#####################################################################
+## DBus Module:
+#####################################################################
+
+qt_internal_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.cpp 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 qdbusmetaobject_p.h
+ qdbusmetatype.cpp qdbusmetatype.h qdbusmetatype_p.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
+ 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)
+
+## Scopes:
+#####################################################################
+
+qt_internal_extend_target(DBus CONDITION QT_FEATURE_dbus_linked
+ DEFINES
+ QT_LINKED_LIBDBUS
+ LIBRARIES
+ dbus-1
+)
+
+qt_internal_extend_target(DBus CONDITION WIN32
+ LIBRARIES
+ advapi32
+ netapi32
+ user32
+ ws2_32
+)
+qt_internal_add_docs(DBus
+ doc/qtdbus.qdocconf
+)
diff --git a/src/dbus/Qt5DBusConfigExtras.cmake.in b/src/dbus/Qt5DBusConfigExtras.cmake.in
deleted file mode 100644
index 1d947159e2..0000000000
--- a/src/dbus/Qt5DBusConfigExtras.cmake.in
+++ /dev/null
@@ -1,33 +0,0 @@
-
-if (NOT TARGET Qt5::qdbuscpp2xml)
- add_executable(Qt5::qdbuscpp2xml IMPORTED)
-
-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
- set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
-!!ELSE
- set(imported_location \"$${CMAKE_BIN_DIR}qdbuscpp2xml$$CMAKE_BIN_SUFFIX\")
-!!ENDIF
- _qt5_DBus_check_file_exists(${imported_location})
-
- set_target_properties(Qt5::qdbuscpp2xml PROPERTIES
- IMPORTED_LOCATION ${imported_location}
- )
-endif()
-
-if (NOT TARGET Qt5::qdbusxml2cpp)
- add_executable(Qt5::qdbusxml2cpp IMPORTED)
-
-!!IF isEmpty(CMAKE_BIN_DIR_IS_ABSOLUTE)
- set(imported_location \"${_qt5DBus_install_prefix}/$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
-!!ELSE
- set(imported_location \"$${CMAKE_BIN_DIR}qdbusxml2cpp$$CMAKE_BIN_SUFFIX\")
-!!ENDIF
- _qt5_DBus_check_file_exists(${imported_location})
-
- set_target_properties(Qt5::qdbusxml2cpp PROPERTIES
- IMPORTED_LOCATION ${imported_location}
- )
-endif()
-
-set(Qt5DBus_QDBUSCPP2XML_EXECUTABLE Qt5::qdbuscpp2xml)
-set(Qt5DBus_QDBUSXML2CPP_EXECUTABLE Qt5::qdbusxml2cpp)
diff --git a/src/dbus/Qt5DBusMacros.cmake b/src/dbus/Qt5DBusMacros.cmake
deleted file mode 100644
index b381ab0934..0000000000
--- a/src/dbus/Qt5DBusMacros.cmake
+++ /dev/null
@@ -1,154 +0,0 @@
-#=============================================================================
-# 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.
-#=============================================================================
-
-include(MacroAddFileDependencies)
-
-include(CMakeParseArguments)
-
-function(QT5_ADD_DBUS_INTERFACE _sources _interface _basename)
- 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_source_file_property(_nonamespace ${_interface} NO_NAMESPACE)
- if(_nonamespace)
- set(_params -N -m)
- else()
- set(_params -m)
- endif()
-
- get_source_file_property(_classname ${_interface} CLASSNAME)
- if(_classname)
- set(_params ${_params} -c ${_classname})
- endif()
-
- get_source_file_property(_include ${_interface} INCLUDE)
- if(_include)
- set(_params ${_params} -i ${_include})
- endif()
-
- add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} ${_params} -p ${_basename} ${_infile}
- DEPENDS ${_infile} VERBATIM)
-
- set_source_files_properties("${_impl}" "${_header}" PROPERTIES SKIP_AUTOMOC TRUE)
-
- qt5_generate_moc("${_header}" "${_moc}")
-
- list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
- macro_add_file_dependencies("${_impl}" "${_moc}")
- set(${_sources} ${${_sources}} PARENT_SCOPE)
-endfunction()
-
-
-function(QT5_ADD_DBUS_INTERFACES _sources)
- foreach(_current_FILE ${ARGN})
- get_filename_component(_infile ${_current_FILE} ABSOLUTE)
- get_filename_component(_basename ${_current_FILE} NAME)
- # get the part before the ".xml" suffix
- string(TOLOWER ${_basename} _basename)
- string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
- qt5_add_dbus_interface(${_sources} ${_infile} ${_basename}interface)
- endforeach()
- set(${_sources} ${${_sources}} PARENT_SCOPE)
-endfunction()
-
-
-function(QT5_GENERATE_DBUS_INTERFACE _header) # _customName OPTIONS -some -options )
- set(options)
- set(oneValueArgs)
- set(multiValueArgs OPTIONS)
-
- cmake_parse_arguments(_DBUS_INTERFACE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- set(_customName ${_DBUS_INTERFACE_UNPARSED_ARGUMENTS})
-
- get_filename_component(_in_file ${_header} ABSOLUTE)
- get_filename_component(_basename ${_header} NAME_WE)
-
- if(_customName)
- if(IS_ABSOLUTE ${_customName})
- get_filename_component(_containingDir ${_customName} PATH)
- if(NOT EXISTS ${_containingDir})
- file(MAKE_DIRECTORY "${_containingDir}")
- endif()
- set(_target ${_customName})
- else()
- set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
- endif()
- else()
- set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
- endif()
-
- add_custom_command(OUTPUT ${_target}
- COMMAND ${Qt5DBus_QDBUSCPP2XML_EXECUTABLE} ${_DBUS_INTERFACE_OPTIONS} ${_in_file} -o ${_target}
- DEPENDS ${_in_file} VERBATIM
- )
-endfunction()
-
-
-function(QT5_ADD_DBUS_ADAPTOR _sources _xml_file _include _parentClass) # _optionalBasename _optionalClassName)
- get_filename_component(_infile ${_xml_file} ABSOLUTE)
-
- set(_optionalBasename "${ARGV4}")
- if(_optionalBasename)
- set(_basename ${_optionalBasename} )
- else()
- string(REGEX REPLACE "(.*[/\\.])?([^\\.]+)\\.xml" "\\2adaptor" _basename ${_infile})
- string(TOLOWER ${_basename} _basename)
- endif()
-
- 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")
-
- if(_optionalClassName)
- add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -c ${_optionalClassName} -i ${_include} -l ${_parentClass} ${_infile}
- DEPENDS ${_infile} VERBATIM
- )
- else()
- add_custom_command(OUTPUT "${_impl}" "${_header}"
- COMMAND ${Qt5DBus_QDBUSXML2CPP_EXECUTABLE} -m -a ${_basename} -i ${_include} -l ${_parentClass} ${_infile}
- DEPENDS ${_infile} VERBATIM
- )
- endif()
-
- qt5_generate_moc("${_header}" "${_moc}")
- set_source_files_properties("${_impl}" "${_header}" PROPERTIES SKIP_AUTOMOC TRUE)
- macro_add_file_dependencies("${_impl}" "${_moc}")
-
- list(APPEND ${_sources} "${_impl}" "${_header}" "${_moc}")
- set(${_sources} ${${_sources}} PARENT_SCOPE)
-endfunction()
diff --git a/src/dbus/Qt6DBusMacros.cmake b/src/dbus/Qt6DBusMacros.cmake
new file mode 100644
index 0000000000..57a4a0735e
--- /dev/null
+++ b/src/dbus/Qt6DBusMacros.cmake
@@ -0,0 +1,236 @@
+# Copyright 2005-2011 Kitware, Inc.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+include(MacroAddFileDependencies)
+
+function(qt6_add_dbus_interface _sources _interface _relativename)
+ get_filename_component(_infile ${_interface} ABSOLUTE)
+ 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)
+ set(_params -N -m)
+ else()
+ set(_params -m)
+ endif()
+
+ get_source_file_property(_classname ${_interface} CLASSNAME)
+ if(_classname)
+ set(_params ${_params} -c ${_classname})
+ endif()
+
+ get_source_file_property(_include ${_interface} INCLUDE)
+ if(_include)
+ set(_params ${_params} -i ${_include})
+ endif()
+
+ add_custom_command(OUTPUT "${_impl}" "${_header}"
+ 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
+ SKIP_AUTOUIC TRUE
+ )
+
+ qt6_generate_moc("${_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)
+ # 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}" "${interface}" "${relativename}")
+ elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
+ qt6_add_dbus_interface("${sources}" "${interface}" "${relativename}")
+ endif()
+ set("${sources}" "${${sources}}" PARENT_SCOPE)
+ endfunction()
+endif()
+
+
+function(qt6_add_dbus_interfaces _sources)
+ foreach(_current_FILE ${ARGN})
+ get_filename_component(_infile ${_current_FILE} ABSOLUTE)
+ get_filename_component(_basename ${_current_FILE} NAME)
+ # get the part before the ".xml" suffix
+ string(TOLOWER ${_basename} _basename)
+ string(REGEX REPLACE "(.*\\.)?([^\\.]+)\\.xml" "\\2" _basename ${_basename})
+ qt6_add_dbus_interface(${_sources} ${_infile} ${_basename}interface)
+ endforeach()
+ set(${_sources} ${${_sources}} PARENT_SCOPE)
+endfunction()
+
+if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS)
+ function(qt_add_dbus_interfaces sources)
+ if(QT_DEFAULT_MAJOR_VERSION EQUAL 5)
+ qt5_add_dbus_interfaces("${sources}" ${ARGN})
+ elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
+ qt6_add_dbus_interfaces("${sources}" ${ARGN})
+ endif()
+ set("${sources}" "${${sources}}" PARENT_SCOPE)
+ endfunction()
+endif()
+
+
+function(qt6_generate_dbus_interface _header) # _customName OPTIONS -some -options )
+ set(options)
+ set(oneValueArgs)
+ set(multiValueArgs OPTIONS)
+
+ cmake_parse_arguments(_DBUS_INTERFACE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
+
+ set(_customName ${_DBUS_INTERFACE_UNPARSED_ARGUMENTS})
+
+ get_filename_component(_in_file ${_header} ABSOLUTE)
+ get_filename_component(_basename ${_header} NAME_WE)
+
+ if(_customName)
+ if(IS_ABSOLUTE ${_customName})
+ get_filename_component(_containingDir ${_customName} PATH)
+ if(NOT EXISTS ${_containingDir})
+ file(MAKE_DIRECTORY "${_containingDir}")
+ endif()
+ set(_target ${_customName})
+ else()
+ set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_customName})
+ endif()
+ else()
+ set(_target ${CMAKE_CURRENT_BINARY_DIR}/${_basename}.xml)
+ endif()
+
+ add_custom_command(OUTPUT ${_target}
+ COMMAND ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml ${_DBUS_INTERFACE_OPTIONS} ${_in_file} -o ${_target}
+ DEPENDS ${_in_file} ${QT_CMAKE_EXPORT_NAMESPACE}::qdbuscpp2xml
+ VERBATIM
+ )
+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)
+ qt6_generate_dbus_interface(${ARGV})
+ endif()
+ endfunction()
+endif()
+
+
+function(qt6_add_dbus_adaptor _sources _xml_file _include) # _optionalParentClass _optionalRelativename _optionalClassName)
+ get_filename_component(_infile ${_xml_file} ABSOLUTE)
+
+ 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" _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}/${_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 ${_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 ${_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
+ SKIP_AUTOUIC TRUE
+ )
+ macro_add_file_dependencies("${_impl}" "${_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 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}" "${dbus_spec}" "${header}"
+ "${parent_class}" "${basename}" "${classname}"
+ )
+ elseif(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
+ qt6_add_dbus_adaptor(
+ "${sources}" "${dbus_spec}" "${header}"
+ "${parent_class}" "${basename}" "${classname}"
+ )
+ endif()
+ set("${sources}" "${${sources}}" PARENT_SCOPE)
+ endfunction()
+endif()
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 e08bbfd94e..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
@@ -10,8 +12,9 @@ project = QtDBus
# Images should be placed in <rootdir>/dic/images and examples in
# <rootdir>/examples.
# Paths are relative to the location of this file.
-exampledirs += ../../../examples/dbus \
- snippets
+exampledirs += . \
+ snippets \
+ ../../../examples/dbus
headerdirs += ..
imagedirs += images \
@@ -24,7 +27,7 @@ examplesinstallpath = dbus
tagfile = qtdbus.tags
-depends += qtdoc qtcore
+depends += qtcore qtdoc qmake qtcmake
# The following parameters are for creating a qhp file, the qhelpgenerator
# program can convert the qhp file into a qch file which can be opened in
@@ -60,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
new file mode 100644
index 0000000000..4b4751d4fa
--- /dev/null
+++ b/src/dbus/doc/snippets/CMakeLists.txt
@@ -0,0 +1,7 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#! [cmake_use]
+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 f5d9fe7889..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,11 @@
-/****************************************************************************
-**
-** 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>
+
+struct RequestData;
+void appendRequest(RequestData *) {}; // stub
//! [10]
struct RequestData
@@ -73,7 +32,7 @@ QString processRequest(const QString &request, const QDBusMessage &message)
void sendReply(RequestData *data)
{
// data->processedData has been initialized with the request's reply
- QDBusMessage &reply = &data->reply;
+ QDBusMessage &reply = data->reply;
// send the reply over D-Bus:
reply << data->processedData;
diff --git a/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp b/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp
deleted file mode 100644
index 444561267d..0000000000
--- a/src/dbus/doc/snippets/code/doc_src_qtdbus.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-//! [0]
-#include <QtDBus>
-//! [0]
diff --git a/src/dbus/doc/snippets/code/doc_src_qtdbus.pro b/src/dbus/doc/snippets/code/doc_src_qtdbus.pro
deleted file mode 100644
index a1ba138a85..0000000000
--- a/src/dbus/doc/snippets/code/doc_src_qtdbus.pro
+++ /dev/null
@@ -1,3 +0,0 @@
-#! [1]
-QT += dbus
-#! [1]
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
index b70cdf3455..92b9dea909 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusabstractinterface.cpp
@@ -1,70 +1,68 @@
-/****************************************************************************
-**
-** 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
+
+public:
+ Abstract_DBus_Interface(QObject *parent = nullptr)
+ : QObject(parent) {
+ interface = new QDBusInterface("org.example.Interface", "/Example/Methods");
+ }
+
+ ~Abstract_DBus_Interface() { delete interface; }
+ void interfaceMain();
+ void asyncCall();
+ QString retrieveValue() { return QString(); }
+
+public slots:
+ void callFinishedSlot();
+
+private:
+ QDBusInterface *interface;
+};
+
+void Abstract_DBus_Interface::interfaceMain()
+{
//! [0]
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, this);
+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 b64ea5cf21..5cb6ce5bb2 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusargument.cpp
@@ -1,146 +1,205 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-//! [0]
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+#include <QString>
+#include <QDBusArgument>
+#include <QDBusMetaType>
+#include <QDBusMessage>
+#include <QDBusContext>
+
+typedef QDBusVariant MyElement;
+typedef QList<MyElement> MyArray;
+typedef QHash<int, MyElement> MyDictionary;
+typedef QDBusVariant MyType;
+typedef QDBusVariant MyValue;
+typedef QDBusVariant Type;
+QDBusArgument argument;
+
+class MyObject: public QObject
+{
+ Q_OBJECT
+
+ Q_CLASSINFO("D-Bus Interface", "org.qtproject.QtDBus.MyObject")
+ Q_CLASSINFO("D-Bus Introspection", ""
+" <interface name=\"org.qtproject.QtDBus.MyObject\" >\n"
+" <property access=\"readwrite\" type=\"i\" name=\"prop1\" />\n"
+" <property name=\"complexProp\" type=\"ai\" access=\"readwrite\">\n"
+" <annotation name=\"org.qtproject.QtDBus.QtTypeName\" value=\"QList&lt;int&gt;\"/>\n"
+" </property>\n"
+" <signal name=\"somethingHappened\" >\n"
+" <arg direction=\"out\" type=\"s\" />\n"
+" </signal>\n"
+" <method name=\"ping\" >\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"ping\" />\n"
+" </method>\n"
+" <method name=\"ping_invokable\" >\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping_invokable\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"ping_invokable\" />\n"
+" </method>\n"
+" <method name=\"ping\" >\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping1\" />\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping2\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"pong1\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"pong2\" />\n"
+" </method>\n"
+" <method name=\"ping_invokable\" >\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping1_invokable\" />\n"
+" <arg direction=\"in\" type=\"v\" name=\"ping2_invokable\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"pong1_invokable\" />\n"
+" <arg direction=\"out\" type=\"v\" name=\"pong2_invokable\" />\n"
+" </method>\n"
+" <method name=\"ping\" >\n"
+" <arg direction=\"in\" type=\"ai\" name=\"ping\" />\n"
+" <arg direction=\"out\" type=\"ai\" name=\"ping\" />\n"
+" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
+" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
+" </method>\n"
+" <method name=\"ping_invokable\" >\n"
+" <arg direction=\"in\" type=\"ai\" name=\"ping_invokable\" />\n"
+" <arg direction=\"out\" type=\"ai\" name=\"ping_invokable\" />\n"
+" <annotation name=\"org.qtproject.QtDBus.QtTypeName.In0\" value=\"QList&lt;int&gt;\"/>\n"
+" <annotation name=\"org.qtproject.QtDBus.QtTypeName.Out0\" value=\"QList&lt;int&gt;\"/>\n"
+" </method>\n"
+" </interface>\n"
+ "")
+ Q_PROPERTY(int prop1 READ prop1 WRITE setProp1)
+ Q_PROPERTY(QList<int> complexProp READ complexProp WRITE setComplexProp)
+
+public:
+ static int callCount;
+ static QVariantList callArgs;
+ MyObject()
+ {
+ QObject *subObject = new QObject(this);
+ subObject->setObjectName("subObject");
+ }
+};
+
+struct MyMember
+{
+ int subMember1;
+ int subMember2;
+};
+
+//! [0-0]
struct MyStructure
{
int count;
QString name;
+//! [0-0]
+ MyMember member1;
+ MyMember member2;
+ MyMember member3;
+ MyMember member4;
+//! [0-1]
+ // ...
};
Q_DECLARE_METATYPE(MyStructure)
// Marshall the MyStructure data into a D-Bus argument
-QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
+QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &myStruct)
{
argument.beginStructure();
- argument << mystruct.count << mystruct.name;
+ argument << myStruct.count << myStruct.name;
argument.endStructure();
return argument;
}
// Retrieve the MyStructure data from the D-Bus argument
-const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct)
+const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &myStruct)
{
argument.beginStructure();
- argument >> mystruct.count >> mystruct.name;
+ argument >> myStruct.count >> myStruct.name;
argument.endStructure();
return argument;
}
-//! [0]
+//! [0-1]
+const QDBusArgument &operator<<(const QDBusArgument &argument, const MyMember &/*member*/)
+{
+ return argument;
+}
+
+const QDBusArgument &operator>>(const QDBusArgument &argument, const MyMember &/*member*/)
+{
+ return argument;
+}
+void registerMyStructure()
+{
//! [1]
qDBusRegisterMetaType<MyStructure>();
//! [1]
+}
-
+void castType()
+{
+QVariant argument = MyObject::callArgs.at(0);
+QDBusVariant dv = qdbus_cast<QDBusVariant>(argument);
//! [2]
MyType item = qdbus_cast<Type>(argument);
//! [2]
+}
-
+void argumentItem()
+{
//! [3]
MyType item;
argument >> item;
//! [3]
-
-
+}
+namespace QDBusSnippets
+{
//! [4]
-QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
+QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &myStruct)
{
argument.beginStructure();
- argument << mystruct.member1 << mystruct.member2 << ... ;
+ argument << myStruct.member1 << myStruct.member2;
argument.endStructure();
return argument;
}
//! [4]
-
+namespace Alt {
//! [5]
-QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &mystruct)
+QDBusArgument &operator<<(QDBusArgument &argument, const MyStructure &myStruct)
{
argument.beginStructure();
- argument << mystruct.member1 << mystruct.member2;
+ argument << myStruct.member1 << myStruct.member2;
argument.beginStructure();
- argument << mystruct.member3.subMember1 << mystruct.member3.subMember2;
+ argument << myStruct.member3.subMember1 << myStruct.member3.subMember2;
argument.endStructure();
- argument << mystruct.member4;
+ argument << myStruct.member4;
argument.endStructure();
return argument;
}
//! [5]
-
+} // namespace
//! [6]
-// append an array of MyElement types
-QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myarray)
+// Append an array of MyElement types
+QDBusArgument &operator<<(QDBusArgument &argument, const MyArray &myArray)
{
- argument.beginArray( qMetaTypeId<MyElement>() );
- for ( int i = 0; i < myarray.length; ++i )
- argument << myarray.elements[i];
+ argument.beginArray(qMetaTypeId<MyElement>());
+ for (const auto &element : myArray)
+ argument << element;
argument.endArray();
return argument;
}
//! [6]
-
//! [7]
-// append a dictionary that associates ints to MyValue types
-QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &mydict)
+// Append a dictionary that associates ints to MyValue types
+QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &myDict)
{
- argument.beginMap( QVariant::Int, qMetaTypeId<MyValue>() );
- for ( int i = 0; i < mydict.length; ++i ) {
+ argument.beginMap(QMetaType::fromType<int>(), QMetaType::fromType<MyValue>());
+ MyDictionary::const_iterator i;
+ for (i = myDict.cbegin(); i != myDict.cend(); ++i) {
argument.beginMapEntry();
- argument << mydict.data[i].key << mydict.data[i].value;
+ argument << i.key() << i.value();
argument.endMapEntry();
}
argument.endMap();
@@ -148,29 +207,27 @@ QDBusArgument &operator<<(QDBusArgument &argument, const MyDictionary &mydict)
}
//! [7]
-
//! [8]
-const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &mystruct)
+const QDBusArgument &operator>>(const QDBusArgument &argument, MyStructure &myStruct)
{
- argument.beginStructure()
- argument >> mystruct.member1 >> mystruct.member2 >> mystruct.member3 >> ...;
+ argument.beginStructure();
+ argument >> myStruct.member1 >> myStruct.member2 >> myStruct.member3;
argument.endStructure();
return argument;
}
//! [8]
-
//! [9]
-// extract a MyArray array of MyElement elements
-const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myarray)
+// Extract a MyArray array of MyElement elements
+const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myArray)
{
argument.beginArray();
- myarray.clear();
+ myArray.clear();
- while ( !argument.atEnd() ) {
+ while (!argument.atEnd()) {
MyElement element;
argument >> element;
- myarray.append( element );
+ myArray.append(element);
}
argument.endArray();
@@ -178,24 +235,24 @@ const QDBusArgument &operator>>(const QDBusArgument &argument, MyArray &myarray)
}
//! [9]
-
//! [10]
-// extract a MyDictionary map that associates ints to MyValue elements
-const QDBusArgument &operator>>(const QDBusArgument &argument, MyDictionary &mydict)
+// Extract a MyDictionary map that associates integers to MyElement items
+const QDBusArgument &operator>>(const QDBusArgument &argument, MyDictionary &myDict)
{
argument.beginMap();
- mydict.clear();
+ myDict.clear();
- while ( !argument.atEnd() ) {
+ while (!argument.atEnd()) {
int key;
- MyValue value;
+ MyElement value;
argument.beginMapEntry();
argument >> key >> value;
argument.endMapEntry();
- mydict.append( key, value );
+ myDict.insert(key, value);
}
argument.endMap();
return argument;
}
//! [10]
+}
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
index dd49e004c5..75b4394595 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuscontext.cpp
@@ -1,62 +1,23 @@
-/****************************************************************************
-**
-** 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>
+#include <QDBusArgument>
+#include <QDBusMetaType>
+#include <QDBusMessage>
+#include <QDBusContext>
//! [0]
class MyObject: public QObject,
protected QDBusContext
{
Q_OBJECT
+
QDBusConnection conn;
QDBusMessage msg;
-...
+ //...
protected slots:
void process();
@@ -76,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 a9c1fdfe6d..06d654b97b 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusinterface.cpp
@@ -1,53 +1,10 @@
-/****************************************************************************
-**
-** 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>
+void DBusInterface_main()
+{
//! [0]
QDBusInterface remoteApp( "com.example.Calculator", "/Calculator/Operations",
"org.mathematics.RPNCalculator" );
@@ -59,3 +16,4 @@ QDBusReply<int> reply = remoteApp.call( "PopOperand" );
if ( reply.isValid() )
printf( "%d", reply.value() ); // prints 4
//! [0]
+}
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
index bc90f118c9..c9e5281cdb 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusmetatype.cpp
@@ -1,54 +1,14 @@
-/****************************************************************************
-**
-** 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) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-//! [0]
+#include <QtCore/qlist.h>
+typedef QList<QString> MyClass;
+
+//! [0-0]
#include <QDBusMetaType>
+//! [0-0]
+void dbus() {
+//! [0-1]
qDBusRegisterMetaType<MyClass>();
-//! [0]
+//! [0-1]
+}
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
index 9552054a5e..67b019a67d 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingcall.cpp
@@ -1,66 +1,46 @@
-/****************************************************************************
-**
-** 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>
+class DBus_PendingCall_Interface : public QObject
+{
+ Q_OBJECT
+
+public:
+ DBus_PendingCall_Interface(QObject *parent = nullptr)
+ : QObject(parent) {
+ iface = new QDBusInterface("org.example.Interface", "/Example/Methods");
+ }
+
+ ~DBus_PendingCall_Interface() { delete iface; }
+ void callInterfaceMain();
+ void showError();
+ void showReply(QString&, QByteArray&);
+ QString value1;
+ QString value2;
+ void callFinishedSlot(QDBusPendingCallWatcher *call);
+public slots:
+
+private:
+ QDBusInterface *iface;
+};
+
+void DBus_PendingCall_Interface::callInterfaceMain()
{
//! [0]
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]
}
//! [1]
-void MyClass::callFinishedSlot(QDBusPendingCallWatcher *call)
+void DBus_PendingCall_Interface::callFinishedSlot(QDBusPendingCallWatcher *call)
{
QDBusPendingReply<QString, QByteArray> reply = *call;
if (reply.isError()) {
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
index 7e6ee55b8a..04f707dba8 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbuspendingreply.cpp
@@ -1,67 +1,51 @@
-/****************************************************************************
-**
-** 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>
+class DBus_PendingReply_Interface : public QObject
+{
+ Q_OBJECT
+
+public:
+ DBus_PendingReply_Interface(QObject *parent = nullptr)
+ : QObject(parent) {
+ iface = new QDBusInterface("org.example.Interface", "/Example/Methods");
+ }
+
+ ~DBus_PendingReply_Interface() { delete iface; }
+ void callInterfaceMainR();
+ void PendingReplyString();
+ void PendingReplyBool();
+ void showErrorD(QDBusError);
+ void showSuccess(QVariant);
+ void showFailure(QVariant);
+ void useValue(QDBusPendingReplyTypes::Select<0, QString, void, void, void, void, void, void, void>::Type);
+public slots:
+
+private:
+ QDBusInterface *iface;
+};
+
+void DBus_PendingReply_Interface::PendingReplyString()
{
//! [0]
- QDBusPendingReply<QString> reply = interface->asyncCall("RemoteMethod");
+ QDBusPendingReply<QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (reply.isError())
// call failed. Show an error condition.
- showError(reply.error());
+ showErrorD(reply.error());
else
// use the returned value
useValue(reply.value());
//! [0]
+}
+void DBus_PendingReply_Interface::PendingReplyBool()
+{
//! [2]
- QDBusPendingReply<bool, QString> reply = interface->asyncCall("RemoteMethod");
+ QDBusPendingReply<bool, QString> reply = iface->asyncCall("RemoteMethod");
reply.waitForFinished();
if (!reply.isError()) {
if (reply.argumentAt<0>())
diff --git a/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
index 1490cbb127..2def08bdfe 100644
--- a/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
+++ b/src/dbus/doc/snippets/code/src_qdbus_qdbusreply.cpp
@@ -1,53 +1,31 @@
-/****************************************************************************
-**
-** 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>
+#include <QDBusReply>
+class DBus_Process_String_Interface : public QObject
+{
+ Q_OBJECT
+
+public:
+ DBus_Process_String_Interface(QObject *parent = nullptr)
+ : QObject(parent) {
+ interface = new QDBusInterface("org.example.Interface", "/Example/Methods");
+ }
+
+ ~DBus_Process_String_Interface() { delete interface; }
+ void QDBus_reply();
+ void useValue(QVariant);
+ void showError(const QDBusError&);
+public slots:
+
+private:
+ QDBusInterface *interface;
+};
+void DBus_Process_String_Interface::QDBus_reply()
+{
//! [0]
QDBusReply<QString> reply = interface->call("RemoteMethod");
if (reply.isValid())
@@ -60,5 +38,6 @@ else
//! [1]
-QString reply = interface->call("RemoteMethod");
+reply = interface->call("RemoteMethod");
//! [1]
+}
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
new file mode 100644
index 0000000000..6c3b57fec9
--- /dev/null
+++ b/src/dbus/doc/snippets/snippets.pro
@@ -0,0 +1,3 @@
+#! [qmake_use]
+QT += dbus
+#! [qmake_use]
diff --git a/src/dbus/doc/src/dbus-adaptors.qdoc b/src/dbus/doc/src/dbus-adaptors.qdoc
index 3398a45af7..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
@@ -79,7 +55,6 @@
\page qdbusdeclaringslots.html
\title Declaring Slots in D-Bus Adaptors
- \contentspage Using Qt D-Bus Adaptors
\nextpage Declaring Signals in D-Bus Adaptors
Slots in D-Bus adaptors are declared just like normal, public slots, but their
@@ -112,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.
@@ -191,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
@@ -208,7 +183,6 @@
\title Declaring Signals in D-Bus Adaptors
\previouspage Declaring Slots in D-Bus Adaptors
- \contentspage Using Qt D-Bus Adaptors
\nextpage The Qt D-Bus Type System
Any signal in a class derived from QDBusAbstractAdaptor will be automatically
@@ -219,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
@@ -237,7 +211,6 @@
\title The Qt D-Bus Type System
\previouspage Declaring Signals in D-Bus Adaptors
- \contentspage Using Qt D-Bus Adaptors
D-Bus has an extensible type system based on a few primitives and
composition of the primitives in arrays and structures. Qt D-Bus
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 18a4aa6d0f..05ca38a207 100644
--- a/src/dbus/doc/src/qtdbus-index.qdoc
+++ b/src/dbus/doc/src/qtdbus-index.qdoc
@@ -1,29 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2018 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,202 +8,75 @@
\keyword QtDBus
- \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
The Qt D-Bus module is available under commercial licenses from \l{The Qt Company}.
- In addition, it is available under free software licenses. Since Qt 5.4,
- these free software licenses are
- \l{GNU Lesser General Public License, version 3}, or
+ In addition, it is available under free software licenses:
+ The \l{GNU Lesser General Public License, version 3}, or
the \l{GNU General Public License, version 2}.
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 0ef5999b11..c89b4dc937 100644
--- a/src/dbus/doc/src/qtdbus-module.qdoc
+++ b/src/dbus/doc/src/qtdbus-module.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) 2020 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
/*!
\module QtDBus
@@ -32,6 +8,7 @@
to perform Inter-Process Communication using the \l{Qt D-Bus}{D-Bus} protocol.
\ingroup modules
+ \qtcmakepackage DBus
\qtvariable dbus
\keyword The QDBus compiler
@@ -42,27 +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.
-
- To use this module, use the following code in your application:
-
- \snippet code/doc_src_qtdbus.cpp 0
-
- \if !defined(qtforpython)
- If you're using qmake to build your application, you can add this
- line to your .pro file to make it link against the Qt D-Bus
- libraries:
-
- \snippet code/doc_src_qtdbus.pro 1
-
- \note The source code for this module is located in the \c{src/qdbus}
- directory. When installing Qt from source, this module is built when Qt's
- tools are built.
- \endif
-
- 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 1e2cbf6da6..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())
@@ -133,10 +96,10 @@ void (*qdbus_resolve_conditionally(const char *name))()
#else
Q_UNUSED(name);
#endif
- return 0;
+ 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()))
@@ -149,7 +112,7 @@ void (*qdbus_resolve_me(const char *name))()
return ptr;
#else
Q_UNUSED(name);
- return 0;
+ return nullptr;
#endif
}
diff --git a/src/dbus/qdbus_symbols_p.h b/src/dbus/qdbus_symbols_p.h
index 7cce0d71aa..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
@@ -213,6 +185,8 @@ DEFINEFUNC(DBusDispatchStatus , dbus_connection_dispatch, (DBusConnection
(connection), return)
DEFINEFUNC(DBusDispatchStatus , dbus_connection_get_dispatch_status, (DBusConnection *connection),
(connection), return)
+DEFINEFUNC(dbus_bool_t, dbus_connection_get_is_authenticated, (DBusConnection * connection),
+ (connection), return )
DEFINEFUNC(dbus_bool_t , dbus_connection_get_is_connected, (DBusConnection *connection),
(connection), return)
DEFINEFUNC(DBusConnection* , dbus_connection_open_private, (const char *address,
diff --git a/src/dbus/qdbusabstractadaptor.cpp b/src/dbus/qdbusabstractadaptor.cpp
index b7b291551d..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,32 +22,26 @@
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;
}
QDBusAdaptorConnector *qDBusFindAdaptorConnector(QObject *obj)
{
if (!obj)
- return 0;
- 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);
+ return nullptr;
+
+ for (QObject *child : std::as_const(obj->children())) {
+ QDBusAdaptorConnector *connector = qobject_cast<QDBusAdaptorConnector *>(child);
if (connector) {
connector->polish();
return connector;
}
}
- return 0;
+ return nullptr;
}
QDBusAdaptorConnector *qDBusFindAdaptorConnector(QDBusAbstractAdaptor *adaptor)
@@ -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
- QVector<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 404901381b..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
@@ -55,11 +19,10 @@
#include <QtDBus/private/qtdbusglobal_p.h>
#include <qdbusabstractadaptor.h>
-#include <QtCore/qobject.h>
+#include <QtCore/qlist.h>
#include <QtCore/qmap.h>
-#include <QtCore/qreadwritelock.h>
+#include <QtCore/qobject.h>
#include <QtCore/qvariant.h>
-#include <QtCore/qvector.h>
#include "private/qobject_p.h"
#define QCLASSINFO_DBUS_INTERFACE "D-Bus Interface"
@@ -103,11 +66,11 @@ 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; }
};
- typedef QVector<AdaptorData> AdaptorMap;
+ typedef QList<AdaptorData> AdaptorMap;
public: // methods
explicit QDBusAdaptorConnector(QObject *parent);
diff --git a/src/dbus/qdbusabstractinterface.cpp b/src/dbus/qdbusabstractinterface.cpp
index 87de784fc0..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.type()) != QMetaType::QVariant) {
+ if (type.id() != QMetaType::QVariant) {
expectedSignature = QDBusMetaType::typeToSignature(type);
- if (expectedSignature == 0) {
+ 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,53 +148,53 @@ 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;
}
QByteArray foundSignature;
- const char *foundType = 0;
+ 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
*/
@@ -597,7 +607,7 @@ bool QDBusAbstractInterface::callWithCallback(const QString &method,
QObject *receiver,
const char *slot)
{
- return callWithCallback(method, args, receiver, slot, 0);
+ return callWithCallback(method, args, receiver, slot, nullptr);
}
/*!
@@ -696,7 +706,7 @@ void QDBusAbstractInterface::internalPropSet(const char *propname, const QVarian
*/
/*!
- \fn QDBusAbstractInterface::call(const QString &message, Args&&...args)
+ \fn template <typename...Args> QDBusMessage QDBusAbstractInterface::call(const QString &method, Args&&...args)
Calls the method \a method on this interface and passes \a args to the method.
All \a args must be convertible to QVariant.
@@ -712,40 +722,20 @@ 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
*/
/*!
- \fn QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &message, Args&&...args)
+ \fn template <typename...Args> QDBusMessage QDBusAbstractInterface::call(QDBus::CallMode mode, const QString &method, Args&&...args)
\overload
@@ -768,66 +758,13 @@ 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
*/
/*!
- \fn QDBusAbstractInterface::asyncCall(const QString &message, Args&&...args)
+ \fn template <typename...Args> QDBusPendingCall QDBusAbstractInterface::asyncCall(const QString &method, Args&&...args)
Calls the method \a method on this interface and passes \a args to the method.
All \a args must be convertible to QVariant.
@@ -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 764bc24165..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,46 +23,45 @@
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 = 0;
- QVariant v(id, null);
+ QVariant v{type};
QDBusArgument arg(marshaller);
- QDBusMetaType::marshall(arg, v.userType(), v.constData());
- arg.d = 0;
+ QDBusMetaType::marshall(arg, v.metaType(), v.constData());
+ arg.d = nullptr;
// delete it
bool ok = marshaller->ok;
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
@@ -188,7 +152,9 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
integer and a string can be constructed using the \l
{qdbustypesystem.html}{Qt D-Bus type system}:
- \snippet code/src_qdbus_qdbusargument.cpp 0
+ \snippet code/src_qdbus_qdbusargument.cpp 0-0
+ \codeline
+ \snippet code/src_qdbus_qdbusargument.cpp 0-1
The type has to be registered with qDBusRegisterMetaType() before
it can be used with QDBusArgument. Therefore, somewhere in your
@@ -247,8 +213,8 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
\value VariantType The variant element (QDBusVariant)
- \value ArrayType An array element, usually represented by QList<T>
- or QVector<T>. Note: QByteArray and associative maps are not
+ \value ArrayType An array element, usually represented by QList<T>.
+ Note: QByteArray and associative maps are not
considered arrays, even if the D-Bus protocol transports them as such.
\value StructureType A custom type represented by a structure,
@@ -267,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
@@ -290,11 +256,11 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
QDBusArgument::QDBusArgument()
{
if (!qdbus_loadLibDBus()) {
- d = 0;
+ d = nullptr;
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
@@ -571,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();
@@ -590,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
{
@@ -709,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
{
@@ -869,7 +835,7 @@ void QDBusArgument::endStructure()
\snippet code/src_qdbus_qdbusargument.cpp 6
- If the type you want to marshall is a QList, QVector or any of the
+ If the type you want to marshall is a QList or any of the
Qt's \l {Container Classes} that take one template parameter,
you need not declare an \c{operator<<} function for it, since
Qt D-Bus provides generic templates to do the job of marshalling
@@ -878,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);
@@ -900,24 +866,25 @@ 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:
\snippet code/src_qdbus_qdbusargument.cpp 7
- If the type you want to marshall is a QMap or QHash, you need not
- declare an \c{operator<<} function for it, since Qt D-Bus provides
- generic templates to do the job of marshalling the data.
+ You usually don't need to provide an \c{operator<<} or \c{operator>>}
+ function for associative containers such as QHash or std::map,
+ since Qt D-Bus provides generic templates to do the job of marshalling
+ the data.
\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);
}
/*!
@@ -996,7 +963,7 @@ void QDBusArgument::endStructure() const
\snippet code/src_qdbus_qdbusargument.cpp 9
- If the type you want to demarshall is a QList, QVector or any of the
+ If the type you want to demarshall is a QList or any of the
Qt's \l {Container Classes} that take one template parameter, you
need not declare an \c{operator>>} function for it, since Qt D-Bus
provides generic templates to do the job of demarshalling the data.
@@ -1105,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.
@@ -1203,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 b7cd4c8989..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;
@@ -150,37 +118,35 @@ protected:
friend class QDBusArgumentPrivate;
mutable QDBusArgumentPrivate *d;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusArgument)
+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();
}
@@ -224,11 +190,11 @@ Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QLineF &li
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QLineF &line);
#endif
-template<template <typename> class Container, typename T>
+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)
@@ -237,7 +203,8 @@ inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<T> &list)
return arg;
}
-template<template <typename> class Container, typename T>
+template<template <typename> class Container, typename T,
+ typename = typename Container<T>::iterator>
inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &list)
{
arg.beginArray();
@@ -252,67 +219,51 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &l
return arg;
}
-// QList specializations
-template<typename T>
-inline QDBusArgument &operator<<(QDBusArgument &arg, const QList<T> &list)
+inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list)
{
- int id = qMetaTypeId<T>();
- arg.beginArray(id);
- typename QList<T>::ConstIterator it = list.constBegin();
- typename QList<T>::ConstIterator end = list.constEnd();
- for ( ; it != end; ++it)
- arg << *it;
+ arg.beginArray(QMetaType::fromType<QDBusVariant>());
+ for (const QVariant &value : list)
+ arg << QDBusVariant(value);
arg.endArray();
return arg;
}
-template<typename T>
-inline const QDBusArgument &operator>>(const QDBusArgument &arg, QList<T> &list)
+// Specializations for associative containers
+template <template <typename, typename> class Container, typename Key, typename T,
+ QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true>
+inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<Key, T> &map)
{
- arg.beginArray();
- list.clear();
- while (!arg.atEnd()) {
- T item;
- arg >> item;
- list.push_back(item);
+ arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>());
+ auto it = map.begin();
+ auto end = map.end();
+ for ( ; it != end; ++it) {
+ arg.beginMapEntry();
+ arg << it.key() << it.value();
+ arg.endMapEntry();
}
- arg.endArray();
-
- return arg;
-}
-
-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.endArray();
+ arg.endMap();
return arg;
}
-// QMap specializations
-template<typename Key, typename T>
-inline QDBusArgument &operator<<(QDBusArgument &arg, const QMap<Key, T> &map)
+template <template <typename, typename> class Container, typename Key, typename T,
+ 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);
- typename QMap<Key, T>::ConstIterator it = map.constBegin();
- typename QMap<Key, T>::ConstIterator end = map.constEnd();
+ arg.beginMap(QMetaType::fromType<Key>(), QMetaType::fromType<T>());
+ auto it = map.begin();
+ auto end = map.end();
for ( ; it != end; ++it) {
arg.beginMapEntry();
- arg << it.key() << it.value();
+ arg << it->first << it->second;
arg.endMapEntry();
}
arg.endMap();
return arg;
}
-template<typename Key, typename T>
-inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &map)
+template <template <typename, typename> class Container, typename Key, typename T,
+ QtPrivate::IfAssociativeIteratorHasKeyAndValue<typename Container<Key, T>::iterator> = true>
+inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<Key, T> &map)
{
arg.beginMap();
map.clear();
@@ -321,7 +272,7 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &m
T value;
arg.beginMapEntry();
arg >> key >> value;
- map.insertMulti(key, value);
+ map.insert(key, value);
arg.endMapEntry();
}
arg.endMap();
@@ -330,47 +281,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &m
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map)
{
- arg.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>());
- QVariantMap::ConstIterator it = map.constBegin();
- QVariantMap::ConstIterator end = map.constEnd();
- for ( ; it != end; ++it) {
- arg.beginMapEntry();
- arg << it.key() << QDBusVariant(it.value());
- arg.endMapEntry();
- }
- arg.endMap();
- return arg;
-}
-
-// QHash specializations
-template<typename Key, typename T>
-inline QDBusArgument &operator<<(QDBusArgument &arg, const QHash<Key, T> &map)
-{
- int kid = qMetaTypeId<Key>();
- int vid = qMetaTypeId<T>();
- arg.beginMap(kid, vid);
- typename QHash<Key, T>::ConstIterator it = map.constBegin();
- typename QHash<Key, T>::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() << it.value();
- arg.endMapEntry();
- }
- arg.endMap();
- return arg;
-}
-
-template<typename Key, typename T>
-inline const QDBusArgument &operator>>(const QDBusArgument &arg, QHash<Key, T> &map)
-{
- arg.beginMap();
- map.clear();
- while (!arg.atEnd()) {
- Key key;
- T value;
- arg.beginMapEntry();
- arg >> key >> value;
- map.insertMulti(key, value);
+ arg << key << QDBusVariant(value);
arg.endMapEntry();
}
arg.endMap();
@@ -379,12 +293,10 @@ inline const QDBusArgument &operator>>(const QDBusArgument &arg, QHash<Key, T> &
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantHash &map)
{
- arg.beginMap(QVariant::String, 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();
@@ -392,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;
@@ -401,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 d6f3230fd2..f6918b70b0 100644
--- a/src/dbus/qdbusconnection.cpp
+++ b/src/dbus/qdbusconnection.cpp
@@ -1,63 +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 <qvector.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>
@@ -70,238 +26,6 @@
QT_BEGIN_NAMESPACE
-#ifdef Q_OS_WIN
-static void preventDllUnload();
-#endif
-
-Q_GLOBAL_STATIC(QDBusConnectionManager, _q_manager)
-
-struct QDBusConnectionManager::ConnectionRequestData
-{
- enum RequestType {
- ConnectToStandardBus,
- ConnectToBusByAddress,
- ConnectToPeerByAddress
- } type;
-
- union {
- QDBusConnection::BusType busType;
- const QString *busAddress;
- };
- const QString *name;
-
- QDBusConnectionPrivate *result;
-
- bool suspendedDelivery;
-};
-
-QDBusConnectionPrivate *QDBusConnectionManager::busConnection(QDBusConnection::BusType type)
-{
- Q_STATIC_ASSERT(int(QDBusConnection::SessionBus) + int(QDBusConnection::SystemBus) == 1);
- Q_ASSERT(type == QDBusConnection::SessionBus || type == QDBusConnection::SystemBus);
-
- if (!qdbus_loadLibDBus())
- return 0;
-
- // 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, 0);
-}
-
-void QDBusConnectionManager::removeConnection(const QString &name)
-{
- QDBusConnectionPrivate *d = 0;
- 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 = 0;
- 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 = 0;
- }
- }
- 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
@@ -426,13 +150,17 @@ void QDBusConnectionManager::createServer(const QString &address, void *server)
*/
QDBusConnection::QDBusConnection(const QString &name)
{
- if (name.isEmpty() || _q_manager.isDestroyed()) {
- d = 0;
+ 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);
}
}
@@ -485,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()) {
- QDBusConnectionPrivate *d = 0;
+ 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));
}
/*!
@@ -505,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()) {
- QDBusConnectionPrivate *d = 0;
+ 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
@@ -520,11 +252,13 @@ QDBusConnection QDBusConnection::connectToBus(const QString &address,
QDBusConnection QDBusConnection::connectToPeer(const QString &address,
const QString &name)
{
- if (_q_manager.isDestroyed() || !qdbus_loadLibDBus()) {
- QDBusConnectionPrivate *d = 0;
+ 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));
}
/*!
@@ -537,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);
}
/*!
@@ -558,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);
}
/*!
@@ -616,7 +346,7 @@ bool QDBusConnection::callWithCallback(const QDBusMessage &message, QObject *rec
d->lastError = err;
return false;
}
- return d->sendWithReplyAsync(message, receiver, returnMethod, errorMethod, timeout) != 0;
+ return d->sendWithReplyAsync(message, receiver, returnMethod, errorMethod, timeout) != nullptr;
}
/*!
@@ -639,7 +369,7 @@ bool QDBusConnection::callWithCallback(const QDBusMessage &message, QObject *rec
bool QDBusConnection::callWithCallback(const QDBusMessage &message, QObject *receiver,
const char *returnMethod, int timeout) const
{
- return callWithCallback(message, receiver, returnMethod, 0, timeout);
+ return callWithCallback(message, receiver, returnMethod, nullptr, timeout);
}
/*!
@@ -701,14 +431,17 @@ 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
{
if (!d || !d->connection) {
- return QDBusPendingCall(0); // null pointer -> disconnected
+ return QDBusPendingCall(nullptr); // null pointer -> disconnected
}
- QDBusPendingCallPrivate *priv = d->sendWithReplyAsync(message, 0, 0, 0, timeout);
+ QDBusPendingCallPrivate *priv = d->sendWithReplyAsync(message, nullptr, nullptr, nullptr, timeout);
return QDBusPendingCall(priv);
}
@@ -909,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 = path.splitRef(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
@@ -954,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) {
@@ -965,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
@@ -1015,9 +749,9 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
Q_ASSERT_X(QDBusUtil::isValidObjectPath(path), "QDBusConnection::registeredObject",
"Invalid object path given");
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
- return 0;
+ return nullptr;
- auto pathComponents = path.splitRef(QLatin1Char('/'));
+ auto pathComponents = QStringView{path}.split(u'/');
if (pathComponents.constLast().isEmpty())
pathComponents.removeLast();
@@ -1027,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;
@@ -1037,10 +771,10 @@ 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 0;
+ return nullptr;
}
@@ -1052,7 +786,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
QDBusConnectionInterface *QDBusConnection::interface() const
{
if (!d || d->mode != QDBusConnectionPrivate::ClientMode)
- return 0;
+ return nullptr;
return d->busService;
}
@@ -1068,7 +802,7 @@ QDBusConnectionInterface *QDBusConnection::interface() const
*/
void *QDBusConnection::internalPointer() const
{
- return d ? d->connection : 0;
+ return d ? d->connection : nullptr;
}
/*!
@@ -1139,7 +873,7 @@ QString QDBusConnection::name() const
*/
QDBusConnection::ConnectionCapabilities QDBusConnection::connectionCapabilities() const
{
- return d ? d->capabilities : ConnectionCapabilities(0);
+ return d ? d->connectionCapabilities() : ConnectionCapabilities();
}
/*!
@@ -1183,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));
}
/*!
@@ -1197,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
@@ -1289,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 368f811602..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
@@ -77,6 +41,8 @@ class QDBusConnectionPrivate;
class Q_DBUS_EXPORT QDBusConnection
{
Q_GADGET
+ Q_MOC_INCLUDE(<QtDBus/qdbuspendingcall.h>)
+
public:
enum BusType { SessionBus, SystemBus, ActivationBus };
Q_ENUM(BusType)
@@ -136,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;
@@ -200,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);
@@ -212,7 +173,7 @@ private:
friend class QDBusConnectionPrivate;
QDBusConnectionPrivate *d;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusConnection)
+Q_DECLARE_SHARED(QDBusConnection)
Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::RegisterOptions)
Q_DECLARE_OPERATORS_FOR_FLAGS(QDBusConnection::VirtualObjectRegisterOptions)
diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h
index da67a6c5d4..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
@@ -59,17 +23,18 @@
#include <QtCore/qatomic.h>
#include <QtCore/qhash.h>
+#include <QtCore/qlist.h>
#include <QtCore/qobject.h>
#include <QtCore/qpointer.h>
#include <QtCore/qreadwritelock.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qvarlengtharray.h>
-#include <QtCore/qvector.h>
#include "qdbus_symbols_p.h"
#include <qdbusmessage.h>
#include <qdbusservicewatcher.h> // for the WatchMode enum
+Q_MOC_INCLUDE(<QtDBus/private/qdbuspendingcall_p.h>)
#ifndef QT_NO_DBUS
@@ -136,7 +101,7 @@ public:
QString service, path, signature;
QObject* obj;
int midx;
- QVector<int> params;
+ QList<QMetaType> params;
ArgMatchRules argumentMatch;
QByteArray matchRule;
};
@@ -148,15 +113,17 @@ public:
struct ObjectTreeNode
{
- typedef QVector<ObjectTreeNode> DataList;
+ 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<(const QStringRef &other) const
- { return QStringRef(&name) < other; }
+ inline bool operator<(QStringView other) const
+ { return name < other; }
inline bool isActive() const
{ return obj || !children.isEmpty(); }
@@ -166,21 +133,20 @@ public:
QObject *obj;
QDBusVirtualObject *treeNode;
};
- int flags;
+ QDBusConnection::RegisterOptions flags;
DataList children;
};
-public:
// typedefs
- typedef QMultiHash<int, Watcher> WatcherHash;
+ typedef QMultiHash<qintptr, Watcher> WatcherHash;
typedef QHash<int, DBusTimeout *> TimeoutHash;
- typedef QVector<QDBusMessage> PendingMessageList;
+ typedef QList<QDBusMessage> PendingMessageList;
typedef QMultiHash<QString, SignalHook> SignalHookHash;
typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
typedef QHash<QByteArray, int> MatchRefCountHash;
- typedef QVector<QDBusPendingCallPrivate*> PendingCallList;
+ typedef QList<QDBusPendingCallPrivate *> PendingCallList;
struct WatchedServiceData {
WatchedServiceData() : refcount(0) {}
@@ -192,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();
@@ -212,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);
@@ -247,6 +212,8 @@ public:
void postEventToThread(int action, QObject *target, QEvent *event);
+ void enableDispatchDelayed(QObject *context);
+
private:
void checkThread();
bool handleError(const QDBusErrorInternal &error);
@@ -258,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 QVector<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);
@@ -274,7 +242,13 @@ 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;
@@ -283,12 +257,10 @@ public slots:
// public slots
void setDispatchEnabled(bool enable);
void doDispatch();
- void socketRead(int);
- void socketWrite(int);
+ void socketRead(qintptr);
+ 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);
@@ -300,15 +272,16 @@ 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;
- QDBusConnection::ConnectionCapabilities capabilities;
+ QAtomicInt capabilities;
+ QDBusConnection::ConnectionCapabilities connectionCapabilities() const
+ {
+ return (QDBusConnection::ConnectionCapabilities)capabilities.loadRelaxed();
+ }
QString name; // this connection's name
QString baseService; // this connection's base service
QStringList serverConnectionNames;
@@ -341,19 +314,18 @@ public:
bool anonymousAuthenticationAllowed;
bool dispatchEnabled; // protected by the dispatch lock, not the main lock
+ bool isAuthenticated;
-public:
// static methods
- static int findSlot(QObject *obj, const QByteArray &normalizedName, QVector<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 QVector<int> &metaTypes,
+ int idx, const QList<QMetaType> &metaTypes,
const QDBusMessage &msg);
static void processFinishedCall(QDBusPendingCallPrivate *call);
@@ -366,9 +338,10 @@ public:
};
// in qdbusmisc.cpp
-extern int qDBusParametersForMethod(const QMetaMethod &mm, QVector<int> &metaTypes, QString &errorMsg);
-#endif // QT_BOOTSTRAPPED
-extern Q_DBUS_EXPORT int qDBusParametersForMethod(const QList<QByteArray> &parameters, QVector<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<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);
@@ -383,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 ac49683cee..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,43 +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
};
QT_END_NAMESPACE
diff --git a/src/dbus/qdbuscontext.cpp b/src/dbus/qdbuscontext.cpp
index 5b21c4fa74..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"
@@ -64,7 +28,7 @@ QDBusContextPrivate *QDBusContextPrivate::set(QObject *obj, QDBusContextPrivate
return old;
}
- return 0;
+ return nullptr;
}
/*!
@@ -104,7 +68,7 @@ QDBusContextPrivate *QDBusContextPrivate::set(QObject *obj, QDBusContextPrivate
Constructs an empty QDBusContext.
*/
QDBusContext::QDBusContext()
- : d_ptr(0)
+ : d_ptr(nullptr)
{
}
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 6befb33d61..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>
@@ -295,7 +259,7 @@ QVariant QDBusDemarshaller::toVariantInternal()
// qWarning("QDBusDemarshaller: Found unknown D-Bus type %d '%c'",
// q_dbus_message_iter_get_arg_type(&iterator),
// q_dbus_message_iter_get_arg_type(&iterator));
- char *ptr = 0;
+ char *ptr = nullptr;
ptr += q_dbus_message_iter_get_arg_type(&iterator);
q_dbus_message_iter_next(&iterator);
@@ -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 312bac71de..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;
@@ -132,7 +96,7 @@ private:
// so the following field cannot be used:
void *unused;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusError)
+Q_DECLARE_SHARED(QDBusError)
#ifndef QT_NO_DEBUG_STREAM
Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusError &);
@@ -140,7 +104,10 @@ 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
+QT_END_NAMESPACE
#endif // QT_NO_DBUS
#endif
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 6bb12ffe49..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);
@@ -79,13 +40,13 @@ public:
private:
void doCheck();
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusObjectPath)
+Q_DECLARE_SHARED(QDBusObjectPath)
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(); }
@@ -105,9 +66,12 @@ inline bool operator!=(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
inline bool operator<(const QDBusObjectPath &lhs, const QDBusObjectPath &rhs)
{ return lhs.path() < rhs.path(); }
-inline uint qHash(const QDBusObjectPath &objectPath, uint seed = 0)
+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);
@@ -132,13 +96,13 @@ public:
private:
void doCheck();
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusSignature)
+Q_DECLARE_SHARED(QDBusSignature)
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(); }
@@ -158,7 +122,7 @@ inline bool operator!=(const QDBusSignature &lhs, const QDBusSignature &rhs)
inline bool operator<(const QDBusSignature &lhs, const QDBusSignature &rhs)
{ return lhs.signature() < rhs.signature(); }
-inline uint qHash(const QDBusSignature &signature, uint seed = 0)
+inline size_t qHash(const QDBusSignature &signature, size_t seed = 0)
{ return qHash(signature.signature(), seed); }
class QDBusVariant
@@ -172,14 +136,14 @@ 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);
inline QVariant variant() const
{ return m_variant; }
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusVariant)
+Q_DECLARE_SHARED(QDBusVariant)
inline QDBusVariant::QDBusVariant(const QVariant &dBusVariant)
: m_variant(dBusVariant) { }
@@ -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 4c27a93382..89b9b2d17e 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)
{
@@ -127,10 +98,37 @@ void qdbusDefaultThreadDebug(int action, int condition, QDBusConnectionPrivate *
"condition unknown")
<< "in connection" << conn;
}
-qdbusThreadDebugFunc qdbusThreadDebug = 0;
+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,7 @@ 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");
+ int timerId = d->startTimer(std::chrono::milliseconds{q_dbus_timeout_get_interval(timeout)});
if (!timerId)
return false;
@@ -222,7 +219,7 @@ static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data)
watcher.write->setEnabled(q_dbus_watch_get_enabled(watch));
d->connect(watcher.write, &QSocketNotifier::activated, d, &QDBusConnectionPrivate::socketWrite);
}
- d->watchers.insertMulti(fd, watcher);
+ d->watchers.insert(fd, watcher);
return true;
}
@@ -280,7 +277,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();
@@ -289,11 +285,12 @@ static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchSt
static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data)
{
// ### We may want to separate the server from the QDBusConnectionPrivate
- Q_ASSERT(server); Q_UNUSED(server);
+ Q_ASSERT(server);
Q_ASSERT(connection);
Q_ASSERT(data);
- if (!QDBusConnectionManager::instance())
+ auto *manager = QDBusConnectionManager::instance();
+ if (!manager)
return;
// keep the connection alive
@@ -304,35 +301,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"
@@ -342,27 +339,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
@@ -373,34 +370,34 @@ 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);
- QStringRef pathComponent(&fullpath, start, end - start);
+ QStringView pathComponent = QStringView{fullpath}.mid(start, end - start);
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
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 = 0;
+ node = nullptr;
start = end + 1;
}
@@ -412,8 +409,8 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
result = *node;
else
// there really is no object here
- // we're just looking at an unused space in the QVector
- node = 0;
+ // we're just looking at an unused space in the QList
+ node = nullptr;
}
return node;
}
@@ -421,7 +418,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;
@@ -433,21 +430,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);
- QStringRef pathComponent(&fullpath, start, pos - start);
-
- const QObjectList children = obj->children();
+ auto pathComponent = QStringView{fullpath}.mid(start, pos - start);
// find a child with the proper name
- QObject *next = 0;
- QObjectList::ConstIterator it = children.constBegin();
- QObjectList::ConstIterator end = children.constEnd();
- for ( ; it != end; ++it)
- if ((*it)->objectName() == pathComponent) {
- next = *it;
+ QObject *next = nullptr;
+ for (QObject *child : std::as_const(obj->children())) {
+ if (child->objectName() == pathComponent) {
+ next = child;
break;
}
+ }
if (!next)
break;
@@ -458,13 +452,13 @@ static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *ro
}
// object not found
- return 0;
+ return nullptr;
}
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();
}
@@ -490,7 +484,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()
@@ -505,14 +503,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" {
@@ -525,7 +524,7 @@ qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data)
if (d->mode == QDBusConnectionPrivate::InvalidMode)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message, d->capabilities);
+ QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message, d->connectionCapabilities());
qDBusDebug() << d << "got message (signal):" << amsg;
return d->handleMessage(amsg) ?
@@ -561,15 +560,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;
@@ -589,28 +587,26 @@ 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 = 0;
- haystack.flags = 0;
+ haystack.obj = nullptr;
+ haystack.flags = {};
}
}
-static void huntAndUnregister(const QVector<QStringRef> &pathComponents, int i, QDBusConnection::UnregisterMode mode,
+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 = 0;
- node->flags = 0;
+ node->obj = nullptr;
+ node->flags = {};
if (mode == QDBusConnection::UnregisterTree) {
// clear the sub-tree as well
@@ -625,7 +621,7 @@ static void huntAndUnregister(const QVector<QStringRef> &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);
}
@@ -635,11 +631,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) {
@@ -660,15 +656,16 @@ static void huntAndEmit(DBusConnection *connection, DBusMessage *msg,
qDBusDebug() << QThread::currentThread() << "emitting signal at" << p;
DBusMessage *msg2 = q_dbus_message_copy(msg);
q_dbus_message_set_path(msg2, p);
- q_dbus_connection_send(connection, msg2, 0);
+ q_dbus_connection_send(connection, msg2, nullptr);
q_dbus_message_unref(msg2);
}
}
static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags,
- const QString &signature_, QVector<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);
@@ -685,18 +682,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;
@@ -727,18 +726,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) == 0)
+ if (returnType.isValid() && returnType.id() != QMetaType::Void && QDBusMetaType::typeToSignature(returnType) == nullptr)
continue;
bool ok = true;
- for (int j = i; ok && j < metaTypes.count(); ++j)
- if (QDBusMetaType::typeToSignature(metaTypes.at(i)) == 0)
+ 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) {
@@ -758,6 +757,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;
}
@@ -777,26 +783,25 @@ void QDBusConnectionPrivate::setDispatchEnabled(bool enable)
static QDBusCallDeliveryEvent * const DIRECT_DELIVERY = (QDBusCallDeliveryEvent *)1;
-QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target,
+QDBusCallDeliveryEvent *QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target,
QObject *object, int idx,
- const QVector<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)
- return 0; // too few arguments
+ 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>())
- return 0; // no match
+ 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
// prepare for the call
@@ -819,14 +824,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.
@@ -861,131 +867,131 @@ 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 QVector<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
- params.append(0);
+ params.append(nullptr);
// 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 = 0;
- 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 = 0;
- 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:
@@ -1014,31 +1020,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), capabilities(0), mode(InvalidMode), busService(0),
- connection(0),
- rootNode(QString(QLatin1Char('/'))),
+QDBusConnectionPrivate::QDBusConnectionPrivate()
+ : ref(1),
+ mode(InvalidMode),
+ busService(nullptr),
+ connection(nullptr),
+ rootNode(QStringLiteral("/")),
anonymousAuthenticationAllowed(false),
- dispatchEnabled(true)
+ dispatchEnabled(true),
+ isAuthenticated(false)
{
static const bool threads = q_dbus_threads_init_default();
- if (::isDebugging == -1)
- ::isDebugging = qEnvironmentVariableIntValue("QDBUS_DEBUG");
- Q_UNUSED(threads)
+ 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
@@ -1049,12 +1055,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
@@ -1068,9 +1070,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();
@@ -1087,23 +1090,19 @@ QDBusConnectionPrivate::~QDBusConnectionPrivate()
}
if (connection)
q_dbus_connection_unref(connection);
- connection = 0;
+ connection = nullptr;
} else if (lastMode == ServerMode) {
if (server)
q_dbus_server_unref(server);
- server = 0;
+ server = nullptr;
}
}
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);
@@ -1131,7 +1130,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
@@ -1140,18 +1143,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()
@@ -1180,7 +1177,7 @@ bool QDBusConnectionPrivate::handleError(const QDBusErrorInternal &error)
void QDBusConnectionPrivate::timerEvent(QTimerEvent *e)
{
{
- DBusTimeout *timeout = timeouts.value(e->timerId(), 0);
+ DBusTimeout *timeout = timeouts.value(e->timerId(), nullptr);
if (timeout)
q_dbus_timeout_handle(timeout);
}
@@ -1191,21 +1188,19 @@ 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) ;
}
}
-void QDBusConnectionPrivate::socketRead(int fd)
+void QDBusConnectionPrivate::socketRead(qintptr fd)
{
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
@@ -1216,10 +1211,13 @@ void QDBusConnectionPrivate::socketRead(int fd)
}
++it;
}
+ if ((mode == ClientMode || mode == PeerMode) && !isAuthenticated
+ && q_dbus_connection_get_is_authenticated(connection))
+ handleAuthentication();
doDispatch();
}
-void QDBusConnectionPrivate::socketWrite(int fd)
+void QDBusConnectionPrivate::socketWrite(qintptr fd)
{
WatcherHash::ConstIterator it = watchers.constFind(fd);
while (it != watchers.constEnd() && it.key() == fd) {
@@ -1230,6 +1228,9 @@ void QDBusConnectionPrivate::socketWrite(int fd)
}
++it;
}
+ if ((mode == ClientMode || mode == PeerMode) && !isAuthenticated
+ && q_dbus_connection_get_is_authenticated(connection))
+ handleAuthentication();
}
void QDBusConnectionPrivate::objectDestroyed(QObject *obj)
@@ -1267,15 +1268,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, capabilities, &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;
}
@@ -1290,46 +1292,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,
- QVector<int> &params)
+int QDBusConnectionPrivate::findSlot(QObject *obj, const QByteArray &normalizedName,
+ 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;
@@ -1349,15 +1351,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);
@@ -1369,21 +1371,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())));
}
}
@@ -1394,7 +1395,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);
@@ -1410,15 +1411,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;
@@ -1452,7 +1453,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) {
@@ -1464,25 +1465,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;
@@ -1531,7 +1529,7 @@ void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg)
// user code, if necessary.
ObjectTreeNode result;
int usedLength;
- QThread *objThread = 0;
+ QThread *objThread = nullptr;
QSemaphore sem;
bool semWait;
@@ -1553,8 +1551,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;
}
@@ -1652,8 +1650,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);
@@ -1670,17 +1668,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
}
@@ -1692,10 +1690,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)
@@ -1718,7 +1716,7 @@ void QDBusConnectionPrivate::setServer(QDBusServer *object, DBusServer *s, const
qDBusAddWatch,
qDBusRemoveWatch,
qDBusToggleWatch,
- this, 0);
+ this, nullptr);
//qDebug() << "watch_functions_set" << watch_functions_set;
Q_UNUSED(watch_functions_set);
@@ -1726,13 +1724,13 @@ void QDBusConnectionPrivate::setServer(QDBusServer *object, DBusServer *s, const
qDBusAddTimeout,
qDBusRemoveTimeout,
qDBusToggleTimeout,
- this, 0);
+ this, nullptr);
//qDebug() << "time_functions_set" << time_functions_set;
Q_UNUSED(time_functions_set);
- q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0);
+ q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, nullptr);
- dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, 0);
+ dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, nullptr);
//qDebug() << "data_set" << data_set;
Q_UNUSED(data_set);
}
@@ -1752,27 +1750,27 @@ void QDBusConnectionPrivate::setPeer(DBusConnection *c, const QDBusErrorInternal
qDBusAddWatch,
qDBusRemoveWatch,
qDBusToggleWatch,
- this, 0);
+ this, nullptr);
q_dbus_connection_set_timeout_functions(connection,
qDBusAddTimeout,
qDBusRemoveTimeout,
qDBusToggleTimeout,
- this, 0);
- q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0);
+ this, nullptr);
+ q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, nullptr);
q_dbus_connection_add_filter(connection,
qDBusSignalFilter,
- this, 0);
+ this, nullptr);
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 = 0;
+ QDBusConnection::ConnectionCapabilities result;
typedef dbus_bool_t (*can_send_type_t)(DBusConnection *, int);
- static can_send_type_t can_send_type = 0;
+ static can_send_type_t can_send_type = nullptr;
#if defined(QT_LINKED_LIBDBUS)
# if DBUS_VERSION-0 >= 0x010400
@@ -1792,6 +1790,12 @@ static QDBusConnection::ConnectionCapabilities connectionCapabilies(DBusConnecti
return result;
}
+void QDBusConnectionPrivate::handleAuthentication()
+{
+ capabilities.storeRelaxed(::connectionCapabilities(connection));
+ isAuthenticated = true;
+}
+
void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusErrorInternal &error)
{
mode = ClientMode;
@@ -1805,15 +1809,16 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError
const char *service = q_dbus_bus_get_unique_name(connection);
Q_ASSERT(service);
baseService = QString::fromUtf8(service);
- capabilities = connectionCapabilies(connection);
+ // bus connections are already authenticated here because q_dbus_bus_register() has been called
+ handleAuthentication();
q_dbus_connection_set_exit_on_disconnect(connection, false);
q_dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch,
- qDBusToggleWatch, this, 0);
+ qDBusToggleWatch, this, nullptr);
q_dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout,
- qDBusToggleTimeout, this, 0);
- q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0);
- q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0);
+ qDBusToggleTimeout, this, nullptr);
+ q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, nullptr);
+ q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, nullptr);
// Initialize the hooks for the NameAcquired and NameLost signals
// we don't use connectSignal here because we don't need the rules to be sent to the bus
@@ -1822,31 +1827,31 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError
hook.service = QDBusUtil::dbusService();
hook.path.clear(); // no matching
hook.obj = this;
- hook.params << QMetaType::Void << QVariant::String; // 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 << QVariant::String << QVariant::String << QVariant::String;
+ 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"{
@@ -1854,7 +1859,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);
}
}
@@ -1874,7 +1878,7 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call)
if (q_dbus_pending_call_get_completed(call->pending)) {
// decode the message
DBusMessage *reply = q_dbus_pending_call_steal_reply(call->pending);
- msg = QDBusMessagePrivate::fromDBusMessage(reply, connection->capabilities);
+ msg = QDBusMessagePrivate::fromDBusMessage(reply, connection->connectionCapabilities());
q_dbus_message_unref(reply);
} else {
msg = QDBusMessage::createError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage());
@@ -1904,7 +1908,7 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call)
if (call->pending) {
q_dbus_pending_call_unref(call->pending);
- call->pending = 0;
+ call->pending = nullptr;
}
// Are there any watchers?
@@ -1928,25 +1932,30 @@ bool QDBusConnectionPrivate::send(const QDBusMessage& message)
// through the d_ptr->localReply link
QDBusError error;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
+ DBusMessage *msg =
+ 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;
}
@@ -1966,20 +1975,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) {
@@ -1993,7 +2002,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");
@@ -2002,7 +2014,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;
@@ -2027,10 +2042,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()));
}
}
@@ -2040,29 +2058,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, 0, 0, 0, timeout);
+ 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
@@ -2082,9 +2089,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()));
}
@@ -2092,12 +2099,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
@@ -2120,6 +2130,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);
@@ -2142,12 +2153,15 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
}
QDBusError error;
- DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error);
+ 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);
@@ -2161,7 +2175,7 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *message, int timeout)
{
QDBusError error;
- DBusPendingCall *pending = 0;
+ DBusPendingCall *pending = nullptr;
DBusMessage *msg = static_cast<DBusMessage *>(message);
bool isNoReply = !pcall;
Q_ASSERT(isNoReply == !!q_dbus_message_get_no_reply(msg));
@@ -2175,7 +2189,7 @@ void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *
q_dbus_message_unref(msg);
pcall->pending = pending;
- q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, 0);
+ q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, nullptr);
// DBus won't notify us when a peer disconnects or server terminates so we need to track these ourselves
if (mode == QDBusConnectionPrivate::PeerMode || mode == QDBusConnectionPrivate::ClientMode)
@@ -2218,15 +2232,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:
@@ -2245,7 +2274,7 @@ bool QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook
}
}
- signalHooks.insertMulti(key, hook);
+ signalHooks.insert(key, hook);
connect(hook.obj, &QObject::destroyed, this, &QDBusConnectionPrivate::objectDestroyed,
Qt::ConnectionType(Qt::BlockingQueuedConnection | Qt::UniqueConnection));
@@ -2261,7 +2290,7 @@ bool QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook
if (connection) {
if (mode != QDBusConnectionPrivate::PeerMode) {
qDBusDebug() << this << "Adding rule:" << hook.matchRule;
- q_dbus_bus_add_match(connection, hook.matchRule, NULL);
+ q_dbus_bus_add_match(connection, hook.matchRule, nullptr);
// Successfully connected the signal
// Do we need to watch for this name?
@@ -2274,7 +2303,7 @@ bool QDBusConnectionPrivate::addSignalHook(const QString &key, const SignalHook
q_dbus_bus_add_match(connection,
buildMatchRule(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(),
QDBusUtil::nameOwnerChanged(), rules, QString()),
- NULL);
+ nullptr);
data.owner = getNameOwnerNoCache(hook.service);
qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:"
<< data.owner << ")";
@@ -2308,15 +2337,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);
@@ -2347,7 +2391,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;
@@ -2362,7 +2408,7 @@ QDBusConnectionPrivate::removeSignalHookNoLock(SignalHookHash::Iterator it)
if (connection && erase) {
if (mode != QDBusConnectionPrivate::PeerMode) {
qDBusDebug() << this << "Removing rule:" << hook.matchRule;
- q_dbus_bus_remove_match(connection, hook.matchRule, NULL);
+ q_dbus_bus_remove_match(connection, hook.matchRule, nullptr);
// Successfully disconnected the signal
// Were we watching for this name?
@@ -2375,7 +2421,7 @@ QDBusConnectionPrivate::removeSignalHookNoLock(SignalHookHash::Iterator it)
q_dbus_bus_remove_match(connection,
buildMatchRule(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(),
QDBusUtil::nameOwnerChanged(), rules, QString()),
- NULL);
+ nullptr);
}
}
}
@@ -2401,8 +2447,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));
}
}
@@ -2410,12 +2456,12 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
{
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
- QVector<QStringRef> pathComponents;
+ QList<QStringView> pathComponents;
int i;
- if (path == QLatin1String("/")) {
+ if (path == "/"_L1) {
i = 0;
} else {
- pathComponents = path.splitRef(QLatin1Char('/'));
+ pathComponents = QStringView{path}.split(u'/');
i = 1;
}
@@ -2435,12 +2481,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,
@@ -2456,12 +2506,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)
@@ -2560,10 +2614,15 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa
// service must be a unique connection name
if (!interface.isEmpty()) {
QDBusReadLocker locker(FindMetaObject1Action, this);
- QDBusMetaObject *mo = cachedMetaObjects.value(interface, 0);
+ QDBusMetaObject *mo = cachedMetaObjects.value(interface, nullptr);
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,
@@ -2575,23 +2634,23 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa
// it doesn't exist yet, we have to create it
QDBusWriteLocker locker(FindMetaObject2Action, this);
- QDBusMetaObject *mo = 0;
+ QDBusMetaObject *mo = nullptr;
if (!interface.isEmpty())
- mo = cachedMetaObjects.value(interface, 0);
+ mo = cachedMetaObjects.value(interface, nullptr);
if (mo)
// maybe it got created when we switched from read to write lock
return mo;
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 {
error = QDBusError(reply);
lastError = error;
if (reply.type() != QDBusMessage::ErrorMessage || error.type() != QDBusError::UnknownMethod)
- return 0; // error
+ return nullptr; // error
}
// release the lock and return
@@ -2641,6 +2700,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 87db910d25..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;
- QVector<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,21 +85,21 @@ class QDBusCallDeliveryEvent: public QAbstractMetaCallEvent
{
public:
QDBusCallDeliveryEvent(const QDBusConnection &c, int id, QObject *sender,
- const QDBusMessage &msg, const QVector<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;
- QVector<int> metaTypes;
+ QList<QMetaType> metaTypes;
int id;
- int flags;
};
class QDBusActivateObjectEvent: public QAbstractMetaCallEvent
@@ -147,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 4dd02e8c76..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,67 +15,69 @@
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 QVariant::Bool:
+ case QMetaType::Bool:
*reinterpret_cast<bool *>(to) = arg.toBool();
return;
case QMetaType::UChar:
- *reinterpret_cast<uchar *>(to) = arg.value<uchar>();
+ *reinterpret_cast<uchar *>(to) = qvariant_cast<uchar>(arg);
return;
case QMetaType::Short:
- *reinterpret_cast<short *>(to) = arg.value<short>();
+ *reinterpret_cast<short *>(to) = qvariant_cast<short>(arg);
return;
case QMetaType::UShort:
- *reinterpret_cast<ushort *>(to) = arg.value<ushort>();
+ *reinterpret_cast<ushort *>(to) = qvariant_cast<ushort>(arg);
return;
- case QVariant::Int:
+ case QMetaType::Int:
*reinterpret_cast<int *>(to) = arg.toInt();
return;
- case QVariant::UInt:
+ case QMetaType::UInt:
*reinterpret_cast<uint *>(to) = arg.toUInt();
return;
- case QVariant::LongLong:
+ case QMetaType::LongLong:
*reinterpret_cast<qlonglong *>(to) = arg.toLongLong();
return;
- case QVariant::ULongLong:
+ case QMetaType::ULongLong:
*reinterpret_cast<qulonglong *>(to) = arg.toULongLong();
return;
- case QVariant::Double:
+ case QMetaType::Double:
*reinterpret_cast<double *>(to) = arg.toDouble();
return;
- case QVariant::String:
+ case QMetaType::QString:
*reinterpret_cast<QString *>(to) = arg.toString();
return;
- case QVariant::ByteArray:
+ case QMetaType::QByteArray:
*reinterpret_cast<QByteArray *>(to) = arg.toByteArray();
return;
- case QVariant::StringList:
+ case QMetaType::QStringList:
*reinterpret_cast<QStringList *>(to) = arg.toStringList();
return;
}
- if (id == QDBusMetaTypeId::variant()) {
- *reinterpret_cast<QDBusVariant *>(to) = arg.value<QDBusVariant>();
+ if (id == QDBusMetaTypeId::variant().id()) {
+ *reinterpret_cast<QDBusVariant *>(to) = qvariant_cast<QDBusVariant>(arg);
return;
- } else if (id == QDBusMetaTypeId::objectpath()) {
- *reinterpret_cast<QDBusObjectPath *>(to) = arg.value<QDBusObjectPath>();
+ } else if (id == QDBusMetaTypeId::objectpath().id()) {
+ *reinterpret_cast<QDBusObjectPath *>(to) = qvariant_cast<QDBusObjectPath>(arg);
return;
- } else if (id == QDBusMetaTypeId::signature()) {
- *reinterpret_cast<QDBusSignature *>(to) = arg.value<QDBusSignature>();
+ } 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?
@@ -136,20 +102,20 @@ static void copyArgument(void *to, int id, const QVariant &arg)
}
// is it the same signature?
- QDBusArgument dbarg = arg.value<QDBusArgument>();
- if (dbarg.currentSignature() != QLatin1String(userSignature)) {
+ QDBusArgument dbarg = qvariant_cast<QDBusArgument>(arg);
+ 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,
const QString &iface, const QDBusConnection &con)
- : QDBusAbstractInterfacePrivate(serv, p, iface, con, true), metaObject(0)
+ : QDBusAbstractInterfacePrivate(serv, p, iface, con, true), metaObject(nullptr)
{
// QDBusAbstractInterfacePrivate's constructor checked the parameters for us
if (connection.isConnected()) {
@@ -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);
}
}
}
@@ -204,7 +170,9 @@ QDBusInterfacePrivate::~QDBusInterfacePrivate()
interface \a interface on object at path \a path on service \a
service, using the given \a connection. If \a interface is an
empty string, the object created will refer to the merging of all
- interfaces found in that object.
+ interfaces found by introspecting that object. Otherwise if
+ \a interface is not empty, the QDBusInterface object will be cached
+ to speedup further creations of the same interface.
\a parent is passed to the base class constructor.
@@ -243,7 +211,7 @@ const QMetaObject *QDBusInterface::metaObject() const
*/
void *QDBusInterface::qt_metacast(const char *_clname)
{
- if (!_clname) return 0;
+ if (!_clname) return nullptr;
if (!strcmp(_clname, "QDBusInterface"))
return static_cast<void*>(const_cast<QDBusInterface*>(this));
if (d_func()->interface.toLatin1() == _clname)
@@ -287,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 edee4fc1e5..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 = 0;
- 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 e60900b162..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
@@ -52,12 +16,11 @@
//
#include <QtDBus/private/qtdbusglobal_p.h>
-#include <QtCore/qstring.h>
-#include <QtCore/qvector.h>
-#include <QtCore/qstringlist.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>
#ifndef QT_NO_DBUS
@@ -74,10 +37,11 @@ public:
struct Interface;
struct Object;
struct ObjectTree;
+ struct Annotation;
// typedefs
- typedef QMap<QString, QString> Annotations;
- typedef QVector<Argument> Arguments;
+ typedef QMap<QString, Annotation> Annotations;
+ typedef QList<Argument> Arguments;
typedef QMultiMap<QString, Method> Methods;
typedef QMultiMap<QString, Signal> Signals;
typedef QMap<QString, Property> Properties;
@@ -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 8e0b3e4598..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,15 +165,15 @@ inline bool QDBusMarshaller::append(const QDBusVariant &arg)
}
const QVariant &value = arg.variant();
- int id = value.userType();
- if (id == QVariant::Invalid) {
+ 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;
}
QByteArray tmpSignature;
- const char *signature = 0;
+ const char *signature = nullptr;
if (id == QDBusMetaTypeId::argument()) {
// take the signature from the QDBusArgument object we're marshalling
tmpSignature =
@@ -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,60 +206,48 @@ 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
}
inline QDBusMarshaller *QDBusMarshaller::beginStructure()
{
- return beginCommon(DBUS_TYPE_STRUCT, 0);
+ 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;
}
@@ -301,7 +261,7 @@ inline QDBusMarshaller *QDBusMarshaller::beginMap(int kid, int vid)
inline QDBusMarshaller *QDBusMarshaller::beginMapEntry()
{
- return beginCommon(DBUS_TYPE_DICT_ENTRY, 0);
+ return beginCommon(DBUS_TYPE_DICT_ENTRY, nullptr);
}
void QDBusMarshaller::open(QDBusMarshaller &sub, int code, const char *signature)
@@ -383,10 +343,10 @@ void QDBusMarshaller::error(const QString &msg)
bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
{
- int id = arg.userType();
- if (id == QVariant::Invalid) {
+ 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,12 +441,12 @@ bool QDBusMarshaller::appendVariantInternal(const QVariant &arg)
case DBUS_TYPE_ARRAY:
// could be many things
// find out what kind of array it is
- switch (arg.type()) {
- case QVariant::StringList:
+ switch (arg.metaType().id()) {
+ case QMetaType::QStringList:
append( arg.toStringList() );
return true;
- case QVariant::ByteArray:
+ case QMetaType::QByteArray:
append( arg.toByteArray() );
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;
@@ -572,7 +528,7 @@ bool QDBusMarshaller::appendCrossMarshalling(QDBusDemarshaller *demarshaller)
QDBusMarshaller mrecursed(capabilities); // create on the stack makes it autoclose
QByteArray subSignature;
- const char *sig = 0;
+ const char *sig = nullptr;
if (code == DBUS_TYPE_VARIANT || code == DBUS_TYPE_ARRAY) {
subSignature = drecursed->currentSignature().toLatin1();
if (!subSignature.isEmpty())
diff --git a/src/dbus/qdbusmessage.cpp b/src/dbus/qdbusmessage.cpp
index 3e8f2eaf3f..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,34 +20,53 @@
QT_BEGIN_NAMESPACE
-Q_STATIC_ASSERT(QDBusMessage::InvalidMessage == DBUS_MESSAGE_TYPE_INVALID);
-Q_STATIC_ASSERT(QDBusMessage::MethodCallMessage == DBUS_MESSAGE_TYPE_METHOD_CALL);
-Q_STATIC_ASSERT(QDBusMessage::ReplyMessage == DBUS_MESSAGE_TYPE_METHOD_RETURN);
-Q_STATIC_ASSERT(QDBusMessage::ErrorMessage == DBUS_MESSAGE_TYPE_ERROR);
-Q_STATIC_ASSERT(QDBusMessage::SignalMessage == DBUS_MESSAGE_TYPE_SIGNAL);
+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);
+static_assert(QDBusMessage::ErrorMessage == DBUS_MESSAGE_TYPE_ERROR);
+static_assert(QDBusMessage::SignalMessage == DBUS_MESSAGE_TYPE_SIGNAL);
static inline const char *data(const QByteArray &arr)
{
- return arr.isEmpty() ? 0 : arr.constData();
+ return arr.isEmpty() ? nullptr : arr.constData();
}
QDBusMessagePrivate::QDBusMessagePrivate()
- : msg(0), reply(0), localReply(0), 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,11 +95,11 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
QDBusError *error)
{
if (!qdbus_loadLibDBus()) {
- *error = QDBusError(QDBusError::Failed, QLatin1String("Could not open lidbus-1 library"));
- return 0;
+ *error = QDBusError(QDBusError::Failed, "Could not open lidbus-1 library"_L1);
+ return nullptr;
}
- DBusMessage *msg = 0;
+ DBusMessage *msg = nullptr;
const QDBusMessagePrivate *d_ptr = message.d_ptr;
switch (d_ptr->type) {
@@ -127,13 +110,13 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
// only service and interface can be empty -> path and name must not be empty
if (!d_ptr->parametersValidated) {
if (!QDBusUtil::checkBusName(d_ptr->service, QDBusUtil::EmptyAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkObjectPath(d_ptr->path, QDBusUtil::EmptyNotAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkInterfaceName(d_ptr->interface, QDBusUtil::EmptyAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method"))
- return 0;
+ return nullptr;
}
msg = q_dbus_message_new_method_call(data(d_ptr->service.toUtf8()), d_ptr->path.toUtf8(),
@@ -145,34 +128,34 @@ 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:
// error name can't be empty
if (!d_ptr->parametersValidated
&& !QDBusUtil::checkErrorName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error))
- return 0;
+ return nullptr;
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:
// only the service name can be empty here
if (!d_ptr->parametersValidated) {
if (!QDBusUtil::checkBusName(d_ptr->service, QDBusUtil::EmptyAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkObjectPath(d_ptr->path, QDBusUtil::EmptyNotAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkInterfaceName(d_ptr->interface, QDBusUtil::EmptyAllowed, error))
- return 0;
+ return nullptr;
if (!QDBusUtil::checkMemberName(d_ptr->name, QDBusUtil::EmptyNotAllowed, error, "method"))
- return 0;
+ return nullptr;
}
msg = q_dbus_message_new_signal(d_ptr->path.toUtf8(), d_ptr->interface.toUtf8(),
@@ -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,8 +183,8 @@ DBusMessage *QDBusMessagePrivate::toDBusMessage(const QDBusMessage &message, QDB
// not ok;
q_dbus_message_unref(msg);
- *error = QDBusError(QDBusError::Failed, QLatin1String("Marshalling failed: ") + marshaller.errorString);
- return 0;
+ *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,18 +253,16 @@ 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 != QVariant::StringList && id != QVariant::ByteArray &&
- 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
QDBusError error;
- DBusMessage *message = toDBusMessage(asSent, conn.capabilities, &error);
+ DBusMessage *message = toDBusMessage(asSent, conn.connectionCapabilities(), &error);
if (!message) {
// failed to marshall, so it's a call error
return QDBusMessage::createError(error);
@@ -290,14 +270,14 @@ QDBusMessage QDBusMessagePrivate::makeLocal(const QDBusConnectionPrivate &conn,
q_dbus_message_set_sender(message, conn.baseService.toUtf8());
- QDBusMessage retval = fromDBusMessage(message, conn.capabilities);
+ QDBusMessage retval = fromDBusMessage(message, conn.connectionCapabilities());
retval.d_ptr->localMessage = true;
q_dbus_message_unref(message);
if (retval.d_ptr->service.isEmpty())
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 41845317c4..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,10 +84,11 @@ public:
QDBusMessage &operator<<(const QVariant &arg);
private:
+ explicit QDBusMessage(QDBusMessagePrivate &dd);
friend class QDBusMessagePrivate;
QDBusMessagePrivate *d_ptr;
};
-Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QDBusMessage)
+Q_DECLARE_SHARED(QDBusMessage)
#ifndef QT_NO_DEBUG_STREAM
Q_DBUS_EXPORT QDebug operator<<(QDebug, const QDBusMessage &);
@@ -137,8 +96,10 @@ 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
#endif // QT_NO_DBUS
#endif
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 806cf7b415..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
{
@@ -127,27 +94,37 @@ QDBusMetaObjectGenerator::QDBusMetaObjectGenerator(const QString &interfaceName,
}
}
-static int registerComplexDBusType(const char *typeName)
+static int registerComplexDBusType(const QByteArray &typeName)
{
- struct QDBusRawTypeHandler {
- static void destruct(void *)
- {
- qFatal("Cannot destruct placeholder type QDBusRawType");
- }
+ struct QDBusRawTypeHandler : QtPrivate::QMetaTypeInterface
+ {
+ const QByteArray name;
+ QDBusRawTypeHandler(const QByteArray &name)
+ : QtPrivate::QMetaTypeInterface {
+ 0, sizeof(void *), sizeof(void *), QMetaType::RelocatableType, 0, nullptr,
+ name.constData(),
+ nullptr, nullptr, nullptr, nullptr,
+ nullptr, nullptr, nullptr,
+ nullptr, nullptr, nullptr
+ },
+ name(name)
+ {}
+ };
- static void *construct(void *, const void *)
+ Q_CONSTINIT static QBasicMutex mutex;
+ Q_CONSTINIT static struct Hash : QHash<QByteArray, QMetaType>
+ {
+ ~Hash()
{
- qFatal("Cannot construct placeholder type QDBusRawType");
- return 0;
+ for (QMetaType entry : *this)
+ QMetaType::unregisterMetaType(std::move(entry));
}
- };
-
- return QMetaType::registerNormalizedType(typeName,
- QDBusRawTypeHandler::destruct,
- QDBusRawTypeHandler::construct,
- sizeof(void *),
- QMetaType::MovableType,
- 0);
+ } hash;
+ QMutexLocker lock(&mutex);
+ QMetaType &metatype = hash[typeName];
+ if (!metatype.isValid())
+ metatype = QMetaType(new QDBusRawTypeHandler(typeName));
+ return metatype.id();
}
Q_DBUS_EXPORT bool qt_dbus_metaobject_skip_annotations = false;
@@ -158,20 +135,21 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
const char *direction, int id)
{
Type result;
- result.id = QVariant::Invalid;
+ result.id = QMetaType::UnknownType;
- int type = QDBusMetaType::signatureToType(signature);
- if (type == QVariant::Invalid && !qt_dbus_metaobject_skip_annotations) {
+ 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()) {
@@ -179,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 == QVariant::Invalid || 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() + ">*";
@@ -197,25 +176,28 @@ QDBusMetaObjectGenerator::findType(const QByteArray &signature,
}
result.name = typeName;
- } else if (type == QVariant::Invalid) {
+ } else if (type == QMetaType::UnknownType) {
// this case is used only by the qdbus command-line tool
// invalid, let's create an impossible type that contains the signature
if (signature == "av") {
result.name = "QVariantList";
- type = QVariant::List;
+ type = QMetaType::QVariantList;
} else if (signature == "a{sv}") {
result.name = "QVariantMap";
- type = QVariant::Map;
+ type = QMetaType::QVariantMap;
} 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;
@@ -229,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();
@@ -242,11 +221,11 @@ 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);
- if (type.id == QVariant::Invalid) {
+ if (type.id == QMetaType::UnknownType) {
ok = false;
break;
}
@@ -261,11 +240,11 @@ 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);
- if (type.id == QVariant::Invalid) {
+ if (type.id == QMetaType::UnknownType) {
ok = false;
break;
}
@@ -287,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
@@ -305,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();
@@ -318,11 +294,11 @@ 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);
- if (type.id == QVariant::Invalid) {
+ if (type.id == QMetaType::UnknownType) {
ok = false;
break;
}
@@ -338,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(')');
@@ -352,13 +328,10 @@ 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 == QVariant::Invalid)
+ if (type.id == QMetaType::UnknownType)
continue;
QByteArray name = p.name.toLatin1();
@@ -381,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();
- sum += m.inputTypes.size() + qMax(1, m.outputTypes.size());
- }
+ qsizetype sum = 0;
+ for (const Method &m : map)
+ sum += m.inputTypes.size() + qMax(qsizetype(1), m.outputTypes.size());
return sum;
}
@@ -398,74 +368,89 @@ 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());
- Q_STATIC_ASSERT_X(QMetaObjectPrivate::OutputRevision == 8, "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 * 5 + 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 * 3;
- header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty;
-
- int data_size = idata.size() +
- (header->methodCount * (5+intsPerMethod)) + methodParametersDataSize +
- (header->propertyCount * (3+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();
+ header->propertyDBusData = int(header->propertyData + header->propertyCount
+ * QMetaObjectPrivate::IntsPerProperty);
+ header->methodDBusData = int(header->propertyDBusData + header->propertyCount * intsPerProperty);
+
+ qsizetype data_size = idata.size() +
+ (header->methodCount * (QMetaObjectPrivate::IntsPerMethod+intsPerMethod)) + methodParametersDataSize +
+ (header->propertyCount * (QMetaObjectPrivate::IntsPerProperty+intsPerProperty));
+
+ // 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 * 5;
- 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
+ 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;
+ }
+ }
+ QMetaType *metaTypes = new QMetaType[totalMetaTypeCount];
+ int propertyId = 0;
+
// add each method:
- 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(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;
idata[offset++] = parametersOffset;
idata[offset++] = strings.enter(mm.tag);
idata[offset++] = mm.flags;
+ 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
@@ -483,34 +468,35 @@ 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);
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();
}
}
- Q_ASSERT(offset == header->methodData + header->methodCount * 5);
+ Q_ASSERT(offset == header->methodData + header->methodCount * QMetaObjectPrivate::IntsPerMethod);
Q_ASSERT(parametersOffset == header->propertyData);
Q_ASSERT(signatureOffset == header->methodDBusData + header->methodCount * intsPerMethod);
Q_ASSERT(typeidOffset == idata.size());
@@ -519,19 +505,21 @@ 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;
+ idata[offset++] = -1; // notify index
+ idata[offset++] = 0; // revision
idata[signatureOffset++] = strings.enter(mp.signature);
idata[signatureOffset++] = mp.type;
+
+ 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);
@@ -540,15 +528,16 @@ 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;
- obj->d.relatedMetaObjects = 0;
- obj->d.static_metacall = 0;
- obj->d.extradata = 0;
- obj->d.stringdata = reinterpret_cast<const QByteArrayData *>(string_data);
+ obj->d.relatedMetaObjects = nullptr;
+ obj->d.static_metacall = nullptr;
+ obj->d.extradata = nullptr;
+ obj->d.stringdata = reinterpret_cast<const uint *>(string_data);
obj->d.superdata = &QDBusAbstractInterface::staticMetaObject;
+ obj->d.metaTypes = reinterpret_cast<QtPrivate::QMetaTypeInterface *const *>(metaTypes);
}
#if 0
@@ -556,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;
@@ -587,7 +576,7 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
error = QDBusError();
QDBusIntrospection::Interfaces parsed = QDBusIntrospection::parseInterfaces(xml);
- QDBusMetaObject *we = 0;
+ QDBusMetaObject *we = nullptr;
QDBusIntrospection::Interfaces::ConstIterator it = parsed.constBegin();
QDBusIntrospection::Interfaces::ConstIterator end = parsed.constEnd();
for ( ; it != end; ++it) {
@@ -595,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)
@@ -621,7 +610,7 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
if (parsed.isEmpty()) {
// object didn't return introspection
we = new QDBusMetaObject;
- QDBusMetaObjectGenerator generator(interface, 0);
+ QDBusMetaObjectGenerator generator(interface, nullptr);
generator.write(we);
we->cached = false;
return we;
@@ -631,13 +620,13 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
QDBusIntrospection::Interface merged = *it.value().constData();
for (++it; it != end; ++it) {
- merged.annotations.unite(it.value()->annotations);
+ merged.annotations.insert(it.value()->annotations);
merged.methods.unite(it.value()->methods);
merged.signals_.unite(it.value()->signals_);
- merged.properties.unite(it.value()->properties);
+ merged.properties.insert(it.value()->properties);
}
- merged.name = QLatin1String("local.Merged");
+ merged.name = "local.Merged"_L1;
merged.introspection.clear();
we = new QDBusMetaObject;
@@ -649,9 +638,8 @@ QDBusMetaObject *QDBusMetaObject::createMetaObject(const QString &interface, con
// mark as an error
error = QDBusError(QDBusError::UnknownInterface,
- QLatin1String("Interface '%1' was not found")
- .arg(interface));
- return 0;
+ "Interface '%1' was not found"_L1.arg(interface));
+ return nullptr;
}
QDBusMetaObject::QDBusMetaObject()
@@ -670,7 +658,7 @@ const int *QDBusMetaObject::inputTypesForMethod(int id) const
int handle = priv(d.data)->methodDBusData + id*intsPerMethod;
return reinterpret_cast<const int*>(d.data + d.data[handle]);
}
- return 0;
+ return nullptr;
}
const int *QDBusMetaObject::outputTypesForMethod(int id) const
@@ -680,7 +668,7 @@ const int *QDBusMetaObject::outputTypesForMethod(int id) const
int handle = priv(d.data)->methodDBusData + id*intsPerMethod;
return reinterpret_cast<const int*>(d.data + d.data[handle + 1]);
}
- return 0;
+ return nullptr;
}
int QDBusMetaObject::propertyMetaType(int id) const
diff --git a/src/dbus/qdbusmetaobject_p.h b/src/dbus/qdbusmetaobject_p.h
index 89fccf9046..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
@@ -77,6 +41,7 @@ struct Q_DBUS_EXPORT QDBusMetaObject: public QMetaObject
{
delete [] reinterpret_cast<const char *>(d.stringdata);
delete [] d.data;
+ delete [] reinterpret_cast<const QMetaType *>(d.metaTypes);
}
// methods (slots & signals):
diff --git a/src/dbus/qdbusmetatype.cpp b/src/dbus/qdbusmetatype.cpp
index 58ce4f8930..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"
@@ -45,8 +9,13 @@
#include <qbytearray.h>
#include <qglobal.h>
+#include <qlist.h>
#include <qreadwritelock.h>
-#include <qvector.h>
+#include <qdatetime.h>
+#include <qrect.h>
+#include <qsize.h>
+#include <qpoint.h>
+#include <qline.h>
#include "qdbusargument_p.h"
#include "qdbusutil_p.h"
@@ -67,7 +36,7 @@ QT_BEGIN_NAMESPACE
class QDBusCustomTypeInfo
{
public:
- QDBusCustomTypeInfo() : signature(), marshall(0), demarshall(0)
+ QDBusCustomTypeInfo() : signature(), marshall(nullptr), demarshall(nullptr)
{ }
// Suggestion:
@@ -77,48 +46,38 @@ public:
QDBusMetaType::DemarshallFunction demarshall;
};
-template<typename T>
-inline static void registerHelper(T * = 0)
-{
- 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,29 +87,25 @@ 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> >();
-
- qDBusRegisterMetaType<QVector<bool> >();
- qDBusRegisterMetaType<QVector<short> >();
- qDBusRegisterMetaType<QVector<ushort> >();
- qDBusRegisterMetaType<QVector<int> >();
- qDBusRegisterMetaType<QVector<uint> >();
- qDBusRegisterMetaType<QVector<qlonglong> >();
- qDBusRegisterMetaType<QVector<qulonglong> >();
- qDBusRegisterMetaType<QVector<double> >();
- qDBusRegisterMetaType<QVector<QDBusObjectPath> >();
- qDBusRegisterMetaType<QVector<QDBusSignature> >();
- qDBusRegisterMetaType<QVector<QDBusUnixFileDescriptor> >();
#endif
initialized.storeRelaxed(true);
}
}
-Q_GLOBAL_STATIC(QVector<QDBusCustomTypeInfo>, customTypes)
-Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
+struct QDBusCustomTypes
+{
+ QReadWriteLock lock;
+ QHash<int, QDBusCustomTypeInfo> hash;
+};
+
+Q_GLOBAL_STATIC(QDBusCustomTypes, customTypes)
/*!
\class QDBusMetaType
@@ -174,7 +129,7 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
*/
/*!
- \fn int qDBusRegisterMetaType()
+ \fn template<typename T> QMetaType qDBusRegisterMetaType()
\relates QDBusArgument
\threadsafe
\since 4.2
@@ -187,7 +142,9 @@ Q_GLOBAL_STATIC(QReadWriteLock, customTypesLock)
Q_DECLARE_METATYPE() macro, and then registered as in the
following example:
- \snippet code/src_qdbus_qdbusmetatype.cpp 0
+ \snippet code/src_qdbus_qdbusmetatype.cpp 0-0
+ \codeline
+ \snippet code/src_qdbus_qdbusmetatype.cpp 0-1
If \c{T} isn't one of
Qt's \l{container classes}, the \c{operator<<} and
@@ -223,43 +180,51 @@ 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)
{
- QVector<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());
- QVector<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 = 0; // make gcc happy
+ mf = nullptr; // make gcc happy
return false;
} else
mf = info.marshall;
@@ -271,24 +236,30 @@ 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());
- QVector<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 = 0; // make gcc happy
+ df = nullptr; // make gcc happy
return false;
} else
df = info.demarshall;
@@ -314,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 QVariant::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 QVariant::Int;
+ return QMetaType(QMetaType::Int);
case DBUS_TYPE_UINT32:
- return QVariant::UInt;
+ return QMetaType(QMetaType::UInt);
case DBUS_TYPE_INT64:
- return QVariant::LongLong;
+ return QMetaType(QMetaType::LongLong);
case DBUS_TYPE_UINT64:
- return QVariant::ULongLong;
+ return QMetaType(QMetaType::ULongLong);
case DBUS_TYPE_DOUBLE:
- return QVariant::Double;
+ return QMetaType(QMetaType::Double);
case DBUS_TYPE_STRING:
- return QVariant::String;
+ return QMetaType(QMetaType::QString);
case DBUS_TYPE_OBJECT_PATH:
return QDBusMetaTypeId::objectpath();
@@ -369,28 +340,48 @@ int QDBusMetaType::signatureToType(const char *signature)
case DBUS_TYPE_ARRAY: // special case
switch (signature[1]) {
case DBUS_TYPE_BYTE:
- return QVariant::ByteArray;
+ return QMetaType(QMetaType::QByteArray);
case DBUS_TYPE_STRING:
- return QVariant::StringList;
+ return QMetaType(QMetaType::QStringList);
case DBUS_TYPE_VARIANT:
- return QVariant::List;
+ 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
@@ -399,17 +390,17 @@ 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;
- case QVariant::Bool:
+ case QMetaType::Bool:
return DBUS_TYPE_BOOLEAN_AS_STRING;
case QMetaType::Short:
@@ -418,29 +409,29 @@ const char *QDBusMetaType::typeToSignature(int type)
case QMetaType::UShort:
return DBUS_TYPE_UINT16_AS_STRING;
- case QVariant::Int:
+ case QMetaType::Int:
return DBUS_TYPE_INT32_AS_STRING;
- case QVariant::UInt:
+ case QMetaType::UInt:
return DBUS_TYPE_UINT32_AS_STRING;
- case QVariant::LongLong:
+ case QMetaType::LongLong:
return DBUS_TYPE_INT64_AS_STRING;
- case QVariant::ULongLong:
+ case QMetaType::ULongLong:
return DBUS_TYPE_UINT64_AS_STRING;
- case QVariant::Double:
+ case QMetaType::Double:
return DBUS_TYPE_DOUBLE_AS_STRING;
- case QVariant::String:
+ case QMetaType::QString:
return DBUS_TYPE_STRING_AS_STRING;
- case QVariant::StringList:
+ case QMetaType::QStringList:
return DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_STRING_AS_STRING; // as
- case QVariant::ByteArray:
+ case QMetaType::QByteArray:
return DBUS_TYPE_ARRAY_AS_STRING
DBUS_TYPE_BYTE_AS_STRING; // ay
}
@@ -456,19 +447,23 @@ const char *QDBusMetaType::typeToSignature(int type)
return DBUS_TYPE_UNIX_FD_AS_STRING;
// try the database
- QVector<QDBusCustomTypeInfo> *ct = customTypes();
+ auto *ct = customTypes();
+ if (!ct)
+ return nullptr;
+
{
- QReadLocker locker(customTypesLock());
- if (type >= ct->size())
- return 0; // 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;
if (!info.marshall)
- return 0; // type not registered with us
+ return nullptr; // type not registered with us
}
// call to user code to construct the signature type
@@ -479,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 eb8f61c783..635258c86d 100644
--- a/src/dbus/qdbusmisc.cpp
+++ b/src/dbus/qdbusmisc.cpp
@@ -1,60 +1,27 @@
-/****************************************************************************
-**
-** 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>
#ifndef QT_BOOTSTRAPPED
#include <QtCore/qcoreapplication.h>
-#include <QtCore/qvariant.h>
+#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"
#include "qdbusabstractadaptor_p.h" // for QCLASSINFO_DBUS_*
#endif
-#include <QtCore/qvector.h>
#include "qdbusmetatype_p.h"
#ifndef QT_NO_DBUS
QT_BEGIN_NAMESPACE
+using namespace Qt::StringLiterals;
+
bool qDBusCheckAsyncTag(const char *tag)
{
static const char noReplyTag[] = "Q_NOREPLY";
@@ -62,7 +29,7 @@ bool qDBusCheckAsyncTag(const char *tag)
return false;
const char *p = strstr(tag, noReplyTag);
- if (p != NULL &&
+ if (p != nullptr &&
(p == tag || *(p-1) == ' ') &&
(p[sizeof noReplyTag - 1] == '\0' || p[sizeof noReplyTag - 1] == ' '))
return true;
@@ -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 = organizationDomain.splitRef(QLatin1Char('.'), QString::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,52 +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, QVector<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, QVector<int>& metaTypes, QString &errorMsg)
+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) {
- const 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) == 0)
+ } 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
}
- int id = QMetaType::type(type);
+ if (type.startsWith("QVector<"))
+ type = "QList<" + type.mid(sizeof("QVector<") - 1);
+
+ 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") {
@@ -188,15 +187,15 @@ int qDBusParametersForMethod(const QList<QByteArray> &parameterTypes, QVector<in
}
#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) == 0) {
- errorMsg = QLatin1String("Type not registered with QtDBus in parameter list: ") + QLatin1String(type);
+ else if (QDBusMetaType::typeToSignature(id) == nullptr) {
+ 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 8e604d5a77..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
@@ -82,8 +48,7 @@ QT_BEGIN_NAMESPACE
provide a method of detaching the copies (since they refer
to the same pending call)
- \sa QDBusPendingReply, QDBusPendingCallWatcher,
- QDBusAbstractInterface::asyncCall()
+ \sa QDBusPendingReply, QDBusPendingCallWatcher
*/
/*!
@@ -115,7 +80,7 @@ QT_BEGIN_NAMESPACE
(one string and one QByteArray), QDBusPendingReply::isError() will
return true.
- \sa QDBusPendingReply, QDBusAbstractInterface::asyncCall()
+ \sa QDBusPendingReply
*/
/*!
@@ -129,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()
@@ -158,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;
@@ -182,14 +150,14 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb
if (metaTypes.at(count) == QDBusMetaTypeId::message())
--count;
- setMetaTypes(count, count ? metaTypes.constData() + 1 : 0);
+ setMetaTypes(count, count ? metaTypes.constData() + 1 : nullptr);
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;
}
@@ -197,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;
}
@@ -222,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));
@@ -241,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.
@@ -259,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd)
if (dd) {
bool r = dd->ref.deref();
Q_ASSERT(r);
- Q_UNUSED(r);
}
}
@@ -311,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
@@ -341,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.
@@ -358,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.
@@ -375,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
@@ -396,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
@@ -446,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()
*/
@@ -469,10 +454,10 @@ QDBusPendingCall QDBusPendingCall::fromError(const QDBusError &error)
*/
QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg)
{
- QDBusPendingCallPrivate *d = 0;
+ QDBusPendingCallPrivate *d = nullptr;
if (msg.type() == QDBusMessage::ErrorMessage ||
msg.type() == QDBusMessage::ReplyMessage) {
- d = new QDBusPendingCallPrivate(QDBusMessage(), 0);
+ d = new QDBusPendingCallPrivate(QDBusMessage(), nullptr);
d->replyMessage = msg;
d->ref.storeRelaxed(1);
}
@@ -480,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);
@@ -509,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);
@@ -547,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 e1f6240f3e..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
@@ -54,10 +18,10 @@
#define QDBUSPENDINGCALL_P_H
#include <QtDBus/private/qtdbusglobal_p.h>
-#include <qshareddata.h>
-#include <qpointer.h>
-#include <qvector.h>
+#include <qlist.h>
#include <qmutex.h>
+#include <qpointer.h>
+#include <qshareddata.h>
#include <qwaitcondition.h>
#include "qdbusmessage.h"
@@ -82,7 +46,7 @@ public:
// for the callback mechanism (see setReplyCallback and QDBusConnectionPrivate::sendWithReplyAsync)
QPointer<QObject> receiver;
- QVector<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 ec49bafb60..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
@@ -91,12 +54,11 @@
QDBusPendingCallWatcher objects, which emit signals when the reply
arrives.
- \sa QDBusPendingCallWatcher, QDBusReply,
- QDBusAbstractInterface::asyncCall()
+ \sa QDBusPendingCallWatcher, QDBusReply
*/
/*!
- \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
@@ -104,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
@@ -113,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
@@ -121,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
@@ -131,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
@@ -141,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
@@ -151,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
@@ -173,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
@@ -185,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
@@ -200,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>().
@@ -213,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>().
@@ -231,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()
@@ -246,27 +208,27 @@
\sa QDBusPendingCallWatcher::waitForFinished()
*/
-QDBusPendingReplyData::QDBusPendingReplyData()
- : QDBusPendingCall(0) // initialize base class empty
+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(), 0); // drops the reference to the old one
+ 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();
@@ -276,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 1d7e60ad7f..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
{
- Q_STATIC_ASSERT_X(Index >= 0 && Index < Count, "Index out of bounds");
+ 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 cf1a70508c..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
@@ -75,6 +41,13 @@ QT_BEGIN_NAMESPACE
*/
/*!
+ \fn template<typename T> QDBusReply<T>::QDBusReply(const QDBusReply &other)
+ \since 5.15
+
+ Constructs a copy of \a other.
+*/
+
+/*!
\fn template<typename T> QDBusReply<T>::QDBusReply(const QDBusMessage &reply)
Automatically construct a QDBusReply object from the reply message \a reply, extracting the
first return value from it if it is a success reply.
@@ -168,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.
@@ -196,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 *receivedType = 0;
+ 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);
}
}
@@ -228,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 869687ac85..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
@@ -64,9 +28,10 @@ public:
{
*this = reply;
}
+ 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;
@@ -130,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;
@@ -171,6 +135,8 @@ public:
return *this;
}
+ inline QDBusReply(const QDBusReply &) = default;
+
inline QDBusReply& operator=(const QDBusReply& other)
{
m_error = other.m_error;
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 73d1db2680..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
@@ -135,7 +101,7 @@ QExplicitlySharedDataPointer<QDBusUnixFileDescriptorPrivate>::~QExplicitlyShared
\sa fileDescriptor(), isValid()
*/
QDBusUnixFileDescriptor::QDBusUnixFileDescriptor()
- : d(0)
+ : d(nullptr)
{
}
@@ -153,7 +119,7 @@ QDBusUnixFileDescriptor::QDBusUnixFileDescriptor()
\sa setFileDescriptor(), fileDescriptor()
*/
QDBusUnixFileDescriptor::QDBusUnixFileDescriptor(int fileDescriptor)
- : d(0)
+ : d(nullptr)
{
if (fileDescriptor != -1)
setFileDescriptor(fileDescriptor);
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 dc94897ac4..827418c487 100644
--- a/src/dbus/qdbusutil.cpp
+++ b/src/dbus/qdbusutil.cpp
@@ -1,48 +1,13 @@
-/****************************************************************************
-**
-** 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"
#include "qdbus_symbols_p.h"
+#include <QtCore/qlist.h>
#include <QtCore/qstringlist.h>
-#include <QtCore/qvector.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 == QVariant::StringList) {
- out += QLatin1Char('{');
+ if (argType == QMetaType::QStringList) {
+ 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('}');
- } else if (argType == QVariant::ByteArray) {
- out += QLatin1Char('{');
+ out += u'}';
+ } else if (argType == QMetaType::QByteArray) {
+ 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('}');
- } else if (argType == QVariant::List) {
- out += QLatin1Char('{');
+ out += u'}';
+ } else if (argType == QMetaType::QVariantList) {
+ 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(QVariant::String)) {
- 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,14 +206,29 @@ 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) != NULL;
+ return c != DBUS_TYPE_INVALID && strchr(basicTypes, c) != nullptr;
}
static bool isFixedType(int c)
{
- return c != DBUS_TYPE_INVALID && strchr(fixedTypes, c) != NULL;
+ return c != DBUS_TYPE_INVALID && strchr(fixedTypes, c) != nullptr;
}
// Returns a pointer to one-past-end of this type if it's valid;
@@ -260,10 +237,10 @@ static const char *validateSingleType(const char *signature)
{
char c = *signature;
if (c == DBUS_TYPE_INVALID)
- return 0;
+ return nullptr;
// is it one of the one-letter types?
- if (strchr(oneLetterTypes, c) != NULL)
+ if (strchr(oneLetterTypes, c) != nullptr)
return signature + 1;
// is it an array?
@@ -277,9 +254,9 @@ static const char *validateSingleType(const char *signature)
// and a free value
c = *++signature;
if (!isBasicType(c))
- return 0;
+ return nullptr;
signature = validateSingleType(signature + 1);
- return signature && *signature == DBUS_DICT_ENTRY_END_CHAR ? signature + 1 : 0;
+ return signature && *signature == DBUS_DICT_ENTRY_END_CHAR ? signature + 1 : nullptr;
}
return validateSingleType(signature);
@@ -291,14 +268,14 @@ static const char *validateSingleType(const char *signature)
while (true) {
signature = validateSingleType(signature);
if (!signature)
- return 0;
+ return nullptr;
if (*signature == DBUS_STRUCT_END_CHAR)
return signature + 1;
}
}
// invalid/unknown type
- return 0;
+ return nullptr;
}
/*!
@@ -331,16 +308,16 @@ namespace QDBusUtil
/*!
\internal
- \fn bool isValidPartOfObjectPath(const QStringRef &part)
+ \fn bool isValidPartOfObjectPath(QStringView part)
See isValidObjectPath
*/
- bool isValidPartOfObjectPath(const QStringRef &part)
+ bool isValidPartOfObjectPath(QStringView part)
{
if (part.isEmpty())
return false; // can't be valid if it's empty
- const QChar *c = part.unicode();
- for (int i = 0; i < part.length(); ++i)
+ const QChar *c = part.data();
+ 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,14 +339,14 @@ 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 = ifaceName.splitRef(QLatin1Char('.'));
- if (parts.count() < 2)
+ const auto parts = QStringView{ifaceName}.split(u'.');
+ if (parts.size() < 2)
return false; // at least two parts
- for (const QStringRef &part : parts)
+ for (auto part : parts)
if (!isValidMemberName(part))
return false;
@@ -384,28 +354,28 @@ namespace QDBusUtil
}
/*!
- \fn bool isValidUniqueConnectionName(const QStringRef &connName)
+ \fn bool isValidUniqueConnectionName(QStringView connName)
Returns \c true if \a connName is a valid unique connection name.
Unique connection names start with a colon (":") and are followed by a list of dot-separated
components composed of ASCII letters, digits, the hyphen or the underscore ("_") character.
*/
- bool isValidUniqueConnectionName(const QStringRef &connName)
+ 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 (const QStringRef &part : parts) {
+ for (QStringView part : parts) {
if (part.isEmpty())
return false;
- const QChar* c = part.unicode();
- for (int j = 0; j < part.length(); ++j)
+ const QChar* c = part.data();
+ 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,24 +400,21 @@ 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 = busName.splitRef(QLatin1Char('.'));
- if (parts.count() < 1)
- return false;
-
- for (const QStringRef &part : parts) {
+ const auto parts = QStringView{busName}.split(u'.');
+ for (QStringView part : parts) {
if (part.isEmpty())
return false;
- const QChar *c = part.unicode();
+ 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;
}
@@ -462,32 +423,26 @@ namespace QDBusUtil
}
/*!
- \fn bool isValidMemberName(const QStringRef &memberName)
+ \fn bool isValidMemberName(QStringView memberName)
Returns \c true if \a memberName is a valid member name. A valid member name does not exceed
255 characters in length, is not empty, is composed only of ASCII letters, digits and
underscores, but does not start with a digit.
*/
- bool isValidMemberName(const QStringRef &memberName)
+ 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.unicode();
+ 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,23 +460,22 @@ 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 = path.midRef(1).split(QLatin1Char('/'));
- for (const QStringRef &part : parts)
+ 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 0814cc8050..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,23 +27,20 @@
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);
- Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QStringRef &busName);
- inline bool isValidUniqueConnectionName(const QString &busName) { return isValidUniqueConnectionName(QStringRef(&busName)); }
+ Q_DBUS_EXPORT bool isValidUniqueConnectionName(QStringView busName);
Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
- Q_DBUS_EXPORT bool isValidMemberName(const QStringRef &memberName);
- inline bool isValidMemberName(const QString &memberName) { return isValidMemberName(QStringRef(&memberName)); }
+ Q_DBUS_EXPORT bool isValidMemberName(QStringView memberName);
Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
- Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QStringRef &path);
- inline bool isValidPartOfObjectPath(const QString &path) { return isValidPartOfObjectPath(QStringRef(&path)); }
+ Q_DBUS_EXPORT bool isValidPartOfObjectPath(QStringView path);
Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
@@ -102,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;
}
@@ -114,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;
}
@@ -126,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;
}
@@ -139,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;
}
@@ -152,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;
}
@@ -169,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 c6b3b90508..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) == QVariant::Invalid) {
- 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) == QVariant::Invalid)
- 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();
- QVector<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) == QVariant::Invalid) {
- 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('.'),
- QString::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 33eaee1ed1..a4c4446862 100644
--- a/src/dbus/qt_attribution.json
+++ b/src/dbus/qt_attribution.json
@@ -7,12 +7,12 @@
"Description": "D-Bus is a message bus system, a simple way for applications to talk to one another.",
"Homepage": "https://www.freedesktop.org/wiki/Software/dbus/",
"Version": "Minimal supported is 1.2, compatible up to ...",
- "Version": "dbus-1.12.12",
+ "Version": "dbus-1.13.12",
"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 633cc352bb..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,28 +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
-#include <QtCore/qvector.h>
-#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