fprime/Drv/TcpClient/TcpClientComponentImpl.cpp
M Starch b76d8c9a0c
Update/types refactor as constants (#1623)
* lestarch: adding logical types implementation into Linux/StandardTypes.hpp

* lestarch: removing VxWorks StandardTypes from repository

* updated fprime types for correct compilation with vxworks and baremetal

* lestarch: refactoring types and configuration header w.r.t type design

* lestarch: replacing usages of AssertArg with FwAssertArgType

* lestarch: missspelled configuration

* lestarch: minor compilation fixes

* lestarch: renaming StandardTypes.hpp -> PlatformTypes.hpp

* lestarch: updating PRI tokens

* lestarch: replacing BasicTypes.hpp includes with FpConfig.hpp

* lestarch: UT and compilation fixes for types refactor

* lestarch: sp

* lestarch: fixing RPI issues in PassiveConsoleTextLogger

* lestarch: converting RPI build to debug

* lestarch: removing duplicate config imports

* lestarch: fixing documentation

* lestarch: fixing up multiple definitions and RPI compilation problems

* lestarch: reverting debug build

* lestarch: reverting platform types to class-based constants

* lestarch: reworking basic types

* lestarch: configured types refactor into classes

* lestarch: fixing bugs with static constants in classes

* lestarch: fixing platform types spelling and documentation

* lestarch: adding include guards to types headers

Co-authored-by: Kevin F Ortega <kevin.f.ortega@jpl.nasa.gov>
2022-08-18 13:25:56 -07:00

87 lines
3.1 KiB
C++

// ======================================================================
// \title TcpClientComponentImpl.cpp
// \author mstarch
// \brief cpp file for TcpClientComponentImpl component implementation class
//
// \copyright
// Copyright 2009-2020, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================
#include <Drv/TcpClient/TcpClientComponentImpl.hpp>
#include <FpConfig.hpp>
#include "Fw/Types/Assert.hpp"
namespace Drv {
// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------
TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName)
: ByteStreamDriverModelComponentBase(compName),
SocketReadTask() {}
void TcpClientComponentImpl::init(const NATIVE_INT_TYPE instance) {
ByteStreamDriverModelComponentBase::init(instance);
}
SocketIpStatus TcpClientComponentImpl::configure(const char* hostname,
const U16 port,
const U32 send_timeout_seconds,
const U32 send_timeout_microseconds) {
return m_socket.configure(hostname, port, send_timeout_seconds, send_timeout_microseconds);
}
TcpClientComponentImpl::~TcpClientComponentImpl() {}
// ----------------------------------------------------------------------
// Implementations for socket read task virtual methods
// ----------------------------------------------------------------------
IpSocket& TcpClientComponentImpl::getSocketHandler() {
return m_socket;
}
Fw::Buffer TcpClientComponentImpl::getBuffer() {
return allocate_out(0, 1024);
}
void TcpClientComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) {
Drv::RecvStatus recvStatus = (status == SOCK_SUCCESS) ? RecvStatus::RECV_OK : RecvStatus::RECV_ERROR;
this->recv_out(0, buffer, recvStatus);
}
void TcpClientComponentImpl::connected() {
if (isConnected_ready_OutputPort(0)) {
this->ready_out(0);
}
}
// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------
Drv::SendStatus TcpClientComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
// Always return the buffer
deallocate_out(0, fwBuffer);
if ((status == SOCK_DISCONNECTED) || (status == SOCK_INTERRUPTED_TRY_AGAIN)) {
return SendStatus::SEND_RETRY;
} else if (status != SOCK_SUCCESS) {
return SendStatus::SEND_ERROR;
}
return SendStatus::SEND_OK;
}
Drv::PollStatus TcpClientComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
FW_ASSERT(0); // It is an error to call this handler on IP drivers
return PollStatus::POLL_ERROR;
}
} // end namespace Drv