F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
16 
17 namespace Drv {
18 
19 // ----------------------------------------------------------------------
20 // Construction, initialization, and destruction
21 // ----------------------------------------------------------------------
22 
24  : ByteStreamDriverModelComponentBase(compName),
25  SocketReadTask() {}
26 
28  ByteStreamDriverModelComponentBase::init(instance);
29 }
30 
32  const U16 port,
33  const U32 send_timeout_seconds,
34  const U32 send_timeout_microseconds) {
35  return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
36 }
37 
39 
40 // ----------------------------------------------------------------------
41 // Implementations for socket read task virtual methods
42 // ----------------------------------------------------------------------
43 
45  return m_socket;
46 }
47 
49  return allocate_out(0, 1024);
50 }
51 
53  this->recv_out(0, buffer, (status == SOCK_SUCCESS) ? RECV_OK : RECV_ERROR);
54 }
55 
56 // ----------------------------------------------------------------------
57 // Handler implementations for user-defined typed input ports
58 // ----------------------------------------------------------------------
59 
60 Drv::SendStatus TcpClientComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
61  Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
62  // Always return the buffer
63  deallocate_out(0, fwBuffer);
64  if ((status == SOCK_DISCONNECTED) || (status == SOCK_INTERRUPTED_TRY_AGAIN)) {
65  return SEND_RETRY;
66  } else if (status != SOCK_SUCCESS) {
67  return SEND_ERROR;
68  }
69  return SEND_OK;
70 }
71 
72 Drv::PollStatus TcpClientComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
73  FW_ASSERT(0); // It is an error to call this handler on IP drivers
74  return Drv::POLL_ERROR;
75 }
76 
77 } // end namespace Drv
Drv::SOCK_SUCCESS
@ SOCK_SUCCESS
Socket operation successful.
Definition: IpSocket.hpp:24
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 filled with data
Definition: TcpClientComponentImpl.cpp:52
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:56
Drv::IpSocket
Helper base-class for setting up Berkley sockets.
Definition: IpSocket.hpp:45
Drv
Definition: BlockDriverImpl.cpp:5
Drv::TcpClientComponentImpl::init
void init(const NATIVE_INT_TYPE instance=0)
Initialize this component.
Definition: TcpClientComponentImpl.cpp:27
Fw::Buffer
Definition: Buffer.hpp:43
Drv::TcpClientComponentImpl::getSocketHandler
IpSocket & getSocketHandler()
returns a reference to the socket handler
Definition: TcpClientComponentImpl.cpp:44
Drv::TcpClientComponentImpl::~TcpClientComponentImpl
~TcpClientComponentImpl(void)
Destroy the component.
Definition: TcpClientComponentImpl.cpp:38
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:60
Drv::SocketReadTask
supports a task to read a given socket adaptation
Definition: SocketReadTask.hpp:27
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:135
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Drv::TcpClientComponentImpl::getBuffer
Fw::Buffer getBuffer()
returns a buffer to fill with data
Definition: TcpClientComponentImpl.cpp:48
Drv::TcpClientComponentImpl::TcpClientComponentImpl
TcpClientComponentImpl(const char *const compName)
construct the TcpClient component.
Definition: TcpClientComponentImpl.cpp:23
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:31
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