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 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_FwIndexType "]",
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_FwIndexType "]",
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 dataReturnOut
70  for (
71  FwIndexType port = 0;
72  port < static_cast<FwIndexType>(this->getNum_dataReturnOut_OutputPorts());
73  port++
74  ) {
75  this->m_dataReturnOut_OutputPort[port].init();
76 
77 #if FW_OBJECT_NAMES == 1
78  Fw::ObjectName portName;
79  portName.format(
80  "%s_dataReturnOut_OutputPort[%" PRI_FwIndexType "]",
81  this->m_objName.toChar(),
82  port
83  );
84  this->m_dataReturnOut_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_FwIndexType "]",
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_FwIndexType "]",
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  (0 <= portNum) && (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  (0 <= portNum) && (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  (0 <= portNum) && (portNum < this->getNum_dataReturnOut_OutputPorts()),
168  static_cast<FwAssertArgType>(portNum)
169  );
170 
171  this->m_dataReturnOut_OutputPort[portNum].addCallPort(port);
172  }
173 
176  FwIndexType portNum,
178  )
179  {
180  FW_ASSERT(
181  (0 <= portNum) && (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  (0 <= portNum) && (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  (0 <= portNum) && (portNum < this->getNum_dataReturnOut_OutputPorts()),
216  static_cast<FwAssertArgType>(portNum)
217  );
218 
219  this->m_dataReturnOut_OutputPort[portNum].registerSerialPort(port);
220  }
221 
224  FwIndexType portNum,
225  Fw::InputSerializePort* port
226  )
227  {
228  FW_ASSERT(
229  (0 <= portNum) && (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  (0 <= portNum) && (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  UdpComponentBase(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_dataReturnOut_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  (0 <= portNum) && (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  (0 <= portNum) && (portNum < this->getNum_dataReturnOut_OutputPorts()),
327  static_cast<FwAssertArgType>(portNum)
328  );
329 
330  return this->m_dataReturnOut_OutputPort[portNum].isConnected();
331  }
332 
335  {
336  FW_ASSERT(
337  (0 <= portNum) && (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  (0 <= portNum) && (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& fwBuffer
365  )
366  {
367  // Make sure port number is valid
368  FW_ASSERT(
369  (0 <= portNum) && (portNum < this->getNum_send_InputPorts()),
370  static_cast<FwAssertArgType>(portNum)
371  );
372 
373  // Lock guard mutex before calling
374  this->lock();
375 
376  // Call handler function
377  this->send_handler(
378  portNum,
379  fwBuffer
380  );
381 
382  // Unlock guard mutex
383  this->unLock();
384  }
385 
386  // ----------------------------------------------------------------------
387  // Invocation functions for typed output ports
388  // ----------------------------------------------------------------------
389 
392  FwIndexType portNum,
393  U32 size
394  )
395  {
396  FW_ASSERT(
397  (0 <= portNum) && (portNum < this->getNum_allocate_OutputPorts()),
398  static_cast<FwAssertArgType>(portNum)
399  );
400 
401  FW_ASSERT(
402  this->m_allocate_OutputPort[portNum].isConnected(),
403  static_cast<FwAssertArgType>(portNum)
404  );
405  return this->m_allocate_OutputPort[portNum].invoke(
406  size
407  );
408  }
409 
412  FwIndexType portNum,
413  Fw::Buffer& buffer,
414  const Drv::ByteStreamStatus& status
415  )
416  {
417  FW_ASSERT(
418  (0 <= portNum) && (portNum < this->getNum_dataReturnOut_OutputPorts()),
419  static_cast<FwAssertArgType>(portNum)
420  );
421 
422  FW_ASSERT(
423  this->m_dataReturnOut_OutputPort[portNum].isConnected(),
424  static_cast<FwAssertArgType>(portNum)
425  );
426  this->m_dataReturnOut_OutputPort[portNum].invoke(
427  buffer,
428  status
429  );
430  }
431 
434  {
435  FW_ASSERT(
436  (0 <= portNum) && (portNum < this->getNum_ready_OutputPorts()),
437  static_cast<FwAssertArgType>(portNum)
438  );
439 
440  FW_ASSERT(
441  this->m_ready_OutputPort[portNum].isConnected(),
442  static_cast<FwAssertArgType>(portNum)
443  );
444  this->m_ready_OutputPort[portNum].invoke();
445  }
446 
449  FwIndexType portNum,
450  Fw::Buffer& buffer,
451  const Drv::ByteStreamStatus& status
452  )
453  {
454  FW_ASSERT(
455  (0 <= portNum) && (portNum < this->getNum_recv_OutputPorts()),
456  static_cast<FwAssertArgType>(portNum)
457  );
458 
459  FW_ASSERT(
460  this->m_recv_OutputPort[portNum].isConnected(),
461  static_cast<FwAssertArgType>(portNum)
462  );
463  this->m_recv_OutputPort[portNum].invoke(
464  buffer,
465  status
466  );
467  }
468 
469  // ----------------------------------------------------------------------
470  // Mutex operations for guarded ports
471  //
472  // You can override these operations to provide more sophisticated
473  // synchronization
474  // ----------------------------------------------------------------------
475 
478  {
479  this->m_guardedPortMutex.lock();
480  }
481 
484  {
485  this->m_guardedPortMutex.unLock();
486  }
487 
488  // ----------------------------------------------------------------------
489  // Calls for messages received on typed input ports
490  // ----------------------------------------------------------------------
491 
492  void UdpComponentBase ::
493  m_p_send_in(
494  Fw::PassiveComponentBase* callComp,
495  FwIndexType portNum,
496  Fw::Buffer& fwBuffer
497  )
498  {
499  FW_ASSERT(callComp);
500  UdpComponentBase* compPtr = static_cast<UdpComponentBase*>(callComp);
501  compPtr->send_handlerBase(
502  portNum,
503  fwBuffer
504  );
505  }
506 
507 }
virtual ~UdpComponentBase()
Destroy UdpComponentBase object.
void send_handlerBase(FwIndexType portNum, Fw::Buffer &fwBuffer)
Handler base-class function for input port send.
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
I32 FwEnumStoreType
void set_dataReturnOut_OutputPort(FwIndexType portNum, Drv::InputByteStreamDataPort *port)
Connect port to dataReturnOut[portNum].
void addCallComp(Fw::PassiveComponentBase *callComp, CompFuncPtr funcPtr)
Register a component.
Fw::Buffer invoke(U32 size) const
Invoke a port interface.
bool isConnected_recv_OutputPort(FwIndexType portNum)
void unLock()
unlock the mutex and assert success
Definition: Mutex.cpp:40
void set_recv_OutputPort(FwIndexType portNum, Drv::InputByteStreamDataPort *port)
Connect port to recv[portNum].
virtual void unLock()
Unlock the guarded mutex.
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port dataReturnOut.
void init()
Object initializer.
Definition: ObjBase.cpp:26
FwIndexType getNum_ready_OutputPorts() const
void addCallPort(InputBufferGetPort *callPort)
Register an input port.
void addCallPort(InputByteStreamDataPort *callPort)
Register an input port.
Status returned by the send call.
FwIndexType getNum_dataReturnOut_OutputPorts() const
void invoke(Fw::Buffer &buffer, const Drv::ByteStreamStatus &status) const
Invoke a port interface.
void init()
Initialization function.
const char * toChar() const
Definition: ObjectName.hpp:50
bool isConnected_ready_OutputPort(FwIndexType portNum)
UdpComponentBase(const char *compName="")
Construct UdpComponentBase object.
virtual void send_handler(FwIndexType portNum, Fw::Buffer &fwBuffer)=0
Handler for input port send.
bool isConnected() const
Definition: PortBase.cpp:42
Fw::InputBufferSendPort * get_send_InputPort(FwIndexType portNum)
#define PRI_FwIndexType
bool isConnected_dataReturnOut_OutputPort(FwIndexType portNum)
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:55
Fw::Buffer allocate_out(FwIndexType portNum, U32 size)
Invoke output port allocate.
void setPortNum(FwIndexType portNum)
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
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.
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:93
void init()
Initialization function.
void ready_out(FwIndexType portNum)
Invoke output port ready.
virtual void lock()
Lock the guarded mutex.
void init()
Initialization function.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
FwIndexType getNum_send_InputPorts() const
void lock()
lock the mutex and assert success
Definition: Mutex.cpp:34