F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
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 
8 #include "Fw/Types/Assert.hpp"
10 #if FW_ENABLE_TEXT_LOGGING
11 #include "Fw/Types/String.hpp"
12 #endif
13 
14 namespace Drv {
15 
16  // ----------------------------------------------------------------------
17  // Component initialization
18  // ----------------------------------------------------------------------
19 
22  {
23  // Initialize base class
25 
26  // Connect input port recvReturnIn
27  for (
28  FwIndexType port = 0;
29  port < static_cast<FwIndexType>(this->getNum_recvReturnIn_InputPorts());
30  port++
31  ) {
32  this->m_recvReturnIn_InputPort[port].init();
33  this->m_recvReturnIn_InputPort[port].addCallComp(
34  this,
35  m_p_recvReturnIn_in
36  );
37  this->m_recvReturnIn_InputPort[port].setPortNum(port);
38 
39 #if FW_OBJECT_NAMES == 1
40  Fw::ObjectName portName;
41  portName.format(
42  "%s_recvReturnIn_InputPort[%" PRI_FwIndexType "]",
43  this->m_objName.toChar(),
44  port
45  );
46  this->m_recvReturnIn_InputPort[port].setObjName(portName.toChar());
47 #endif
48  }
49 
50  // Connect input port send
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_send_InputPorts());
54  port++
55  ) {
56  this->m_send_InputPort[port].init();
57  this->m_send_InputPort[port].addCallComp(
58  this,
59  m_p_send_in
60  );
61  this->m_send_InputPort[port].setPortNum(port);
62 
63 #if FW_OBJECT_NAMES == 1
64  Fw::ObjectName portName;
65  portName.format(
66  "%s_send_InputPort[%" PRI_FwIndexType "]",
67  this->m_objName.toChar(),
68  port
69  );
70  this->m_send_InputPort[port].setObjName(portName.toChar());
71 #endif
72  }
73 
74  // Connect output port allocate
75  for (
76  FwIndexType port = 0;
77  port < static_cast<FwIndexType>(this->getNum_allocate_OutputPorts());
78  port++
79  ) {
80  this->m_allocate_OutputPort[port].init();
81 
82 #if FW_OBJECT_NAMES == 1
83  Fw::ObjectName portName;
84  portName.format(
85  "%s_allocate_OutputPort[%" PRI_FwIndexType "]",
86  this->m_objName.toChar(),
87  port
88  );
89  this->m_allocate_OutputPort[port].setObjName(portName.toChar());
90 #endif
91  }
92 
93  // Connect output port deallocate
94  for (
95  FwIndexType port = 0;
96  port < static_cast<FwIndexType>(this->getNum_deallocate_OutputPorts());
97  port++
98  ) {
99  this->m_deallocate_OutputPort[port].init();
100 
101 #if FW_OBJECT_NAMES == 1
102  Fw::ObjectName portName;
103  portName.format(
104  "%s_deallocate_OutputPort[%" PRI_FwIndexType "]",
105  this->m_objName.toChar(),
106  port
107  );
108  this->m_deallocate_OutputPort[port].setObjName(portName.toChar());
109 #endif
110  }
111 
112  // Connect output port ready
113  for (
114  FwIndexType port = 0;
115  port < static_cast<FwIndexType>(this->getNum_ready_OutputPorts());
116  port++
117  ) {
118  this->m_ready_OutputPort[port].init();
119 
120 #if FW_OBJECT_NAMES == 1
121  Fw::ObjectName portName;
122  portName.format(
123  "%s_ready_OutputPort[%" PRI_FwIndexType "]",
124  this->m_objName.toChar(),
125  port
126  );
127  this->m_ready_OutputPort[port].setObjName(portName.toChar());
128 #endif
129  }
130 
131  // Connect output port recv
132  for (
133  FwIndexType port = 0;
134  port < static_cast<FwIndexType>(this->getNum_recv_OutputPorts());
135  port++
136  ) {
137  this->m_recv_OutputPort[port].init();
138 
139 #if FW_OBJECT_NAMES == 1
140  Fw::ObjectName portName;
141  portName.format(
142  "%s_recv_OutputPort[%" PRI_FwIndexType "]",
143  this->m_objName.toChar(),
144  port
145  );
146  this->m_recv_OutputPort[port].setObjName(portName.toChar());
147 #endif
148  }
149 
150  // Connect output port sendReturnOut
151  for (
152  FwIndexType port = 0;
153  port < static_cast<FwIndexType>(this->getNum_sendReturnOut_OutputPorts());
154  port++
155  ) {
156  this->m_sendReturnOut_OutputPort[port].init();
157 
158 #if FW_OBJECT_NAMES == 1
159  Fw::ObjectName portName;
160  portName.format(
161  "%s_sendReturnOut_OutputPort[%" PRI_FwIndexType "]",
162  this->m_objName.toChar(),
163  port
164  );
165  this->m_sendReturnOut_OutputPort[port].setObjName(portName.toChar());
166 #endif
167  }
168  }
169 
170  // ----------------------------------------------------------------------
171  // Getters for typed input ports
172  // ----------------------------------------------------------------------
173 
176  {
177  FW_ASSERT(
178  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
179  static_cast<FwAssertArgType>(portNum)
180  );
181 
182  return &this->m_recvReturnIn_InputPort[portNum];
183  }
184 
187  {
188  FW_ASSERT(
189  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
190  static_cast<FwAssertArgType>(portNum)
191  );
192 
193  return &this->m_send_InputPort[portNum];
194  }
195 
196  // ----------------------------------------------------------------------
197  // Connect typed input ports to typed output ports
198  // ----------------------------------------------------------------------
199 
202  FwIndexType portNum,
204  )
205  {
206  FW_ASSERT(
207  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
208  static_cast<FwAssertArgType>(portNum)
209  );
210 
211  this->m_allocate_OutputPort[portNum].addCallPort(port);
212  }
213 
216  FwIndexType portNum,
218  )
219  {
220  FW_ASSERT(
221  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
222  static_cast<FwAssertArgType>(portNum)
223  );
224 
225  this->m_deallocate_OutputPort[portNum].addCallPort(port);
226  }
227 
230  FwIndexType portNum,
232  )
233  {
234  FW_ASSERT(
235  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
236  static_cast<FwAssertArgType>(portNum)
237  );
238 
239  this->m_ready_OutputPort[portNum].addCallPort(port);
240  }
241 
244  FwIndexType portNum,
246  )
247  {
248  FW_ASSERT(
249  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
250  static_cast<FwAssertArgType>(portNum)
251  );
252 
253  this->m_recv_OutputPort[portNum].addCallPort(port);
254  }
255 
258  FwIndexType portNum,
260  )
261  {
262  FW_ASSERT(
263  (0 <= portNum) && (portNum < this->getNum_sendReturnOut_OutputPorts()),
264  static_cast<FwAssertArgType>(portNum)
265  );
266 
267  this->m_sendReturnOut_OutputPort[portNum].addCallPort(port);
268  }
269 
270 #if FW_PORT_SERIALIZATION
271 
272  // ----------------------------------------------------------------------
273  // Connect serial input ports to typed output ports
274  // ----------------------------------------------------------------------
275 
278  FwIndexType portNum,
279  Fw::InputSerializePort* port
280  )
281  {
282  FW_ASSERT(
283  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
284  static_cast<FwAssertArgType>(portNum)
285  );
286 
287  this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
288  }
289 
292  FwIndexType portNum,
293  Fw::InputSerializePort* port
294  )
295  {
296  FW_ASSERT(
297  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
298  static_cast<FwAssertArgType>(portNum)
299  );
300 
301  this->m_ready_OutputPort[portNum].registerSerialPort(port);
302  }
303 
306  FwIndexType portNum,
307  Fw::InputSerializePort* port
308  )
309  {
310  FW_ASSERT(
311  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
312  static_cast<FwAssertArgType>(portNum)
313  );
314 
315  this->m_recv_OutputPort[portNum].registerSerialPort(port);
316  }
317 
320  FwIndexType portNum,
321  Fw::InputSerializePort* port
322  )
323  {
324  FW_ASSERT(
325  (0 <= portNum) && (portNum < this->getNum_sendReturnOut_OutputPorts()),
326  static_cast<FwAssertArgType>(portNum)
327  );
328 
329  this->m_sendReturnOut_OutputPort[portNum].registerSerialPort(port);
330  }
331 
332 #endif
333 
334  // ----------------------------------------------------------------------
335  // Component construction and destruction
336  // ----------------------------------------------------------------------
337 
339  TcpServerComponentBase(const char* compName) :
340  Fw::PassiveComponentBase(compName)
341  {
342 
343  }
344 
347  {
348 
349  }
350 
351  // ----------------------------------------------------------------------
352  // Getters for numbers of typed input ports
353  // ----------------------------------------------------------------------
354 
357  {
358  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_recvReturnIn_InputPort));
359  }
360 
363  {
364  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_send_InputPort));
365  }
366 
367  // ----------------------------------------------------------------------
368  // Getters for numbers of typed output ports
369  // ----------------------------------------------------------------------
370 
373  {
374  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
375  }
376 
379  {
380  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
381  }
382 
385  {
386  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
387  }
388 
391  {
392  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_recv_OutputPort));
393  }
394 
397  {
398  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_sendReturnOut_OutputPort));
399  }
400 
401  // ----------------------------------------------------------------------
402  // Connection status queries for typed output ports
403  // ----------------------------------------------------------------------
404 
407  {
408  FW_ASSERT(
409  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
410  static_cast<FwAssertArgType>(portNum)
411  );
412 
413  return this->m_allocate_OutputPort[portNum].isConnected();
414  }
415 
418  {
419  FW_ASSERT(
420  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
421  static_cast<FwAssertArgType>(portNum)
422  );
423 
424  return this->m_deallocate_OutputPort[portNum].isConnected();
425  }
426 
429  {
430  FW_ASSERT(
431  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
432  static_cast<FwAssertArgType>(portNum)
433  );
434 
435  return this->m_ready_OutputPort[portNum].isConnected();
436  }
437 
440  {
441  FW_ASSERT(
442  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
443  static_cast<FwAssertArgType>(portNum)
444  );
445 
446  return this->m_recv_OutputPort[portNum].isConnected();
447  }
448 
451  {
452  FW_ASSERT(
453  (0 <= portNum) && (portNum < this->getNum_sendReturnOut_OutputPorts()),
454  static_cast<FwAssertArgType>(portNum)
455  );
456 
457  return this->m_sendReturnOut_OutputPort[portNum].isConnected();
458  }
459 
460  // ----------------------------------------------------------------------
461  // Port handler base-class functions for typed input ports
462  //
463  // Call these functions directly to bypass the corresponding ports
464  // ----------------------------------------------------------------------
465 
468  FwIndexType portNum,
469  Fw::Buffer& fwBuffer
470  )
471  {
472  // Make sure port number is valid
473  FW_ASSERT(
474  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
475  static_cast<FwAssertArgType>(portNum)
476  );
477 
478  // Lock guard mutex before calling
479  this->lock();
480 
481  // Call handler function
482  this->recvReturnIn_handler(
483  portNum,
484  fwBuffer
485  );
486 
487  // Unlock guard mutex
488  this->unLock();
489  }
490 
493  FwIndexType portNum,
494  Fw::Buffer& fwBuffer
495  )
496  {
497  // Make sure port number is valid
498  FW_ASSERT(
499  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
500  static_cast<FwAssertArgType>(portNum)
501  );
502 
503  // Lock guard mutex before calling
504  this->lock();
505 
506  // Call handler function
507  this->send_handler(
508  portNum,
509  fwBuffer
510  );
511 
512  // Unlock guard mutex
513  this->unLock();
514  }
515 
516  // ----------------------------------------------------------------------
517  // Invocation functions for typed output ports
518  // ----------------------------------------------------------------------
519 
522  FwIndexType portNum,
523  U32 size
524  )
525  {
526  FW_ASSERT(
527  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
528  static_cast<FwAssertArgType>(portNum)
529  );
530 
531  FW_ASSERT(
532  this->m_allocate_OutputPort[portNum].isConnected(),
533  static_cast<FwAssertArgType>(portNum)
534  );
535  return this->m_allocate_OutputPort[portNum].invoke(
536  size
537  );
538  }
539 
542  FwIndexType portNum,
543  Fw::Buffer& fwBuffer
544  )
545  {
546  FW_ASSERT(
547  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
548  static_cast<FwAssertArgType>(portNum)
549  );
550 
551  FW_ASSERT(
552  this->m_deallocate_OutputPort[portNum].isConnected(),
553  static_cast<FwAssertArgType>(portNum)
554  );
555  this->m_deallocate_OutputPort[portNum].invoke(
556  fwBuffer
557  );
558  }
559 
562  {
563  FW_ASSERT(
564  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
565  static_cast<FwAssertArgType>(portNum)
566  );
567 
568  FW_ASSERT(
569  this->m_ready_OutputPort[portNum].isConnected(),
570  static_cast<FwAssertArgType>(portNum)
571  );
572  this->m_ready_OutputPort[portNum].invoke();
573  }
574 
577  FwIndexType portNum,
578  Fw::Buffer& buffer,
579  const Drv::ByteStreamStatus& status
580  )
581  {
582  FW_ASSERT(
583  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
584  static_cast<FwAssertArgType>(portNum)
585  );
586 
587  FW_ASSERT(
588  this->m_recv_OutputPort[portNum].isConnected(),
589  static_cast<FwAssertArgType>(portNum)
590  );
591  this->m_recv_OutputPort[portNum].invoke(
592  buffer,
593  status
594  );
595  }
596 
599  FwIndexType portNum,
600  Fw::Buffer& buffer,
601  const Drv::ByteStreamStatus& status
602  )
603  {
604  FW_ASSERT(
605  (0 <= portNum) && (portNum < this->getNum_sendReturnOut_OutputPorts()),
606  static_cast<FwAssertArgType>(portNum)
607  );
608 
609  FW_ASSERT(
610  this->m_sendReturnOut_OutputPort[portNum].isConnected(),
611  static_cast<FwAssertArgType>(portNum)
612  );
613  this->m_sendReturnOut_OutputPort[portNum].invoke(
614  buffer,
615  status
616  );
617  }
618 
619  // ----------------------------------------------------------------------
620  // Mutex operations for guarded ports
621  //
622  // You can override these operations to provide more sophisticated
623  // synchronization
624  // ----------------------------------------------------------------------
625 
628  {
629  this->m_guardedPortMutex.lock();
630  }
631 
634  {
635  this->m_guardedPortMutex.unLock();
636  }
637 
638  // ----------------------------------------------------------------------
639  // Calls for messages received on typed input ports
640  // ----------------------------------------------------------------------
641 
642  void TcpServerComponentBase ::
643  m_p_recvReturnIn_in(
644  Fw::PassiveComponentBase* callComp,
645  FwIndexType portNum,
646  Fw::Buffer& fwBuffer
647  )
648  {
649  FW_ASSERT(callComp);
650  TcpServerComponentBase* compPtr = static_cast<TcpServerComponentBase*>(callComp);
651  compPtr->recvReturnIn_handlerBase(
652  portNum,
653  fwBuffer
654  );
655  }
656 
657  void TcpServerComponentBase ::
658  m_p_send_in(
659  Fw::PassiveComponentBase* callComp,
660  FwIndexType portNum,
661  Fw::Buffer& fwBuffer
662  )
663  {
664  FW_ASSERT(callComp);
665  TcpServerComponentBase* compPtr = static_cast<TcpServerComponentBase*>(callComp);
666  compPtr->send_handlerBase(
667  portNum,
668  fwBuffer
669  );
670  }
671 
672 }
FwIndexType getNum_deallocate_OutputPorts() const
void addCallPort(InputByteStreamReadyPort *callPort)
Register an input port.
void set_sendReturnOut_OutputPort(FwIndexType portNum, Drv::InputByteStreamDataPort *port)
Connect port to sendReturnOut[portNum].
bool isConnected_sendReturnOut_OutputPort(FwIndexType portNum)
Auto-generated base for TcpServer component.
Fw::InputBufferSendPort * get_recvReturnIn_InputPort(FwIndexType portNum)
void set_deallocate_OutputPort(FwIndexType portNum, Fw::InputBufferSendPort *port)
Connect port to deallocate[portNum].
virtual ~TcpServerComponentBase()
Destroy TcpServerComponentBase object.
I32 FwEnumStoreType
FwIndexType getNum_sendReturnOut_OutputPorts() const
bool isConnected_ready_OutputPort(FwIndexType portNum)
void recvReturnIn_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port recvReturnIn.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Fw::Buffer invoke(U32 size) const
Invoke a port interface.
Fw::InputBufferSendPort * get_send_InputPort(FwIndexType portNum)
void set_ready_OutputPort(FwIndexType portNum, Drv::InputByteStreamReadyPort *port)
Connect port to ready[portNum].
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:40
FwIndexType getNum_allocate_OutputPorts() const
void set_allocate_OutputPort(FwIndexType portNum, Fw::InputBufferGetPort *port)
Connect port to allocate[portNum].
void init()
Object initializer.
Definition: ObjBase.cpp:26
void addCallPort(InputBufferGetPort *callPort)
Register an input port.
virtual void unLock()
Unlock the guarded mutex.
void addCallPort(InputByteStreamDataPort *callPort)
Register an input port.
FwIndexType getNum_ready_OutputPorts() const
Status returned by the send call.
virtual void recvReturnIn_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port recvReturnIn.
void invoke(Fw::Buffer &buffer, const Drv::ByteStreamStatus &status) const
Invoke a port interface.
void invoke(Fw::Buffer &fwBuffer) const
Invoke a port interface.
void init()
Initialization function.
void addCallPort(InputBufferSendPort *callPort)
Register an input port.
const char * toChar() const
Definition: ObjectName.hpp:50
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port recv.
void send_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port send.
void sendReturnOut_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port sendReturnOut.
bool isConnected() const
Definition: PortBase.cpp:42
Fw::Buffer allocate_out(FwIndexType portNum, U32 size)
Invoke output port allocate.
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
void setPortNum(FwIndexType portNum)
bool isConnected_deallocate_OutputPort(FwIndexType portNum)
void init()
Initialization function.
void set_recv_OutputPort(FwIndexType portNum, Drv::InputByteStreamDataPort *port)
Connect port to recv[portNum].
virtual void lock()
Lock the guarded mutex.
void init()
Initialization function.
PlatformIndexType FwIndexType
void invoke() const
Invoke a port interface.
bool isConnected_recv_OutputPort(FwIndexType portNum)
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:93
bool isConnected_allocate_OutputPort(FwIndexType portNum)
void init()
Initialization function.
FwIndexType getNum_recv_OutputPorts() const
virtual void send_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port send.
FwIndexType getNum_send_InputPorts() const
void init()
Initialization function.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
FwIndexType getNum_recvReturnIn_InputPorts() const
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
void ready_out(FwIndexType portNum)
Invoke output port ready.
TcpServerComponentBase(const char *compName="")
Construct TcpServerComponentBase object.