OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
oscquery_mirror_asio_dense.hpp
1#pragma once
2
3#include <ossia/network/sockets/udp_socket.hpp>
4#include <ossia/protocols/dense/dense_protocol.hpp>
5#include <ossia/protocols/oscquery/oscquery_fwd.hpp>
6
7#include <span>
8
9namespace ossia::oscquery_asio
10{
11class oscquery_mirror_asio_protocol_dense;
12struct oscquery_dense_shared_async_state
13{
14 oscquery_mirror_asio_protocol_dense& self;
15 bool active = true;
16};
17
18class OSSIA_EXPORT oscquery_mirror_asio_protocol_dense final
20{
21 struct osc_sender_impl;
22 struct osc_receiver_impl;
23 using async_state = oscquery_dense_shared_async_state;
24
25public:
26 oscquery_mirror_asio_protocol_dense(
27 ossia::net::network_context_ptr ctx, std::string host,
28 uint16_t local_osc_port = 0);
29 ~oscquery_mirror_asio_protocol_dense() override;
30
31 bool pull(net::parameter_base&) override;
32 std::future<void> pull_async(net::parameter_base&) override;
33 void request(net::parameter_base&) override;
34 bool push(const net::parameter_base&, const ossia::value& v) override;
35 bool push_raw(const ossia::net::full_parameter_data& parameter_base) override;
36 bool push_bundle(const std::vector<const ossia::net::parameter_base*>&) override;
37 bool push_raw_bundle(const std::vector<ossia::net::full_parameter_data>&) override;
38 bool observe(net::parameter_base&, bool) override;
39 bool observe_quietly(net::parameter_base&, bool) override;
40 bool update(net::node_base& b) override;
41 bool echo_incoming_message(
42 const ossia::net::message_origin_identifier& id,
43 const ossia::net::parameter_base& addr, const value& val) override;
44
45 std::future<void> update_async(net::node_base& b) override;
46
47 void stop() override;
48 void set_device(net::device_base& dev) override;
49 ossia::net::device_base& get_device() const { return *m_device; }
50
51 ossia::oscquery::host_info get_host_info() const noexcept;
52
53 void connect() override;
54
55 void set_feedback(bool fb) override;
56private:
57 void update_function();
58 void recompute_nodes();
59 int write_packet(std::span<unsigned char> data);
60
61 friend struct http_async_answer<async_state>;
62 friend struct http_async_value_answer<async_state>;
63 using http_async_request = ossia::oscquery_asio::http_async_request<async_state>;
64 using http_async_value_request
65 = ossia::oscquery_asio::http_async_value_request<async_state>;
66 using http_async_answer = ossia::oscquery_asio::http_async_answer<async_state>;
67 using http_async_value_answer
68 = ossia::oscquery_asio::http_async_value_answer<async_state>;
69 using connection_handler = std::weak_ptr<void>;
70
71 void init();
72
73 void start_http();
74 void start_osc();
75
76 void cleanup_connections();
77
78 // Input
79 bool on_text_ws_message(connection_handler hdl, const std::string& message);
80 bool on_binary_ws_message(connection_handler hdl, const std::string& message);
81 bool on_value_http_message(const std::string& address, const std::string& message);
82 void on_osc_message(const oscpack::ReceivedMessage& m);
83 void process_raw_osc_data(const char* data, std::size_t sz);
84
85 // Output
86 void http_send_message(const std::string& str);
87 void http_send_message(const rapidjson::StringBuffer& str);
88
89 // ZeroConf
90 bool query_connected();
91 void query_stop();
92
93 void on_nodeRenamed(const ossia::net::node_base& n, std::string oldname);
94
95 ossia::net::network_context_ptr m_ctx;
96
97 std::unique_ptr<osc_receiver_impl> m_oscServer;
98
99 std::shared_ptr<oscquery_dense_shared_async_state> m_async_state;
100 std::atomic_bool m_hasWS{};
101
102 // Listening status of the local software
103 net::listened_parameters m_listening;
104
105 ossia::net::device_base* m_device{};
106
107 std::promise<void> m_namespacePromise;
108
109 std::string m_queryHost;
110 std::string m_queryPort;
111 std::string m_httpHost;
112 int m_osc_port{};
113
114 std::unique_ptr<http_async_client_context> m_http;
115 ossia::oscquery::host_info m_host_info;
116
117 ossia::timer m_timer;
118
119 ossia::flat_set<ossia::net::parameter_base*, ossia::net::parameter_alphabetical_sort>
120 m_sorted_params;
121
122 std::optional<ossia::net::udp_send_socket> to_client;
123 ossia::net::message_origin_identifier m_id;
124 std::atomic<bool> m_feedback{true};
125 bool m_zombie_on_remove{true};
126};
127}
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Definition git_info.h:7
Full information about a parameter.
Definition parameter_data.hpp:61
Represents the capabilities of an OSCQuery server.
Definition host_info.hpp:12