|
1 /* |
|
2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: WlanMemoryPool declaration |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 6 % |
|
20 */ |
|
21 |
|
22 #ifndef WLANMEMORYPOOL_H |
|
23 #define WLANMEMORYPOOL_H |
|
24 |
|
25 #include "wlanobject.h" |
|
26 |
|
27 #include "osaplatformhwchunk.h" |
|
28 #include "osalist.h" |
|
29 #include "osahandle.h" |
|
30 |
|
31 struct SMemHeader; |
|
32 |
|
33 /** |
|
34 * memory pool for managing memory |
|
35 * |
|
36 * |
|
37 * @lib wlanosa.lib |
|
38 * @since S60 v3.2 |
|
39 */ |
|
40 class WlanMemoryPool : public DBase, public WlanObject |
|
41 { |
|
42 |
|
43 typedef Handle<WlanPlatformHwChunk> HwChunkHandle; |
|
44 |
|
45 public: |
|
46 |
|
47 /** |
|
48 * ctor |
|
49 * NOTE: call IsValid() member from super class |
|
50 * to validate object after ctor |
|
51 * |
|
52 * @since S60 v3.2 |
|
53 * @param aUseCachedMemory ETrue if cached memory shall be used |
|
54 * EFalse otherwise |
|
55 * @param aAllocationUnit allocation unit size for interconnect memory in |
|
56 * bytes |
|
57 */ |
|
58 explicit WlanMemoryPool( TBool aUseCachedMemory, TInt aAllocationUnit ); |
|
59 |
|
60 /** |
|
61 * Destructor. |
|
62 * |
|
63 * @since S60 v3.2 |
|
64 */ |
|
65 virtual ~WlanMemoryPool(); |
|
66 |
|
67 /** |
|
68 * Memory allocation. |
|
69 * Correct alignment guaranteed |
|
70 * |
|
71 * @since S60 v3.2 |
|
72 * @param aOsaMemoryType memory type to be allocated |
|
73 * @param aSize size of the buffer to be allocated in bytes. |
|
74 * Must be positive otherwise the allocation fails |
|
75 * @param aZeroStamp zero stamp the memory or not |
|
76 * @return begin of the allocated memory, NULL upon failure |
|
77 */ |
|
78 void* Alloc( MWlanOsa::TOsaMemoryType aOsaMemoryType, |
|
79 TInt aSize, |
|
80 TBool aZeroStamp ); |
|
81 |
|
82 /** |
|
83 * Releases memory allocated by the Alloc method |
|
84 * |
|
85 * @since S60 v3.2 |
|
86 * @param aPtr begin of the buffer to be freed |
|
87 */ |
|
88 void Free( void* aPtr ); |
|
89 |
|
90 private: |
|
91 |
|
92 /** |
|
93 * Init pool |
|
94 * |
|
95 * @since S60 v3.2 |
|
96 * @return ETrue upon success any other for failure |
|
97 */ |
|
98 TBool InitPool(); |
|
99 |
|
100 /** |
|
101 * Appends hw chunk handle to the back of the list |
|
102 * |
|
103 * @since S60 v3.2 |
|
104 * @param aHwChunkHandle hw chunk handle to be appended |
|
105 * @return ETrue upon success any other for failure |
|
106 */ |
|
107 TBool PushBack( const HwChunkHandle& aHwChunkHandle ); |
|
108 |
|
109 /** |
|
110 * Creates a new hw chunk and allocates memory from it |
|
111 * |
|
112 * @since S60 v3.2 |
|
113 * @param aSize size of the buffer to be allocated in bytes. |
|
114 * Must be positive otherwise the allocation fails |
|
115 * @param aHwChunkId unique chunk identifier used when freeing the memory |
|
116 * @param aZeroStamp zero stamp memory or not |
|
117 * @return begin of the allocated memory, NULL upon failure |
|
118 */ |
|
119 void* HwChunkAllocWithCreate( const TInt aSize, |
|
120 TInt& aHwChunkId, |
|
121 TBool aZeroStamp ); |
|
122 |
|
123 /** |
|
124 * Allocates memory from a hw chunk |
|
125 * |
|
126 * @since S60 v3.2 |
|
127 * @param aSize size of the buffer to be allocated in bytes. Must be |
|
128 * positive otherwise the allocation fails |
|
129 * @param aHwChunkId unique chunk identifier used when freeing the memory |
|
130 * @param aZeroStamp zero stamp memory or not |
|
131 * @return begin of the allocated memory, NULL upon failure |
|
132 */ |
|
133 void* HwChunkAlloc( const TInt aSize, TInt& aHwChunkId, TBool aZeroStamp ); |
|
134 |
|
135 /** |
|
136 * Evaluates is a chunk the initial chunk. |
|
137 * The intial chunk is the one created at object creation time and its |
|
138 * lifetime is equal to the lifetime of this object itself |
|
139 * |
|
140 * @since S60 v3.2 |
|
141 * @param aChunk chunk to be evaluated against the intial chunk |
|
142 * @return ETrue when aChunk is the intial chunk, any other if not |
|
143 */ |
|
144 inline TBool IsInitialChunk( WlanPlatformHwChunk* aChunk ); |
|
145 |
|
146 /** |
|
147 * Frees memory from a hw chunk |
|
148 * |
|
149 * @since S60 v3.2 |
|
150 * @param aMemHeader begin of the buffer to be freed |
|
151 */ |
|
152 void HwChunkFree( SMemHeader& aMemHeader ); |
|
153 |
|
154 // Prohibit copy constructor. |
|
155 WlanMemoryPool( const WlanMemoryPool& ); |
|
156 // Prohibit assigment operator. |
|
157 WlanMemoryPool& operator= ( const WlanMemoryPool& ); |
|
158 |
|
159 private: // data |
|
160 |
|
161 typedef list<HwChunkHandle> HwChunkHandleList; |
|
162 |
|
163 typedef HwChunkHandleList::iterator iterator; |
|
164 typedef HwChunkHandleList::const_iterator const_iterator; |
|
165 typedef HwChunkHandleList::size_type size_type; |
|
166 |
|
167 /** |
|
168 * list of hw chunks |
|
169 */ |
|
170 HwChunkHandleList iHwChunkHandles; |
|
171 |
|
172 /** |
|
173 * ETrue if cached memory shall be used, |
|
174 * EFalse otherwise |
|
175 */ |
|
176 TBool iUseCachedMemory; |
|
177 |
|
178 /** |
|
179 * Allocation unit size in bytes |
|
180 */ |
|
181 TInt iAllocationUnit; |
|
182 |
|
183 /** |
|
184 * Number of extra bytes required to align interconnect memory buffer |
|
185 * start address returned to the requester to allocation unit boundary |
|
186 */ |
|
187 TInt iExtraPadding; |
|
188 }; |
|
189 |
|
190 #endif // WLANMEMORYPOOL_H |