Repo-Init
 
Loading...
Searching...
No Matches
ZeroMQServer.hpp File Reference
#include "zeromq/ZeroMQ.hpp"
#include "zeromq/ZeroMQMonitor.hpp"
#include "zeromq/ZeroMQStats.hpp"
#include <functional>
Include dependency graph for ZeroMQServer.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  ZeroMQServer
 

Typedefs

using FPTR_MessageCallback = std::function<bool(const std::vector<zmq::message_t> &, std::vector<zmq::message_t> &)>
 

Functions

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

Typedef Documentation

◆ FPTR_MessageCallback

using FPTR_MessageCallback = std::function<bool(const std::vector<zmq::message_t> &, std::vector<zmq::message_t> &)>

Definition at line 9 of file ZeroMQServer.hpp.

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 107 of file ZeroMQServer.cpp.

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