F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TcpClientComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TcpClientComponentImpl.cpp
3 // \author mstarch
4 // \brief cpp file for TcpClientComponentImpl component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2020, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
14 #include <Fw/FPrimeBasicTypes.hpp>
15 #include <limits>
16 #include "Fw/Types/Assert.hpp"
17 
18 namespace Drv {
19 
20 // ----------------------------------------------------------------------
21 // Construction, initialization, and destruction
22 // ----------------------------------------------------------------------
23 
25 
27  const U16 port,
28  const U32 send_timeout_seconds,
29  const U32 send_timeout_microseconds,
30  FwSizeType buffer_size) {
31  m_allocation_size = buffer_size; // Store the buffer size
32  return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
33 }
34 
36 
37 // ----------------------------------------------------------------------
38 // Implementations for socket read task virtual methods
39 // ----------------------------------------------------------------------
40 
42  return m_socket;
43 }
44 
46  return allocate_out(0, m_allocation_size);
47 }
48 
51  if (status == SOCK_SUCCESS) {
52  recvStatus = ByteStreamStatus::OP_OK;
53  } else if (status == SOCK_NO_DATA_AVAILABLE) {
54  recvStatus = ByteStreamStatus::RECV_NO_DATA;
55  } else {
56  recvStatus = ByteStreamStatus::OTHER_ERROR;
57  }
58  this->recv_out(0, buffer, recvStatus);
59 }
60 
63  this->ready_out(0);
64  }
65 }
66 
67 // ----------------------------------------------------------------------
68 // Handler implementations for user-defined typed input ports
69 // ----------------------------------------------------------------------
70 
71 Drv::ByteStreamStatus TcpClientComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
72  Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
73  Drv::ByteStreamStatus returnStatus;
74  switch (status) {
76  returnStatus = ByteStreamStatus::SEND_RETRY;
77  break;
78  case SOCK_SUCCESS:
79  returnStatus = ByteStreamStatus::OP_OK;
80  break;
81  default:
82  returnStatus = ByteStreamStatus::OTHER_ERROR;
83  break;
84  }
85  return returnStatus;
86 }
87 
88 void TcpClientComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
89  this->deallocate_out(0, fwBuffer);
90 }
91 
92 } // end namespace Drv
Fw::Buffer getBuffer() override
returns a buffer to fill with data
Interrupted status for retries.
Definition: IpSocket.hpp:36
PlatformSizeType FwSizeType
~TcpClientComponentImpl()
Destroy the component.
Auto-generated base for TcpClient component.
SocketIpStatus send(const U8 *const data, const FwSizeType size)
send data to the IP socket from the given buffer
SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds=SOCKET_SEND_TIMEOUT_SECONDS, const U32 send_timeout_microseconds=SOCKET_SEND_TIMEOUT_MICROSECONDS, FwSizeType buffer_size=1024)
Configures the TcpClient settings but does not open the connection.
TcpClientComponentImpl(const char *const compName)
construct the TcpClient component.
U8 * getData() const
Definition: Buffer.cpp:56
void recv_out(FwIndexType portNum, Fw::Buffer &buffer, const Drv::ByteStreamStatus &status)
Invoke output port recv.
Error occurred, retrying may succeed.
Receive worked, but there was no data.
IpSocket & getSocketHandler() override
returns a reference to the socket handler
Status returned by the send call.
Socket operation successful.
Definition: IpSocket.hpp:30
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size)
Invoke output port allocate.
Operation worked as expected.
void connected() override
called when the IPv4 system has been connected
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
virtual SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with host and transmission timeouts
Definition: IpSocket.cpp:51
FwSizeType getSize() const
Definition: Buffer.cpp:60
PlatformIndexType FwIndexType
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:57
No data available or read operation would block.
Definition: IpSocket.hpp:45
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override
sends a buffer to be filled with data
bool isConnected_ready_OutputPort(FwIndexType portNum)
void ready_out(FwIndexType portNum)
Invoke output port ready.