Directory: | ./ |
---|---|
File: | pdserv/src/msrproto/Subscription.cpp |
Date: | 2024-12-15 04:08:34 |
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 | 44 | Subscription::Subscription(const Channel *channel, | |
38 | 44 | size_t decimation, size_t blocksize, bool base64, std::streamsize precision): | |
39 | channel(channel), | ||
40 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 2 times.
|
44 | decimation(blocksize ? decimation : 1), |
41 | blocksize(blocksize), | ||
42 | 44 | bufferOffset(channel->offset), | |
43 | 132 | trigger_start(decimation) | |
44 | { | ||
45 | 44 | trigger = 0; | |
46 | 44 | nblocks = 0; | |
47 | |||
48 | 44 | this->precision = precision; | |
49 | 44 | this->base64 = base64; | |
50 | |||
51 | 44 | size_t dataLen = (blocksize + !blocksize) * channel->memSize; | |
52 | |||
53 | 44 | data_bptr = new char[dataLen]; | |
54 | 44 | data_eptr = data_bptr + dataLen; | |
55 | |||
56 |
1/2✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
|
44 | std::fill_n(data_bptr, dataLen, 0); |
57 | |||
58 | 44 | data_pptr = data_bptr; | |
59 | 44 | } | |
60 | |||
61 | ///////////////////////////////////////////////////////////////////////////// | ||
62 | 88 | Subscription::~Subscription() | |
63 | { | ||
64 |
1/2✓ Branch 1 taken 44 times.
✗ Branch 2 not taken.
|
44 | delete[] data_bptr; |
65 | 44 | } | |
66 | |||
67 | ///////////////////////////////////////////////////////////////////////////// | ||
68 | 1178 | bool Subscription::newValue (const char *buf) | |
69 | { | ||
70 | 1178 | const size_t n = channel->memSize; | |
71 | 1178 | buf += bufferOffset; | |
72 | |||
73 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 1166 times.
|
1178 | 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 | 1168 | std::copy(buf, buf + n, data_pptr); | |
81 | 1168 | data_pptr += n; | |
82 | 1168 | ++nblocks; | |
83 | |||
84 | 1168 | return true; | |
85 | } | ||
86 | |||
87 | ///////////////////////////////////////////////////////////////////////////// | ||
88 | 503 | void Subscription::print(XmlElement &parent) | |
89 | { | ||
90 |
1/2✓ Branch 2 taken 503 times.
✗ Branch 3 not taken.
|
503 | if (nblocks >= blocksize) { |
91 |
3/4✓ Branch 2 taken 501 times.
✓ Branch 3 taken 2 times.
✓ Branch 5 taken 503 times.
✗ Branch 6 not taken.
|
1006 | XmlElement datum(parent.createChild(blocksize ? "F" : "E")); |
92 |
2/4✓ Branch 2 taken 503 times.
✗ Branch 3 not taken.
✓ Branch 9 taken 503 times.
✗ Branch 10 not taken.
|
503 | XmlElement::Attribute(datum, "c") << channel->index; |
93 | |||
94 |
1/2✓ Branch 2 taken 503 times.
✗ Branch 3 not taken.
|
1006 | XmlElement::Attribute value(datum, "d"); |
95 |
2/4✗ Branch 1 not taken.
✓ Branch 2 taken 503 times.
✓ Branch 3 taken 503 times.
✗ Branch 4 not taken.
|
503 | if (base64) |
96 |
1/2✓ Branch 9 taken 503 times.
✗ Branch 10 not taken.
|
503 | value.base64(data_bptr, nblocks * channel->memSize); |
97 | else | ||
98 | ✗ | value.csv(channel, data_bptr, nblocks, precision); | |
99 | } | ||
100 | |||
101 | 503 | data_pptr = data_bptr; | |
102 | 503 | nblocks = 0; | |
103 | 503 | } | |
104 | |||
105 | ///////////////////////////////////////////////////////////////////////////// | ||
106 | ✗ | void Subscription::reset() | |
107 | { | ||
108 | ✗ | data_pptr = data_bptr; | |
109 | ✗ | nblocks = 0; | |
110 | } | ||
111 |