|
1 /* |
|
2 * Copyright (c) 2002-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: This file contains methofs which wraps functionality related |
|
15 * to landmark database initialization into a simpler interface. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include "Debug.h" |
|
27 #include "CLmkDbUtils.h" |
|
28 #include "CLmkDbInitializer.h" |
|
29 #include <lmkerrors.h> |
|
30 |
|
31 |
|
32 // CONSTANTS |
|
33 /// Unnamed namespace for local definitions |
|
34 namespace { |
|
35 // We wrap two async. tasks (db initialize and compress) into one |
|
36 // using estimated 0.2/0.8 progress distribution: |
|
37 const TReal32 KLmkInitMaxProgress( TReal32( 0.2 ) ); |
|
38 |
|
39 #if defined(_DEBUG) |
|
40 _LIT( KPanicMsg, "CLmkDbInitializer" ); |
|
41 |
|
42 void Panic( TPanicCode aReason ) |
|
43 { |
|
44 User::Panic( KPanicMsg, aReason ); |
|
45 } |
|
46 #endif |
|
47 } // namespace |
|
48 |
|
49 // ============================ MEMBER FUNCTIONS =============================== |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CLmkDbInitializer::CLmkDbInitializer |
|
53 // C++ default constructor can NOT contain any code, that |
|
54 // might leave. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CLmkDbInitializer::CLmkDbInitializer( |
|
58 MLmkAOOperationObserver& aObserver, |
|
59 TBool aProgressNote ) |
|
60 : iObserver( aObserver ), |
|
61 iProgressNote( aProgressNote ) |
|
62 { |
|
63 } |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CLmkDbInitializer::NewL |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 CLmkDbInitializer* CLmkDbInitializer::NewL( |
|
70 CPosLandmarkDatabase& aDb, |
|
71 MLmkAOOperationObserver& aObserver, |
|
72 TBool aProgressNote ) |
|
73 { |
|
74 CLmkDbInitializer* self = |
|
75 new ( ELeave ) CLmkDbInitializer( aObserver, aProgressNote ); |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL( aDb ); |
|
78 CleanupStack::Pop(); //self |
|
79 return self; |
|
80 } |
|
81 |
|
82 // ----------------------------------------------------------------------------- |
|
83 // CLmkDbInitializer::ConstructL |
|
84 // ----------------------------------------------------------------------------- |
|
85 // |
|
86 void CLmkDbInitializer::ConstructL( CPosLandmarkDatabase& aDb ) |
|
87 { |
|
88 iDbUtils = CLmkDbUtils::NewL( aDb, *this, iProgressNote ); |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CLmkDbInitializer::~CLmkDbInitializer |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 CLmkDbInitializer::~CLmkDbInitializer() |
|
96 { |
|
97 delete iDbUtils; // also cancels possibly ongoing operation |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CLmkDbInitializer::HandleOperationL |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CLmkDbInitializer::HandleOperationL( |
|
105 TOperationTypes aType, |
|
106 TReal32 aProgress, |
|
107 TInt aStatus ) |
|
108 { |
|
109 DEBUG2( CLmkDbInitializer::HandleOperationL entered: progress=%d status=%d, |
|
110 aProgress, aStatus ); |
|
111 |
|
112 __ASSERT_DEBUG( aType == EInitialize, |
|
113 Panic( KLmkPanicUnknownOperation ) ); |
|
114 |
|
115 // Modify progress information because we have wrapped two tasks into one: |
|
116 if ( aType == EInitialize && aStatus == KPosLmOperationNotComplete ) |
|
117 { |
|
118 aProgress = aProgress * KLmkInitMaxProgress; |
|
119 } |
|
120 |
|
121 if( iProgressNote || aStatus != KPosLmOperationNotComplete ) |
|
122 { |
|
123 // Caller either requested to receive all events, or we |
|
124 // have completed entirely and inform that to the caller. |
|
125 |
|
126 /* |
|
127 *In the called method 'aProgress' is not used |
|
128 *This code change of passing '0' instead of aPrgress is |
|
129 *because of compiler error for winscw-urel target |
|
130 *and this is a temparary fix |
|
131 */ |
|
132 //iObserver.HandleOperationL( EInitAndCompact, aProgress, aStatus ); |
|
133 iObserver.HandleOperationL( EInitialize, 0, aStatus ); |
|
134 } |
|
135 } |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CLmkDbInitializer::StartInitAndCompactL |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 void CLmkDbInitializer::StartInitAndCompactL() |
|
142 { |
|
143 DEBUG( CLmkDbInitializer::StartInitAndCompactL entered ); |
|
144 iDbUtils->InitializeDbL(); |
|
145 } |
|
146 |
|
147 // End of File |