-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathelement.cpp
More file actions
121 lines (101 loc) · 2.79 KB
/
Copy pathelement.cpp
File metadata and controls
121 lines (101 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// SPDX-License-Identifier: LGPL-2.1-only
//
// libpisoundmicro - a utility library for Pisound Micro I/O expander capabilities.
// Copyright (c) 2017-2025 Vilniaus Blokas UAB, https://blokas.io/
//
// This file is part of libpisoundmicro.
//
// libpisoundmicro is free software: you can redistribute it and/or modify it under the terms of the
// GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License.
//
// libpisoundmicro is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
// for more details.
//
// You should have received a copy of the GNU Lesser General Public License along with libpisoundmicro. If not, see <https://www.gnu.org/licenses/>.
#include "include/pisound-micro.h"
namespace upisnd
{
template <> upisnd_element_type_e Element::classType<Encoder>() { return UPISND_ELEMENT_TYPE_ENCODER; }
template <> upisnd_element_type_e Element::classType<AnalogInput>() { return UPISND_ELEMENT_TYPE_ANALOG_INPUT; }
template <> upisnd_element_type_e Element::classType<Gpio>() { return UPISND_ELEMENT_TYPE_GPIO; }
template <> upisnd_element_type_e Element::classType<Activity>() { return UPISND_ELEMENT_TYPE_ACTIVITY; }
Element::Element()
:m_ref(NULL)
{
}
Element::Element(upisnd_element_ref_t el)
:m_ref(upisnd_element_add_ref(el))
{
}
Element::Element(upisnd_element_ref_t el, bool)
:m_ref(el)
{
}
Element::Element(const Element &rhs)
:m_ref(upisnd_element_add_ref(rhs.m_ref))
{
}
Element& Element::operator=(const Element &rhs)
{
if (this != &rhs)
{
if (rhs.ref())
upisnd_element_add_ref(rhs.ref());
upisnd_element_unref(&m_ref);
m_ref = rhs.ref();
}
return *this;
}
Element::Element(Element &&rhs)
{
m_ref = rhs.ref();
rhs.m_ref = NULL;
}
Element& Element::operator=(Element &&rhs)
{
if (this != &rhs)
{
upisnd_element_unref(&m_ref);
m_ref = rhs.ref();
rhs.m_ref = NULL;
}
return *this;
}
Element::~Element()
{
upisnd_element_unref(&m_ref);
}
Element Element::get(ElementName name)
{
return Element(upisnd_element_get(name), false);
}
Element Element::setup(ElementName name, upisnd_setup_t setup)
{
return Element(upisnd_setup(name, setup), false);
}
bool Element::isValid() const
{
return ref() != NULL;
}
void Element::release()
{
upisnd_element_unref(&m_ref);
}
const char *Element::getName() const
{
return upisnd_element_get_name(ref());
}
upisnd_element_type_e Element::getType() const
{
return upisnd_element_get_type(ref());
}
upisnd_pin_t Element::getPin() const
{
return upisnd_element_get_pin(ref());
}
ValueFd Element::openValueFd(int flags) const
{
return ValueFd(upisnd_element_open_value_fd(ref(), flags));
}
} // namespace upisnd