Repo-Init
 
Loading...
Searching...
No Matches
ZeroMQMonitor Class Reference

#include <ZeroMQMonitor.hpp>

Inheritance diagram for ZeroMQMonitor:
Collaboration diagram for ZeroMQMonitor:

Public Member Functions

 ZeroMQMonitor ()=default
 Constructor.
 
 ZeroMQMonitor (const ZeroMQMonitor &)=delete
 Copy constructor.
 
 ZeroMQMonitor (ZeroMQMonitor &&)=delete
 Move constructor.
 
ZeroMQMonitoroperator= (ZeroMQMonitor)=delete
 Copy assignment operator.
 
ZeroMQMonitoroperator= (ZeroMQMonitor &&)=delete
 Move assignment operator.
 
void startMonitoring (zmq::socket_t *socket, const std::string &monitorAddress)
 
void stopMonitoring ()
 
 ~ZeroMQMonitor () override
 

Private Member Functions

void threadFunc ()
 
void on_monitor_started () override
 
void on_event_connected (const zmq_event_t &, const char *addr_) override
 
void on_event_connect_delayed (const zmq_event_t &, const char *addr_) override
 
void on_event_connect_retried (const zmq_event_t &, const char *addr_) override
 
void on_event_listening (const zmq_event_t &, const char *addr_) override
 
void on_event_bind_failed (const zmq_event_t &, const char *addr_) override
 
void on_event_accepted (const zmq_event_t &, const char *addr_) override
 
void on_event_accept_failed (const zmq_event_t &, const char *addr_) override
 
void on_event_closed (const zmq_event_t &, const char *addr_) override
 
void on_event_close_failed (const zmq_event_t &, const char *addr_) override
 
void on_event_disconnected (const zmq_event_t &, const char *addr_) override
 
void on_event_handshake_failed_no_detail (const zmq_event_t &, const char *addr_) override
 
void on_event_handshake_failed_protocol (const zmq_event_t &, const char *addr_) override
 
void on_event_handshake_failed_auth (const zmq_event_t &, const char *addr_) override
 
void on_event_handshake_succeeded (const zmq_event_t &, const char *addr_) override
 
void on_event_unknown (const zmq_event_t &, const char *addr_) override
 

Static Private Member Functions

static void on_event (const std::string &messageStr, int level, const char *addr=nullptr)
 

Private Attributes

std::unique_ptr< std::thread > _monitorThread
 
std::atomic_flag _shouldStop {false}
 

Detailed Description

Class for monitoring ZeroMQ events on a socket.

The ZeroMQMonitor class provides functionality to monitor ZeroMQ events on a socket. It starts a separate thread to listen for events and invokes corresponding event handlers. The class supports various event types such as connection, binding, acceptance, closure, etc.

Definition at line 17 of file ZeroMQMonitor.hpp.

Constructor & Destructor Documentation

◆ ZeroMQMonitor() [1/3]

ZeroMQMonitor::ZeroMQMonitor ( )
default

Constructor.

◆ ZeroMQMonitor() [2/3]

ZeroMQMonitor::ZeroMQMonitor ( const ZeroMQMonitor & )
delete

Copy constructor.

◆ ZeroMQMonitor() [3/3]

ZeroMQMonitor::ZeroMQMonitor ( ZeroMQMonitor && )
delete

Move constructor.

◆ ~ZeroMQMonitor()

ZeroMQMonitor::~ZeroMQMonitor ( )
inlineoverride

Destructor.

Definition at line 101 of file ZeroMQMonitor.hpp.

101{ stopMonitoring(); }
Here is the call graph for this function:

Member Function Documentation

◆ on_event()

void ZeroMQMonitor::on_event ( const std::string & messageStr,
int level,
const char * addr = nullptr )
staticprivate

Definition at line 15 of file ZeroMQMonitor.cpp.

