![]() |
F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
|
supports a task to read a given socket adaptation More...
#include <Drv/Ip/SocketComponentHelper.hpp>
Public Types | |
enum | OpenState { NOT_OPEN, OPENING, OPEN, SKIP } |
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 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 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... | |
SocketIpStatus | send (const U8 *const data, const U32 size) |
send data to the IP socket from the given buffer More... | |
SocketIpStatus | recv (U8 *data, U32 &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... | |
void | stop () |
stop the socket read task and close the associated socket. More... | |
Os::Task::Status | join () |
joins to the stopping read task to wait for it to close More... | |
Protected Member Functions | |
virtual void | readLoop () |
receive off the TCP socket More... | |
virtual IpSocket & | getSocketHandler ()=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... | |
Static Protected Member Functions | |
static void | readTask (void *pointer) |
a task designed to read from the socket and output incoming data More... | |
Protected Attributes | |
Os::Task | m_task |
Os::Mutex | m_lock |
SocketDescriptor | m_descriptor |
bool | m_reopen = true |
Force reopen on disconnect. More... | |
bool | m_stop = true |
Stops the task when set to true. More... | |
OpenState | m_open = OpenState::NOT_OPEN |
Have we successfully opened. More... | |
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 28 of file SocketComponentHelper.hpp.
Enumerator | |
---|---|
NOT_OPEN | |
OPENING | |
OPEN | |
SKIP |
Definition at line 30 of file SocketComponentHelper.hpp.
Drv::SocketComponentHelper::SocketComponentHelper | ( | ) |
constructs the socket read task
Definition at line 20 of file SocketComponentHelper.cpp.
|
virtual |
destructor of the socket read task
Definition at line 22 of file SocketComponentHelper.cpp.
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 134 of file SocketComponentHelper.cpp.
|
protectedpure virtual |
called when the IPv4 system has been connected
Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.
|
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
Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.
|
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
Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.
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.
Definition at line 72 of file SocketComponentHelper.cpp.
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.
value_ptr | a pointer to fill with data. Passed to the Os::Task::join call. NULL to ignore. |
Definition at line 141 of file SocketComponentHelper.cpp.
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
Definition at line 36 of file SocketComponentHelper.cpp.
|
protectedvirtual |
receive off the TCP socket
Reimplemented in Drv::TcpServerComponentImpl.
Definition at line 176 of file SocketComponentHelper.cpp.
|
staticprotected |
a task designed to read from the socket and output incoming data
pointer | pointer to "this" component |
Definition at line 220 of file SocketComponentHelper.cpp.
SocketIpStatus Drv::SocketComponentHelper::recv | ( | U8 * | data, |
U32 & | size | ||
) |
receive data from the IP socket from the given buffer
data | pointer to data to fill with received data |
size | maximum size of data buffer to fill |
Definition at line 160 of file SocketComponentHelper.cpp.
bool Drv::SocketComponentHelper::running | ( | ) |
is the read loop running
Definition at line 154 of file SocketComponentHelper.cpp.
SocketIpStatus Drv::SocketComponentHelper::send | ( | const U8 *const | data, |
const U32 | size | ||
) |
send data to the IP socket from the given buffer
data | pointer to data to send |
size | size of data to send |
Definition at line 105 of file SocketComponentHelper.cpp.
|
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
Implemented in Drv::TcpServerComponentImpl, Drv::UdpComponentImpl, and Drv::TcpClientComponentImpl.
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.
auto_open | true to automatically open and reopen sockets, false otherwise |
Definition at line 78 of file SocketComponentHelper.cpp.
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 129 of file SocketComponentHelper.cpp.
void Drv::SocketComponentHelper::start | ( | const Fw::StringBase & | name, |
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
Starts up the socket reading task and when reopen was configured, will open up the socket.
setAutomaticOpen
to configure the socket to automatically open connections. The default behavior is to automatically open connections.name | name of the task |
priority | priority of the started task. See: Os::Task::start. Default: TASK_DEFAULT, not prioritized |
stack | stack size provided to the task. See: Os::Task::start. Default: TASK_DEFAULT, posix threads default |
cpuAffinity | cpu affinity provided to task. See: Os::Task::start. Default: TASK_DEFAULT, don't care |
Definition at line 24 of file SocketComponentHelper.cpp.
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 145 of file SocketComponentHelper.cpp.
|
protected |
Definition at line 228 of file SocketComponentHelper.hpp.
|
protected |
Definition at line 227 of file SocketComponentHelper.hpp.
|
protected |
Have we successfully opened.
Definition at line 231 of file SocketComponentHelper.hpp.
|
protected |
Force reopen on disconnect.
Definition at line 229 of file SocketComponentHelper.hpp.
|
protected |
Stops the task when set to true.
Definition at line 230 of file SocketComponentHelper.hpp.
|
protected |
Definition at line 226 of file SocketComponentHelper.hpp.