refactor(ipc): use more QStringLiterals
This commit is contained in:
parent
bdb7309778
commit
d1074f64ae
7 changed files with 33 additions and 33 deletions
|
|
@ -24,5 +24,5 @@ void ipcSendToClient(const QString &command, const QString &args)
|
|||
void ipcSendConnectionState(deskflow::core::ConnectionState state)
|
||||
{
|
||||
const auto metaEnum = QMetaEnum::fromType<deskflow::core::ConnectionState>();
|
||||
ipcSendToClient("connectionState", metaEnum.valueToKey(static_cast<int>(state)));
|
||||
ipcSendToClient(QStringLiteral("connectionState"), metaEnum.valueToKey(static_cast<int>(state)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace deskflow::core::ipc {
|
|||
|
||||
static CoreIpcServer *s_instance = nullptr;
|
||||
|
||||
CoreIpcServer::CoreIpcServer(QObject *parent) : IpcServer(parent, kCoreIpcName, "core")
|
||||
CoreIpcServer::CoreIpcServer(QObject *parent) : IpcServer(parent, kCoreIpcName, QStringLiteral("core"))
|
||||
{
|
||||
assert(s_instance == nullptr);
|
||||
s_instance = this;
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const auto kAckMessage = "ok";
|
|||
const auto kErrorMessage = "error";
|
||||
|
||||
DaemonIpcServer::DaemonIpcServer(QObject *parent, const QString &logFilename)
|
||||
: IpcServer(parent, kDaemonIpcName, "daemon"),
|
||||
: IpcServer(parent, kDaemonIpcName, QStringLiteral("daemon")),
|
||||
m_logFilename(logFilename)
|
||||
{
|
||||
// do nothing
|
||||
|
|
@ -25,24 +25,24 @@ DaemonIpcServer::DaemonIpcServer(QObject *parent, const QString &logFilename)
|
|||
|
||||
void DaemonIpcServer::processCommand(QLocalSocket *clientSocket, const QString &command, const QStringList &parts)
|
||||
{
|
||||
if (command == "logLevel") {
|
||||
if (command == QStringLiteral("logLevel")) {
|
||||
processLogLevel(clientSocket, parts);
|
||||
} else if (command == "elevate") {
|
||||
} else if (command == QStringLiteral("elevate")) {
|
||||
processElevate(clientSocket, parts);
|
||||
} else if (command == "command") {
|
||||
} else if (command == QStringLiteral("command")) {
|
||||
processCommandMessage(clientSocket, parts);
|
||||
} else if (command == "start") {
|
||||
} else if (command == QStringLiteral("start")) {
|
||||
LOG_DEBUG("daemon ipc server got start message");
|
||||
Q_EMIT startProcessRequested();
|
||||
writeToClientSocket(clientSocket, kAckMessage);
|
||||
} else if (command == "stop") {
|
||||
} else if (command == QStringLiteral("stop")) {
|
||||
LOG_DEBUG("daemon ipc server got stop message");
|
||||
Q_EMIT stopProcessRequested();
|
||||
writeToClientSocket(clientSocket, kAckMessage);
|
||||
} else if (command == "logPath") {
|
||||
} else if (command == QStringLiteral("logPath")) {
|
||||
LOG_DEBUG("daemon ipc server got log path request");
|
||||
writeToClientSocket(clientSocket, "logPath=" + m_logFilename.toUtf8());
|
||||
} else if (command == "clearSettings") {
|
||||
writeToClientSocket(clientSocket, QStringLiteral("logPath=%1").arg(m_logFilename.toUtf8()));
|
||||
} else if (command == QStringLiteral("clearSettings")) {
|
||||
LOG_DEBUG("daemon ipc server got clear settings message");
|
||||
Q_EMIT clearSettingsRequested();
|
||||
writeToClientSocket(clientSocket, kAckMessage);
|
||||
|
|
@ -80,14 +80,14 @@ void DaemonIpcServer::processElevate(QLocalSocket *&clientSocket, const QStringL
|
|||
}
|
||||
|
||||
const auto &elevate = messageParts[1];
|
||||
if (elevate != "yes" && elevate != "no") {
|
||||
if (elevate != QStringLiteral("yes") && elevate != QStringLiteral("no")) {
|
||||
LOG_ERR("daemon ipc server got invalid elevate value: %s", elevate.toUtf8().constData());
|
||||
writeToClientSocket(clientSocket, kErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_DEBUG("daemon ipc server got new elevate value: %s", elevate.toUtf8().constData());
|
||||
Q_EMIT elevateModeChanged(elevate == "yes");
|
||||
Q_EMIT elevateModeChanged(elevate == QStringLiteral("yes"));
|
||||
writeToClientSocket(clientSocket, kAckMessage);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -107,11 +107,11 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag
|
|||
const auto parts = message.split('=');
|
||||
if (parts.isEmpty()) {
|
||||
LOG_ERR("%s ipc server got invalid message: %s", m_typeName.constData(), message.toUtf8().constData());
|
||||
writeToClientSocket(clientSocket, "error");
|
||||
writeToClientSocket(clientSocket, QStringLiteral("error"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (const auto &command = parts.at(0); command == "hello") {
|
||||
if (const auto &command = parts.at(0); command == QStringLiteral("hello")) {
|
||||
if (parts.size() < 2) {
|
||||
LOG_ERR("%s ipc client hello missing version", m_typeName.constData());
|
||||
writeToClientSocket(clientSocket, "error=missing version");
|
||||
|
|
@ -136,7 +136,7 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag
|
|||
}
|
||||
|
||||
LOG_DEBUG("%s ipc server sending hello back", m_typeName.constData());
|
||||
writeToClientSocket(clientSocket, QString("hello=%1").arg(versionId));
|
||||
writeToClientSocket(clientSocket, QStringLiteral("hello=%1").arg(versionId));
|
||||
|
||||
// Replay messages that were queued before any clients connected.
|
||||
LOG_DEBUG1("ipc server replaying %d pending messages", m_pendingMessages.size());
|
||||
|
|
@ -145,9 +145,9 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag
|
|||
writeToClientSocket(clientSocket, pending);
|
||||
}
|
||||
m_pendingMessages.clear();
|
||||
} else if (command == "noop") {
|
||||
} else if (command == QStringLiteral("noop")) {
|
||||
LOG_DEBUG("%s ipc server got noop message", m_typeName.constData());
|
||||
writeToClientSocket(clientSocket, "ok");
|
||||
writeToClientSocket(clientSocket, QStringLiteral("ok"));
|
||||
} else {
|
||||
processCommand(clientSocket, command, parts);
|
||||
}
|
||||
|
|
@ -157,7 +157,7 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag
|
|||
|
||||
void IpcServer::broadcastCommand(const QString &command, const QString &args)
|
||||
{
|
||||
const auto message = args.isEmpty() ? command : command + "=" + args;
|
||||
const auto message = args.isEmpty() ? command : QStringLiteral("%1=%2").arg(command, args);
|
||||
|
||||
if (m_clients.isEmpty()) {
|
||||
LOG_DEBUG1(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
|
||||
namespace deskflow::gui::ipc {
|
||||
|
||||
CoreIpcClient::CoreIpcClient(QObject *parent) : IpcClient(parent, kCoreIpcName, "core")
|
||||
CoreIpcClient::CoreIpcClient(QObject *parent) : IpcClient(parent, kCoreIpcName, QStringLiteral("core"))
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,41 +12,41 @@
|
|||
|
||||
namespace deskflow::gui::ipc {
|
||||
|
||||
DaemonIpcClient::DaemonIpcClient(QObject *parent) : IpcClient(parent, kDaemonIpcName, "daemon")
|
||||
DaemonIpcClient::DaemonIpcClient(QObject *parent) : IpcClient(parent, kDaemonIpcName, QStringLiteral("daemon"))
|
||||
{
|
||||
}
|
||||
|
||||
void DaemonIpcClient::sendLogLevel(const QString &logLevel)
|
||||
{
|
||||
sendMessage("logLevel=" + logLevel);
|
||||
sendMessage(QStringLiteral("logLevel=%1").arg(logLevel));
|
||||
}
|
||||
|
||||
void DaemonIpcClient::sendStartProcess(const QString &command, bool elevate)
|
||||
{
|
||||
const auto elevateStr = elevate ? QStringLiteral("yes") : QStringLiteral("no");
|
||||
sendMessage("elevate=" + elevateStr);
|
||||
sendMessage("command=" + command);
|
||||
sendMessage("start");
|
||||
sendMessage(QStringLiteral("elevate=%1").arg(elevateStr));
|
||||
sendMessage(QStringLiteral("command=%1").arg(command));
|
||||
sendMessage(QStringLiteral("start"));
|
||||
}
|
||||
|
||||
void DaemonIpcClient::sendStopProcess()
|
||||
{
|
||||
sendMessage("stop");
|
||||
sendMessage(QStringLiteral("stop"));
|
||||
}
|
||||
|
||||
void DaemonIpcClient::sendClearSettings()
|
||||
{
|
||||
sendMessage("clearSettings");
|
||||
sendMessage(QStringLiteral("clearSettings"));
|
||||
}
|
||||
|
||||
void DaemonIpcClient::requestLogPath()
|
||||
{
|
||||
sendMessage("logPath");
|
||||
sendMessage(QStringLiteral("logPath"));
|
||||
}
|
||||
|
||||
void DaemonIpcClient::processCommand(const QString &command, const QStringList &parts)
|
||||
{
|
||||
if (command == "logPath" && parts.size() == 2) {
|
||||
if (command == QStringLiteral("logPath") && parts.size() == 2) {
|
||||
Q_EMIT logPathReceived(parts[1]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,15 +161,15 @@ void IpcClient::handleReadyRead()
|
|||
|
||||
void IpcClient::handleHandshakeMessage(const QStringList &parts)
|
||||
{
|
||||
if (parts.at(0) == "error") {
|
||||
const auto detail = parts.size() >= 2 ? parts.at(1) : QString("unknown");
|
||||
qCritical().noquote() << m_typeName << "ipc server rejected connection:" << detail;
|
||||
if (parts.at(0) == QStringLiteral("error")) {
|
||||
const auto detail = parts.size() >= 2 ? parts.at(1) : QStringLiteral("unknown");
|
||||
qCritical().noquote() << QStringLiteral("%1 ipc server rejected connection: %2").arg(m_typeName, detail);
|
||||
disconnectFromServer();
|
||||
Q_EMIT connectionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
if (parts.at(0) != "hello") {
|
||||
if (parts.at(0) != QStringLiteral("hello")) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue