OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
ws_generic_client_protocol.hpp
1#pragma once
3#include <ossia/network/base/protocol.hpp>
4#include <ossia/network/generic/wrapped_parameter.hpp>
5
6#include <ossia-qt/js_utilities.hpp>
7
8#include <QByteArray>
9#include <QJSValue>
10#include <QList>
11#include <QObject>
12
13#include <verdigris>
14
15class QQmlEngine;
16class QQmlComponent;
17class QWebSocket;
18class QNetworkReply;
19
20namespace ossia
21{
22namespace net
23{
24class WS;
25struct ws_generic_client_parameter_data_base
26{
27 ws_generic_client_parameter_data_base() = default;
28 ws_generic_client_parameter_data_base(const ws_generic_client_parameter_data_base&)
29 = default;
30 ws_generic_client_parameter_data_base(ws_generic_client_parameter_data_base&&)
31 = default;
32 ws_generic_client_parameter_data_base&
33 operator=(const ws_generic_client_parameter_data_base&)
34 = default;
35 ws_generic_client_parameter_data_base&
36 operator=(ws_generic_client_parameter_data_base&&)
37 = default;
38 ws_generic_client_parameter_data_base(const QJSValue& val)
39 : request{val.property("request")}
40 , openListening{val.property("openListening")}
41 , closeListening{val.property("closeListening")}
42 {
43 }
44
45 QJSValue request;
46 QJSValue openListening;
47 QJSValue closeListening;
48};
49
50struct ws_generic_client_parameter_data
51 : public parameter_data
52 , public ws_generic_client_parameter_data_base
53{
54 using base_data_type = ws_generic_client_parameter_data_base;
55 ws_generic_client_parameter_data() = default;
56 ws_generic_client_parameter_data(const ws_generic_client_parameter_data&) = default;
57 ws_generic_client_parameter_data(ws_generic_client_parameter_data&&) = default;
58 ws_generic_client_parameter_data& operator=(const ws_generic_client_parameter_data&)
59 = default;
60 ws_generic_client_parameter_data& operator=(ws_generic_client_parameter_data&&)
61 = default;
62
63 ws_generic_client_parameter_data(const std::string& name)
64 : parameter_data{name}
65 {
66 }
67
68 ws_generic_client_parameter_data(const QJSValue& val)
69 : parameter_data{ossia::qt::make_parameter_data(val)}
70 , ws_generic_client_parameter_data_base{val}
71 {
72 }
73
74 bool valid() const noexcept { return !request.isNull() || type; }
75};
76
77using ws_generic_client_parameter = wrapped_parameter<ws_generic_client_parameter_data>;
78using ws_generic_client_node = ossia::net::wrapped_node<
79 ws_generic_client_parameter_data, ws_generic_client_parameter>;
80
81class OSSIA_EXPORT ws_generic_client_protocol final
82 : public QObject
84{
85 W_OBJECT(ws_generic_client_protocol)
86
87public:
88 ws_generic_client_protocol(const QString& addr, QByteArray code);
89
90 ws_generic_client_protocol(const ws_generic_client_protocol&) = delete;
91 ws_generic_client_protocol(ws_generic_client_protocol&&) = delete;
92 ws_generic_client_protocol& operator=(const ws_generic_client_protocol&) = delete;
93 ws_generic_client_protocol& operator=(ws_generic_client_protocol&&) = delete;
94
95 ~ws_generic_client_protocol() override;
96
97 bool update(ossia::net::node_base& node_base) override;
98
99 bool pull(ossia::net::parameter_base& parameter_base) override;
100
101 bool
102 push(const ossia::net::parameter_base& parameter_base, const ossia::value& v) override;
103 bool push_raw(const ossia::net::full_parameter_data& parameter_base) override;
104
105 bool observe(ossia::net::parameter_base& parameter_base, bool enable) override;
106
107 void set_device(ossia::net::device_base& dev) override;
108
109 static ws_generic_client_parameter_data read_data(const QJSValue& js) { return js; }
110
111public:
112 void sig_push(const ws_generic_client_parameter* arg_1, const ossia::value& v)
113 E_SIGNAL(OSSIA_EXPORT, sig_push, arg_1, v)
114
115 private
116 : void slot_push(const ws_generic_client_parameter*, const ossia::value& v);
117 W_SLOT(slot_push);
118
119private:
120 void on_ready(const QString& host);
121 void apply_reply(QJSValue);
122
123 QQmlEngine* m_engine{};
124 QQmlComponent* m_component{};
125 WS* m_object{};
126
127 QWebSocket* m_websocket{};
128
129 QByteArray m_code;
130 ossia::net::device_base* m_device{};
131 QList<std::pair<QNetworkReply*, const ws_generic_client_parameter*>> m_replies;
132};
133
134using ws_generic_client_device
135 = ossia::net::wrapped_device<ws_generic_client_node, ws_generic_client_protocol>;
136class OSSIA_EXPORT WS : public QObject
137{
138 W_OBJECT(WS)
139
140 W_INLINE_PROPERTY_VALUE(
141 bool, processFromJson, = false, processFromJson, setProcessFromJson,
142 processFromJsonChanged);
143};
144}
145}
146
147Q_DECLARE_METATYPE(ossia::net::ws_generic_client_parameter*)
148W_REGISTER_ARGTYPE(ossia::net::ws_generic_client_parameter*)
149W_REGISTER_ARGTYPE(const ossia::net::ws_generic_client_parameter*)
Root of a device tree.
Definition ossia/network/base/device.hpp:58
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition protocol.hpp:40
The value class.
Definition value.hpp:173
Definition git_info.h:7
Full information about a parameter.
Definition parameter_data.hpp:61