OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
qml_ws_inbound_socket.hpp
1#pragma once
2#include <ossia/network/context.hpp>
3#include <ossia/network/sockets/udp_socket.hpp>
4
5#include <ossia-qt/protocols/utils.hpp>
6
7#include <QJSValue>
8#include <QObject>
9#include <QQmlEngine>
10
11#include <nano_observer.hpp>
12
13#include <verdigris>
14
15namespace ossia::qt
16{
17class qml_websocket_inbound_socket
18 : public QObject
19 , public Nano::Observer
20{
21 W_OBJECT(qml_websocket_inbound_socket)
22public:
23 struct state
24 {
25 boost::asio::io_context& context;
26 std::atomic_bool alive{true};
27
28 state(boost::asio::io_context& ctx)
29 : context{ctx}
30 {
31 }
32 };
33
34 qml_websocket_inbound_socket(
35 const ossia::net::inbound_socket_configuration& conf, boost::asio::io_context& ctx)
36 : m_state{std::make_shared<state>(ctx)}
37 {
38 // FIXME
39 // WebSocket server implementation simplified for now
40 }
41
42 ~qml_websocket_inbound_socket() { m_state->alive = false; }
43
44 inline boost::asio::io_context& context() noexcept { return m_state->context; }
45
46 void open()
47 {
48 if(onOpen.isCallable())
49
50 onOpen.call({qjsEngine(this)->newQObject(this)});
51 }
52
53 void close()
54 {
55 if(!m_state->alive)
56 return;
57 ossia::qt::run_async(this, [=, this] { onClose.call(); }, Qt::AutoConnection);
58 }
59 W_SLOT(close)
60
61 QJSValue onOpen;
62 QJSValue onClose;
63 QJSValue onError;
64 QJSValue onConnection;
65 QJSValue onBytes;
66 QJSValue onTextMessage;
67 QJSValue onBinaryMessage;
68
69private:
70 std::shared_ptr<state> m_state;
71};
72}
Definition qml_device.cpp:43