OSSIA
Open Scenario System for Interactive Application
protocol.hpp
1 #pragma once
2 #include <ossia/detail/config.hpp>
3 
4 #include <ossia/network/base/message_origin_identifier.hpp>
5 #include <ossia/network/common/network_logger.hpp>
6 
7 #include <tcb/span.hpp>
8 
9 #include <nano_signal_slot.hpp>
10 
11 #include <future>
12 #include <memory>
13 #include <vector>
14 
15 namespace ossia
16 {
17 class value;
18 struct bundle_element;
19 namespace net
20 {
21 class parameter_base;
22 class node_base;
23 class device_base;
24 struct full_parameter_data;
25 
26 class protocol_base;
27 
39 class OSSIA_EXPORT protocol_base
40 {
41 public:
42  enum flags
43  {
44  SupportsMultiplex = (1 << 0)
45  };
46 
47  explicit protocol_base()
48  : m_flags{}
49  {
50  }
51  explicit protocol_base(flags f)
52  : m_flags{f}
53  {
54  }
55  protocol_base(const protocol_base&) = delete;
56  protocol_base(protocol_base&&) = delete;
57  protocol_base& operator=(const protocol_base&) = delete;
58  protocol_base& operator=(protocol_base&&) = delete;
59 
60  virtual ~protocol_base();
61 
66  virtual bool pull(parameter_base&) = 0;
67 
72  virtual std::future<void> pull_async(parameter_base&);
73 
77  virtual void request(parameter_base&);
78 
82  virtual bool push(const parameter_base&, const ossia::value& v) = 0;
83  virtual bool push(const parameter_base&, ossia::value&& v);
84  bool push(const parameter_base& p);
85 
92  virtual bool echo_incoming_message(
93  const message_origin_identifier&, const parameter_base&, const ossia::value& v);
94 
98  virtual bool push_bundle(const std::vector<const ossia::net::parameter_base*>&);
99  virtual bool push_bundle(tcb::span<ossia::bundle_element>);
100  virtual bool push_bundle_bounded(tcb::span<ossia::bundle_element>);
101 
105  virtual bool push_raw(const full_parameter_data&) = 0;
106 
110  virtual bool push_raw_bundle(const std::vector<full_parameter_data>&);
111 
126  virtual bool observe(parameter_base&, bool) = 0;
127 
134  virtual bool publish(const parameter_base&);
135 
142  virtual bool unpublish(const parameter_base&);
143 
147  virtual bool observe_quietly(parameter_base&, bool) { return false; }
148 
153  virtual std::future<void> update_async(node_base& node_base);
154 
160  virtual bool update(node_base& node_base) = 0;
161 
167  virtual void set_device(ossia::net::device_base& dev);
168 
170  virtual void set_logger(const network_logger& l) { m_logger = l; }
171 
172  virtual const network_logger& get_logger() const noexcept { return m_logger; }
173 
174  virtual bool connected() const noexcept;
175  virtual void connect();
176  Nano::Signal<void()> on_connection_open;
177  Nano::Signal<void()> on_connection_closed;
178  Nano::Signal<void()> on_connection_failure;
179 
180  virtual void start_execution() { }
181  virtual void stop_execution() { }
182  virtual void stop() { }
183 
184  flags get_flags() const noexcept { return m_flags; }
185  bool test_flag(flags f) const noexcept { return m_flags & f; }
186 
187 protected:
188  const flags m_flags{};
189  network_logger m_logger;
190 };
191 
192 template <typename T>
193 class can_learn : public T
194 {
195 public:
196  using T::T;
197 
198  bool learning() const noexcept { return m_learning; }
199 
200  void set_learning(bool v) noexcept { m_learning = v; }
201 
202 private:
203  std::atomic_bool m_learning{};
204 };
205 
206 }
207 }
Root of a device tree.
Definition: ossia/network/base/device.hpp:58
Stores custom loggers for the inbound and outbound network messages.
Definition: network_logger.hpp:19
The node_base class.
Definition: network/base/node.hpp:48
The parameter_base class.
Definition: ossia/network/base/parameter.hpp:48
The protocol_base class.
Definition: protocol.hpp:40
virtual bool push_raw(const full_parameter_data &)=0
Send a value to the network.
virtual bool observe(parameter_base &, bool)=0
Notify the network that a parameter should be listened to.
virtual bool update(node_base &node_base)=0
If the protocol supports it, request the namespace corresponding to this node. If the update takes to...
virtual bool observe_quietly(parameter_base &, bool)
Begin observation without notifying the other computers.
Definition: protocol.hpp:147
virtual bool pull(parameter_base &)=0
Pulls a value from the server synchronously.
virtual bool push(const parameter_base &, const ossia::value &v)=0
Send a value to the network.
virtual void set_logger(const network_logger &l)
Replace the loggers used.
Definition: protocol.hpp:170
The value class.
Definition: value.hpp:173
Definition: git_info.h:7
Full information about a parameter.
Definition: parameter_data.hpp:61