GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_gpiodevices.cpp
Date: 2026-05-04 21:11:01
Exec Total Coverage
Lines: 0 42 0.0%
Functions: 0 9 0.0%
Branches: 0 34 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright (c) 2018-2026, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28
29 #include "gate/io/gpiodevices.hpp"
30 #include "gate/exceptions.hpp"
31
32 namespace gate
33 {
34 namespace io
35 {
36
37
38 enumint_t const GPIODevice::LineConfig_Input = GATE_GPIODEVICE_LINE_CONFIG_INPUT;
39 enumint_t const GPIODevice::LineConfig_Output = GATE_GPIODEVICE_LINE_CONFIG_OUTPUT;
40
41
42 String GPIODevice::getDefaultDevicePath()
43 {
44 gate_string_t path = GATE_STRING_INIT_EMPTY;
45 result_t result = gate_gpiodevice_default_path(&path);
46 GATEXX_CHECK_EXCEPTION(result);
47 return String::createFrom(path);
48 }
49
50
51 GPIODevice::GPIODevice(String const& devicePath, enumint_t flags)
52 {
53 result_t result = gate_gpiodevice_open(devicePath.c_impl(), flags, &this->impl);
54 GATEXX_CHECK_EXCEPTION(result);
55 }
56
57 GPIODevice::~GPIODevice() noexcept
58 {
59 gate_gpiodevice_close(&this->impl);
60 }
61
62 static gate_bool_t GATE_CALL GPIODevice_listLines_cb(gate_intptr_t line_address, gate_string_t const* description, gate_bool_t is_used, void* param)
63 {
64 GPIODevice::LinesInfoMap* ptrMap = static_cast<GPIODevice::LinesInfoMap*>(param);
65 GPIODevice::LineInfo info;
66 info.Description = String(*description);
67 info.IsUsed = is_used;
68 ptrMap->add(line_address, info);
69 return true;
70 }
71
72 GPIODevice::LinesInfoMap GPIODevice::listLines()
73 {
74 LinesInfoMap ret;
75 result_t result = gate_gpiodevice_lines_list(&this->impl, &GPIODevice_listLines_cb, &ret);
76 GATEXX_CHECK_EXCEPTION(result);
77 return ret;
78 }
79
80 enumint_t GPIODevice::getLineConfig(line_t lineAddress)
81 {
82 enumint_t ret = 0;
83 result_t result = gate_gpiodevice_lines_get_config(&this->impl, lineAddress, &ret);
84 GATEXX_CHECK_EXCEPTION(result);
85 return ret;
86 }
87
88 void GPIODevice::setLineConfig(line_t lineAddress, enumint_t configFlags)
89 {
90 result_t result = gate_gpiodevice_lines_set_config(&this->impl, lineAddress, configFlags);
91 GATEXX_CHECK_EXCEPTION(result);
92 }
93
94 intptr_t GPIODevice::readLine(line_t lineAddress)
95 {
96 intptr_t ret = 0;
97 result_t result = gate_gpiodevice_lines_read(&this->impl, lineAddress, &ret);
98 GATEXX_CHECK_EXCEPTION(result);
99 return ret;
100 }
101
102 void GPIODevice::writeLine(line_t lineAddress, intptr_t value)
103 {
104 result_t result = gate_gpiodevice_lines_write(&this->impl, lineAddress, value);
105 GATEXX_CHECK_EXCEPTION(result);
106 }
107
108
109 } // end of namespace io
110 } // end of namespace gate
111