17 template <
typename Protocol>
19 Protocol& proto,
const typename Protocol::connection_handler& hdl,
20 const rapidjson::Document& doc)
22 auto& dev = proto.get_device();
23 auto& root = proto.get_device().get_root_node();
28 const auto& arr = doc.GetArray();
29 for(
const auto& e : arr)
31 json_parser::parse_parameter_value(root, e, dev);
36 switch(json_parser::message_type(doc))
38 case message_type::StartOscStreaming:
39 handle_start_streaming(proto, hdl, doc);
41 case message_type::Listen:
42 handle_listen(proto, hdl, doc);
44 case message_type::Ignore:
45 handle_ignore(proto, hdl, doc);
48 json_parser::parse_parameter_value(root, doc, dev);
52 return rapidjson::StringBuffer{};
55 template <
typename Protocol>
56 static json_writer::string_t handle_start_streaming(
57 Protocol& proto,
const oscquery_server_protocol::connection_handler& hdl,
58 const rapidjson::Document& doc)
60 auto m = doc.FindMember(
"DATA");
61 if(m == doc.MemberEnd())
63 if(!m->value.IsObject())
65 auto obj = m->value.GetObject();
66 auto remote_server_port_it = obj.FindMember(detail::local_server_port().data());
67 auto remote_sender_port_it = obj.FindMember(detail::local_sender_port().data());
69 if(remote_server_port_it == obj.MemberEnd())
71 if(!remote_server_port_it->value.IsInt())
74 int remote_server = remote_server_port_it->value.GetInt();
75 int remote_sender = 0;
77 if(remote_sender_port_it != obj.MemberEnd())
79 if(remote_sender_port_it->value.IsInt())
81 remote_sender = remote_sender_port_it->value.GetInt();
85 return open_osc_sender(proto, hdl, remote_server, remote_sender);
88 template <
typename Protocol>
89 static json_writer::string_t open_osc_sender(
90 Protocol& proto,
const typename Protocol::connection_handler& hdl,
int port,
94 auto clt = proto.find_client(hdl);
106 clt->open_osc_sender(proto, port);
109 clt->remote_sender_port = remotePort;
116 template <
typename Protocol>
117 static json_writer::string_t handle_listen(
118 Protocol& proto,
const typename Protocol::connection_handler& hdl,
119 const rapidjson::Document& doc)
122 auto clt = proto.find_client(hdl);
127 auto m = doc.FindMember(
"DATA");
128 if(m == doc.MemberEnd())
131 auto nodes = ossia::net::find_nodes(
132 proto.get_device().get_root_node(), m->value.GetString());
135 clt->start_listen(n->osc_address(), n->get_parameter());
140 template <
typename Protocol>
141 static json_writer::string_t handle_ignore(
142 Protocol& proto,
const typename Protocol::connection_handler& hdl,
143 const rapidjson::Document& doc)
146 auto clt = proto.find_client(hdl);
151 auto m = doc.FindMember(
"DATA");
152 if(m == doc.MemberEnd())
155 auto nodes = ossia::net::find_nodes(
156 proto.get_device().get_root_node(), m->value.GetString());
159 clt->stop_listen(n->osc_address());