Commit 8ac35454 authored by legoc's avatar legoc
Browse files

(split2) Implemented request server version. Console application updated to...

(split2) Implemented request server version. Console application updated to provide the information.
parent b4721f50
......@@ -149,6 +149,9 @@ void This::initApplication(int argc, char *argv[]) {
// Create the request socket. The server endpoint has been defined.
Services::initRequestSocket();
// Retrieve the server version.
Services::retrieveServerVersion();
string nameId = tokens[3];
int index = nameId.find_last_of('.');
......
......@@ -53,6 +53,9 @@ Server::Server(const std::string& endpoint, int timeoutMs) :
// Create the request socket. The server endpoint has been defined.
Services::initRequestSocket();
// Retrieve the server version.
Services::retrieveServerVersion();
// Manage the ConnectionTimeout exception that can occur.
try {
// Start the event thread.
......
......@@ -33,6 +33,10 @@ Services::Services() :
m_port(0),
m_statusPort(0),
m_impl(nullptr) {
m_serverVersion[0] = 0;
m_serverVersion[1] = 0;
m_serverVersion[2] = 0;
}
Services::~Services() {
......@@ -107,6 +111,20 @@ bool Services::isAvailable(int timeout) const {
return m_impl->isAvailable(m_requestSocket.get(), timeout);
}
void Services::retrieveServerVersion() {
// Get the version.
unique_ptr<zmq::message_t> reply = m_requestSocket->request(m_impl->createVersionRequest());
// Get the JSON response.
json::Object response;
json::parse(response, reply.get());
m_serverVersion[0] = response[message::VersionResponse::MAJOR].GetInt();
m_serverVersion[1] = response[message::VersionResponse::MINOR].GetInt();
m_serverVersion[2] = response[message::VersionResponse::REVISION].GetInt();
}
void Services::initStatus() {
// Get the status port.
......
......@@ -47,6 +47,7 @@ public:
const std::string& getStatusEndpoint() const;
bool isAvailable(int timeout) const;
void retrieveServerVersion();
void initStatus();
std::unique_ptr<EventStreamSocket> openEventStream();
std::unique_ptr<OutputStreamSocket> createOutputStreamSocket(int port);
......@@ -54,6 +55,7 @@ public:
std::unique_ptr<RequestSocketImpl> createRequestSocket(const std::string& endpoint, int timeout);
std::string m_serverEndpoint;
int m_serverVersion[3];
std::string m_url;
int m_port;
int m_statusPort;
......
......@@ -62,6 +62,15 @@ std::string ServicesImpl::createSyncRequest() const {
return request.toString();
}
std::string ServicesImpl::createVersionRequest() const {
json::StringObject request;
request.pushKey(message::TYPE);
request.pushInt(message::IMPL_VERSION);
return request.toString();
}
std::string ServicesImpl::createIsAliveRequest(int id) const {
json::StringObject request;
......
......@@ -35,6 +35,7 @@ public:
int getTimeout() const;
std::string createSyncRequest() const;
std::string createVersionRequest() const;
std::string createStartRequest(const std::string& name, const std::vector<std::string> & args, const std::string& instanceReference) const;
std::string createStopRequest(int id) const;
std::string createKillRequest(int id) const;
......
......@@ -53,6 +53,7 @@ namespace message {
const int RESPONSE = 26;
const int STARTED_UNMANAGED = 27;
const int TERMINATED_UNMANAGED = 28;
const int IMPL_VERSION = 29;
namespace Event {
constexpr const char* CANCEL = "CANCEL";
......@@ -234,6 +235,13 @@ namespace message {
namespace TerminatedUnmanagedRequest {
constexpr const char* ID = "id"; // required int32 id = 1;
}
namespace VersionResponse {
constexpr const char* MAJOR = "major";
constexpr const char* MINOR = "minor";
constexpr const char* REVISION = "revision";
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment