GCC Code Coverage Report


Directory: ./
File: pdserv-1.1.0/src/lib/interface.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 47 73 64.4%
Branches: 8 34 23.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 "Main.h"
25 #include "Task.h"
26 #include "Signal.h"
27 #include "Event.h"
28 #include "Parameter.h"
29 #include "../DataType.h"
30 #include "pdserv.h"
31
32 typedef std::vector<PdServ::DataType*> CompoundVector;
33 1 CompoundVector compoundType;
34
35 static const PdServ::DataType& getDataType(int dt);
36
37 /////////////////////////////////////////////////////////////////////////////
38 11 struct pdserv* pdserv_create( const char *name, const char *version,
39 int (*gettime)(struct timespec*))
40 {
41 return reinterpret_cast<struct pdserv*>(
42
1/2
✓ Branch 3 taken 11 times.
✗ Branch 4 not taken.
11 new Main(name, version, gettime));
43 }
44
45 /////////////////////////////////////////////////////////////////////////////
46 11 void pdserv_config_file( struct pdserv* pdserv, const char *name)
47 {
48 11 reinterpret_cast<Main*>(pdserv)->setConfigFile(name);
49 11 }
50
51 /////////////////////////////////////////////////////////////////////////////
52 22 struct pdtask* pdserv_create_task(struct pdserv* pdserv, double tsample,
53 const char *name)
54 {
55 return reinterpret_cast<struct pdtask*>(
56 22 reinterpret_cast<Main*>(pdserv)->addTask(tsample, name));
57 }
58
59 /////////////////////////////////////////////////////////////////////////////
60 int pdserv_create_compound( const char *name, size_t size)
61 {
62 int dt = pd_datatype_end + compoundType.size();
63 compoundType.push_back(new PdServ::DataType(name, size));
64 return dt;
65 }
66
67 /////////////////////////////////////////////////////////////////////////////
68 void pdserv_compound_add_field(int compound, const char *name,
69 int data_type, size_t offset, size_t ndims, const size_t *dim)
70 {
71 compoundType[compound - pd_datatype_end]
72 ->addField(name, getDataType(data_type), offset, ndims, dim);
73 }
74
75 /////////////////////////////////////////////////////////////////////////////
76 11 void pdserv_exit(struct pdserv* pdserv)
77 {
78 11 for (CompoundVector::const_iterator it = compoundType.begin();
79
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 11 times.
11 it != compoundType.end(); ++it)
80 delete *it;
81
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 delete reinterpret_cast<Main*>(pdserv);
82 11 }
83
84 /////////////////////////////////////////////////////////////////////////////
85 1305 void pdserv_get_parameters(struct pdserv* pdserv, struct pdtask *task,
86 const struct timespec *t)
87 {
88 1305 reinterpret_cast<Main*>(pdserv)->getParameters(
89 reinterpret_cast<Task*>(task), t);
90 1305 }
91
92 /////////////////////////////////////////////////////////////////////////////
93 void pdserv_update_statistics(struct pdtask* task,
94 double exec_time, double cycle_time, unsigned int overrun)
95 {
96 reinterpret_cast<Task*>(task)->updateStatistics(
97 exec_time, cycle_time, overrun);
98 }
99
100 /////////////////////////////////////////////////////////////////////////////
101 1376 void pdserv_update(struct pdtask* task, const struct timespec *t)
102 {
103 1376 reinterpret_cast<Task*>(task)->update(t);
104 1376 }
105
106 /////////////////////////////////////////////////////////////////////////////
107 110 static const PdServ::DataType& getDataType(int dt)
108 {
109
4/12
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 66 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 11 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
110 switch (dt) {
110 case pd_boolean_T: return PdServ::DataType::boolean;
111 case pd_uint8_T: return PdServ::DataType::uint8;
112 case pd_uint16_T: return PdServ::DataType::uint16;
113 22 case pd_uint32_T: return PdServ::DataType::uint32;
114 case pd_uint64_T: return PdServ::DataType::uint64;
115 case pd_sint8_T: return PdServ::DataType::int8;
116 11 case pd_sint16_T: return PdServ::DataType::int16;
117 66 case pd_sint32_T: return PdServ::DataType::int32;
118 case pd_sint64_T: return PdServ::DataType::int64;
119 11 case pd_double_T: return PdServ::DataType::float64;
120 case pd_single_T: return PdServ::DataType::float32;
121 default:
122 return *compoundType[dt - pd_datatype_end];
123 }
124 }
125
126 /////////////////////////////////////////////////////////////////////////////
127 22 const struct pdevent *pdserv_event (struct pdserv* pdserv, const char *path,
128 int prio, size_t n, const char **message)
129 {
130 22 Main *main = reinterpret_cast<Main*>(pdserv);
131
132 22 Event *e = main->addEvent(path, prio, n, message);
133
134 22 return reinterpret_cast<const struct pdevent *>(e);
135 }
136
137 /////////////////////////////////////////////////////////////////////////////
138 2 void pdserv_event_set(const struct pdevent *event,
139 size_t element, char state, const timespec *t)
140 {
141 2 reinterpret_cast<const Event*>(event)->set(element, state != 0, t);
142 2 }
143
144 /////////////////////////////////////////////////////////////////////////////
145 44 struct pdvariable *pdserv_signal(
146 struct pdtask* pdtask,
147 unsigned int decimation,
148 const char *path,
149 int datatype,
150 const void *addr,
151 size_t n,
152 const size_t *dim
153 )
154 {
155 44 Task *task = reinterpret_cast<Task*>(pdtask);
156
157 44 PdServ::Variable *v = task->main->addSignal(
158 44 task, decimation, path, getDataType(datatype), addr, n, dim);
159
160 44 return reinterpret_cast<struct pdvariable *>(v);
161 }
162
163 /////////////////////////////////////////////////////////////////////////////
164 66 struct pdvariable *pdserv_parameter(
165 struct pdserv* pdserv,
166 const char *path,
167 unsigned int mode,
168 int datatype,
169 void *addr,
170 size_t n,
171 const size_t *dim,
172 paramtrigger_t trigger = 0,
173 void *priv_data = 0
174 )
175 {
176 66 Main *main = reinterpret_cast<Main*>(pdserv);
177
178 66 Parameter *p = main->addParameter(
179 66 path, mode, getDataType(datatype), addr, n, dim);
180
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66 times.
66 if (trigger)
181 p->trigger = trigger;
182 66 p->priv_data = priv_data;
183
184 return reinterpret_cast<struct pdvariable *>
185 66 (static_cast<PdServ::Variable*>(p));
186 }
187
188 /////////////////////////////////////////////////////////////////////////////
189 void pdserv_set_alias(struct pdvariable *var, const char *alias)
190 {
191 reinterpret_cast<PdServ::Variable*>(var)->alias = alias;
192 }
193
194 /////////////////////////////////////////////////////////////////////////////
195 void pdserv_set_unit(struct pdvariable *var, const char *unit)
196 {
197 reinterpret_cast<PdServ::Variable*>(var)->unit = unit;
198 }
199
200 /////////////////////////////////////////////////////////////////////////////
201 void pdserv_set_comment(struct pdvariable *var, const char *comment)
202 {
203 reinterpret_cast<PdServ::Variable*>(var)->comment = comment;
204 }
205
206 /////////////////////////////////////////////////////////////////////////////
207 11 int pdserv_prepare(struct pdserv* pdserv)
208 {
209 11 return reinterpret_cast<Main*>(pdserv)->run();
210 3 }
211