GCC Code Coverage Report


Directory: ./
File: Drv/TcpClient/TcpClientComponentImpl.cpp
Date: 2026-09-03 21:13:48
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 10 taken 7 times.
✓ Branch 21 taken 7 times.
7 TcpClientComponentImpl::TcpClientComponentImpl(const char* const compName) : TcpClientComponentBase(compName) {}
25
26 6 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 6 m_allocation_size = buffer_size; // Store the buffer size
32 6 return m_socket.configure(ipv4_address, port, send_timeout_seconds, send_timeout_microseconds);
33 }
34
35 14 TcpClientComponentImpl::~TcpClientComponentImpl() {}
36
37 // ----------------------------------------------------------------------
38 // Implementations for socket read task virtual methods
39 // ----------------------------------------------------------------------
40
41 612 IpSocket& TcpClientComponentImpl::getSocketHandler() {
42 612 return m_socket;
43 }
44
45 20 Fw::Buffer TcpClientComponentImpl::getBuffer() {
46 20 return allocate_out(0, m_allocation_size);
47 }
48
49 20 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 20 FW_ASSERT((status != SOCK_SUCCESS) || (buffer.getData() != nullptr));
52
1/1
✓ Branch 2 taken 20 times.
20 Drv::ByteStreamStatus recvStatus = ByteStreamStatus::OTHER_ERROR;
53
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9 times.
20 if (status == SOCK_SUCCESS) {
54
1/1
✓ Branch 2 taken 11 times.
11 recvStatus = ByteStreamStatus::OP_OK;
55
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
9 } else if (status == SOCK_NO_DATA_AVAILABLE) {
56 recvStatus = ByteStreamStatus::RECV_NO_DATA;
57 } else {
58
1/1
✓ Branch 2 taken 9 times.
9 recvStatus = ByteStreamStatus::OTHER_ERROR;
59 }
60
1/1
✓ Branch 5 taken 20 times.
20 this->recv_out(0, buffer, recvStatus);
61 40 }
62
63 112 void TcpClientComponentImpl::connected() {
64
1/2
✓ Branch 5 taken 112 times.
✗ Branch 6 not taken.
112 if (isConnected_ready_OutputPort(0)) {
65 112 this->ready_out(0);
66 }
67 112 }
68
69 // ----------------------------------------------------------------------
70 // Handler implementations for user-defined typed input ports
71 // ----------------------------------------------------------------------
72
73 112 Drv::ByteStreamStatus TcpClientComponentImpl::send_handler(const FwIndexType portNum, Fw::Buffer& fwBuffer) {
74 112 Drv::SocketIpStatus status = send(fwBuffer.getData(), fwBuffer.getSize());
75 112 Drv::ByteStreamStatus returnStatus;
76
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 112 times.
✗ Branch 2 not taken.
112 switch (status) {
77 case SOCK_INTERRUPTED_TRY_AGAIN:
78 returnStatus = ByteStreamStatus::SEND_RETRY;
79 break;
80 112 case SOCK_SUCCESS:
81
1/1
✓ Branch 3 taken 112 times.
112 returnStatus = ByteStreamStatus::OP_OK;
82 112 break;
83 default:
84 returnStatus = ByteStreamStatus::OTHER_ERROR;
85 break;
86 }
87 112 return returnStatus;
88 }
89
90 1 void TcpClientComponentImpl::recvReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
91 1 this->deallocate_out(0, fwBuffer);
92 1 }
93
94 } // end namespace Drv
95