GCC Code Coverage Report


Directory: /home/runner/work/fprime/fprime/Svc/ComRetry/
File: ComRetry.cpp
Date: 2026-09-03 22:13:34
Exec Total Coverage
Lines: 0 50 0.0%
Functions: 0 6 0.0%
Branches: 0 22 0.0%

Line Branch Exec Source
1 // ======================================================================
2 // \title ComRetry.cpp
3 // \author valdaarhun
4 // \brief cpp file for ComRetry component implementation class
5 // ======================================================================
6
7 #include "Svc/ComRetry/ComRetry.hpp"
8 #include "ComRetry.hpp"
9
10 namespace Svc {
11
12 // ----------------------------------------------------------------------
13 // Component construction and destruction
14 // ----------------------------------------------------------------------
15
16 ComRetry ::ComRetry(const char* const compName)
17 : ComRetryComponentBase(compName),
18 m_num_retries(3),
19 m_retry_count(0),
20 m_retry_state(WAITING_FOR_SEND),
21 m_bufferState(Fw::Buffer::OwnershipState::OWNED) {}
22
23 ComRetry ::~ComRetry() {}
24
25 void ComRetry::configure(U32 num_retries) {
26 this->m_num_retries = num_retries;
27 }
28
29 // ----------------------------------------------------------------------
30 // Handler implementations for typed input ports
31 // ----------------------------------------------------------------------
32
33 void ComRetry ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
34 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
35
36 // When waiting for send, just pass the status up the stack as the buffer should still be upstream
37 if (this->m_retry_state == WAITING_FOR_SEND) {
38 FW_ASSERT(!this->m_buffer.isValid());
39 this->comStatusOut_out(0, condition);
40 }
41 // Nominal case where delivery of buffer is successful, and everything is passed back up the stack
42 else if ((this->m_retry_state == WAITING_FOR_STATUS) && (condition == Fw::Success::SUCCESS)) {
43 FW_ASSERT(this->m_buffer.isValid());
44 this->m_retry_state = WAITING_FOR_SEND; // Successful transmission, reset state
45 this->dataReturnOut_out(0, this->m_buffer, this->m_context);
46 this->m_buffer = Fw::Buffer(); // Clear buffer
47 this->comStatusOut_out(0, condition);
48 }
49 // When retrying, and "success" is received, this is the retry case
50 else if ((this->m_retry_state == RETRYING) && (condition == Fw::Success::SUCCESS)) {
51 FW_ASSERT(this->m_buffer.isValid());
52 this->m_retry_count++;
53 this->m_retry_state = WAITING_FOR_STATUS;
54 this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
55 this->dataOut_out(0, this->m_buffer, this->m_context);
56 } else {
57 // When a failure has been seen, it can **only** be in WAITING_FOR_STATUS state
58 FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
59 FW_ASSERT(condition == Fw::Success::FAILURE);
60
61 // If we have retries left then switch to RETRYING, and wait for success
62 if (this->m_retry_count < this->m_num_retries) {
63 this->m_retry_state = RETRYING;
64 }
65 // If no retries left, pass failure back up the stack and reset state
66 else {
67 this->m_retry_state = WAITING_FOR_SEND;
68 this->dataReturnOut_out(0, this->m_buffer, this->m_context);
69 this->m_buffer = Fw::Buffer(); // Clear buffer
70 this->comStatusOut_out(0, condition);
71 }
72 }
73 }
74
75 void ComRetry ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
76 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED);
77 FW_ASSERT(this->m_retry_state == WAITING_FOR_SEND);
78 this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
79 this->m_retry_state = WAITING_FOR_STATUS;
80 this->m_retry_count = 0;
81 this->dataOut_out(0, buffer, context);
82 }
83
84 void ComRetry ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) {
85 FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
86 FW_ASSERT(this->m_retry_state == WAITING_FOR_STATUS);
87 this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
88 this->m_buffer = buffer;
89 this->m_context = context;
90 }
91
92 } // namespace Svc
93