F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BufferRepeater.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferRepeater.cpp
3 // \author lestarch
4 // \brief cpp file for GenericRepeater component implementation class
5 //
6 // \copyright
7 // Copyright 2009-2015, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // ======================================================================
12 
13 #include <Fw/FPrimeBasicTypes.hpp>
15 
16 namespace Svc {
17 
18 // ----------------------------------------------------------------------
19 // Construction, initialization, and destruction
20 // ----------------------------------------------------------------------
21 
22 BufferRepeater ::BufferRepeater(const char* const compName)
23  : BufferRepeaterComponentBase(compName),
24  m_allocation_failure_response(BufferRepeater::NUM_BUFFER_REPEATER_FAILURE_OPTIONS) {}
25 
27 
29  this->m_allocation_failure_response = allocation_failure_response;
30 }
31 
32 bool BufferRepeater ::check_allocation(FwIndexType index,
33  const Fw::Buffer& new_allocation,
34  const Fw::Buffer& incoming_buffer) {
35  FW_ASSERT(index < NUM_PORTOUT_OUTPUT_PORTS, static_cast<FwAssertArgType>(index));
36  bool is_valid = (new_allocation.getData() != nullptr) && (new_allocation.getSize() >= incoming_buffer.getSize());
37 
38  // Respond to invalid buffer allocation
39  if (!is_valid) {
40  switch (this->m_allocation_failure_response) {
42  // No response intended
43  break;
45  this->log_WARNING_HI_AllocationSoftFailure(index, incoming_buffer.getSize());
46  break;
48  this->log_FATAL_AllocationHardFailure(index, incoming_buffer.getSize());
49  break;
50  default:
51  FW_ASSERT(0);
52  break;
53  }
54  }
55  return is_valid;
56 }
57 
58 // ----------------------------------------------------------------------
59 // Handler implementations for user-defined serial input ports
60 // ----------------------------------------------------------------------
61 
62 void BufferRepeater ::portIn_handler(FwIndexType portNum,
63  Fw::Buffer& buffer
64 ) {
65  FW_ASSERT(this->m_allocation_failure_response < NUM_BUFFER_REPEATER_FAILURE_OPTIONS);
66  for (FwIndexType i = 0; i < NUM_PORTOUT_OUTPUT_PORTS; i++) {
68  Fw::Buffer new_allocation = this->allocate_out(0, buffer.getSize());
69  if (this->check_allocation(i, new_allocation, buffer)) {
70  // Clone the data and send it
71  FW_ASSERT_NO_OVERFLOW(buffer.getSize(), size_t);
72  ::memcpy(new_allocation.getData(), buffer.getData(), static_cast<size_t>(buffer.getSize()));
73  new_allocation.setSize(buffer.getSize());
74  this->portOut_out(i, new_allocation);
75  }
76  }
77  }
78  this->deallocate_out(0, buffer);
79 }
80 } // end namespace Svc
void setSize(FwSizeType size)
Definition: Buffer.cpp:75
U8 * getData() const
Definition: Buffer.cpp:56
void portOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port portOut.
void log_WARNING_HI_AllocationSoftFailure(I32 port, FwSizeType size) const
BufferRepeater(const char *const compName)
bool isConnected_portOut_OutputPort(FwIndexType portNum)
FwSizeType getSize() const
Definition: Buffer.cpp:60
void log_FATAL_AllocationHardFailure(I32 port, FwSizeType size) const
PlatformIndexType FwIndexType
#define FW_ASSERT_NO_OVERFLOW(value, T)
Definition: Assert.hpp:49
void configure(BufferRepeaterFailureOption allocation_failure_response)
RateGroupDivider component implementation.
Auto-generated base for BufferRepeater component.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Fw::Buffer allocate_out(FwIndexType portNum, FwSizeType size)
Invoke output port allocate.
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.