2#include <ossia/detail/buffer_pool.hpp>
4#include <ossia/network/base/bundle.hpp>
5#include <ossia/network/base/osc_address.hpp>
6#include <ossia/network/osc/detail/osc_1_0_policy.hpp>
7#include <ossia/network/osc/detail/osc_messages.hpp>
8#include <ossia/network/value/value.hpp>
10#include <oscpack/osc/OscOutboundPacketStream.h>
18template <
typename OscPolicy>
19struct bundle_common_policy
21 template <
typename Addr_T>
23 operator()(oscpack::OutboundPacketStream& str,
ossia::value& val,
const Addr_T& addr)
25 if(val = bound_value(addr, val); val.valid())
27 str << oscpack::BeginMessageN(osc_address(addr));
28 val.apply(
typename OscPolicy::dynamic_policy{{str, addr.get_unit()}});
29 str << oscpack::EndMessage();
34template <
typename OscPolicy>
35struct bundle_client_policy
37 template <
typename Addr_T>
39 operator()(oscpack::OutboundPacketStream& str,
ossia::value& val,
const Addr_T& addr)
44 bundle_common_policy<OscPolicy>{}(str, val, addr);
48template <
typename OscPolicy>
49using bundle_server_policy = bundle_common_policy<OscPolicy>;
52template <
typename OscPolicy>
53struct bundle_bounded_common_policy
55 template <
typename Addr_T>
57 operator()(oscpack::OutboundPacketStream& str,
ossia::value& val,
const Addr_T& addr)
61 str << oscpack::BeginMessageN(osc_address(addr));
62 val.apply(
typename OscPolicy::dynamic_policy{{str, addr.get_unit()}});
63 str << oscpack::EndMessage();
68template <
typename OscPolicy>
69struct bundle_bounded_client_policy
71 template <
typename Addr_T>
73 operator()(oscpack::OutboundPacketStream& str,
ossia::value& val,
const Addr_T& addr)
78 bundle_bounded_common_policy<OscPolicy>{}(str, val, addr);
82template <
typename OscPolicy>
83using bundle_bounded_server_policy = bundle_bounded_common_policy<OscPolicy>;
93static inline auto& access_parameter(
const ossia::bundle_element& p)
100 ossia::buffer_pool::buffer data;
104template <
typename NetworkPolicy,
typename Addresses>
106make_bundle(NetworkPolicy add_element_to_bundle,
const Addresses& addresses)
109 bundle ret{ossia::buffer_pool::instance().acquire(max_osc_message_size),
false};
111 oscpack::OutboundPacketStream str(ret.data.data(), max_osc_message_size);
112 str << oscpack::BeginBundleImmediate();
115 for(
const auto& a : addresses)
117 auto& param = access_parameter(a);
118 ret.critical |= param.get_critical();
120 add_element_to_bundle(str, val, param);
122 str << oscpack::EndBundle();
123 ret.data.resize(str.Size());
131catch(
const oscpack::OutOfBufferMemoryException&)
134 "make_bundle_client: message too large (limit is {} bytes)", max_osc_message_size);
137catch(
const std::runtime_error& e)
148template <
typename NetworkPolicy>
149std::optional<bundle> make_bundle(
154 ossia::buffer_pool::instance().acquire(max_osc_message_size), param.critical};
156 oscpack::OutboundPacketStream str(ret.data.data(), max_osc_message_size);
157 str << oscpack::BeginBundleImmediate();
158 auto val = param.value();
159 add_element_to_bundle(str, val, param);
160 str << oscpack::EndBundle();
161 ret.data.resize(str.Size());
169catch(
const oscpack::OutOfBufferMemoryException&)
172 "make_bundle_client: message too large (limit is {} bytes)", max_osc_message_size);
175catch(
const std::runtime_error& e)
186template <
typename NetworkPolicy>
187std::optional<bundle> make_bundle(
193 ossia::buffer_pool::instance().acquire(max_osc_message_size),
194 param.get_critical()};
196 oscpack::OutboundPacketStream str(ret.data.data(), max_osc_message_size);
197 str << oscpack::BeginBundleImmediate();
198 add_element_to_bundle(str, v, param);
199 str << oscpack::EndBundle();
200 ret.data.resize(str.Size());
208catch(
const oscpack::OutOfBufferMemoryException&)
211 "make_bundle_client: message too large (limit is {} bytes)", max_osc_message_size);
214catch(
const std::runtime_error& e)
225template <
typename NetworkPolicy>
226std::optional<bundle> make_bundle(
227 NetworkPolicy add_element_to_bundle,
228 const tcb::span<ossia::bundle_element>& addresses)
231 bundle ret{ossia::buffer_pool::instance().acquire(max_osc_message_size),
false};
233 oscpack::OutboundPacketStream str(ret.data.data(), max_osc_message_size);
234 str << oscpack::BeginBundleImmediate();
236 for(
auto& [p, v] : addresses)
239 ret.critical |= param.get_critical();
240 add_element_to_bundle(str, v, param);
242 str << oscpack::EndBundle();
243 ret.data.resize(str.Size());
251catch(
const oscpack::OutOfBufferMemoryException&)
254 "make_bundle_client: message too large (limit is {} bytes)", max_osc_message_size);
257catch(
const std::runtime_error& e)
268template <
typename NetworkPolicy>
269bool make_bundle_bounded(
270 NetworkPolicy add_element_to_bundle,
271 const tcb::span<ossia::bundle_element>& addresses,
auto callback)
273 bundle ret{ossia::buffer_pool::instance().acquire(max_osc_message_size),
false};
277 oscpack::OutboundPacketStream str(ret.data.data(), max_osc_message_size);
278 str << oscpack::BeginBundleImmediate();
280 for(
auto& [p, v] : addresses)
283 ret.critical |= param.get_critical();
284 add_element_to_bundle(str, v, param);
286 str << oscpack::EndBundle();
287 ret.data.resize(str.Size());
295 catch(
const oscpack::OutOfBufferMemoryException&)
298 "make_bundle_client: message too large (limit is {} bytes)",
299 max_osc_message_size);
301 catch(
const std::runtime_error& e)
309 ossia::buffer_pool::instance().release(std::move(ret.data));
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.
bool critical
Means that the node is very important, e.g. a "play" message.
Definition node_attributes.hpp:92
Full information about a parameter.
Definition parameter_data.hpp:61