2#include <ossia/network/context.hpp>
3#include <ossia/network/sockets/udp_socket.hpp>
5#include <ossia-qt/protocols/utils.hpp>
11#include <nano_observer.hpp>
18class qml_udp_outbound_socket
20 ,
public Nano::Observer
21 ,
public protocols_sender
23 W_OBJECT(qml_udp_outbound_socket)
27 ossia::net::udp_send_socket socket;
28 std::atomic_bool alive{
true};
31 const ossia::net::outbound_socket_configuration& conf,
32 boost::asio::io_context& ctx)
39 std::shared_ptr<state> m_state;
42 ossia::net::udp_send_socket& socket;
44 qml_udp_outbound_socket(
45 const ossia::net::outbound_socket_configuration& conf,
46 boost::asio::io_context& ctx)
47 : m_state{std::make_shared<state>(conf, ctx)}
48 , socket{m_state->socket}
52 ~qml_udp_outbound_socket() { m_state->alive =
false; }
54 inline boost::asio::io_context& context() noexcept {
return m_state->socket.m_context; }
58 if(onClose.isCallable())
59 m_state->socket.on_close.connect<&qml_udp_outbound_socket::on_close>(*this);
61 m_state->socket.connect();
63 if(onOpen.isCallable())
64 onOpen.call({qjsEngine(
this)->newQObject(
this)});
67 void close() { m_state->socket.close(); }
74 ossia::qt::run_async(
this, [=,
this] { onClose.call(); }, Qt::AutoConnection);
77 void write(QByteArray buffer)
80 boost::asio::dispatch(st->socket.m_context, [st, buffer] {
82 st->socket.write(buffer.data(), buffer.size());
87 void osc(QByteArray address, QJSValueList values) { this->send_osc(address, values); }
Definition qml_device.cpp:43