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 
23  // To use the class, instantiate an instance of the BufferBins struct below. This
24  // table specifies N buffers of M size per bin. Up to MAX_NUM_BINS bins can be specified.
25  // The table is copied when setup() is called, so it does not need to be retained after
26  // the call.
27  //
28  // The rules for specifying bins:
29  // 1. For each bin (BufferBins.bins[n]), specify the size of the buffers (bufferSize) in the
30  // bin and how many buffers for that bin (numBuffers).
31  // 2. The bins should be ordered based on an increasing bufferSize to allow BufferManager to
32  // search for available buffers. When receiving a request for a buffer, the component will
33  // search for the first buffer from the bins that is equal to or greater
34  // than the requested size, starting at the beginning of the table.
35  // 3. Any unused bins should have numBuffers set to 0.
36  // 4. A single bin can be specified if a single size is needed.
37  //
38  // If a buffer is requested that can't be found among available buffers, the call will
39  // return an Fw::Buffer with a size of zero. It is expected that the user will notice
40  // and have the appropriate response for the design. If an empty buffer is returned to
41  // the BufferManager instance, a warning event will be issued but no other action will
42  // be taken.
43  //
44  // Buffer manager will assert under the following conditions:
45  // 1. A returned buffer has the incorrect manager ID.
46  // 2. A returned buffer has an incorrect buffer ID.
47  // 3. A returned buffer is returned with a correct buffer ID, but it isn't already allocated.
48  // 4. A returned buffer has an indicated size larger than originally allocated.
49  // 5. A returned buffer has a pointer different than the one originally allocated.
50  //
51  // Note that a pointer to the Fw::MemAllocator used in setup() is stored for later memory cleanup.
52  // The instance of the allocator must persist beyond calling the cleanup() function or the
53  // destructor of BufferManager if cleanup() is not called. If a project-specific manual memory
54  // allocator is not needed, Fw::MallocAllocator can be used.
55 
57  {
58 
59  friend class BufferManagerTester;
60 
61  public:
62 
63  // ----------------------------------------------------------------------
64  // Construction, initialization, and destruction
65  // ----------------------------------------------------------------------
66 
70  const char *const compName
71  );
72 
73  // Defines a buffer bin
74  struct BufferBin
75  {
77  U16 numBuffers;
78  };
79 
80  // Set of bins for the BufferManager
81  struct BufferBins
82  {
84  };
85 
87 
88  void setup(
89  U16 mgrID,
90  FwEnumStoreType memID,
91  Fw::MemAllocator &allocator,
92  const BufferBins &bins
94  );
95 
96  void cleanup(); // Free memory prior to end of program if desired. Otherwise,
97  // will be deleted in destructor
98 
102 
103  private :
104 
105  // ----------------------------------------------------------------------
106  // Handler implementations for user-defined typed input ports
107  // ----------------------------------------------------------------------
108 
111  void
112  bufferSendIn_handler(
113  const FwIndexType portNum,
114  Fw::Buffer &fwBuffer);
115 
118  Fw::Buffer bufferGetCallee_handler(
119  const FwIndexType portNum,
120  Fw::Buffer::SizeType size);
121 
124  void schedIn_handler(
125  const FwIndexType portNum,
126  U32 context
127  );
128 
129 
130  bool m_setup;
131  bool m_cleaned;
132  U16 m_mgrId;
133 
134  BufferBins m_bufferBins;
135 
136  struct AllocatedBuffer
137  {
138  Fw::Buffer buff;
139  U8 *memory;
140  Fw::Buffer::SizeType size;
141  bool allocated;
142  };
143 
144  AllocatedBuffer *m_buffers;
145  Fw::MemAllocator *m_allocator;
146  FwEnumStoreType m_memId;
147  U16 m_numStructs;
148 
149  // stats
150  U32 m_highWater;
151  U32 m_currBuffs;
152  U32 m_noBuffs;
153  U32 m_emptyBuffs;
154  };
155 
156 } // end namespace Svc
157 
158 #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:56
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.