Debian Codegraph @

bindings/cxx/info-event.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]>
3
4 #include <map>
5 #include <ostream>
6
7 #include "internal.hpp"
8
9 namespace gpiod {
10
11 namespace {
12
13 const ::std::map<int, info_event::event_type> event_type_mapping = {
14 { GPIOD_INFO_EVENT_LINE_REQUESTED, info_event::event_type::LINE_REQUESTED },
15 { GPIOD_INFO_EVENT_LINE_RELEASED, info_event::event_type::LINE_RELEASED },
16 { GPIOD_INFO_EVENT_LINE_CONFIG_CHANGED, info_event::event_type::LINE_CONFIG_CHANGED },
17 };
18
19 const ::std::map<info_event::event_type, ::std::string> event_type_names = {
20 { info_event::event_type::LINE_REQUESTED, "LINE_REQUESTED" },
21 { info_event::event_type::LINE_RELEASED, "LINE_RELEASED" },
22 { info_event::event_type::LINE_CONFIG_CHANGED, "LINE_CONFIG_CHANGED" },
23 };
24
25 } /* namespace */
26
27 void info_event::impl::set_info_event_ptr(info_event_ptr& new_event)
28 {
29 ::gpiod_line_info* info = ::gpiod_info_event_get_line_info(new_event.get());
30
31 line_info_ptr copy(::gpiod_line_info_copy(info));
32 if (!copy)
33 throw_from_errno("unable to copy the line info object");
34
35 this->event = ::std::move(new_event);
36 this->info._m_priv->set_info_ptr(copy);
37 }
38
39 info_event::info_event()
40 : _m_priv(new impl)
41 {
42
43 }
44
45 GPIOD_CXX_API info_event::info_event(const info_event& other)
46 : _m_priv(other._m_priv)
47 {
48
49 }
50
51 GPIOD_CXX_API info_event::info_event(info_event&& other) noexcept
52 : _m_priv(::std::move(other._m_priv))
53 {
54
55 }
56
57 GPIOD_CXX_API info_event::~info_event()
58 {
59
60 }
61
62 GPIOD_CXX_API info_event& info_event::operator=(const info_event& other)
63 {
64 this->_m_priv = other._m_priv;
65
66 return *this;
67 }
68
69 GPIOD_CXX_API info_event& info_event::operator=(info_event&& other) noexcept
70 {
71 this->_m_priv = ::std::move(other._m_priv);
72
73 return *this;
74 }
75
76 GPIOD_CXX_API info_event::event_type info_event::type() const
77 {
78 int type = ::gpiod_info_event_get_event_type(this->_m_priv->event.get());
79
80 return get_mapped_value(type, event_type_mapping);
81 }
82
83 GPIOD_CXX_API ::std::uint64_t info_event::timestamp_ns() const noexcept
84 {
85 return ::gpiod_info_event_get_timestamp_ns(this->_m_priv->event.get());
86 }
87
88 GPIOD_CXX_API const line_info& info_event::get_line_info() const noexcept
89 {
90 return this->_m_priv->info;
91 }
92
93 GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const info_event& event)
94 {
95 out << "gpiod::info_event(event_type='" << event_type_names.at(event.type()) <<
96 "', timestamp=" << event.timestamp_ns() <<
97 ", line_info=" << event.get_line_info() <<
98 ")";
99
100 return out;
101 }
102
103 } /* namespace gpiod */