F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
TcpClientComponentAc.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TcpClientComponentAc.cpp
3 // \author Generated by fpp-to-cpp
4 // \brief cpp file for TcpClient component base class
5 // ======================================================================
6 
7 #include <cstdio>
8 
10 #include "Fw/Types/Assert.hpp"
11 #if FW_ENABLE_TEXT_LOGGING
12 #include "Fw/Types/String.hpp"
13 #endif
14 
15 namespace Drv {
16 
17  // ----------------------------------------------------------------------
18  // Component initialization
19  // ----------------------------------------------------------------------
20 
22  init(NATIVE_INT_TYPE instance)
23  {
24  // Initialize base class
26 
27  // Connect input port send
28  for (
29  PlatformIntType port = 0;
30  port < static_cast<PlatformIntType>(this->getNum_send_InputPorts());
31  port++
32  ) {
33  this->m_send_InputPort[port].init();
34  this->m_send_InputPort[port].addCallComp(
35  this,
36  m_p_send_in
37  );
38  this->m_send_InputPort[port].setPortNum(port);
39 
40 #if FW_OBJECT_NAMES == 1
41  // The port name consists of this->m_objName and some extra info.
42  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
43  // However, the compiler may assume that this->m_objName fills
44  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
45  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
46  // bytes to cover the extra info.
47  char portName[2*FW_OBJ_NAME_MAX_SIZE];
48  (void) snprintf(
49  portName,
50  sizeof(portName),
51  "%s_send_InputPort[%" PRI_PlatformIntType "]",
52  this->m_objName,
53  port
54  );
55  this->m_send_InputPort[port].setObjName(portName);
56 #endif
57  }
58 
59  // Connect output port allocate
60  for (
61  PlatformIntType port = 0;
62  port < static_cast<PlatformIntType>(this->getNum_allocate_OutputPorts());
63  port++
64  ) {
65  this->m_allocate_OutputPort[port].init();
66 
67 #if FW_OBJECT_NAMES == 1
68  // The port name consists of this->m_objName and some extra info.
69  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
70  // However, the compiler may assume that this->m_objName fills
71  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
72  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
73  // bytes to cover the extra info.
74  char portName[2*FW_OBJ_NAME_MAX_SIZE];
75  (void) snprintf(
76  portName,
77  sizeof(portName),
78  "%s_allocate_OutputPort[%" PRI_PlatformIntType "]",
79  this->m_objName,
80  port
81  );
82  this->m_allocate_OutputPort[port].setObjName(portName);
83 #endif
84  }
85 
86  // Connect output port deallocate
87  for (
88  PlatformIntType port = 0;
89  port < static_cast<PlatformIntType>(this->getNum_deallocate_OutputPorts());
90  port++
91  ) {
92  this->m_deallocate_OutputPort[port].init();
93 
94 #if FW_OBJECT_NAMES == 1
95  // The port name consists of this->m_objName and some extra info.
96  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
97  // However, the compiler may assume that this->m_objName fills
98  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
99  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
100  // bytes to cover the extra info.
101  char portName[2*FW_OBJ_NAME_MAX_SIZE];
102  (void) snprintf(
103  portName,
104  sizeof(portName),
105  "%s_deallocate_OutputPort[%" PRI_PlatformIntType "]",
106  this->m_objName,
107  port
108  );
109  this->m_deallocate_OutputPort[port].setObjName(portName);
110 #endif
111  }
112 
113  // Connect output port ready
114  for (
115  PlatformIntType port = 0;
116  port < static_cast<PlatformIntType>(this->getNum_ready_OutputPorts());
117  port++
118  ) {
119  this->m_ready_OutputPort[port].init();
120 
121 #if FW_OBJECT_NAMES == 1
122  // The port name consists of this->m_objName and some extra info.
123  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
124  // However, the compiler may assume that this->m_objName fills
125  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
126  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
127  // bytes to cover the extra info.
128  char portName[2*FW_OBJ_NAME_MAX_SIZE];
129  (void) snprintf(
130  portName,
131  sizeof(portName),
132  "%s_ready_OutputPort[%" PRI_PlatformIntType "]",
133  this->m_objName,
134  port
135  );
136  this->m_ready_OutputPort[port].setObjName(portName);
137 #endif
138  }
139 
140  // Connect output port recv
141  for (
142  PlatformIntType port = 0;
143  port < static_cast<PlatformIntType>(this->getNum_recv_OutputPorts());
144  port++
145  ) {
146  this->m_recv_OutputPort[port].init();
147 
148 #if FW_OBJECT_NAMES == 1
149  // The port name consists of this->m_objName and some extra info.
150  // We expect all of this to fit in FW_OBJ_NAME_MAX_SIZE bytes.
151  // However, the compiler may assume that this->m_objName fills
152  // the entire array, whose size is FW_OBJ_NAME_MAX_SIZE. So to
153  // avoid a compiler warning, we provide an extra FW_OBJ_NAME_MAX_SIZE
154  // bytes to cover the extra info.
155  char portName[2*FW_OBJ_NAME_MAX_SIZE];
156  (void) snprintf(
157  portName,
158  sizeof(portName),
159  "%s_recv_OutputPort[%" PRI_PlatformIntType "]",
160  this->m_objName,
161  port
162  );
163  this->m_recv_OutputPort[port].setObjName(portName);
164 #endif
165  }
166  }
167 
168  // ----------------------------------------------------------------------
169  // Getters for typed input ports
170  // ----------------------------------------------------------------------
171 
174  {
175  FW_ASSERT(
176  portNum < this->getNum_send_InputPorts(),
177  static_cast<FwAssertArgType>(portNum)
178  );
179 
180  return &this->m_send_InputPort[portNum];
181  }
182 
183  // ----------------------------------------------------------------------
184  // Connect typed input ports to typed output ports
185  // ----------------------------------------------------------------------
186 
189  NATIVE_INT_TYPE portNum,
191  )
192  {
193  FW_ASSERT(
194  portNum < this->getNum_allocate_OutputPorts(),
195  static_cast<FwAssertArgType>(portNum)
196  );
197 
198  this->m_allocate_OutputPort[portNum].addCallPort(port);
199  }
200 
203  NATIVE_INT_TYPE portNum,
205  )
206  {
207  FW_ASSERT(
208  portNum < this->getNum_deallocate_OutputPorts(),
209  static_cast<FwAssertArgType>(portNum)
210  );
211 
212  this->m_deallocate_OutputPort[portNum].addCallPort(port);
213  }
214 
217  NATIVE_INT_TYPE portNum,
219  )
220  {
221  FW_ASSERT(
222  portNum < this->getNum_ready_OutputPorts(),
223  static_cast<FwAssertArgType>(portNum)
224  );
225 
226  this->m_ready_OutputPort[portNum].addCallPort(port);
227  }
228 
231  NATIVE_INT_TYPE portNum,
233  )
234  {
235  FW_ASSERT(
236  portNum < this->getNum_recv_OutputPorts(),
237  static_cast<FwAssertArgType>(portNum)
238  );
239 
240  this->m_recv_OutputPort[portNum].addCallPort(port);
241  }
242 
243 #if FW_PORT_SERIALIZATION
244 
245  // ----------------------------------------------------------------------
246  // Connect serial input ports to typed output ports
247  // ----------------------------------------------------------------------
248 
251  NATIVE_INT_TYPE portNum,
252  Fw::InputSerializePort* port
253  )
254  {
255  FW_ASSERT(
256  portNum < this->getNum_deallocate_OutputPorts(),
257  static_cast<FwAssertArgType>(portNum)
258  );
259 
260  this->m_deallocate_OutputPort[portNum].registerSerialPort(port);
261  }
262 
265  NATIVE_INT_TYPE portNum,
266  Fw::InputSerializePort* port
267  )
268  {
269  FW_ASSERT(
270  portNum < this->getNum_ready_OutputPorts(),
271  static_cast<FwAssertArgType>(portNum)
272  );
273 
274  this->m_ready_OutputPort[portNum].registerSerialPort(port);
275  }
276 
279  NATIVE_INT_TYPE portNum,
280  Fw::InputSerializePort* port
281  )
282  {
283  FW_ASSERT(
284  portNum < this->getNum_recv_OutputPorts(),
285  static_cast<FwAssertArgType>(portNum)
286  );
287 
288  this->m_recv_OutputPort[portNum].registerSerialPort(port);
289  }
290 
291 #endif
292 
293  // ----------------------------------------------------------------------
294  // Component construction and destruction
295  // ----------------------------------------------------------------------
296 
298  TcpClientComponentBase(const char* compName) :
299  Fw::PassiveComponentBase(compName)
300  {
301 
302  }
303 
306  {
307 
308  }
309 
310  // ----------------------------------------------------------------------
311  // Getters for numbers of typed input ports
312  // ----------------------------------------------------------------------
313 
316  {
317  return static_cast<NATIVE_INT_TYPE>(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<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_allocate_OutputPort));
328  }
329 
332  {
333  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_deallocate_OutputPort));
334  }
335 
338  {
339  return static_cast<NATIVE_INT_TYPE>(FW_NUM_ARRAY_ELEMENTS(this->m_ready_OutputPort));
340  }
341 
344  {
345  return static_cast<NATIVE_INT_TYPE>(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  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  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  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  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  NATIVE_INT_TYPE portNum,
405  Fw::Buffer& sendBuffer
406  )
407  {
408  // Make sure port number is valid
409  FW_ASSERT(
410  portNum < this->getNum_send_InputPorts(),
411  static_cast<FwAssertArgType>(portNum)
412  );
413 
414  Drv::SendStatus retVal;
415 
416  // Lock guard mutex before calling
417  this->lock();
418 
419  // Call handler function
420  retVal = this->send_handler(
421  portNum,
422  sendBuffer
423  );
424 
425  // Unlock guard mutex
426  this->unLock();
427 
428  return retVal;
429  }
430 
431  // ----------------------------------------------------------------------
432  // Invocation functions for typed output ports
433  // ----------------------------------------------------------------------
434 
437  NATIVE_INT_TYPE portNum,
438  U32 size
439  )
440  {
441  FW_ASSERT(
442  portNum < this->getNum_allocate_OutputPorts(),
443  static_cast<FwAssertArgType>(portNum)
444  );
445  return this->m_allocate_OutputPort[portNum].invoke(
446  size
447  );
448  }
449 
452  NATIVE_INT_TYPE portNum,
453  Fw::Buffer& fwBuffer
454  )
455  {
456  FW_ASSERT(
457  portNum < this->getNum_deallocate_OutputPorts(),
458  static_cast<FwAssertArgType>(portNum)
459  );
460  this->m_deallocate_OutputPort[portNum].invoke(
461  fwBuffer
462  );
463  }
464 
467  {
468  FW_ASSERT(
469  portNum < this->getNum_ready_OutputPorts(),
470  static_cast<FwAssertArgType>(portNum)
471  );
472  this->m_ready_OutputPort[portNum].invoke();
473  }
474 
476  recv_out(
477  NATIVE_INT_TYPE portNum,
478  Fw::Buffer& recvBuffer,
479  const Drv::RecvStatus& recvStatus
480  )
481  {
482  FW_ASSERT(
483  portNum < this->getNum_recv_OutputPorts(),
484  static_cast<FwAssertArgType>(portNum)
485  );
486  this->m_recv_OutputPort[portNum].invoke(
487  recvBuffer,
488  recvStatus
489  );
490  }
491 
492  // ----------------------------------------------------------------------
493  // Mutex operations for guarded ports
494  //
495  // You can override these operations to provide more sophisticated
496  // synchronization
497  // ----------------------------------------------------------------------
498 
500  lock()
501  {
502  this->m_guardedPortMutex.lock();
503  }
504 
506  unLock()
507  {
508  this->m_guardedPortMutex.unLock();
509  }
510 
511  // ----------------------------------------------------------------------
512  // Calls for messages received on typed input ports
513  // ----------------------------------------------------------------------
514 
515  Drv::SendStatus TcpClientComponentBase ::
516  m_p_send_in(
517  Fw::PassiveComponentBase* callComp,
518  NATIVE_INT_TYPE portNum,
519  Fw::Buffer& sendBuffer
520  )
521  {
522  FW_ASSERT(callComp);
523  TcpClientComponentBase* compPtr = static_cast<TcpClientComponentBase*>(callComp);
524  return compPtr->send_handlerBase(
525  portNum,
526  sendBuffer
527  );
528  }
529 
530 }
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
#define FW_NUM_ARRAY_ELEMENTS(a)
number of elements in an array
Definition: BasicTypes.h:66
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
#define PRI_PlatformIntType
PlatformAssertArgType FwAssertArgType
Definition: FpConfig.h:21
#define FW_OBJ_NAME_MAX_SIZE
Size of object name (if object names enabled). AC Limits to 80, truncation occurs above 80.
Definition: FpConfig.h:184
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 TcpClient component.
virtual Drv::SendStatus send_handler(NATIVE_INT_TYPE portNum, Fw::Buffer &sendBuffer)=0
Handler for input port send.
void deallocate_out(NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
Drv::SendStatus send_handlerBase(NATIVE_INT_TYPE portNum, Fw::Buffer &sendBuffer)
Handler base-class function for input port send.
bool isConnected_allocate_OutputPort(NATIVE_INT_TYPE portNum)
void set_ready_OutputPort(NATIVE_INT_TYPE portNum, Drv::InputByteStreamReadyPort *port)
Connect port to ready[portNum].
NATIVE_INT_TYPE getNum_deallocate_OutputPorts() const
void recv_out(NATIVE_INT_TYPE portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
Invoke output port recv.
NATIVE_INT_TYPE getNum_send_InputPorts() const
virtual ~TcpClientComponentBase()
Destroy TcpClientComponentBase object.
NATIVE_INT_TYPE getNum_recv_OutputPorts() const
Drv::InputByteStreamSendPort * get_send_InputPort(NATIVE_INT_TYPE portNum)
virtual void unLock()
Unlock the guarded mutex.
NATIVE_INT_TYPE getNum_allocate_OutputPorts() const
void ready_out(NATIVE_INT_TYPE portNum)
Invoke output port ready.
bool isConnected_deallocate_OutputPort(NATIVE_INT_TYPE portNum)
bool isConnected_ready_OutputPort(NATIVE_INT_TYPE portNum)
void set_recv_OutputPort(NATIVE_INT_TYPE portNum, Drv::InputByteStreamRecvPort *port)
Connect port to recv[portNum].
void set_allocate_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputBufferGetPort *port)
Connect port to allocate[portNum].
TcpClientComponentBase(const char *compName="")
Construct TcpClientComponentBase object.
NATIVE_INT_TYPE getNum_ready_OutputPorts() const
Fw::Buffer allocate_out(NATIVE_INT_TYPE portNum, U32 size)
Invoke output port allocate.
virtual void lock()
Lock the guarded mutex.
bool isConnected_recv_OutputPort(NATIVE_INT_TYPE portNum)
void set_deallocate_OutputPort(NATIVE_INT_TYPE portNum, Fw::InputBufferSendPort *port)
Connect port to deallocate[portNum].
void setPortNum(NATIVE_INT_TYPE portNum)
void init()
Object initializer.
Definition: ObjBase.cpp:27
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 unLock()
unlock the mutex
Definition: Mutex.cpp:13
void lock()
lock the mutex
Definition: Mutex.cpp:12