OSSIA
Open Scenario System for Interactive Application
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
device_parameter_t.hpp
1#pragma once
2
3#include <ossia/network/base/node.hpp>
4#include <ossia/network/base/protocol.hpp>
5#include <ossia/network/common/complex_type.hpp>
6#include <ossia/network/domain/domain.hpp>
7#include <ossia/network/oscquery/oscquery_server.hpp>
8#include <ossia/network/value/value.hpp>
9
10namespace ossia::net
11{
12template <typename T>
13class device_parameter_t : public ossia::net::parameter_base
14{
15public:
16 explicit device_parameter_t(net::node_base& node)
17 : net::parameter_base{node}
18 , m_current_value{}
19 {
20 set_repetition_filter(repetition_filter::ON);
21 }
22
23 ~device_parameter_t() = default;
24
25 void device_value_change_event(const ossia::value& val)
26 {
27 if(val.valid())
28 {
29 m_current_value = val;
30 get_protocol().push(*this);
31 }
32 }
33
34 void pull_value() override { get_protocol().pull(*this); }
35
36 ossia::value value() const override { return m_current_value; }
37
38 net::parameter_base& push_value(const ossia::value& val) override
39 {
40 set_value(val);
41 get_protocol().push(*this);
42 return *this;
43 }
44
45 net::parameter_base& push_value(ossia::value&& val) override
46 {
47 return push_value(val);
48 }
49
50 net::parameter_base& push_value() override
51 {
52 get_protocol().push(*this);
53 return *this;
54 }
55
56 ossia::value set_value(const ossia::value& val) override
57 {
58 if(val.valid())
59 {
60 m_current_value = ossia::convert<T>(val);
61 send(val);
62 device_update_value();
63 }
64
65 return m_current_value;
66 }
67
68 ossia::value set_value(ossia::value&& val) override { return set_value(val); }
69
70 ossia::val_type get_value_type() const noexcept override
71 {
72 return ossia::value_trait<T>::ossia_enum;
73 }
74
75 ossia::net::parameter_base& set_value_type(ossia::val_type) override { return *this; }
76
77 ossia::access_mode get_access() const noexcept override
78 {
80 }
81 ossia::net::parameter_base& set_access(ossia::access_mode) override { return *this; }
82
83 const domain& get_domain() const noexcept override
84 {
85 static const thread_local ossia::domain dom;
86 return dom;
87 }
88
89 ossia::bounding_mode get_bounding() const noexcept override
90 {
92 }
94 {
95 return *this;
96 }
97
98 ossia::net::parameter_base& set_domain(const ossia::domain&) override { return *this; }
99
100protected:
101 virtual void device_update_value()
102 {
103 // Here should be the code that actually make the hardware update to
104 // current value
105 }
106
107 T m_current_value;
108};
109}
void send(Args &&... args)
send Trigger all callbacks
Definition callback_container.hpp:190
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
ossia::value value(ossia::destination_index) const
Returns the sub-value at the index given by destination_index.
Definition ossia/network/base/parameter.cpp:31
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.
The value class.
Definition value.hpp:173
val_type
Enum to represent the types that a value can take.
Definition parameter_properties.hpp:16
bounding_mode
Address behaviors at crossing domain boundaries.
Definition parameter_properties.hpp:56
@ CLIP
The bounds are ignored.
access_mode
Address behaviors at crossing domain boundaries time.
Definition parameter_properties.hpp:46
@ SET
The value can be retrieved.
OSSIA_EXPORT void push_value(const ossia::destination &addr, const ossia::value_with_unit &)
Send a value to a given destination.
Definition ossia/network/base/parameter.cpp:151
domain A domain of values
Definition domain_base.hpp:23