F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
SocketComponentHelper.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SocketComponentHelper.hpp
3 // \author mstarch
4 // \brief hpp file for SocketComponentHelper 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 #ifndef DRV_SocketComponentHelper_HPP
13 #define DRV_SocketComponentHelper_HPP
14 
15 #include <Fw/Buffer/Buffer.hpp>
16 #include <Drv/Ip/IpSocket.hpp>
17 #include <Os/Task.hpp>
18 #include <Os/Mutex.hpp>
19 
20 namespace Drv {
29  public:
30  enum OpenState{
34  SKIP
35  };
40 
44  virtual ~SocketComponentHelper();
45 
59  void start(const Fw::StringBase &name,
60  const bool reconnect = true,
63  const Os::Task::ParamType cpuAffinity = Os::Task::TASK_DEFAULT);
64 
76 
86  bool isOpened();
87 
95 
104  SocketIpStatus send(const U8* const data, const U32 size);
105 
114  SocketIpStatus recv(U8* data, U32 &size);
115 
123  void close();
124 
133  void shutdown();
134 
138  bool running();
139 
146  void stop();
147 
157 
158  PROTECTED:
162  virtual void readLoop();
173  virtual IpSocket& getSocketHandler() = 0;
174 
185  virtual Fw::Buffer getBuffer() = 0;
186 
197  virtual void sendBuffer(Fw::Buffer buffer, SocketIpStatus status) = 0;
198 
202  virtual void connected() = 0;
203 
204 
210  static void readTask(void* pointer);
211 
215  bool m_reconnect = false;
216  bool m_stop = true;
217  OpenState m_open = OpenState::NOT_OPEN;
218 };
219 }
220 #endif // DRV_SocketComponentHelper_HPP
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:30
Helper base-class for setting up Berkeley sockets.
Definition: IpSocket.hpp:55
supports a task to read a given socket adaptation
virtual void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)=0
sends a buffer to be filled with data
bool isOpened()
check if IP socket has previously been opened
SocketComponentHelper()
constructs 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
bool m_reconnect
Force reconnection.
OpenState m_open
Have we successfully opened.
virtual Fw::Buffer getBuffer()=0
returns a buffer to fill with data
virtual IpSocket & getSocketHandler()=0
returns a reference to the socket handler
virtual void readLoop()
receive off the TCP socket
bool m_stop
Stops the task when set to true.
virtual void connected()=0
called when the IPv4 system has been connected
void close()
close the socket communications
void shutdown()
shutdown the socket communications
Os::Task::Status join()
joins to the stopping read task to wait for it to close
SocketIpStatus open()
open the socket for communications
SocketIpStatus recv(U8 *data, U32 &size)
receive data from the IP socket from the given buffer
SocketIpStatus send(const U8 *const data, const U32 size)
send data to the IP socket from the given buffer
SocketIpStatus reconnect()
Re-open port if it has been disconnected.
bool running()
is the read loop running
void stop()
stop the socket read task and close the associated socket.
virtual ~SocketComponentHelper()
destructor of the socket read task
static void readTask(void *pointer)
a task designed to read from the socket and output incoming data
FwSizeType ParamType
backwards-compatible parameter type
Definition: Task.hpp:219
static constexpr FwSizeType TASK_DEFAULT
Definition: Task.hpp:28
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:29