2#include <ossia/network/base/osc_address.hpp>
3#include <ossia/network/base/parameter.hpp>
4#include <ossia/network/base/parameter_data.hpp>
5#include <ossia/network/osc/detail/bundle.hpp>
6#include <ossia/network/osc/detail/osc.hpp>
7#include <ossia/network/osc/detail/osc_1_1_extended_policy.hpp>
8#include <ossia/network/osc/detail/osc_value_write_visitor.hpp>
9#include <ossia/network/sockets/udp_socket.hpp>
10#include <ossia/network/sockets/writers.hpp>
12namespace ossia::oscquery
14template <
typename OscVersion>
15struct oscquery_protocol_common
17 template <
typename Protocol,
typename Socket,
typename Addr>
18 static void osc_send_message(
19 Protocol& proto, Socket& socket,
const Addr& addr,
const ossia::value& val)
21 using namespace ossia::net;
23 = osc_value_send_visitor<Addr, OscVersion, socket_writer<udp_send_socket>>;
24 send_visitor vis{addr, ossia::net::osc_address(addr), {socket}};
27 template <
typename Protocol,
typename Addr>
29 osc_send_message(Protocol& proto,
const Addr& addr,
const ossia::value& val)
31 osc_send_message(proto, proto.osc_sender(), addr, val);
34 template <
typename Protocol,
typename Socket,
typename Addr>
35 static void ws_send_binary_message(
36 Protocol& proto, Socket&& socket,
const Addr& addr,
const ossia::value& val)
38 using namespace ossia::net;
39 using write_visitor = osc_value_write_visitor<Addr, OscVersion>;
41 auto& pool = buffer_pool::instance();
42 auto buf = pool.acquire();
44 write_visitor vis{addr, ossia::net::osc_address(addr), buf};
47 socket.send_binary_message({buf.data(), buf.size()});
49 pool.release(std::move(buf));
52 template <
typename Protocol,
typename Addr>
54 ws_send_binary_message(Protocol& proto,
const Addr& addr,
const ossia::value& val)
56 using namespace ossia::net;
57 using write_visitor = osc_value_write_visitor<Addr, OscVersion>;
59 auto& pool = buffer_pool::instance();
60 auto buf = pool.acquire();
62 write_visitor vis{addr, ossia::net::osc_address(addr), buf};
64 proto.ws_client().send_binary_message({buf.data(), buf.size()});
66 pool.release(std::move(buf));
69 template <
typename Protocol,
typename Addr>
70 static bool push(Protocol& proto,
const Addr& addr,
const ossia::value& v)
72 if(
auto val = bound_value(addr, v); val.valid())
75 const bool critical = addr.get_critical();
76 const bool has_ws = proto.ws_connected();
77 const bool has_osc = proto.osc_connected();
78 if((!
critical || !has_ws) && has_osc)
84 osc_send_message(proto, addr, val);
94 ws_send_binary_message(proto, addr, val);
107template <
typename OscVersion>
108struct oscquery_protocol_client : oscquery_protocol_common<OscVersion>
110 template <
typename T,
typename Addr_T,
typename Val_T>
111 static bool push(T& self,
const Addr_T& addr, Val_T&& v)
116 return oscquery_protocol_common<OscVersion>::push(
117 self, addr, std::forward<Val_T>(v));
120 template <
typename Protocol,
typename Addresses>
121 requires(!
requires(Protocol p) { p.ws_connected(); })
122 static bool push_bundle(Protocol& proto,
const Addresses& addresses)
129 template <
typename Protocol,
typename Addresses>
130 requires requires(Protocol p) { p.ws_connected(); }
131 static bool push_bundle(Protocol& proto,
const Addresses& addresses)
133 if(
auto bundle = ossia::net::make_bundle(
134 ossia::net::bundle_client_policy<OscVersion>{}, addresses))
136 const bool critical = bundle->critical;
137 const bool has_ws = proto.ws_connected();
138 const bool has_osc = proto.osc_connected();
139 if((!
critical || !has_ws) && has_osc)
141 proto.osc_sender().write(bundle->data.data(), bundle->data.size());
142 ossia::buffer_pool::instance().release(std::move(bundle->data));
146 proto.ws_client().send_binary_message(
147 {bundle->data.data(), bundle->data.size()});
The value class.
Definition value.hpp:173
@ GET
The value can be retrieved and changed.
bool critical
Means that the node is very important, e.g. a "play" message.
Definition node_attributes.hpp:92