OSSIA
Open Scenario System for Interactive Application
Loading...
Searching...
No Matches
device_parameter.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{
12
13class OSSIA_EXPORT device_parameter : public ossia::net::parameter_base
14{
15public:
16 device_parameter(
17 ossia::net::node_base& node, const ossia::val_type type,
18 const ossia::bounding_mode bounding, const ossia::access_mode access,
19 ossia::domain domain);
20
21 virtual ~device_parameter();
22
23 // Must be called when the hardware send a new value
24 // (typically from an event loop)
25 // This will NOT call device_update_value() in order to avoid loop
26 void device_value_change_event(const ossia::value& value);
27
28 void pull_value() override;
29 ossia::value value() const override;
30
34
35 ossia::value set_value(const ossia::value& val) override;
36 ossia::value set_value(ossia::value&& v) override;
37
38 ossia::val_type get_value_type() const noexcept override;
39 ossia::net::parameter_base& set_value_type(ossia::val_type) override { return *this; }
40
41 ossia::access_mode get_access() const noexcept override;
42 ossia::net::parameter_base& set_access(ossia::access_mode) override { return *this; }
43
44 const ossia::domain& get_domain() const noexcept override;
45 ossia::net::parameter_base& set_domain(const ossia::domain&) override { return *this; }
46
47 ossia::bounding_mode get_bounding() const noexcept override;
48 ossia::net::parameter_base& set_bounding(ossia::bounding_mode) override
49 {
50 return *this;
51 }
52
53 template <class ParamType = device_parameter, class... T>
54 static ParamType* create_device_parameter(
55 ossia::net::node_base& root_node, const std::string& path,
56 const ossia::value& initial_value, T&&... ctor_args)
57 {
58 static_assert(std::is_base_of<device_parameter, ParamType>::value);
59
60 auto& param_node = ossia::net::create_node(root_node, path);
61 auto param = std::make_unique<ParamType>(param_node, std::forward<T>(ctor_args)...);
62
63 ParamType* ret = param.get();
64
65 param->set_value(initial_value);
66 param_node.set_parameter(std::move(param));
67
68 return ret;
69 }
70
71protected:
72 virtual void device_update_value()
73 {
74 // Here should be the code that actually make the hardware update to
75 // current value
76 }
77
78 ossia::value m_current_value{};
79
80 const ossia::val_type m_type{};
81 const ossia::bounding_mode m_bounding{};
82 const ossia::access_mode m_access{};
83 const ossia::domain m_domain{};
84};
85}
The node_base class.
Definition node.hpp:48
The parameter_base class.
Definition ossia/network/base/parameter.hpp:48
The value class.
Definition value.hpp:173
Definition git_info.h:7
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
access_mode
Address behaviors at crossing domain boundaries time.
Definition parameter_properties.hpp:46
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