F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Drv::TcpServerComponentImpl Class Reference

#include <Drv/TcpServer/TcpServerComponentImpl.hpp>

Inheritance diagram for Drv::TcpServerComponentImpl:
Drv::TcpServerComponentBase Drv::SocketComponentHelper Fw::PassiveComponentBase Fw::ObjBase

Public Member Functions

 TcpServerComponentImpl (const char *const compName)
 construct the TcpServer component.
 
 ~TcpServerComponentImpl ()
 Destroy the 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, FwSizeType buffer_size=1024)
 Configures the TcpServer settings but does not open the connection.
 
bool isStarted ()
 is started
 
SocketIpStatus startup ()
 startup the server socket for communications
 
void terminate ()
 terminate the server socket
 
U16 getListenPort ()
 get the port being listened on
 
- Public Member Functions inherited from Drv::TcpServerComponentBase
void init (FwEnumStoreType instance=0)
 Initialize TcpServerComponentBase object.
 
Drv::InputByteStreamSendPortget_send_InputPort (FwIndexType portNum)
 
void set_allocate_OutputPort (FwIndexType portNum, Fw::InputBufferGetPort *port)
 Connect port to allocate[portNum].
 
void set_deallocate_OutputPort (FwIndexType portNum, Fw::InputBufferSendPort *port)
 Connect port to deallocate[portNum].
 
void set_ready_OutputPort (FwIndexType portNum, Drv::InputByteStreamReadyPort *port)
 Connect port to ready[portNum].
 
void set_recv_OutputPort (FwIndexType portNum, Drv::InputByteStreamRecvPort *port)
 Connect port to recv[portNum].
 
- Public Member Functions inherited from Fw::PassiveComponentBase
void setIdBase (const U32)
 Set the ID base.
 
U32 getIdBase () const
 
- Public Member Functions inherited from Drv::SocketComponentHelper
 SocketComponentHelper ()
 constructs the socket read task
 
virtual ~SocketComponentHelper ()
 destructor of the socket read task
 
void start (const Fw::StringBase &name, const bool reconnect=true, const Os::Task::ParamType priority=Os::Task::TASK_DEFAULT, const Os::Task::ParamType stack=Os::Task::TASK_DEFAULT, const Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT)
 start the socket read task to start producing data
 
SocketIpStatus open ()
 open the socket for communications
 
bool isOpened ()
 check if IP socket has previously been opened
 
SocketIpStatus reconnect ()
 Re-open port if it has been disconnected.
 
SocketIpStatus send (const U8 *const data, const U32 size)
 send data to the IP socket from the given buffer
 
SocketIpStatus recv (U8 *data, U32 &size)
 receive data from the IP socket from the given buffer
 
void close ()
 close the socket communications
 
void shutdown ()
 shutdown the socket communications
 
bool running ()
 is the read loop running
 
void stop ()
 stop the socket read task and close the associated socket.
 
Os::Task::Status join ()
 joins to the stopping read task to wait for it to close
 

Protected Member Functions

IpSocketgetSocketHandler () override
 returns a reference to the socket handler
 
Fw::Buffer getBuffer () override
 returns a buffer to fill with data
 
void sendBuffer (Fw::Buffer buffer, SocketIpStatus status) override
 sends a buffer to be filled with data
 
void connected () override
 called when the IPv4 system has been connected
 
void readLoop () override
 read from the socket, overridden to start and terminate the server socket
 
- Protected Member Functions inherited from Drv::TcpServerComponentBase
 TcpServerComponentBase (const char *compName="")
 Construct TcpServerComponentBase object.
 
virtual ~TcpServerComponentBase ()
 Destroy TcpServerComponentBase object.
 
FwIndexType getNum_send_InputPorts () const
 
FwIndexType getNum_allocate_OutputPorts () const
 
FwIndexType getNum_deallocate_OutputPorts () const
 
FwIndexType getNum_ready_OutputPorts () const
 
FwIndexType getNum_recv_OutputPorts () const
 
bool isConnected_allocate_OutputPort (FwIndexType portNum)
 
bool isConnected_deallocate_OutputPort (FwIndexType portNum)
 
bool isConnected_ready_OutputPort (FwIndexType portNum)
 
bool isConnected_recv_OutputPort (FwIndexType portNum)
 
Drv::SendStatus send_handlerBase (FwIndexType portNum, Fw::Buffer &sendBuffer)
 Handler base-class function for input port send.
 
Fw::Buffer allocate_out (FwIndexType portNum, U32 size)
 Invoke output port allocate.
 
void deallocate_out (FwIndexType portNum, Fw::Buffer &fwBuffer)
 Invoke output port deallocate.
 
void ready_out (FwIndexType portNum)
 Invoke output port ready.
 
void recv_out (FwIndexType portNum, Fw::Buffer &recvBuffer, const Drv::RecvStatus &recvStatus)
 Invoke output port recv.
 
virtual void lock ()
 Lock the guarded mutex.
 
virtual void unLock ()
 Unlock the guarded mutex.
 
- Protected Member Functions inherited from Fw::PassiveComponentBase
 PassiveComponentBase (const char *name)
 Named constructor.
 
virtual ~PassiveComponentBase ()
 Destructor.
 
void init (NATIVE_INT_TYPE instance)
 Initialization function.
 
NATIVE_INT_TYPE getInstance () const
 
- Protected Member Functions inherited from Fw::ObjBase
 ObjBase (const char *name)
 ObjBase constructor.
 
virtual ~ObjBase ()
 Destructor.
 
void init ()
 Object initializer.
 

Additional Inherited Members

- Public Types inherited from Drv::SocketComponentHelper
enum  OpenState { NOT_OPEN , OPENING , OPEN , SKIP }
 
