F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Drv::SocketComponentHelper Class Referenceabstract

supports a task to read a given socket adaptation More...

#include <Drv/Ip/SocketComponentHelper.hpp>

Inheritance diagram for Drv::SocketComponentHelper:
Drv::TcpClientComponentImpl Drv::TcpServerComponentImpl Drv::UdpComponentImpl

Public Types

enum  OpenState { NOT_OPEN, OPENING, OPEN, SKIP }
 
enum  ReconnectState { NOT_RECONNECTING, REQUEST_RECONNECT, RECONNECT_IN_PROGRESS }
 

Public Member Functions

 SocketComponentHelper ()
 constructs the socket read task More...
 
virtual ~SocketComponentHelper ()
 destructor of the socket read task More...
 
void start (const Fw::StringBase &name, const FwTaskPriorityType priority=Os::Task::TASK_PRIORITY_DEFAULT, const Os::Task::ParamType stack=Os::Task::TASK_DEFAULT, const Os::Task::ParamType cpuAffinity=Os::Task::TASK_DEFAULT, const FwTaskPriorityType priorityReconnect=Os::Task::TASK_PRIORITY_DEFAULT, const Os::Task::ParamType stackReconnect=Os::Task::TASK_DEFAULT, const Os::Task::ParamType cpuAffinityReconnect=Os::Task::TASK_DEFAULT)
 start the socket read task to start producing data More...
 
SocketIpStatus open ()
 open the socket for communications More...
 
bool isOpened ()
 check if IP socket has previously been opened More...
 
void setAutomaticOpen (bool auto_open)
 set socket to automatically open connections when true, or not when false More...
 
bool getAutomaticOpen ()
 get socket automatically open connections status More...
 
SocketIpStatus send (const U8 *const data, const FwSizeType size)
 send data to the IP socket from the given buffer More...
 
SocketIpStatus recv (U8 *data, FwSizeType &size)
 receive data from the IP socket from the given buffer More...
 
void close ()
 close the socket communications More...
 
void shutdown ()
 shutdown the socket communications More...
 
bool running ()
 is the read loop running More...
 
bool runningReconnect ()
 
void stop ()
 stop the socket read task and close the associated socket. More...
 
void stopReconnect ()
 
Os::Task::Status join ()
 joins to the stopping read task to wait for it to close More...
 
Os::Task::Status joinReconnect ()
 

Protected Member Functions

virtual void readLoop ()
 receive off the TCP socket More...
 
virtual void reconnectLoop ()
 reconnect TCP socket More...
 
virtual IpSocketgetSocketHandler ()=0
 returns a reference to the socket handler More...
 
virtual Fw::Buffer getBuffer ()=0
 returns a buffer to fill with data More...
 
virtual void sendBuffer (Fw::Buffer buffer, SocketIpStatus status)=0
 sends a buffer to be filled with data More...
 
virtual void connected ()=0
 called when the IPv4 system has been connected More...
 
void requestReconnect ()
 signal to reconnect task that a reconnect is needed More...
 
SocketIpStatus waitForReconnect (Fw::TimeInterval timeout=Fw::TimeInterval(1, 0))
 wait method for a task to wait for a reconnect request to complete More...
 

Static Protected Member Functions

static void readTask (void *pointer)
 a task designed to read from the socket and output incoming data More...
 
static void reconnectTask (void *pointer)
 a task designed for socket reconnection More...
 

Protected Attributes

bool m_reopen = true
 Force reopen on disconnect. More...
 
SocketDescriptor m_descriptor
 
Os::Task m_task
 
Os::Mutex m_lock
 
bool m_stop = true
 Stops the task when set to true. More...
 
OpenState m_open = OpenState::NOT_OPEN
 Have we successfully opened. More...
 
Os::Task m_reconnectTask
 
Os::Mutex m_reconnectLock
 
bool m_reconnectStop = true
 
ReconnectState m_reconnectState = ReconnectState::NOT_RECONNECTING
 
Fw::TimeInterval m_reconnectCheckInterval
 
Fw::TimeInterval m_reconnectWaitInterval
 

