comparison src/aci2/bmi/mmiUserData.c @ 120:3c2acfa1a72f

src/aci2/bmi: file renames to make filename case consistent
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 07 Oct 2016 03:46:05 +0000
parents src/aci2/bmi/MmiUserData.c@93999a60b835
children
comparison
equal deleted inserted replaced
119:b92a33c204b6 120:3c2acfa1a72f
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: MMI
15 $File: MmiUserData.c
16 $Revision: 1.0
17
18 $Author: Condat(UK)
19 $Date: 22/02/01
20
21 ********************************************************************************
22
23 Description:
24
25
26
27 ********************************************************************************
28
29 $History: MmiUserData.c
30
31 25/10/00 Original Condat(UK) BMI version.
32
33 $End
34
35 *******************************************************************************/
36
37 #define ENTITY_MFW
38
39 /* includes */
40 #include <string.h>
41 #include <stdio.h>
42 #include <stdlib.h>
43
44 #if defined (NEW_FRAME)
45
46 #include "typedefs.h"
47 #include "vsi.h"
48 #include "pei.h"
49 #include "custom.h"
50 #include "gsm.h"
51
52 #else
53
54 #include "STDDEFS.H"
55 #include "custom.h"
56 #include "gsm.h"
57 #include "vsi.h"
58
59 #endif
60 #include "mfw_sys.h"
61 #include "mfw_mfw.h"
62 #include "mfw_win.h"
63
64 #include "MmiMmi.h"
65 #include "MmiUserData.h"
66
67
68 typedef struct uDe
69 {
70 UserKey key;
71 void *data;
72 struct uDe *next;
73 } UserDataElement, *UserDataLink;
74
75
76 static UserDataLink userDataFind( UserDataLink first, UserKey key)
77 {
78 while( first != NULL && first->key != key )
79 {
80 first = first->next;
81 }
82
83 return first;
84 }
85
86
87 static UserDataLink userDataPrevious( UserDataLink first,
88 UserDataLink beforeThis)
89 {
90 if( first == beforeThis ) // <beforeThis> is the first element in the list.
91 {
92 return NULL;
93 }
94
95 while( first->next != beforeThis )
96 {
97 first = first->next;
98 }
99
100 return first;
101 }
102
103
104 /*
105 * Sets the user data for <window> with <key> to <data>,
106 * and returns the previous contents of the user data.
107 * If <data> itself is returned no user data with <key>
108 * existed and a new user data element with <key> has been created
109 * and set to <data>.
110 * If NULL is returned, either <window> was invalid or a new user data
111 * element could not be created.
112 */
113 void *userDataHndSet( MfwHnd window, UserKey key, void *data)
114 {
115 if( window == NULL ) { return NULL; }
116
117 return userDataWinSet( (MfwWin *)((MfwHdr *)window)->data, key, data);
118 }
119
120
121 void *userDataWinSet( MfwWin *window, UserKey key, void *data)
122 {
123 UserDataLink thisOne;
124
125 if( window == NULL ) { return NULL; }
126
127 thisOne = userDataFind( (UserDataLink)window->user, key);
128
129 if( thisOne == NULL ) // element with <key> does not exist: create.
130 {
131 thisOne = (UserDataLink)ALLOC_MEMORY(sizeof(UserDataElement));
132
133 if( thisOne == NULL )
134 {
135 return NULL;
136 }
137
138 thisOne->key = key;
139 thisOne->data = data;
140 thisOne->next = (UserDataLink)window->user;
141
142 window->user = (void *)thisOne;
143
144 return data;
145 }
146 else
147 {
148 void *oldData = thisOne->data;
149
150 thisOne->data = data;
151
152 return oldData;
153 }
154 }
155
156
157 /*
158 * Returns the user data for <window> with <key>.
159 * If NULL is returned, either <window> was invalid or no user data
160 * with <key> existed.
161 */
162 void *userDataHndGet( MfwHnd window, UserKey key)
163 {
164 if( window == NULL ) { return NULL; }
165
166 return userDataWinGet( (MfwWin *)((MfwHdr *)window)->data, key);
167 }
168
169
170 void *userDataWinGet( MfwWin *window, UserKey key)
171 {
172 UserDataLink thisOne;
173
174 if( window == NULL ) { return NULL; }
175
176 thisOne = userDataFind( (UserDataLink)window->user, key);
177
178 if( thisOne == NULL ) { return NULL; }
179
180 return thisOne->data;
181 }
182
183
184 /*
185 * Deletes the user data for <window> with <key>, and returns the
186 * contents of the user data.
187 * If NULL is returned, either <window> was invalid or no user data
188 * with <key> existed.
189 */
190 void *userDataHndDelete( MfwHnd window, UserKey key)
191 {
192 if( window == NULL ) { return NULL; }
193
194 return userDataWinDelete( (MfwWin *)((MfwHdr *)window)->data, key);
195 }
196
197
198 void *userDataWinDelete( MfwWin *window, UserKey key)
199 {
200 UserDataLink doomed;
201
202 if( window == NULL ) { return NULL; }
203
204 doomed = userDataFind( (UserDataLink)window->user, key);
205
206 if( doomed == NULL ) // element with <key> does not exist.
207 {
208 return NULL;
209 }
210 else
211 {
212 void * oldData = doomed->data;
213 UserDataLink previous;
214
215 previous = userDataPrevious( (UserDataLink)window->user, doomed);
216
217 if( previous == NULL ) // <doomed> is the first element in the list.
218 {
219 window->user = (void *)doomed->next;
220 }
221 else
222 {
223 previous->next = doomed->next;
224 }
225
226 FREE_MEMORY( (void *)doomed, sizeof(UserDataElement));
227
228 return oldData;
229 }
230 }
231