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