OSSIA
Open Scenario System for Interactive Application
oscquery_client_asio.hpp
1 #pragma once
2 #include <ossia/detail/mutex.hpp>
4 #include <ossia/network/common/network_logger.hpp>
5 #include <ossia/network/context.hpp>
6 #include <ossia/network/osc/detail/sender.hpp>
7 #include <ossia/network/oscquery/detail/outbound_visitor.hpp>
8 #include <ossia/network/sockets/udp_socket.hpp>
9 #include <ossia/network/sockets/websocket_server.hpp>
10 #include <ossia/protocols/oscquery/oscquery_server_asio.hpp>
11 
12 namespace ossia::oscquery_asio
13 {
14 struct oscquery_client
15 {
16  ossia::net::websocket_server::connection_handler connection;
17  mutex_t listeningMutex;
18  string_map<ossia::net::parameter_base*> listening TS_GUARDED_BY(listeningMutex);
19 
20  std::string client_ip;
21  std::unique_ptr<ossia::net::udp_send_socket> osc_socket;
22  int remote_sender_port{};
23 
24 public:
25  oscquery_client() = delete;
26  oscquery_client(const oscquery_client& other) noexcept = delete;
27  oscquery_client& operator=(const oscquery_client& other) noexcept = delete;
28  oscquery_client(oscquery_client&& other) noexcept = delete;
29  oscquery_client& operator=(oscquery_client&& other) noexcept = delete;
30 
31  explicit oscquery_client(ossia::net::websocket_server::connection_handler h)
32  : connection{std::move(h)}
33  {
34  }
35 
36  void start_listen(std::string path, ossia::net::parameter_base* addr)
37  {
38  if(addr)
39  {
40  std::lock_guard lck{listeningMutex};
41  listening.insert(std::make_pair(std::move(path), addr));
42  }
43  }
44 
45  void stop_listen(const std::string& path)
46  {
47  std::lock_guard lck{listeningMutex};
48  listening.erase(path);
49  }
50 
51  bool operator==(const ossia::net::websocket_server::connection_handler& h) const
52  {
53  return !connection.expired() && connection.lock() == h.lock();
54  }
55 
56  void
57  open_osc_sender(ossia::oscquery_asio::oscquery_server_protocol& proto, uint16_t port)
58  {
59  osc_socket = std::make_unique<ossia::net::udp_send_socket>(
60  ossia::net::socket_configuration{client_ip, port}, proto.m_context->context);
61  osc_socket->connect();
62  }
63 };
64 
65 }
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
Implementation of an oscquery server.
Definition: oscquery_server_asio.hpp:45