mirror of
https://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git
synced 2026-10-24 00:48:53 +03:00
Commit ea84f882d5 ("licensing: relicense C++ library code under
LGPL-3.0-or-later") changed the license of C++ bindings in order to
solve potential issues with code generated from templates[1], default
implementations, etc. However this change makes the bindings less
attractive to projects that have strict licensing restrictions and avoid
GPL-3.0 code[2].
After talking to Grant Likely I decided that the best approach is to
make the bindings available under LGPL-v2.1-or-later and simply let the
end user decide which version's text to apply.
While at it: tweak the README to also mention that examples are provided
under GPL-2.0-or-later.
Link: [1] https://www.spinics.net/lists/linux-gpio/msg46605.html
Link: [2] https://github.com/brgl/libgpiod/issues/72
Suggested-by: Walter Lozano <walter.lozano@collabora.com>
Suggested-by: Grant Likely <grant.likely@linaro.org>
Acked-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Kevin Hilman <khilman@baylibre.com>
Acked-by: Grant Likely <grant.likely@linaro.org>
Link: https://lore.kernel.org/r/20240416212141.6683-2-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
138 lines
3.2 KiB
C++
138 lines
3.2 KiB
C++
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
// SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <brgl@bgdev.pl>
|
|
|
|
#include <map>
|
|
#include <ostream>
|
|
#include <utility>
|
|
|
|
#include "internal.hpp"
|
|
|
|
namespace gpiod {
|
|
|
|
namespace {
|
|
|
|
const ::std::map<int, edge_event::event_type> event_type_mapping = {
|
|
{ GPIOD_EDGE_EVENT_RISING_EDGE, edge_event::event_type::RISING_EDGE },
|
|
{ GPIOD_EDGE_EVENT_FALLING_EDGE, edge_event::event_type::FALLING_EDGE },
|
|
};
|
|
|
|
const ::std::map<edge_event::event_type, ::std::string> event_type_names = {
|
|
{ edge_event::event_type::RISING_EDGE, "RISING_EDGE" },
|
|
{ edge_event::event_type::FALLING_EDGE, "FALLING_EDGE" },
|
|
};
|
|
|
|
} /* namespace */
|
|
|
|
::gpiod_edge_event* edge_event::impl_managed::get_event_ptr() const noexcept
|
|
{
|
|
return this->event.get();
|
|
}
|
|
|
|
::std::shared_ptr<edge_event::impl>
|
|
edge_event::impl_managed::copy(const ::std::shared_ptr<impl>& self) const
|
|
{
|
|
return self;
|
|
}
|
|
|
|
edge_event::impl_external::impl_external()
|
|
: impl(),
|
|
event(nullptr)
|
|
{
|
|
|
|
}
|
|
|
|
::gpiod_edge_event* edge_event::impl_external::get_event_ptr() const noexcept
|
|
{
|
|
return this->event;
|
|
}
|
|
|
|
::std::shared_ptr<edge_event::impl>
|
|
edge_event::impl_external::copy([[maybe_unused]] const ::std::shared_ptr<impl>& self) const
|
|
{
|
|
::std::shared_ptr<impl> ret(new impl_managed);
|
|
impl_managed& managed = dynamic_cast<impl_managed&>(*ret);
|
|
|
|
managed.event.reset(::gpiod_edge_event_copy(this->event));
|
|
if (!managed.event)
|
|
throw_from_errno("unable to copy the edge event object");
|
|
|
|
return ret;
|
|
}
|
|
|
|
edge_event::edge_event()
|
|
: _m_priv()
|
|
{
|
|
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event::edge_event(const edge_event& other)
|
|
: _m_priv(other._m_priv->copy(other._m_priv))
|
|
{
|
|
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event::edge_event(edge_event&& other) noexcept
|
|
: _m_priv(::std::move(other._m_priv))
|
|
{
|
|
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event::~edge_event()
|
|
{
|
|
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event& edge_event::operator=(const edge_event& other)
|
|
{
|
|
this->_m_priv = other._m_priv->copy(other._m_priv);
|
|
|
|
return *this;
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event& edge_event::operator=(edge_event&& other) noexcept
|
|
{
|
|
this->_m_priv = ::std::move(other._m_priv);
|
|
|
|
return *this;
|
|
}
|
|
|
|
GPIOD_CXX_API edge_event::event_type edge_event::type() const
|
|
{
|
|
int evtype = ::gpiod_edge_event_get_event_type(this->_m_priv->get_event_ptr());
|
|
|
|
return get_mapped_value(evtype, event_type_mapping);
|
|
}
|
|
|
|
GPIOD_CXX_API timestamp edge_event::timestamp_ns() const noexcept
|
|
{
|
|
return ::gpiod_edge_event_get_timestamp_ns(this->_m_priv->get_event_ptr());
|
|
}
|
|
|
|
GPIOD_CXX_API line::offset edge_event::line_offset() const noexcept
|
|
{
|
|
return ::gpiod_edge_event_get_line_offset(this->_m_priv->get_event_ptr());
|
|
}
|
|
|
|
GPIOD_CXX_API unsigned long edge_event::global_seqno() const noexcept
|
|
{
|
|
return ::gpiod_edge_event_get_global_seqno(this->_m_priv->get_event_ptr());
|
|
}
|
|
|
|
GPIOD_CXX_API unsigned long edge_event::line_seqno() const noexcept
|
|
{
|
|
return ::gpiod_edge_event_get_line_seqno(this->_m_priv->get_event_ptr());
|
|
}
|
|
|
|
GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const edge_event& event)
|
|
{
|
|
out << "gpiod::edge_event(type='" << event_type_names.at(event.type()) <<
|
|
"', timestamp=" << event.timestamp_ns() <<
|
|
", line_offset=" << event.line_offset() <<
|
|
", global_seqno=" << event.global_seqno() <<
|
|
", line_seqno=" << event.line_seqno() << ")";
|
|
|
|
return out;
|
|
}
|
|
|
|
} /* namespace gpiod */
|