GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/msrproto/TimeSignal.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 1 23 4.3%
Branches: 0 18 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 #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 TimeSignal::TimeSignal(const PdServ::Task *t, size_t index):
36 PdServ::Signal("Time", t->sampleTime, 1, PdServ::DataType::float64, 1, 0),
37 Channel(this, index,
38 this->PdServ::Signal::dtype, this->PdServ::Signal::dim, 0, 0),
39 task(t)
40 {
41 }
42
43 /////////////////////////////////////////////////////////////////////////////
44 void TimeSignal::subscribe(PdServ::SessionTask *session) const
45 {
46 session->newSignal(this);
47 }
48
49 /////////////////////////////////////////////////////////////////////////////
50 void TimeSignal::unsubscribe(PdServ::SessionTask *) const
51 {
52 }
53
54 /////////////////////////////////////////////////////////////////////////////
55 double TimeSignal::poll(const PdServ::Session *s,
56 void *buf, struct timespec *t) const
57 {
58 const Session *session = static_cast<const Session*>(s);
59 const struct timespec *time = session->getTaskTime(task);
60
61 if (time) {
62 *reinterpret_cast<double*>(buf) = 1.0e-9 * time->tv_nsec + time->tv_sec;
63
64 if (t)
65 *t = *time;
66 }
67
68 return 0;
69 }
70
71 /////////////////////////////////////////////////////////////////////////////
72 const char *TimeSignal::getValue(const PdServ::SessionTask* std) const
73 {
74 const SubscriptionManager* sm =
75 static_cast<const SubscriptionManager*>(std);
76 double* value = sm->session->getDouble();
77
78 poll(sm->session, value, 0);
79
80 return reinterpret_cast<const char*>(value);
81 }
82
83 /////////////////////////////////////////////////////////////////////////////
84 void TimeSignal::getValue(const PdServ::Session* session,
85 void *buf, struct timespec* t) const
86 {
87 poll(session, buf, t);
88 3 }
89