Skip to content

Commit

Permalink
Moved JSON.h out of include
Browse files Browse the repository at this point in the history
  • Loading branch information
legocill committed Oct 8, 2024
1 parent b24e895 commit 82e48e4
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 98 deletions.
28 changes: 0 additions & 28 deletions cpp/api/include/RequestSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#ifndef CAMEO_REQUESTSOCKET_H_
#define CAMEO_REQUESTSOCKET_H_

#include "JSON.h"
#include <string>
#include <memory>

Expand Down Expand Up @@ -79,33 +78,6 @@ class RequestSocket {
*/
std::string request(const std::string& requestPart1, const std::string& requestPart2, const std::string& requestPart3, int overrideTimeout = -1);

/**
* Send a request.
* \param request The JSON string request.
* \param overrideTimeout Timeout that overrides the timeout defined previously.
* \return The JSON object response.
*/
json::Object requestJSON(const std::string& request, int overrideTimeout = -1);

/**
* Send a request.
* \param requestPart1 The JSON string request part 1.
* \param requestPart2 The request part 2.
* \param overrideTimeout Timeout that overrides the timeout defined previously.
* \return The JSON object response.
*/
json::Object requestJSON(const std::string& requestPart1, const std::string& requestPart2, int overrideTimeout = -1);

/**
* Send a request.
* \param requestPart1 The JSON string request part 1.
* \param requestPart2 The request part 2.
* \param requestPart3 The request part 3.
* \param overrideTimeout Timeout that overrides the timeout defined previously.
* \return The JSON object response.
*/
json::Object requestJSON(const std::string& requestPart1, const std::string& requestPart2, const std::string& requestPart3, int overrideTimeout = -1);

private:
std::unique_ptr<RequestSocketImpl> m_impl;
};
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/base/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ void This::stop() {
std::unique_ptr<RequestSocket> requestSocket{m_server->createServerRequestSocket()};

std::string request {createStopRequest(m_id, true)};
requestSocket->requestJSON(request);
requestSocket->request(request);
}

