FreeCalypso > hg > fc-tourmaline
comparison src/ui/bmi/mmiBlkResources.c @ 141:67b91d34f75e
mmiBlkResources.c: bogotab fixes
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 14 Nov 2020 04:29:03 +0000 |
parents | c0052fe355d3 |
children |
comparison
equal
deleted
inserted
replaced
140:1c4536a30e32 | 141:67b91d34f75e |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 | 2 |
3 CONDAT (UK) | 3 CONDAT (UK) |
4 | 4 |
5 ******************************************************************************** | 5 ******************************************************************************** |
6 | 6 |
7 This software product is the property of Condat (UK) Ltd and may not be | 7 This software product is the property of Condat (UK) Ltd and may not be |
8 disclosed to any third party without the express permission of the owner. | 8 disclosed to any third party without the express permission of the owner. |
9 | 9 |
10 ******************************************************************************** | 10 ******************************************************************************** |
11 | 11 |
12 $Project name: Basic MMI | 12 $Project name: Basic MMI |
13 $Project code: BMI (6349) | 13 $Project code: BMI (6349) |
14 $Module: PhoneBook | 14 $Module: PhoneBook |
15 $File: MmiBlkResources.c | 15 $File: MmiBlkResources.c |
16 $Revision: 1.0 | 16 $Revision: 1.0 |
17 | 17 |
18 $Author: Condat(UK) | 18 $Author: Condat(UK) |
19 $Date: 25/10/00 | 19 $Date: 25/10/00 |
20 | 20 |
21 ******************************************************************************** | 21 ******************************************************************************** |
22 | 22 |
23 Description: | 23 Description: |
24 | 24 |
25 This modules provides, in conjunction with the MmiBlkManager module, | 25 This modules provides, in conjunction with the MmiBlkManager module, |
26 the resource management facilities for the MMI. | 26 the resource management facilities for the MMI. |
27 | 27 |
28 ******************************************************************************** | 28 ******************************************************************************** |
29 | 29 |
30 $History: MmiBlkResources.c | 30 $History: MmiBlkResources.c |
31 | 31 |
32 25/10/00 Original Condat(UK) BMI version. | 32 25/10/00 Original Condat(UK) BMI version. |
33 | 33 |
34 $End | 34 $End |
35 | 35 |
36 *******************************************************************************/ | 36 *******************************************************************************/ |
37 | 37 |
76 *******************************************************************************/ | 76 *******************************************************************************/ |
77 | 77 |
78 /* Define the control structures used to implement the block resource | 78 /* Define the control structures used to implement the block resource |
79 manager | 79 manager |
80 */ | 80 */ |
81 #define RESOURCE_MANAGER_KEY 0x00BABE02L | 81 #define RESOURCE_MANAGER_KEY 0x00BABE02L |
82 #define RESOURCE_SEARCH_LIMIT 4 | 82 #define RESOURCE_SEARCH_LIMIT 4 |
83 | 83 |
84 typedef struct _tBlkEntry_ | 84 typedef struct _tBlkEntry_ |
85 { | 85 { |
86 tBlkId BlkId; | 86 tBlkId BlkId; |
87 tBlkHandle BlkHandle; | 87 tBlkHandle BlkHandle; |
88 } tBlkEntry, *pBlkEntry; | 88 } tBlkEntry, *pBlkEntry; |
89 | 89 |
90 typedef struct _tBlkControl_ | 90 typedef struct _tBlkControl_ |
91 { | 91 { |
92 long int BlkKey; | 92 long int BlkKey; |
93 tBlkHandle BlkBase; | 93 tBlkHandle BlkBase; |
94 int BlkLength; | 94 int BlkLength; |
95 pBlkEntry BlkStartPtr; | 95 pBlkEntry BlkStartPtr; |
96 tBlkHandle BlkMinAddress; | 96 tBlkHandle BlkMinAddress; |
97 tBlkHandle BlkMaxAddress; | 97 tBlkHandle BlkMaxAddress; |
98 } tBlkControl, *pBlkControl; | 98 } tBlkControl, *pBlkControl; |
99 | 99 |
100 | 100 |
101 /******************************************************************************* | 101 /******************************************************************************* |
102 | 102 |
104 | 104 |
105 *******************************************************************************/ | 105 *******************************************************************************/ |
106 | 106 |
107 /******************************************************************************* | 107 /******************************************************************************* |
108 | 108 |
109 $Function: ValidBlockResource | 109 $Function: ValidBlockResource |
110 | 110 |
111 $Description: Verifies that the resource indicated by the handle is a valid | 111 $Description: Verifies that the resource indicated by the handle is a valid |
112 resource. | 112 resource. |
113 | 113 |
114 $Returns: 0 If invalid, non-zero if valid. | 114 $Returns: 0 If invalid, non-zero if valid. |
115 | 115 |
116 $Arguments: BlkRsrc, handle of resource | 116 $Arguments: BlkRsrc, handle of resource |
117 | 117 |
118 *******************************************************************************/ | 118 *******************************************************************************/ |
119 | 119 |
120 | 120 |
121 static int ValidBlockResource( tBlkHandle BlkRsrc ) | 121 static int ValidBlockResource( tBlkHandle BlkRsrc ) |
122 { | 122 { |
123 pBlkControl BlkControl = (pBlkControl) BlkRsrc; | 123 pBlkControl BlkControl = (pBlkControl) BlkRsrc; |
124 | 124 |
125 /* Check for non-NULL handle | 125 /* Check for non-NULL handle |
126 */ | 126 */ |
127 if ( BlkControl == NULL ) | 127 if ( BlkControl == NULL ) |
128 return 0; | 128 return 0; |
129 | 129 |
130 /* Check key has been set up correctly | 130 /* Check key has been set up correctly |
131 */ | 131 */ |
132 return ( BlkControl->BlkKey == RESOURCE_MANAGER_KEY ); | 132 return ( BlkControl->BlkKey == RESOURCE_MANAGER_KEY ); |
133 } | 133 } |
134 | 134 |
135 | 135 |
136 /******************************************************************************* | 136 /******************************************************************************* |
137 | 137 |
139 | 139 |
140 *******************************************************************************/ | 140 *******************************************************************************/ |
141 | 141 |
142 /******************************************************************************* | 142 /******************************************************************************* |
143 | 143 |
144 $Function: mmibr_Initialise | 144 $Function: mmibr_Initialise |
145 | 145 |
146 $Description: | 146 $Description: |
147 | 147 |
148 The initialisation routine must be called as part of the startup | 148 The initialisation routine must be called as part of the startup |
149 phase of the system, it will allocate working space for the block | 149 phase of the system, it will allocate working space for the block |
150 handler if required, and will initialise any structures required | 150 handler if required, and will initialise any structures required |
151 to maintain the corect operation of the functions. This routine | 151 to maintain the corect operation of the functions. This routine |
152 must be called prior to invocation of any other block resource | 152 must be called prior to invocation of any other block resource |
153 function | 153 function |
154 | 154 |
155 $Returns: Handle to a resource block, NULL if unsuccessful | 155 $Returns: Handle to a resource block, NULL if unsuccessful |
156 | 156 |
157 $Arguments: BlkBase, Base address of the block of data relating | 157 $Arguments: BlkBase, Base address of the block of data relating |
158 to the resource | 158 to the resource |
159 NumEntries, number of entries associated with the resource | 159 NumEntries, number of entries associated with the resource |
160 | 160 |
161 *******************************************************************************/ | 161 *******************************************************************************/ |
162 | 162 |
163 tBlkHandle mmibr_Initialise( tBlkHandle BlkBase, int NumEntries ) | 163 tBlkHandle mmibr_Initialise( tBlkHandle BlkBase, int NumEntries ) |
164 { | 164 { |
165 pBlkControl Blk; | 165 pBlkControl Blk; |
166 int i; | 166 int i; |
167 | 167 |
168 /* As part of the initialisation process, we need to allocate a | 168 /* As part of the initialisation process, we need to allocate a |
169 block of memory in which to store the control information | 169 block of memory in which to store the control information |
170 associated with this block resource manager | 170 associated with this block resource manager |
171 */ | 171 */ |
172 if ( ( Blk = (pBlkControl) ALLOC_MEMORY( sizeof(tBlkControl) ) ) != NULL ) | 172 if ( ( Blk = (pBlkControl) ALLOC_MEMORY( sizeof(tBlkControl) ) ) != NULL ) |
173 { | 173 { |
174 /* Store the things we know straight off | 174 /* Store the things we know straight off |
175 */ | 175 */ |
176 Blk->BlkKey = RESOURCE_MANAGER_KEY; | 176 Blk->BlkKey = RESOURCE_MANAGER_KEY; |
177 Blk->BlkBase = BlkBase; | 177 Blk->BlkBase = BlkBase; |
178 Blk->BlkLength = NumEntries; | 178 Blk->BlkLength = NumEntries; |
179 Blk->BlkStartPtr = (pBlkEntry) BlkBase; | 179 Blk->BlkStartPtr = (pBlkEntry) BlkBase; |
180 | 180 |
181 /* In order to detect memory allocations, we scan the list | 181 /* In order to detect memory allocations, we scan the list |
182 of known entries, storing the maximum and minimum addresses | 182 of known entries, storing the maximum and minimum addresses |
183 in the list. This scan allows us to detect when allocated | 183 in the list. This scan allows us to detect when allocated |
184 memory is being returned, since the address will be outside | 184 memory is being returned, since the address will be outside |
185 the contiguous memory block we are managing. | 185 the contiguous memory block we are managing. |
186 */ | 186 */ |
187 Blk->BlkMinAddress = Blk->BlkMaxAddress = BlkBase; | 187 Blk->BlkMinAddress = Blk->BlkMaxAddress = BlkBase; |
188 for ( i = 0; i < NumEntries; i++ ) | 188 for ( i = 0; i < NumEntries; i++ ) |
189 { | 189 { |
190 if ( Blk->BlkMaxAddress < Blk->BlkStartPtr[i].BlkHandle ) | 190 if ( Blk->BlkMaxAddress < Blk->BlkStartPtr[i].BlkHandle ) |
191 Blk->BlkMaxAddress = Blk->BlkStartPtr[i].BlkHandle; | 191 Blk->BlkMaxAddress = Blk->BlkStartPtr[i].BlkHandle; |
192 } | 192 } |
193 } | 193 } |
194 | 194 |
195 return Blk; | 195 return Blk; |
196 } | 196 } |
197 | 197 |
198 /******************************************************************************* | 198 /******************************************************************************* |
199 | 199 |
200 $Function: mmibr_ShutDown | 200 $Function: mmibr_ShutDown |
201 | 201 |
202 $Description: | 202 $Description: |
203 | 203 |
204 The shutdown function can be called to free any allocations set up | 204 The shutdown function can be called to free any allocations set up |
205 by the Initialise routine. In a running system this is unlikely to | 205 by the Initialise routine. In a running system this is unlikely to |
206 be called unless a catastrophic error has occurred and the system | 206 be called unless a catastrophic error has occurred and the system |
207 needs to be restarted. | 207 needs to be restarted. |
208 | 208 |
209 $Returns: none. | 209 $Returns: none. |
210 | 210 |
211 $Arguments: Pointer to a block resource handle (ie ptr to ptr) | 211 $Arguments: Pointer to a block resource handle (ie ptr to ptr) |
212 | 212 |
213 *******************************************************************************/ | 213 *******************************************************************************/ |
214 | 214 |
215 void mmibr_ShutDown( tBlkHandle *BlkRsrc ) | 215 void mmibr_ShutDown( tBlkHandle *BlkRsrc ) |
216 { | 216 { |
217 /* Only allow the resource manager to be shutdown if the provided | 217 /* Only allow the resource manager to be shutdown if the provided |
218 handle is consistent | 218 handle is consistent |
219 */ | 219 */ |
220 if ( ValidBlockResource( *BlkRsrc ) ) | 220 if ( ValidBlockResource( *BlkRsrc ) ) |
221 { | 221 { |
222 free( *BlkRsrc ); | 222 free( *BlkRsrc ); |
223 *BlkRsrc = NULL; | 223 *BlkRsrc = NULL; |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 /******************************************************************************* | 227 /******************************************************************************* |
228 | 228 |
229 $Function: mmibr_Fetch | 229 $Function: mmibr_Fetch |
230 | 230 |
231 $Description: | 231 $Description: |
232 | 232 |
233 We will adopt a mechanism where each block of data being provided | 233 We will adopt a mechanism where each block of data being provided |
234 will need to be returned to the block resource manager when it | 234 will need to be returned to the block resource manager when it |
235 is no longer being used, this will provide an orthogonal approach | 235 is no longer being used, this will provide an orthogonal approach |
236 when dealing with data coming from either ROM or dynamically | 236 when dealing with data coming from either ROM or dynamically |
237 allocated memory. | 237 allocated memory. |
238 | 238 |
239 $Returns: pointer to resource, NULL if unsuccessful | 239 $Returns: pointer to resource, NULL if unsuccessful |
240 | 240 |
241 $Arguments: BlkRsrc, resource handle created by mmibr_Initialise | 241 $Arguments: BlkRsrc, resource handle created by mmibr_Initialise |
242 Id, identifier of the resource to be returned | 242 Id, identifier of the resource to be returned |
243 | 243 |
244 *******************************************************************************/ | 244 *******************************************************************************/ |
245 | 245 |
246 tBlkHandle mmibr_Fetch( tBlkHandle BlkRsrc, tBlkId Id ) | 246 tBlkHandle mmibr_Fetch( tBlkHandle BlkRsrc, tBlkId Id ) |
247 { | 247 { |
248 int Start, End, Search; | 248 int Start, End, Search; |
249 tBlkId CurrentId; | 249 tBlkId CurrentId; |
250 tBlkHandle SearchPtr; | 250 tBlkHandle SearchPtr; |
251 | 251 |
252 /* convert the handle and verify it's valid | 252 /* convert the handle and verify it's valid |
253 */ | 253 */ |
254 pBlkControl BlkControl = (pBlkControl) BlkRsrc; | 254 pBlkControl BlkControl = (pBlkControl) BlkRsrc; |
255 if ( ! ValidBlockResource( BlkRsrc ) ) | 255 if ( ! ValidBlockResource( BlkRsrc ) ) |
256 return NULL; | 256 return NULL; |
257 | 257 |
258 /* When locating a specific entry, we need to search the list of | 258 /* When locating a specific entry, we need to search the list of |
259 ids for one matching the input value. Since the Ids will be | 259 ids for one matching the input value. Since the Ids will be |
260 organised as an ordered list, very important that bit, we can | 260 organised as an ordered list, very important that bit, we can |
261 perform a simple binary search to locate the items. | 261 perform a simple binary search to locate the items. |
262 */ | 262 */ |
263 Start = 0; | 263 Start = 0; |
264 End = BlkControl->BlkLength - 1; | 264 End = BlkControl->BlkLength - 1; |
265 SearchPtr = NULL; | 265 SearchPtr = NULL; |
266 do | 266 do |
267 { | 267 { |
268 /* grab the entry midway between the current start and end | 268 /* grab the entry midway between the current start and end |
269 */ | 269 */ |
270 Search = Start + ((End - Start) >> 1); | 270 Search = Start + ((End - Start) >> 1); |
271 CurrentId = BlkControl->BlkStartPtr[Search].BlkId; | 271 CurrentId = BlkControl->BlkStartPtr[Search].BlkId; |
272 | 272 |
273 /* Binary chop the search space | 273 /* Binary chop the search space |
274 */ | 274 */ |
275 if ( CurrentId == Id ) | 275 if ( CurrentId == Id ) |
276 { | 276 { |
277 /* Found a match, grab handle and terminate search | 277 /* Found a match, grab handle and terminate search |
278 */ | 278 */ |
279 SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; | 279 SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; |
280 Start = End; | 280 Start = End; |
281 } | 281 } |
282 else if ( CurrentId > Id ) | 282 else if ( CurrentId > Id ) |
283 { | 283 { |
284 /* Not got a match, but it's not in the top half so move | 284 /* Not got a match, but it's not in the top half so move |
285 the End pointer down | 285 the End pointer down |
286 */ | 286 */ |
287 End = Search; | 287 End = Search; |
288 } | 288 } |
289 else | 289 else |
290 { | 290 { |
291 /* Not got a match, but it's not in the bottom half so | 291 /* Not got a match, but it's not in the bottom half so |
292 move the Start pointer up | 292 move the Start pointer up |
293 */ | 293 */ |
294 Start = Search; | 294 Start = Search; |
295 } | 295 } |
296 | 296 |
297 /* when we get down to the last three or four entries, just | 297 /* when we get down to the last three or four entries, just |
298 search linearly to solve it, this is generally quicker for | 298 search linearly to solve it, this is generally quicker for |
299 a small number of entries than continuing the binary chop | 299 a small number of entries than continuing the binary chop |
300 */ | 300 */ |
301 if ( ( End - Start ) < RESOURCE_SEARCH_LIMIT ) | 301 if ( ( End - Start ) < RESOURCE_SEARCH_LIMIT ) |
302 { | 302 { |
303 /* search quickly through the possibles | 303 /* search quickly through the possibles |
304 */ | 304 */ |
305 for ( Search = Start; Search <= End; Search++ ) | 305 for ( Search = Start; Search <= End; Search++ ) |
306 if ( Id == BlkControl->BlkStartPtr[Search].BlkId ) | 306 if ( Id == BlkControl->BlkStartPtr[Search].BlkId ) |
307 SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; | 307 SearchPtr = BlkControl->BlkStartPtr[Search].BlkHandle; |
308 | 308 |
309 /* And terminate the binary chop | 309 /* And terminate the binary chop |
310 */ | 310 */ |
311 Start = End; | 311 Start = End; |
312 } | 312 } |
313 | 313 |
314 } while ( Start != End ); | 314 } while ( Start != End ); |
315 | 315 |
316 return SearchPtr; | 316 return SearchPtr; |
317 } | 317 } |
318 | 318 |
319 /******************************************************************************* | 319 /******************************************************************************* |
320 | 320 |
321 End of File | 321 End of File |
322 | 322 |
323 *******************************************************************************/ | 323 *******************************************************************************/ |
324 |