Detailed Description

supports a task to read a given socket adaptation

Defines an Os::Task task to read a socket and send out the data. This represents the task itself, which is capable of reading the data from the socket, sending the data out, and reopening the connection should a non-retry error occur.

Definition at line 29 of file SocketComponentHelper.hpp.

Member Enumeration Documentation

◆ OpenState

Enumerator
NOT_OPEN 
OPENING 
OPEN 
SKIP 

Definition at line 31 of file SocketComponentHelper.hpp.

◆ ReconnectState

Enumerator
NOT_RECONNECTING 
REQUEST_RECONNECT 
RECONNECT_IN_PROGRESS 

Definition at line 32 of file SocketComponentHelper.hpp.

Constructor & Destructor Documentation

◆ SocketComponentHelper()

Drv::SocketComponentHelper::SocketComponentHelper ( )

constructs the socket read task

Definition at line 20 of file SocketComponentHelper.cpp.

◆ ~SocketComponentHelper()

Drv::SocketComponentHelper::~SocketComponentHelper ( )
virtual

destructor of the socket read task

Definition at line 22 of file SocketComponentHelper.cpp.

Member Function Documentation

◆ close()

void Drv::SocketComponentHelper::close ( )

close the socket communications

Close the client connection. This will ensure that the resources used are cleaned-up.

Note: this just delegates to the handler

Definition at line 151 of file SocketComponentHelper.cpp.

◆ connected()

virtual void Drv::SocketComponentHelper::connected ( )
protectedpure virtual

called when the IPv4 system has been connected

Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.

◆ getAutomaticOpen()

bool Drv::SocketComponentHelper::getAutomaticOpen ( )

get socket automatically open connections status

Returns
status of auto_open

Definition at line 98 of file SocketComponentHelper.cpp.

◆ getBuffer()

virtual Fw::Buffer Drv::SocketComponentHelper::getBuffer ( )
protectedpure virtual

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.

Note: this must be implemented by the inheritor

Returns
Fw::Buffer to fill with data

Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.

◆ getSocketHandler()

virtual IpSocket& Drv::SocketComponentHelper::getSocketHandler ( )
protectedpure virtual

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.

Note: this must be implemented by the inheritor

Returns
IpSocket reference

Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.

◆ isOpened()

bool Drv::SocketComponentHelper::isOpened ( )

check if IP socket has previously been opened

Check if this IpSocket has previously been opened. In the case of Udp this will check for outgoing transmissions and (if configured) incoming transmissions as well. This does not guarantee errors will not occur when using this socket as the remote component may have disconnected.

Returns
true if socket is open, false otherwise

Definition at line 87 of file SocketComponentHelper.cpp.

◆ join()

Os::Task::Status Drv::SocketComponentHelper::join ( )

joins to the stopping read task to wait for it to close

Called to join with the read socket task. This will block and return after the task has been stopped with a call to the stopSocketTask method.

Parameters
value_ptra pointer to fill with data. Passed to the Os::Task::join call. NULL to ignore.
Returns
: Os::Task::Status passed back from the Os::Task::join call.

Definition at line 160 of file SocketComponentHelper.cpp.

◆ joinReconnect()

Os::Task::Status Drv::SocketComponentHelper::joinReconnect ( )

Definition at line 247 of file SocketComponentHelper.cpp.

◆ open()

SocketIpStatus Drv::SocketComponentHelper::open ( )

open the socket for communications

Typically the socket read task will open the connection and keep it open. However, in cases where the socket is not automatically opening, this call will open the socket. This will block until the socket is opened.

Note: this just delegates to the handler

Returns
status of open, SOCK_SUCCESS for success, something else on error

Definition at line 52 of file SocketComponentHelper.cpp.

◆ readLoop()

void Drv::SocketComponentHelper::readLoop ( )
protectedvirtual

receive off the TCP socket

Reimplemented in Drv::TcpServerComponentImpl.

Definition at line 201 of file SocketComponentHelper.cpp.

◆ readTask()

void Drv::SocketComponentHelper::readTask ( void *  pointer)
staticprotected