16{
17 switch (level)
18 {
19 case spdlog::level::trace:
20 spdlog::trace("{} {}", messageStr, addr == nullptr ? "" : addr);
21 break;
22 case spdlog::level::debug:
23 spdlog::debug("{} {}", messageStr, addr == nullptr ? "" : addr);
24 break;
25 case spdlog::level::info:
26 spdlog::info("{} {}", messageStr, addr == nullptr ? "" : addr);
27 break;
28 case spdlog::level::warn:
29 spdlog::warn("{} {}", messageStr, addr == nullptr ? "" : addr);
30 break;
31 case spdlog::level::err:
32 spdlog::error("{} {}", messageStr, addr == nullptr ? "" : addr);
33 break;
34 case spdlog::level::critical:
35 spdlog::critical("{} {}", messageStr, addr == nullptr ? "" : addr);
36 break;
37 default:
38 spdlog::warn("Unknown log level {} {} {}", messageStr, addr == nullptr ? "" : addr, level);
39 break;
40 }
41}
Here is the caller graph for this function:

◆ on_event_accept_failed()

void ZeroMQMonitor::on_event_accept_failed ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 75 of file ZeroMQMonitor.cpp.

76{
77 on_event("Accept failed", spdlog::level::warn, addr_);
78}
static void on_event(const std::string &messageStr, int level, const char *addr=nullptr)
Here is the call graph for this function:

◆ on_event_accepted()

void ZeroMQMonitor::on_event_accepted ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 70 of file ZeroMQMonitor.cpp.

71{
72 on_event("Accepted", spdlog::level::info, addr_);
73}
Here is the call graph for this function:

◆ on_event_bind_failed()

void ZeroMQMonitor::on_event_bind_failed ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 65 of file ZeroMQMonitor.cpp.

66{
67 on_event("Bind failed", spdlog::level::warn, addr_);
68}
Here is the call graph for this function:

◆ on_event_close_failed()

void ZeroMQMonitor::on_event_close_failed ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 85 of file ZeroMQMonitor.cpp.

86{
87 on_event("Close failed", spdlog::level::warn, addr_);
88}
Here is the call graph for this function:

◆ on_event_closed()

void ZeroMQMonitor::on_event_closed ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 80 of file ZeroMQMonitor.cpp.

81{
82 on_event("Closed", spdlog::level::debug, addr_);
83}
Here is the call graph for this function:

◆ on_event_connect_delayed()

void ZeroMQMonitor::on_event_connect_delayed ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 50 of file ZeroMQMonitor.cpp.

51{
52 on_event("Connect delayed", spdlog::level::debug, addr_);
53}
Here is the call graph for this function:

◆ on_event_connect_retried()

void ZeroMQMonitor::on_event_connect_retried ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 55 of file ZeroMQMonitor.cpp.

56{
57 on_event("Connect retried", spdlog::level::debug, addr_);
58}
Here is the call graph for this function:

◆ on_event_connected()

void ZeroMQMonitor::on_event_connected ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 45 of file ZeroMQMonitor.cpp.

46{
47 on_event("Connected", spdlog::level::info, addr_);
48}
Here is the call graph for this function:

◆ on_event_disconnected()

void ZeroMQMonitor::on_event_disconnected ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 90 of file ZeroMQMonitor.cpp.

91{
92 on_event("Disconnected", spdlog::level::info, addr_);
93}
Here is the call graph for this function:

◆ on_event_handshake_failed_auth()

void ZeroMQMonitor::on_event_handshake_failed_auth ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 107 of file ZeroMQMonitor.cpp.

108{
109 on_event("Handshake failed (auth)", spdlog::level::warn, addr_);
110}
Here is the call graph for this function:

◆ on_event_handshake_failed_no_detail()

void ZeroMQMonitor::on_event_handshake_failed_no_detail ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 97 of file ZeroMQMonitor.cpp.

98{
99 on_event("Handshake failed (no detail)", spdlog::level::warn, addr_);
100}
Here is the call graph for this function:

◆ on_event_handshake_failed_protocol()

void ZeroMQMonitor::on_event_handshake_failed_protocol ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 102 of file ZeroMQMonitor.cpp.

