GCC Code Coverage Report


Directory: ./
File: pdcom5/src/msrproto/Subscription.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 26 31 83.9%
Branches: 15 34 44.1%

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 79 void InvalidSubscription::unsubscribe(T &This)
44 {
45
2/4
✓ Branch 3 taken 46 times.
✗ Branch 4 not taken.
✓ Branch 10 taken 33 times.
✗ Branch 11 not taken.
158 if (const auto p = This.process_.lock()) {
46 79 const auto ph = p->template castProtocolHandler<ProtocolHandler>();
47
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
79 if (ph)
48 79 ph->unsubscribe(This);
49 }
50 79 }
51
52 void InvalidSubscription::poll()
53 {
54 throw PdCom::InvalidSubscription();
55 }
56
57 const void *InvalidSubscription::getData() const
58 {
59 throw PdCom::InvalidSubscription();
60 }
61
62 66 EventSubscription::~EventSubscription()
63 {
64 33 unsubscribe(*this);
65 33 }
66
67 92 PeriodicSubscription::~PeriodicSubscription()
68 {
69 46 unsubscribe(*this);
70 46 }
71
72 83 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 83 const PdCom::Selector &selector) :
78 InvalidSubscription(
79 This,
80 subscriber,
81 process,
82 166 std::static_pointer_cast<const PdCom::impl::Variable>(variable)),
83
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 83 times.
166 is_parameter_(variable->is_parameter_),
84 83 copy_function_(selector.impl_->getCopyFunction(*variable)),
85
3/6
✓ Branch 18 taken 83 times.
✗ Branch 19 not taken.
✓ Branch 33 taken 83 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 83 times.
✗ Branch 37 not taken.
498 data_(selector.impl_->getRequiredSize(*variable) + 2)
86 83 {}
87
88 13 void PollSubscription::poll()
89 {
90
1/2
✓ Branch 3 taken 13 times.
✗ Branch 4 not taken.
26 if (const auto p = process_.lock()) {
91
1/2
✓ Branch 5 taken 13 times.
✗ Branch 6 not taken.
13 auto &h = p->template protocolHandler<ProtocolHandler>();
92
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 7 times.
13 if (is_parameter_)
93
1/2
✓ Branch 5 taken 6 times.
✗ Branch 6 not taken.
6 h.pollParameter(*this);
94 else
95
1/2
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
7 h.pollChannel(*this);
96 }
97 else
98 throw ProcessGoneAway();
99 13 }
100