|
1 /* |
|
2 * Copyright (c) 2005 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: XDM Engine |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <utf.h> |
|
23 #include <ecom.h> |
|
24 #include <f32file.h> |
|
25 #include <flogger.h> |
|
26 #include "XdmEngine.h" |
|
27 #include "XdmDocument.h" |
|
28 #include "XdmProtocol.h" |
|
29 #include "XdmDirectory.h" |
|
30 #include "XdmLogWriter.h" |
|
31 #include "XdmStaticUtils.h" |
|
32 #include "XdmSettingsApi.h" |
|
33 #include "XdmProtocolInfo.h" |
|
34 |
|
35 // ---------------------------------------------------------- |
|
36 // CXdmEngine::CXdmEngine |
|
37 // |
|
38 // ---------------------------------------------------------- |
|
39 // |
|
40 CXdmEngine::CXdmEngine() : CActive( EPriorityStandard ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------- |
|
45 // CXdmEngine::NewL |
|
46 // |
|
47 // ---------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CXdmEngine* CXdmEngine::NewL( const CXdmProtocolInfo& aProtocolInfo ) |
|
50 { |
|
51 CXdmEngine* self = new ( ELeave ) CXdmEngine(); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL( CONST_CAST( CXdmProtocolInfo&, aProtocolInfo ) ); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------- |
|
59 // CXdmEngine::XdmSettingsLC |
|
60 // |
|
61 // ---------------------------------------------------------- |
|
62 // |
|
63 EXPORT_C CDesC16Array* CXdmEngine::XdmSettingsLC( RArray<TInt>& aSettingIds ) |
|
64 { |
|
65 return TXdmSettingsApi::CollectionNamesLC( aSettingIds ); |
|
66 } |
|
67 |
|
68 // ---------------------------------------------------------- |
|
69 // CXdmEngine::ConstructL |
|
70 // |
|
71 // ---------------------------------------------------------- |
|
72 // |
|
73 void CXdmEngine::ConstructL( CXdmProtocolInfo& aProtocolInfo ) |
|
74 { |
|
75 #ifdef _DEBUG |
|
76 iLogWriter = CXdmLogWriter::NewL( KXdmEngLogFile ); |
|
77 WriteToLog( _L8( "CXdmEngine::ConstructL()" ) ); |
|
78 #endif |
|
79 TRAPD( error, iXdmProtocol = CXdmProtocol::NewL( *this, aProtocolInfo ) ); |
|
80 if( error == KErrNone && iXdmProtocol != NULL ) |
|
81 { |
|
82 #ifdef _DEBUG |
|
83 WriteToLog( _L8( " Protocol implementation created successfully" ) ); |
|
84 #endif |
|
85 CActiveScheduler::Add( this ); |
|
86 } |
|
87 else |
|
88 { |
|
89 #ifdef _DEBUG |
|
90 WriteToLog( _L8( " Protocol creation failed - Error: %d Protocol: %x" ), error, iXdmProtocol ); |
|
91 #endif |
|
92 User::Leave( KErrUnknown ); |
|
93 } |
|
94 } |
|
95 |
|
96 // ---------------------------------------------------- |
|
97 // CXdmEngine::~CXdmEngine |
|
98 // |
|
99 // ---------------------------------------------------- |
|
100 // |
|
101 CXdmEngine::~CXdmEngine() |
|
102 { |
|
103 #ifdef _DEBUG |
|
104 WriteToLog( _L8( "CXdmEngine::~CXdmEngine()" ) ); |
|
105 #endif |
|
106 iDocUpdateQueue.Close(); |
|
107 iDirUpdateQueue.Close(); |
|
108 iDocumentQueue.Close(); |
|
109 iDirectoryQueue.Close(); |
|
110 #ifdef _DEBUG |
|
111 WriteToLog( _L8( " Queues closed" ) ); |
|
112 #endif |
|
113 delete iXdmProtocol; |
|
114 #ifdef _DEBUG |
|
115 WriteToLog( _L8( " Protocol deleted" ) ); |
|
116 #endif |
|
117 REComSession::FinalClose(); |
|
118 #ifdef _DEBUG |
|
119 WriteToLog( _L8( " Destructor finished" ) ); |
|
120 #endif |
|
121 delete iLogWriter; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------- |
|
125 // CXdmEngine::WriteToLog |
|
126 // |
|
127 // ---------------------------------------------------------- |
|
128 // |
|
129 void CXdmEngine::WriteToLog( TRefByValue<const TDesC8> aFmt,... ) const |
|
130 { |
|
131 VA_LIST list; |
|
132 VA_START( list, aFmt ); |
|
133 TBuf8<KLogBufferMaxSize> buf; |
|
134 buf.FormatList( aFmt, list ); |
|
135 iLogWriter->WriteToLog( buf ); |
|
136 } |
|
137 |
|
138 // ---------------------------------------------------- |
|
139 // CXdmEngine::DirectoryCollection |
|
140 // |
|
141 // ---------------------------------------------------- |
|
142 // |
|
143 EXPORT_C const RPointerArray<CXdmDocument>& CXdmEngine::DocumentCollection() const |
|
144 { |
|
145 return iDocumentQueue; |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------- |
|
149 // CXdmEngine::DirectoryCollection |
|
150 // |
|
151 // ---------------------------------------------------- |
|
152 // |
|
153 EXPORT_C const RPointerArray<CXdmDirectory>& CXdmEngine::DirectoryCollection() const |
|
154 { |
|
155 return iDirectoryQueue; |
|
156 } |
|
157 |
|
158 |
|
159 // ---------------------------------------------------- |
|
160 // CXdmEngine::CancelUpdate |
|
161 // |
|
162 // ---------------------------------------------------- |
|
163 // |
|
164 EXPORT_C void CXdmEngine::CancelUpdate( CXdmDocument* aDocument ) |
|
165 { |
|
166 #ifdef _DEBUG |
|
167 WriteToLog( _L8( "CXdmEngine::CancelUpdate( document )" ) ); |
|
168 #endif |
|
169 TInt index = iDocumentQueue.Find( aDocument ); |
|
170 if( IsActive() ) |
|
171 { |
|
172 #ifdef _DEBUG |
|
173 WriteToLog( _L8( " Transfer media init pending, cancel self" ) ); |
|
174 #endif |
|
175 Cancel(); |
|
176 } |
|
177 else if( index != KErrNotFound && aDocument->IsActive() ) |
|
178 { |
|
179 #ifdef _DEBUG |
|
180 WriteToLog( _L8( " Cancel document update" ) ); |
|
181 #endif |
|
182 aDocument->CancelUpdate(); |
|
183 if( iDocUpdateQueue.Find( aDocument ) == KErrNone ) |
|
184 iDocUpdateQueue.Remove( index ); |
|
185 } |
|
186 } |
|
187 |
|
188 // ---------------------------------------------------- |
|
189 // CXdmEngine::CancelUpdate |
|
190 // |
|
191 // ---------------------------------------------------- |
|
192 // |
|
193 EXPORT_C void CXdmEngine::CancelUpdate( CXdmDirectory* aDirectory ) |
|
194 { |
|
195 #ifdef _DEBUG |
|
196 WriteToLog( _L8( "CXdmEngine::CancelUpdate( directory )" ) ); |
|
197 #endif |
|
198 TInt index = iDirectoryQueue.Find( aDirectory ); |
|
199 if( IsActive() ) |
|
200 { |
|
201 #ifdef _DEBUG |
|
202 WriteToLog( _L8( " Transfer media init pending, cancel self" ) ); |
|
203 #endif |
|
204 Cancel(); |
|
205 } |
|
206 else if( index != KErrNotFound && aDirectory->IsActive() ) |
|
207 { |
|
208 #ifdef _DEBUG |
|
209 WriteToLog( _L8( " Cancel directory update" ) ); |
|
210 #endif |
|
211 aDirectory->CancelUpdate(); |
|
212 if( iDirUpdateQueue.Find( aDirectory ) == KErrNone ) |
|
213 iDirUpdateQueue.Remove( index ); |
|
214 } |
|
215 } |
|
216 |
|
217 // ---------------------------------------------------- |
|
218 // CXdmEngine::CreateDocumentModelL |
|
219 // |
|
220 // ---------------------------------------------------- |
|
221 // |
|
222 EXPORT_C CXdmDocument* CXdmEngine::CreateDocumentModelL( const TDesC& aDocumentName, |
|
223 const TXdmDocType aDocumentType ) |
|
224 { |
|
225 #ifdef _DEBUG |
|
226 WriteToLog( _L8( "CXdmEngine::CreateDocumentModelL()" ) ); |
|
227 #endif |
|
228 CXdmDocument* document = iXdmProtocol->CreateDocumentL( aDocumentName, aDocumentType ); |
|
229 CleanupStack::PushL( document ); |
|
230 User::LeaveIfError( iDocumentQueue.Append( document ) ); |
|
231 CleanupStack::Pop(); //document |
|
232 return document; |
|
233 } |
|
234 |
|
235 // ---------------------------------------------------- |
|
236 // CXdmEngine::DeleteDocumentModelL |
|
237 // |
|
238 // ---------------------------------------------------- |
|
239 // |
|
240 EXPORT_C void CXdmEngine::DeleteDocumentModelL( const CXdmDocument* aDocument ) |
|
241 { |
|
242 #ifdef _DEBUG |
|
243 WriteToLog( _L8( "CXdmEngine::DeleteDocumentModelL()" ) ); |
|
244 #endif |
|
245 TInt index = iDocumentQueue.Find( aDocument ); |
|
246 __ASSERT_ALWAYS( index != KErrNotFound, User::Leave( KErrNotFound ) ); |
|
247 iDocumentQueue.Remove( index ); |
|
248 delete aDocument; |
|
249 aDocument = NULL; |
|
250 } |
|
251 |
|
252 // ---------------------------------------------------- |
|
253 // CXdmEngine::CreateDirectoryModelL |
|
254 // |
|
255 // ---------------------------------------------------- |
|
256 // |
|
257 EXPORT_C CXdmDirectory* CXdmEngine::CreateDirectoryModelL( const TDesC& aDirectoryPath ) |
|
258 { |
|
259 #ifdef _DEBUG |
|
260 WriteToLog( _L8( "CXdmEngine::CreateDirectoryModelL()" ) ); |
|
261 #endif |
|
262 CXdmDirectory* directory = iXdmProtocol->CreateDirectoryL( aDirectoryPath ); |
|
263 CleanupStack::PushL( directory ); |
|
264 User::LeaveIfError( iDirectoryQueue.Append( directory ) ); |
|
265 CleanupStack::Pop(); //document |
|
266 return directory; |
|
267 } |
|
268 |
|
269 // ---------------------------------------------------- |
|
270 // CXdmEngine::DeleteDirectoryModelL |
|
271 // |
|
272 // ---------------------------------------------------- |
|
273 // |
|
274 EXPORT_C void CXdmEngine::DeleteDirectoryModelL( const CXdmDirectory* aDirectory ) |
|
275 { |
|
276 #ifdef _DEBUG |
|
277 WriteToLog( _L8( "CXdmEngine::DeleteDirectoryModelL()" ) ); |
|
278 #endif |
|
279 TInt index = iDirectoryQueue.Find( aDirectory ); |
|
280 __ASSERT_ALWAYS( index != KErrNotFound, User::Panic( _L( "CXdmEngine" ), EDirModelNotFound ) ); |
|
281 iDirectoryQueue.Remove( index ); |
|
282 delete aDirectory; |
|
283 aDirectory = NULL; |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------- |
|
287 // CXdmEngine::CreateDocumentNodeL |
|
288 // |
|
289 // ---------------------------------------------------- |
|
290 // |
|
291 EXPORT_C CXdmDocumentNode* CXdmEngine::CreateDocumentNodeL() |
|
292 { |
|
293 #ifdef _DEBUG |
|
294 WriteToLog( _L8( "CXdmEngine::CreateDocumentNodeL()" ) ); |
|
295 #endif |
|
296 return iXdmProtocol->CreateDocumentNodeL(); |
|
297 } |
|
298 |
|
299 // ---------------------------------------------------- |
|
300 // CXdmEngine::UpdateL |
|
301 // |
|
302 // ---------------------------------------------------- |
|
303 // |
|
304 EXPORT_C void CXdmEngine::UpdateL( CXdmDocument* aDocument, |
|
305 TRequestStatus& aStatus ) |
|
306 { |
|
307 #ifdef _DEBUG |
|
308 WriteToLog( _L8( "CXdmEngine::UpdateL( document )" ) ); |
|
309 #endif |
|
310 iClientStatus = &aStatus; |
|
311 aStatus = KRequestPending; |
|
312 aDocument->SaveClientStatus( aStatus ); |
|
313 User::LeaveIfError( iDocUpdateQueue.Append( aDocument ) ); |
|
314 if( !IsActive() ) |
|
315 { |
|
316 iXdmProtocol->InitTransferMedium( KDefaultIdleTimeout, iStatus ); |
|
317 SetActive(); |
|
318 } |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------- |
|
322 // CXdmEngine::UpdateL |
|
323 // |
|
324 // ---------------------------------------------------- |
|
325 // |
|
326 EXPORT_C void CXdmEngine::UpdateL( TRequestStatus& aStatus, |
|
327 CXdmDirectory* aDirectory, |
|
328 TDirUpdatePhase aUpdatePhase ) |
|
329 { |
|
330 #ifdef _DEBUG |
|
331 WriteToLog( _L8( "CXdmEngine::UpdateL( directory )" ) ); |
|
332 #endif |
|
333 iClientStatus = &aStatus; |
|
334 aStatus = KRequestPending; |
|
335 aDirectory->SaveRequestData( aUpdatePhase, aStatus ); |
|
336 User::LeaveIfError( iDirUpdateQueue.Append( aDirectory ) ); |
|
337 if( !IsActive() ) |
|
338 { |
|
339 iXdmProtocol->InitTransferMedium( KDefaultIdleTimeout, iStatus ); |
|
340 SetActive(); |
|
341 } |
|
342 } |
|
343 |
|
344 // --------------------------------------------------------- |
|
345 // CXdmEngine::RunL |
|
346 // |
|
347 // --------------------------------------------------------- |
|
348 // |
|
349 void CXdmEngine::RunL() |
|
350 { |
|
351 #ifdef _DEBUG |
|
352 WriteToLog( _L8( "CXdmEngine::RunL() - Status: %d" ), iStatus.Int() ); |
|
353 #endif |
|
354 if( iStatus == KErrCancel ) |
|
355 { |
|
356 #ifdef _DEBUG |
|
357 WriteToLog( _L8( " Update cancelled, complete client request" ) ); |
|
358 #endif |
|
359 if( iClientStatus ) |
|
360 { |
|
361 iDocUpdateQueue.Reset(); |
|
362 iDirUpdateQueue.Reset(); |
|
363 User::RequestComplete( iClientStatus, KErrCancel ); |
|
364 #ifdef _DEBUG |
|
365 WriteToLog( _L8( " Request complete" ) ); |
|
366 #endif |
|
367 } |
|
368 } |
|
369 else |
|
370 { |
|
371 #ifdef _DEBUG |
|
372 WriteToLog( _L8( " Transfer media initialised, start update" ) ); |
|
373 #endif |
|
374 TInt dirCount( iDirUpdateQueue.Count() ); |
|
375 TInt docCount( iDocUpdateQueue.Count() ); |
|
376 #ifdef _DEBUG |
|
377 WriteToLog( _L8( " Document queue count: %d" ), docCount ); |
|
378 WriteToLog( _L8( " Directory queue count: %d" ), dirCount ); |
|
379 #endif |
|
380 //First check the document queue |
|
381 for( TInt i = 0;i < docCount;i++ ) |
|
382 { |
|
383 iDocUpdateQueue[0]->StartUpdateL(); |
|
384 iDocUpdateQueue.Remove( 0 ); |
|
385 } |
|
386 //Then the directory queue |
|
387 for( TInt j = 0;j < dirCount;j++ ) |
|
388 { |
|
389 iDirUpdateQueue[0]->StartUpdateL(); |
|
390 iDirUpdateQueue.Remove( 0 ); |
|
391 } |
|
392 } |
|
393 } |
|
394 |
|
395 // --------------------------------------------------------- |
|
396 // CXdmEngine::DoCancel |
|
397 // |
|
398 // --------------------------------------------------------- |
|
399 // |
|
400 void CXdmEngine::DoCancel() |
|
401 { |
|
402 #ifdef _DEBUG |
|
403 WriteToLog( _L8( "CXdmEngine::DoCancel()" ) ); |
|
404 #endif |
|
405 iXdmProtocol->CancelTransferMediumInit(); |
|
406 if( iClientStatus ) |
|
407 { |
|
408 #ifdef _DEBUG |
|
409 WriteToLog( _L8( " Client request pending => Complete" ) ); |
|
410 #endif |
|
411 iDocUpdateQueue.Reset(); |
|
412 iDirUpdateQueue.Reset(); |
|
413 User::RequestComplete( iClientStatus, KErrCancel ); |
|
414 } |
|
415 } |
|
416 |
|
417 // --------------------------------------------------------- |
|
418 // CXdmEngine::XdmProtocol |
|
419 // |
|
420 // --------------------------------------------------------- |
|
421 // |
|
422 CXdmProtocol* CXdmEngine::XdmProtocol() const |
|
423 { |
|
424 #ifdef _DEBUG |
|
425 WriteToLog( _L8( "CXdmEngine::XdmProtocol()" ) ); |
|
426 #endif |
|
427 return iXdmProtocol; |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------- |
|
431 // CXdmEngine::ConvertToUTF8L |
|
432 // |
|
433 // --------------------------------------------------------- |
|
434 // |
|
435 HBufC8* CXdmEngine::ConvertToUTF8L( const TDesC& aUnicodeDesc ) |
|
436 { |
|
437 /*#ifdef _DEBUG |
|
438 WriteToLog( _L8( "CXdmEngine::ConvertToUTF8L()" ) ); |
|
439 #endif*/ |
|
440 return CnvUtfConverter::ConvertFromUnicodeToUtf8L( aUnicodeDesc ); |
|
441 } |
|
442 |
|
443 |
|
444 |
|
445 |
|
446 |