|
| 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(1), |
| 19 | + m_retry_count(0), |
| 20 | + m_bufferState(OWNED) {} |
| 21 | + |
| 22 | +ComRetry ::~ComRetry() {} |
| 23 | + |
| 24 | +void ComRetry::configure(U32 num_retries) { |
| 25 | + this->m_num_retries = num_retries; |
| 26 | +} |
| 27 | + |
| 28 | +// ---------------------------------------------------------------------- |
| 29 | +// Handler implementations for typed input ports |
| 30 | +// ---------------------------------------------------------------------- |
| 31 | + |
| 32 | +void ComRetry ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) { |
| 33 | + // TODO: Check if m_buffer is valid before attempting delivery |
| 34 | + if (condition == Fw::Success::SUCCESS) { |
| 35 | + this->dataReturnOut_out(0, this->m_buffer, this->m_context); |
| 36 | + this->comStatusOut_out(0, condition); |
| 37 | + } |
| 38 | + // Delivery of last message failed |
| 39 | + else if (this->m_retry_count < this->m_num_retries) { |
| 40 | + FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED); |
| 41 | + this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED; |
| 42 | + this->m_retry_count++; |
| 43 | + this->dataOut_out(0, this->m_buffer, this->m_context); |
| 44 | + } |
| 45 | + // All retries failed, send FAILURE to upstream component |
| 46 | + else { |
| 47 | + this->dataReturnOut_out(0, this->m_buffer, this->m_context); |
| 48 | + this->m_retry_count = 0; |
| 49 | + Fw::Success condition = Fw::Success::FAILURE; |
| 50 | + this->comStatusOut_out(0, condition); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +void ComRetry ::dataIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) { |
| 55 | + FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED); |
| 56 | + this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED; |
| 57 | + this->dataOut_out(0, buffer, context); |
| 58 | +} |
| 59 | + |
| 60 | +void ComRetry ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& buffer, const ComCfg::FrameContext& context) { |
| 61 | + FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED); |
| 62 | + this->m_bufferState = Fw::Buffer::OwnershipState::OWNED; |
| 63 | + this->m_buffer = buffer; |
| 64 | + this->m_context = context; |
| 65 | +} |
| 66 | + |
| 67 | +} // namespace Svc |
0 commit comments