F´ Flight Software - C/C++ Documentation  NASA-v2.0.1
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
IpSocket.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title IpSocket.hpp
3 // \author mstarch
4 // \brief hpp file for IpSocket core implementation classes
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_IP_IPHELPER_HPP_
13 #define DRV_IP_IPHELPER_HPP_
14 
15 #include <Fw/Types/BasicTypes.hpp>
16 #include <IpCfg.hpp>
17 #include <Os/Mutex.hpp>
18 
19 namespace Drv {
37 };
38 
45 class IpSocket {
46  public:
47  IpSocket();
66  SocketIpStatus configure(const char* hostname, const U16 port, const U32 send_timeout_seconds,
67  const U32 send_timeout_microseconds);
68 
78  bool isOpened(void);
79 
96  SocketIpStatus open(void);
112  SocketIpStatus send(const U8* const data, const U32 size);
128  SocketIpStatus recv(U8* const data, I32& size);
135  void close(void);
136 
137  PROTECTED:
138 
145 
152  static SocketIpStatus addressToIp4(const char* address, void* ip4);
165  virtual I32 sendProtocol(const U8* const data, const U32 size) = 0;
166 
173  virtual I32 recvProtocol( U8* const data, const U32 size) = 0;
174 
179  U16 m_port;
180  bool m_open;
182 };
183 } // namespace Drv
184 
185 #endif /* DRV_SOCKETIPDRIVER_SOCKETHELPER_HPP_ */
Drv::IpSocket::open
SocketIpStatus open(void)
open the IP socket for communications
Definition: IpSocket.cpp:117
Drv::SOCK_SUCCESS
@ SOCK_SUCCESS
Socket operation successful.
Definition: IpSocket.hpp:24
Drv::IpSocket::m_timeoutSeconds
U32 m_timeoutSeconds
Definition: IpSocket.hpp:177
Drv::SOCK_INTERRUPTED_TRY_AGAIN
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition: IpSocket.hpp:30
Drv::SOCK_FAILED_TO_SET_SOCKET_OPTIONS
@ SOCK_FAILED_TO_SET_SOCKET_OPTIONS
Failed to configure socket.
Definition: IpSocket.hpp:29
Drv::IpSocket::configure
SocketIpStatus configure(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the ip socket with host and transmission timeouts
Definition: IpSocket.cpp:52
Drv::IpSocket::openProtocol
virtual SocketIpStatus openProtocol(NATIVE_INT_TYPE &fd)=0
Protocol specific open implementation, called from open.
Drv::IpSocket::setupTimeouts
SocketIpStatus setupTimeouts(NATIVE_INT_TYPE socketFd)
setup the socket timeout properties of the opened outgoing socket
Definition: IpSocket.cpp:62
U8
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.hpp:76
Drv::SOCK_FAILED_TO_CONNECT
@ SOCK_FAILED_TO_CONNECT
Failed to connect socket.
Definition: IpSocket.hpp:28
Drv::IpSocket
Helper base-class for setting up Berkley sockets.
Definition: IpSocket.hpp:45
Drv::IpSocket::sendProtocol
virtual I32 sendProtocol(const U8 *const data, const U32 size)=0
Protocol specific implementation of send. Called directly with retry from send.
Drv
Definition: BlockDriverImpl.cpp:5
IpCfg.hpp
Drv::SOCK_FAILED_TO_ACCEPT
@ SOCK_FAILED_TO_ACCEPT
Failed to accept connection.
Definition: IpSocket.hpp:35
Drv::SOCK_INVALID_IP_ADDRESS
@ SOCK_INVALID_IP_ADDRESS
Bad IP address supplied.
Definition: IpSocket.hpp:27
Drv::IpSocket::m_hostname
char m_hostname[SOCKET_MAX_HOSTNAME_SIZE]
Hostname to supply.
Definition: IpSocket.hpp:181
Drv::IpSocket::m_lock
Os::Mutex m_lock
Definition: IpSocket.hpp:175
Drv::IpSocket::IpSocket
IpSocket()
Definition: IpSocket.cpp:48
Drv::SOCK_FAILED_TO_LISTEN
@ SOCK_FAILED_TO_LISTEN
Failed to listen on socket.
Definition: IpSocket.hpp:34
Drv::IpSocket::m_timeoutMicroseconds
U32 m_timeoutMicroseconds
Definition: IpSocket.hpp:178
Drv::IpSocket::recvProtocol
virtual I32 recvProtocol(U8 *const data, const U32 size)=0
Protocol specific implementation of recv. Called directly with error handling from recv.
Drv::SOCK_FAILED_TO_GET_SOCKET
@ SOCK_FAILED_TO_GET_SOCKET
Socket open failed.
Definition: IpSocket.hpp:25
Drv::IpSocket::m_open
bool m_open
Have we successfully opened.
Definition: IpSocket.hpp:180
Os::Mutex
Definition: Mutex.hpp:8
Drv::SOCK_FAILED_TO_GET_HOST_IP
@ SOCK_FAILED_TO_GET_HOST_IP
Host IP lookup failed.
Definition: IpSocket.hpp:26
Drv::IpSocket::send
SocketIpStatus send(const U8 *const data, const U32 size)
send data out the IP socket from the given buffer
Definition: IpSocket.cpp:135
Drv::SocketIpStatus
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:23
Drv::SOCK_FAILED_TO_BIND
@ SOCK_FAILED_TO_BIND
Failed to bind to socket.
Definition: IpSocket.hpp:33
BasicTypes.hpp
Declares ISF basic types.
Drv::IpSocket::addressToIp4
static SocketIpStatus addressToIp4(const char *address, void *ip4)
converts a given address in dot form x.x.x.x to an ip address. ONLY works for IPv4.
Definition: IpSocket.cpp:79
Drv::SOCK_READ_ERROR
@ SOCK_READ_ERROR
Failed to read socket.
Definition: IpSocket.hpp:31
Mutex.hpp
Drv::IpSocket::recv
SocketIpStatus recv(U8 *const data, I32 &size)
receive data from the IP socket from the given buffer
Definition: IpSocket.cpp:170
Drv::SOCK_DISCONNECTED
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
Definition: IpSocket.hpp:32
SOCKET_MAX_HOSTNAME_SIZE
@ SOCKET_MAX_HOSTNAME_SIZE
Definition: IpCfg.hpp:23
Drv::SOCK_SEND_ERROR
@ SOCK_SEND_ERROR
Failed to send after configured retries.
Definition: IpSocket.hpp:36
Drv::IpSocket::m_fd
NATIVE_INT_TYPE m_fd
Definition: IpSocket.hpp:176
Drv::IpSocket::m_port
U16 m_port
IP address port used.
Definition: IpSocket.hpp:179
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Drv::IpSocket::close
void close(void)
closes the socket
Definition: IpSocket.cpp:106
Drv::IpSocket::isOpened
bool isOpened(void)
check if IP socket has previously been opened
Definition: IpSocket.cpp:98