GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/TimeSignal.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 3 22 13.6%
Branches: 3 18 16.7%

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 "TimeSignal.h"
25 #include "Session.h"
26 #include "SubscriptionManager.h"
27 #include "TaskStatistics.h"
28 #include "../TaskStatistics.h"
29 #include "../Task.h"
30 #include "../DataType.h"
31
32 using namespace MsrProto;
33
34 /////////////////////////////////////////////////////////////////////////////
35 260 TimeSignal::TimeSignal(const PdServ::Task *task, size_t index):
36 PdServ::Signal("Time", task, 1U, PdServ::DataType::float64),
37 Channel(this, index,
38
3/6
✓ Branch 5 taken 260 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 260 times.
✗ Branch 10 not taken.
✓ Branch 21 taken 260 times.
✗ Branch 22 not taken.
260 this->PdServ::Signal::dtype, this->PdServ::Signal::dim, 0)
39 {
40 260 }
41
42 /////////////////////////////////////////////////////////////////////////////
43 void TimeSignal::subscribe(PdServ::SessionTask *session) const
44 {
45 session->newSignal(this);
46 }
47
48 /////////////////////////////////////////////////////////////////////////////
49 void TimeSignal::unsubscribe(PdServ::SessionTask *) const
50 {
51 }
52
53 /////////////////////////////////////////////////////////////////////////////
54 double TimeSignal::poll(const PdServ::Session *s,
55 void *buf, struct timespec *t) const
56 {
57 const Session *session = static_cast<const Session*>(s);
58 const struct timespec *time = session->getTaskTime(task);
59
60 if (time) {
61 *reinterpret_cast<double*>(buf) = 1.0e-9 * time->tv_nsec + time->tv_sec;
62
63 if (t)
64 *t = *time;
65 }
66
67 return 0;
68 }
69
70 /////////////////////////////////////////////////////////////////////////////
71 const char *TimeSignal::getValue(const PdServ::SessionTask* std) const
72 {
73 const SubscriptionManager* sm =
74 static_cast<const SubscriptionManager*>(std);
75 double* value = sm->session->getDouble();
76
77 poll(sm->session, value, 0);
78
79 return reinterpret_cast<const char*>(value);
80 }
81
82 /////////////////////////////////////////////////////////////////////////////
83 int TimeSignal::getValue(const PdServ::Session* session,
84 void *buf, struct timespec* t) const
85 {
86 poll(session, buf, t);
87 return 0;
88 }
89