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>
17class qml_udp_inbound_socket
19 ,
public Nano::Observer
21 W_OBJECT(qml_udp_inbound_socket)
25 ossia::net::udp_receive_socket socket;
26 std::atomic_bool alive{
true};
29 const ossia::net::inbound_socket_configuration& conf,
30 boost::asio::io_context& ctx)
36 qml_udp_inbound_socket(
37 const ossia::net::inbound_socket_configuration& conf, boost::asio::io_context& ctx)
38 : m_state{std::make_shared<state>(conf, ctx)}
42 ~qml_udp_inbound_socket() { m_state->alive =
false; }
44 inline boost::asio::io_context& context() noexcept {
return m_state->socket.m_context; }
48 if(onClose.isCallable())
49 m_state->socket.on_close.connect<&qml_udp_inbound_socket::on_close>(*this);
51 m_state->socket.open();
52 if(onOpen.isCallable())
53 onOpen.call({qjsEngine(
this)->newQObject(
this)});
56 auto self = QPointer{
this};
57 st->socket.receive([st, self](
const char* data, std::size_t sz) {
62 [self, arg = QByteArray(data, sz)] {
65 if(self->onMessage.isCallable())
67 self->onMessage.call({qjsEngine(self.get())->toScriptValue(arg)});
78 ossia::qt::run_async(
this, [=,
this] { onClose.call(); }, Qt::AutoConnection);
81 void close() { m_state->socket.close(); }
90 std::shared_ptr<state> m_state;
Definition qml_device.cpp:43