|
1 /* |
|
2 * Copyright (c) 2006-2008 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 "ncdcreateaccesspointoperationimpl.h" |
|
20 |
|
21 #include <s32mem.h> |
|
22 #include <apmstd.h> |
|
23 |
|
24 #include "catalogsbasemessage.h" |
|
25 #include "catalogsutils.h" |
|
26 #include "catalogscontext.h" |
|
27 #include "catalogsaccesspointmanager.h" |
|
28 #include "ncdproviderdefines.h" |
|
29 #include "ncdparserfactory.h" |
|
30 #include "ncdparser.h" |
|
31 |
|
32 #include "ncd_cp_query.h" |
|
33 #include "ncd_cp_queryelement.h" |
|
34 #include "ncd_cp_queryoption.h" |
|
35 #include "ncd_cp_detail.h" |
|
36 #include "ncd_cp_clientconfiguration.h" |
|
37 #include "ncd_cp_error.h" |
|
38 #include "ncd_cp_serverdetails.h" |
|
39 #include "ncd_cp_actionrequest.h" |
|
40 #include "ncd_cp_queryresponseimpl.h" |
|
41 #include "ncdparserimpl.h" |
|
42 #include "ncd_parser_cp_clientconfiguration.h" |
|
43 #include "ncdgeneralmanager.h" |
|
44 |
|
45 #include "catalogsdebug.h" |
|
46 |
|
47 // ======== MEMBER FUNCTIONS ======== |
|
48 |
|
49 // --------------------------------------------------------------------------- |
|
50 // NewL |
|
51 // --------------------------------------------------------------------------- |
|
52 // |
|
53 CNcdCreateAccessPointOperation* CNcdCreateAccessPointOperation::NewL( |
|
54 HBufC* aAccessPointData, |
|
55 MNcdOperationRemoveHandler& aRemoveHandler, |
|
56 CNcdGeneralManager& aGeneralManager, |
|
57 MCatalogsSession& aSession ) |
|
58 { |
|
59 CNcdCreateAccessPointOperation* self = |
|
60 new( ELeave ) CNcdCreateAccessPointOperation( |
|
61 aRemoveHandler, |
|
62 aGeneralManager, |
|
63 aSession ); |
|
64 |
|
65 CleanupClosePushL( *self ); |
|
66 self->ConstructL( aAccessPointData ); |
|
67 CleanupStack::Pop(); |
|
68 return self; |
|
69 } |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // Destructor |
|
74 // --------------------------------------------------------------------------- |
|
75 // |
|
76 CNcdCreateAccessPointOperation::~CNcdCreateAccessPointOperation() |
|
77 { |
|
78 DLTRACEIN(( "" )); |
|
79 delete iParser; |
|
80 delete iAccessPointData; |
|
81 |
|
82 } |
|
83 |
|
84 |
|
85 // --------------------------------------------------------------------------- |
|
86 // Cancel |
|
87 // --------------------------------------------------------------------------- |
|
88 // |
|
89 void CNcdCreateAccessPointOperation::Cancel() |
|
90 { |
|
91 DLTRACEIN(( "" )); |
|
92 if ( iParser ) |
|
93 { |
|
94 iParser->CancelParsing(); |
|
95 } |
|
96 iOperationState = EStateCancelled; |
|
97 |
|
98 } |
|
99 |
|
100 |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 // --------------------------------------------------------------------------- |
|
104 // |
|
105 void CNcdCreateAccessPointOperation::ParseError( TInt aErrorCode ) |
|
106 { |
|
107 DLTRACEIN(("error:%d", aErrorCode )); |
|
108 |
|
109 // Handle error only if not handling an error already |
|
110 // (cancellation of parsing may cause an unnecessary call to this function). |
|
111 if( iError == KErrNone ) |
|
112 { |
|
113 iError = aErrorCode; |
|
114 |
|
115 if ( iParser ) |
|
116 { |
|
117 iParser->CancelParsing(); |
|
118 } |
|
119 |
|
120 iOperationState = EStateComplete; |
|
121 RunOperation(); |
|
122 } |
|
123 } |
|
124 |
|
125 // --------------------------------------------------------------------------- |
|
126 // ?implementation_description |
|
127 // --------------------------------------------------------------------------- |
|
128 // |
|
129 void CNcdCreateAccessPointOperation::ParseCompleteL( TInt aError ) |
|
130 { |
|
131 DLTRACEIN(("error: %d", aError )); |
|
132 |
|
133 if ( aError == KErrNone ) |
|
134 { |
|
135 ParseAccessPointDataL(); |
|
136 } |
|
137 |
|
138 delete iParser; |
|
139 iParser = NULL; |
|
140 |
|
141 iOperationState = EStateComplete; |
|
142 iError = aError; |
|
143 |
|
144 RunOperation(); |
|
145 } |
|
146 |
|
147 |
|
148 // --------------------------------------------------------------------------- |
|
149 // RunOperation |
|
150 // --------------------------------------------------------------------------- |
|
151 // |
|
152 TInt CNcdCreateAccessPointOperation::RunOperation() |
|
153 { |
|
154 DLTRACEIN(( "Pending message: %X", iPendingMessage )); |
|
155 |
|
156 if ( !iPendingMessage ) |
|
157 { |
|
158 DLTRACE(("No pending message")); |
|
159 return KErrNotReady; |
|
160 } |
|
161 |
|
162 // One trap to rule them all |
|
163 TRAPD( err, HandleStateL() ); |
|
164 |
|
165 HandleError( err ); |
|
166 DLTRACEOUT(("err: %d", err)); |
|
167 return err; |
|
168 } |
|
169 |
|
170 |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 // --------------------------------------------------------------------------- |
|
174 // |
|
175 void CNcdCreateAccessPointOperation::HandleStateL() |
|
176 { |
|
177 DLTRACEIN(("")); |
|
178 switch( iOperationState ) |
|
179 { |
|
180 case EStateRunning: |
|
181 { |
|
182 StartParsingL(); |
|
183 break; |
|
184 } |
|
185 |
|
186 |
|
187 case EStateComplete: |
|
188 { |
|
189 if ( !iError && !iAccessPoint ) |
|
190 { |
|
191 DLERROR(("No accesspoint was created, error KErrNotFound")); |
|
192 iError = KErrNotFound; |
|
193 } |
|
194 |
|
195 // Returns false if there was no error |
|
196 if ( !HandleError( iError ) ) |
|
197 { |
|
198 DLTRACE(("Completing the operation")); |
|
199 iProgress.iProgress = iAccessPoint; |
|
200 CNcdBaseOperation::CompleteMessage( |
|
201 iPendingMessage, |
|
202 ENCDOperationMessageCompletionComplete, |
|
203 iProgress, |
|
204 KErrNone ); |
|
205 } |
|
206 break; |
|
207 } |
|
208 |
|
209 default: |
|
210 { |
|
211 DLTRACE(("Default")); |
|
212 break; |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 TBool CNcdCreateAccessPointOperation::HandleError( TInt aError ) |
|
223 { |
|
224 DLTRACEIN(("aError: %d", aError )); |
|
225 if ( aError != KErrNone ) |
|
226 { |
|
227 DLERROR(("Error %d occurred", aError )); |
|
228 iError = aError; |
|
229 iOperationState = EStateCancelled; |
|
230 Cancel(); |
|
231 if ( iPendingMessage ) |
|
232 { |
|
233 // ignoring error because operation already failed |
|
234 CNcdBaseOperation::CompleteMessage( iPendingMessage, |
|
235 ENCDOperationMessageCompletionError, iError ); |
|
236 } |
|
237 return ETrue; |
|
238 } |
|
239 return EFalse; |
|
240 } |
|
241 |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 void CNcdCreateAccessPointOperation::StartParsingL() |
|
248 { |
|
249 DLTRACEIN(("")); |
|
250 // create parser |
|
251 delete iParser; |
|
252 iParser = NULL; |
|
253 iParser = NcdParserFactory::CreateParserL( NULL ); |
|
254 |
|
255 MNcdParserObserverBundle& observers = iParser->Observers(); |
|
256 observers.SetParserObserver( this ); |
|
257 |
|
258 |
|
259 iSubParser = |
|
260 CNcdConfigurationProtocolClientConfigurationParser::NewL( |
|
261 observers, *static_cast<CNcdParserImpl*>( iParser ), 0 ); |
|
262 |
|
263 iParser->BeginAsyncL( iSubParser ); // ownership is transferred |
|
264 |
|
265 DLTRACE(("Start parsing the data")); |
|
266 iParser->ParseL( *iAccessPointData ); |
|
267 // Inform parser that no more data will be sent |
|
268 iParser->EndL(); |
|
269 } |
|
270 |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // ?implementation_description |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CNcdCreateAccessPointOperation::ParseAccessPointDataL() |
|
277 { |
|
278 DLTRACEIN(("")); |
|
279 // Ownership is transferred here |
|
280 MNcdConfigurationProtocolClientConfiguration* configuration = |
|
281 iSubParser->ClientConfiguration(); |
|
282 |
|
283 if ( !configuration ) |
|
284 { |
|
285 DLTRACEOUT(("No configuration")); |
|
286 return; |
|
287 } |
|
288 |
|
289 CleanupDeletePushL( configuration ); |
|
290 DASSERT( iPendingMessage ); |
|
291 |
|
292 RArray<TUint32> accesspoints; |
|
293 CleanupClosePushL( accesspoints ); |
|
294 // Parse access point data from client configuration response. |
|
295 iGeneralManager.AccessPointManager().ParseAccessPointDataFromClientConfL( |
|
296 *configuration, |
|
297 iPendingMessage->Session().Context().FamilyId(), |
|
298 ETrue, |
|
299 &accesspoints ); |
|
300 |
|
301 iAccessPoint = 0; |
|
302 |
|
303 if ( accesspoints.Count() ) |
|
304 { |
|
305 DLTRACE(("%d accesspoints were created", accesspoints.Count() )); |
|
306 iAccessPoint = accesspoints[0]; |
|
307 DLTRACE(("iAccessPoint: %d", iAccessPoint )); |
|
308 } |
|
309 |
|
310 CleanupStack::PopAndDestroy( 2, configuration ); // accesspoints, aConfiguration |
|
311 } |
|
312 |
|
313 |
|
314 // --------------------------------------------------------------------------- |
|
315 // Constructor |
|
316 // --------------------------------------------------------------------------- |
|
317 // |
|
318 CNcdCreateAccessPointOperation::CNcdCreateAccessPointOperation( |
|
319 MNcdOperationRemoveHandler& aRemoveHandler, |
|
320 CNcdGeneralManager& aGeneralManager, |
|
321 MCatalogsSession& aSession ) |
|
322 : |
|
323 CNcdBaseOperation( aGeneralManager, &aRemoveHandler, ECreateAccessPointOperation, |
|
324 aSession ) |
|
325 { |
|
326 } |
|
327 |
|
328 |
|
329 // --------------------------------------------------------------------------- |
|
330 // ConstructL |
|
331 // --------------------------------------------------------------------------- |
|
332 // |
|
333 void CNcdCreateAccessPointOperation::ConstructL( |
|
334 HBufC* aAccessPointData ) |
|
335 { |
|
336 DLTRACEIN( ( "" ) ); |
|
337 |
|
338 // Call ConstructL for the base class |
|
339 CNcdBaseOperation::ConstructL(); |
|
340 |
|
341 iAccessPointData = aAccessPointData; |
|
342 |
|
343 } |