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 #if !FW_DIRECT_PORT_CALLS
27  // Connect input port recvReturnIn
28  for (
29  FwIndexType port = 0;
30  port < static_cast<FwIndexType>(this->getNum_recvReturnIn_InputPorts());
31  port++
32  ) {
33  this->m_recvReturnIn_InputPort[port].init();
34  this->m_recvReturnIn_InputPort[port].addCallComp(
35  this,
36  m_p_recvReturnIn_in
37  );
38  this->m_recvReturnIn_InputPort[port].setPortNum(port);
39 
40 #if FW_OBJECT_NAMES == 1
41  Fw::ObjectName portName;
42  portName.format(
43  "%s_recvReturnIn_InputPort[%" PRI_FwIndexType "]",
44  this->m_objName.toChar(),
45  port
46  );
47  this->m_recvReturnIn_InputPort[port].setObjName(portName.toChar());
48 #endif
49  }
50 #endif
51 
52 #if !FW_DIRECT_PORT_CALLS
53  // Connect input port send
54  for (
55  FwIndexType port = 0;
56  port < static_cast<FwIndexType>(this->getNum_send_InputPorts());
57  port++
58  ) {
59  this->m_send_InputPort[port].init();
60  this->m_send_InputPort[port].addCallComp(
61  this,
62  m_p_send_in
63  );
64  this->m_send_InputPort[port].setPortNum(port);
65 
66 #if FW_OBJECT_NAMES == 1
67  Fw::ObjectName portName;
68  portName.format(
69  "%s_send_InputPort[%" PRI_FwIndexType "]",
70  this->m_objName.toChar(),
71  port
72  );
73  this->m_send_InputPort[port].setObjName(portName.toChar());
74 #endif
75  }
76 #endif
77 
78 #if !FW_DIRECT_PORT_CALLS
79  // Connect output port allocate
80  for (
81  FwIndexType port = 0;
82  port < static_cast<FwIndexType>(this->getNum_allocate_OutputPorts());
83  port++
84  ) {
85  this->m_allocate_OutputPort[port].init();
86 
87 #if FW_OBJECT_NAMES == 1
88  Fw::ObjectName portName;
89  portName.format(
90  "%s_allocate_OutputPort[%" PRI_FwIndexType "]",
91  this->m_objName.toChar(),
92  port
93  );
94  this->m_allocate_OutputPort[port].setObjName(portName.toChar());
95 #endif
96  }
97 #endif
98 
99 #if !FW_DIRECT_PORT_CALLS
100  // Connect output port deallocate
101  for (
102  FwIndexType port = 0;
103  port < static_cast<FwIndexType>(this->getNum_deallocate_OutputPorts());
104  port++
105  ) {
106  this->m_deallocate_OutputPort[port].init();
107 
108 #if FW_OBJECT_NAMES == 1
109  Fw::ObjectName portName;
110  portName.format(
111  "%s_deallocate_OutputPort[%" PRI_FwIndexType "]",
112  this->m_objName.toChar(),
113  port
114  );
115  this->m_deallocate_OutputPort[port].setObjName(portName.toChar());
116 #endif
117  }
118 #endif
119 
120 #if !FW_DIRECT_PORT_CALLS
121  // Connect output port ready
122  for (
123  FwIndexType port = 0;
124  port < static_cast<FwIndexType>(this->getNum_ready_OutputPorts());
125  port++
126  ) {
127  this->m_ready_OutputPort[port].init();
128 
129 #if FW_OBJECT_NAMES == 1
130  Fw::ObjectName portName;
131  portName.format(
132  "%s_ready_OutputPort[%" PRI_FwIndexType "]",
133  this->m_objName.toChar(),
134  port
135  );
136  this->m_ready_OutputPort[port].setObjName(portName.toChar());
137 #endif
138  }
139 #endif
140 
141 #if !FW_DIRECT_PORT_CALLS
142  // Connect output port recv
143  for (
144  FwIndexType port = 0;
145  port < static_cast<FwIndexType>(this->getNum_recv_OutputPorts());
146  port++
147  ) {
148  this->m_recv_OutputPort[port].init();
149 
150 #if FW_OBJECT_NAMES == 1
151  Fw::ObjectName portName;
152  portName.format(
153  "%s_recv_OutputPort[%" PRI_FwIndexType "]",
154  this->m_objName.toChar(),
155  port
156  );
157  this->m_recv_OutputPort[port].setObjName(portName.toChar());
158 #endif
159  }
160 #endif
161  }
162 
163 #if !FW_DIRECT_PORT_CALLS
164 
165  // ----------------------------------------------------------------------
166  // Getters for typed input ports
167  // ----------------------------------------------------------------------
168 
171  {
172  FW_ASSERT(
173  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
174  static_cast<FwAssertArgType>(portNum)
175  );
176 
177  return &this->m_recvReturnIn_InputPort[portNum];
178  }
179 
182  {
183  FW_ASSERT(
184  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
185  static_cast<FwAssertArgType>(portNum)
186  );
187 
188  return &this->m_send_InputPort[portNum];
189  }
190 
191 #endif
192 
193 #if !FW_DIRECT_PORT_CALLS
194 
195  // ----------------------------------------------------------------------
196  // Connect typed input ports to typed output ports
197  // ----------------------------------------------------------------------
198 
201  FwIndexType portNum,
203  )
204  {
205  FW_ASSERT(
206  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
207  static_cast<FwAssertArgType>(portNum)
208  );
209 
210  this->m_allocate_OutputPort[portNum].addCallPort(port);
211  }
212 
215  FwIndexType portNum,
217  )
218  {
219  FW_ASSERT(
220  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
221  static_cast<FwAssertArgType>(portNum)
222  );
223 
224  this->m_deallocate_OutputPort[portNum].addCallPort(port);
225  }
226 
229  FwIndexType portNum,
231  )
232  {
233  FW_ASSERT(
234  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
235  static_cast<FwAssertArgType>(portNum)
236  );
237 
238  this->m_ready_OutputPort[portNum].addCallPort(port);
239  }
240 
243  FwIndexType portNum,
245  )
246  {
247  FW_ASSERT(
248  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
249  static_cast<FwAssertArgType>(portNum)
250  );
251 
252  this->m_recv_OutputPort[portNum].addCallPort(port);
253  }
254 
255 #endif
256 
257 #if !FW_DIRECT_PORT_CALLS && FW_PORT_SERIALIZATION
258 
259  // ----------------------------------------------------------------------
260  // Connect serial input ports to typed output ports
261  // ----------------------------------------------------------------------
262 
265  FwIndexType portNum,
266  Fw::InputSerializePort* port
267  )
268  {
269  FW_ASSERT(
270  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
271  static_cast<FwAssertArgType>(portNum)
272  );
273 
274  this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
275  }
276 
279  FwIndexType portNum,
280  Fw::InputSerializePort* port
281  )
282  {
283  FW_ASSERT(
284  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
285  static_cast<FwAssertArgType>(portNum)
286  );
287 
288  this->m_ready_OutputPort[portNum].registerSerialPort(port);
289  }
290 
293  FwIndexType portNum,
294  Fw::InputSerializePort* port
295  )
296  {
297  FW_ASSERT(
298  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
299  static_cast<FwAssertArgType>(portNum)
300  );
301 
302  this->m_recv_OutputPort[portNum].registerSerialPort(port);
303  }
304 
305 #endif
306 
307  // ----------------------------------------------------------------------
308  // Component construction and destruction
309  // ----------------------------------------------------------------------
310 
312  UdpComponentBase(const char* compName) :
313  Fw::PassiveComponentBase(compName)
314  {
315 
316  }
317 
320  {
321 
322  }
323 
324 #if !FW_DIRECT_PORT_CALLS
325 
326  // ----------------------------------------------------------------------
327  // Connection status queries for typed output ports
328  // ----------------------------------------------------------------------
329 
332  {
333  FW_ASSERT(
334  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
335  static_cast<FwAssertArgType>(portNum)
336  );
337 
338  return this->m_allocate_OutputPort[portNum].isConnected();
339  }
340 
343  {
344  FW_ASSERT(
345  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
346  static_cast<FwAssertArgType>(portNum)
347  );
348 
349  return this->m_deallocate_OutputPort[portNum].isConnected();
350  }
351 
354  {
355  FW_ASSERT(
356  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
357  static_cast<FwAssertArgType>(portNum)
358  );
359 
360  return this->m_ready_OutputPort[portNum].isConnected();
361  }
362 
365  {
366  FW_ASSERT(
367  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
368  static_cast<FwAssertArgType>(portNum)
369  );
370 
371  return this->m_recv_OutputPort[portNum].isConnected();
372  }
373 
374 #endif
375 
376  // ----------------------------------------------------------------------
377  // Port handler base-class functions for typed input ports
378  //
379  // Call these functions directly to bypass the corresponding ports
380  // ----------------------------------------------------------------------
381 
384  FwIndexType portNum,
385  Fw::Buffer& fwBuffer
386  )
387  {
388  // Make sure port number is valid
389  FW_ASSERT(
390  (0 <= portNum) && (portNum < this->getNum_recvReturnIn_InputPorts()),
391  static_cast<FwAssertArgType>(portNum)
392  );
393 
394  // Lock guard mutex before calling
395  this->lock();
396 
397  // Call handler function
398  this->recvReturnIn_handler(
399  portNum,
400  fwBuffer
401  );
402 
403  // Unlock guard mutex
404  this->unLock();
405  }
406 
409  FwIndexType portNum,
410  Fw::Buffer& sendBuffer
411  )
412  {
413  // Make sure port number is valid
414  FW_ASSERT(
415  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
416  static_cast<FwAssertArgType>(portNum)
417  );
418 
419  Drv::ByteStreamStatus retVal;
420 
421  // Lock guard mutex before calling
422  this->lock();
423 
424  // Call handler function
425  retVal = this->send_handler(
426  portNum,
427  sendBuffer
428  );
429 
430  // Unlock guard mutex
431  this->unLock();
432 
433  return retVal;
434  }
435 
436 #if !FW_DIRECT_PORT_CALLS
437 
438  // ----------------------------------------------------------------------
439  // Invocation functions for typed output ports
440  // ----------------------------------------------------------------------
441 
444  FwIndexType portNum,
445  FwSizeType size
446  ) const
447  {
448  FW_ASSERT(
449  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
450  static_cast<FwAssertArgType>(portNum)
451  );
452 
453  FW_ASSERT(
454  this->m_allocate_OutputPort[portNum].isConnected(),
455  static_cast<FwAssertArgType>(portNum)
456  );
457  return this->m_allocate_OutputPort[portNum].invoke(
458  size
459  );
460  }
461 
464  FwIndexType portNum,
465  Fw::Buffer& fwBuffer
466  ) const
467  {
468  FW_ASSERT(
469  (0 <= portNum) && (portNum < this->getNum_deallocate_OutputPorts()),
470  static_cast<FwAssertArgType>(portNum)
471  );
472 
473  FW_ASSERT(
474  this->m_deallocate_OutputPort[portNum].isConnected(),
475  static_cast<FwAssertArgType>(portNum)
476  );
477  this->m_deallocate_OutputPort[portNum].invoke(
478  fwBuffer
479  );
480  }
481 
483  ready_out(FwIndexType portNum) const
484  {
485  FW_ASSERT(
486  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
487  static_cast<FwAssertArgType>(portNum)
488  );
489 
490  FW_ASSERT(
491  this->m_ready_OutputPort[portNum].isConnected(),
492  static_cast<FwAssertArgType>(portNum)
493  );
494  this->m_ready_OutputPort[portNum].invoke();
495  }
496 
499  FwIndexType portNum,
500  Fw::Buffer& buffer,
501  const Drv::ByteStreamStatus& status
502  ) const
503  {
504  FW_ASSERT(
505  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
506  static_cast<FwAssertArgType>(portNum)
507  );
508 
509  FW_ASSERT(
510  this->m_recv_OutputPort[portNum].isConnected(),
511  static_cast<FwAssertArgType>(portNum)
512  );
513  this->m_recv_OutputPort[portNum].invoke(
514  buffer,
515  status
516  );
517  }
518 
519 #endif
520 
521  // ----------------------------------------------------------------------
522  // Mutex operations for guarded ports
523  //
524  // You can override these operations to provide more sophisticated
525  // synchronization
526  // ----------------------------------------------------------------------
527 
530  {
531  this->m_guardedPortMutex.lock();
532  }
533 
536  {
537  this->m_guardedPortMutex.unLock();
538  }
539 
540  // ----------------------------------------------------------------------
541  // Calls for messages received on typed input ports
542  // ----------------------------------------------------------------------
543 
544  void UdpComponentBase ::
545  m_p_recvReturnIn_in(
546  Fw::PassiveComponentBase* callComp,
547  FwIndexType portNum,
548  Fw::Buffer& fwBuffer
549  )
550  {
551  FW_ASSERT(callComp);
552  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
553  compPtr->recvReturnIn_handlerBase(
554  portNum,
555  fwBuffer
556  );
557  }
558 
559  Drv::ByteStreamStatus UdpComponentBase ::
560  m_p_send_in(
561  Fw::PassiveComponentBase* callComp,
562  FwIndexType portNum,
563  Fw::Buffer& sendBuffer
564  )
565  {
566  FW_ASSERT(callComp);
567  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
568  return compPtr->send_handlerBase(
569  portNum,
570  sendBuffer
571  );
572  }
573 
574 }
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status) const
Invoke output port recv.
virtual ~UdpComponentBase()
Destroy UdpComponentBase object.
void addCallPort(InputByteStreamReadyPort *callPort)
Register an input port.
void ready_out(FwIndexType portNum) const
Invoke output port ready.
static constexpr FwIndexType getNum_ready_OutputPorts()
PlatformSizeType FwSizeType
I32 FwEnumStoreType
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
bool isConnected_allocate_OutputPort(FwIndexType portNum) const
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
bool isConnected_deallocate_OutputPort(FwIndexType portNum) const
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()
bool isConnected_recv_OutputPort(FwIndexType portNum) const
static constexpr FwIndexType getNum_send_InputPorts()
void init()
Object initializer.
Definition: ObjBase.cpp:24
void addCallPort(InputBufferGetPort *callPort)
Register an input port.
void addCallPort(InputByteStreamDataPort *callPort)
Register an input port.
Status returned by the send call.
void invoke(Fw::Buffer &buffer, const Drv::ByteStreamStatus &status) const
Invoke a port connection.
void invoke(Fw::Buffer &fwBuffer) const
Invoke a port connection.
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
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port deallocate.
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
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].
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 connection.
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size) const
Invoke output port allocate.
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.
virtual void lock()
Lock the guarded mutex.
Implementation of malloc based allocator.
bool isConnected_ready_OutputPort(FwIndexType portNum) const
void init()
Initialization function.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34