Repo-Init
 
Loading...
Searching...
No Matches
ZeroMQServer.cpp File Reference
#include "zeromq/ZeroMQServer.hpp"
#include "Version.h"
#include "utils/ErrorHelpers.hpp"
#include "utils/Hasher.hpp"
#include <spdlog/spdlog.h>
Include dependency graph for ZeroMQServer.cpp:

Go to the source code of this file.

Functions

bool ZeroMQServerMessageCallback (const std::vector< zmq::message_t > &recvMsgs, std::vector< zmq::message_t > &replyMsgs)
 

Variables

constexpr uint32_t LOG_LEVEL_ID = ('L' | ('O' << 8) | ('G' << 16) | ('L' << 24))
 
constexpr uint32_t VERSION_INFO_ID = ('V' | ('E' << 8) | ('R' << 16) | ('I' << 24))
 
constexpr uint32_t PING_PONG_ID = ('P' | ('I' << 8) | ('N' << 16) | ('G' << 24))
 
constexpr uint32_t STATUS_CHECK_ID = ('S' | ('C' << 8) | ('H' << 16) | ('K' << 24))
 

Function Documentation

◆ ZeroMQServerMessageCallback()

bool ZeroMQServerMessageCallback ( const std::vector< zmq::message_t > & recvMsgs,
std::vector< zmq::message_t > & replyMsgs )

ZeroMQ message received callback

Parameters
[in]recvMsgsReceived messages
[out]replyMsgsReply messages returned by callback
Returns
true If the callback successfully processes the received messages
false otherwise

Definition at line 104 of file ZeroMQServer.cpp.

105{
106 spdlog::trace("Received {} messages", recvMsgs.size());
107 replyMsgs.clear();
108
109 std::string replyBody;
110 int reply = ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL;
111 switch (*(static_cast<const uint64_t *>(recvMsgs[0].data())))
112 {
113 case LOG_LEVEL_ID: {
114 if (recvMsgs.size() != 2)
115 {
116 spdlog::error("Received unknown number of messages for log level change");
117 break;
118 }
119
120 spdlog::warn("Log level change request received");
121 const auto receivedMsg = std::string(static_cast<const char *>(recvMsgs[1].data()), recvMsgs[1].size());
122
123 if (receivedMsg == "v")
124 {
125 spdlog::set_level(spdlog::level::info);
126 }
127 if (receivedMsg == "vv")
128 {
129 spdlog::set_level(spdlog::level::debug);
130 }
131 if (receivedMsg == "vvv")
132 {
133 spdlog::set_level(spdlog::level::trace);
134 }
135 reply = ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
136 break;
137 }
138 case VERSION_INFO_ID: {
139 if (recvMsgs.size() != 1)
140 {
141 spdlog::error("Received unknown number of messages for version information");
142 break;
143 }
144
145 reply = ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
146 replyBody = PROJECT_FULL_VERSION_STRING;
147 break;
148 }
149 case PING_PONG_ID: {
150 if (recvMsgs.size() != 1)
151 {
152 spdlog::error("Received unknown number of messages for ping");
153 break;
154 }
155
156 reply = ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
157 replyBody = "PONG";
158 break;
159 }
160 case STATUS_CHECK_ID: {
161 if (recvMsgs.size() != 1)
162 {
163 spdlog::error("Received unknown number of messages for status check");
164 break;
165 }
166
167 reply = ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
168
169 std::ostringstream oss;
170 oss << "{";
171 for (const auto &entry : vCheckFlag)
172 {
173 oss << "\"" << entry.first << "\":" << (entry.second->_M_i ? "1," : "0,");
174 }
175 replyBody = oss.str();
176 replyBody.replace(replyBody.size() - 1, 1, "}");
177 break;
178 }
179 /* ################################################################################### */
180 /* ############################# MAKE MODIFICATIONS HERE ############################# */
181 /* ################################################################################### */
182
183 /* ################################################################################### */
184 /* ################################ END MODIFICATIONS ################################ */
185 /* ################################################################################### */
186 default:
187 spdlog::error("Unknown command received from control");
188 break;
189 }
190
191 // Prepare reply
192 replyMsgs.emplace_back(&reply, sizeof(reply));
193 replyMsgs.emplace_back(replyBody.c_str(), replyBody.size());
194
195 return reply == ZMQ_EVENT_HANDSHAKE_SUCCEEDED;
196}
std::vector< std::pair< std::string, std::shared_ptr< std::atomic_flag > > > vCheckFlag
Global variable to check if the servers are running.
constexpr uint32_t PING_PONG_ID
constexpr uint32_t VERSION_INFO_ID
constexpr uint32_t LOG_LEVEL_ID
constexpr uint32_t STATUS_CHECK_ID
Here is the caller graph for this function:

Variable Documentation

◆ LOG_LEVEL_ID

uint32_t LOG_LEVEL_ID = ('L' | ('O' << 8) | ('G' << 16) | ('L' << 24))
constexpr

Definition at line 9 of file ZeroMQServer.cpp.

◆ PING_PONG_ID

uint32_t PING_PONG_ID = ('P' | ('I' << 8) | ('N' << 16) | ('G' << 24))
constexpr

Definition at line 11 of file ZeroMQServer.cpp.

◆ STATUS_CHECK_ID

uint32_t STATUS_CHECK_ID = ('S' | ('C' << 8) | ('H' << 16) | ('K' << 24))
constexpr

Definition at line 12 of file ZeroMQServer.cpp.

◆ VERSION_INFO_ID

uint32_t VERSION_INFO_ID = ('V' | ('E' << 8) | ('R' << 16) | ('I' << 24))
constexpr

Definition at line 10 of file ZeroMQServer.cpp.