F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
BufferManagerComponentImpl.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title BufferManagerComponentImpl.hpp
3 // \author tcanham
4 // \brief hpp file for BufferManager 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 #ifndef BufferManager_HPP
14 #define BufferManager_HPP
15 
18 #include "config/BufferManagerComponentImplCfg.hpp"
19 
20 namespace Svc {
21 
22 // To use the class, instantiate an instance of the BufferBins struct below. This
23 // table specifies N buffers of M size per bin. Up to MAX_NUM_BINS bins can be specified.
24 // The table is copied when setup() is called, so it does not need to be retained after
25 // the call.
26 //
27 // The rules for specifying bins:
28 // 1. For each bin (BufferBins.bins[n]), specify the size of the buffers (bufferSize) in the
29 // bin and how many buffers for that bin (numBuffers).
30 // 2. The bins should be ordered based on an increasing bufferSize to allow BufferManager to
31 // search for available buffers. When receiving a request for a buffer, the component will
32 // search for the first buffer from the bins that is equal to or greater
33 // than the requested size, starting at the beginning of the table.
34 // 3. Any unused bins should have numBuffers set to 0.
35 // 4. A single bin can be specified if a single size is needed.
36 //
37 // If a buffer is requested that can't be found among available buffers, the call will
38 // return an Fw::Buffer with a size of zero. It is expected that the user will notice
39 // and have the appropriate response for the design. If an empty buffer is returned to
40 // the BufferManager instance, a warning event will be issued but no other action will
41 // be taken.
42 //
43 // Buffer manager will assert under the following conditions:
44 // 1. A returned buffer has the incorrect manager ID.
45 // 2. A returned buffer has an incorrect buffer ID.
46 // 3. A returned buffer is returned with a correct buffer ID, but it isn't already allocated.
47 // 4. A returned buffer has an indicated size larger than originally allocated.
48 // 5. A returned buffer has a pointer different than the one originally allocated.
49 //
50 // Note that a pointer to the Fw::MemAllocator used in setup() is stored for later memory cleanup.
51 // The instance of the allocator must persist beyond calling the cleanup() function or the
52 // destructor of BufferManager if cleanup() is not called. If a project-specific manual memory
53 // allocator is not needed, Fw::MallocAllocator can be used.
54 
56  friend class BufferManagerTester;
57 
58  public:
59  // ----------------------------------------------------------------------
60  // Construction, initialization, and destruction
61  // ----------------------------------------------------------------------
62 
65  BufferManagerComponentImpl(const char* const compName
66  );
67 
68  // Defines a buffer bin
69  struct BufferBin {
71  U16 numBuffers;
72  };
73 
74  // Set of bins for the BufferManager
75  struct BufferBins {
77  };
78 
80 
81  void setup(U16 mgrID,
82  FwEnumStoreType memID,
83  Fw::MemAllocator& allocator,
84  const BufferBins& bins
86  );
87 
88  void cleanup(); // Free memory prior to end of program if desired. Otherwise,
89  // will be deleted in destructor
90 
94 
95  private:
96  // ----------------------------------------------------------------------
97  // Handler implementations for user-defined typed input ports
98  // ----------------------------------------------------------------------
99 
102  void bufferSendIn_handler(const FwIndexType portNum,
103  Fw::Buffer& fwBuffer);
104 
107  Fw::Buffer bufferGetCallee_handler(const FwIndexType portNum,
108  Fw::Buffer::SizeType size);
109 
112  void schedIn_handler(const FwIndexType portNum,
113  U32 context
114  );
115 
116  bool m_setup;
117  bool m_cleaned;
118  U16 m_mgrId;
119 
120  BufferBins m_bufferBins;
121 
122  struct AllocatedBuffer {
123  Fw::Buffer buff;
124  U8* memory;
125  Fw::Buffer::SizeType size;
126  bool allocated;
127  };
128 
129  AllocatedBuffer* m_buffers;
130  Fw::MemAllocator* m_allocator;
131  FwEnumStoreType m_memId;
132  U16 m_numStructs;
133 
134  // stats
135  U32 m_highWater;
136  U32 m_currBuffs;
137  U32 m_noBuffs;
138  U32 m_emptyBuffs;
139 };
140 
141 } // end namespace Svc
142 
143 #endif
BufferBin bins[BUFFERMGR_MAX_NUM_BINS]
set of bins to define buffers
I32 FwEnumStoreType
Fw::Buffer::SizeType bufferSize
size of the buffers in this bin. Set to zero for unused bins.
static const U16 BUFFERMGR_MAX_NUM_BINS
BufferManagerComponentImpl(const char *const compName)
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:53
void setup(U16 mgrID, FwEnumStoreType memID, Fw::MemAllocator &allocator, const BufferBins &bins)
set up configuration
PlatformIndexType FwIndexType
FwSizeType SizeType
The size type for a buffer - for backwards compatibility.
Definition: Buffer.hpp:52
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.
Auto-generated base for BufferManager component.
U16 numBuffers
number of buffers in this bin. Set to zero for unused bins.