1 /* |
|
2 * Copyright (c) 2009 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: |
|
15 * |
|
16 */ |
|
17 #include <e32std.h> |
|
18 #include "DictionaryContext.h" |
|
19 #include "cxml_internal.h" |
|
20 #include "featmgr.h" |
|
21 #include <xml/cxml/nw_wbxml_dictionary.h> |
|
22 |
|
23 /* There is possibility that dictionary initialize is called by the embedded |
|
24 * application also. To make allocation/deallocation of dictionary possible. |
|
25 * The NW_CONTEXT_REF_DICT_CNT variable is added. This variable of TLS context |
|
26 * will keep the reference count of the number of times dictionary |
|
27 * inialization/destroy is called. |
|
28 * |
|
29 * The dictionary is destroyed when NW_CONTEXT_REF_DICT_CNT is zero. |
|
30 * |
|
31 */ |
|
32 |
|
33 typedef enum { |
|
34 NW_CONTEXT_DICTIONARY = 0, |
|
35 NW_CONTEXT_DICTIONARY_COUNT = 1, |
|
36 NW_CONTEXT_REF_DICT_CNT = 2, /*Number of times dictionary rerferenced*/ |
|
37 |
|
38 NW_CONTEXT_NUM_ENTRIES = 3 |
|
39 |
|
40 } NW_DictionaryContext_Id_t; |
|
41 |
|
42 |
|
43 typedef struct { |
|
44 NW_Uint16 numContexts; |
|
45 void *contexts[NW_CONTEXT_NUM_ENTRIES]; |
|
46 } NW_DictionaryContext_Array_t; |
|
47 |
|
48 |
|
49 /***************************************************************** |
|
50 |
|
51 Name: NW_Ctx_Init() |
|
52 |
|
53 Description: Initialize the context manager |
|
54 |
|
55 Parameters: |
|
56 |
|
57 Return Value: NW_STAT_SUCCESS or NW_STAT_OUT_OF_MEMORY |
|
58 |
|
59 ******************************************************************/ |
|
60 static NW_Status_t DictContext_Init() |
|
61 { |
|
62 NW_DictionaryContext_Array_t* contextArray; |
|
63 NW_Uint32 i; |
|
64 |
|
65 /*lint --e{429} Custodial pointer has not been freed or returned */ |
|
66 |
|
67 /* Initialize the context manager once, and only once! */ |
|
68 if (Dll::Tls() == NULL) { |
|
69 /* Allocate and init array to hold context pointers */ |
|
70 contextArray = new NW_DictionaryContext_Array_t; |
|
71 |
|
72 /*lint -e{774} Boolean within 'if' always evaluates to False */ |
|
73 if (contextArray == NULL) { |
|
74 DestroyDictionaries(); |
|
75 return NW_STAT_OUT_OF_MEMORY; |
|
76 } |
|
77 |
|
78 contextArray->numContexts = NW_CONTEXT_NUM_ENTRIES; |
|
79 |
|
80 for (i = 0; i < NW_CONTEXT_NUM_ENTRIES; i++) { |
|
81 contextArray->contexts[i] = NULL; |
|
82 } |
|
83 |
|
84 /* Store the pointer to the context array */ |
|
85 if( Dll::SetTls( contextArray ) != KErrNone) |
|
86 { |
|
87 DestroyDictionaries(); |
|
88 } |
|
89 } |
|
90 |
|
91 return NW_STAT_SUCCESS; |
|
92 } |
|
93 |
|
94 |
|
95 /***************************************************************** |
|
96 |
|
97 Name: NW_Ctx_Set() |
|
98 |
|
99 Description: Set the context for the specified component |
|
100 |
|
101 Parameters: component - which context |
|
102 *ctx - pointer to the context to store |
|
103 |
|
104 Return Value: NW_STAT_SUCCESS or NW_STAT_FAILURE |
|
105 |
|
106 ******************************************************************/ |
|
107 NW_Status_t DictContext_Set(const NW_DictionaryContext_Id_t aContextId, |
|
108 void *ctx) |
|
109 { |
|
110 NW_Status_t status = NW_STAT_SUCCESS; |
|
111 NW_DictionaryContext_Array_t* contextArray; |
|
112 |
|
113 NW_ASSERT(aContextId < NW_CONTEXT_NUM_ENTRIES); |
|
114 |
|
115 /* Get the pointer to the context array */ |
|
116 contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
117 |
|
118 if (contextArray == NULL) { |
|
119 status = DictContext_Init(); |
|
120 if (status != NW_STAT_SUCCESS) { |
|
121 return status; |
|
122 } |
|
123 contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
124 } |
|
125 |
|
126 /* Save the aContextId's context */ |
|
127 if (contextArray != NULL) { |
|
128 /*lint -e{661} Possible access of out-of-bounds pointer */ |
|
129 contextArray->contexts[aContextId] = ctx; |
|
130 return NW_STAT_SUCCESS; |
|
131 } |
|
132 |
|
133 return status; |
|
134 } |
|
135 |
|
136 |
|
137 /***************************************************************** |
|
138 |
|
139 Name: DictContext_Get() |
|
140 |
|
141 Description: Get the context for the specified component |
|
142 |
|
143 Parameters: aContextId - which context |
|
144 |
|
145 Return Value: pointer to the component's context or NULL |
|
146 |
|
147 ******************************************************************/ |
|
148 void *DictContext_Get(const NW_DictionaryContext_Id_t aContextId) |
|
149 { |
|
150 NW_Status_t status; |
|
151 NW_DictionaryContext_Array_t* contextArray; |
|
152 |
|
153 /* Use "<=" rather than "<", as PushMtm tests last item for NULL */ |
|
154 NW_ASSERT(aContextId <= NW_CONTEXT_NUM_ENTRIES); |
|
155 |
|
156 /* Get the pointer to the context array */ |
|
157 contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
158 |
|
159 if (contextArray == NULL) { |
|
160 status = DictContext_Init(); |
|
161 if (status != NW_STAT_SUCCESS) { |
|
162 return NULL; |
|
163 } |
|
164 contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
165 } |
|
166 |
|
167 /* Return the component's context */ |
|
168 if (contextArray != NULL) { |
|
169 /*lint --e{661} Possible access of out-of-bounds pointer */ |
|
170 /*lint --e{662} Possible creation of out-of-bounds pointer */ |
|
171 return contextArray->contexts[aContextId]; |
|
172 } |
|
173 |
|
174 return NULL; |
|
175 } |
|
176 |
|
177 void DestroyDictionaries() |
|
178 { |
|
179 NW_DictionaryContext_Array_t* contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
180 |
|
181 if(contextArray) |
|
182 { |
|
183 |
|
184 /*Check the dictionary reference count. If it is zero |
|
185 * then free the dictionary. |
|
186 */ |
|
187 if(contextArray->contexts[NW_CONTEXT_REF_DICT_CNT] == 0) |
|
188 { |
|
189 NW_WBXML_Dictionary_t **dictionaries = GetDictionaries(); |
|
190 |
|
191 NW_Mem_Free(dictionaries); |
|
192 StoreDictionaries(NULL); |
|
193 StoreDictionaryCount(0); |
|
194 |
|
195 // Get the TLS pointer |
|
196 |
|
197 delete contextArray; |
|
198 contextArray = NULL; |
|
199 Dll::SetTls(contextArray); |
|
200 } |
|
201 }/*end if(contextArray)*/ |
|
202 } |
|
203 |
|
204 /* Temporary methods for storing dictionary & dictionary size inside the context. |
|
205 */ |
|
206 void StoreDictionaries(NW_WBXML_Dictionary_t** dictionaries) |
|
207 { |
|
208 DictContext_Set(NW_CONTEXT_DICTIONARY, (void*)dictionaries); |
|
209 |
|
210 } |
|
211 |
|
212 NW_WBXML_Dictionary_t** GetDictionaries() |
|
213 { |
|
214 return (NW_WBXML_Dictionary_t**)DictContext_Get(NW_CONTEXT_DICTIONARY); |
|
215 } |
|
216 |
|
217 void StoreDictionaryCount(NW_Uint32 dictionary_count) |
|
218 { |
|
219 DictContext_Set(NW_CONTEXT_DICTIONARY_COUNT, (void*)dictionary_count); |
|
220 |
|
221 } |
|
222 |
|
223 NW_Uint32 GetDictionaryCount() |
|
224 { |
|
225 NW_Uint32 count = (NW_Uint32)DictContext_Get(NW_CONTEXT_DICTIONARY_COUNT); |
|
226 |
|
227 return count; |
|
228 |
|
229 } |
|
230 |
|
231 |
|
232 void UpdateDictRefCnt(CXML_DICT_REF_CNT updateVal) |
|
233 { |
|
234 NW_DictionaryContext_Array_t* contextArray; |
|
235 NW_Uint32 refCount = 0; |
|
236 |
|
237 /* Get the pointer to the context array */ |
|
238 |
|
239 contextArray = (NW_DictionaryContext_Array_t*)Dll::Tls(); |
|
240 |
|
241 if(contextArray != NULL) |
|
242 { |
|
243 refCount = (NW_Uint32) contextArray->contexts[NW_CONTEXT_REF_DICT_CNT]; |
|
244 if(updateVal == NW_CONTEXT_REF_DICT_CNT_INR) |
|
245 { |
|
246 contextArray->contexts[NW_CONTEXT_REF_DICT_CNT] = |
|
247 (void*)++refCount; |
|
248 } |
|
249 else if(updateVal == NW_CONTEXT_REF_DICT_CNT_DCR) |
|
250 { |
|
251 contextArray->contexts[NW_CONTEXT_REF_DICT_CNT] = |
|
252 (void*)--refCount; |
|
253 } |
|
254 |
|
255 }/*end if(contextArray != NULL)*/ |
|
256 return; |
|
257 }/*end UpdateDictRefCnt(CXML_DICT_REF_CNT updateVal)*/ |
|
258 |
|
259 |
|
260 // |
|
261 //For Non DTD element support and checking for other features in the release |
|
262 // |
|
263 |
|
264 EXPORT_C |
|
265 CXML_Int32 CXML_Additional_Feature_Supprted() |
|
266 { |
|
267 |
|
268 CXML_Int32 featureFlag = 0; |
|
269 |
|
270 featureFlag |= CXML_DTD_SUPPORT_ON; |
|
271 |
|
272 /* The feature manager not supported. May be hook up for future use. |
|
273 |
|
274 CXML_Bool retVal = CXML_TRUE; |
|
275 |
|
276 FeatureManager::InitializeLibL(); |
|
277 |
|
278 if(FeatureManager::FeatureSupported(KFeatureIdEcmaScript) ) |
|
279 { |
|
280 retVal = CXML_TRUE; |
|
281 } |
|
282 else |
|
283 { |
|
284 retVal = CXML_FALSE; |
|
285 } |
|
286 |
|
287 |
|
288 retVal = CXML_TRUE; |
|
289 |
|
290 return retVal; |
|
291 */ |
|
292 |
|
293 return featureFlag; |
|
294 |
|
295 }//end CXML_Non_DTD_supprted() |
|
296 |
|