GCC Code Coverage Report


Directory: ./
File: src/msrproto/Subscription.cpp
Date: 2024-11-05 15:23:15
Exec Total Coverage
Lines: 30 31 96.8%
Branches: 22 34 64.7%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2021 Richard Hacker (lerichi at gmx dot net),
4 * Florian Pose (fp at igh dot de),
5 * Bjarne von Horn (vh at igh dot de).
6 *
7 * This file is part of the PdCom library.
8 *
9 * The PdCom library is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at your
12 * option) any later version.
13 *
14 * The PdCom library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the PdCom library. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *****************************************************************************/
23
24 #include "Subscription.h"
25
26 #include "../Process.h"
27 #include "ProtocolHandler.h"
28 #include "Variable.h"
29
30 #include <cstring>
31 #include <pdcom5/Exception.h>
32 #include <pdcom5/Process.h>
33 #include <pdcom5/details.h>
34
35 using PdCom::impl::MsrProto::EventSubscription;
36 using PdCom::impl::MsrProto::InvalidSubscription;
37 using PdCom::impl::MsrProto::PendingSubscription;
38 using PdCom::impl::MsrProto::PeriodicSubscription;
39 using PdCom::impl::MsrProto::PollSubscription;
40 using PdCom::impl::MsrProto::ProtocolHandler;
41
42 template <typename T>
43 80 void InvalidSubscription::unsubscribe(T &This)
44 {
45
4/4
✓ Branch 3 taken 48 times.
✓ Branch 4 taken 7 times.
✓ Branch 10 taken 23 times.
✓ Branch 11 taken 2 times.
160 if (const auto p = This.process_.lock()) {
46 71 const auto ph = p->template castProtocolHandler<ProtocolHandler>();
47
3/4
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 1 times.
71 if (ph)
48 70 ph->unsubscribe(This);
49 }
50 80 }
51
52 1 void InvalidSubscription::poll()
53 {
54
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 throw PdCom::InvalidSubscription();
55 }
56
57 2 const void *InvalidSubscription::getData() const
58 {
59
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 throw PdCom::InvalidSubscription();
60 }
61
62 50 EventSubscription::~EventSubscription()
63 {
64 25 unsubscribe(*this);
65 25 }
66
67 110 PeriodicSubscription::~PeriodicSubscription()
68 {
69 55 unsubscribe(*this);
70 55 }
71
72 90 PollSubscription::PollSubscription(
73 std::shared_ptr<const PdCom::impl::MsrProto::Variable> variable,
74 PdCom::Subscription *This,
75 PdCom::Subscriber &subscriber,
76 std::weak_ptr<PdCom::impl::Process> process,
77 90 const PdCom::Selector &selector) :
78 InvalidSubscription(
79 This,
80 subscriber,
81 process,
82 180 std::static_pointer_cast<const PdCom::impl::Variable>(variable)),
83
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 90 times.
180 is_parameter_(variable->is_parameter_),
84 90 copy_function_(selector.impl_->getCopyFunction(*variable)),
85
4/6
✓ Branch 18 taken 86 times.
✓ Branch 19 taken 4 times.
✓ Branch 33 taken 86 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 86 times.
✗ Branch 37 not taken.
540 data_(selector.impl_->getRequiredSize(*variable) + 2)
86 86 {}
87
88 14 void PollSubscription::poll()
89 {
90
1/2
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
28 if (const auto p = process_.lock()) {
91
1/2
✓ Branch 5 taken 14 times.
✗ Branch 6 not taken.
14 auto &h = p->template protocolHandler<ProtocolHandler>();
92
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
✓ Branch 5 taken 7 times.
✓ Branch 6 taken 7 times.
14 if (is_parameter_)
93
1/2
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
7 h.pollParameter(*this);
94 else
95
2/2
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 1 times.
7 h.pollChannel(*this);
96 }
97 else
98 throw ProcessGoneAway();
99 13 }
100