rad 6.2.0
Loading...
Searching...
No Matches
topicSub.hpp
Go to the documentation of this file.
1
9#ifndef RAD_TOPIC_SUB_HPP
10#define RAD_TOPIC_SUB_HPP
11
12#include <rad/topicHandler.hpp>
13
14#include <azmq/message.hpp>
15#include <azmq/socket.hpp>
16
17#include <boost/asio.hpp>
18
19#include <array>
20
21namespace rad {
22
28class TopicSub {
29 public:
30 using TopicHandler_t = std::function<void(const std::string&, const void*, size_t)>;
31 using TopicHandlerMap_t = std::unordered_map<std::string, TopicHandler_t>;
32
33 TopicSub(boost::asio::io_context& ios, std::unique_ptr<TopicHandler>&& fallback);
34 ~TopicSub();
35
36 void Subscribe(const std::string& topic_name);
37 void Subscribe(const std::string& topic_name, TopicHandler_t handler);
38 void Unsubscribe(const std::string& topic_name);
39
40 void Connect(const std::string& endpoint);
41 void Disconnect(const std::string& endpoint);
42 void Flush();
43
44 TopicSub(const TopicSub&) = delete;
45 TopicSub& operator=(const TopicSub&) = delete;
46 // Enable moving
47 TopicSub(TopicSub&& rhs) = default;
48
49 private:
50 void Register();
51 void Callback(boost::system::error_code const& error_code, azmq::message& msg, size_t nbytes);
52
53 azmq::sub_socket m_socket;
54 std::unique_ptr<TopicHandler> m_fallback_handler;
55 TopicHandlerMap_t m_handlers_map;
56};
57
58} // namespace rad
59
60#endif // RAD_TOPIC_SUB_HPP
Definition topicSub.hpp:28
std::unordered_map< std::string, TopicHandler_t > TopicHandlerMap_t
Definition topicSub.hpp:31
std::function< void(const std::string &, const void *, size_t)> TopicHandler_t
Definition topicSub.hpp:30
~TopicSub()
Definition topicSub.cpp:35
void Disconnect(const std::string &endpoint)
Definition topicSub.cpp:108
void Flush()
Definition topicSub.cpp:118
TopicSub & operator=(const TopicSub &)=delete
void Subscribe(const std::string &topic_name)
Definition topicSub.cpp:52
TopicSub(const TopicSub &)=delete
void Unsubscribe(const std::string &topic_name)
Definition topicSub.cpp:74
TopicSub(boost::asio::io_context &ios, std::unique_ptr< TopicHandler > &&fallback)
Definition topicSub.cpp:27
TopicSub(TopicSub &&rhs)=default
void Connect(const std::string &endpoint)
Definition topicSub.cpp:85
Definition actionsApp.cpp:23
public header file.