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
UdpComponentImpl.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title UdpComponentImpl.cpp
3 // \author mstarch
4 // \brief cpp file for UdpComponentImpl 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 
14 #include <IpCfg.hpp>
15 #include "Fw/Types/BasicTypes.hpp"
16 
17 
18 namespace Drv {
19 
20 // ----------------------------------------------------------------------
21 // Construction, initialization, and destruction
22 // ----------------------------------------------------------------------
23 
24 UdpComponentImpl::UdpComponentImpl(const char* const compName)
25  : ByteStreamDriverModelComponentBase(compName),
26  SocketReadTask() {}
27 
29  ByteStreamDriverModelComponentBase::init(instance);
30 }
31 
33  const U16 port,
34  const U32 send_timeout_seconds,
35  const U32 send_timeout_microseconds) {
36  return m_socket.configureSend(hostname, port, send_timeout_seconds, send_timeout_microseconds);
37 }
38 
39 SocketIpStatus UdpComponentImpl::configureRecv(const char* hostname, const U16 port) {
40  return m_socket.configureRecv(hostname, port);
41 }
42 
44 
45 // ----------------------------------------------------------------------
46 // Implementations for socket read task virtual methods
47 // ----------------------------------------------------------------------
48 
50  return m_socket;
51 }
52 
54  return allocate_out(0, 1024);
55 }
56 
58  this->recv_out(0, buffer, (status == SOCK_SUCCESS) ? RECV_OK : RECV_ERROR);
59 }
60 
61 // ----------------------------------------------------------------------
62 // Handler implementations for user-defined typed input ports
63 // ----------------------------------------------------------------------
64 
65 Drv::SendStatus UdpComponentImpl::send_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
66  Drv::SocketIpStatus status = m_socket.send(fwBuffer.getData(), fwBuffer.getSize());
67  // Always return the buffer
68  deallocate_out(0, fwBuffer);
69  if ((status == SOCK_DISCONNECTED) || (status == SOCK_INTERRUPTED_TRY_AGAIN)) {
70  return SEND_RETRY;
71  } else if (status != SOCK_SUCCESS) {
72  return SEND_ERROR;
73  }
74  return SEND_OK;
75 }
76 
77 Drv::PollStatus UdpComponentImpl::poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
78  FW_ASSERT(0); // It is an error to call this handler on IP drivers
79  return Drv::POLL_ERROR;
80 }
81 
82 } // end namespace Drv
Drv::UdpComponentImpl::~UdpComponentImpl
~UdpComponentImpl(void)
Destroy the component.
Definition: UdpComponentImpl.cpp:43
Drv::SOCK_SUCCESS
@ SOCK_SUCCESS
Socket operation successful.
Definition: IpSocket.hpp:24
Drv::UdpComponentImpl::getSocketHandler
IpSocket & getSocketHandler()
returns a reference to the socket handler
Definition: UdpComponentImpl.cpp:49
Drv::SOCK_INTERRUPTED_TRY_AGAIN
@ SOCK_INTERRUPTED_TRY_AGAIN
Interrupted status for retries.
Definition: IpSocket.hpp:30
Drv::UdpComponentImpl::configureRecv
SocketIpStatus configureRecv(const char *hostname, const U16 port)
Configures the Udp receive settings but does not open the connection.
Definition: UdpComponentImpl.cpp:39
Fw::Buffer::getData
U8 * getData() const
Definition: Buffer.cpp:56
Drv::IpSocket
Helper base-class for setting up Berkley sockets.
Definition: IpSocket.hpp:45
Drv
Definition: BlockDriverImpl.cpp:5
IpCfg.hpp
Drv::UdpComponentImpl::sendBuffer
void sendBuffer(Fw::Buffer buffer, SocketIpStatus status)
sends a buffer to filled with data
Definition: UdpComponentImpl.cpp:57
Fw::Buffer
Definition: Buffer.hpp:43
UdpComponentImpl.hpp
Fw::Buffer::getSize
U32 getSize() const
Definition: Buffer.cpp:60
Drv::SocketReadTask
supports a task to read a given socket adaptation
Definition: SocketReadTask.hpp:27
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
FW_ASSERT
#define FW_ASSERT(...)
Definition: Assert.hpp:9
Drv::UdpSocket::configureSend
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds, const U32 send_timeout_microseconds)
configure the udp socket for outgoing transmissions
Definition: UdpSocket.cpp:59
Drv::UdpComponentImpl::init
void init(const NATIVE_INT_TYPE instance=0)
Initialize this component.
Definition: UdpComponentImpl.cpp:28
Drv::SocketIpStatus
SocketIpStatus
Status enumeration for socket return values.
Definition: IpSocket.hpp:23
Drv::UdpComponentImpl::UdpComponentImpl
UdpComponentImpl(const char *const compName)
construct the TcpClient component.
Definition: UdpComponentImpl.cpp:24
BasicTypes.hpp
Declares ISF basic types.
Drv::SOCK_DISCONNECTED
@ SOCK_DISCONNECTED
Failed to read socket with disconnect.
Definition: IpSocket.hpp:32
Drv::UdpSocket::configureRecv
SocketIpStatus configureRecv(const char *hostname, const U16 port)
configure the udp socket for incoming transmissions
Definition: UdpSocket.cpp:64
NATIVE_INT_TYPE
int NATIVE_INT_TYPE
native integer type declaration
Definition: BasicTypes.hpp:29
Drv::UdpComponentImpl::configureSend
SocketIpStatus configureSend(const char *hostname, const U16 port, const U32 send_timeout_seconds=SOCKET_SEND_TIMEOUT_SECONDS, const U32 send_timeout_microseconds=SOCKET_SEND_TIMEOUT_MICROSECONDS)
Configures the Udp send settings but does not open the connection.
Definition: UdpComponentImpl.cpp:32
Drv::UdpComponentImpl::poll_handler
Drv::PollStatus poll_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer &fwBuffer)
not supported
Definition: UdpComponentImpl.cpp:77
Drv::UdpComponentImpl::getBuffer
Fw::Buffer getBuffer()
returns a buffer to fill with data
Definition: UdpComponentImpl.cpp:53