GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/StatSignal.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 4 32 12.5%
Branches: 3 24 12.5%

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 780 StatSignal::StatSignal(const PdServ::Task *task, Type type, size_t index):
36 PdServ::Signal("StatSignal", task, 1U, PdServ::DataType::float64),
37 Channel(this, index,
38 780 this->PdServ::Signal::dtype, this->PdServ::Signal::dim, 0),
39
3/6
✓ Branch 5 taken 780 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 780 times.
✗ Branch 10 not taken.
✓ Branch 19 taken 780 times.
✗ Branch 20 not taken.
1560 type(type)
40 {
41 780 }
42
43 /////////////////////////////////////////////////////////////////////////////
44 void StatSignal::subscribe(PdServ::SessionTask *session) const
45 {
46 session->newSignal(this);
47 }
48
49 /////////////////////////////////////////////////////////////////////////////
50 void StatSignal::unsubscribe(PdServ::SessionTask *) const
51 {
52 }
53
54 /////////////////////////////////////////////////////////////////////////////
55 double StatSignal::getValue (
56 const PdServ::Session *s, struct timespec *t) const
57 {
58 const Session *session = static_cast<const Session*>(s);
59 const PdServ::TaskStatistics* stats =
60 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 int 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 return 0;
111 }
112