Debian Codegraph @

bindings/cxx/request-config.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // SPDX-FileCopyrightText: 2021 Bartosz Golaszewski <[email protected]>
3
4 #include <ostream>
5 #include <utility>
6
7 #include "internal.hpp"
8
9 namespace gpiod {
10
11 namespace {
12
13 request_config_ptr make_request_config()
14 {
15 request_config_ptr config(::gpiod_request_config_new());
16 if (!config)
17 throw_from_errno("Unable to allocate the request config object");
18
19 return config;
20 }
21
22 } /* namespace */
23
24 request_config::impl::impl()
25 : config(make_request_config())
26 {
27
28 }
29
30 GPIOD_CXX_API request_config::request_config()
31 : _m_priv(new impl)
32 {
33
34 }
35
36 GPIOD_CXX_API request_config::request_config(request_config&& other) noexcept
37 : _m_priv(::std::move(other._m_priv))
38 {
39
40 }
41
42 GPIOD_CXX_API request_config::~request_config()
43 {
44
45 }
46
47 request_config& request_config::operator=(const request_config& other)
48 {
49 this->_m_priv = other._m_priv;
50
51 return *this;
52 }
53
54 GPIOD_CXX_API request_config& request_config::operator=(request_config&& other) noexcept
55 {
56 this->_m_priv = ::std::move(other._m_priv);
57
58 return *this;
59 }
60
61 GPIOD_CXX_API request_config&
62 request_config::set_consumer(const ::std::string& consumer) noexcept
63 {
64 ::gpiod_request_config_set_consumer(this->_m_priv->config.get(), consumer.c_str());
65
66 return *this;
67 }
68
69 GPIOD_CXX_API ::std::string request_config::consumer() const noexcept
70 {
71 const char* consumer = ::gpiod_request_config_get_consumer(this->_m_priv->config.get());
72
73 return consumer ?: "";
74 }
75
76 GPIOD_CXX_API request_config&
77 request_config::set_event_buffer_size(::std::size_t event_buffer_size) noexcept
78 {
79 ::gpiod_request_config_set_event_buffer_size(this->_m_priv->config.get(),
80 event_buffer_size);
81
82 return *this;
83 }
84
85 GPIOD_CXX_API ::std::size_t request_config::event_buffer_size() const noexcept
86 {
87 return ::gpiod_request_config_get_event_buffer_size(this->_m_priv->config.get());
88 }
89
90 GPIOD_CXX_API ::std::ostream& operator<<(::std::ostream& out, const request_config& config)
91 {
92 ::std::string consumer;
93
94 consumer = config.consumer().empty() ? "N/A" : ::std::string("'") + config.consumer() + "'";
95
96 out << "gpiod::request_config(consumer=" << consumer <<
97 ", event_buffer_size=" << config.event_buffer_size() <<
98 ")";
99
100 return out;
101 }
102
103 } /* namespace gpiod */