2#include <ossia/network/context.hpp>
3#include <ossia/network/sockets/tcp_socket.hpp>
5#include <ossia-qt/protocols/utils.hpp>
11#include <nano_observer.hpp>
17class qml_tcp_outbound_socket
19 ,
public Nano::Observer
20 ,
public protocols_sender
22 W_OBJECT(qml_tcp_outbound_socket)
24 qml_tcp_outbound_socket(
25 const ossia::net::outbound_socket_configuration& conf,
26 boost::asio::io_context& ctx)
30 inline boost::asio::io_context& context() noexcept {
return socket.m_context; }
36 if(onOpen.isCallable())
37 socket.on_open.connect<&qml_tcp_outbound_socket::on_open>(
this);
38 if(onClose.isCallable())
39 socket.on_close.connect<&qml_tcp_outbound_socket::on_close>(
this);
40 if(onError.isCallable())
41 socket.on_fail.connect<&qml_tcp_outbound_socket::on_fail>(
this);
44 catch(
const std::exception& e)
46 if(onError.isCallable())
48 onError.call({QString::fromStdString(e.what())});
53 void write(QByteArray buffer)
55 run_on_asio_thread({ socket.write(buffer.data(), buffer.size()); });
59 void close() { socket.close(); }
64 run_on_qt_thread({ onOpen.call({qjsEngine(
this)->newQObject(
this)}); });
68 run_on_qt_thread({ onError.call(); });
72 run_on_qt_thread({ onClose.call(); });
75 void osc(QByteArray address, QJSValueList values) { this->send_osc(address, values); }
83 ossia::net::tcp_client socket;
Definition qml_device.cpp:43