OSSIA
Open Scenario System for Interactive Application
ossia-max/src/ZeroconfMinuitListener.hpp
1 // This is an open source non-commercial project. Dear PVS-Studio, please check it.
2 // PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
3 #pragma once
4 
5 #include <ossia/network/generic/generic_device.hpp>
6 #include <ossia/network/zeroconf/zeroconf.hpp>
7 
8 #include <servus/servus.h>
9 
10 #include <memory>
11 
12 namespace ossia
13 {
14 namespace max_binding
15 {
16 class ZeroconfMinuitListener final : servus::Listener
17 {
18 public:
19  ZeroconfMinuitListener();
20  ~ZeroconfMinuitListener() override;
21 
22  static std::shared_ptr<ossia::net::generic_device>
23  find_device(const std::string& name);
24  static std::vector<std::shared_ptr<ossia::net::generic_device>> get_devices()
25  {
26  return s_devices;
27  }
28 
29  void browse();
30 
31 private:
32  // since Max is not thread safe, we put connection events (from Servus thread) in a
33  // vector and process it at scheduled interval triggered by Max clock
34  void instanceAdded(const std::string& instance) final override;
35  void instanceRemoved(const std::string& instance) final override;
36  void add_instance(const std::string& instance);
37  void remove_instance(const std::string& instance);
38 
39  enum ConnectionEvent
40  {
41  ADDED = 0,
42  REMOVED
43  };
44 
45  static std::vector<std::shared_ptr<ossia::net::generic_device>> s_devices;
46  static std::vector<std::pair<ConnectionEvent, std::string>> s_connection_events;
47 
48  servus::Servus service;
49  static std::mutex s_mutex;
50 };
51 
52 } // namespace pd
53 } // namespace ossia
Definition: git_info.h:7