GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/TimeSignal.cpp
Date: 2025-08-17 04:10:43
Exec Total Coverage
Lines: 3 23 13.0%
Branches: 3 18 16.7%

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