103{
104 on_event("Handshake failed (protocol)", spdlog::level::warn, addr_);
105}
Here is the call graph for this function:

◆ on_event_handshake_succeeded()

void ZeroMQMonitor::on_event_handshake_succeeded ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 112 of file ZeroMQMonitor.cpp.

113{
114 on_event("Handshake succeeded", spdlog::level::info, addr_);
115}
Here is the call graph for this function:

◆ on_event_listening()

void ZeroMQMonitor::on_event_listening ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 60 of file ZeroMQMonitor.cpp.

61{
62 on_event("Listening", spdlog::level::debug, addr_);
63}
Here is the call graph for this function:

◆ on_event_unknown()

void ZeroMQMonitor::on_event_unknown ( const zmq_event_t & ,
const char * addr_ )
overrideprivate

Definition at line 129 of file ZeroMQMonitor.cpp.

130{
131 on_event("Unknown event", spdlog::level::warn, addr_);
132}
Here is the call graph for this function:

◆ on_monitor_started()

void ZeroMQMonitor::on_monitor_started ( )
overrideprivate

Definition at line 43 of file ZeroMQMonitor.cpp.

43{ on_event("Monitor started", spdlog::level::info); }
Here is the call graph for this function:

◆ operator=() [1/2]

ZeroMQMonitor & ZeroMQMonitor::operator= ( ZeroMQMonitor && )
delete

Move assignment operator.

◆ operator=() [2/2]

ZeroMQMonitor & ZeroMQMonitor::operator= ( ZeroMQMonitor )
delete

Copy assignment operator.

◆ startMonitoring()

void ZeroMQMonitor::startMonitoring ( zmq::socket_t * socket,
const std::string & monitorAddress )

Start monitoring events on the given socket.

This method starts a separate thread to listen for events on the given socket. The method also sets up the event handlers for various event types.

Parameters
[in]socketZeromq socket
[in]monitorAddressMonitoring address

Definition at line 134 of file ZeroMQMonitor.cpp.

135{
136 if (socket == nullptr)
137 {
138 throw std::invalid_argument("ZeroMQ socket to monitor is nullptr");
139 }
140
141 init(*socket, monitorAddress);
142 _monitorThread = std::make_unique<std::thread>(&ZeroMQMonitor::threadFunc, this);
143}
std::unique_ptr< std::thread > _monitorThread
Here is the call graph for this function:
Here is the caller graph for this function:

◆ stopMonitoring()

void ZeroMQMonitor::stopMonitoring ( )

Stop monitoring events on the socket.

Definition at line 145 of file ZeroMQMonitor.cpp.

146{
147 _shouldStop.test_and_set();
148#ifdef ZMQ_EVENT_MONITOR_STOPPED
149 abort();
150#endif
151
152 // Join the thread
153 if (_monitorThread && _monitorThread->joinable())
154 {
155 _monitorThread->join();
156 _monitorThread.reset();
157 }
158
159 spdlog::info("Monitor stopped");
160}
std::atomic_flag _shouldStop
Here is the caller graph for this function:

◆ threadFunc()

void ZeroMQMonitor::threadFunc ( )
private

Definition at line 7 of file ZeroMQMonitor.cpp.

8{
9 while (!_shouldStop._M_i)
10 {
11 check_event(EVENT_CHECK_TIMEOUT_MS);
12 }
13}
constexpr int EVENT_CHECK_TIMEOUT_MS
Here is the caller graph for this function:

Member Data Documentation

◆ _monitorThread

std::unique_ptr<std::thread> ZeroMQMonitor::_monitorThread
private

Thread for monitoring events.

Definition at line 19 of file ZeroMQMonitor.hpp.

◆ _shouldStop

std::atomic_flag ZeroMQMonitor::_shouldStop {false}
private

Flag to stop monitoring.

Definition at line 20 of file ZeroMQMonitor.hpp.

20{false};

The documentation for this class was generated from the following files: