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  // Getters for numbers of typed input ports
306  // ----------------------------------------------------------------------
307 
310  {
311  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_recvReturnIn_InputPort));
312  }
313 
316  {
317  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_send_InputPort));
318  }
319 
320  // ----------------------------------------------------------------------
321  // Getters for numbers of typed output ports
322  // ----------------------------------------------------------------------
323 
326  {
327  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
328  }
329 
332  {
333  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
334  }
335 
338  {
339  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
340  }
341 
344  {
345  return static_cast<FwIndexType>(FW_NUM_ARRAY_ELEMENTS(this->m_recv_OutputPort));
346  }
347 
348  // ----------------------------------------------------------------------
349  // Connection status queries for typed output ports
350  // ----------------------------------------------------------------------
351 
354  {
355  FW_ASSERT(
356  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
357  static_cast<FwAssertArgType>(portNum)
358  );
359 
360  return this->m_allocate_OutputPort[portNum].isConnected();
361  }
362 
365  {
366  FW_ASSERT(
367  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
368  static_cast<FwAssertArgType>(portNum)
369  );
370 
371  return this->m_deallocate_OutputPort[portNum].isConnected();
372  }
373 
376  {
377  FW_ASSERT(
378  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
379  static_cast<FwAssertArgType>(portNum)
380  );
381 
382  return this->m_ready_OutputPort[portNum].isConnected();
383  }
384 
387  {
388  FW_ASSERT(
389  (0 <= portNum) && (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 
404  FwIndexType portNum,
405  Fw::Buffer& fwBuffer
406  )
407  {
408  // Make sure port number is valid
409  FW_ASSERT(
410  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
411  static_cast<FwAssertArgType>(portNum)
412  );
413 
414  // Lock guard mutex before calling
415  this->lock();
416 
417  // Call handler function
418  this->recvReturnIn_handler(
419  portNum,
420  fwBuffer
421  );
422 
423  // Unlock guard mutex
424  this->unLock();
425  }
426 
429  FwIndexType portNum,
430  Fw::Buffer& sendBuffer
431  )
432  {
433  // Make sure port number is valid
434  FW_ASSERT(
435  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
436  static_cast<FwAssertArgType>(portNum)
437  );
438 
439  Drv::ByteStreamStatus retVal;
440 
441  // Lock guard mutex before calling
442  this->lock();
443 
444  // Call handler function
445  retVal = this->send_handler(
446  portNum,
447  sendBuffer
448  );
449 
450  // Unlock guard mutex
451  this->unLock();
452 
453  return retVal;
454  }
455 
456  // ----------------------------------------------------------------------
457  // Invocation functions for typed output ports
458  // ----------------------------------------------------------------------
459 
462  FwIndexType portNum,
463  FwSizeType size
464  )
465  {
466  FW_ASSERT(
467  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
468  static_cast<FwAssertArgType>(portNum)
469  );
470 
471  FW_ASSERT(
472  this->m_allocate_OutputPort[portNum].isConnected(),
473  static_cast<FwAssertArgType>(portNum)
474  );
475  return this->m_allocate_OutputPort[portNum].invoke(
476  size
477  );
478  }
479 
482  FwIndexType portNum,
483  Fw::Buffer& fwBuffer
484  )
485  {
486  FW_ASSERT(
487  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
488  static_cast<FwAssertArgType>(portNum)
489  );
490 
491  FW_ASSERT(
492  this->m_deallocate_OutputPort[portNum].isConnected(),
493  static_cast<FwAssertArgType>(portNum)
494  );
495  this->m_deallocate_OutputPort[portNum].invoke(
496  fwBuffer
497  );
498  }
499 
502  {
503  FW_ASSERT(
504  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
505  static_cast<FwAssertArgType>(portNum)
506  );
507 
508  FW_ASSERT(
509  this->m_ready_OutputPort[portNum].isConnected(),
510  static_cast<FwAssertArgType>(portNum)
511  );
512  this->m_ready_OutputPort[portNum].invoke();
513  }
514 
517  FwIndexType portNum,
518  Fw::Buffer& buffer,
519  const Drv::ByteStreamStatus& status
520  )
521  {
522  FW_ASSERT(
523  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
524  static_cast<FwAssertArgType>(portNum)
525  );
526 
527  FW_ASSERT(
528  this->m_recv_OutputPort[portNum].isConnected(),
529  static_cast<FwAssertArgType>(portNum)
530  );
531  this->m_recv_OutputPort[portNum].invoke(
532  buffer,
533  status
534  );
535  }
536 
537  // ----------------------------------------------------------------------
538  // Mutex operations for guarded ports
539  //
540  // You can override these operations to provide more sophisticated
541  // synchronization
542  // ----------------------------------------------------------------------
543 
546  {
547  this->m_guardedPortMutex.lock();
548  }
549 
552  {
553  this->m_guardedPortMutex.unLock();
554  }
555 
556  // ----------------------------------------------------------------------
557  // Calls for messages received on typed input ports
558  // ----------------------------------------------------------------------
559 
560  void UdpComponentBase ::
561  m_p_recvReturnIn_in(
562  Fw::PassiveComponentBase* callComp,
563  FwIndexType portNum,
564  Fw::Buffer& fwBuffer
565  )
566  {
567  FW_ASSERT(callComp);
568  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
569  compPtr->recvReturnIn_handlerBase(
570  portNum,
571  fwBuffer
572  );
573  }
574 
575  Drv::ByteStreamStatus UdpComponentBase ::
576  m_p_send_in(
577  Fw::PassiveComponentBase* callComp,
578  FwIndexType portNum,
579  Fw::Buffer& sendBuffer
580  )
581  {
582  FW_ASSERT(callComp);
583  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
584  return compPtr->send_handlerBase(
585  portNum,
586  sendBuffer
587  );
588  }
589 
590 }
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.
FwIndexType getNum_allocate_OutputPorts() const
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.
void init()
Object initializer.
Definition: ObjBase.cpp:24
FwIndexType getNum_ready_OutputPorts() const
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
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].
bool isConnected() const
Definition: PortBase.cpp:38
#define PRI_FwIndexType
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
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.
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.
FwIndexType getNum_recv_OutputPorts() const
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)
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:90
void recvReturnIn_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port recvReturnIn.
void init()
Initialization function.
void init()
Initialization function.
void ready_out(FwIndexType portNum)
Invoke output port ready.
FwIndexType getNum_deallocate_OutputPorts() const
virtual void lock()
Lock the guarded mutex.
void init()
Initialization function.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
FwIndexType getNum_send_InputPorts() const
FwIndexType getNum_recvReturnIn_InputPorts() const
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34