a task designed to read from the socket and output incoming data

Parameters
pointerpointer to "this" component

Definition at line 239 of file SocketComponentHelper.cpp.

◆ reconnectLoop()

void Drv::SocketComponentHelper::reconnectLoop ( )
protectedvirtual

reconnect TCP socket

Definition at line 263 of file SocketComponentHelper.cpp.

◆ reconnectTask()

void Drv::SocketComponentHelper::reconnectTask ( void *  pointer)
staticprotected

a task designed for socket reconnection

Parameters
pointerpointer to "this" component

Definition at line 310 of file SocketComponentHelper.cpp.

◆ recv()

SocketIpStatus Drv::SocketComponentHelper::recv ( U8 data,
FwSizeType size 
)

receive data from the IP socket from the given buffer

Parameters
datapointer to data to fill with received data
sizemaximum size of data buffer to fill
Returns
status of the send, SOCK_DISCONNECTED to reopen, SOCK_SUCCESS on success, something else on error

Definition at line 185 of file SocketComponentHelper.cpp.

◆ requestReconnect()

void Drv::SocketComponentHelper::requestReconnect ( )
protected

signal to reconnect task that a reconnect is needed

Definition at line 316 of file SocketComponentHelper.cpp.

◆ running()

bool Drv::SocketComponentHelper::running ( )

is the read loop running

Definition at line 179 of file SocketComponentHelper.cpp.

◆ runningReconnect()

bool Drv::SocketComponentHelper::runningReconnect ( )

Definition at line 257 of file SocketComponentHelper.cpp.

◆ send()

SocketIpStatus Drv::SocketComponentHelper::send ( const U8 *const  data,
const FwSizeType  size 
)

send data to the IP socket from the given buffer

Parameters
datapointer to data to send
sizesize of data to send
Returns
status of send, SOCK_SUCCESS for success, something else on error

Definition at line 121 of file SocketComponentHelper.cpp.

◆ sendBuffer()

virtual void Drv::SocketComponentHelper::sendBuffer ( Fw::Buffer  buffer,
SocketIpStatus  status 
)
protectedpure virtual

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.

Note: this must be implemented by the inheritor

Returns
Fw::Buffer filled with data to send out

Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.

◆ setAutomaticOpen()

void Drv::SocketComponentHelper::setAutomaticOpen ( bool  auto_open)

set socket to automatically open connections when true, or not when false

When passed true, this instructs the socket to automatically open a socket and reopen socket failed connections. When passed false the user must explicitly call the open method to open the socket initially and when a socket fails.

Parameters
auto_opentrue to automatically open and reopen sockets, false otherwise

Definition at line 93 of file SocketComponentHelper.cpp.

◆ shutdown()

void Drv::SocketComponentHelper::shutdown ( )

shutdown the socket communications

Shutdown communication. This will begin the process of cleanly closing communications. This process will be finished with a receive of 0 size and should be followed by a close.

Note: this just delegates to the handler

Definition at line 146 of file SocketComponentHelper.cpp.

◆ start()

void Drv::SocketComponentHelper::start ( const Fw::StringBase name,
const FwTaskPriorityType  priority = Os::Task::TASK_PRIORITY_DEFAULT,
const Os::Task::ParamType  stack = Os::Task::TASK_DEFAULT,
const Os::Task::ParamType  cpuAffinity = Os::Task::TASK_DEFAULT,
const FwTaskPriorityType  priorityReconnect = Os::Task::TASK_PRIORITY_DEFAULT,
const Os::Task::ParamType  stackReconnect = Os::Task::TASK_DEFAULT,
const Os::Task::ParamType  cpuAffinityReconnect = Os::Task::TASK_DEFAULT 
)

start the socket read task to start producing data

Starts up the socket reading task and when reopen was configured, will open up the socket.

