OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
mqtt_protocol.hpp
1#pragma once
2#include <ossia/detail/audio_spin_mutex.hpp>
3#include <ossia/detail/variant.hpp>
4#include <ossia/network/base/protocol.hpp>
5#include <ossia/network/context.hpp>
6#include <ossia/network/sockets/configuration.hpp>
7
8#include <boost/asio/cancellation_signal.hpp>
9#include <boost/asio/strand.hpp>
10#include <boost/unordered/concurrent_flat_map.hpp>
11namespace ossia::net
12{
13using strand_type
14 = decltype(boost::asio::make_strand(std::declval<boost::asio::io_context&>()));
15
16struct mqtt5_configuration
17{
18 ossia::variant<tcp_client_configuration, ws_client_configuration> transport;
19};
20
21struct mqtt5_client_base;
22
23class OSSIA_EXPORT mqtt5_protocol
24 : public ossia::net::can_learn<ossia::net::protocol_base>
25 , public Nano::Observer
26{
27public:
28 explicit mqtt5_protocol(
29 ossia::net::network_context_ptr, const mqtt5_configuration& conf);
30 ~mqtt5_protocol();
31
32 bool pull(parameter_base&) override;
33 bool push(const parameter_base&, const value& v) override;
34 bool push_raw(const full_parameter_data&) override;
35 bool observe(parameter_base&, bool) override;
36 bool update(node_base& node_base) override;
37 void set_device(device_base& dev) override;
38
39 void set_learning(bool);
40 void on_learn(const std::string& topic, const std::string& payload);
41 void on_message(const std::string& topic, const std::string& payload);
42
43 void stop() override;
44
45private:
46 void on_new_param(const parameter_base& param);
47 void on_removed_param(const parameter_base& param);
48 void on_subscribe(parameter_base& param);
49 void on_unsubscribe(const parameter_base& param);
50
51 ossia::net::network_context_ptr m_context;
52 ossia::net::device_base* m_device{};
53 mqtt5_configuration m_conf{};
54 std::unique_ptr<mqtt5_client_base> m_client;
55
56 struct subscribe_state;
57 boost::unordered::concurrent_flat_map<std::string, ossia::net::parameter_base*>
58 m_topics;
59 std::shared_ptr<subscribe_state> m_root;
60
61 strand_type m_strand;
62};
63}
Root of a device tree.
Definition ossia/network/base/device.hpp:58