F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
UdpComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UdpComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for Udp 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 
151  // ----------------------------------------------------------------------
152  // Getters for typed input ports
153  // ----------------------------------------------------------------------
154 
157  {
158  FW_ASSERT(
159  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
160  static_cast<FwAssertArgType>(portNum)
161  );
162 
163  return &this->m_recvReturnIn_InputPort[portNum];
164  }
165 
168  {
169  FW_ASSERT(
170  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
171  static_cast<FwAssertArgType>(portNum)
172  );
173 
174  return &this->m_send_InputPort[portNum];
175  }
176 
177  // ----------------------------------------------------------------------
178  // Connect typed input ports to typed output ports
179  // ----------------------------------------------------------------------
180 
183  FwIndexType portNum,
185  )
186  {
187  FW_ASSERT(
188  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
189  static_cast<FwAssertArgType>(portNum)
190  );
191 
192  this->m_allocate_OutputPort[portNum].addCallPort(port);
193  }
194 
197  FwIndexType portNum,
199  )
200  {
201  FW_ASSERT(
202  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
203  static_cast<FwAssertArgType>(portNum)
204  );
205 
206  this->m_deallocate_OutputPort[portNum].addCallPort(port);
207  }
208 
211  FwIndexType portNum,
213  )
214  {
215  FW_ASSERT(
216  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
217  static_cast<FwAssertArgType>(portNum)
218  );
219 
220  this->m_ready_OutputPort[portNum].addCallPort(port);
221  }
222 
225  FwIndexType portNum,
227  )
228  {
229  FW_ASSERT(
230  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
231  static_cast<FwAssertArgType>(portNum)
232  );
233 
234  this->m_recv_OutputPort[portNum].addCallPort(port);
235  }
236 
237 #if FW_PORT_SERIALIZATION
238 
239  // ----------------------------------------------------------------------
240  // Connect serial input ports to typed output ports
241  // ----------------------------------------------------------------------
242 
245  FwIndexType portNum,
246  Fw::InputSerializePort* port
247  )
248  {
249  FW_ASSERT(
250  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
251  static_cast<FwAssertArgType>(portNum)
252  );
253 
254  this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
255  }
256 
259  FwIndexType portNum,
260  Fw::InputSerializePort* port
261  )
262  {
263  FW_ASSERT(
264  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
265  static_cast<FwAssertArgType>(portNum)
266  );
267 
268  this->m_ready_OutputPort[portNum].registerSerialPort(port);
269  }
270 
273  FwIndexType portNum,
274  Fw::InputSerializePort* port
275  )
276  {
277  FW_ASSERT(
278  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
279  static_cast<FwAssertArgType>(portNum)
280  );
281 
282  this->m_recv_OutputPort[portNum].registerSerialPort(port);
283  }
284 
285 #endif
286 
287  // ----------------------------------------------------------------------
288  // Component construction and destruction
289  // ----------------------------------------------------------------------
290 
292  UdpComponentBase(const char* compName) :
293  Fw::PassiveComponentBase(compName)
294  {
295 
296  }
297 
300  {
301 
302  }
303 
304  // ----------------------------------------------------------------------
305  // Connection status queries for typed output ports
306  // ----------------------------------------------------------------------
307 
310  {
311  FW_ASSERT(
312  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
313  static_cast<FwAssertArgType>(portNum)
314  );
315 
316  return this->m_allocate_OutputPort[portNum].isConnected();
317  }
318 
321  {
322  FW_ASSERT(
323  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
324  static_cast<FwAssertArgType>(portNum)
325  );
326 
327  return this->m_deallocate_OutputPort[portNum].isConnected();
328  }
329 
332  {
333  FW_ASSERT(
334  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
335  static_cast<FwAssertArgType>(portNum)
336  );
337 
338  return this->m_ready_OutputPort[portNum].isConnected();
339  }
340 
343  {
344  FW_ASSERT(
345  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
346  static_cast<FwAssertArgType>(portNum)
347  );
348 
349  return this->m_recv_OutputPort[portNum].isConnected();
350  }
351 
352  // ----------------------------------------------------------------------
353  // Port handler base-class functions for typed input ports
354  //
355  // Call these functions directly to bypass the corresponding ports
356  // ----------------------------------------------------------------------
357 
360  FwIndexType portNum,
361  Fw::Buffer& fwBuffer
362  )
363  {
364  // Make sure port number is valid
365  FW_ASSERT(
366  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
367  static_cast<FwAssertArgType>(portNum)
368  );
369 
370  // Lock guard mutex before calling
371  this->lock();
372 
373  // Call handler function
374  this->recvReturnIn_handler(
375  portNum,
376  fwBuffer
377  );
378 
379  // Unlock guard mutex
380  this->unLock();
381  }
382 
385  FwIndexType portNum,
386  Fw::Buffer& sendBuffer
387  )
388  {
389  // Make sure port number is valid
390  FW_ASSERT(
391  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
392  static_cast<FwAssertArgType>(portNum)
393  );
394 
395  Drv::ByteStreamStatus retVal;
396 
397  // Lock guard mutex before calling
398  this->lock();
399 
400  // Call handler function
401  retVal = this->send_handler(
402  portNum,
403  sendBuffer
404  );
405 
406  // Unlock guard mutex
407  this->unLock();
408 
409  return retVal;
410  }
411 
412  // ----------------------------------------------------------------------
413  // Invocation functions for typed output ports
414  // ----------------------------------------------------------------------
415 
418  FwIndexType portNum,
419  FwSizeType size
420  )
421  {
422  FW_ASSERT(
423  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
424  static_cast<FwAssertArgType>(portNum)
425  );
426 
427  FW_ASSERT(
428  this->m_allocate_OutputPort[portNum].isConnected(),
429  static_cast<FwAssertArgType>(portNum)
430  );
431  return this->m_allocate_OutputPort[portNum].invoke(
432  size
433  );
434  }
435 
438  FwIndexType portNum,
439  Fw::Buffer& fwBuffer
440  )
441  {
442  FW_ASSERT(
443  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
444  static_cast<FwAssertArgType>(portNum)
445  );
446 
447  FW_ASSERT(
448  this->m_deallocate_OutputPort[portNum].isConnected(),
449  static_cast<FwAssertArgType>(portNum)
450  );
451  this->m_deallocate_OutputPort[portNum].invoke(
452  fwBuffer
453  );
454  }
455 
458  {
459  FW_ASSERT(
460  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
461  static_cast<FwAssertArgType>(portNum)
462  );
463 
464  FW_ASSERT(
465  this->m_ready_OutputPort[portNum].isConnected(),
466  static_cast<FwAssertArgType>(portNum)
467  );
468  this->m_ready_OutputPort[portNum].invoke();
469  }
470 
473  FwIndexType portNum,
474  Fw::Buffer& buffer,
475  const Drv::ByteStreamStatus& status
476  )
477  {
478  FW_ASSERT(
479  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
480  static_cast<FwAssertArgType>(portNum)
481  );
482 
483  FW_ASSERT(
484  this->m_recv_OutputPort[portNum].isConnected(),
485  static_cast<FwAssertArgType>(portNum)
486  );
487  this->m_recv_OutputPort[portNum].invoke(
488  buffer,
489  status
490  );
491  }
492 
493  // ----------------------------------------------------------------------
494  // Mutex operations for guarded ports
495  //
496  // You can override these operations to provide more sophisticated
497  // synchronization
498  // ----------------------------------------------------------------------
499 
502  {
503  this->m_guardedPortMutex.lock();
504  }
505 
508  {
509  this->m_guardedPortMutex.unLock();
510  }
511 
512  // ----------------------------------------------------------------------
513  // Calls for messages received on typed input ports
514  // ----------------------------------------------------------------------
515 
516  void UdpComponentBase ::
517  m_p_recvReturnIn_in(
518  Fw::PassiveComponentBase* callComp,
519  FwIndexType portNum,
520  Fw::Buffer& fwBuffer
521  )
522  {
523  FW_ASSERT(callComp);
524  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
525  compPtr->recvReturnIn_handlerBase(
526  portNum,
527  fwBuffer
528  );
529  }
530 
531  Drv::ByteStreamStatus UdpComponentBase ::
532  m_p_send_in(
533  Fw::PassiveComponentBase* callComp,
534  FwIndexType portNum,
535  Fw::Buffer& sendBuffer
536  )
537  {
538  FW_ASSERT(callComp);
539  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
540  return compPtr->send_handlerBase(
541  portNum,
542  sendBuffer
543  );
544  }
545 
546 }
virtual ~UdpComponentBase()
Destroy UdpComponentBase object.
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port recv.
void addCallPort(InputByteStreamReadyPort *callPort)
Register an input port.
static constexpr FwIndexType getNum_ready_OutputPorts()
PlatformSizeType FwSizeType
I32 FwEnumStoreType
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
bool isConnected_recv_OutputPort(FwIndexType portNum)
virtual Drv::ByteStreamStatus send_handler(FwIndexType portNum, Fw::Buffer &sendBuffer)=0
Handler for input port send.
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:41
void set_recv_OutputPort(FwIndexType portNum, Drv::InputByteStreamDataPort *port)
Connect port to recv[portNum].
virtual void unLock()
Unlock the guarded mutex.
static constexpr FwIndexType getNum_allocate_OutputPorts()
static constexpr FwIndexType getNum_send_InputPorts()
void init()
Object initializer.
Definition: ObjBase.cpp:24
void addCallPort(InputBufferGetPort *callPort)
Register an input port.
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size)
Invoke output port allocate.
void addCallPort(InputByteStreamDataPort *callPort)
Register an input port.
bool isConnected_deallocate_OutputPort(FwIndexType portNum)
Status returned by the send call.
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 deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
void init()
Initialization function.
void addCallPort(InputBufferSendPort *callPort)
Register an input port.
const char * toChar() const
Convert to a C-style char*.
Definition: ObjectName.hpp:50
bool isConnected_ready_OutputPort(FwIndexType portNum)
UdpComponentBase(const char *compName="")
Construct UdpComponentBase object.
void set_deallocate_OutputPort(FwIndexType portNum, Fw::InputBufferSendPort *port)
Connect port to deallocate[portNum].
static constexpr FwIndexType getNum_recv_OutputPorts()
bool isConnected() const
Definition: PortBase.cpp:38
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:39
void setPortNum(FwIndexType portNum)
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Fw::Buffer invoke(FwSizeType size) const
Invoke a port interface.
Drv::ByteStreamStatus send_handlerBase(FwIndexType portNum, Fw::Buffer &sendBuffer)
Handler base-class function for input port send.
void init()
Initialization function.
static constexpr FwIndexType getNum_recvReturnIn_InputPorts()
virtual void recvReturnIn_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port recvReturnIn.
void set_allocate_OutputPort(FwIndexType portNum, Fw::InputBufferGetPort *port)
Connect port to allocate[portNum].
bool isConnected_allocate_OutputPort(FwIndexType portNum)
void init()
Initialization function.
Drv::InputByteStreamSendPort * get_send_InputPort(FwIndexType portNum)
PlatformIndexType FwIndexType
void set_ready_OutputPort(FwIndexType portNum, Drv::InputByteStreamReadyPort *port)
Connect port to ready[portNum].
void invoke() const
Invoke a port interface.
Auto-generated base for Udp component.
Fw::InputBufferSendPort * get_recvReturnIn_InputPort(FwIndexType portNum)
void recvReturnIn_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port recvReturnIn.
static constexpr FwIndexType getNum_deallocate_OutputPorts()
void init()
Initialization function.
void init()
Initialization function.
void ready_out(FwIndexType portNum)
Invoke output port ready.
virtual void lock()
Lock the guarded mutex.
Implementation of malloc based allocator.
void init()
Initialization function.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34