F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TcpServerComponentImpl.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TcpServerComponentImpl.hpp
3 // \author mstarch
4 // \brief hpp file for TcpServerComponentImpl 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 
13 #ifndef TcpServerComponentImpl_HPP
14 #define TcpServerComponentImpl_HPP
15 
16 #include <IpCfg.hpp>
17 #include <Drv/Ip/IpSocket.hpp>
21 
22 namespace Drv {
23 
25  public:
26  // ----------------------------------------------------------------------
27  // Construction, initialization, and destruction
28  // ----------------------------------------------------------------------
29 
34  TcpServerComponentImpl(const char* const compName);
35 
40 
41  // ----------------------------------------------------------------------
42  // Helper methods to start and stop socket
43  // ----------------------------------------------------------------------
44 
61  SocketIpStatus configure(const char* hostname,
62  const U16 port,
63  const U32 send_timeout_seconds = SOCKET_SEND_TIMEOUT_SECONDS,
64  const U32 send_timeout_microseconds = SOCKET_SEND_TIMEOUT_MICROSECONDS,
65  FwSizeType buffer_size = 1024);
66 
70  bool isStarted();
71 
79 
85  void terminate();
86 
95  U16 getListenPort();
96 
97  PROTECTED:
98  // ----------------------------------------------------------------------
99  // Implementations for socket read task virtual methods
100  // ----------------------------------------------------------------------
101 
110  IpSocket& getSocketHandler() override;
111 
120  Fw::Buffer getBuffer() override;
121 
130  void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override;
131 
135  void connected() override;
136 
140  void readLoop() override;
141 
142  PRIVATE:
143 
144  // ----------------------------------------------------------------------
145  // Handler implementations for user-defined typed input ports
146  // ----------------------------------------------------------------------
147 
163  Drv::SendStatus send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) override;
164 
165  Drv::TcpServerSocket m_socket;
166 
167  FwSizeType m_allocation_size;
168 };
169 
170 } // end namespace Drv
171 
172 #endif // end TcpServerComponentImpl
Auto-generated base for TcpServer component.
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override
sends a buffer to be filled with data
IpSocket & getSocketHandler() override
returns a reference to the socket handler
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
Helper for setting up Tcp using Berkeley sockets as a server.
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
supports a task to read a given socket adaptation
void readLoop() override
read from the socket, overridden to start and terminate the server socket
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.
void connected() override
called when the IPv4 system has been connected
TcpServerComponentImpl(const char *const compName)
construct the TcpServer component.
void terminate()
terminate the server socket
~TcpServerComponentImpl()
Destroy the component.
Status returned by the send call.
U16 getListenPort()
get the port being listened on
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:57
Fw::Buffer getBuffer() override
returns a buffer to fill with data
SocketIpStatus startup()
startup the server socket for communications