summaryrefslogtreecommitdiffstats
path: root/src/dbus/qdbusargument.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dbus/qdbusargument.cpp')
-rw-r--r--src/dbus/qdbusargument.cpp123
1 files changed, 54 insertions, 69 deletions
diff --git a/src/dbus/qdbusargument.cpp b/src/dbus/qdbusargument.cpp
index 2c6be1994c..99e60244da 100644
--- a/src/dbus/qdbusargument.cpp
+++ b/src/dbus/qdbusargument.cpp
@@ -1,55 +1,20 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtDBus module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qdbusargument.h"
#include "qdbusargument_p.h"
#include <qatomic.h>
#include <qbytearray.h>
+#include <qdatetime.h>
+#include <qline.h>
#include <qlist.h>
#include <qmap.h>
#include <qstring.h>
#include <qstringlist.h>
-#include <qvariant.h>
-#include <qdatetime.h>
#include <qrect.h>
-#include <qline.h>
+#include <qtimezone.h>
+#include <qvariant.h>
#include "qdbusmetatype_p.h"
#include "qdbusutil_p.h"
@@ -58,26 +23,27 @@
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QDBusArgument)
+
QDBusArgumentPrivate::~QDBusArgumentPrivate()
{
if (message)
q_dbus_message_unref(message);
}
-QByteArray QDBusArgumentPrivate::createSignature(int id)
+QByteArray QDBusArgumentPrivate::createSignature(QMetaType type)
{
if (!qdbus_loadLibDBus())
return "";
QByteArray signature;
- QDBusMarshaller *marshaller = new QDBusMarshaller(0);
+ QDBusMarshaller *marshaller = new QDBusMarshaller;
marshaller->ba = &signature;
// run it
- void *null = nullptr;
- QVariant v(id, null);
+ QVariant v{type};
QDBusArgument arg(marshaller);
- QDBusMetaType::marshall(arg, v.userType(), v.constData());
+ QDBusMetaType::marshall(arg, v.metaType(), v.constData());
arg.d = nullptr;
// delete it
@@ -85,19 +51,17 @@ QByteArray QDBusArgumentPrivate::createSignature(int id)
delete marshaller;
if (signature.isEmpty() || !ok || !QDBusUtil::isValidSingleSignature(QString::fromLatin1(signature))) {
- qWarning("QDBusMarshaller: type `%s' produces invalid D-BUS signature `%s' "
+ qWarning("QDBusMarshaller: type '%s' produces invalid D-Bus signature '%s' "
"(Did you forget to call beginStructure() ?)",
- QMetaType::typeName(id),
- signature.isEmpty() ? "<empty>" : signature.constData());
+ type.name(), signature.isEmpty() ? "<empty>" : signature.constData());
return "";
} else if ((signature.at(0) != DBUS_TYPE_ARRAY && signature.at(0) != DBUS_STRUCT_BEGIN_CHAR) ||
(signature.at(0) == DBUS_TYPE_ARRAY && (signature.at(1) == DBUS_TYPE_BYTE ||
signature.at(1) == DBUS_TYPE_STRING))) {
- qWarning("QDBusMarshaller: type `%s' attempts to redefine basic D-BUS type '%s' (%s) "
+ qWarning("QDBusMarshaller: type '%s' attempts to redefine basic D-Bus type '%s' (%s) "
"(Did you forget to call beginStructure() ?)",
- QMetaType::typeName(id),
- signature.constData(),
- QMetaType::typeName(QDBusMetaType::signatureToType(signature)));
+ type.name(), signature.constData(),
+ QDBusMetaType::signatureToMetaType(signature).name());
return "";
}
return signature;
@@ -107,7 +71,7 @@ bool QDBusArgumentPrivate::checkWrite(QDBusArgumentPrivate *&d)
{
if (!d)
return false;
- if (d->direction == Marshalling) {
+ if (d->direction == Direction::Marshalling) {
if (!d->marshaller()->ok)
return false;
@@ -135,7 +99,7 @@ bool QDBusArgumentPrivate::checkRead(QDBusArgumentPrivate *d)
{
if (!d)
return false;
- if (d->direction == Demarshalling)
+ if (d->direction == Direction::Demarshalling)
return true;
#ifdef QT_DEBUG
@@ -269,7 +233,7 @@ bool QDBusArgumentPrivate::checkReadAndDetach(QDBusArgumentPrivate *&d)
*/
/*!
- \fn template<typename T> T qdbus_cast(const QDBusArgument &arg, T*)
+ \fn template<typename T> T qdbus_cast(const QDBusArgument &arg)
\relates QDBusArgument
\since 4.2
@@ -296,7 +260,7 @@ QDBusArgument::QDBusArgument()
return;
}
- QDBusMarshaller *dd = new QDBusMarshaller(0);
+ QDBusMarshaller *dd = new QDBusMarshaller;
d = dd;
// create a new message with any type, we won't sent it anyways
@@ -573,7 +537,7 @@ QString QDBusArgument::currentSignature() const
{
if (!d)
return QString();
- if (d->direction == QDBusArgumentPrivate::Demarshalling)
+ if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling)
return d->demarshaller()->currentSignature();
else
return d->marshaller()->currentSignature();
@@ -592,14 +556,14 @@ QDBusArgument::ElementType QDBusArgument::currentType() const
{
if (!d)
return UnknownType;
- if (d->direction == QDBusArgumentPrivate::Demarshalling)
+ if (d->direction == QDBusArgumentPrivate::Direction::Demarshalling)
return d->demarshaller()->currentType();
return UnknownType;
}
/*!
- Extracts one D-BUS primitive argument of type \c{BYTE} from the
- D-BUS stream and puts it into \a arg.
+ Extracts one D-Bus primitive argument of type \c{BYTE} from the
+ D-Bus stream and puts it into \a arg.
*/
const QDBusArgument &QDBusArgument::operator>>(uchar &arg) const
{
@@ -711,7 +675,7 @@ const QDBusArgument &QDBusArgument::operator>>(qulonglong &arg) const
/*!
\overload
Extracts one D-Bus primitive argument of type \c{DOUBLE}
- (double-precision floating pount) from the D-Bus stream.
+ (double-precision floating point) from the D-Bus stream.
*/
const QDBusArgument &QDBusArgument::operator>>(double &arg) const
{
@@ -880,7 +844,7 @@ void QDBusArgument::endStructure()
\sa endArray(), beginStructure(), beginMap()
*/
-void QDBusArgument::beginArray(int id)
+void QDBusArgument::beginArray(QMetaType id)
{
if (QDBusArgumentPrivate::checkWrite(d))
d = d->marshaller()->beginArray(id);
@@ -902,8 +866,8 @@ void QDBusArgument::endArray()
Opens a new D-Bus map suitable for
appending elements. Maps are containers that associate one entry
(the key) to another (the value), such as Qt's QMap or QHash. The
- ids of the map's key and value meta types must be passed in \a kid
- and \a vid respectively.
+ ids of the map's key and value meta types must be passed in \a keyMetaType
+ and \a valueMetaType respectively.
This function is used usually in \c{operator<<} streaming
operators, as in the following example:
@@ -917,10 +881,10 @@ void QDBusArgument::endArray()
\sa endMap(), beginStructure(), beginArray(), beginMapEntry()
*/
-void QDBusArgument::beginMap(int kid, int vid)
+void QDBusArgument::beginMap(QMetaType keyMetaType, QMetaType valueMetaType)
{
if (QDBusArgumentPrivate::checkWrite(d))
- d = d->marshaller()->beginMap(kid, vid);
+ d = d->marshaller()->beginMap(keyMetaType, valueMetaType);
}
/*!
@@ -1108,7 +1072,7 @@ bool QDBusArgument::atEnd() const
argument (for example, by calling asVariant() in it).
For example, if the current argument is an INT32, this function
- will return a QVariant with an argument of type QVariant::Int. For
+ will return a QVariant with an argument of type QMetaType::Int. For
an array of INT32, it will return a QVariant containing a
QDBusArgument.
@@ -1206,12 +1170,33 @@ const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt)
a >> date >> time >> timespec;
a.endStructure();
- dt = QDateTime(date, time, Qt::TimeSpec(timespec));
+ switch (Qt::TimeSpec(timespec)) {
+ case Qt::TimeZone:
+ qWarning("Restoring zoned date-time without zone info");
+ Q_FALLTHROUGH(); // Treat as local time.
+ case Qt::LocalTime:
+ dt = QDateTime(date, time);
+ break;
+ case Qt::OffsetFromUTC:
+ qWarning("Restoring date-time without its offset");
+ Q_FALLTHROUGH(); // Use zero offset
+ case Qt::UTC:
+ dt = QDateTime(date, time, QTimeZone::UTC);
+ break;
+ }
return a;
}
QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt)
{
+ // TODO: Only viable for UTC and LocalTime
+ if (Q_UNLIKELY(dt.timeSpec() != Qt::UTC && dt.timeSpec() != Qt::LocalTime)) {
+ qWarning() << "Serializing a date-time with unsupported time-spec" << dt.timeSpec();
+ // Coerce to a supported timespec. When a time-zone is the current
+ // system zone, local time is suitable; so map all time-zones to local,
+ // plain offsets to UTC.
+ return a << (dt.timeSpec() == Qt::OffsetFromUTC ? dt.toUTC() : dt.toLocalTime());
+ }
a.beginStructure();
a << dt.date() << dt.time() << int(dt.timeSpec());
a.endStructure();