|
1 /* |
|
2 * Copyright (c) 2002 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CWPWimHandler.h" |
|
21 #include <e32std.h> |
|
22 #include "CWPEngine.pan" |
|
23 // #include "SimApiTest.h" |
|
24 #include <ProvSC.h> |
|
25 #include "MWPWimObserver.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CWPWimHandler::CWPWimHandler |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CWPWimHandler::CWPWimHandler( MWPWimObserver& aObserver ) |
|
36 : CActive( EPriorityIdle ), iObserver( aObserver ), |
|
37 iClientInitialized( EFalse ), iProvData( 0, 0 ), iFileType( EBootStrap) |
|
38 { |
|
39 } |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CWPWimHandler::ConstructL |
|
43 // Symbian 2nd phase constructor can leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CWPWimHandler::ConstructL() |
|
47 { |
|
48 CActiveScheduler::Add( this ); |
|
49 // iFileLoader = CSimApiTest::NewL(); |
|
50 |
|
51 iFileLoader = CWimOMAProv::NewL(); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CWPWimHandler::NewL |
|
56 // Two-phased constructor. |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 CWPWimHandler* CWPWimHandler::NewL( MWPWimObserver& aObserver ) |
|
60 { |
|
61 CWPWimHandler* handler = CWPWimHandler::NewLC( aObserver ); |
|
62 CleanupStack::Pop(); |
|
63 return handler; |
|
64 } |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CWPWimHandler::NewLC |
|
68 // Two-phased constructor. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CWPWimHandler* CWPWimHandler::NewLC( MWPWimObserver& aObserver ) |
|
72 { |
|
73 CWPWimHandler* self = new( ELeave ) CWPWimHandler( aObserver ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 return self; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CWPWimHandler::~CWPWimHandler |
|
81 // Destructor |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 CWPWimHandler::~CWPWimHandler() |
|
85 { |
|
86 Cancel(); // CActive |
|
87 delete iFileLoader; |
|
88 delete iProvisioningDoc; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CWPWimHandler::RunL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CWPWimHandler::RunL() |
|
96 { |
|
97 switch( iPhase ) |
|
98 { |
|
99 case EInitialize: |
|
100 { |
|
101 if( iStatus == KErrNone ) |
|
102 { |
|
103 Retrieve(); // ready to read the actual document |
|
104 } |
|
105 else |
|
106 { |
|
107 iObserver.ReadErrorL(); |
|
108 } |
|
109 break; |
|
110 } |
|
111 case EGetSize: |
|
112 { |
|
113 if (iFileSize > 0 && iStatus == KErrNone ) |
|
114 { |
|
115 iProvisioningDoc = HBufC8::NewL( iFileSize ); |
|
116 // get the provisioningdoc from sim card, use first accessible |
|
117 // file type (EBootStrap, EConfig1, EConfig2) |
|
118 iProvData.Set(iProvisioningDoc->Des()) ; |
|
119 iFileLoader->Retrieve( iFileType, iProvData, iStatus ); |
|
120 iPhase = ERetrieve; |
|
121 SetActive(); |
|
122 } |
|
123 else // try to get another type |
|
124 { |
|
125 TBool tryToRead( ETrue ); |
|
126 switch( iFileType ) |
|
127 { |
|
128 case EBootStrap: |
|
129 { |
|
130 iFileType = EConfig1; |
|
131 } |
|
132 break; |
|
133 case EConfig1: |
|
134 { |
|
135 iFileType = EConfig2; |
|
136 } |
|
137 break; |
|
138 default: |
|
139 { |
|
140 tryToRead = EFalse; |
|
141 } |
|
142 break; |
|
143 } |
|
144 if( tryToRead ) |
|
145 { |
|
146 iFileLoader->GetSize( iFileSize, iFileType, iStatus ); |
|
147 iPhase = EGetSize; |
|
148 SetActive(); |
|
149 } |
|
150 else |
|
151 { |
|
152 iObserver.ReadErrorL(); |
|
153 } |
|
154 } |
|
155 break; |
|
156 } |
|
157 case ERetrieve: |
|
158 { |
|
159 if( iStatus==KErrNone ) |
|
160 { |
|
161 iObserver.ReadCompletedL(); |
|
162 } |
|
163 else |
|
164 { |
|
165 iObserver.ReadErrorL(); |
|
166 } |
|
167 break; |
|
168 } |
|
169 default: |
|
170 { |
|
171 break; |
|
172 } |
|
173 } |
|
174 } |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // CWPWimHandler::DoCancel |
|
178 // Cancel active request |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CWPWimHandler::DoCancel() |
|
182 { |
|
183 TRAPD( ignoreError, iObserver.ReadCancelledL() ); |
|
184 if (ignoreError) ignoreError = KErrNone; |
|
185 switch( iPhase ) |
|
186 { |
|
187 case EInitialize: |
|
188 { |
|
189 iFileLoader->CancelInitialize(); |
|
190 break; |
|
191 } |
|
192 case EGetSize: |
|
193 { |
|
194 iFileLoader->CancelGetSize(); |
|
195 break; |
|
196 } |
|
197 case ERetrieve: |
|
198 { |
|
199 iFileLoader->CancelRetrieve(); |
|
200 break; |
|
201 } |
|
202 default: |
|
203 { |
|
204 break; |
|
205 } |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CWPWimHandler::ReadProvFile(); |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CWPWimHandler::ReadProvFile() |
|
214 { |
|
215 if(!iClientInitialized) |
|
216 { |
|
217 iPhase = EInitialize; |
|
218 iFileLoader->Initialize( iStatus ); |
|
219 SetActive(); |
|
220 } |
|
221 } |
|
222 |
|
223 void CWPWimHandler::Retrieve() |
|
224 { |
|
225 if( iProvisioningDoc ) |
|
226 { |
|
227 delete iProvisioningDoc; |
|
228 iProvisioningDoc = NULL; |
|
229 } |
|
230 // 1. try to get the size of the first possible filetype |
|
231 iFileType = EBootStrap; |
|
232 iFileLoader->GetSize( iFileSize, iFileType, iStatus ); |
|
233 iPhase = EGetSize; |
|
234 SetActive(); |
|
235 // 2. other types are tried and read in RunL |
|
236 } |
|
237 |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CWPWimHandler::DocLength(); |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 TInt CWPWimHandler::DocLength() |
|
244 { |
|
245 return iProvisioningDoc->Length(); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CWPWimHandler::Doc(); |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 HBufC8* CWPWimHandler::DocL() |
|
253 { |
|
254 return iProvisioningDoc->AllocL(); |
|
255 } |
|
256 |
|
257 // End of File |