- Protected Types inherited from Drv::TcpServerComponentBase
enum  { NUM_SEND_INPUT_PORTS = 1 }
 Enumerations for numbers of typed input ports. More...
 
enum  { NUM_ALLOCATE_OUTPUT_PORTS = 1 , NUM_DEALLOCATE_OUTPUT_PORTS = 1 , NUM_READY_OUTPUT_PORTS = 1 , NUM_RECV_OUTPUT_PORTS = 1 }
 Enumerations for numbers of typed output ports. More...
 
- Static Protected Member Functions inherited from Drv::SocketComponentHelper
static void readTask (void *pointer)
 a task designed to read from the socket and output incoming data
 
- Protected Attributes inherited from Drv::SocketComponentHelper
Os::Task m_task
 
Os::Mutex m_lock
 
SocketDescriptor m_descriptor
 
bool m_reconnect = false
 Force reconnection.
 
bool m_stop = true
 Stops the task when set to true.
 
OpenState m_open = OpenState::NOT_OPEN
 Have we successfully opened.
 

Detailed Description

Definition at line 24 of file TcpServerComponentImpl.hpp.

Constructor & Destructor Documentation

◆ TcpServerComponentImpl()

Drv::TcpServerComponentImpl::TcpServerComponentImpl ( const char *const  compName)

construct the TcpServer component.

Parameters
compNamename of this component

Definition at line 25 of file TcpServerComponentImpl.cpp.

◆ ~TcpServerComponentImpl()

Drv::TcpServerComponentImpl::~TcpServerComponentImpl ( )

Destroy the component.

Definition at line 43 of file TcpServerComponentImpl.cpp.

Member Function Documentation

◆ configure()

SocketIpStatus Drv::TcpServerComponentImpl::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 TcpServer settings but does not open the connection.

The TcpServerComponent needs to listen for a remote TCP client. This call configures the hostname, port and send timeouts for that socket connection. This call should be performed on system startup before recv or send are called. Note: hostname must be a dot-notation IP address of the form "x.x.x.x". DNS translation is left up to the user.

Parameters
hostnameip address of remote tcp server in the form x.x.x.x
portport of remote tcp server
send_timeout_secondssend timeout seconds component. Defaults to: SOCKET_TIMEOUT_SECONDS
send_timeout_microsecondssend timeout microseconds component. Must be less than 1000000. Defaults to: SOCKET_TIMEOUT_MICROSECONDS
buffer_sizesize of the buffer to be allocated. Defaults to 1024.
Returns
status of the configure

Definition at line 28 of file TcpServerComponentImpl.cpp.

◆ connected()

void Drv::TcpServerComponentImpl::connected ( )
overrideprotectedvirtual

called when the IPv4 system has been connected

Implements Drv::SocketComponentHelper.

Definition at line 75 of file TcpServerComponentImpl.cpp.

◆ getBuffer()

Fw::Buffer Drv::TcpServerComponentImpl::getBuffer ( )
overrideprotectedvirtual

returns a buffer to fill with data

Gets a reference to a buffer to fill with data. This allows the component to determine how to provide a buffer and the socket read task just fills said buffer.

Returns
Fw::Buffer to fill with data

Implements Drv::SocketComponentHelper.

Definition at line 57 of file TcpServerComponentImpl.cpp.

◆ getListenPort()

U16 Drv::TcpServerComponentImpl::getListenPort ( )

get the port being listened on

Most useful when listen was configured to use port "0", this will return the port used for listening after a port has been determined. Will return 0 if the connection has not been setup.

Returns
receive port

Definition at line 49 of file TcpServerComponentImpl.cpp.

◆ getSocketHandler()

IpSocket & Drv::TcpServerComponentImpl::getSocketHandler ( )
overrideprotectedvirtual

returns a reference to the socket handler

Gets a reference to the current socket handler in order to operate generically on the IpSocket instance. Used for receive, and open calls. This socket handler will be a TcpServer.

Returns
IpSocket reference

Implements Drv::SocketComponentHelper.

Definition at line 53 of file TcpServerComponentImpl.cpp.

◆ isStarted()

bool Drv::TcpServerComponentImpl::isStarted ( )

is started

Definition at line 81 of file TcpServerComponentImpl.cpp.

◆ readLoop()

void Drv::TcpServerComponentImpl::readLoop ( )
overrideprotectedvirtual

read from the socket, overridden to start and terminate the server socket

Reimplemented from Drv::SocketComponentHelper.

Definition at line 102 of file TcpServerComponentImpl.cpp.

◆ sendBuffer()

void Drv::TcpServerComponentImpl::sendBuffer ( Fw::Buffer  buffer,
SocketIpStatus  status 
)
overrideprotectedvirtual

sends a buffer to be filled with data

Sends the buffer gotten by getBuffer that has now been filled with data. This is used to delegate to the component how to send back the buffer. Ignores buffers with error status error.

Returns
Fw::Buffer filled with data to send out

Implements Drv::SocketComponentHelper.

Definition at line 61 of file TcpServerComponentImpl.cpp.

◆ startup()

SocketIpStatus Drv::TcpServerComponentImpl::startup ( )

startup the server socket for communications

Start up the server socket by listening on a port. Note: does not accept clients, this is done in open to facilitate re-connection of clients.

Definition at line 86 of file TcpServerComponentImpl.cpp.

◆ terminate()

void Drv::TcpServerComponentImpl::terminate ( )

terminate the server socket

Close the server socket. Should be done after all clients are shutdown and closed.

Definition at line 96 of file TcpServerComponentImpl.cpp.


The documentation for this class was generated from the following files: