2#include <ossia/network/base/parameter.hpp>
3#include <ossia/network/osc/detail/bundle.hpp>
4#include <ossia/network/osc/detail/message_generator.hpp>
5#include <ossia/network/osc/detail/osc_1_0_policy.hpp>
6#include <ossia/network/osc/detail/osc_packet_processor.hpp>
7#include <ossia/network/osc/detail/osc_receive.hpp>
8#include <ossia/network/osc/detail/osc_value_write_visitor.hpp>
9#include <ossia/network/value/format_value.hpp>
14template <
typename OscVersion>
15struct osc_protocol_common
17 using osc_configuration = OscVersion;
18 template <
typename T,
typename Value_T>
21 auto val = bound_value(addr, std::forward<Value_T>(v));
24 using send_visitor = osc_value_send_visitor<
27 send_visitor vis{addr, addr.get_node().osc_address(), self.writer()};
30 if(
const auto&
logger = self.m_logger.outbound_logger)
32 logger->info(
"[push] {} {}", addr.get_node().osc_address(), val);
42 auto val = bound_value(addr, addr.value());
45 using send_visitor = osc_value_send_visitor<
47 val.apply(send_visitor{addr, addr.address, self.writer()});
49 if(
const auto&
logger = self.m_logger.outbound_logger)
51 logger->info(
"[push_raw] {} {}", addr.address, val);
59 static bool echo_incoming_message(
60 T& self,
const message_origin_identifier&
id,
const parameter_base& addr,
63 if(&
id.protocol == &self)
66 using send_visitor = osc_value_send_visitor<
68 val.apply(send_visitor{addr, addr.get_node().osc_address(), self.writer()});
70 if(
const auto&
logger = self.m_logger.outbound_logger)
72 logger->info(
"[echo] {} {}", addr.get_node().osc_address(), val);
81 self.m_listening.insert(
82 std::make_pair(address.get_node().osc_address(), &address));
84 self.m_listening.erase(address.get_node().osc_address());
90 static void on_received_message(T& self,
const oscpack::ReceivedMessage& m)
92 [[unlikely]]
if(self.learning())
94 auto already_learned = ossia::net::osc_learn(&self.m_device->get_root_node(), m);
99 ossia::net::on_input_message<false>(
100 m.AddressPattern(), ossia::net::osc_message_applier{self.m_id, m},
101 self.m_listening, *self.m_device, self.m_logger);
106template <
typename OscVersion>
107struct osc_protocol_client : osc_protocol_common<OscVersion>
109 template <
typename T,
typename Val_T>
115 return osc_protocol_common<OscVersion>::push(self, addr, std::forward<Val_T>(v));
118 template <
typename T>
124 return osc_protocol_common<OscVersion>::push_raw(self, addr);
127 template <
typename T,
typename Writer>
128 static bool push_bundle(
131 if(
auto bundle = make_bundle(bundle_client_policy<OscVersion>{}, addr, v))
133 writer(bundle->data.data(), bundle->data.size());
134 ossia::buffer_pool::instance().release(std::move(bundle->data));
140 template <
typename T,
typename Writer>
144 if(
auto bundle = make_bundle(bundle_client_policy<OscVersion>{}, addr))
146 writer(bundle->data.data(), bundle->data.size());
147 ossia::buffer_pool::instance().release(std::move(bundle->data));
153 template <
typename T,
typename Writer,
typename Addresses>
154 static bool push_bundle(T& self, Writer writer,
const Addresses& addresses)
156 if(
auto bundle = make_bundle(bundle_client_policy<OscVersion>{}, addresses))
158 writer(bundle->data.data(), bundle->data.size());
159 ossia::buffer_pool::instance().release(std::move(bundle->data));
165 template <
typename T,
typename Writer,
typename Addresses>
166 static bool push_bundle_bounded(T& self, Writer writer,
const Addresses& addresses)
168 return make_bundle_bounded(
169 bundle_bounded_client_policy<OscVersion>{}, addresses,
170 [writer](
const ossia::net::bundle& bundle) {
171 writer(bundle.data.data(), bundle.data.size());
177template <
typename OscVersion>
178struct osc_protocol_server : osc_protocol_common<OscVersion>
180 template <
typename T,
typename Val_T>
186 return osc_protocol_common<OscVersion>::push(self, addr, std::forward<Val_T>(v));
189 template <
typename T>
195 return osc_protocol_common<OscVersion>::push_raw(self, addr);
198 template <
typename T,
typename Writer>
202 if(
auto bundle = make_bundle(bundle_server_policy<OscVersion>{}, addr))
204 writer(bundle->data.data(), bundle->data.size());
205 ossia::buffer_pool::instance().release(std::move(bundle->data));
211 template <
typename T,
typename Writer>
212 static bool push_bundle(
215 if(
auto bundle = make_bundle(bundle_server_policy<OscVersion>{}, addr, v))
217 writer(bundle->data.data(), bundle->data.size());
218 ossia::buffer_pool::instance().release(std::move(bundle->data));
224 template <
typename T,
typename Writer,
typename Addresses>
225 static bool push_bundle(T& self, Writer writer,
const Addresses& addresses)
227 if(
auto bundle = make_bundle(bundle_server_policy<OscVersion>{}, addresses))
229 writer(bundle->data.data(), bundle->data.size());
230 ossia::buffer_pool::instance().release(std::move(bundle->data));
236 template <
typename T,
typename Writer>
238 push_bundle(T& self, Writer writer, tcb::span<ossia::bundle_element> addresses)
240 if(
auto bundle = make_bundle(bundle_server_policy<OscVersion>{}, addresses))
242 writer(bundle->data.data(), bundle->data.size());
243 ossia::buffer_pool::instance().release(std::move(bundle->data));
249 template <
typename T,
typename Writer>
251 push_bundle_bounded(T& self, Writer writer, tcb::span<ossia::bundle_element> addresses)
253 return make_bundle_bounded(
254 bundle_bounded_server_policy<OscVersion>{}, addresses,
255 [writer](
const ossia::net::bundle& bundle) {
256 writer(bundle.data.data(), bundle.data.size());
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The value class.
Definition value.hpp:173
spdlog::logger & logger() noexcept
Where the errors will be logged. Default is stderr.
Definition context.cpp:118
@ GET
The value can be retrieved and changed.
@ SET
The value can be retrieved.
Full information about a parameter.
Definition parameter_data.hpp:61