GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/Main.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 13 66 19.7%
Branches: 9 92 9.8%

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 "config.h"
25 #include "Debug.h"
26
27 #include <cerrno>
28 #include <cstdlib>
29 #include <syslog.h>
30 #include <log4cplus/logger.h>
31 #include <log4cplus/loggingmacros.h>
32
33 #include "Main.h"
34 #include "Task.h"
35 #include "Signal.h"
36 #include "ProcessParameter.h"
37 #include "Config.h"
38 //#include "etlproto/Server.h"
39 #include "msrproto/Server.h"
40 #include "supervisor/Server.h"
41
42 using namespace PdServ;
43
44 /////////////////////////////////////////////////////////////////////////////
45 11 Main::Main(const std::string& name, const std::string& version):
46 name(name), version(version), mutex(1),
47 parameterLog(log4cplus::Logger::getInstance(
48
4/8
✓ Branch 7 taken 11 times.
✗ Branch 8 not taken.
✓ Branch 15 taken 11 times.
✗ Branch 16 not taken.
✓ Branch 21 taken 11 times.
✗ Branch 22 not taken.
✓ Branch 26 taken 11 times.
✗ Branch 27 not taken.
11 LOG4CPLUS_STRING_TO_TSTRING("parameter")))
49 {
50 11 msrproto = 0;
51 11 supervisor = 0;
52 11 }
53
54 /////////////////////////////////////////////////////////////////////////////
55 22 Main::~Main()
56 {
57 77 for (ProcessParameters::iterator it = parameters.begin();
58
2/2
✓ Branch 6 taken 66 times.
✓ Branch 7 taken 11 times.
77 it != parameters.end(); ++it)
59
1/2
✓ Branch 2 taken 66 times.
✗ Branch 3 not taken.
66 delete *it;
60
61
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
11 delete msrproto;
62
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
11 delete supervisor;
63 11 }
64
65 /////////////////////////////////////////////////////////////////////////////
66 int Main::localtime(struct timespec* t)
67 {
68 struct timeval tv;
69
70 if (gettimeofday(&tv, 0))
71 return errno;
72 t->tv_sec = tv.tv_sec;
73 t->tv_nsec = tv.tv_usec * 1000;
74
75 return 0;
76 }
77
78 /////////////////////////////////////////////////////////////////////////////
79 void Main::getSessionStatistics(std::list<SessionStatistics>& stats) const
80 {
81 msrproto->getSessionStatistics(stats);
82 //etlproto->getSessionStatistics(stats);
83 }
84
85 /////////////////////////////////////////////////////////////////////////////
86 size_t Main::numTasks() const
87 {
88 return task.size();
89 }
90
91 /////////////////////////////////////////////////////////////////////////////
92 const Task* Main::getTask(size_t n) const
93 {
94 return task[n];
95 }
96
97 /////////////////////////////////////////////////////////////////////////////
98 const Task* Main::getTask(double sampleTime) const
99 {
100 for (TaskList::const_iterator it = task.begin();
101 it != task.end(); ++it)
102 if ((*it)->sampleTime == sampleTime)
103 return *it;
104
105 return 0;
106 }
107
108 /////////////////////////////////////////////////////////////////////////////
109 const Main::ProcessParameters& Main::getParameters() const
110 {
111 return parameters;
112 }
113
114 /////////////////////////////////////////////////////////////////////////////
115 void Main::startServers(const Config& config)
116 {
117 supervisor = new Supervisor::Server(this, config["supervisor"]);
118
119 msrproto = new MsrProto::Server(this, config["msr"]);
120
121 // EtlProto::Server etlproto(this);
122
123 }
124
125 /////////////////////////////////////////////////////////////////////////////
126 int Main::setParameter(const Session *, const ProcessParameter *param,
127 size_t offset, size_t count, const char *data) const
128 {
129 int rv = param->setValue(data, offset, count);
130
131 if (rv)
132 return rv;
133
134 msrproto->parameterChanged(param, offset, count);
135
136 std::ostringstream os;
137 os.imbue(std::locale::classic());
138 os << param->path;
139
140 if (count < param->memSize) {
141 os << '[' << offset;
142 if (count > 1)
143 os << ".." << (offset + count - 1);
144 os << ']';
145 }
146
147 os << " = ";
148
149 param->dtype.print(os, data - offset, data, data + count);
150
151 LOG4CPLUS_INFO(parameterLog, os.str());
152
153 return 0;
154 }
155
156 /////////////////////////////////////////////////////////////////////////////
157 void Main::poll( Session *session, const Signal * const *s,
158 size_t nelem, void *buf, struct timespec *t) const
159 {
160 ost::SemaphoreLock lock(mutex);
161 char *dest = reinterpret_cast<char*>(buf);
162 double delay = 0.01;
163 void *pollDest[nelem];
164
165 for (size_t i = 0; i < nelem; ++i) {
166 delay = std::max(delay,
167 std::min(0.1, s[i]->poll(session, dest, t)));
168 pollDest[i] = dest;
169 dest += s[i]->memSize;
170 }
171
172 processPoll(static_cast<unsigned>(delay * 1000 + 0.5),
173 s, nelem, pollDest, t);
174 3 }
175
176