summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Christian <andrew.christian@nokia.com>2012-02-16 09:20:48 -0500
committerChris Craig <ext-chris.craig@nokia.com>2012-02-16 16:34:20 +0100
commit7140c90c4c771f9e027b1922fea167ff102026a9 (patch)
tree77744a06028de361abedfc5a0bad0a237a274b46
parenteca172878a135b0d60f4540c8495b3a6dad0dc3c (diff)
Moved strings for remote protocol into common header.
Commons strings are all declared as functions that return QStringLiteral values. This follows Qt practice and should allow for reliable reuse of strings values from 3rd-party applications. Change-Id: Ic3bd0fa0bfb2705d388aeba462dfac8c22d5eba2 Reviewed-by: Chris Craig <ext-chris.craig@nokia.com>
-rw-r--r--src/core/core-lib.pri3
-rw-r--r--src/core/launcherclient.cpp70
-rw-r--r--src/core/pipelauncher.cpp3
-rw-r--r--src/core/pipeprocessbackendfactory.cpp3
-rw-r--r--src/core/remoteprocessbackend.cpp77
-rw-r--r--src/core/remoteprotocol.h80
-rw-r--r--src/core/socketprocessbackendfactory.cpp6
-rw-r--r--src/core/unixprocessbackend.cpp5
8 files changed, 165 insertions, 82 deletions
diff --git a/src/core/core-lib.pri b/src/core/core-lib.pri
index b6861d1..77ecb38 100644
--- a/src/core/core-lib.pri
+++ b/src/core/core-lib.pri
@@ -28,7 +28,8 @@ PUBLIC_HEADERS += \
$$PWD/launcherclient.h \
$$PWD/pipelauncher.h \
$$PWD/socketlauncher.h \
- $$PWD/procutils.h
+ $$PWD/procutils.h \
+ $$PWD/remoteprotocol.h
HEADERS += \
$$PUBLIC_HEADERS \
diff --git a/src/core/launcherclient.cpp b/src/core/launcherclient.cpp
index 1f30dd9..4c64934 100644
--- a/src/core/launcherclient.cpp
+++ b/src/core/launcherclient.cpp
@@ -40,6 +40,7 @@
#include <QDebug>
#include "launcherclient.h"
+#include "remoteprotocol.h"
#include "processbackend.h"
#include "processbackendmanager.h"
@@ -54,9 +55,6 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER
Create a new LauncherClient with ProcessBackendManager \a manager
*/
-static inline QString kEvent() { return QStringLiteral("event"); }
-static inline QString kId() { return QStringLiteral("id"); }
-
LauncherClient::LauncherClient(ProcessBackendManager *manager)
: QObject(manager)
, m_manager(manager)
@@ -70,10 +68,10 @@ LauncherClient::LauncherClient(ProcessBackendManager *manager)
void LauncherClient::receive(const QJsonObject& message)
{
// qDebug() << Q_FUNC_INFO << message;
- QString cmd = message.value(QStringLiteral("command")).toString();
- int id = message.value(QStringLiteral("id")).toDouble();
- if ( cmd == QLatin1String("start") ) {
- ProcessInfo info(message.value(QStringLiteral("info")).toObject().toVariantMap());
+ QString cmd = message.value(RemoteProtocol::command()).toString();
+ int id = message.value(RemoteProtocol::id()).toDouble();
+ if ( cmd == RemoteProtocol::start() ) {
+ ProcessInfo info(message.value(RemoteProtocol::info()).toObject().toVariantMap());
ProcessBackend *backend = m_manager->create(info, this);
if (backend) {
connect(backend, SIGNAL(started()), SLOT(started()));
@@ -91,26 +89,26 @@ void LauncherClient::receive(const QJsonObject& message)
backend->start();
}
}
- else if ( cmd == QLatin1String("stop") ) {
+ else if ( cmd == RemoteProtocol::stop() ) {
ProcessBackend *backend = m_idToBackend.value(id);
if (backend) {
- int timeout = message.value(QStringLiteral("timeout")).toDouble();
+ int timeout = message.value(RemoteProtocol::timeout()).toDouble();
backend->stop(timeout);
}
}
- else if ( cmd == QLatin1String("set") ) {
+ else if ( cmd == RemoteProtocol::set() ) {
ProcessBackend *backend = m_idToBackend.value(id);
if (backend) {
- QString key = message.value(QStringLiteral("key")).toString();
- int value = message.value(QStringLiteral("value")).toDouble();
- if (key == QLatin1String("priority"))
+ QString key = message.value(RemoteProtocol::key()).toString();
+ int value = message.value(RemoteProtocol::value()).toDouble();
+ if (key == RemoteProtocol::priority())
backend->setDesiredPriority(value);
- else if (key == QLatin1String("oomAdjustment"))
+ else if (key == RemoteProtocol::oomAdjustment())
backend->setDesiredOomAdjustment(value);
}
}
- else if ( cmd == QLatin1String("write") ) {
- QByteArray data = message.value(QStringLiteral("data")).toString().toLocal8Bit();
+ else if ( cmd == RemoteProtocol::write() ) {
+ QByteArray data = message.value(RemoteProtocol::data()).toString().toLocal8Bit();
ProcessBackend *backend = m_idToBackend.value(id);
if (backend)
backend->write(data);
@@ -125,9 +123,9 @@ void LauncherClient::started()
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("started"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QStringLiteral("pid"), (double) backend->pid());
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::started());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::pid(), (double) backend->pid());
emit send(msg);
}
@@ -139,10 +137,10 @@ void LauncherClient::finished(int exitCode, QProcess::ExitStatus exitStatus)
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("finished"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QStringLiteral("exitCode"), exitCode);
- msg.insert(QStringLiteral("exitStatus"), exitStatus);
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::finished());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::exitCode(), exitCode);
+ msg.insert(RemoteProtocol::exitStatus(), exitStatus);
emit send(msg);
}
@@ -154,10 +152,10 @@ void LauncherClient::error(QProcess::ProcessError err)
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("error"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QStringLiteral("error"), err);
- msg.insert(QStringLiteral("errorString"), backend->errorString());
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::error());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::error(), err);
+ msg.insert(RemoteProtocol::errorString(), backend->errorString());
emit send(msg);
}
@@ -169,9 +167,9 @@ void LauncherClient::stateChanged(QProcess::ProcessState state)
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("stateChanged"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QStringLiteral("stateChanged"), state);
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::stateChanged());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::stateChanged(), state);
emit send(msg);
}
@@ -183,9 +181,9 @@ void LauncherClient::standardOutput(const QByteArray& data)
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("output"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QLatin1String("stdout"), QString::fromLocal8Bit(data.data(), data.size()));
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::output());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::stdout(), QString::fromLocal8Bit(data.data(), data.size()));
emit send(msg);
}
@@ -197,9 +195,9 @@ void LauncherClient::standardError(const QByteArray& data)
{
ProcessBackend *backend = qobject_cast<ProcessBackend *>(sender());
QJsonObject msg;
- msg.insert(kEvent(), QLatin1String("output"));
- msg.insert(kId(), m_backendToId.value(backend));
- msg.insert(QLatin1String("stderr"), QString::fromLocal8Bit(data.data(), data.size()));
+ msg.insert(RemoteProtocol::event(), RemoteProtocol::output());
+ msg.insert(RemoteProtocol::id(), m_backendToId.value(backend));
+ msg.insert(RemoteProtocol::stderr(), QString::fromLocal8Bit(data.data(), data.size()));
emit send(msg);
}
diff --git a/src/core/pipelauncher.cpp b/src/core/pipelauncher.cpp
index 57e80ac..6099072 100644
--- a/src/core/pipelauncher.cpp
+++ b/src/core/pipelauncher.cpp
@@ -44,6 +44,7 @@
#include "pipelauncher.h"
#include "launcherclient.h"
+#include "remoteprotocol.h"
QT_BEGIN_NAMESPACE_PROCESSMANAGER
@@ -97,7 +98,7 @@ void PipeLauncher::inReady(int fd)
QByteArray msg = m_inbuf.left(message_size);
m_inbuf = m_inbuf.mid(message_size);
QJsonObject message = QJsonDocument::fromBinaryData(msg).object();
- if (message.value(QStringLiteral("remote")).toString() == QLatin1String("stop"))
+ if (message.value(RemoteProtocol::remote()).toString() == RemoteProtocol::stop())
exit(0);
m_client->receive(message);
}
diff --git a/src/core/pipeprocessbackendfactory.cpp b/src/core/pipeprocessbackendfactory.cpp
index 06c0e18..da867f5 100644
--- a/src/core/pipeprocessbackendfactory.cpp
+++ b/src/core/pipeprocessbackendfactory.cpp
@@ -39,6 +39,7 @@
#include "pipeprocessbackendfactory.h"
#include "remoteprocessbackend.h"
+#include "remoteprotocol.h"
#include <QDebug>
#include <QJsonDocument>
@@ -104,7 +105,7 @@ PipeProcessBackendFactory::~PipeProcessBackendFactory()
// However, we do send it a "stop" message before we exit
if (m_process) {
QJsonObject object;
- object.insert(QLatin1String("remote"), QLatin1String("stop"));
+ object.insert(RemoteProtocol::remote(), RemoteProtocol::stop());
m_process->write(QJsonDocument(object).toBinaryData());
m_process->waitForBytesWritten(); // Block until they have been written
m_process = NULL;
diff --git a/src/core/remoteprocessbackend.cpp b/src/core/remoteprocessbackend.cpp
index 5d80863..a6fafec 100644
--- a/src/core/remoteprocessbackend.cpp
+++ b/src/core/remoteprocessbackend.cpp
@@ -38,6 +38,7 @@
****************************************************************************/
#include "remoteprocessbackend.h"
+#include "remoteprotocol.h"
#include "procutils.h"
#include <sys/resource.h>
#include <errno.h>
@@ -46,10 +47,6 @@
QT_BEGIN_NAMESPACE_PROCESSMANAGER
-static const QLatin1String kCommand("command");
-static const QLatin1String kId("id");
-static const QLatin1String kSignal("signal");
-
/*!
\class RemoteProcessBackend
@@ -125,10 +122,10 @@ void RemoteProcessBackend::setDesiredPriority(qint32 priority)
ProcessBackend::setDesiredPriority(priority);
if (m_factory && m_pid != -1) {
QJsonObject object;
- object.insert(kCommand, QLatin1String("set"));
- object.insert(kId, m_id);
- object.insert(QStringLiteral("key"), QLatin1String("priority"));
- object.insert(QStringLiteral("value"), priority);
+ object.insert(RemoteProtocol::command(), RemoteProtocol::set());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::key(), RemoteProtocol::priority());
+ object.insert(RemoteProtocol::value(), priority);
m_factory->send(object);
}
}
@@ -160,10 +157,10 @@ void RemoteProcessBackend::setDesiredOomAdjustment(qint32 oomAdjustment)
ProcessBackend::setDesiredOomAdjustment(oomAdjustment);
if (m_factory && m_pid != -1) {
QJsonObject object;
- object.insert(kCommand, QLatin1String("set"));
- object.insert(kId, m_id);
- object.insert(QStringLiteral("key"), QLatin1String("oomAdjustment"));
- object.insert(QStringLiteral("value"), oomAdjustment);
+ object.insert(RemoteProtocol::command(), RemoteProtocol::set());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::key(), RemoteProtocol::oomAdjustment());
+ object.insert(RemoteProtocol::value(), oomAdjustment);
m_factory->send(object);
}
}
@@ -187,9 +184,9 @@ void RemoteProcessBackend::start()
{
if (m_factory) {
QJsonObject object;
- object.insert(kCommand, QLatin1String("start"));
- object.insert(kId, m_id);
- object.insert(QLatin1String("info"), QJsonValue::fromVariant(m_info.toMap()));
+ object.insert(RemoteProtocol::command(), RemoteProtocol::start());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::info(), QJsonValue::fromVariant(m_info.toMap()));
m_factory->send(object);
}
}
@@ -204,9 +201,9 @@ void RemoteProcessBackend::stop(int timeout)
{
if (m_factory) {
QJsonObject object;
- object.insert(kCommand, QLatin1String("stop"));
- object.insert(kId, m_id);
- object.insert(QLatin1String("timeout"), timeout);
+ object.insert(RemoteProtocol::command(), RemoteProtocol::stop());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::timeout(), timeout);
m_factory->send(object);
}
}
@@ -223,9 +220,9 @@ qint64 RemoteProcessBackend::write(const char *data, qint64 maxSize)
{
if (m_factory) {
QJsonObject object;
- object.insert(kCommand, QLatin1String("write"));
- object.insert(kId, m_id);
- object.insert(QLatin1String("data"), QString::fromLocal8Bit(data, maxSize));
+ object.insert(RemoteProtocol::command(), RemoteProtocol::write());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::data(), QString::fromLocal8Bit(data, maxSize));
if (m_factory->send(object))
return maxSize;
}
@@ -248,30 +245,30 @@ QString RemoteProcessBackend::errorString() const
void RemoteProcessBackend::receive(const QJsonObject& message)
{
- QString event = message.value(QStringLiteral("event")).toString();
+ QString event = message.value(RemoteProtocol::event()).toString();
// qDebug() << Q_FUNC_INFO << message;
- if (event == QLatin1String("started")) {
- m_pid = message.value(QStringLiteral("pid")).toDouble();
+ if (event == RemoteProtocol::started()) {
+ m_pid = message.value(RemoteProtocol::pid()).toDouble();
emit started();
}
- else if (event == QLatin1String("error")) {
- m_errorString = message.value(QStringLiteral("errorString")).toString();
- emit error(static_cast<QProcess::ProcessError>(message.value(QStringLiteral("error")).toDouble()));
+ else if (event == RemoteProtocol::error()) {
+ m_errorString = message.value(RemoteProtocol::errorString()).toString();
+ emit error(static_cast<QProcess::ProcessError>(message.value(RemoteProtocol::error()).toDouble()));
}
- else if (event == QLatin1String("finished")) {
- emit finished(message.value(QStringLiteral("exitCode")).toDouble(),
- static_cast<QProcess::ExitStatus>(message.value(QStringLiteral("exitStatus")).toDouble()));
+ else if (event == RemoteProtocol::finished()) {
+ emit finished(message.value(RemoteProtocol::exitCode()).toDouble(),
+ static_cast<QProcess::ExitStatus>(message.value(RemoteProtocol::exitStatus()).toDouble()));
}
- else if (event == QLatin1String("stateChanged")) {
- m_state = static_cast<QProcess::ProcessState>(message.value(QStringLiteral("stateChanged")).toDouble());
+ else if (event == RemoteProtocol::stateChanged()) {
+ m_state = static_cast<QProcess::ProcessState>(message.value(RemoteProtocol::stateChanged()).toDouble());
emit stateChanged(m_state);
}
- else if (event == QLatin1String("output")) {
- if (message.contains(QStringLiteral("stdout"))) {
- handleStandardOutput(message.value(QStringLiteral("stdout")).toString().toLocal8Bit());
+ else if (event == RemoteProtocol::output()) {
+ if (message.contains(RemoteProtocol::stdout())) {
+ handleStandardOutput(message.value(RemoteProtocol::stdout()).toString().toLocal8Bit());
}
- if (message.contains(QStringLiteral("stderr"))) {
- handleStandardError(message.value(QStringLiteral("stderr")).toString().toLocal8Bit());
+ if (message.contains(RemoteProtocol::stderr())) {
+ handleStandardError(message.value(RemoteProtocol::stderr()).toString().toLocal8Bit());
}
}
else
@@ -286,9 +283,9 @@ void RemoteProcessBackend::killTimeout()
{
if (m_factory) {
QJsonObject object;
- object.insert(kCommand, kSignal);
- object.insert(kId, m_id);
- object.insert(kSignal, SIGKILL);
+ object.insert(RemoteProtocol::command(), RemoteProtocol::signal());
+ object.insert(RemoteProtocol::id(), m_id);
+ object.insert(RemoteProtocol::signal(), SIGKILL);
m_factory->send(object);
}
}
diff --git a/src/core/remoteprotocol.h b/src/core/remoteprotocol.h
new file mode 100644
index 0000000..3a31613
--- /dev/null
+++ b/src/core/remoteprotocol.h
@@ -0,0 +1,80 @@
+/****************************************************************************
+**
+** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef _REMOTE_PROTOCOL_H
+#define _REMOTE_PROTOCOL_H
+
+#include "processmanager-global.h"
+
+QT_BEGIN_NAMESPACE_PROCESSMANAGER
+
+class RemoteProtocol {
+public:
+ static inline const QString command() { return QStringLiteral("command"); }
+ static inline const QString data() { return QStringLiteral("data"); }
+ static inline const QString error() { return QStringLiteral("error"); }
+ static inline const QString errorString() { return QStringLiteral("errorString"); }
+ static inline const QString event() { return QStringLiteral("event"); }
+ static inline const QString exitCode() { return QStringLiteral("exitCode"); }
+ static inline const QString exitStatus() { return QStringLiteral("exitStatus"); }
+ static inline const QString finished() { return QStringLiteral("finished"); }
+ static inline const QString id() { return QStringLiteral("id"); }
+ static inline const QString info() { return QStringLiteral("info"); }
+ static inline const QString key() { return QStringLiteral("key"); }
+ static inline const QString oomAdjustment() { return QStringLiteral("oomAdjustment"); }
+ static inline const QString output() { return QStringLiteral("output"); }
+ static inline const QString pid() { return QStringLiteral("pid"); }
+ static inline const QString priority() { return QStringLiteral("priority"); }
+ static inline const QString remote() { return QStringLiteral("remote"); }
+ static inline const QString set() { return QStringLiteral("set"); }
+ static inline const QString signal() { return QStringLiteral("signal"); }
+ static inline const QString start() { return QStringLiteral("start"); }
+ static inline const QString started() { return QStringLiteral("started"); }
+ static inline const QString stateChanged() { return QStringLiteral("stateChanged"); }
+ static inline const QString stderr() { return QStringLiteral("stderr"); }
+ static inline const QString stdout() { return QStringLiteral("stdout"); }
+ static inline const QString stop() { return QStringLiteral("stop"); }
+ static inline const QString timeout() { return QStringLiteral("timeout"); }
+ static inline const QString value() { return QStringLiteral("value"); }
+ static inline const QString write() { return QStringLiteral("write"); }
+};
+
+QT_END_NAMESPACE_PROCESSMANAGER
+
+#endif // _REMOTE_PROTOCOL_H
diff --git a/src/core/socketprocessbackendfactory.cpp b/src/core/socketprocessbackendfactory.cpp
index 1d8a4ce..a2f2de2 100644
--- a/src/core/socketprocessbackendfactory.cpp
+++ b/src/core/socketprocessbackendfactory.cpp
@@ -55,8 +55,12 @@ QT_BEGIN_NAMESPACE_PROCESSMANAGER
*/
/*!
+ \property SocketProcessBackendFactory::socketName
+ The name of the Unix local socket that this factory should connect to.
+ */
+
+/*!
Construct a SocketProcessBackendFactory with optional \a parent.
- Connect to an application launcher listening on Unix local socket \a socketname
*/
SocketProcessBackendFactory::SocketProcessBackendFactory(QObject *parent)
diff --git a/src/core/unixprocessbackend.cpp b/src/core/unixprocessbackend.cpp
index 0084132..ff33c34 100644
--- a/src/core/unixprocessbackend.cpp
+++ b/src/core/unixprocessbackend.cpp
@@ -261,10 +261,11 @@ qint64 UnixProcessBackend::write(const char *data, qint64 maxSize)
*/
void UnixProcessBackend::handleProcessStarted()
{
- if (m_info.contains(QStringLiteral("priority")) && setpriority(PRIO_PROCESS, m_process->pid(), m_info.priority()))
+ if (m_info.contains(ProcessInfoConstants::Priority) &&
+ setpriority(PRIO_PROCESS, m_process->pid(), m_info.priority()))
qWarning() << "Failed to set process priority at startup from " << actualPriority() <<
"to" << m_info.priority() << " : errno = " << errno;
- if (m_info.contains(QStringLiteral("oomAdjustment")) &&
+ if (m_info.contains(ProcessInfoConstants::OomAdjustment) &&
!ProcUtils::setOomAdjustment(m_process->pid(), m_info.oomAdjustment()))
qWarning() << "Failed to set process oom score at startup from " << actualOomAdjustment() <<
"to" << m_info.oomAdjustment();