Use QStringLiteral where applicable in QtDBus
Move to qdbusutil_p.h the string constants that are used often and in multiple places; use QStringLiteral in qdbusintegrator.cpp for the strings that are used often. Change-Id: I8e1325b9ba015bda91bf01c42175d8032ea32f62 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
This commit is contained in:
parent
635f95846e
commit
26edd5a3b1
@ -88,7 +88,7 @@ QDBusAbstractInterfacePrivate::QDBusAbstractInterfacePrivate(const QString &serv
|
||||
|
||||
if (!connection.isConnected()) {
|
||||
lastError = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-Bus server"));
|
||||
QDBusUtil::disconnectedErrorMessage());
|
||||
} else if (!service.isEmpty()) {
|
||||
currentOwner = connectionPrivate()->getNameOwner(service); // verify the name owner
|
||||
if (currentOwner.isEmpty()) {
|
||||
@ -131,8 +131,8 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
|
||||
|
||||
// try to read this property
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
|
||||
QLatin1String(DBUS_INTERFACE_PROPERTIES),
|
||||
QLatin1String("Get"));
|
||||
QDBusUtil::dbusInterfaceProperties(),
|
||||
QStringLiteral("Get"));
|
||||
QDBusMessagePrivate::setParametersValidated(msg, true);
|
||||
msg << interface << QString::fromUtf8(mp.name());
|
||||
QDBusMessage reply = connection.call(msg, QDBus::Block, timeout);
|
||||
@ -144,7 +144,7 @@ bool QDBusAbstractInterfacePrivate::property(const QMetaProperty &mp, void *retu
|
||||
if (reply.signature() != QLatin1String("v")) {
|
||||
QString errmsg = QLatin1String("Invalid signature `%1' in return from call to "
|
||||
DBUS_INTERFACE_PROPERTIES);
|
||||
lastError = QDBusError(QDBusError::InvalidSignature, errmsg.arg(reply.signature()));
|
||||
lastError = QDBusError(QDBusError::InvalidSignature, qMove(errmsg).arg(reply.signature()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -198,8 +198,8 @@ bool QDBusAbstractInterfacePrivate::setProperty(const QMetaProperty &mp, const Q
|
||||
|
||||
// send the value
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
|
||||
QLatin1String(DBUS_INTERFACE_PROPERTIES),
|
||||
QLatin1String("Set"));
|
||||
QDBusUtil::dbusInterfaceProperties(),
|
||||
QStringLiteral("Set"));
|
||||
QDBusMessagePrivate::setParametersValidated(msg, true);
|
||||
msg << interface << QString::fromUtf8(mp.name()) << QVariant::fromValue(QDBusVariant(value));
|
||||
QDBusMessage reply = connection.call(msg, QDBus::Block, timeout);
|
||||
@ -290,10 +290,10 @@ QDBusAbstractInterface::QDBusAbstractInterface(QDBusAbstractInterfacePrivate &d,
|
||||
&& !d.service.isEmpty()
|
||||
&& !d.service.startsWith(QLatin1Char(':'))
|
||||
&& d.connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
|
||||
d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
|
||||
d_func()->connection.connect(QDBusUtil::dbusService(), // service
|
||||
QString(), // path
|
||||
QLatin1String(DBUS_INTERFACE_DBUS), // interface
|
||||
QLatin1String("NameOwnerChanged"),
|
||||
QDBusUtil::dbusInterface(), // interface
|
||||
QDBusUtil::nameOwnerChanged(),
|
||||
QStringList() << d.service,
|
||||
QString(), // signature
|
||||
this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
|
||||
@ -316,10 +316,10 @@ QDBusAbstractInterface::QDBusAbstractInterface(const QString &service, const QSt
|
||||
&& !service.isEmpty()
|
||||
&& !service.startsWith(QLatin1Char(':'))
|
||||
&& d_func()->connectionPrivate()->mode != QDBusConnectionPrivate::PeerMode)
|
||||
d_func()->connection.connect(QLatin1String(DBUS_SERVICE_DBUS), // service
|
||||
d_func()->connection.connect(QDBusUtil::dbusService(), // service
|
||||
QString(), // path
|
||||
QLatin1String(DBUS_INTERFACE_DBUS), // interface
|
||||
QLatin1String("NameOwnerChanged"),
|
||||
QDBusUtil::dbusInterface(), // interface
|
||||
QDBusUtil::nameOwnerChanged(),
|
||||
QStringList() << service,
|
||||
QString(), //signature
|
||||
this, SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
|
||||
|
@ -462,7 +462,7 @@ bool QDBusConnection::send(const QDBusMessage &message) const
|
||||
{
|
||||
if (!d || !d->connection) {
|
||||
QDBusError err = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-BUS server"));
|
||||
QDBusUtil::disconnectedErrorMessage());
|
||||
if (d)
|
||||
d->lastError = err;
|
||||
return false;
|
||||
@ -495,7 +495,7 @@ bool QDBusConnection::callWithCallback(const QDBusMessage &message, QObject *rec
|
||||
{
|
||||
if (!d || !d->connection) {
|
||||
QDBusError err = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-BUS server"));
|
||||
QDBusUtil::disconnectedErrorMessage());
|
||||
if (d)
|
||||
d->lastError = err;
|
||||
return false;
|
||||
@ -553,7 +553,7 @@ QDBusMessage QDBusConnection::call(const QDBusMessage &message, QDBus::CallMode
|
||||
{
|
||||
if (!d || !d->connection) {
|
||||
QDBusError err = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-Bus server"));
|
||||
QDBusUtil::disconnectedErrorMessage());
|
||||
if (d)
|
||||
d->lastError = err;
|
||||
|
||||
@ -968,7 +968,7 @@ bool QDBusConnection::isConnected() const
|
||||
*/
|
||||
QDBusError QDBusConnection::lastError() const
|
||||
{
|
||||
return d ? d->lastError : QDBusError(QDBusError::Disconnected, QStringLiteral("Not connected."));
|
||||
return d ? d->lastError : QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -42,7 +42,7 @@
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
#include "qdbus_symbols_p.h" // for the DBUS_* constants
|
||||
#include "qdbusutil_p.h" // for the DBUS_* constants
|
||||
|
||||
#ifndef QT_NO_DBUS
|
||||
|
||||
@ -154,8 +154,8 @@ const char *QDBusConnectionInterface::staticInterfaceName()
|
||||
*/
|
||||
QDBusConnectionInterface::QDBusConnectionInterface(const QDBusConnection &connection,
|
||||
QObject *parent)
|
||||
: QDBusAbstractInterface(QLatin1String(DBUS_SERVICE_DBUS),
|
||||
QLatin1String(DBUS_PATH_DBUS),
|
||||
: QDBusAbstractInterface(QDBusUtil::dbusService(),
|
||||
QDBusUtil::dbusPath(),
|
||||
DBUS_INTERFACE_DBUS, connection, parent)
|
||||
{
|
||||
connect(this, SIGNAL(NameAcquired(QString)), this, SIGNAL(serviceRegistered(QString)));
|
||||
|
@ -72,23 +72,6 @@ static dbus_int32_t server_slot = -1;
|
||||
static QBasicAtomicInt isDebugging = Q_BASIC_ATOMIC_INITIALIZER(-1);
|
||||
#define qDBusDebug if (::isDebugging == 0); else qDebug
|
||||
|
||||
static inline QString orgFreedesktopDBusString()
|
||||
{
|
||||
return QStringLiteral(DBUS_SERVICE_DBUS);
|
||||
}
|
||||
|
||||
static inline QString dbusServiceString()
|
||||
{
|
||||
return orgFreedesktopDBusString();
|
||||
}
|
||||
|
||||
static inline QString dbusInterfaceString()
|
||||
{
|
||||
// it's the same string, but just be sure
|
||||
Q_ASSERT(orgFreedesktopDBusString() == QLatin1String(DBUS_INTERFACE_DBUS));
|
||||
return orgFreedesktopDBusString();
|
||||
}
|
||||
|
||||
static inline QDebug operator<<(QDebug dbg, const QThread *th)
|
||||
{
|
||||
QDebugStateSaver saver(dbg);
|
||||
@ -1041,7 +1024,7 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p)
|
||||
|
||||
// prepopulate watchedServices:
|
||||
// we know that the owner of org.freedesktop.DBus is itself
|
||||
watchedServices.insert(dbusServiceString(), WatchedServiceData(dbusServiceString(), 1));
|
||||
watchedServices.insert(QDBusUtil::dbusService(), WatchedServiceData(QDBusUtil::dbusService(), 1));
|
||||
|
||||
// prepopulate matchRefCounts:
|
||||
// we know that org.freedesktop.DBus will never change owners
|
||||
@ -1377,7 +1360,7 @@ bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node,
|
||||
// object may be null
|
||||
const QString interface = msg.interface();
|
||||
|
||||
if (interface.isEmpty() || interface == QLatin1String(DBUS_INTERFACE_INTROSPECTABLE)) {
|
||||
if (interface.isEmpty() || interface == QDBusUtil::dbusInterfaceIntrospectable()) {
|
||||
if (msg.member() == QLatin1String("Introspect") && msg.signature().isEmpty()) {
|
||||
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters introspect" << msg.d_ptr->msg;
|
||||
QDBusMessage reply = msg.createReply(qDBusIntrospectObject(node, msg.path()));
|
||||
@ -1392,7 +1375,7 @@ bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node,
|
||||
}
|
||||
|
||||
if (node.obj && (interface.isEmpty() ||
|
||||
interface == QLatin1String(DBUS_INTERFACE_PROPERTIES))) {
|
||||
interface == QDBusUtil::dbusInterfaceProperties())) {
|
||||
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters properties" << msg.d_ptr->msg;
|
||||
if (msg.member() == QLatin1String("Get") && msg.signature() == QLatin1String("ss")) {
|
||||
QDBusMessage reply = qDBusPropertyGet(node, msg);
|
||||
@ -1779,7 +1762,7 @@ void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusError
|
||||
// we don't use connectSignal here because we don't need the rules to be sent to the bus
|
||||
// the bus will always send us these two signals
|
||||
SignalHook hook;
|
||||
hook.service = dbusServiceString();
|
||||
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
|
||||
@ -2205,10 +2188,10 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM
|
||||
return pcall;
|
||||
} else {
|
||||
// we're probably disconnected at this point
|
||||
lastError = error = QDBusError(QDBusError::Disconnected, QLatin1String("Not connected to server"));
|
||||
lastError = error = QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage());
|
||||
}
|
||||
} else {
|
||||
lastError = error = QDBusError(QDBusError::NoMemory, QLatin1String("Out of memory"));
|
||||
lastError = error = QDBusError(QDBusError::NoMemory, QStringLiteral("Out of memory"));
|
||||
}
|
||||
|
||||
q_dbus_message_unref(msg);
|
||||
@ -2279,8 +2262,8 @@ void QDBusConnectionPrivate::connectSignal(const QString &key, const SignalHook
|
||||
WatchedServicesHash::mapped_type &data = watchedServices[hook.service];
|
||||
if (++data.refcount == 1) {
|
||||
// we need to watch for this service changing
|
||||
connectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
|
||||
QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
|
||||
connectSignal(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(),
|
||||
QStringLiteral("NameOwnerChanged"), QStringList() << hook.service, QString(),
|
||||
this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString)));
|
||||
data.owner = getNameOwnerNoCache(hook.service);
|
||||
qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:"
|
||||
@ -2359,8 +2342,8 @@ QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it)
|
||||
if (sit != watchedServices.end()) {
|
||||
if (--sit.value().refcount == 0) {
|
||||
watchedServices.erase(sit);
|
||||
disconnectSignal(dbusServiceString(), QString(), dbusInterfaceString(),
|
||||
QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(),
|
||||
disconnectSignal(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(),
|
||||
QStringLiteral("NameOwnerChanged"), QStringList() << hook.service, QString(),
|
||||
this, SLOT(serviceOwnerChangedNoLock(QString,QString,QString)));
|
||||
}
|
||||
}
|
||||
@ -2501,9 +2484,9 @@ QString QDBusConnectionPrivate::getNameOwner(const QString& serviceName)
|
||||
|
||||
QString QDBusConnectionPrivate::getNameOwnerNoCache(const QString &serviceName)
|
||||
{
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(dbusServiceString(),
|
||||
QLatin1String(DBUS_PATH_DBUS), dbusInterfaceString(),
|
||||
QLatin1String("GetNameOwner"));
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(QDBusUtil::dbusService(),
|
||||
QDBusUtil::dbusPath(), QDBusUtil::dbusInterface(),
|
||||
QStringLiteral("GetNameOwner"));
|
||||
QDBusMessagePrivate::setParametersValidated(msg, true);
|
||||
msg << serviceName;
|
||||
QDBusMessage reply = sendWithReply(msg, QDBus::Block);
|
||||
@ -2526,8 +2509,8 @@ QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &pa
|
||||
|
||||
// introspect the target object
|
||||
QDBusMessage msg = QDBusMessage::createMethodCall(service, path,
|
||||
QLatin1String(DBUS_INTERFACE_INTROSPECTABLE),
|
||||
QLatin1String("Introspect"));
|
||||
QDBusUtil::dbusInterfaceIntrospectable(),
|
||||
QStringLiteral("Introspect"));
|
||||
QDBusMessagePrivate::setParametersValidated(msg, true);
|
||||
|
||||
QDBusMessage reply = sendWithReply(msg, QDBus::Block);
|
||||
@ -2586,7 +2569,7 @@ bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceN
|
||||
{
|
||||
if (!serviceName.isEmpty() && serviceName == baseService)
|
||||
return true;
|
||||
if (serviceName == dbusServiceString())
|
||||
if (serviceName == QDBusUtil::dbusService())
|
||||
return false;
|
||||
|
||||
QDBusReadLocker locker(UnregisterServiceAction, this);
|
||||
|
@ -36,6 +36,7 @@
|
||||
|
||||
#include "qdbusconnection_p.h"
|
||||
#include "qdbusmetatype_p.h"
|
||||
#include "qdbusutil_p.h"
|
||||
#include "qcoreapplication.h"
|
||||
#include "qcoreevent.h"
|
||||
#include <private/qobject_p.h>
|
||||
@ -383,7 +384,7 @@ QDBusError QDBusPendingCall::error() const
|
||||
|
||||
// not connected, return an error
|
||||
QDBusError err = QDBusError(QDBusError::Disconnected,
|
||||
QLatin1String("Not connected to D-Bus server"));
|
||||
QDBusUtil::disconnectedErrorMessage());
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "qdbusserver.h"
|
||||
#include "qdbusconnection_p.h"
|
||||
#include "qdbusconnectionmanager_p.h"
|
||||
#include "qdbusutil_p.h"
|
||||
|
||||
#ifndef QT_NO_DBUS
|
||||
|
||||
@ -130,7 +131,7 @@ bool QDBusServer::isConnected() const
|
||||
*/
|
||||
QDBusError QDBusServer::lastError() const
|
||||
{
|
||||
return d ? d->lastError : QDBusError(QDBusError::Disconnected, QStringLiteral("Not connected."));
|
||||
return d ? d->lastError : QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage());
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#include "qdbusservicewatcher.h"
|
||||
#include "qdbusconnection.h"
|
||||
#include "qdbus_symbols_p.h"
|
||||
#include "qdbusutil_p.h"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
@ -43,10 +43,6 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, busService, (QLatin1String(DBUS_SERVICE_DBUS)))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, busInterface, (QLatin1String(DBUS_INTERFACE_DBUS)))
|
||||
Q_GLOBAL_STATIC_WITH_ARGS(QString, signalName, (QLatin1String("NameOwnerChanged")))
|
||||
|
||||
class QDBusServiceWatcherPrivate: public QObjectPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QDBusServiceWatcher)
|
||||
@ -120,7 +116,7 @@ QStringList QDBusServiceWatcherPrivate::matchArgsForService(const QString &servi
|
||||
void QDBusServiceWatcherPrivate::addService(const QString &service)
|
||||
{
|
||||
QStringList matchArgs = matchArgsForService(service);
|
||||
connection.connect(*busService(), QString(), *busInterface(), *signalName(),
|
||||
connection.connect(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), QDBusUtil::nameOwnerChanged(),
|
||||
matchArgs, QString(), q_func(),
|
||||
SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
|
||||
}
|
||||
@ -128,7 +124,7 @@ void QDBusServiceWatcherPrivate::addService(const QString &service)
|
||||
void QDBusServiceWatcherPrivate::removeService(const QString &service)
|
||||
{
|
||||
QStringList matchArgs = matchArgsForService(service);
|
||||
connection.disconnect(*busService(), QString(), *busInterface(), *signalName(),
|
||||
connection.disconnect(QDBusUtil::dbusService(), QString(), QDBusUtil::dbusInterface(), QDBusUtil::nameOwnerChanged(),
|
||||
matchArgs, QString(), q_func(),
|
||||
SLOT(_q_serviceOwnerChanged(QString,QString,QString)));
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2015 Intel Corporation.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtDBus module of the Qt Toolkit.
|
||||
@ -51,6 +52,8 @@
|
||||
#include <QtDBus/qdbusmacros.h>
|
||||
#include <QtDBus/qdbuserror.h>
|
||||
|
||||
#include "qdbus_symbols_p.h"
|
||||
|
||||
#ifndef QT_NO_DBUS
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -147,6 +150,25 @@ namespace QDBusUtil
|
||||
*error = QDBusError(QDBusError::InvalidInterface, QString::fromLatin1("Invalid error name: %1").arg(name));
|
||||
return false;
|
||||
}
|
||||
|
||||
inline QString dbusService()
|
||||
{ return QStringLiteral(DBUS_SERVICE_DBUS); }
|
||||
inline QString dbusPath()
|
||||
{ return QStringLiteral(DBUS_PATH_DBUS); }
|
||||
inline QString dbusInterface()
|
||||
{
|
||||
// it's the same string, but just be sure
|
||||
Q_ASSERT(dbusService() == QLatin1String(DBUS_INTERFACE_DBUS));
|
||||
return dbusService();
|
||||
}
|
||||
inline QString dbusInterfaceProperties()
|
||||
{ return QStringLiteral(DBUS_INTERFACE_PROPERTIES); }
|
||||
inline QString dbusInterfaceIntrospectable()
|
||||
{ return QStringLiteral(DBUS_INTERFACE_INTROSPECTABLE); }
|
||||
inline QString nameOwnerChanged()
|
||||
{ return QStringLiteral("NameOwnerChanged"); }
|
||||
inline QString disconnectedErrorMessage()
|
||||
{ return QStringLiteral("Not connected to D-Bus server"); }
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
Loading…
Reference in New Issue
Block a user