comparison src/ui3/bmi/MmiBlkManager.c @ 420:e8ddbb0837ed

src/ui3: initial import of TCS3/LoCosto BMI & MFW code
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Jan 2018 03:09:00 +0000
parents
children
comparison
equal deleted inserted replaced
419:59143cd42ec7 420:e8ddbb0837ed
1 /*******************************************************************************
2
3 CONDAT (UK)
4
5 ********************************************************************************
6
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.
9
10 ********************************************************************************
11
12 $Project name: Basic MMI
13 $Project code: BMI (6349)
14 $Module: PhoneBook
15 $File: MmiBlkManager.c
16 $Revision: 1.0
17
18 $Author: Condat(UK)
19 $Date: 25/10/00
20
21 ********************************************************************************
22
23 Description:
24
25 This module, in conjunction with the MmiBlkResources module,
26 provides the access to block resources for the MMI.
27
28 The block manager is responsible for creating and initialising
29 the structures and tables to allow access to the strings, icons
30 sounds and vibrations required by the MMI.
31
32 Each of these items is effectively a contiguous block of memory,
33 which is accessed via a block resource. Each of the block resources
34 are provided by this package
35
36 ********************************************************************************
37
38 $History: MmiBlkManager.c
39
40 25/10/00 Original Condat(UK) BMI version.
41
42 $End
43
44 *******************************************************************************/
45
46
47 /*******************************************************************************
48
49 Include Files
50
51 *******************************************************************************/
52
53 #define ENTITY_MFW
54
55 /* includes */
56 #include <string.h>
57 #include <stdio.h>
58 #include <stdlib.h>
59
60 #if defined (NEW_FRAME)
61
62 #include "typedefs.h"
63 #include "vsi.h"
64 #include "pei.h"
65 #include "custom.h"
66 #include "gsm.h"
67
68 #else
69
70 #include "STDDEFS.H"
71 #include "custom.h"
72 #include "gsm.h"
73 #include "vsi.h"
74
75 #endif
76 // #include <malloc.h>
77
78 #include "MmiBlkManager.h"
79
80
81 /*******************************************************************************
82
83 Local structures and definitions
84
85 *******************************************************************************/
86
87 /* Define a type for the manager control block, this contains
88 an array identifying each of the resource manager handles
89 which are populated as part of the initialisation sequence
90 */
91 #define BLOCK_MANAGER_KEY 0x00BABE01L
92 #define BLOCK_MANAGER_ENTRY_COUNT 0x00000010L
93
94 typedef struct _tManagerEntry_
95 {
96 tBlkId Id;
97 int NumEntries;
98 tBlkHandle EntryBase;
99 } tManagerEntry, *pManagerEntry;
100
101 typedef struct _tManagerControl_
102 {
103 long int BlkKey;
104 tBlkHandle BaseAddress;
105 int BlkLength;
106 tBlkHandle RsrcList[BLOCK_MANAGER_ENTRY_COUNT];
107 pManagerEntry EntryPtr;
108 } tManagerControl, *pManagerControl;
109
110
111 /*******************************************************************************
112
113 Local routines
114
115 *******************************************************************************/
116
117 /*******************************************************************************
118
119 $Function: ValidManagerResource
120
121 $Description: Determines if the resource indicated by the handle is valid
122
123 $Returns: Zero if failure, non-zero if valid resource
124
125 $Arguments: ManagerRsrc, handle of resource manager
126
127 *******************************************************************************/
128
129 static int ValidManagerResource( tBlkHandle ManagerRsrc )
130 {
131 pManagerControl ManagerControl = (pManagerControl) ManagerRsrc;
132
133 if ( ManagerControl == NULL )
134 return 0;
135
136 return ( ManagerControl->BlkKey == BLOCK_MANAGER_KEY );
137 }
138
139
140 /*******************************************************************************
141
142 Public routines
143
144 *******************************************************************************/
145
146
147 /*******************************************************************************
148
149 $Function: mmibm_Initialise
150
151 $Description: Initialise a block manager object
152
153 $Returns: Handle of block manager object, NULL if failure
154
155 $Arguments: BlkBase, base address of the block manager data
156 NumEntries, number of entries to be dealt with by the
157 block manager
158
159 *******************************************************************************/
160
161 tBlkHandle mmibm_Initialise( tBlkHandle BlkBase, int NumEntries )
162 {
163 pManagerControl MyControl;
164 tBlkId Entry;
165 int i;
166
167 if ( ( MyControl = (pManagerControl) ALLOC_MEMORY( sizeof(tManagerControl) ) ) != NULL )
168 {
169 /* Fill in the bits we know are pretty constant
170 */
171 MyControl->BlkKey = BLOCK_MANAGER_KEY;
172 MyControl->BaseAddress = BlkBase;
173 MyControl->BlkLength = NumEntries;
174 MyControl->EntryPtr = (pManagerEntry) BlkBase;
175
176 /* Initialise the handle array to empty initially
177 */
178 for ( i = 0; i < BLOCK_MANAGER_ENTRY_COUNT; i++ )
179 MyControl->RsrcList[i] = NULL;
180
181 /* Now for each entry in the incoming block list we can create
182 a handler instance
183 */
184 for ( i = 0; i < NumEntries; i++ )
185 if ( ( Entry = MyControl->EntryPtr[i].Id ) < BLOCK_MANAGER_ENTRY_COUNT )
186 MyControl->RsrcList[ Entry ] = mmibr_Initialise(
187 MyControl->EntryPtr[i].EntryBase, MyControl->EntryPtr[i].NumEntries );
188 }
189
190 return MyControl;
191 }
192
193
194 /*******************************************************************************
195
196 $Function: mmibm_ShutDown
197
198 $Description: Shutdown routine to deallocate resources ina controlled manner
199
200 $Returns: none.
201
202 $Arguments: *BlkHandle, pointer to resource manager handle
203
204 *******************************************************************************/
205
206 void mmibm_ShutDown( tBlkHandle *BlkHandle )
207 {
208 /* Convert and verify the incoming handle
209 */
210 pManagerControl MyControl = (pManagerControl) *BlkHandle;
211 int i;
212
213 if ( ValidManagerResource( *BlkHandle ) )
214 {
215 /* Clear down the allocated resource managers
216 */
217 for ( i = 0; i < BLOCK_MANAGER_ENTRY_COUNT; i++ )
218 if ( MyControl->RsrcList[i] != NULL )
219 mmibr_ShutDown( &MyControl->RsrcList[i] );
220
221 /* and free the resource manager handle
222 */
223 free( *BlkHandle );
224 *BlkHandle = NULL;
225 }
226 }
227
228
229 /*******************************************************************************
230
231 $Function: mmibm_SupplyResourceHandler
232
233 $Description:
234
235 Since this module will be managing each of the block handlers
236 for each of the resources, we need to be able to supply the
237 appropriate handle for any given type to the calling routine.
238
239 $Returns: Handle to requesteb block resource handler, NULL if failure
240
241 $Arguments: ManagerHandle, handle of the block manager
242 Id, identifier of the resource table for which the resource
243 handler is required
244
245 *******************************************************************************/
246
247 tBlkHandle mmibm_SupplyResourceHandler( tBlkHandle ManagerHandle, tBlkId Id )
248 {
249 /* Convert and verify the incoming handle
250 */
251 pManagerControl MyControl = (pManagerControl) ManagerHandle;
252 if ( ! ValidManagerResource( ManagerHandle ) )
253 return NULL;
254
255 /* Verify the id is within the range we expect
256 */
257 if ( ( Id >= 0 ) && ( Id < BLOCK_MANAGER_ENTRY_COUNT ) )
258 return MyControl->RsrcList[Id];
259
260 /* Okay, we have something invalid, so return NULL
261 */
262 return NULL;
263 }
264
265
266
267 /*******************************************************************************
268
269 End of File
270
271 *******************************************************************************/
272