GCC Code Coverage Report


Directory: ./
File: src/IoLinkDevice.cpp
Date: 2026-09-03 16:05:57
Exec Total Coverage
Lines: 16 22 72.7%
Branches: 14 32 43.8%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * This file is part of the ecapp library (EtherCAT application devices).
4 *
5 * Copyright (C) 2026 Florian Pose <fp@igh.de>
6 *
7 * The ecapp library is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation, version 3 of the
10 * License.
11 *
12 * The ecapp library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with the ecapp library. If not, see
19 * <https://www.gnu.org/licenses/>.
20 *
21 ****************************************************************************/
22
23 #include "ecapp/IoLinkDevice.h"
24
25 #include "ecapp/Exceptions.h"
26
27 #include <sstream>
28 #include <string>
29 #include <utility>
30
31 using std::string;
32 using std::stringstream;
33
34 /****************************************************************************/
35
36 namespace EcApp {
37
38 42 IoLinkDeviceRegistry &IoLinkDeviceRegistry::instance()
39 {
40
3/4
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 34 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
42 static IoLinkDeviceRegistry registry;
41 42 return registry;
42 }
43
44 /****************************************************************************/
45
46 40 void IoLinkDeviceRegistry::add(
47 string name,
48 string sourceFile,
49 IoLinkDeviceFactory factory)
50 {
51
1/2
✓ Branch 4 taken 40 times.
✗ Branch 5 not taken.
160 factories.push_back(
52 120 {std::move(name), std::move(sourceFile), std::move(factory)});
53 40 }
54
55 /****************************************************************************/
56
57 const IoLinkDeviceFactory &
58 2 IoLinkDeviceRegistry::find(const string &name) const
59 {
60
2/2
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 1 times.
7 for (const auto &entry : factories) {
61
2/2
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 5 times.
6 if (entry.name == name) {
62 2 return entry.factory;
63 }
64 }
65
66
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
2 stringstream err;
67 err << "No IO-Link device driver registered under the name \"" << name
68
3/6
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
1 << "\".";
69
2/4
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
1 throw UnknownDevice(err.str());
70 }
71
72 /****************************************************************************/
73
74 std::vector<IoLinkDriverDescriptor> IoLinkDeviceRegistry::all() const
75 {
76 std::vector<IoLinkDriverDescriptor> ret;
77 ret.reserve(factories.size());
78 for (const auto &entry : factories) {
79 ret.push_back({entry.name, entry.sourceFile});
80 }
81 return ret;
82 }
83
84 /****************************************************************************/
85
86 2 std::unique_ptr<IoLinkDevice> createIoLinkDevice(const string &name)
87 {
88 2 return IoLinkDeviceRegistry::instance().find(name)();
89 }
90
91 } // namespace EcApp
92
93 /****************************************************************************/
94