2#include <ossia/network/base/protocol.hpp>
3#include <ossia/network/generic/wrapped_parameter.hpp>
5#include <ossia-qt/js_utilities.hpp>
16class QNetworkAccessManager;
22struct http_parameter_data_base
24 http_parameter_data_base() =
default;
25 http_parameter_data_base(
const http_parameter_data_base&) =
default;
26 http_parameter_data_base(http_parameter_data_base&&) =
default;
27 http_parameter_data_base& operator=(
const http_parameter_data_base&) =
default;
28 http_parameter_data_base& operator=(http_parameter_data_base&&) =
default;
29 http_parameter_data_base(
const QJSValue& val)
31 if(
auto r = val.property(
"request"); r.isString() || r.isCallable())
38 auto a = val.property(
"answer");
45 if(
auto data = val.property(
"requestData"); data.isString() || data.isCallable())
49 if(
auto post = val.property(
"method"); post.toString().toLower() ==
"post")
53 if(
auto r = val.property(
"onRead"); r.isCallable())
57 if(
auto r = val.property(
"onReadString"); r.isCallable())
63 bool requestIsValid() const noexcept
65 return !request.isUndefined() && !request.isNull();
71 QJSValue onReadString;
75struct http_parameter_data
76 :
public parameter_data
77 ,
public http_parameter_data_base
79 using base_data_type = http_parameter_data_base;
80 http_parameter_data() =
default;
81 http_parameter_data(
const http_parameter_data&) =
default;
82 http_parameter_data(http_parameter_data&&) =
default;
83 http_parameter_data& operator=(
const http_parameter_data&) =
default;
84 http_parameter_data& operator=(http_parameter_data&&) =
default;
86 http_parameter_data(
const std::string& name)
87 : parameter_data{name}
91 http_parameter_data(
const QJSValue& val)
92 : parameter_data{
ossia::qt::make_parameter_data(val)}
93 , http_parameter_data_base{val}
97 bool valid() const noexcept {
return requestIsValid() || type; }
100using http_parameter = wrapped_parameter<http_parameter_data>;
101using http_node = ossia::net::wrapped_node<http_parameter_data, http_parameter>;
102class OSSIA_EXPORT http_protocol final
106 W_OBJECT(http_protocol)
109 explicit http_protocol(QByteArray code);
111 http_protocol(
const http_protocol&) =
delete;
112 http_protocol(http_protocol&&) =
delete;
113 http_protocol& operator=(
const http_protocol&) =
delete;
114 http_protocol& operator=(http_protocol&&) =
delete;
116 ~http_protocol()
override;
130 static http_parameter_data read_data(
const QJSValue& js) {
return js; }
133 void sig_push(http_parameter* arg_1,
const ossia::value& v)
134 E_SIGNAL(OSSIA_EXPORT, sig_push, arg_1, v)
141 QUrl requestUrl(
const http_parameter* addr_p,
const ossia::value& v);
142 QByteArray requestData(
const http_parameter* addr_p,
const ossia::value& v);
143 void apply_reply(QJSValue);
145 QQmlEngine* m_engine{};
146 QQmlComponent* m_component{};
148 QNetworkAccessManager* m_access{};
152 ossia::hash_map<QNetworkReply*, http_parameter*> m_replies;
154using http_device = ossia::net::wrapped_device<http_node, http_protocol>;
155class OSSIA_EXPORT HTTP :
public QObject
160Q_DECLARE_METATYPE(ossia::net::http_parameter*)
161W_REGISTER_ARGTYPE(ossia::net::http_parameter*)
162W_REGISTER_ARGTYPE(
const ossia::net::http_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
Full information about a parameter.
Definition parameter_data.hpp:61