F´ Flight Software - C/C++ Documentation devel
A framework for building embedded system applications to NASA flight quality standards.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
73 void init(
74 const NATIVE_INT_TYPE instance = 0
75 );
76
77 // Defines a buffer bin
83
84 // Set of bins for the BufferManager
89
91
92 void setup(
93 NATIVE_UINT_TYPE mgrID,
94 NATIVE_UINT_TYPE memID,
95 Fw::MemAllocator &allocator,
97 const BufferBins &bins
98 );
99
100 void cleanup(); // Free memory prior to end of program if desired. Otherwise,
101 // will be deleted in destructor
102
106
107 PRIVATE :
108
109 // ----------------------------------------------------------------------
110 // Handler implementations for user-defined typed input ports
111 // ----------------------------------------------------------------------
112
115 void
116 bufferSendIn_handler(
117 const NATIVE_INT_TYPE portNum,
118 Fw::Buffer &fwBuffer);
119
122 Fw::Buffer bufferGetCallee_handler(
123 const NATIVE_INT_TYPE portNum,
124 U32 size);
125
128 void schedIn_handler(
129 const NATIVE_INT_TYPE portNum,
130 NATIVE_UINT_TYPE context
131 );
132
133
134 bool m_setup;
135 bool m_cleaned;
136 NATIVE_UINT_TYPE m_mgrId;
137
138 BufferBins m_bufferBins;
139
140 struct AllocatedBuffer
141 {
142 Fw::Buffer buff;
143 U8 *memory;
144 U32 size;
145 bool allocated;
146 };
147
148 AllocatedBuffer *m_buffers;
149 Fw::MemAllocator *m_allocator;
150 NATIVE_UINT_TYPE m_memId;
151 NATIVE_UINT_TYPE m_numStructs;
152
153 // stats
154 U32 m_highWater;
155 U32 m_currBuffs;
156 U32 m_noBuffs;
157 U32 m_emptyBuffs;
158 };
159
160} // end namespace Svc
161
162#endif
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
PlatformUIntType NATIVE_UINT_TYPE
Definition BasicTypes.h:52
Defines a base class for a memory allocator for classes.
void init()
Object initializer.
Definition ObjBase.cpp:27
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
BufferManagerComponentImpl(const char *const compName)
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