2#include <ossia/network/context.hpp>
3#if defined(BOOST_ASIO_HAS_LOCAL_SOCKETS)
4#include <ossia/network/sockets/unix_socket.hpp>
6#include <ossia-qt/protocols/utils.hpp>
12#include <nano_observer.hpp>
18class qml_unix_datagram_outbound_socket
20 ,
public Nano::Observer
21 ,
public protocols_sender
23 W_OBJECT(qml_unix_datagram_outbound_socket)
25 qml_unix_datagram_outbound_socket(
26 const ossia::net::fd_configuration& conf, boost::asio::io_context& ctx)
30 inline boost::asio::io_context& context() noexcept {
return socket.m_context; }
34 if(onClose.isCallable())
35 socket.on_close.connect<&qml_unix_datagram_outbound_socket::on_close>(
this);
39 if(onOpen.isCallable())
41 onOpen.call({qjsEngine(
this)->newQObject(
this)});
44 void close() { socket.close(); }
49 run_on_qt_thread({ onClose.call(); });
52 void write(QByteArray buffer)
54 run_on_asio_thread({ socket.write(buffer.data(), buffer.size()); });
58 void osc(QByteArray address, QJSValueList values) { this->send_osc(address, values); }
65 ossia::net::unix_datagram_socket socket;
68class qml_unix_stream_outbound_socket
70 ,
public Nano::Observer
71 ,
public protocols_sender
73 W_OBJECT(qml_unix_stream_outbound_socket)
75 qml_unix_stream_outbound_socket(
76 const ossia::net::fd_configuration& conf, boost::asio::io_context& ctx)
80 inline boost::asio::io_context& context() noexcept {
return socket.m_context; }
86 if(onOpen.isCallable())
87 socket.on_open.connect<&qml_unix_stream_outbound_socket::on_open>(
this);
88 if(onClose.isCallable())
89 socket.on_close.connect<&qml_unix_stream_outbound_socket::on_close>(
this);
90 if(onError.isCallable())
91 socket.on_fail.connect<&qml_unix_stream_outbound_socket::on_fail>(
this);
94 catch(
const std::exception& e)
96 if(onError.isCallable())
98 onError.call({QString::fromStdString(e.what())});
103 void write(QByteArray buffer)
105 run_on_asio_thread({ socket.write(buffer.data(), buffer.size()); });
109 void close() { socket.close(); }
114 run_on_qt_thread({ onOpen.call({qjsEngine(
this)->newQObject(
this)}); });
118 run_on_qt_thread({ onError.call(); });
122 run_on_qt_thread({ onClose.call(); });
125 void osc(QByteArray address, QJSValueList values) { this->send_osc(address, values); }
132 ossia::net::unix_stream_client socket;
Definition qml_device.cpp:43