GCC Code Coverage Report


Directory: ./
File: pdserv/src/lib/Task.h
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 0 1 0.0%
Branches: 0 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 LIB_TASK_H
25 #define LIB_TASK_H
26
27 #include <vector>
28 #include <set>
29 #include <cstddef>
30
31 #include "../PThread.h"
32 #include "../Task.h"
33 #include "../TaskStatistics.h"
34 #include "../SessionTask.h"
35
36 namespace PdServ {
37 class SessionTask;
38 class DataType;
39 }
40
41 class Main;
42 class Signal;
43 class Parameter;
44 class SessionTaskData;
45
46 class Task: public PdServ::Task {
47 public:
48 Task(Main *main, size_t index, double sampleTime, const char *name);
49 virtual ~Task();
50
51 Main * const main;
52
53 Signal* addSignal( unsigned int decimation,
54 const char *path, const PdServ::DataType& datatype,
55 const void *addr, size_t n, const size_t *dim);
56 void setSignalReadLock(
57 void (*fn)(int state, void* priv_data), void *priv_data);
58 void makePersistent(const Signal* s);
59 bool getPersistentValue(const PdServ::Signal* s,
60 char* buf, const struct timespec** t) const;
61
62 size_t getShmemSpace(double t) const;
63
64 void prepare(void *start, void *end);
65 void rt_init();
66 void nrt_init();
67 // can throw RtProcessExited
68 void nrt_init_persistent();
69 void updateStatistics(
70 double exec_time, double cycle_time, unsigned int overrun);
71 void rt_update(const struct timespec *);
72 void nrt_update();
73 void pollSignalValue(
74 const Signal* signal, void* dst, struct timespec* time) const;
75
76 // can throw RtProcessExited
77 bool subscribe(const Signal* s, SessionTaskData*, bool insert);
78 void getSignalList(const Signal ** s, size_t *n,
79 unsigned int *signalListId);
80
81 void getCurrentTime(struct timespec* t) const;
82
83 private:
84 pthread::Mutex mutex;
85
86 struct timespec m_time;
87
88 void (*signal_readlock_cb)(int, void *);
89 void *readlock_data;
90
91 size_t signalTypeCount[4];
92 size_t signalMemSize;
93
94 PdServ::TaskStatistics taskStatistics;
95
96 // Cache of the currently transferred signals
97 const Signal **signalCopyList[4];
98
99 std::vector<Signal*> signals;
100
101 unsigned int seqNo;
102 unsigned int signalListId;
103
104 // Pointer into shared memory used to communicate changes
105 // to the signal copy list
106 // The non-realtime thread writes using signalListWp whereas the
107 // realtime task reads using signalListRp
108 // This list is null terminated
109 struct SignalList *signalList, *signalListEnd,
110 * volatile *signalListRp, * volatile *signalListWp;
111
112 // Structure managed by the realtime thread containing a list of
113 // signals which it has to copy into every PDO
114 struct CopyList *copyList[4];
115
116 // Process data communication. Points to shared memory
117 struct Pdo *txMemBegin, *txPdo, * volatile *nextTxPdo;
118 const void *txMemEnd;
119
120 // Reimplemented from PdServ::Task
121 std::list<const PdServ::Signal*> getSignals() const;
122 void prepare(PdServ::SessionTask *) const;
123 void cleanup(const PdServ::SessionTask *) const;
124 // can throw RtProcessExited
125 bool rxPdo(PdServ::SessionTask *, const struct timespec **tasktime,
126 const PdServ::TaskStatistics **taskStatistics) const;
127
128 // These methods are used in real time context
129 void processSignalList();
130 void calculateCopyList();
131 void copyData(const struct timespec* t);
132
133 typedef std::set<const PdServ::Signal*> PersistentSet;
134 PersistentSet persistentSet;
135
136 struct Persistent: PdServ::SessionTask {
137 Persistent(Task* t);
138
139 // Reimplemented from PdServ::SessionTask
140 void newSignal( const PdServ::Signal *);
141
142 PersistentSet active;
143 };
144
145 Persistent *persist;
146 };
147
148 #endif // LIB_TASK_H
149