GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Drv/TcpClient/
File: TcpClientComponentImpl.cpp
Date: 2026-09-23 22:11:55
Exec Total Coverage
Lines: 33 41 80.5%
Functions: 9 9 100.0%
Branches: 12 19 63.2%

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 875 IpSocket& TcpClientComponentImpl::getSocketHandler() {
42 875 return m_socket;
43 }
44
45 630 Fw::Buffer TcpClientComponentImpl::getBuffer() {
46 630 return allocate_out(0, m_allocation_size);
47 }
48
49 630 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 630 FW_ASSERT((status != SOCK_SUCCESS) || (buffer.getData() != nullptr));
52
1/1
✓ Branch 1 taken 630 times.
630 Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR;
53
2/2
✓ Branch 0 taken 629 times.
✓ Branch 1 taken 1 times.
630 if (status == SOCK_SUCCESS) {
54
1/1
✓ Branch 1 taken 629 times.
629 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 630 times.
630 this->recv_out(0, buffer, recvStatus);
61 630 }
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 239 Drv::ByteStreamStatus TcpClientComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
74 239 Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
75 239 Drv::ByteStreamStatus returnStatus;
76
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 239 times.
✗ Branch 2 not taken.
239 switch (status) {
77 ✗ case SOCK_INTERRUPTED_TRY_AGAIN:
78 ✗ returnStatus = ByteStreamStatus::SEND_RETRY;
79 ✗ break;
80 239 case SOCK_SUCCESS:
81
1/1
✓ Branch 1 taken 239 times.
239 returnStatus = ByteStreamStatus::OP_OK;
82 239 break;
83 ✗ default:
84 ✗ returnStatus = ByteStreamStatus::OTHER_ERROR;
85 ✗ break;
86 }
87 239 return returnStatus;
88 ✗ }
89
90 630 void TcpClientComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
91 630 this->deallocate_out(0, fwBuffer);
92 630 }
93
94 } // end namespace Drv
95