GCC Code Coverage Report


Directory: ./
File: pdcom5/src/msrproto/Subscription.cpp
Date: 2023-11-12 04:06:57
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 49 void InvalidSubscription::unsubscribe(T &This)
44 {
45
2/4
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 10 taken 35 times.
✗ Branch 11 not taken.
98 if (const auto p = This.process_.lock()) {
46 49 const auto ph = p->template castProtocolHandler<ProtocolHandler>();
47
2/4
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35 times.
✗ Branch 3 not taken.
49 if (ph)
48 49 ph->unsubscribe(This);
49 }
50 49 }
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 70 EventSubscription::~EventSubscription()
63 {
64 35 unsubscribe(*this);
65 35 }
66
67 28 PeriodicSubscription::~PeriodicSubscription()
68 {
69 14 unsubscribe(*this);
70 14 }
71
72 53 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 53 const PdCom::Selector &selector) :
78 InvalidSubscription(
79 This,
80 subscriber,
81 process,
82 106 std::static_pointer_cast<const PdCom::impl::Variable>(variable)),
83
1/2
✗ Branch 4 not taken.
✓ Branch 5 taken 53 times.
106 is_parameter_(variable->is_parameter_),
84 53 copy_function_(selector.impl_->getCopyFunction(*variable)),
85
3/6
✓ Branch 18 taken 53 times.
✗ Branch 19 not taken.
✓ Branch 33 taken 53 times.
✗ Branch 34 not taken.
✓ Branch 36 taken 53 times.
✗ Branch 37 not taken.
318 data_(selector.impl_->getRequiredSize(*variable) + 2)
86 53 {}
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 6 times.
✓ Branch 6 taken 8 times.
14 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 8 times.
✗ Branch 6 not taken.
8 h.pollChannel(*this);
96 }
97 else
98 throw ProcessGoneAway();
99 14 }
100