F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
DpManager.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title DpManager.cpp
3 // \author bocchino
4 // \brief cpp file for DpManager component implementation class
5 // ======================================================================
6 
7 #include "FpConfig.hpp"
9 
10 namespace Svc {
11 
12 // ----------------------------------------------------------------------
13 // Construction, initialization, and destruction
14 // ----------------------------------------------------------------------
15 
16 DpManager::DpManager(const char* const compName)
17  : DpManagerComponentBase(compName),
18  numSuccessfulAllocations(0),
19  numFailedAllocations(0),
20  numDataProducts(0),
21  numBytes(0) {}
22 
24 
25 // ----------------------------------------------------------------------
26 // Handler implementations for user-defined typed input ports
27 // ----------------------------------------------------------------------
28 
29 Fw::Success DpManager::productGetIn_handler(const NATIVE_INT_TYPE portNum,
30  FwDpIdType id,
31  FwSizeType size,
32  Fw::Buffer& buffer) {
33  return this->getBuffer(portNum, id, size, buffer);
34 }
35 
36 void DpManager::productRequestIn_handler(const NATIVE_INT_TYPE portNum, FwDpIdType id, FwSizeType size) {
37  // Get a buffer
38  Fw::Buffer buffer;
39  const Fw::Success status = this->getBuffer(portNum, id, size, buffer);
40  // Send buffer on productResponseOut
41  this->productResponseOut_out(portNum, id, buffer, status);
42 }
43 
44 void DpManager::productSendIn_handler(const NATIVE_INT_TYPE portNum, FwDpIdType id, const Fw::Buffer& buffer) {
45  // id is unused
46  (void)id;
47  // Update state variables
48  ++this->numDataProducts;
49  this->numBytes += buffer.getSize();
50  // Send the buffer on productSendOut
51  Fw::Buffer sendBuffer = buffer;
52  this->productSendOut_out(portNum, sendBuffer);
53 }
54 
55 void DpManager::schedIn_handler(const NATIVE_INT_TYPE portNum, U32 context) {
56  // Emit telemetry
57  this->tlmWrite_NumSuccessfulAllocations(this->numSuccessfulAllocations);
58  this->tlmWrite_NumFailedAllocations(this->numFailedAllocations);
59  this->tlmWrite_NumDataProducts(this->numDataProducts);
60  this->tlmWrite_NumBytes(this->numBytes);
61 }
62 
63 // ----------------------------------------------------------------------
64 // Handler implementations for commands
65 // ----------------------------------------------------------------------
66 
67 void DpManager ::CLEAR_EVENT_THROTTLE_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
69  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
70 }
71 
72 // ----------------------------------------------------------------------
73 // Private helper functions
74 // ----------------------------------------------------------------------
75 
76 Fw::Success DpManager::getBuffer(FwIndexType portNum, FwDpIdType id, FwSizeType size, Fw::Buffer& buffer) {
77  // Set status
79  // Get a buffer
80  buffer = this->bufferGetOut_out(portNum, static_cast<U32>(size));
81  if (buffer.isValid()) {
82  // Buffer is valid
83  ++this->numSuccessfulAllocations;
84  status = Fw::Success::SUCCESS;
85  } else {
86  // Buffer is invalid
87  ++this->numFailedAllocations;
89  }
90  return status;
91 }
92 
93 } // end namespace Svc
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:51
U32 FwDpIdType
Definition: FpConfig.h:102
U32 FwOpcodeType
Definition: FpConfig.h:78
PlatformSizeType FwSizeType
Definition: FpConfig.h:30
PlatformIndexType FwIndexType
Definition: FpConfig.h:20
C++-compatible configuration header for fprime configuration.
bool isValid() const
Definition: Buffer.cpp:64
U32 getSize() const
Definition: Buffer.cpp:72
@ OK
Command successfully executed.
Success/Failure.
@ FAILURE
Representing failure.
@ SUCCESS
Representing success.
Auto-generated base for DpManager component.
void tlmWrite_NumDataProducts(U32 arg, Fw::Time _tlmTime=Fw::Time())
void log_WARNING_HI_BufferAllocationFailed_ThrottleClear()
Reset throttle value for BufferAllocationFailed.
void tlmWrite_NumSuccessfulAllocations(U32 arg, Fw::Time _tlmTime=Fw::Time())
void cmdResponse_out(FwOpcodeType opCode, U32 cmdSeq, Fw::CmdResponse response)
Emit command response.
void tlmWrite_NumBytes(U64 arg, Fw::Time _tlmTime=Fw::Time())
Fw::Buffer bufferGetOut_out(FwIndexType portNum, U32 size)
Invoke output port bufferGetOut.
void tlmWrite_NumFailedAllocations(U32 arg, Fw::Time _tlmTime=Fw::Time())
void productSendOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port productSendOut.
void productResponseOut_out(FwIndexType portNum, FwDpIdType id, const Fw::Buffer &buffer, const Fw::Success &status)
Invoke output port productResponseOut.
~DpManager()
Destroy the DpManager.
Definition: DpManager.cpp:23
DpManager(const char *const compName)
Construct a DpManager.
Definition: DpManager.cpp:16