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 <Drv/Ip/IpSocket.hpp>
19 #include <config/IpCfg.hpp>
21 
22 namespace Drv {
23 
25  friend class TcpServerTester;
26 
27  public:
28  // ----------------------------------------------------------------------
29  // Construction, initialization, and destruction
30  // ----------------------------------------------------------------------
31 
36  TcpServerComponentImpl(const char* const compName);
37 
42 
43  // ----------------------------------------------------------------------
44  // Helper methods to start and stop socket
45  // ----------------------------------------------------------------------
46 
66  SocketIpStatus configure(const char* const ipv4_address,
67  const U16 port,
68  const U32 send_timeout_seconds = SOCKET_SEND_TIMEOUT_SECONDS,
69  const U32 send_timeout_microseconds = SOCKET_SEND_TIMEOUT_MICROSECONDS,
70  FwSizeType buffer_size = 1024);
71 
75  bool isStarted();
76 
84 
94  void terminate();
95 
104  U16 getListenPort();
105 
106  protected:
107  // ----------------------------------------------------------------------
108  // Implementations for socket read task virtual methods
109  // ----------------------------------------------------------------------
110 
119  IpSocket& getSocketHandler() override;
120 
129  Fw::Buffer getBuffer() override;
130 
139  void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) override;
140 
144  void connected() override;
145 
149  void readLoop() override;
150 
151  private:
152  // ----------------------------------------------------------------------
153  // Handler implementations for user-defined typed input ports
154  // ----------------------------------------------------------------------
155 
170  Drv::ByteStreamStatus send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) override;
171 
175  void recvReturnIn_handler(FwIndexType portNum,
176  Fw::Buffer& fwBuffer
177  ) override;
178 
179  Drv::TcpServerSocket m_socket;
180 
181  FwSizeType m_allocation_size = 0;
182 };
183 
184 } // end namespace Drv
185 
186 #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
PlatformSizeType FwSizeType
IpSocket & getSocketHandler() override
returns a reference to the socket handler
Helper for setting up Tcp using Berkeley sockets as a server.
SocketIpStatus configure(const char *const ipv4_address, 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.
supports a task to read a given socket adaptation
void readLoop() override
read from the socket, overridden to start and terminate the server socket
Status returned by the send call.
void connected() override
called when the IPv4 system has been connected
TcpServerComponentImpl(const char *const compName)
construct the TcpServer component.
void terminate()
stop the read task and terminate the server socket
~TcpServerComponentImpl()
Destroy the component.
U16 getListenPort()
get the port being listened on
PlatformIndexType FwIndexType
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