GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/lib/Signal.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 6 25 24.0%
Branches: 3 38 7.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 "../Debug.h"
25
26 #include "../SessionTask.h"
27 #include "Signal.h"
28 #include "Main.h"
29 #include "SessionTaskData.h"
30 #include "../DataType.h"
31
32 //////////////////////////////////////////////////////////////////////
33 const size_t Signal::dataTypeIndex[PdServ::DataType::maxWidth+1] = {
34 3 /*0*/, 3 /*1*/, 2 /*2*/, 3 /*3*/,
35 1 /*4*/, 3 /*5*/, 3 /*6*/, 3 /*7*/, 0 /*8*/
36 };
37
38 //////////////////////////////////////////////////////////////////////
39 60 Signal::Signal( Task *task,
40 size_t index,
41 unsigned int decimation,
42 const char *path,
43 const PdServ::DataType& dtype,
44 const void *addr,
45 size_t ndims,
46 60 const size_t *dim):
47 60 PdServ::Signal(path, task->sampleTime, decimation, dtype, ndims, dim),
48 addr(reinterpret_cast<const char *>(addr)),
49 index(index), task(task),
50
3/6
✓ Branch 5 taken 60 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 60 times.
✗ Branch 10 not taken.
✓ Branch 27 taken 60 times.
✗ Branch 28 not taken.
120 mutex(1)
51 {
52 60 }
53
54 //////////////////////////////////////////////////////////////////////
55 void Signal::subscribe(PdServ::SessionTask *s) const
56 {
57 ost::SemaphoreLock lock(mutex);
58
59 if (sessions.empty()) {
60 // log_debug("Request signal from RT task %p", s);
61 task->subscribe(this, true);
62 }
63 else if (s->sessionTaskData->isBusy(this)) {
64 // log_debug("Signal already transferred");
65 s->newSignal(this);
66 }
67
68 sessions.insert(s);
69 }
70
71 //////////////////////////////////////////////////////////////////////
72 void Signal::unsubscribe(PdServ::SessionTask *s) const
73 {
74 ost::SemaphoreLock lock(mutex);
75
76 if (sessions.erase(s) and sessions.empty())
77 task->subscribe(this, false);
78 }
79
80 //////////////////////////////////////////////////////////////////////
81 double Signal::poll(const PdServ::Session *,
82 void *dest, struct timespec *) const
83 {
84 task->pollPrepare(this, dest);
85
86 return task->sampleTime / 2;
87 }
88
89 //////////////////////////////////////////////////////////////////////
90 void Signal::getValue( const PdServ::Session*, void *dest,
91 struct timespec *t) const
92 {
93 const PdServ::Signal *signal = this;
94
95 task->main->poll(0, &signal, 1, dest, t);
96 }
97
98 //////////////////////////////////////////////////////////////////////
99 const char *Signal::getValue(const PdServ::SessionTask* st) const
100 {
101 return st->sessionTaskData->getValue(this);
102 3 }
103