F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
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
19
20namespace 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 public:
60
61 // ----------------------------------------------------------------------
62 // Construction, initialization, and destruction
63 // ----------------------------------------------------------------------
64
68 const char *const compName
69 );
70
71 // Defines a buffer bin
77
78 // Set of bins for the BufferManager
83
85
86 void setup(
87 NATIVE_UINT_TYPE mgrID,
88 NATIVE_UINT_TYPE memID,
89 Fw::MemAllocator &allocator,
91 const BufferBins &bins
92 );
93
94 void cleanup(); // Free memory prior to end of program if desired. Otherwise,
95 // will be deleted in destructor
96
100
101 PRIVATE :
102
103 // ----------------------------------------------------------------------
104 // Handler implementations for user-defined typed input ports
105 // ----------------------------------------------------------------------
106
109 void
110 bufferSendIn_handler(
111 const NATIVE_INT_TYPE portNum,
112 Fw::Buffer &fwBuffer);
113
116 Fw::Buffer bufferGetCallee_handler(
117 const NATIVE_INT_TYPE portNum,
118 U32 size);
119
122 void schedIn_handler(
123 const NATIVE_INT_TYPE portNum,
124 U32 context
125 );
126
127
128 bool m_setup;
129 bool m_cleaned;
130 NATIVE_UINT_TYPE m_mgrId;
131
132 BufferBins m_bufferBins;
133
134 struct AllocatedBuffer
135 {
136 Fw::Buffer buff;
137 U8 *memory;
138 U32 size;
139 bool allocated;
140 };
141
142 AllocatedBuffer *m_buffers;
143 Fw::MemAllocator *m_allocator;
144 NATIVE_UINT_TYPE m_memId;
145 NATIVE_UINT_TYPE m_numStructs;
146
147 // stats
148 U32 m_highWater;
149 U32 m_currBuffs;
150 U32 m_noBuffs;
151 U32 m_emptyBuffs;
152 };
153
154} // end namespace Svc
155
156#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:55
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:30
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:56
Defines a base class for a memory allocator for classes.
Auto-generated base for BufferManager component.
void setup(NATIVE_UINT_TYPE mgrID, NATIVE_UINT_TYPE memID, Fw::MemAllocator &allocator, const BufferBins &bins)
set up configuration
static const NATIVE_UINT_TYPE BUFFERMGR_MAX_NUM_BINS
NATIVE_UINT_TYPE numBuffers
number of buffers in this bin. Set to zero for unused bins.
NATIVE_UINT_TYPE bufferSize
size of the buffers in this bin. Set to zero for unused bins.
BufferBin bins[BUFFERMGR_MAX_NUM_BINS]
set of bins to define buffers