Repo-Init
 
Loading...
Searching...
No Matches
ZeroMQ.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <zmq.hpp>
4
13class ZeroMQ {
14 private:
15 // Internal context
16 std::shared_ptr<zmq::context_t> _contextPtr;
17 // Internal socket
18 std::unique_ptr<zmq::socket_t> _socketPtr;
19
20 // Is currently active
21 bool _isActive{false};
22 // Should be binded
23 bool _isBinded{false};
24 // Address to bind/connect
25 std::string _socketAddr;
26
27 // Initializes class
28 void init(const std::shared_ptr<zmq::context_t> &ctx, const zmq::socket_type &type, const std::string_view &addr,
29 bool isBind);
30
31 public:
38 ZeroMQ(const zmq::socket_type &type, const std::string &addr, bool isBind);
39
47 ZeroMQ(const std::shared_ptr<zmq::context_t> &ctx, const zmq::socket_type &type, const std::string &addr,
48 bool isBind);
49
51 ZeroMQ(const ZeroMQ & /*unused*/) = delete;
52
54 ZeroMQ(ZeroMQ && /*unused*/) = delete;
55
57 ZeroMQ &operator=(ZeroMQ /*unused*/) = delete;
58
60 ZeroMQ &operator=(ZeroMQ && /*unused*/) = delete;
61
66 bool start();
67
71 void stop();
72
77 std::vector<zmq::message_t> recvMessages();
78
84 size_t sendMessages(std::vector<zmq::message_t> &msg);
85
90 [[nodiscard]] const std::unique_ptr<zmq::socket_t> &getSocket() const { return _socketPtr; }
91
96 [[nodiscard]] const std::shared_ptr<zmq::context_t> &getContext() const { return _contextPtr; }
97
102 [[nodiscard]] const std::string &getAddress() const { return _socketAddr; }
103
107 ~ZeroMQ();
108};
ZeroMQ(const ZeroMQ &)=delete
Copy constructor.
void stop()
Definition ZeroMQ.cpp:63
ZeroMQ & operator=(ZeroMQ &&)=delete
Move assignment operator.
std::vector< zmq::message_t > recvMessages()
Definition ZeroMQ.cpp:81
const std::shared_ptr< zmq::context_t > & getContext() const
Definition ZeroMQ.hpp:96
void init(const std::shared_ptr< zmq::context_t > &ctx, const zmq::socket_type &type, const std::string_view &addr, bool isBind)
Definition ZeroMQ.cpp:14
const std::unique_ptr< zmq::socket_t > & getSocket() const
Definition ZeroMQ.hpp:90
ZeroMQ & operator=(ZeroMQ)=delete
Copy assignment operator.
size_t sendMessages(std::vector< zmq::message_t > &msg)
Definition ZeroMQ.cpp:96
const std::string & getAddress() const
Definition ZeroMQ.hpp:102
std::string _socketAddr
Definition ZeroMQ.hpp:25
bool _isActive
Definition ZeroMQ.hpp:21
ZeroMQ(ZeroMQ &&)=delete
Move constructor.
std::unique_ptr< zmq::socket_t > _socketPtr
Definition ZeroMQ.hpp:18
~ZeroMQ()
Definition ZeroMQ.cpp:111
bool _isBinded
Definition ZeroMQ.hpp:23
bool start()
Definition ZeroMQ.cpp:43
std::shared_ptr< zmq::context_t > _contextPtr
Definition ZeroMQ.hpp:16
ZeroMQ(const zmq::socket_type &type, const std::string &addr, bool isBind)
Definition ZeroMQ.cpp:32