GCC Code Coverage Report


Directory: ./
File: src/SlaveContext.h
Date: 2026-09-03 16:05:57
Exec Total Coverage
Lines: 7 7 100.0%
Branches: 2 4 50.0%

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 * Internal convenience only -- never part of the public API. The one
22 * contract every device family must actually satisfy is
23 * EcApp::FactoryFn (ecapp/Factory.h), which takes every construction
24 * parameter directly, no bundling struct. SlaveContext exists purely
25 * so a family's own factory lambda (and its adapter constructor)
26 * doesn't have to repeat that same long parameter list by hand;
27 * wrapFactory() adapts a SlaveContext-taking lambda to the real,
28 * struct-free FactoryFn the Registry expects.
29 *
30 ****************************************************************************/
31
32 #ifndef ECAPP_INTERNAL_SLAVECONTEXT_H
33 #define ECAPP_INTERNAL_SLAVECONTEXT_H
34
35 /****************************************************************************/
36
37 #include "ecapp/Factory.h"
38
39 #include <cstdint>
40 #include <functional>
41 #include <memory>
42 #include <pdserv.h>
43 #include <string>
44 #include <utility>
45
46 /****************************************************************************/
47
48 namespace EcApp {
49
50 11 struct SlaveContext
51 {
52 Master *master;
53 Domain *domainOut;
54 Domain *domainIn;
55 uint16_t alias;
56 uint16_t position;
57 Mode mode;
58 std::string prefix;
59 pdserv *pdServ = nullptr;
60 pdtask *task = nullptr;
61 };
62
63 using DeviceFactoryFn =
64 std::function<std::unique_ptr<SubDevice>(const SlaveContext &)>;
65
66 376 inline FactoryFn wrapFactory(DeviceFactoryFn f)
67 {
68 1504 return [f = std::move(f)](
69 Master *master, Domain *domainOut, Domain *domainIn,
70 uint16_t alias, uint16_t position, Mode mode,
71 const std::string &prefix, pdserv *pdServ,
72 11 pdtask *task) -> std::unique_ptr<SubDevice> {
73 22 return f(SlaveContext {
74 master, domainOut, domainIn, alias, position, mode, prefix,
75
1/2
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
33 pdServ, task});
76
1/2
✓ Branch 2 taken 376 times.
✗ Branch 3 not taken.
376 };
77 }
78
79 } // namespace EcApp
80
81 #endif // ECAPP_INTERNAL_SLAVECONTEXT_H
82
83 /****************************************************************************/
84