Note
: users must now use setAutomaticOpen to configure the socket to automatically open connections. The default behavior is to automatically open connections.
Parameters
namename of the task
prioritypriority of the started read task. See: Os::Task::start. Default: TASK_PRIORITY_DEFAULT, not prioritized
stackstack size provided to the read task. See: Os::Task::start. Default: TASK_DEFAULT, posix threads default
cpuAffinitycpu affinity provided to read task. See: Os::Task::start. Default: TASK_DEFAULT, don't care
priorityReconnectpriority of the started reconnect task. See: Os::Task::start. Default: TASK_PRIORITY_DEFAULT, not prioritized
stackReconnectstack size provided to the reconnect task. See: Os::Task::start. Default: TASK_DEFAULT, posix threads default
cpuAffinityReconnectcpu affinity provided to reconnect task. See: Os::Task::start. Default: TASK_DEFAULT, don't care

Definition at line 24 of file SocketComponentHelper.cpp.

◆ stop()

void Drv::SocketComponentHelper::stop ( )

stop the socket read task and close the associated socket.

Called to stop the socket read task. It is an error to call this before the thread has been started using the startSocketTask call. This will stop the read task and close the client socket.

Definition at line 169 of file SocketComponentHelper.cpp.

◆ stopReconnect()

void Drv::SocketComponentHelper::stopReconnect ( )

Definition at line 251 of file SocketComponentHelper.cpp.

◆ waitForReconnect()

SocketIpStatus Drv::SocketComponentHelper::waitForReconnect ( Fw::TimeInterval  timeout = Fw::TimeInterval(1, 0))
protected

wait method for a task to wait for a reconnect request to complete

After requesting a reconnect, tasks should call this method to wait for the reconnect thread to complete

Parameters
timeouttimeout so that the wait doesn't hang indefinitely
Returns
status of the reconnect request, SOCK_DISCONNECTED for reopen again, or SOCK_SUCCESS on success, something else on error

Definition at line 324 of file SocketComponentHelper.cpp.

Member Data Documentation

◆ m_descriptor

SocketDescriptor Drv::SocketComponentHelper::m_descriptor
protected

Definition at line 280 of file SocketComponentHelper.hpp.

◆ m_lock

Os::Mutex Drv::SocketComponentHelper::m_lock
protected

Definition at line 284 of file SocketComponentHelper.hpp.

◆ m_open

OpenState Drv::SocketComponentHelper::m_open = OpenState::NOT_OPEN
protected

Have we successfully opened.

Definition at line 286 of file SocketComponentHelper.hpp.

◆ m_reconnectCheckInterval

Fw::TimeInterval Drv::SocketComponentHelper::m_reconnectCheckInterval
protected
Initial value:
=
Fw::TimeInterval(0, 50000)

Definition at line 293 of file SocketComponentHelper.hpp.

◆ m_reconnectLock

Os::Mutex Drv::SocketComponentHelper::m_reconnectLock
protected

Definition at line 290 of file SocketComponentHelper.hpp.

◆ m_reconnectState

ReconnectState Drv::SocketComponentHelper::m_reconnectState = ReconnectState::NOT_RECONNECTING
protected

Definition at line 292 of file SocketComponentHelper.hpp.

◆ m_reconnectStop

bool Drv::SocketComponentHelper::m_reconnectStop = true
protected

Definition at line 291 of file SocketComponentHelper.hpp.

◆ m_reconnectTask

Os::Task Drv::SocketComponentHelper::m_reconnectTask
protected

Definition at line 289 of file SocketComponentHelper.hpp.

◆ m_reconnectWaitInterval

Fw::TimeInterval Drv::SocketComponentHelper::m_reconnectWaitInterval
protected
Initial value:
=
Fw::TimeInterval(0, 10000)

Definition at line 295 of file SocketComponentHelper.hpp.

◆ m_reopen

bool Drv::SocketComponentHelper::m_reopen = true
protected

Force reopen on disconnect.

Definition at line 279 of file SocketComponentHelper.hpp.

◆ m_stop

bool Drv::SocketComponentHelper::m_stop = true
protected

Stops the task when set to true.

Definition at line 285 of file SocketComponentHelper.hpp.

◆ m_task

Os::Task Drv::SocketComponentHelper::m_task
protected

Definition at line 283 of file SocketComponentHelper.hpp.


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