GCC Code Coverage Report


Directory: ./
File: util/TmpFileGPIO.cpp
Date: 2026-10-29 08:11:58
Exec Total Coverage
Lines: 40 42 95.2%
Functions: 11 11 100.0%
Branches: 21 30 70.0%

Line Branch Exec Source
1 /*
2 * This file is part of the Falcon Player (FPP) and is Copyright (C)
3 * 2013-2022 by the Falcon Player Developers.
4 *
5 * The Falcon Player (FPP) is free software, and is covered under
6 * multiple Open Source licenses. Please see the included 'LICENSES'
7 * file for descriptions of what files are covered by each license.
8 *
9 * This source file is covered under the LGPL v2.1 as described in the
10 * included LICENSE.LGPL file.
11 */
12
13 #include "fpp-pch.h"
14
15 #include <fcntl.h>
16 #include <unistd.h>
17
18 #include "../common.h"
19
20 #include "TmpFileGPIO.h"
21
22 36922 TmpFilePinCapabilities::TmpFilePinCapabilities(const std::string& n, uint32_t kg) :
23 36922 PinCapabilitiesFluent(n, kg) {
24
1/2
✓ Branch 0 taken 36922 times.
✗ Branch 1 not taken.
36922 filename = "/tmp/GPIO-";
25
1/2
✓ Branch 0 taken 36922 times.
✗ Branch 1 not taken.
36922 filename += n;
26 36922 }
27
28 496 int TmpFilePinCapabilities::configPin(const std::string& mode,
29 bool directionOut,
30 const std::string& desc) const {
31 496 unlink(filename.c_str());
32 496 return 0;
33 }
34
35 181 bool TmpFilePinCapabilities::getValue() const {
36 181 return FileExists(filename);
37 }
38 1256 void TmpFilePinCapabilities::setValue(bool i) const {
39
2/2
✓ Branch 0 taken 520 times.
✓ Branch 1 taken 736 times.
1256 if (i)
40 520 Touch(filename);
41 else
42 736 unlink(filename.c_str());
43 1256 }
44
45 class NullTmpFilePinCapabilities : public TmpFilePinCapabilities {
46 public:
47 2362 NullTmpFilePinCapabilities() :
48
2/4
✓ Branch 0 taken 2362 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2362 times.
✗ Branch 3 not taken.
7086 TmpFilePinCapabilities("-none-", 0) {}
49 340 virtual const PinCapabilities* ptr() const override { return nullptr; }
50 };
51 static NullTmpFilePinCapabilities NULL_TMPFILE_INSTANCE;
52
53 static std::vector<TmpFilePinCapabilities> TMPFILE_PINS;
54
55 1728 void TmpFilePinProvider::Init() {
56
2/2
✓ Branch 0 taken 34560 times.
✓ Branch 1 taken 1728 times.
36288 for (int x = 1; x <= 20; x++) {
57
1/2
✓ Branch 0 taken 34560 times.
✗ Branch 1 not taken.
34560 std::string p = "TF-" + std::to_string(x);
58
2/4
✓ Branch 0 taken 34560 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34560 times.
✗ Branch 3 not taken.
34560 TMPFILE_PINS.push_back(TmpFilePinCapabilities(p, x));
59 34560 }
60 1728 }
61 1737 std::vector<std::string> TmpFilePinProvider::getPinNames() {
62 1737 std::vector<std::string> ret;
63
2/2
✓ Branch 0 taken 34740 times.
✓ Branch 1 taken 1737 times.
36477 for (auto& a : TMPFILE_PINS) {
64
1/2
✓ Branch 0 taken 34740 times.
✗ Branch 1 not taken.
34740 ret.push_back(a.name);
65 }
66 1737 return ret;
67 ✗ }
68 1002 const PinCapabilities& TmpFilePinProvider::getPinByName(const std::string& name) {
69
2/2
✓ Branch 0 taken 9155 times.
✓ Branch 1 taken 267 times.
9422 for (auto& a : TMPFILE_PINS) {
70
2/2
✓ Branch 0 taken 735 times.
✓ Branch 1 taken 8420 times.
9155 if (a.name == name) {
71 735 return a;
72 }
73 }
74 267 return NULL_TMPFILE_INSTANCE;
75 }
76 6 const PinCapabilities& TmpFilePinProvider::getPinByGPIO(int chip, int gpio) {
77
2/2
✓ Branch 0 taken 120 times.
✓ Branch 1 taken 6 times.
126 for (auto& a : TMPFILE_PINS) {
78
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 120 times.
120 if (a.gpio == gpio) {
79 ✗ return a;
80 }
81 }
82 6 return NULL_TMPFILE_INSTANCE;
83 }
84 69 const PinCapabilities& TmpFilePinProvider::getPinByUART(const std::string& n) {
85 69 return NULL_TMPFILE_INSTANCE;
86 }
87