F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
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 <FpConfig.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 
26 void BufferRepeater ::init(const NATIVE_INT_TYPE instance) {
28 }
29 
31 
33  this->m_allocation_failure_response = allocation_failure_response;
34 }
35 
36 bool BufferRepeater ::check_allocation(FwIndexType index,
37  const Fw::Buffer& new_allocation,
38  const Fw::Buffer& incoming_buffer) {
39  FW_ASSERT(index < NUM_PORTOUT_OUTPUT_PORTS, index);
40  bool is_valid = (new_allocation.getData() != nullptr) && (new_allocation.getSize() >= incoming_buffer.getSize());
41 
42  // Respond to invalid buffer allocation
43  if (!is_valid) {
44  switch (this->m_allocation_failure_response) {
46  // No response intended
47  break;
49  this->log_WARNING_HI_AllocationSoftFailure(index, incoming_buffer.getSize());
50  break;
52  this->log_FATAL_AllocationHardFailure(index, incoming_buffer.getSize());
53  break;
54  default:
55  FW_ASSERT(0);
56  break;
57  }
58  }
59  return is_valid;
60 }
61 
62 // ----------------------------------------------------------------------
63 // Handler implementations for user-defined serial input ports
64 // ----------------------------------------------------------------------
65 
66 void BufferRepeater ::portIn_handler(NATIVE_INT_TYPE portNum,
67  Fw::Buffer& buffer
68 ) {
69  FW_ASSERT(this->m_allocation_failure_response < NUM_BUFFER_REPEATER_FAILURE_OPTIONS);
70  for (FwIndexType i = 0; i < NUM_PORTOUT_OUTPUT_PORTS; i++) {
72  Fw::Buffer new_allocation = this->allocate_out(0, buffer.getSize());
73  if (this->check_allocation(i, new_allocation, buffer)) {
74  // Clone the data and send it
75  ::memcpy(new_allocation.getData(), buffer.getData(), buffer.getSize());
76  new_allocation.setSize(buffer.getSize());
77  this->portOut_out(i, new_allocation);
78  }
79  }
80  }
81  this->deallocate_out(0, buffer);
82 }
83 } // end namespace Svc
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
PlatformIndexType FwIndexType
Definition: FpConfig.h:20
C++-compatible configuration header for fprime configuration.
U8 * getData() const
Definition: Buffer.cpp:68
U32 getSize() const
Definition: Buffer.cpp:72
void setSize(U32 size)
Definition: Buffer.cpp:87
void init()
Object initializer.
Definition: ObjBase.cpp:27
Auto-generated base for BufferRepeater component.
void log_WARNING_HI_AllocationSoftFailure(I32 port, U32 size)
Fw::Buffer allocate_out(FwIndexType portNum, U32 size)
Invoke output port allocate.
bool isConnected_portOut_OutputPort(FwIndexType portNum)
void log_FATAL_AllocationHardFailure(I32 port, U32 size)
void deallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port deallocate.
void portOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port portOut.
void configure(BufferRepeaterFailureOption allocation_failure_response)
BufferRepeater(const char *const compName)