Skip to content

Commit

Permalink
Format with clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew J. Milner <[email protected]>
  • Loading branch information
matterhorn103 committed Oct 24, 2024
1 parent 47e5fc0 commit 4e06ec3
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 178 deletions.
123 changes: 60 additions & 63 deletions avogadro/molequeue/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,16 @@

#include "client.h"

#include "jsonrpcclient.h"
#include "jobobject.h"
#include "jsonrpcclient.h"

#include <QtCore/QJsonDocument>

namespace Avogadro::MoleQueue {

Client::Client(QObject *parent_) : QObject(parent_), m_jsonRpcClient(nullptr)
{
}
Client::Client(QObject* parent_) : QObject(parent_), m_jsonRpcClient(nullptr) {}

Client::~Client()
{
}
Client::~Client() {}

bool Client::isConnected() const
{
Expand All @@ -28,7 +24,7 @@ bool Client::isConnected() const
return m_jsonRpcClient->isConnected();
}

bool Client::connectToServer(const QString &serverName)
bool Client::connectToServer(const QString& serverName)
{
if (!m_jsonRpcClient) {
m_jsonRpcClient = new JsonRpcClient(this);
Expand Down Expand Up @@ -60,7 +56,7 @@ int Client::requestQueueList()
return localId;
}

int Client::submitJob(const JobObject &job)
int Client::submitJob(const JobObject& job)
{
if (!m_jsonRpcClient)
return -1;
Expand Down Expand Up @@ -112,8 +108,8 @@ int Client::cancelJob(unsigned int moleQueueId)
return localId;
}

int Client::registerOpenWith(const QString &name, const QString &executable,
const QList<QRegularExpression> &filePatterns)
int Client::registerOpenWith(const QString& name, const QString& executable,
const QList<QRegularExpression>& filePatterns)
{
if (!m_jsonRpcClient)
return -1;
Expand All @@ -131,9 +127,9 @@ int Client::registerOpenWith(const QString &name, const QString &executable,
return localId;
}

int Client::registerOpenWith(const QString &name,
const QString &rpcServer, const QString &rpcMethod,
const QList<QRegularExpression> &filePatterns)
int Client::registerOpenWith(const QString& name, const QString& rpcServer,
const QString& rpcMethod,
const QList<QRegularExpression>& filePatterns)
{
if (!m_jsonRpcClient)
return -1;
Expand Down Expand Up @@ -167,7 +163,7 @@ int Client::listOpenWithNames()
return localId;
}

int Client::unregisterOpenWith(const QString &handlerName)
int Client::unregisterOpenWith(const QString& handlerName)
{
if (!m_jsonRpcClient)
return -1;
Expand All @@ -191,60 +187,60 @@ void Client::flush()
m_jsonRpcClient->flush();
}

void Client::processResult(const QJsonObject &response)
void Client::processResult(const QJsonObject& response)
{
if (response["id"] != QJsonValue::Null
&& m_requests.contains(static_cast<int>(response["id"].toDouble()))) {
if (response["id"] != QJsonValue::Null &&
m_requests.contains(static_cast<int>(response["id"].toDouble()))) {
int localId = static_cast<int>(response["id"].toDouble());
switch (m_requests[localId]) {
case ListQueues:
emit queueListReceived(response["result"].toObject());
break;
case SubmitJob:
emit submitJobResponse(localId,
static_cast<unsigned int>(response["result"]
.toObject()["moleQueueId"].toDouble()));
break;
case LookupJob:
emit lookupJobResponse(localId, response["result"].toObject());
break;
case CancelJob:
emit cancelJobResponse(static_cast<unsigned int>(response["result"]
.toObject()["moleQueueId"].toDouble()));
break;
case RegisterOpenWith:
emit registerOpenWithResponse(localId);
break;
case ListOpenWithNames:
emit listOpenWithNamesResponse(localId, response["result"].toArray());
break;
case UnregisterOpenWith:
emit unregisterOpenWithResponse(localId);
break;
default:
break;
case ListQueues:
emit queueListReceived(response["result"].toObject());
break;
case SubmitJob:
emit submitJobResponse(
localId, static_cast<unsigned int>(
response["result"].toObject()["moleQueueId"].toDouble()));
break;
case LookupJob:
emit lookupJobResponse(localId, response["result"].toObject());
break;
case CancelJob:
emit cancelJobResponse(static_cast<unsigned int>(
response["result"].toObject()["moleQueueId"].toDouble()));
break;
case RegisterOpenWith:
emit registerOpenWithResponse(localId);
break;
case ListOpenWithNames:
emit listOpenWithNamesResponse(localId, response["result"].toArray());
break;
case UnregisterOpenWith:
emit unregisterOpenWithResponse(localId);
break;
default:
break;
}
}
}

void Client::processNotification(const QJsonObject &notification)
void Client::processNotification(const QJsonObject& notification)
{
if (notification["method"].toString() == "jobStateChanged") {
QJsonObject params = notification["params"].toObject();
emit jobStateChanged(
static_cast<unsigned int>(params["moleQueueId"].toDouble()),
params["oldState"].toString(), params["newState"].toString());
static_cast<unsigned int>(params["moleQueueId"].toDouble()),
params["oldState"].toString(), params["newState"].toString());
}
}

void Client::processError(const QJsonObject &error)
void Client::processError(const QJsonObject& error)
{
int localId = static_cast<int>(error["id"].toDouble());
int errorCode = -1;
QString errorMessage = tr("No message specified.");
QJsonValue errorData;

const QJsonValue &errorValue = error.value(QLatin1String("error"));
const QJsonValue& errorValue = error.value(QLatin1String("error"));
if (errorValue.isObject()) {
const QJsonObject errorObject = errorValue.toObject();
if (errorObject.value("code").isDouble())
Expand All @@ -258,27 +254,28 @@ void Client::processError(const QJsonObject &error)
}

QJsonObject Client::buildRegisterOpenWithRequest(
const QString &name, const QList<QRegularExpression> &filePatterns,
const QJsonObject &handlerMethod)
const QString& name, const QList<QRegularExpression>& filePatterns,
const QJsonObject& handlerMethod)
{
QJsonArray patterns;
foreach (const QRegularExpression &regex, filePatterns) {
QJsonArray patterns;
foreach (const QRegularExpression& regex, filePatterns) {
QJsonObject pattern;
pattern["regex"] = regex.pattern();
pattern["caseSensitive"] = regex.patternOptions().testFlag(QRegularExpression::CaseInsensitiveOption);
pattern["caseSensitive"] = regex.patternOptions().testFlag(
QRegularExpression::CaseInsensitiveOption);
patterns.append(pattern);
}

QJsonObject params;
params["name"] = name;
params["method"] = handlerMethod;
params["patterns"] = patterns;
QJsonObject params;
params["name"] = name;
params["method"] = handlerMethod;
params["patterns"] = patterns;

QJsonObject packet = m_jsonRpcClient->emptyRequest();
packet["method"] = QLatin1String("registerOpenWith");
packet["params"] = params;
QJsonObject packet = m_jsonRpcClient->emptyRequest();
packet["method"] = QLatin1String("registerOpenWith");
packet["params"] = params;

return packet;
return packet;
}

} // End namespace Avogadro
} // namespace Avogadro::MoleQueue
39 changes: 20 additions & 19 deletions avogadro/molequeue/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#include "avogadromolequeueexport.h"

#include <QRegularExpression>
#include <QtCore/QHash>
#include <QtCore/QJsonArray>
#include <QtCore/QJsonObject>
#include <QtCore/QObject>
#include <QRegularExpression>
#include <QtCore/QHash>

namespace Avogadro {
namespace MoleQueue {
Expand All @@ -35,7 +35,7 @@ class AVOGADROMOLEQUEUE_EXPORT Client : public QObject
Q_OBJECT

public:
explicit Client(QObject *parent_ = nullptr);
explicit Client(QObject* parent_ = nullptr);
~Client();

/**
Expand All @@ -50,7 +50,7 @@ public slots:
* @param serverName Name of the socket to connect to, the default of
* "MoleQueue" is usually correct when connecting to the running MoleQueue.
*/
bool connectToServer(const QString &serverName = "MoleQueue");
bool connectToServer(const QString& serverName = "MoleQueue");

/**
* Request the list of queues and programs from the server. The signal
Expand All @@ -65,7 +65,7 @@ public slots:
* @param job The job specification to be submitted to MoleQueue.
* @return The local ID of the job submission request.
*/
int submitJob(const JobObject &job);
int submitJob(const JobObject& job);

/**
* Request information about a job. You should supply the MoleQueue ID that
Expand Down Expand Up @@ -98,8 +98,8 @@ public slots:
executable /absolute/path/to/selected/fileName
~~~
*/
int registerOpenWith(const QString &name, const QString &executable,
const QList<QRegularExpression> &filePatterns);
int registerOpenWith(const QString& name, const QString& executable,
const QList<QRegularExpression>& filePatterns);

/**
* Register a JSON-RPC 2.0 local socket file handler with MoleQueue.
Expand All @@ -125,9 +125,9 @@ executable /absolute/path/to/selected/fileName
~~~
* where <rpcMethod> is replaced by the @a rpcMethod argument.
*/
int registerOpenWith(const QString &name,
const QString &rpcServer, const QString &rpcMethod,
const QList<QRegularExpression> &filePatterns);
int registerOpenWith(const QString& name, const QString& rpcServer,
const QString& rpcMethod,
const QList<QRegularExpression>& filePatterns);

/**
* @brief Request a list of all file handler names.
Expand All @@ -141,7 +141,7 @@ executable /absolute/path/to/selected/fileName
* @return The local ID of the request.
* @sa listOpenWithNames
*/
int unregisterOpenWith(const QString &handlerName);
int unregisterOpenWith(const QString& handlerName);

/**
* @brief flush Flush all pending messages to the server.
Expand Down Expand Up @@ -215,16 +215,17 @@ executable /absolute/path/to/selected/fileName

protected slots:
/** Parse the response object and emit the appropriate signal(s). */
void processResult(const QJsonObject &response);
void processResult(const QJsonObject& response);

/** Parse a notification object and emit the appropriate signal(s). */
void processNotification(const QJsonObject &notification);
void processNotification(const QJsonObject& notification);

/** Parse an error object and emit the appropriate signal(s). */
void processError(const QJsonObject &notification);
void processError(const QJsonObject& notification);

protected:
enum MessageType {
enum MessageType
{
Invalid = -1,
ListQueues,
SubmitJob,
Expand All @@ -235,13 +236,13 @@ protected slots:
UnregisterOpenWith
};

JsonRpcClient *m_jsonRpcClient;
JsonRpcClient* m_jsonRpcClient;
QHash<unsigned int, MessageType> m_requests;

private:
QJsonObject buildRegisterOpenWithRequest(const QString &name,
const QList<QRegularExpression> &filePatterns,
const QJsonObject &handlerMethod);
QJsonObject buildRegisterOpenWithRequest(
const QString& name, const QList<QRegularExpression>& filePatterns,
const QJsonObject& handlerMethod);
};

} // End namespace MoleQueue
Expand Down
Loading

0 comments on commit 4e06ec3

Please sign in to comment.