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)
23 qml_udp_inbound_socket(
24 const ossia::net::inbound_socket_configuration& conf, boost::asio::io_context& ctx)
28 inline boost::asio::io_context& context() noexcept {
return socket.m_context; }
32 if(onClose.isCallable())
33 socket.on_close.connect<&qml_udp_inbound_socket::on_close>(*this);
36 if(onOpen.isCallable())
38 onOpen.call({qjsEngine(
this)->newQObject(
this)});
40 socket.receive([
this](
const char* data, std::size_t sz) {
41 ossia::qt::run_async(
this, [
this, arg = QString::fromUtf8(data, sz)] {
42 if(onMessage.isCallable())
44 onMessage.call({arg});
46 }, Qt::AutoConnection);
52 run_on_qt_thread({ onClose.call(); });
55 void close() { socket.close(); }
63 ossia::net::udp_receive_socket socket;
Definition qml_device.cpp:43