GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/msrproto/StatSignal.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 1 32 3.1%
Branches: 0 24 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 "StatSignal.h"
25 #include "Session.h"
26 #include "TaskStatistics.h"
27 #include "SubscriptionManager.h"
28 #include "../TaskStatistics.h"
29 #include "../Task.h"
30 #include "../DataType.h"
31
32 using namespace MsrProto;
33
34 /////////////////////////////////////////////////////////////////////////////
35 StatSignal::StatSignal(const PdServ::Task *t, Type type, size_t index):
36 PdServ::Signal("StatSignal", t->sampleTime, 1,
37 PdServ::DataType::float64, 1, 0),
38 Channel(this, index,
39 this->PdServ::Signal::dtype, this->PdServ::Signal::dim, 0, 0),
40 task(t), type(type)
41 {
42 }
43
44 /////////////////////////////////////////////////////////////////////////////
45 void StatSignal::subscribe(PdServ::SessionTask *session) const
46 {
47 session->newSignal(this);
48 }
49
50 /////////////////////////////////////////////////////////////////////////////
51 void StatSignal::unsubscribe(PdServ::SessionTask *) const
52 {
53 }
54
55 /////////////////////////////////////////////////////////////////////////////
56 double StatSignal::getValue (
57 const PdServ::Session *s, struct timespec *t) const
58 {
59 const Session *session = static_cast<const Session*>(s);
60 const PdServ::TaskStatistics* stats = session->getTaskStatistics(task);
61
62 if (t)
63 *t = *session->getTaskTime(task);
64
65 if (stats) {
66 switch (type) {
67 case ExecTime:
68 return stats->exec_time;
69 break;
70
71 case Period:
72 return stats->cycle_time;
73 break;
74
75 case Overrun:
76 return stats->overrun;
77 }
78 }
79
80 return 0;
81 }
82
83 /////////////////////////////////////////////////////////////////////////////
84 double StatSignal::poll(const PdServ::Session *session,
85 void *buf, struct timespec *t) const
86 {
87 *reinterpret_cast<double*>(buf) = getValue(session, t);
88
89 return 0;
90 }
91
92 /////////////////////////////////////////////////////////////////////////////
93 const char *StatSignal::getValue(const PdServ::SessionTask* std) const
94 {
95 const SubscriptionManager* sm =
96 static_cast<const SubscriptionManager*>(std);
97 double* value = sm->session->getDouble();
98
99 poll(sm->session, value, 0);
100
101 return reinterpret_cast<const char*>(value);
102 }
103
104 /////////////////////////////////////////////////////////////////////////////
105 void StatSignal::getValue( const PdServ::Session *session,
106 void *buf, struct timespec* t) const
107 {
108 // cout << __PRETTY_FUNCTION__ << endl;
109 poll(session, buf, t);
110 3 }
111