void This::startCheckStatesThread() {
Expand Down
File renamed without changes.
33 changes: 0 additions & 33 deletions cpp/api/src/base/RequestSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,4 @@ std::string RequestSocket::request(const std::string& requestPart1, const std::s
return m_impl->request(requestPart1, requestPart2, requestPart3, overrideTimeout);
}

json::Object RequestSocket::requestJSON(const std::string& request, int overrideTimeout) {

std::string reply {this->request(request, overrideTimeout)};

// Get the JSON response.
json::Object response;
json::parse(response, reply);

return response;
}

json::Object RequestSocket::requestJSON(const std::string& requestPart1, const std::string& requestPart2, int overrideTimeout) {

std::string reply {this->request(requestPart1, requestPart2, overrideTimeout)};

// Get the JSON response.
json::Object response;
json::parse(response, reply);

return response;
}

json::Object RequestSocket::requestJSON(const std::string& requestPart1, const std::string& requestPart2, const std::string& requestPart3, int overrideTimeout) {

std::string reply {this->request(requestPart1, requestPart2, requestPart3, overrideTimeout)};

// Get the JSON response.
json::Object response;
json::parse(response, reply);

return response;
}

}
48 changes: 24 additions & 24 deletions cpp/api/src/base/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ bool Server::usesProxy() const {
bool Server::isAvailable(int timeout) const {

try {
m_requestSocket->requestJSON(createSyncRequest(), timeout);
m_requestSocket->request(createSyncRequest(), timeout);
return true;
}
catch (const ConnectionTimeout&) {
Expand Down Expand Up @@ -243,10 +243,10 @@ std::unique_ptr<App> Server::start(const std::string& name, const std::vector<st
json::Object response;

if (This::getId() == -1) {
response = m_requestSocket->requestJSON(createStartRequest(name, args, "", 0, "", 0, false));
response = json::toJSON(m_requestSocket->request(createStartRequest(name, args, "", 0, "", 0, false)));
}
else {
response = m_requestSocket->requestJSON(createStartRequest(name, args, This::getName(), This::getId(), This::getEndpoint().toString(), This::getServer().m_responderProxyPort, linked));
response = json::toJSON(m_requestSocket->request(createStartRequest(name, args, This::getName(), This::getId(), This::getEndpoint().toString(), This::getServer().m_responderProxyPort, linked)));
}

int value {response[message::RequestResponse::VALUE].GetInt()};
Expand Down Expand Up @@ -279,7 +279,7 @@ Response Server::stop(int id, bool immediately) const {
request = createStopRequest(id, false);
}

json::Object response {m_requestSocket->requestJSON(request)};
json::Object response {json::toJSON(m_requestSocket->request(request))};

int value {response[message::RequestResponse::VALUE].GetInt()};
std::string message {response[message::RequestResponse::MESSAGE].GetString()};
Expand All @@ -291,7 +291,7 @@ AppArray Server::connectAll(const std::string& name, int options) {

bool outputStream {((options & option::OUTPUTSTREAM) != 0)};

json::Object response {m_requestSocket->requestJSON(createConnectRequest(name))};
json::Object response {json::toJSON(m_requestSocket->request(createConnectRequest(name)))};

AppArray instances;

Expand Down Expand Up @@ -362,7 +362,7 @@ std::unique_ptr<App> Server::connect(int id, int options) {

bool outputStream {((options & option::OUTPUTSTREAM) != 0)};

json::Object response {m_requestSocket->requestJSON(createConnectWithIdRequest(id))};
json::Object response {json::toJSON(m_requestSocket->request(createConnectWithIdRequest(id)))};

json::Value& applicationInfo {response[message::ApplicationInfoListResponse::APPLICATION_INFO]};
json::Value::Array array = {applicationInfo.GetArray()};
Expand Down Expand Up @@ -411,7 +411,7 @@ void Server::killAllAndWaitFor(const std::string& name) {

bool Server::isAlive(int id) const {

json::Object response {m_requestSocket->requestJSON(createIsAliveRequest(id))};
json::Object response {json::toJSON(m_requestSocket->request(createIsAliveRequest(id)))};

return response[message::IsAliveResponse::IS_ALIVE].GetBool();
}
Expand All @@ -420,7 +420,7 @@ std::vector<App::Config> Server::getApplicationConfigs() const {

std::vector<App::Config> configs;

json::Object response {m_requestSocket->requestJSON(createListRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createListRequest()))};

json::Value& applicationConfigs {response[message::ApplicationConfigListResponse::APPLICATION_CONFIG]};
json::Value::Array array {applicationConfigs.GetArray()};
Expand Down Expand Up @@ -464,7 +464,7 @@ std::vector<App::Info> Server::getApplicationInfos() const {

std::vector<App::Info> infos;

json::Object response {m_requestSocket->requestJSON(createAppsRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createAppsRequest()))};

json::Value& applicationInfos {response[message::ApplicationInfoListResponse::APPLICATION_INFO]};
json::Value::Array array {applicationInfos.GetArray()};
Expand Down Expand Up @@ -512,7 +512,7 @@ std::vector<App::Port> Server::getPorts() const {

std::vector<App::Port> ports;

json::Object response {m_requestSocket->requestJSON(createPortsRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createPortsRequest()))};

json::Value& portInfos {response[message::PortInfoListResponse::PORT_INFO]};
json::Value::Array array {portInfos.GetArray()};
Expand Down Expand Up @@ -540,14 +540,14 @@ state::Value Server::getActualState(int id) const {

state::Value Server::getState(int id) const {

json::Object response {m_requestSocket->requestJSON(createGetStatusRequest(id))};
json::Object response {json::toJSON(m_requestSocket->request(createGetStatusRequest(id)))};

return response[message::StatusEvent::APPLICATION_STATE].GetInt();
}

std::set<state::Value> Server::getPastStates(int id) const {

json::Object response {m_requestSocket->requestJSON(createGetStatusRequest(id))};
json::Object response {json::toJSON(m_requestSocket->request(createGetStatusRequest(id)))};

state::Value applicationStates {response[message::StatusEvent::PAST_APPLICATION_STATES].GetInt()};

Expand Down Expand Up @@ -623,7 +623,7 @@ std::unique_ptr<ConnectionChecker> Server::createConnectionChecker(ConnectionChe

void Server::storeKeyValue(int id, const std::string& key, const std::string& value) {

json::Object response {m_requestSocket->requestJSON(createStoreKeyValueRequest(id, key, value))};
json::Object response {json::toJSON(m_requestSocket->request(createStoreKeyValueRequest(id, key, value)))};

int responseValue {response[message::RequestResponse::VALUE].GetInt()};
if (responseValue == -1) {
Expand All @@ -636,7 +636,7 @@ void Server::storeKeyValue(int id, const std::string& key, const std::string& va

std::string Server::getKeyValue(int id, const std::string& key) {

json::Object response {m_requestSocket->requestJSON(createGetKeyValueRequest(id, key))};
json::Object response {json::toJSON(m_requestSocket->request(createGetKeyValueRequest(id, key)))};

int responseValue {response[message::RequestResponse::VALUE].GetInt()};
if (responseValue == 0) {
Expand All @@ -654,7 +654,7 @@ std::string Server::getKeyValue(int id, const std::string& key) {

void Server::removeKey(int id, const std::string& key) {

json::Object response {m_requestSocket->requestJSON(createRemoveKeyRequest(id, key))};
json::Object response {json::toJSON(m_requestSocket->request(createRemoveKeyRequest(id, key)))};

int value {response[message::RequestResponse::VALUE].GetInt()};
if (value == -1) {
Expand All @@ -667,7 +667,7 @@ void Server::removeKey(int id, const std::string& key) {

int Server::requestPort(int id) {

json::Object response {m_requestSocket->requestJSON(createRequestPortRequest(id))};
json::Object response {json::toJSON(m_requestSocket->request(createRequestPortRequest(id)))};

int value {response[message::RequestResponse::VALUE].GetInt()};
if (value == -1) {
Expand All @@ -679,7 +679,7 @@ int Server::requestPort(int id) {

void Server::setPortUnavailable(int id, int port) {

json::Object response {m_requestSocket->requestJSON(createPortUnavailableRequest(id, port))};
json::Object response {json::toJSON(m_requestSocket->request(createPortUnavailableRequest(id, port)))};

int value {response[message::RequestResponse::VALUE].GetInt()};
if (value == -1) {
Expand All @@ -689,7 +689,7 @@ void Server::setPortUnavailable(int id, int port) {

void Server::releasePort(int id, int port) {

json::Object response {m_requestSocket->requestJSON(createReleasePortRequest(id, port))};
json::Object response {json::toJSON(m_requestSocket->request(createReleasePortRequest(id, port)))};

int value = response[message::RequestResponse::VALUE].GetInt();
if (value == -1) {
Expand Down Expand Up @@ -748,7 +748,7 @@ void Server::initRequestSocket() {

void Server::retrieveServerVersion() {

json::Object response {m_requestSocket->requestJSON(createVersionRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createVersionRequest()))};

m_serverVersion[0] = response[message::VersionResponse::MAJOR].GetInt();
m_serverVersion[1] = response[message::VersionResponse::MINOR].GetInt();
Expand All @@ -757,35 +757,35 @@ void Server::retrieveServerVersion() {

int Server::retrieveStatusPort() {

json::Object response {m_requestSocket->requestJSON(createStreamStatusRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createStreamStatusRequest()))};

return response[message::RequestResponse::VALUE].GetInt();
}

int Server::retrieveStreamPort(const std::string& name) {

json::Object response {m_requestSocket->requestJSON(createOutputPortRequest(name))};
json::Object response {json::toJSON(m_requestSocket->request(createOutputPortRequest(name)))};

return response[message::RequestResponse::VALUE].GetInt();
}

int Server::retrieveResponderProxyPort() {

json::Object response {m_requestSocket->requestJSON(createResponderProxyPortRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createResponderProxyPortRequest()))};

return response[message::RequestResponse::VALUE].GetInt();
}

int Server::retrievePublisherProxyPort() {

json::Object response {m_requestSocket->requestJSON(createPublisherProxyPortRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createPublisherProxyPortRequest()))};

return response[message::RequestResponse::VALUE].GetInt();
}

int Server::retrieveSubscriberProxyPort() {

json::Object response {m_requestSocket->requestJSON(createSubscriberProxyPortRequest())};
json::Object response {json::toJSON(m_requestSocket->request(createSubscriberProxyPortRequest()))};

return response[message::RequestResponse::VALUE].GetInt();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/base/impl/zmq/EventStreamSocketZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void EventStreamSocketZmq::init(Context * context, const Endpoint& endpoint, Req

while (true) {
try {
requestSocket->requestJSON(createSyncRequest());
requestSocket->request(createSyncRequest());
}
catch (const ConnectionTimeout& e) {
// The server is not accessible.
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/base/impl/zmq/OutputStreamSocketZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void OutputStreamSocketZmq::init(Context * context, const Endpoint& endpoint, Re

while (true) {
try {
requestSocket->requestJSON(createSyncStreamRequest(m_name));
requestSocket->request(createSyncStreamRequest(m_name));
}
catch (const ConnectionTimeout&) {
// The server is not accessible.
Expand Down
1 change: 1 addition & 0 deletions cpp/api/src/coms/PublisherSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "Requester.h"
#include "impl/zmq/PublisherZmq.h"
#include "impl/zmq/SubscriberZmq.h"
#include "../base/JSON.h"

namespace cameo {
namespace coms {
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/BasicResponderZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void ResponderZmq::cancel() {

// Create a request socket connected directly to the responder.
std::unique_ptr<RequestSocket> requestSocket {This::getCom().createRequestSocket(This::getEndpoint().withPort(m_responderPort).toString(), m_responderIdentity)};
requestSocket->requestJSON(jsonRequest.dump());
requestSocket->request(jsonRequest.dump());
}

bool ResponderZmq::isCanceled() {
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/BasicResponderZmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define CAMEO_COMS_BASIC_RESPONDERZMQ_H_

#include "../BasicResponderImpl.h"
#include "JSON.h"
#include "../../../base/JSON.h"
#include <zmq.hpp>
#include <atomic>

Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/MultiResponderZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void ResponderZmq::cancel() {

// Create a request socket connected directly to the responder.
std::unique_ptr<RequestSocket> requestSocket {This::getCom().createRequestSocket(m_cancelEndpoint, "")};
requestSocket->requestJSON(jsonRequest.dump());
requestSocket->request(jsonRequest.dump());
}

std::unique_ptr<Request> ResponderZmq::processCancel() {
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/MultiResponderZmq.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define CAMEO_COMS_BASIC_RESPONDERZMQ_H_

#include "../MultiResponderImpl.h"
#include "JSON.h"
#include "../../../base/JSON.h"
#include <zmq.hpp>
#include <atomic>

Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/PublisherZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
#include "PublisherZmq.h"
#include "Application.h"
#include "Messages.h"
#include "JSON.h"
#include "RequestSocket.h"
#include "ContextZmq.h"
#include "../../../base/JSON.h"

namespace cameo {
namespace coms {
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/RequesterZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#include "RequesterZmq.h"
#include "Application.h"
#include "Messages.h"
#include "JSON.h"
#include "ContextZmq.h"
#include "../../../base/JSON.h"

namespace cameo {
namespace coms {
Expand Down
2 changes: 1 addition & 1 deletion cpp/api/src/coms/impl/zmq/SubscriberZmq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#include "SubscriberZmq.h"
#include "Server.h"
#include "Messages.h"
#include "JSON.h"
#include "Waiting.h"
#include "RequestSocket.h"
#include "ContextZmq.h"
#include "IdGenerator.h"
#include "../PublisherImpl.h"
#include "../../../base/JSON.h"

namespace cameo {
namespace coms {
Expand Down
Loading

0 comments on commit 82e48e4

Please sign in to comment.