GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/SubscriptionManager.h
Date: 2025-08-17 04:10:43
Exec Total Coverage
Lines: 7 7 100.0%
Branches: 2 2 100.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright 2010 Richard Hacker (lerichi at gmx dot net)
4 *
5 * This file is part of the pdserv library.
6 *
7 * The pdserv library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or (at
10 * your option) any later version.
11 *
12 * The pdserv library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #ifndef SUBSCRIPTIONMANAGER_H
23 #define SUBSCRIPTIONMANAGER_H
24
25 #include "../SessionTask.h"
26
27 #include <set>
28 #include <map>
29 #include <memory>
30
31 namespace PdServ {
32 class Task;
33 struct TaskStatistics;
34 }
35
36 namespace MsrProto {
37
38 class Channel;
39 class Subscription;
40 class Session;
41
42 class SubscriptionManager: public PdServ::SessionTask {
43 public:
44 SubscriptionManager(Session *session, const PdServ::Task*);
45 ~SubscriptionManager();
46
47 Session * const session;
48
49 void rxPdo(bool quiet);
50
51 void clear();
52 void unsubscribe(const Channel *s, size_t group);
53 void subscribe(const Channel *s, size_t group,
54 size_t decimation, size_t blocksize,
55 bool base64, std::streamsize precision);
56
57 void sync();
58
59 const struct timespec *taskTime;
60 const PdServ::TaskStatistics *taskStatistics;
61
62 private:
63 static struct timespec dummyTime;
64 static PdServ::TaskStatistics dummyTaskStatistics;
65
66 // Here is a map of all subscribed channels. Organization:
67 // signalSubscriptionMap
68 // -> [signal]
69 // -> [channel]
70 // -> [group]
71 // -> subscription
72 typedef std::map<size_t, Subscription*> SubscriptionGroup;
73 typedef std::map<const Channel*, SubscriptionGroup>
74 ChannelSubscriptionMap;
75 typedef std::map<const PdServ::Signal*, ChannelSubscriptionMap>
76 SignalSubscriptionMap;
77 SignalSubscriptionMap signalSubscriptionMap;
78
79 // Here is a template class that implements a decimation counter
80 template <class T>
81 36 struct DecimationCounter: std::map<size_t, T> {
82 36 DecimationCounter(): counter(0) {}
83 1985 bool busy(size_t start) {
84
2/2
✓ Branch 1 taken 870 times.
✓ Branch 2 taken 1115 times.
1985 if (!counter)
85 870 counter = start;
86 1985 return --counter;
87 }
88 size_t counter;
89 };
90
91 // Here are the active signals, those that are transferred via shmem.
92 // Organization: activeSignals
93 // -> [group]
94 // -> [decimation]
95 // -> [blocksize]
96 // -> subscriptionSet
97 // -> subscription
98 72 struct SubscriptionSet: std::set<Subscription*> {
99 std::unique_ptr<uint64_t[]> time;
100 uint64_t *timePtr;
101 };
102 typedef DecimationCounter<SubscriptionSet> BlocksizeGroup;
103 typedef std::map<size_t, BlocksizeGroup> DecimationGroup;
104 typedef std::map<size_t, DecimationGroup> ActiveSignals;
105 ActiveSignals activeSignals;
106
107 std::set<const PdServ::Signal*> activeSignalSet;
108
109 void remove(Subscription *s, size_t group);
110
111 // Reimplemented from PdServ::SessionTask
112 void newSignal( const PdServ::Signal *);
113 };
114
115 }
116 #endif //SUBSCRIPTIONMANAGER_H
117