GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/Subscription.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 39 43 90.7%
Branches: 23 36 63.9%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright 2010 Richard Hacker (lerichi at gmx dot net)
6 *
7 * This file is part of the pdserv library.
8 *
9 * The pdserv 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
11 * by the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * The pdserv 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 pdserv library. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *****************************************************************************/
23
24 #include "../Signal.h"
25 #include "../Debug.h"
26 #include "XmlElement.h"
27 #include "Channel.h"
28 #include "SubscriptionManager.h"
29 #include "Subscription.h"
30 #include "../DataType.h"
31
32 #include <algorithm>
33
34 using namespace MsrProto;
35
36 /////////////////////////////////////////////////////////////////////////////
37 12 Subscription::Subscription(const Channel *channel,
38 12 size_t decimation, size_t blocksize, bool base64, std::streamsize precision):
39 channel(channel),
40
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 decimation(blocksize ? decimation : 1),
41 blocksize(blocksize),
42 12 bufferOffset(channel->offset),
43 36 trigger_start(decimation)
44 {
45 12 trigger = 0;
46 12 nblocks = 0;
47
48 12 this->precision = precision;
49 12 this->base64 = base64;
50
51 12 size_t dataLen = (blocksize + !blocksize) * channel->memSize;
52
53 12 data_bptr = new char[dataLen];
54 12 data_eptr = data_bptr + dataLen;
55
56
1/2
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
12 std::fill_n(data_bptr, dataLen, 0);
57
58 12 data_pptr = data_bptr;
59 12 }
60
61 /////////////////////////////////////////////////////////////////////////////
62 24 Subscription::~Subscription()
63 {
64
1/2
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
12 delete[] data_bptr;
65 12 }
66
67 /////////////////////////////////////////////////////////////////////////////
68 65 bool Subscription::newValue (const char *buf)
69 {
70 65 const size_t n = channel->memSize;
71 65 buf += bufferOffset;
72
73
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 53 times.
65 if (!blocksize) {
74
7/8
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 6 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 4 times.
✓ Branch 11 taken 2 times.
✓ Branch 12 taken 10 times.
✓ Branch 13 taken 2 times.
12 if ((trigger and --trigger) or std::equal(buf, buf + n, data_bptr))
75 10 return false;
76
77 2 trigger = trigger_start;
78 }
79
80 55 std::copy(buf, buf + n, data_pptr);
81 55 data_pptr += n;
82 55 ++nblocks;
83
84 55 return true;
85 }
86
87 /////////////////////////////////////////////////////////////////////////////
88 49 void Subscription::print(XmlElement &parent)
89 {
90
1/2
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
49 if (nblocks >= blocksize) {
91
3/4
✓ Branch 2 taken 47 times.
✓ Branch 3 taken 2 times.
✓ Branch 5 taken 49 times.
✗ Branch 6 not taken.
98 XmlElement datum(parent.createChild(blocksize ? "F" : "E"));
92
2/4
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
✓ Branch 9 taken 49 times.
✗ Branch 10 not taken.
49 XmlElement::Attribute(datum, "c") << channel->index;
93
94
1/2
✓ Branch 2 taken 49 times.
✗ Branch 3 not taken.
98 XmlElement::Attribute value(datum, "d");
95
2/4
✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
✓ Branch 3 taken 49 times.
✗ Branch 4 not taken.
49 if (base64)
96
1/2
✓ Branch 9 taken 49 times.
✗ Branch 10 not taken.
49 value.base64(data_bptr, nblocks * channel->memSize);
97 else
98 value.csv(channel, data_bptr, nblocks, precision);
99 }
100
101 49 data_pptr = data_bptr;
102 49 nblocks = 0;
103 49 }
104
105 /////////////////////////////////////////////////////////////////////////////
106 void Subscription::reset()
107 {
108 data_pptr = data_bptr;
109 nblocks = 0;
110 }
111