GCC Code Coverage Report


Directory: src/gate/
File: src/gate/io/cxx_gpiodevices.cpp
Date: 2026-10-19 17:06:30
Exec Total Coverage
Lines: 7 47 14.9%
Functions: 2 11 18.2%
Branches: 4 34 11.8%

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 1 String GPIODevice::getDefaultDevicePath()
43 {
44 1 gate_string_t path = GATE_STRING_INIT_EMPTY;
45
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_gpiodevice_default_path(&path);
46
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
47 ✗ return String::createFrom(path);
48 }
49
50
51 1 GPIODevice::GPIODevice(String const& devicePath, enumint_t flags)
52 {
53 1 result_t result = gate_gpiodevice_open(devicePath.c_impl(), flags, &this->impl);
54
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
55 ✗ }
56
57 ✗ GPIODevice::~GPIODevice() noexcept
58 {
59 ✗ gate_gpiodevice_close(&this->impl);
60 ✗ }
61
62 ✗ gate_gpiodevice_t* GPIODevice::c_impl()
63 {
64 ✗ return &this->impl;
65 }
66
67 ✗ GPIODevice::LineInfo::LineInfo()
68 ✗ : IsUsed(false)
69 {
70 ✗ }
71
72 ✗ 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)
73 {
74 ✗ GPIODevice::LinesInfoMap* ptrMap = static_cast<GPIODevice::LinesInfoMap*>(param);
75 ✗ GPIODevice::LineInfo info;
76 ✗ info.Description = String(*description);
77 ✗ info.IsUsed = is_used;
78 ✗ ptrMap->add(line_address, info);
79 ✗ return true;
80 }
81
82 ✗ GPIODevice::LinesInfoMap GPIODevice::listLines()
83 {
84 ✗ LinesInfoMap ret;
85 ✗ result_t result = gate_gpiodevice_lines_list(&this->impl, &GPIODevice_listLines_cb, &ret);
86 ✗ GATEXX_CHECK_EXCEPTION(result);
87 ✗ return ret;
88 }
89
90 ✗ enumint_t GPIODevice::getLineConfig(line_t lineAddress)
91 {
92 ✗ enumint_t ret = 0;
93 ✗ result_t result = gate_gpiodevice_lines_get_config(&this->impl, lineAddress, &ret);
94 ✗ GATEXX_CHECK_EXCEPTION(result);
95 ✗ return ret;
96 }
97
98 ✗ void GPIODevice::setLineConfig(line_t lineAddress, enumint_t configFlags)
99 {
100 ✗ result_t result = gate_gpiodevice_lines_set_config(&this->impl, lineAddress, configFlags);
101 ✗ GATEXX_CHECK_EXCEPTION(result);
102 ✗ }
103
104 ✗ intptr_t GPIODevice::readLine(line_t lineAddress)
105 {
106 ✗ intptr_t ret = 0;
107 ✗ result_t result = gate_gpiodevice_lines_read(&this->impl, lineAddress, &ret);
108 ✗ GATEXX_CHECK_EXCEPTION(result);
109 ✗ return ret;
110 }
111
112 ✗ void GPIODevice::writeLine(line_t lineAddress, intptr_t value)
113 {
114 ✗ result_t result = gate_gpiodevice_lines_write(&this->impl, lineAddress, value);
115 ✗ GATEXX_CHECK_EXCEPTION(result);
116 ✗ }
117
118
119 } // end of namespace io
120 } // end of namespace gate
121