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 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: