| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title TcpClientComponentImpl.cpp | ||
| 3 | // \author mstarch | ||
| 4 | // \brief cpp file for TcpClientComponentImpl 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 | #include <Drv/TcpClient/TcpClientComponentImpl.hpp> | ||
| 14 | #include <Fw/FPrimeBasicTypes.hpp> | ||
| 15 | #include <limits> | ||
| 16 | #include "Fw/Types/Assert.hpp" | ||
| 17 | |||
| 18 | namespace Drv { | ||
| 19 | |||
| 20 | // ---------------------------------------------------------------------- | ||
| 21 | // Construction, initialization, and destruction | ||
| 22 | // ---------------------------------------------------------------------- | ||
| 23 | |||
| 24 |
2/2✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
|
1 | TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName) : TcpClientComponentBase(compName) {} |
| 25 | |||
| 26 | 1 | SocketIpStatus TcpClientComponentImpl::configure(const char* const ipv4_address, | |
| 27 | const U16 port, | ||
| 28 | const U32 send_timeout_seconds, | ||
| 29 | const U32 send_timeout_microseconds, | ||
| 30 | FwSizeType buffer_size) { | ||
| 31 | 1 | m_allocation_size = buffer_size; // Store the buffer size | |
| 32 | 1 | return m_socket.configure(ipv4_address, port, send_timeout_seconds, send_timeout_microseconds); | |
| 33 | } | ||
| 34 | |||
| 35 | 2 | TcpClientComponentImpl::~TcpClientComponentImpl() {} | |
| 36 | |||
| 37 | // ---------------------------------------------------------------------- | ||
| 38 | // Implementations for socket read task virtual methods | ||
| 39 | // ---------------------------------------------------------------------- | ||
| 40 | |||
| 41 | 850 | IpSocket& TcpClientComponentImpl::getSocketHandler() { | |
| 42 | 850 | return m_socket; | |
| 43 | } | ||
| 44 | |||
| 45 | 615 | Fw::Buffer TcpClientComponentImpl::getBuffer() { | |
| 46 | 615 | return allocate_out(0, m_allocation_size); | |
| 47 | } | ||
| 48 | |||
| 49 | 615 | void TcpClientComponentImpl::sendBuffer(Fw::Buffer buffer, SocketIpStatus status) { | |
| 50 | // A successful receive must have produced a buffer with backing data (size may be zero) | ||
| 51 | 615 | FW_ASSERT((status != SOCK_SUCCESS) || (buffer.getData() != nullptr)); | |
| 52 |
1/1✓ Branch 1 taken 615 times.
|
615 | Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR; |
| 53 |
2/2✓ Branch 0 taken 614 times.
✓ Branch 1 taken 1 times.
|
615 | if (status == SOCK_SUCCESS) { |
| 54 |
1/1✓ Branch 1 taken 614 times.
|
614 | recvStatus = ByteStreamStatus::OP_OK; |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | } else if (status == SOCK_NO_DATA_AVAILABLE) { |
| 56 | ✗ | recvStatus = ByteStreamStatus::RECV_NO_DATA; | |
| 57 | } else { | ||
| 58 |
1/1✓ Branch 1 taken 1 times.
|
1 | recvStatus = ByteStreamStatus::OTHER_ERROR; |
| 59 | } | ||
| 60 |
1/1✓ Branch 1 taken 615 times.
|
615 | this->recv_out(0, buffer, recvStatus); |
| 61 | 615 | } | |
| 62 | |||
| 63 | 1 | void TcpClientComponentImpl::connected() { | |
| 64 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | if (isConnected_ready_OutputPort(0)) { |
| 65 | 1 | this->ready_out(0); | |
| 66 | } | ||
| 67 | 1 | } | |
| 68 | |||
| 69 | // ---------------------------------------------------------------------- | ||
| 70 | // Handler implementations for user-defined typed input ports | ||
| 71 | // ---------------------------------------------------------------------- | ||
| 72 | |||
| 73 | 229 | Drv::ByteStreamStatus TcpClientComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) { | |
| 74 | 229 | Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize()); | |
| 75 | 229 | Drv::ByteStreamStatus returnStatus; | |
| 76 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 229 times.
✗ Branch 2 not taken.
|
229 | switch (status) { |
| 77 | ✗ | case SOCK_INTERRUPTED_TRY_AGAIN: | |
| 78 | ✗ | returnStatus = ByteStreamStatus::SEND_RETRY; | |
| 79 | ✗ | break; | |
| 80 | 229 | case SOCK_SUCCESS: | |
| 81 |
1/1✓ Branch 1 taken 229 times.
|
229 | returnStatus = ByteStreamStatus::OP_OK; |
| 82 | 229 | break; | |
| 83 | ✗ | default: | |
| 84 | ✗ | returnStatus = ByteStreamStatus::OTHER_ERROR; | |
| 85 | ✗ | break; | |
| 86 | } | ||
| 87 | 229 | return returnStatus; | |
| 88 | ✗ | } | |
| 89 | |||
| 90 | 615 | void TcpClientComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) { | |
| 91 | 615 | this->deallocate_out(0, fwBuffer); | |
| 92 | 615 | } | |
| 93 | |||
| 94 | } // end namespace Drv | ||
| 95 |