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 // The port name consists of this->m_objName and some extra info.
42 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
43 // However, the compiler may assume that this->m_objName fills
44 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
45 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
46 // bytes to cover the extra info.
47 char portName[2*FW_OBJ_NAME_MAX_SIZE];
48 (void) snprintf(
49 portName,
50 sizeof(portName),
51 "%s_send_InputPort[%" PRI_PlatformIntType "]",
52 this->m_objName,
53 port
54 );
55 this->m_send_InputPort[port].setObjName(portName);
56#endif
57 }
58
59 // Connect output port allocate
60 for (
61 PlatformIntType port = 0;
62 port < static_cast<PlatformIntType>(this->getNum_allocate_OutputPorts());
63 port++
64 ) {
65 this->m_allocate_OutputPort[port].init();
66
67#if FW_OBJECT_NAMES == 1
68 // The port name consists of this->m_objName and some extra info.
69 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
70 // However, the compiler may assume that this->m_objName fills
71 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
72 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
73 // bytes to cover the extra info.
74 char portName[2*FW_OBJ_NAME_MAX_SIZE];
75 (void) snprintf(
76 portName,
77 sizeof(portName),
78 "%s_allocate_OutputPort[%" PRI_PlatformIntType "]",
79 this->m_objName,
80 port
81 );
82 this->m_allocate_OutputPort[port].setObjName(portName);
83#endif
84 }
85
86 // Connect output port deallocate
87 for (
88 PlatformIntType port = 0;
89 port < static_cast<PlatformIntType>(this->getNum_deallocate_OutputPorts());
90 port++
91 ) {
92 this->m_deallocate_OutputPort[port].init();
93
94#if FW_OBJECT_NAMES == 1
95 // The port name consists of this->m_objName and some extra info.
96 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
97 // However, the compiler may assume that this->m_objName fills
98 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
99 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
100 // bytes to cover the extra info.
101 char portName[2*FW_OBJ_NAME_MAX_SIZE];
102 (void) snprintf(
103 portName,
104 sizeof(portName),
105 "%s_deallocate_OutputPort[%" PRI_PlatformIntType "]",
106 this->m_objName,
107 port
108 );
109 this->m_deallocate_OutputPort[port].setObjName(portName);
110#endif
111 }
112
113 // Connect output port ready
114 for (
115 PlatformIntType port = 0;
116 port < static_cast<PlatformIntType>(this->getNum_ready_OutputPorts());
117 port++
118 ) {
119 this->m_ready_OutputPort[port].init();
120
121#if FW_OBJECT_NAMES == 1
122 // The port name consists of this->m_objName and some extra info.
123 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
124 // However, the compiler may assume that this->m_objName fills
125 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
126 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
127 // bytes to cover the extra info.
128 char portName[2*FW_OBJ_NAME_MAX_SIZE];
129 (void) snprintf(
130 portName,
131 sizeof(portName),
132 "%s_ready_OutputPort[%" PRI_PlatformIntType "]",
133 this->m_objName,
134 port
135 );
136 this->m_ready_OutputPort[port].setObjName(portName);
137#endif
138 }
139
140 // Connect output port recv
141 for (
142 PlatformIntType port = 0;
143 port < static_cast<PlatformIntType>(this->getNum_recv_OutputPorts());
144 port++
145 ) {
146 this->m_recv_OutputPort[port].init();
147
148#if FW_OBJECT_NAMES == 1
149 // The port name consists of this->m_objName and some extra info.
150 // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
151 // However, the compiler may assume that this->m_objName fills
152 // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
153 // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
154 // bytes to cover the extra info.
155 char portName[2*FW_OBJ_NAME_MAX_SIZE];
156 (void) snprintf(
157 portName,
158 sizeof(portName),
159 "%s_recv_OutputPort[%" PRI_PlatformIntType "]",
160 this->m_objName,
161 port
162 );
163 this->m_recv_OutputPort[port].setObjName(portName);
164#endif
165 }
166 }
167
168 // ----------------------------------------------------------------------
169 // Getters for typed input ports
170 // ----------------------------------------------------------------------
171
172 Drv::InputByteStreamSendPort* TcpServerComponentBase ::
173 get_send_InputPort(NATIVE_INT_TYPE portNum)
174 {
175 FW_ASSERT(
176 portNum < this->getNum_send_InputPorts(),
177 static_cast<FwAssertArgType>(portNum)
178 );
179
180 return &this->m_send_InputPort[portNum];
181 }
182
183 // ----------------------------------------------------------------------
184 // Connect typed input ports to typed output ports
185 // ----------------------------------------------------------------------
186
187 void TcpServerComponentBase ::
188 set_allocate_OutputPort(
189 NATIVE_INT_TYPE portNum,
191 )
192 {
193 FW_ASSERT(
194 portNum < this->getNum_allocate_OutputPorts(),
195 static_cast<FwAssertArgType>(portNum)
196 );
197
198 this->m_allocate_OutputPort[portNum].addCallPort(port);
199 }
200
201 void TcpServerComponentBase ::
202 set_deallocate_OutputPort(
203 NATIVE_INT_TYPE portNum,
205 )
206 {
207 FW_ASSERT(
208 portNum < this->getNum_deallocate_OutputPorts(),
209 static_cast<FwAssertArgType>(portNum)
210 );
211
212 this->m_deallocate_OutputPort[portNum].addCallPort(port);
213 }
214
215 void TcpServerComponentBase ::
216 set_ready_OutputPort(
217 NATIVE_INT_TYPE portNum,
219 )
220 {
221 FW_ASSERT(
222 portNum < this->getNum_ready_OutputPorts(),
223 static_cast<FwAssertArgType>(portNum)
224 );
225
226 this->m_ready_OutputPort[portNum].addCallPort(port);
227 }
228
229 void TcpServerComponentBase ::
230 set_recv_OutputPort(
231 NATIVE_INT_TYPE portNum,
233 )
234 {
235 FW_ASSERT(
236 portNum < this->getNum_recv_OutputPorts(),
237 static_cast<FwAssertArgType>(portNum)
238 );
239
240 this->m_recv_OutputPort[portNum].addCallPort(port);
241 }
242
243#if FW_PORT_SERIALIZATION
244
245 // ----------------------------------------------------------------------
246 // Connect serial input ports to typed output ports
247 // ----------------------------------------------------------------------
248
249 void TcpServerComponentBase ::
250 set_deallocate_OutputPort(
251 NATIVE_INT_TYPE portNum,
252 Fw::InputSerializePort* port
253 )
254 {
255 FW_ASSERT(
256 portNum < this->getNum_deallocate_OutputPorts(),
257 static_cast<FwAssertArgType>(portNum)
258 );
259
260 this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
261 }
262
263 void TcpServerComponentBase ::
264 set_ready_OutputPort(
265 NATIVE_INT_TYPE portNum,
266 Fw::InputSerializePort* port
267 )
268 {
269 FW_ASSERT(
270 portNum < this->getNum_ready_OutputPorts(),
271 static_cast<FwAssertArgType>(portNum)
272 );
273
274 this->m_ready_OutputPort[portNum].registerSerialPort(port);
275 }
276
277 void TcpServerComponentBase ::
278 set_recv_OutputPort(
279 NATIVE_INT_TYPE portNum,
280 Fw::InputSerializePort* port
281 )
282 {
283 FW_ASSERT(
284 portNum < this->getNum_recv_OutputPorts(),
285 static_cast<FwAssertArgType>(portNum)
286 );
287
288 this->m_recv_OutputPort[portNum].registerSerialPort(port);
289 }
290
291#endif
292
293 // ----------------------------------------------------------------------
294 // Component construction and destruction
295 // ----------------------------------------------------------------------
296
297 TcpServerComponentBase ::
298 TcpServerComponentBase(const char* compName) :
299 Fw::PassiveComponentBase(compName)
300 {
301
302 }
303
304 TcpServerComponentBase ::
305 ~TcpServerComponentBase()
306 {
307
308 }
309
310 // ----------------------------------------------------------------------
311 // Getters for numbers of typed input ports
312 // ----------------------------------------------------------------------
313
314 NATIVE_INT_TYPE TcpServerComponentBase ::
315 getNum_send_InputPorts() const
316 {
317 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_send_InputPort));
318 }
319
320 // ----------------------------------------------------------------------
321 // Getters for numbers of typed output ports
322 // ----------------------------------------------------------------------
323
324 NATIVE_INT_TYPE TcpServerComponentBase ::
325 getNum_allocate_OutputPorts() const
326 {
327 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
328 }
329
330 NATIVE_INT_TYPE TcpServerComponentBase ::
331 getNum_deallocate_OutputPorts() const
332 {
333 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
334 }
335
336 NATIVE_INT_TYPE TcpServerComponentBase ::
337 getNum_ready_OutputPorts() const
338 {
339 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
340 }
341
342 NATIVE_INT_TYPE TcpServerComponentBase ::
343 getNum_recv_OutputPorts() const
344 {
345 return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_recv_OutputPort));
346 }
347
348 // ----------------------------------------------------------------------
349 // Connection status queries for typed output ports
350 // ----------------------------------------------------------------------
351
352 bool TcpServerComponentBase ::
353 isConnected_allocate_OutputPort(NATIVE_INT_TYPE portNum)
354 {
355 FW_ASSERT(
356 portNum < this->getNum_allocate_OutputPorts(),
357 static_cast<FwAssertArgType>(portNum)
358 );
359
360 return this->m_allocate_OutputPort[portNum].isConnected();
361 }
362
363 bool TcpServerComponentBase ::
364 isConnected_deallocate_OutputPort(NATIVE_INT_TYPE portNum)
365 {
366 FW_ASSERT(
367 portNum < this->getNum_deallocate_OutputPorts(),
368 static_cast<FwAssertArgType>(portNum)
369 );
370
371 return this->m_deallocate_OutputPort[portNum].isConnected();
372 }
373
374 bool TcpServerComponentBase ::
375 isConnected_ready_OutputPort(NATIVE_INT_TYPE portNum)
376 {
377 FW_ASSERT(
378 portNum < this->getNum_ready_OutputPorts(),
379 static_cast<FwAssertArgType>(portNum)
380 );
381
382 return this->m_ready_OutputPort[portNum].isConnected();
383 }
384
385 bool TcpServerComponentBase ::
386 isConnected_recv_OutputPort(NATIVE_INT_TYPE portNum)
387 {
388 FW_ASSERT(
389 portNum < this->getNum_recv_OutputPorts(),
390 static_cast<FwAssertArgType>(portNum)
391 );
392
393 return this->m_recv_OutputPort[portNum].isConnected();
394 }
395
396 // ----------------------------------------------------------------------
397 // Port handler base-class functions for typed input ports
398 //
399 // Call these functions directly to bypass the corresponding ports
400 // ----------------------------------------------------------------------
401
402 Drv::SendStatus TcpServerComponentBase ::
403 send_handlerBase(
404 NATIVE_INT_TYPE portNum,
405 Fw::Buffer& sendBuffer
406 )
407 {
408 // Make sure port number is valid
409 FW_ASSERT(
410 portNum < this->getNum_send_InputPorts(),
411 static_cast<FwAssertArgType>(portNum)
412 );
413
414 Drv::SendStatus retVal;
415
416 // Lock guard mutex before calling
417 this->lock();
418
419 // Call handler function
420 retVal = this->send_handler(
421 portNum,
422 sendBuffer
423 );
424
425 // Unlock guard mutex
426 this->unLock();
427
428 return retVal;
429 }
430
431 // ----------------------------------------------------------------------
432 // Invocation functions for typed output ports
433 // ----------------------------------------------------------------------
434
435 Fw::Buffer TcpServerComponentBase ::
436 allocate_out(
437 NATIVE_INT_TYPE portNum,
438 U32 size
439 )
440 {
441 FW_ASSERT(
442 portNum < this->getNum_allocate_OutputPorts(),
443 static_cast<FwAssertArgType>(portNum)
444 );
445 return this->m_allocate_OutputPort[portNum].invoke(
446 size
447 );
448 }
449
450 void TcpServerComponentBase ::
451 deallocate_out(
452 NATIVE_INT_TYPE portNum,
453 Fw::Buffer& fwBuffer
454 )
455 {
456 FW_ASSERT(
457 portNum < this->getNum_deallocate_OutputPorts(),
458 static_cast<FwAssertArgType>(portNum)
459 );
460 this->m_deallocate_OutputPort[portNum].invoke(
461 fwBuffer
462 );
463 }
464
465 void TcpServerComponentBase ::
466 ready_out(NATIVE_INT_TYPE portNum)
467 {
468 FW_ASSERT(
469 portNum < this->getNum_ready_OutputPorts(),
470 static_cast<FwAssertArgType>(portNum)
471 );
472 this->m_ready_OutputPort[portNum].invoke();
473 }
474
475 void TcpServerComponentBase ::
476 recv_out(
477 NATIVE_INT_TYPE portNum,
478 Fw::Buffer& recvBuffer,
479 const Drv::RecvStatus& recvStatus
480 )
481 {
482 FW_ASSERT(
483 portNum < this->getNum_recv_OutputPorts(),
484 static_cast<FwAssertArgType>(portNum)
485 );
486 this->m_recv_OutputPort[portNum].invoke(
487 recvBuffer,
488 recvStatus
489 );
490 }
491
492 // ----------------------------------------------------------------------
493 // Mutex operations for guarded ports
494 //
495 // You can override these operations to provide more sophisticated
496 // synchronization
497 // ----------------------------------------------------------------------
498
499 void TcpServerComponentBase ::
500 lock()
501 {
502 this->m_guardedPortMutex.lock();
503 }
504
505 void TcpServerComponentBase ::
506 unLock()
507 {
508 this->m_guardedPortMutex.unLock();
509 }
510
511 // ----------------------------------------------------------------------
512 // Calls for messages received on typed input ports
513 // ----------------------------------------------------------------------
514
515 Drv::SendStatus TcpServerComponentBase ::
516 m_p_send_in(
517 Fw::PassiveComponentBase* callComp,
518 NATIVE_INT_TYPE portNum,
519 Fw::Buffer& sendBuffer
520 )
521 {
522 FW_ASSERT(callComp);
523 TcpServerComponentBase* compPtr = static_cast<TcpServerComponentBase*>(callComp);
524 return compPtr->send_handlerBase(
525 portNum,
526 sendBuffer
527 );
528 }
529
530}
#define FW_ASSERT(...)
Definition Assert.hpp:14
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.
void init()
Object initializer.
Definition ObjBase.cpp:27