|
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // e32/euser/us_shbuf.cpp |
|
15 // Shareable Data Buffers |
|
16 |
|
17 #include "e32shbuf.h" |
|
18 #include <u32exec.h> |
|
19 #include <e32base.h> |
|
20 |
|
21 EXPORT_C TShPoolInfo::TShPoolInfo() |
|
22 { |
|
23 memclr(this, sizeof(TShPoolInfo)); |
|
24 } |
|
25 |
|
26 |
|
27 EXPORT_C TShPoolCreateInfo::TShPoolCreateInfo(TShPoolPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs) |
|
28 { |
|
29 iInfo.iBufSize = aBufSize; |
|
30 iInfo.iInitialBufs = aInitialBufs; |
|
31 iInfo.iFlags = aFlag; |
|
32 iInfo.iAlignment = 0; |
|
33 SetSizingAttributes(aInitialBufs, 0,0,0); |
|
34 } |
|
35 |
|
36 |
|
37 EXPORT_C TShPoolCreateInfo::TShPoolCreateInfo(TShPoolNonPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment) |
|
38 { |
|
39 iInfo.iBufSize = aBufSize; |
|
40 iInfo.iInitialBufs = aInitialBufs; |
|
41 iInfo.iAlignment = aAlignment; |
|
42 iInfo.iFlags = aFlag; |
|
43 SetSizingAttributes(aInitialBufs, 0,0,0); |
|
44 } |
|
45 |
|
46 |
|
47 EXPORT_C TInt TShPoolCreateInfo::SetSizingAttributes(TUint aMaxBufs, TUint aGrowTriggerRatio, |
|
48 TUint aGrowByRatio, TUint aShrinkHysteresisRatio) |
|
49 { |
|
50 if (aGrowTriggerRatio == 0 || aGrowByRatio == 0) // No automatic growing/shrinking |
|
51 { |
|
52 aGrowTriggerRatio = aGrowByRatio = 0; |
|
53 if (aMaxBufs != iInfo.iInitialBufs) |
|
54 return KErrArgument; |
|
55 } |
|
56 else |
|
57 { |
|
58 // aGrowTriggerRatio must be < 1.0 (i.e. 256) |
|
59 // aShrinkHysteresisRatio must be > 1.0 |
|
60 if (aGrowTriggerRatio >= 256 || aShrinkHysteresisRatio <= 256) |
|
61 return KErrArgument; |
|
62 |
|
63 if ((iInfo.iFlags & EShPoolContiguous) && (iInfo.iFlags & EShPoolNonPageAlignedBuffer)) |
|
64 return KErrNotSupported; |
|
65 } |
|
66 |
|
67 iInfo.iMaxBufs = aMaxBufs; |
|
68 iInfo.iGrowTriggerRatio = aGrowTriggerRatio; |
|
69 iInfo.iGrowByRatio = aGrowByRatio; |
|
70 iInfo.iShrinkHysteresisRatio = aShrinkHysteresisRatio; |
|
71 |
|
72 return KErrNone; |
|
73 } |
|
74 |
|
75 |
|
76 EXPORT_C TInt TShPoolCreateInfo::SetExclusive() |
|
77 { |
|
78 iInfo.iFlags |= EShPoolExclusiveAccess; |
|
79 |
|
80 return KErrNone; |
|
81 } |
|
82 |
|
83 |
|
84 EXPORT_C TInt TShPoolCreateInfo::SetGuardPages() |
|
85 { |
|
86 iInfo.iFlags |= EShPoolGuardPages; |
|
87 |
|
88 return KErrNone; |
|
89 } |
|
90 |
|
91 |
|
92 EXPORT_C RShPool::RShPool() |
|
93 { |
|
94 memclr(this, sizeof(RShPool)); |
|
95 } |
|
96 |
|
97 |
|
98 EXPORT_C TInt RShPool::Create(const TShPoolCreateInfo& aInfo, TUint aFlags) |
|
99 { |
|
100 return SetReturnedHandle(Exec::ShPoolCreate(aInfo.iInfo, aFlags)); |
|
101 } |
|
102 |
|
103 |
|
104 EXPORT_C void RShBuf::Close() |
|
105 { |
|
106 if ((iHandle!=KNullHandle) && ((iHandle & CObjectIx::ENoClose)==0)) |
|
107 { |
|
108 iBase = 0; |
|
109 iSize = 0; |
|
110 |
|
111 TInt h = iHandle; |
|
112 iHandle=0; |
|
113 Exec::HandleClose(h); |
|
114 } |
|
115 } |
|
116 |
|
117 EXPORT_C void RShPool::GetInfo(TShPoolInfo& aInfo) const |
|
118 { |
|
119 Exec::ShPoolGetInfo(iHandle, aInfo); |
|
120 } |
|
121 |
|
122 |
|
123 EXPORT_C TInt RShPool::SetBufferWindow(TInt aWindowSize, TBool aAutoMap) |
|
124 { |
|
125 return Exec::ShPoolBufferWindow(iHandle, aWindowSize, aAutoMap); |
|
126 } |
|
127 |
|
128 |
|
129 EXPORT_C TUint RShPool::FreeCount() const |
|
130 { |
|
131 return Exec::ShPoolFreeCount(iHandle); |
|
132 } |
|
133 |
|
134 |
|
135 EXPORT_C void RShPool::RequestLowSpaceNotification(TUint aThreshold, TRequestStatus& aStatus) |
|
136 { |
|
137 aStatus = KRequestPending; |
|
138 Exec::ShPoolNotification(iHandle, EShPoolLowSpace, aThreshold, aStatus); |
|
139 } |
|
140 |
|
141 |
|
142 EXPORT_C void RShPool::RequestFreeSpaceNotification(TUint aThreshold, TRequestStatus& aStatus) |
|
143 { |
|
144 aStatus = KRequestPending; |
|
145 Exec::ShPoolNotification(iHandle, EShPoolFreeSpace, aThreshold, aStatus); |
|
146 } |
|
147 |
|
148 |
|
149 EXPORT_C void RShPool::CancelLowSpaceNotification(TRequestStatus& aStatus) |
|
150 { |
|
151 Exec::ShPoolNotificationCancel(iHandle, EShPoolLowSpace, aStatus); |
|
152 } |
|
153 |
|
154 |
|
155 EXPORT_C void RShPool::CancelFreeSpaceNotification(TRequestStatus& aStatus) |
|
156 { |
|
157 Exec::ShPoolNotificationCancel(iHandle, EShPoolFreeSpace, aStatus); |
|
158 } |
|
159 |
|
160 |
|
161 EXPORT_C TInt RShBuf::Alloc(RShPool& aPool, TUint aFlags) |
|
162 { |
|
163 SShBufBaseAndSize bs; |
|
164 |
|
165 TInt handle = Exec::ShPoolAlloc(aPool.Handle(), aFlags, bs); |
|
166 |
|
167 TInt r = SetReturnedHandle(handle); |
|
168 |
|
169 if (r == KErrNone) |
|
170 { |
|
171 iBase = bs.iBase; |
|
172 iSize = bs.iSize; |
|
173 } |
|
174 |
|
175 return r; |
|
176 } |
|
177 |
|
178 |
|
179 EXPORT_C TInt RShBuf::Map(TBool aReadOnly) |
|
180 { |
|
181 SShBufBaseAndSize bs; |
|
182 TInt r = Exec::ShBufMap(iHandle, aReadOnly, bs); |
|
183 |
|
184 if (r == KErrNone) |
|
185 { |
|
186 iBase = bs.iBase; |
|
187 iSize = bs.iSize; |
|
188 } |
|
189 return r; |
|
190 } |
|
191 |
|
192 |
|
193 EXPORT_C TInt RShBuf::UnMap() |
|
194 { |
|
195 return Exec::ShBufUnMap(iHandle); |
|
196 } |
|
197 |
|
198 |
|
199 EXPORT_C TUint8* RShBuf::Ptr() |
|
200 { |
|
201 // if iBase is null RShBuf has not been intialised |
|
202 if (iBase == 0) |
|
203 { |
|
204 SShBufBaseAndSize bs; |
|
205 Exec::ShBufBaseAndSize(iHandle, bs); |
|
206 iBase = bs.iBase; |
|
207 iSize = bs.iSize; |
|
208 } |
|
209 return reinterpret_cast<TUint8*>(iBase); |
|
210 } |
|
211 |
|
212 |
|
213 EXPORT_C TUint RShBuf::Size() |
|
214 { |
|
215 // if iBase is null RShBuf has not been intialised |
|
216 if (iBase == 0) |
|
217 { |
|
218 SShBufBaseAndSize bs; |
|
219 Exec::ShBufBaseAndSize(iHandle, bs); |
|
220 iBase = bs.iBase; |
|
221 iSize = bs.iSize; |
|
222 } |
|
223 return iSize; |
|
224 } |