F´ Flight Software - C/C++ Documentation  NASA-v1.6.0
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/Types/BasicTypes.hpp"
15 #include "Fw/Types/Assert.hpp"
16 
17 
18 namespace Drv {
19 
20 // ----------------------------------------------------------------------
21 // Construction, initialization, and destruction
22 // ----------------------------------------------------------------------
23 
25  : ByteStreamDriverModelComponentBase(compName),
26  SocketReadTask() {}
27 
29  ByteStreamDriverModelComponentBase::init(instance);
30 }
31 
33  const U16 port,
34  const U32 send_timeout_seconds,
35  const U32 send_timeout_microseconds) {
36  return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
37 }
38 
40 
41 // ----------------------------------------------------------------------
42 // Implementations for socket read task virtual methods
43 // ----------------------------------------------------------------------
44 
46  return m_socket;
47 }
48 
50  return allocate_out(0, 1024);
51 }
52 
54  Drv::RecvStatus recvStatus = (status == SOCK_SUCCESS) ? RecvStatus::RECV_OK : RecvStatus::RECV_ERROR;
55  this->recv_out(0, buffer, recvStatus);
56 }
57 
59  if (isConnected_ready_OutputPort(0)) {
60  this->ready_out(0);
61  }
62 
63 }
64 
65 // ----------------------------------------------------------------------
66 // Handler implementations for user-defined typed input ports
67 // ----------------------------------------------------------------------
68 
69 Drv::SendStatus TcpClientComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
70  Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
71  // Always return the buffer
72  deallocate_out(0, fwBuffer);
73  if ((status == SOCK_DISCONNECTED) || (status == SOCK_INTERRUPTED_TRY_AGAIN)) {
74  return SendStatus::SEND_RETRY;
75  } else if (status != SOCK_SUCCESS) {
76  return SendStatus::SEND_ERROR;
77  }
78  return SendStatus::SEND_OK;
79 }
80 
81 Drv::PollStatus TcpClientComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
82  FW_ASSERT(0); // It is an error to call this handler on IP drivers
83  return PollStatus::POLL_ERROR;
84 }
85 
86 } // end namespace Drv
Drv::SOCK_INTERRUPTED_TRY_AGAIN
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition: IpSocket.hpp:30
Drv::TcpClientComponentImpl::sendBuffer
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)
sends a buffer to be filled with data
Definition: TcpClientComponentImpl.cpp:53
Drv::IpSocket::configure
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:52
Fw::Buffer::getData
U8 * getData() const
Definition: Buffer.cpp:60
Drv::IpSocket
Helper base-class for setting up Berkley sockets.
Definition: IpSocket.hpp:45
Drv
Definition: BlockDriver.hpp:11
Drv::TcpClientComponentImpl::init
void init(const NATIVE_INT_TYPE instance=0)
Initialize this component.
Definition: TcpClientComponentImpl.cpp:28
Fw::Buffer
Definition: Buffer.hpp:43
Assert.hpp
Drv::TcpClientComponentImpl::getSocketHandler
IpSocket & getSocketHandler()
returns a reference to the socket handler
Definition: TcpClientComponentImpl.cpp:45
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:64
Drv::TcpClientComponentImpl::connected
void connected()
called when the IPv4 system has been connected
Definition: TcpClientComponentImpl.cpp:58
Drv::SocketReadTask
supports a task to read a given socket adaptation
Definition: SocketReadTask.hpp:27
Drv::TcpClientComponentImpl::~TcpClientComponentImpl
~TcpClientComponentImpl()
Destroy the component.
Definition: TcpClientComponentImpl.cpp:39
TcpClientComponentImpl.hpp
Drv::IpSocket::send
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Definition: IpSocket.cpp:137
Drv::SOCK_SUCCESS
@ SOCK_SUCCESS
Socket operation successful.
Definition: IpSocket.hpp:24
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:8
Drv::TcpClientComponentImpl::getBuffer
Fw::Buffer getBuffer()
returns a buffer to fill with data
Definition: TcpClientComponentImpl.cpp:49
Drv::TcpClientComponentImpl::TcpClientComponentImpl
TcpClientComponentImpl(const char *const compName)
construct the TcpClient component.
Definition: TcpClientComponentImpl.cpp:24
Drv::SocketIpStatus
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:23
Drv::TcpClientComponentImpl::configure
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)
Configures the TcpClient settings but does not open the connection.
Definition: TcpClientComponentImpl.cpp:32
BasicTypes.hpp
Declares ISF basic types.
Drv::SOCK_DISCONNECTED
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
Definition: IpSocket.hpp:32
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29