|
1 /* |
|
2 * Copyright (c) 2008-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 "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: Utility class to manage attribute retrieval errors |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "glxerrormanager.h" |
|
22 |
|
23 //#include <glxerrors.h> |
|
24 |
|
25 #include "glxfetcherrorarray.h" |
|
26 #include "glxcachemanager.h" |
|
27 #include "glxmedialist.h" |
|
28 #include <glxtracer.h> // For Logs |
|
29 #include <glxlog.h> // For Logs |
|
30 |
|
31 /** Error attribute content ID */ |
|
32 const TInt KGlxErrorContentId = 0x200071AC; |
|
33 const TMPXAttributeData KGlxMediaErrorArray = { KGlxErrorContentId, 0x01 }; // CGlxFetchErrorArray |
|
34 |
|
35 const TInt KGlxErrorTimeOut = -10033; |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // Return errors |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 inline CGlxFetchErrorArray* Errors( const CGlxMedia& aMedia ) |
|
42 { |
|
43 TRACER("GlxErrorManager::Errors"); |
|
44 |
|
45 return const_cast<CGlxFetchErrorArray*>( |
|
46 static_cast<const CGlxFetchErrorArray*>( aMedia.ValueCObject( |
|
47 KGlxMediaErrorArray ) ) ); |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // SetAttributeErrorL |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void GlxErrorManager::SetAttributeErrorL(CGlxMedia* aItem, const RArray<TMPXAttribute>& aAttributes, TInt aError) |
|
55 { |
|
56 TRACER("GlxErrorManager::SetAttributeErrorL"); |
|
57 |
|
58 if ( aItem ) |
|
59 { |
|
60 CGlxFetchErrorArray* errorArray = NULL; |
|
61 |
|
62 if ( aItem->IsSupported(KGlxMediaErrorArray) ) |
|
63 { |
|
64 const CGlxFetchErrorArray* existingArray = static_cast<const CGlxFetchErrorArray*>(aItem->ValueCObject(KGlxMediaErrorArray)); |
|
65 |
|
66 if ( existingArray ) |
|
67 { |
|
68 errorArray = CGlxFetchErrorArray::NewLC(existingArray); |
|
69 } |
|
70 } |
|
71 |
|
72 if ( !errorArray ) |
|
73 { |
|
74 errorArray = new(ELeave) CGlxFetchErrorArray(); |
|
75 CleanupStack::PushL(errorArray); |
|
76 } |
|
77 |
|
78 TInt attrCount = aAttributes.Count(); |
|
79 |
|
80 for ( TInt attrIndex = 0; attrIndex < attrCount; attrIndex++ ) |
|
81 { |
|
82 errorArray->AddErrorL(TGlxFetchError(aAttributes[attrIndex], aError)); |
|
83 } |
|
84 |
|
85 aItem->SetCObjectValueL(KGlxMediaErrorArray, errorArray); |
|
86 |
|
87 CleanupStack::Pop(errorArray); |
|
88 } |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // HasAttributeErrorL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C TInt GlxErrorManager::HasAttributeErrorL(const CGlxMedia* aMedia, |
|
96 const TMPXAttribute& aAttribute) |
|
97 { |
|
98 TRACER("GlxErrorManager::HasAttributeErrorL"); |
|
99 |
|
100 TInt retVal = KErrNone; |
|
101 |
|
102 if ( aMedia ) |
|
103 { |
|
104 const CGlxFetchErrorArray* errors = Errors( *aMedia ); |
|
105 |
|
106 if ( errors ) |
|
107 { |
|
108 TInt index = errors->FindError(aAttribute); |
|
109 if ( KErrNotFound != index ) |
|
110 { |
|
111 TGlxFetchError error = errors->Error(index); |
|
112 retVal = error.iError; |
|
113 |
|
114 if ( IsExpired( error ) ) |
|
115 { |
|
116 retVal = KErrNone; |
|
117 } |
|
118 |
|
119 if ( KErrNone != retVal ) |
|
120 { |
|
121 if ( IsTemporaryError(retVal) ) |
|
122 { |
|
123 // Inform cache manager that at least one temporary error still exists |
|
124 CGlxCacheManager* cacheManager = CGlxCacheManager::InstanceL(); |
|
125 cacheManager->SetTemporaryErrorFlag(); |
|
126 cacheManager->Close(); |
|
127 } |
|
128 } |
|
129 } |
|
130 } |
|
131 } |
|
132 |
|
133 return retVal; |
|
134 } |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // HasAttributeErrorL |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 EXPORT_C TInt GlxErrorManager::HasAttributeErrorL(const CGlxMedia* aMedia, |
|
141 TInt aContentId) |
|
142 { |
|
143 TRACER("GlxErrorManager::HasAttributeErrorL"); |
|
144 |
|
145 TInt retVal = KErrNone; |
|
146 if ( aMedia ) |
|
147 { |
|
148 const CGlxFetchErrorArray* errors = Errors( *aMedia ); |
|
149 |
|
150 if ( errors ) |
|
151 { |
|
152 TInt index = errors->FindError(aContentId); |
|
153 if ( KErrNotFound != index ) |
|
154 { |
|
155 TGlxFetchError error = errors->Error(index); |
|
156 retVal = error.iError; |
|
157 |
|
158 if ( IsExpired( error ) ) |
|
159 { |
|
160 retVal = KGlxErrorTimeOut; |
|
161 } |
|
162 |
|
163 if ( KErrNone != retVal && KGlxErrorTimeOut != retVal) |
|
164 { |
|
165 if ( IsTemporaryError(retVal) ) |
|
166 { |
|
167 // Inform cache manager that at least one temporary error still exists |
|
168 CGlxCacheManager* cacheManager = CGlxCacheManager::InstanceL(); |
|
169 cacheManager->SetTemporaryErrorFlag(); |
|
170 cacheManager->Close(); |
|
171 } |
|
172 } |
|
173 } |
|
174 |
|
175 } |
|
176 } |
|
177 |
|
178 return retVal; |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // IsTemporaryError |
|
183 // ----------------------------------------------------------------------------- |
|
184 // |
|
185 TBool GlxErrorManager::IsTemporaryError(TInt aErrorCode) |
|
186 { |
|
187 TRACER("GlxErrorManager::IsTemporaryError"); |
|
188 GLX_DEBUG2("GlxErrorManager::IsTemporaryError() aErrorCode=%d", aErrorCode); |
|
189 |
|
190 /// @todo Implement this when list of temporary and permanent errors are known. Currently assume |
|
191 /// all errors are temporary |
|
192 switch ( aErrorCode ) |
|
193 { |
|
194 case KErrArgument: // fallthrough |
|
195 case KErrNotSupported: // fallthrough |
|
196 case KErrNoMemory: |
|
197 case KErrCorrupt: |
|
198 // add other permanent error codes here |
|
199 return EFalse; |
|
200 |
|
201 default: |
|
202 return ETrue; |
|
203 }; |
|
204 } |
|
205 |
|
206 // ----------------------------------------------------------------------------- |
|
207 // IsErrorStillVal |
|
208 // ----------------------------------------------------------------------------- |
|
209 // |
|
210 TBool GlxErrorManager::IsExpired( const TGlxFetchError& aError ) |
|
211 { |
|
212 TRACER("GlxErrorManager::IsExpired"); |
|
213 |
|
214 if ( IsTemporaryError(aError.iError) ) |
|
215 { |
|
216 TTime now; |
|
217 now.UniversalTime(); |
|
218 |
|
219 TTime errorTime(aError.iTimestamp); |
|
220 |
|
221 if ( now - TTimeIntervalSeconds(KGlxTemporaryErrorValidityPeriodInSeconds) > errorTime ) |
|
222 { |
|
223 return ETrue; |
|
224 } |
|
225 } |
|
226 |
|
227 return EFalse; |
|
228 } |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 // HasError |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 TBool GlxErrorManager::HasError(const CGlxMedia* aMedia) |
|
235 { |
|
236 TRACER("GlxErrorManager::HasError"); |
|
237 |
|
238 if ( aMedia ) |
|
239 { |
|
240 return ( Errors( *aMedia ) != NULL ); |
|
241 } |
|
242 |
|
243 return EFalse; |
|
244 } |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 // ClearExpiredAndUnusedErrorsL |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 void GlxErrorManager::ClearExpiredAndUnusedErrorsL( CGlxMedia& aMedia, |
|
251 const RArray<TMPXAttribute>& aAttributesInUse ) |
|
252 { |
|
253 TRACER("GlxErrorManager::ClearExpiredAndUnusedErrorsL"); |
|
254 |
|
255 CGlxFetchErrorArray* errors = Errors( aMedia ); |
|
256 |
|
257 if ( errors ) |
|
258 { |
|
259 // Iterate through the list of errors backwards, so that removal is more |
|
260 // efficient, and loop control easier |
|
261 for ( TInt i = errors->ErrorCount() - 1; i >= 0; i-- ) |
|
262 { |
|
263 TGlxFetchError error = errors->Error( i ); |
|
264 // remove the error if it has expired, or if the attribute |
|
265 // that the error is for is no longer in use |
|
266 if ( IsExpired( error ) || |
|
267 KErrNotFound == aAttributesInUse.Find( error.iAttr, TMPXAttribute::Match ) ) |
|
268 { |
|
269 errors->Remove( i ); |
|
270 } |
|
271 } |
|
272 |
|
273 // no further errors are remaining, so can remove the error array |
|
274 // attribute from the media object |
|
275 if ( errors->ErrorCount() == 0 ) |
|
276 { |
|
277 aMedia.DeleteAttribute( KGlxMediaErrorArray ); |
|
278 } |
|
279 } |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // Return error attribute's id |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 TMPXAttribute GlxErrorManager::ErrorAttribute() |
|
287 { |
|
288 TRACER("GlxErrorManager::ErrorAttribute"); |
|
289 |
|
290 return KGlxMediaErrorArray; |
|
291 } |