F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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 <FpConfig.hpp>
15#include "Fw/Types/Assert.hpp"
16
17
18namespace Drv {
19
20// ----------------------------------------------------------------------
21// Construction, initialization, and destruction
22// ----------------------------------------------------------------------
23
25 : ByteStreamDriverModelComponentBase(compName),
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
69Drv::SendStatus TcpClientComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
70 Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
71 // Only deallocate buffer when the caller is not asked to retry
72 if (status == SOCK_INTERRUPTED_TRY_AGAIN) {
73 return SendStatus::SEND_RETRY;
74 } else if (status != SOCK_SUCCESS) {
75 deallocate_out(0, fwBuffer);
76 return SendStatus::SEND_ERROR;
77 }
78 deallocate_out(0, fwBuffer);
79 return SendStatus::SEND_OK;
80}
81
82Drv::PollStatus TcpClientComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
83 FW_ASSERT(0); // It is an error to call this handler on IP drivers
84 return PollStatus::POLL_ERROR;
85}
86
87} // end namespace Drv
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
C++-compatible configuration header for fprime configuration.
Helper base-class for setting up Berkley sockets.
Definition IpSocket.hpp:45
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Definition IpSocket.cpp:138
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:53
supports a task to read a given socket adaptation
TcpClientComponentImpl(const char *const compName)
construct the TcpClient component.
void connected()
called when the IPv4 system has been connected
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)
sends a buffer to be filled with data
IpSocket & getSocketHandler()
returns a reference to the socket handler
Fw::Buffer getBuffer()
returns a buffer to fill with data
~TcpClientComponentImpl()
Destroy the component.
void init(const NATIVE_INT_TYPE instance=0)
Initialize this component.
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.
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
SocketIpStatus
Status enumeration for socket return values.
Definition IpSocket.hpp:23
@ SOCK_SUCCESS
Socket operation successful.
Definition IpSocket.hpp:24
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition IpSocket.hpp:30