GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/SubscriptionManager.h
Date: 2024-12-15 04:08:34
Exec Total Coverage
Lines: 7 7 100.0%
Branches: 2 2 100.0%

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 #ifndef SUBSCRIPTIONMANAGER_H
25 #define SUBSCRIPTIONMANAGER_H
26
27 #include "../SessionTask.h"
28
29 #include <set>
30 #include <map>
31 #include <memory>
32
33 namespace PdServ {
34 class Task;
35 struct TaskStatistics;
36 }
37
38 namespace MsrProto {
39
40 class Channel;
41 class Subscription;
42 class Session;
43
44 class SubscriptionManager: public PdServ::SessionTask {
45 public:
46 SubscriptionManager(Session *session, const PdServ::Task*);
47 ~SubscriptionManager();
48
49 Session * const session;
50
51 void rxPdo(bool quiet);
52
53 void clear();
54 void unsubscribe(const Channel *s, size_t group);
55 void subscribe(const Channel *s, size_t group,
56 size_t decimation, size_t blocksize,
57 bool base64, std::streamsize precision);
58
59 void sync();
60
61 const struct timespec *taskTime;
62 const PdServ::TaskStatistics *taskStatistics;
63
64 private:
65 static struct timespec dummyTime;
66 static PdServ::TaskStatistics dummyTaskStatistics;
67
68 // Here is a map of all subscribed channels. Organization:
69 // signalSubscriptionMap
70 // -> [signal]
71 // -> [channel]
72 // -> [group]
73 // -> subscription
74 typedef std::map<size_t, Subscription*> SubscriptionGroup;
75 typedef std::map<const Channel*, SubscriptionGroup>
76 ChannelSubscriptionMap;
77 typedef std::map<const PdServ::Signal*, ChannelSubscriptionMap>
78 SignalSubscriptionMap;
79 SignalSubscriptionMap signalSubscriptionMap;
80
81 // Here is a template class that implements a decimation counter
82 template <class T>
83 36 struct DecimationCounter: std::map<size_t, T> {
84 36 DecimationCounter(): counter(0) {}
85 1990 bool busy(size_t start) {
86
2/2
✓ Branch 1 taken 873 times.
✓ Branch 2 taken 1117 times.
1990 if (!counter)
87 873 counter = start;
88 1990 return --counter;
89 }
90 size_t counter;
91 };
92
93 // Here are the active signals, those that are transferred via shmem.
94 // Organization: activeSignals
95 // -> [group]
96 // -> [decimation]
97 // -> [blocksize]
98 // -> subscriptionSet
99 // -> subscription
100 72 struct SubscriptionSet: std::set<Subscription*> {
101 std::unique_ptr<uint64_t[]> time;
102 uint64_t *timePtr;
103 };
104 typedef DecimationCounter<SubscriptionSet> BlocksizeGroup;
105 typedef std::map<size_t, BlocksizeGroup> DecimationGroup;
106 typedef std::map<size_t, DecimationGroup> ActiveSignals;
107 ActiveSignals activeSignals;
108
109 std::set<const PdServ::Signal*> activeSignalSet;
110
111 void remove(Subscription *s, size_t group);
112
113 // Reimplemented from PdServ::SessionTask
114 void newSignal( const PdServ::Signal *);
115 };
116
117 }
118 #endif //SUBSCRIPTIONMANAGER_H
119