F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
TcpServerComponentAc.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title TcpServerComponentAc.cpp
3// \author Generated by fpp-to-cpp
4// \brief cpp file for TcpServer component base class
5// ======================================================================
6
7#include <cstdio>
8
10#include "Fw/Types/Assert.hpp"
11#if FW_ENABLE_TEXT_LOGGING
12#include "Fw/Types/String.hpp"
13#endif
14
15namespace Drv {
16
17 // ----------------------------------------------------------------------
18 // Component initialization
19 // ----------------------------------------------------------------------
20
21 void TcpServerComponentBase ::
22 init(NATIVE_INT_TYPE instance)
23 {
24 // Initialize base class
26
27 // Connect input port send
28 for (
29 PlatformIntType port = 0;
30 port < static_cast<PlatformIntType>(this->getNum_send_InputPorts());
31 port++
32 ) {
33 this->m_send_InputPort[port].init();
34 this->m_send_InputPort[port].addCallComp(
35 this,
36 m_p_send_in
37 );
38 this->m_send_InputPort[port].setPortNum(port);
39
40#if FW_OBJECT_NAMES == 1
41 char portName[120];
42 (void) snprintf(
43 portName,
44 sizeof(portName),
45 "%s_send_InputPort[%" PRI_PlatformIntType "]",
46 this->m_objName,
47 port
48 );
49 this->m_send_InputPort[port].setObjName(portName);
50#endif
51 }
52
53 // Connect output port allocate
54 for (
55 PlatformIntType port = 0;
56 port < static_cast<PlatformIntType>(this->getNum_allocate_OutputPorts());
57 port++
58 ) {
59 this->m_allocate_OutputPort[port].init();
60
61#if FW_OBJECT_NAMES == 1
62 char portName[120];
63 (void) snprintf(
64 portName,
65 sizeof(portName),
66 "%s_allocate_OutputPort[%" PRI_PlatformIntType "]",
67 this->m_objName,
68 port
69 );
70 this->m_allocate_OutputPort[port].setObjName(portName);
71#endif
72 }
73
74 // Connect output port deallocate
75 for (
76 PlatformIntType port = 0;
77 port < static_cast<PlatformIntType>(this->getNum_deallocate_OutputPorts());
78 port++
79 ) {
80 this->m_deallocate_OutputPort[port].init();
81
82#if FW_OBJECT_NAMES == 1
83 char portName[120];
84 (void) snprintf(
85 portName,
86 sizeof(portName),
87 "%s_deallocate_OutputPort[%" PRI_PlatformIntType "]",
88 this->m_objName,
89 port
90 );
91 this->m_deallocate_OutputPort[port].setObjName(portName);
92#endif
93 }
94
95 // Connect output port ready
96 for (
97 PlatformIntType port = 0;
98 port < static_cast<PlatformIntType>(this->getNum_ready_OutputPorts());
99 port++
100 ) {
101 this->m_ready_OutputPort[port].init();
102
103#if FW_OBJECT_NAMES == 1
104 char portName[120];
105 (void) snprintf(
106 portName,
107 sizeof(portName),
108 "%s_ready_OutputPort[%" PRI_PlatformIntType "]",
109 this->m_objName,
110 port
111 );
112 this->m_ready_OutputPort[port].setObjName(portName);
113#endif
114 }
115
116 // Connect output port recv
117 for (
118 PlatformIntType port = 0;
119 port < static_cast<PlatformIntType>(this->getNum_recv_OutputPorts());
120 port++
121 ) {
122 this->m_recv_OutputPort[port].init();
123
124#if FW_OBJECT_NAMES == 1
125 char portName[120];
126 (void) snprintf(
127 portName,
128 sizeof(portName),
129 "%s_recv_OutputPort[%" PRI_PlatformIntType "]",
130 this->m_objName,
131 port
132 );
133 this->m_recv_OutputPort[port].setObjName(portName);
134#endif
135 }
136 }
137
138 // ----------------------------------------------------------------------
139 // Getters for typed input ports
140 // ----------------------------------------------------------------------
141
142 Drv::InputByteStreamSendPort* TcpServerComponentBase ::
143 get_send_InputPort(NATIVE_INT_TYPE portNum)
144 {
145 FW_ASSERT(
146 portNum < this->getNum_send_InputPorts(),
147 static_cast<FwAssertArgType>(portNum)
148 );
149
150 return &this->m_send_InputPort[portNum];
151 }
152
153 // ----------------------------------------------------------------------
154 // Connect typed input ports to typed output ports
155 // ----------------------------------------------------------------------
156
157 void TcpServerComponentBase ::
158 set_allocate_OutputPort(
159 NATIVE_INT_TYPE portNum,
161 )
162 {
163 FW_ASSERT(
164 portNum < this->getNum_allocate_OutputPorts(),
165 static_cast<FwAssertArgType>(portNum)
166 );
167
168 this->m_allocate_OutputPort[portNum].addCallPort(port);
169 }
170
171 void TcpServerComponentBase ::
172 set_deallocate_OutputPort(
173 NATIVE_INT_TYPE portNum,
175 )
176 {
177 FW_ASSERT(
178 portNum < this->getNum_deallocate_OutputPorts(),
179 static_cast<FwAssertArgType>(portNum)
180 );
181
182 this->m_deallocate_OutputPort[portNum].addCallPort(port);
183 }
184
185 void TcpServerComponentBase ::
186 set_ready_OutputPort(
187 NATIVE_INT_TYPE portNum,
189 )
190 {
191 FW_ASSERT(
192 portNum < this->getNum_ready_OutputPorts(),
193 static_cast<FwAssertArgType>(portNum)
194 );
195
196 this->m_ready_OutputPort[portNum].addCallPort(port);
197 }
198
199 void TcpServerComponentBase ::
200 set_recv_OutputPort(
201 NATIVE_INT_TYPE portNum,
203 )
204 {
205 FW_ASSERT(
206 portNum < this->getNum_recv_OutputPorts(),
207 static_cast<FwAssertArgType>(portNum)
208 );
209
210 this->m_recv_OutputPort[portNum].addCallPort(port);
211 }
212
213#if FW_PORT_SERIALIZATION
214
215 // ----------------------------------------------------------------------
216 // Connect serial input ports to typed output ports
217 // ----------------------------------------------------------------------
218
219 void TcpServerComponentBase ::
220 set_deallocate_OutputPort(
221 NATIVE_INT_TYPE portNum,
222 Fw::InputSerializePort* port
223 )
224 {
225 FW_ASSERT(
226 portNum < this->getNum_deallocate_OutputPorts(),
227 static_cast<FwAssertArgType>(portNum)
228 );
229
230 this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
231 }
232
233 void TcpServerComponentBase ::
234 set_ready_OutputPort(
235 NATIVE_INT_TYPE portNum,
236 Fw::InputSerializePort* port
237 )
238 {
239 FW_ASSERT(
240 portNum < this->getNum_ready_OutputPorts(),
241 static_cast<FwAssertArgType>(portNum)
242 );
243
244 this->m_ready_OutputPort[portNum].registerSerialPort(port);
245 }
246
247 void TcpServerComponentBase ::
248 set_recv_OutputPort(
249 NATIVE_INT_TYPE portNum,
250 Fw::InputSerializePort* port
251 )
252 {
253 FW_ASSERT(
254 portNum < this->getNum_recv_OutputPorts(),
255 static_cast<FwAssertArgType>(portNum)
256 );
257
258 this->m_recv_OutputPort[portNum].registerSerialPort(port);
259 }
260
261#endif
262
263 // ----------------------------------------------------------------------
264 // Component construction and destruction
265 // ----------------------------------------------------------------------
266
267 TcpServerComponentBase ::
268 TcpServerComponentBase(const char* compName) :
269 Fw::PassiveComponentBase(compName)
270 {
271
272 }
273
274 TcpServerComponentBase ::
275 ~TcpServerComponentBase()
276 {
277
278 }
279
280 // ----------------------------------------------------------------------
281 // Getters for numbers of typed input ports
282 // ----------------------------------------------------------------------
283
284 NATIVE_INT_TYPE TcpServerComponentBase ::
285 getNum_send_InputPorts() const
286 {
287 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_send_InputPort));
288 }
289
290 // ----------------------------------------------------------------------
291 // Getters for numbers of typed output ports
292 // ----------------------------------------------------------------------
293
294 NATIVE_INT_TYPE TcpServerComponentBase ::
295 getNum_allocate_OutputPorts() const
296 {
297 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
298 }
299
300 NATIVE_INT_TYPE TcpServerComponentBase ::
301 getNum_deallocate_OutputPorts() const
302 {
303 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
304 }
305
306 NATIVE_INT_TYPE TcpServerComponentBase ::
307 getNum_ready_OutputPorts() const
308 {
309 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
310 }
311
312 NATIVE_INT_TYPE TcpServerComponentBase ::
313 getNum_recv_OutputPorts() const
314 {
315 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_recv_OutputPort));
316 }
317
318 // ----------------------------------------------------------------------
319 // Connection status queries for typed output ports
320 // ----------------------------------------------------------------------
321
322 bool TcpServerComponentBase ::
323 isConnected_allocate_OutputPort(NATIVE_INT_TYPE portNum)
324 {
325 FW_ASSERT(
326 portNum < this->getNum_allocate_OutputPorts(),
327 static_cast<FwAssertArgType>(portNum)
328 );
329
330 return this->m_allocate_OutputPort[portNum].isConnected();
331 }
332
333 bool TcpServerComponentBase ::
334 isConnected_deallocate_OutputPort(NATIVE_INT_TYPE portNum)
335 {
336 FW_ASSERT(
337 portNum < this->getNum_deallocate_OutputPorts(),
338 static_cast<FwAssertArgType>(portNum)
339 );
340
341 return this->m_deallocate_OutputPort[portNum].isConnected();
342 }
343
344 bool TcpServerComponentBase ::
345 isConnected_ready_OutputPort(NATIVE_INT_TYPE portNum)
346 {
347 FW_ASSERT(
348 portNum < this->getNum_ready_OutputPorts(),
349 static_cast<FwAssertArgType>(portNum)
350 );
351
352 return this->m_ready_OutputPort[portNum].isConnected();
353 }
354
355 bool TcpServerComponentBase ::
356 isConnected_recv_OutputPort(NATIVE_INT_TYPE portNum)
357 {
358 FW_ASSERT(
359 portNum < this->getNum_recv_OutputPorts(),
360 static_cast<FwAssertArgType>(portNum)
361 );
362
363 return this->m_recv_OutputPort[portNum].isConnected();
364 }
365
366 // ----------------------------------------------------------------------
367 // Port handler base-class functions for typed input ports
368 //
369 // Call these functions directly to bypass the corresponding ports
370 // ----------------------------------------------------------------------
371
372 Drv::SendStatus TcpServerComponentBase ::
373 send_handlerBase(
374 NATIVE_INT_TYPE portNum,
375 Fw::Buffer& sendBuffer
376 )
377 {
378 // Make sure port number is valid
379 FW_ASSERT(
380 portNum < this->getNum_send_InputPorts(),
381 static_cast<FwAssertArgType>(portNum)
382 );
383
384 Drv::SendStatus retVal;
385
386 // Lock guard mutex before calling
387 this->lock();
388
389 // Down call to pure virtual handler method implemented in Impl class
390 retVal = this->send_handler(
391 portNum,
392 sendBuffer
393 );
394
395 // Unlock guard mutex
396 this->unLock();
397
398 return retVal;
399 }
400
401 // ----------------------------------------------------------------------
402 // Invocation functions for typed output ports
403 // ----------------------------------------------------------------------
404
405 Fw::Buffer TcpServerComponentBase ::
406 allocate_out(
407 NATIVE_INT_TYPE portNum,
408 U32 size
409 )
410 {
411 FW_ASSERT(
412 portNum < this->getNum_allocate_OutputPorts(),
413 static_cast<FwAssertArgType>(portNum)
414 );
415 return this->m_allocate_OutputPort[portNum].invoke(
416 size
417 );
418 }
419
420 void TcpServerComponentBase ::
421 deallocate_out(
422 NATIVE_INT_TYPE portNum,
423 Fw::Buffer& fwBuffer
424 )
425 {
426 FW_ASSERT(
427 portNum < this->getNum_deallocate_OutputPorts(),
428 static_cast<FwAssertArgType>(portNum)
429 );
430 this->m_deallocate_OutputPort[portNum].invoke(
431 fwBuffer
432 );
433 }
434
435 void TcpServerComponentBase ::
436 ready_out(NATIVE_INT_TYPE portNum)
437 {
438 FW_ASSERT(
439 portNum < this->getNum_ready_OutputPorts(),
440 static_cast<FwAssertArgType>(portNum)
441 );
442 this->m_ready_OutputPort[portNum].invoke();
443 }
444
445 void TcpServerComponentBase ::
446 recv_out(
447 NATIVE_INT_TYPE portNum,
448 Fw::Buffer& recvBuffer,
449 const Drv::RecvStatus& recvStatus
450 )
451 {
452 FW_ASSERT(
453 portNum < this->getNum_recv_OutputPorts(),
454 static_cast<FwAssertArgType>(portNum)
455 );
456 this->m_recv_OutputPort[portNum].invoke(
457 recvBuffer,
458 recvStatus
459 );
460 }
461
462 // ----------------------------------------------------------------------
463 // Mutex operations for guarded ports
464 //
465 // You can override these operations to provide more sophisticated
466 // synchronization
467 // ----------------------------------------------------------------------
468
469 void TcpServerComponentBase ::
470 lock()
471 {
472 this->m_guardedPortMutex.lock();
473 }
474
475 void TcpServerComponentBase ::
476 unLock()
477 {
478 this->m_guardedPortMutex.unLock();
479 }
480
481 // ----------------------------------------------------------------------
482 // Calls for messages received on typed input ports
483 // ----------------------------------------------------------------------
484
485 Drv::SendStatus TcpServerComponentBase ::
486 m_p_send_in(
487 Fw::PassiveComponentBase* callComp,
488 NATIVE_INT_TYPE portNum,
489 Fw::Buffer& sendBuffer
490 )
491 {
492 FW_ASSERT(callComp);
493 TcpServerComponentBase* compPtr = static_cast<TcpServerComponentBase*>(callComp);
494 return compPtr->send_handlerBase(
495 portNum,
496 sendBuffer
497 );
498 }
499
500}
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition BasicTypes.h:66
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
PlatformAssertArgType FwAssertArgType
Definition FpConfig.h:21
Status associated with the received data.
Status returned by the send call.
Auto-generated base for TcpServer component.
Drv::SendStatus send_handlerBase(NATIVE_INT_TYPE portNum, Fw::Buffer &sendBuffer)
Handler base-class function for input port send.
Input BufferGet port.
Input BufferSend port.
void init()
Object initializer.
Definition ObjBase.cpp:27