F´ Flight Software - C/C++ Documentation  devel
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 
21  init(FwEnumStoreType instance)
22  {
23  // Initialize base class
25 
26  // Connect input port send
27  for (
28  FwIndexType port = 0;
29  port < static_cast<FwIndexType>(this->getNum_send_InputPorts());
30  port++
31  ) {
32  this->m_send_InputPort[port].init();
33  this->m_send_InputPort[port].addCallComp(
34  this,
35  m_p_send_in
36  );
37  this->m_send_InputPort[port].setPortNum(port);
38 
39 #if FW_OBJECT_NAMES == 1
40  Fw::ObjectName portName;
41  portName.format(
42  "%s_send_InputPort[%" PRI_PlatformIntType "]",
43  this->m_objName.toChar(),
44  port
45  );
46  this->m_send_InputPort[port].setObjName(portName.toChar());
47 #endif
48  }
49 
50  // Connect output port allocate
51  for (
52  FwIndexType port = 0;
53  port < static_cast<FwIndexType>(this->getNum_allocate_OutputPorts());
54  port++
55  ) {
56  this->m_allocate_OutputPort[port].init();
57 
58 #if FW_OBJECT_NAMES == 1
59  Fw::ObjectName portName;
60  portName.format(
61  "%s_allocate_OutputPort[%" PRI_PlatformIntType "]",
62  this->m_objName.toChar(),
63  port
64  );
65  this->m_allocate_OutputPort[port].setObjName(portName.toChar());
66 #endif
67  }
68 
69  // Connect output port deallocate
70  for (
71  FwIndexType port = 0;
72  port < static_cast<FwIndexType>(this->getNum_deallocate_OutputPorts());
73  port++
74  ) {
75  this->m_deallocate_OutputPort[port].init();
76 
77 #if FW_OBJECT_NAMES == 1
78  Fw::ObjectName portName;
79  portName.format(
80  "%s_deallocate_OutputPort[%" PRI_PlatformIntType "]",
81  this->m_objName.toChar(),
82  port
83  );
84  this->m_deallocate_OutputPort[port].setObjName(portName.toChar());
85 #endif
86  }
87 
88  // Connect output port ready
89  for (
90  FwIndexType port = 0;
91  port < static_cast<FwIndexType>(this->getNum_ready_OutputPorts());
92  port++
93  ) {
94  this->m_ready_OutputPort[port].init();
95 
96 #if FW_OBJECT_NAMES == 1
97  Fw::ObjectName portName;
98  portName.format(
99  "%s_ready_OutputPort[%" PRI_PlatformIntType "]",
100  this->m_objName.toChar(),
101  port
102  );
103  this->m_ready_OutputPort[port].setObjName(portName.toChar());
104 #endif
105  }
106 
107  // Connect output port recv
108  for (
109  FwIndexType port = 0;
110  port < static_cast<FwIndexType>(this->getNum_recv_OutputPorts());
111  port++
112  ) {
113  this->m_recv_OutputPort[port].init();
114 
115 #if FW_OBJECT_NAMES == 1
116  Fw::ObjectName portName;
117  portName.format(
118  "%s_recv_OutputPort[%" PRI_PlatformIntType "]",
119  this->m_objName.toChar(),
120  port
121  );
122  this->m_recv_OutputPort[port].setObjName(portName.toChar());
123 #endif
124  }
125  }
126 
127  // ----------------------------------------------------------------------
128  // Getters for typed input ports
129  // ----------------------------------------------------------------------
130 
133  {
134  FW_ASSERT(
135  portNum < this->getNum_send_InputPorts(),
136  static_cast<FwAssertArgType>(portNum)
137  );
138 
139  return &this->m_send_InputPort[portNum];
140  }
141 
142  // ----------------------------------------------------------------------
143  // Connect typed input ports to typed output ports
144  // ----------------------------------------------------------------------
145 
148  FwIndexType portNum,
150  )
151  {
152  FW_ASSERT(
153  portNum < this->getNum_allocate_OutputPorts(),
154  static_cast<FwAssertArgType>(portNum)
155  );
156 
157  this->m_allocate_OutputPort[portNum].addCallPort(port);
158  }
159 
162  FwIndexType portNum,
164  )
165  {
166  FW_ASSERT(
167  portNum < this->getNum_deallocate_OutputPorts(),
168  static_cast<FwAssertArgType>(portNum)
169  );
170 
171  this->m_deallocate_OutputPort[portNum].addCallPort(port);
172  }
173 
176  FwIndexType portNum,
178  )
179  {
180  FW_ASSERT(
181  portNum < this->getNum_ready_OutputPorts(),
182  static_cast<FwAssertArgType>(portNum)
183  );
184 
185  this->m_ready_OutputPort[portNum].addCallPort(port);
186  }
187 
190  FwIndexType portNum,
192  )
193  {
194  FW_ASSERT(
195  portNum < this->getNum_recv_OutputPorts(),
196  static_cast<FwAssertArgType>(portNum)
197  );
198 
199  this->m_recv_OutputPort[portNum].addCallPort(port);
200  }
201 
202 #if FW_PORT_SERIALIZATION
203 
204  // ----------------------------------------------------------------------
205  // Connect serial input ports to typed output ports
206  // ----------------------------------------------------------------------
207 
210  FwIndexType portNum,
211  Fw::InputSerializePort* port
212  )
213  {
214  FW_ASSERT(
215  portNum < this->getNum_deallocate_OutputPorts(),
216  static_cast<FwAssertArgType>(portNum)
217  );
218 
219  this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
220  }
221 
224  FwIndexType portNum,
225  Fw::InputSerializePort* port
226  )
227  {
228  FW_ASSERT(
229  portNum < this->getNum_ready_OutputPorts(),
230  static_cast<FwAssertArgType>(portNum)
231  );
232 
233  this->m_ready_OutputPort[portNum].registerSerialPort(port);
234  }
235 
238  FwIndexType portNum,
239  Fw::InputSerializePort* port
240  )
241  {
242  FW_ASSERT(
243  portNum < this->getNum_recv_OutputPorts(),
244  static_cast<FwAssertArgType>(portNum)
245  );
246 
247  this->m_recv_OutputPort[portNum].registerSerialPort(port);
248  }
249 
250 #endif
251 
252  // ----------------------------------------------------------------------
253  // Component construction and destruction
254  // ----------------------------------------------------------------------
255 
257  TcpServerComponentBase(const char* compName) :
258  Fw::PassiveComponentBase(compName)
259  {
260 
261  }
262 
265  {
266 
267  }
268 
269  // ----------------------------------------------------------------------
270  // Getters for numbers of typed input ports
271  // ----------------------------------------------------------------------
272 
275  {
276  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_send_InputPort));
277  }
278 
279  // ----------------------------------------------------------------------
280  // Getters for numbers of typed output ports
281  // ----------------------------------------------------------------------
282 
285  {
286  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
287  }
288 
291  {
292  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
293  }
294 
297  {
298  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
299  }
300 
303  {
304  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_recv_OutputPort));
305  }
306 
307  // ----------------------------------------------------------------------
308  // Connection status queries for typed output ports
309  // ----------------------------------------------------------------------
310 
313  {
314  FW_ASSERT(
315  portNum < this->getNum_allocate_OutputPorts(),
316  static_cast<FwAssertArgType>(portNum)
317  );
318 
319  return this->m_allocate_OutputPort[portNum].isConnected();
320  }
321 
324  {
325  FW_ASSERT(
326  portNum < this->getNum_deallocate_OutputPorts(),
327  static_cast<FwAssertArgType>(portNum)
328  );
329 
330  return this->m_deallocate_OutputPort[portNum].isConnected();
331  }
332 
335  {
336  FW_ASSERT(
337  portNum < this->getNum_ready_OutputPorts(),
338  static_cast<FwAssertArgType>(portNum)
339  );
340 
341  return this->m_ready_OutputPort[portNum].isConnected();
342  }
343 
346  {
347  FW_ASSERT(
348  portNum < this->getNum_recv_OutputPorts(),
349  static_cast<FwAssertArgType>(portNum)
350  );
351 
352  return this->m_recv_OutputPort[portNum].isConnected();
353  }
354 
355  // ----------------------------------------------------------------------
356  // Port handler base-class functions for typed input ports
357  //
358  // Call these functions directly to bypass the corresponding ports
359  // ----------------------------------------------------------------------
360 
363  FwIndexType portNum,
364  Fw::Buffer& sendBuffer
365  )
366  {
367  // Make sure port number is valid
368  FW_ASSERT(
369  portNum < this->getNum_send_InputPorts(),
370  static_cast<FwAssertArgType>(portNum)
371  );
372 
373  Drv::SendStatus retVal;
374 
375  // Lock guard mutex before calling
376  this->lock();
377 
378  // Call handler function
379  retVal = this->send_handler(
380  portNum,
381  sendBuffer
382  );
383 
384  // Unlock guard mutex
385  this->unLock();
386 
387  return retVal;
388  }
389 
390  // ----------------------------------------------------------------------
391  // Invocation functions for typed output ports
392  // ----------------------------------------------------------------------
393 
396  FwIndexType portNum,
397  U32 size
398  )
399  {
400  FW_ASSERT(
401  portNum < this->getNum_allocate_OutputPorts(),
402  static_cast<FwAssertArgType>(portNum)
403  );
404  return this->m_allocate_OutputPort[portNum].invoke(
405  size
406  );
407  }
408 
411  FwIndexType portNum,
412  Fw::Buffer& fwBuffer
413  )
414  {
415  FW_ASSERT(
416  portNum < this->getNum_deallocate_OutputPorts(),
417  static_cast<FwAssertArgType>(portNum)
418  );
419  this->m_deallocate_OutputPort[portNum].invoke(
420  fwBuffer
421  );
422  }
423 
425  ready_out(FwIndexType portNum)
426  {
427  FW_ASSERT(
428  portNum < this->getNum_ready_OutputPorts(),
429  static_cast<FwAssertArgType>(portNum)
430  );
431  this->m_ready_OutputPort[portNum].invoke();
432  }
433 
435  recv_out(
436  FwIndexType portNum,
437  Fw::Buffer& recvBuffer,
438  const Drv::RecvStatus& recvStatus
439  )
440  {
441  FW_ASSERT(
442  portNum < this->getNum_recv_OutputPorts(),
443  static_cast<FwAssertArgType>(portNum)
444  );
445  this->m_recv_OutputPort[portNum].invoke(
446  recvBuffer,
447  recvStatus
448  );
449  }
450 
451  // ----------------------------------------------------------------------
452  // Mutex operations for guarded ports
453  //
454  // You can override these operations to provide more sophisticated
455  // synchronization
456  // ----------------------------------------------------------------------
457 
459  lock()
460  {
461  this->m_guardedPortMutex.lock();
462  }
463 
465  unLock()
466  {
467  this->m_guardedPortMutex.unLock();
468  }
469 
470  // ----------------------------------------------------------------------
471  // Calls for messages received on typed input ports
472  // ----------------------------------------------------------------------
473 
474  Drv::SendStatus TcpServerComponentBase ::
475  m_p_send_in(
476  Fw::PassiveComponentBase* callComp,
477  FwIndexType portNum,
478  Fw::Buffer& sendBuffer
479  )
480  {
481  FW_ASSERT(callComp);
482  TcpServerComponentBase* compPtr = static_cast<TcpServerComponentBase*>(callComp);
483  return compPtr->send_handlerBase(
484  portNum,
485  sendBuffer
486  );
487  }
488 
489 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:70
#define PRI_PlatformIntType
I32 FwEnumStoreType
Definition: FpConfig.h:64
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:39
PlatformIndexType FwIndexType
Definition: FpConfig.h:25
void init()
Initialization function.
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
void invoke()
Invoke a port interface.
void addCallPort(InputByteStreamReadyPort *callPort)
Register an input port.
void init()
Initialization function.
void init()
Initialization function.
void addCallPort(InputByteStreamRecvPort *callPort)
Register an input port.
void invoke(Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Invoke a port interface.
Status associated with the received data.
Status returned by the send call.
Auto-generated base for TcpServer component.
bool isConnected_allocate_OutputPort(FwIndexType portNum)
void set_deallocate_OutputPort(FwIndexType portNum, Fw::InputBufferSendPort *port)
Connect port to deallocate[portNum].
FwIndexType getNum_send_InputPorts() const
virtual void unLock()
Unlock the guarded mutex.
void ready_out(FwIndexType portNum)
Invoke output port ready.
bool isConnected_deallocate_OutputPort(FwIndexType portNum)
Drv::SendStatus send_handlerBase(FwIndexType portNum, Fw::Buffer &sendBuffer)
Handler base-class function for input port send.
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
Fw::Buffer allocate_out(FwIndexType portNum, U32 size)
Invoke output port allocate.
FwIndexType getNum_ready_OutputPorts() const
bool isConnected_recv_OutputPort(FwIndexType portNum)
virtual void lock()
Lock the guarded mutex.
TcpServerComponentBase(const char *compName="")
Construct TcpServerComponentBase object.
virtual Drv::SendStatus send_handler(FwIndexType portNum, Fw::Buffer &sendBuffer)=0
Handler for input port send.
void recv_out(FwIndexType portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Invoke output port recv.
void set_ready_OutputPort(FwIndexType portNum, Drv::InputByteStreamReadyPort *port)
Connect port to ready[portNum].
FwIndexType getNum_recv_OutputPorts() const
virtual ~TcpServerComponentBase()
Destroy TcpServerComponentBase object.
bool isConnected_ready_OutputPort(FwIndexType portNum)
FwIndexType getNum_deallocate_OutputPorts() const
FwIndexType getNum_allocate_OutputPorts() const
void set_recv_OutputPort(FwIndexType portNum, Drv::InputByteStreamRecvPort *port)
Connect port to recv[portNum].
void set_allocate_OutputPort(FwIndexType portNum, Fw::InputBufferGetPort *port)
Connect port to allocate[portNum].
Drv::InputByteStreamSendPort * get_send_InputPort(FwIndexType portNum)
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
const char * toChar() const
Definition: ObjectName.hpp:50
void init()
Initialization function.
void addCallPort(InputBufferGetPort *callPort)
Register an input port.
Fw::Buffer invoke(U32 size)
Invoke a port interface.
void addCallPort(InputBufferSendPort *callPort)
Register an input port.
void invoke(Fw::Buffer &fwBuffer)
Invoke a port interface.
void init()
Initialization function.
bool isConnected()
Definition: PortBase.cpp:41
void format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:56
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:40
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34