|
1 /* |
|
2 * Copyright (c) 2000 - 2006 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: Device Management Adapter Engine. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <utf.h> |
|
20 #include <sysutil.h> |
|
21 |
|
22 #include "dmadengine.h" |
|
23 #include "dmadcommand.h" |
|
24 #include "dmadutil.h" |
|
25 #include "vpnlogger.h" |
|
26 |
|
27 //=================================================================================================== |
|
28 |
|
29 |
|
30 |
|
31 //=================================================================================================== |
|
32 |
|
33 DMAD_EXPORT_C CDmAdEngine* CDmAdEngine::NewL(MDmAdCallBack* aDmAdCallBack, |
|
34 MDmAdStoreApi* aStoreApi, |
|
35 MDmAdDdfApi* aDdfApi, |
|
36 MDmAdRtNodeDataApi* aRtNodeDataApi) |
|
37 { |
|
38 TRACE("CDmAdEngine::NewL"); |
|
39 |
|
40 CDmAdEngine* self = NewLC(aDmAdCallBack, aStoreApi, aDdfApi, aRtNodeDataApi); |
|
41 CleanupStack::Pop(); |
|
42 return self; |
|
43 } |
|
44 |
|
45 DMAD_EXPORT_C CDmAdEngine* CDmAdEngine::NewLC(MDmAdCallBack* aDmAdCallBack, |
|
46 MDmAdStoreApi* aStoreApi, |
|
47 MDmAdDdfApi* aDdfApi, |
|
48 MDmAdRtNodeDataApi* aRtNodeDataApi) |
|
49 { |
|
50 CDmAdEngine* self = new (ELeave) CDmAdEngine(aDmAdCallBack, aStoreApi, aDdfApi, aRtNodeDataApi); |
|
51 CleanupStack::PushL(self); |
|
52 self->ConstructL(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CDmAdEngine::ConstructL() |
|
57 { |
|
58 TRACE("CDmAdEngine::ConstructL"); |
|
59 iRtNodes = new (ELeave) CArrayPtrFlat<CDmAdRtNode>(4); |
|
60 } |
|
61 |
|
62 CDmAdEngine::CDmAdEngine(MDmAdCallBack* aDmAdCallBack, |
|
63 MDmAdStoreApi* aStoreApi, |
|
64 MDmAdDdfApi* aDdfApi, |
|
65 MDmAdRtNodeDataApi* aRtNodeDataApi) : |
|
66 iCallBack(aDmAdCallBack), iStoreApi(aStoreApi), iDdfApi(aDdfApi), iRtNodeDataApi(aRtNodeDataApi) |
|
67 { |
|
68 TRACE("CDmAdEngine::CDmAdEngine"); |
|
69 } |
|
70 |
|
71 DMAD_EXPORT_C CDmAdEngine::~CDmAdEngine() |
|
72 { |
|
73 TRACE("CDmAdEngine::~CDmAdEngine"); |
|
74 CDmAdRtNode::CleanupOperationDeleteCArrayPtr(iRtNodes); |
|
75 } |
|
76 |
|
77 //=================================================================================================== |
|
78 |
|
79 DMAD_EXPORT_C void CDmAdEngine::ChildURIListL(const TDesC8& aUri, const TDesC8& aParentLuid, |
|
80 const CArrayFix<TSmlDmMappingInfo>& aPreviousUriSegmentList, |
|
81 TInt aResultsRef, TInt aStatusRef) |
|
82 { |
|
83 TRACE("CDmAdEngine::ChildURIListL"); |
|
84 |
|
85 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
86 DEBUG_LOG1(_L8("aParentLuid %S"), &aParentLuid); |
|
87 DEBUG_LOG2(_L("aResultsRef = %d, aStatusRef = %d"), aResultsRef, aStatusRef); |
|
88 |
|
89 |
|
90 TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri)); |
|
91 TRAPD(err, DoChildUriListL(uri, aParentLuid, aPreviousUriSegmentList, aResultsRef, aStatusRef)); |
|
92 if (err != KErrNone) |
|
93 { |
|
94 iCallBack->SetStatusL(aStatusRef, err); |
|
95 } |
|
96 } |
|
97 |
|
98 DMAD_EXPORT_C void CDmAdEngine::AddNodeObjectL(const TDesC8& aUri, const TDesC8& aParentLuid, |
|
99 TInt aStatusRef) |
|
100 { |
|
101 TRACE("CDmAdEngine::AddNodeObjectL"); |
|
102 |
|
103 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
104 DEBUG_LOG1(_L8("aParentLuid %S"), &aParentLuid); |
|
105 DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef); |
|
106 |
|
107 TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri)); |
|
108 TRAPD(err, DoAddNodeObjectL(uri, aParentLuid, aStatusRef)); |
|
109 if (err != KErrNone) |
|
110 { |
|
111 iCallBack->SetStatusL(aStatusRef, err); |
|
112 } |
|
113 } |
|
114 |
|
115 DMAD_EXPORT_C void CDmAdEngine::UpdateLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, |
|
116 const TDesC8& aObject, const TDesC8& aType, |
|
117 TInt aStatusRef) |
|
118 { |
|
119 TRACE("CDmAdEngine::UpdateLeafObjectL"); |
|
120 |
|
121 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
122 DEBUG_LOG1(_L8("aLuid %S"), &aLuid); |
|
123 DEBUG_LOG1(_L8("aType %S"), &aType); |
|
124 DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef); |
|
125 |
|
126 |
|
127 DEBUG_LOG(_L("Object:")); |
|
128 DEBUG_LOG_HEX(aObject); |
|
129 |
|
130 TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri)); |
|
131 TRAPD(err, DoUpdateLeafObjectL(uri, aLuid, aObject, aType, aStatusRef)); |
|
132 if (err != KErrNone) |
|
133 { |
|
134 iCallBack->SetStatusL(aStatusRef, err); |
|
135 } |
|
136 } |
|
137 |
|
138 DMAD_EXPORT_C void CDmAdEngine::FetchLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, |
|
139 const TDesC8& aType, TInt aResultsRef, TInt aStatusRef) |
|
140 { |
|
141 TRACE("CDmAdEngine::FetchLeafObjectL"); |
|
142 |
|
143 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
144 DEBUG_LOG1(_L8("aLuid %S"), &aLuid); |
|
145 DEBUG_LOG1(_L8("aType %S"), &aType); |
|
146 DEBUG_LOG2(_L("aResultsRef = %d, aStatusRef = %d"), aResultsRef, aStatusRef); |
|
147 |
|
148 TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri)); |
|
149 TRAPD(err, DoFetchLeafObjectL(uri, aLuid, aType, aResultsRef, aStatusRef)); |
|
150 if (err != KErrNone) |
|
151 { |
|
152 iCallBack->SetStatusL(aStatusRef, err); |
|
153 } |
|
154 } |
|
155 |
|
156 DMAD_EXPORT_C void CDmAdEngine::DeleteObjectL(const TDesC8& aUri, const TDesC8& aLuid, TInt aStatusRef) |
|
157 { |
|
158 TRACE("CDmAdEngine::DeleteObjectL"); |
|
159 DEBUG_LOG1(_L8("aUri %S"), &aUri); |
|
160 DEBUG_LOG1(_L8("aLuid %S"), &aLuid); |
|
161 DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef); |
|
162 |
|
163 TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri)); |
|
164 TRAPD(err, DoDeleteObjectL(uri, aLuid, aStatusRef)); |
|
165 if (err != KErrNone) |
|
166 { |
|
167 iCallBack->SetStatusL(aStatusRef, err); |
|
168 } |
|
169 } |
|
170 |
|
171 DMAD_EXPORT_C void CDmAdEngine::CompleteOutstandingCmdsL() |
|
172 { |
|
173 TRACE("CDmAdEngine::CompleteOutstandingCmdsL"); |
|
174 |
|
175 TRAPD(err, DoCompleteOutstandingCmdsL()); |
|
176 if (err != KErrNone) |
|
177 { |
|
178 iRtNodes->ResetAndDestroy(); |
|
179 } |
|
180 } |
|
181 |
|
182 //=================================================================================================== |
|
183 |
|
184 void CDmAdEngine::DoChildUriListL(const TDesC8& aUri, const TDesC8& aParentLuid, const CArrayFix<TSmlDmMappingInfo>& aPreviousUriSegmentList, TInt aResultsRef, TInt aStatusRef) |
|
185 { |
|
186 TRACE("CDmAdEngine::DoChildUriListL"); |
|
187 |
|
188 CBufBase* currentList; |
|
189 iDdfApi->BuildChildUriListLC(aUri, aParentLuid, aPreviousUriSegmentList, currentList); |
|
190 iCallBack->SetResultsL(aResultsRef, *currentList, KNullDesC8); |
|
191 iCallBack->SetStatusL(aStatusRef, KErrNone); |
|
192 CleanupStack::PopAndDestroy(); //currentList |
|
193 } |
|
194 |
|
195 |
|
196 void CDmAdEngine::DoAddNodeObjectL(const TDesC8& aUri, const TDesC8& aParentLuid, TInt aStatusRef) |
|
197 { |
|
198 TRACE("CDmAdEngine::DoAddNodeObjectL"); |
|
199 |
|
200 if (!iDdfApi->IsNodeRtNodeL(aUri)) |
|
201 { |
|
202 iDdfApi->NotRtNodeAddNodeObjectL(aUri, aParentLuid, aStatusRef); |
|
203 return; |
|
204 } |
|
205 |
|
206 if (FindRtNodeInStoreL(aParentLuid, aUri)) |
|
207 { |
|
208 iCallBack->SetStatusL(aStatusRef, KErrAlreadyExists); |
|
209 return; |
|
210 } |
|
211 |
|
212 CDmAdRtNode* rtNode = FindRtNodeInBuffer(aUri); |
|
213 if (rtNode != NULL) |
|
214 { |
|
215 iCallBack->SetStatusL(aStatusRef, KErrAlreadyExists); |
|
216 return; |
|
217 } |
|
218 |
|
219 if (SysUtil::FFSSpaceBelowCriticalLevelL(0, 0)) |
|
220 { |
|
221 iCallBack->SetStatusL(aStatusRef, KErrDiskFull); |
|
222 return; |
|
223 } |
|
224 |
|
225 rtNode = CDmAdRtNode::NewL(aUri, aParentLuid, iCallBack, iRtNodeDataApi); |
|
226 CleanupStack::PushL(rtNode); |
|
227 |
|
228 iRtNodeDataApi->SetDefaultSettingsL(rtNode->Data(), aUri); |
|
229 rtNode->SetSomeLeafAddedToRtNode(ETrue); |
|
230 |
|
231 CDmAdCommand* command = CDmAdCommand::NewLC(aUri, aStatusRef, EFalse); |
|
232 rtNode->AppendCommandL(command); |
|
233 CleanupStack::Pop(); //command |
|
234 |
|
235 iRtNodes->AppendL(rtNode); |
|
236 CleanupStack::Pop(); // rtNode |
|
237 |
|
238 } |
|
239 |
|
240 void CDmAdEngine::DoUpdateLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, const TDesC8& aObject, const TDesC8& aType, TInt aStatusRef) |
|
241 { |
|
242 TRACE("CDmAdEngine::DoUpdateLeafObjectL"); |
|
243 |
|
244 CDmAdRtNode* rtNode = NULL; |
|
245 |
|
246 if (!iDdfApi->IsLeafUnderRtNodeL(aUri)) |
|
247 { |
|
248 iDdfApi->NotRtNodeUpdateLeafObjectL(aUri, aLuid, aObject, aType, aStatusRef); |
|
249 return; |
|
250 } |
|
251 |
|
252 TPtrC8 rtNodeUri(iDdfApi->RtNodeUriForLeafL(aUri)); |
|
253 if (!FindRtNodeInStoreL(aLuid, rtNodeUri)) |
|
254 { |
|
255 rtNode = FindRtNodeInBuffer(rtNodeUri); |
|
256 if (rtNode == NULL) |
|
257 { |
|
258 iCallBack->SetStatusL(aStatusRef, KErrNotFound); |
|
259 return; |
|
260 } |
|
261 rtNode->AddLeafObjectL(aUri, aObject, aStatusRef); |
|
262 return; |
|
263 } |
|
264 |
|
265 rtNode = RestoreRtNodeInBufferIfNotDoneL(rtNodeUri, aLuid); |
|
266 rtNode->UpdateLeafObjectL(aUri, aObject, aStatusRef); |
|
267 } |
|
268 |
|
269 |
|
270 void CDmAdEngine::DoFetchLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, const TDesC8& aType, TInt aResultsRef, TInt aStatusRef) |
|
271 { |
|
272 TRACE("CDmAdEngine::DoFetchLeafObjectL"); |
|
273 |
|
274 CBufBase* object = 0; |
|
275 TInt status = DoFetchLeafObjectL(aUri, aLuid, aType, object); |
|
276 CleanupStack::PushL(object); |
|
277 if (status == KErrNone) |
|
278 { |
|
279 iCallBack->SetResultsL(aResultsRef, *object, aType); |
|
280 } |
|
281 iCallBack->SetStatusL(aStatusRef, status); |
|
282 CleanupStack::PopAndDestroy(); //object |
|
283 } |
|
284 |
|
285 TInt CDmAdEngine::DoFetchLeafObjectL(const TDesC8& aUri, const TDesC8& aLuid, const TDesC8& aType, CBufBase*& aObject) |
|
286 { |
|
287 TRACE("CDmAdEngine::DoFetchLeafObjectL"); |
|
288 |
|
289 TInt status = KErrNone; |
|
290 aObject = 0; |
|
291 if (!iDdfApi->IsLeafUnderRtNodeL(aUri)) |
|
292 { |
|
293 status = iDdfApi->NotRtNodeFetchLeafObjectLC(aUri, aLuid, aType, aObject); |
|
294 CleanupStack::Pop(); //aObject |
|
295 return status; |
|
296 } |
|
297 |
|
298 if (aLuid.Length() == 0) |
|
299 { |
|
300 aObject = CBufFlat::NewL(32); |
|
301 status = KErrNotFound; |
|
302 return status; |
|
303 } |
|
304 |
|
305 TPtrC8 rtNodeUri(TDmAdUtil::RemoveLastUriSeg(aUri)); |
|
306 CDmAdRtNode* rtNode = RestoreRtNodeInBufferIfNotDoneL(rtNodeUri, aLuid); |
|
307 iRtNodeDataApi->FetchLeafObjectLC(rtNode->Data(), aUri, aLuid, aObject); |
|
308 CleanupStack::Pop(); //object |
|
309 return status; |
|
310 } |
|
311 |
|
312 |
|
313 void CDmAdEngine::DoDeleteObjectL(const TDesC8& aUri, const TDesC8& aLuid, TInt aStatusRef) |
|
314 { |
|
315 TRACE("CDmAdEngine::DoDeleteObjectL"); |
|
316 |
|
317 if (aLuid.Length() == 0) |
|
318 { |
|
319 if (iDdfApi->IsNodeRtNodeL(aUri)) |
|
320 { |
|
321 iCallBack->SetStatusL(aStatusRef, KErrNotFound); |
|
322 return; |
|
323 } |
|
324 iDdfApi->NotRtNodeDeleteObjectL(aUri, aLuid, aStatusRef); |
|
325 return; |
|
326 } |
|
327 |
|
328 /* |
|
329 if (IsLeaf(aUri)) |
|
330 { |
|
331 DMADERR(DmAdErr::Printf(_L("*** CDmAdEngine::DoDeleteObjectL: %d (line=%d)\n"), KDmAdErr1, __LINE__)); |
|
332 User::Leave(KErrGeneral); |
|
333 } |
|
334 */ |
|
335 |
|
336 if (!iDdfApi->IsTopLevelRtNode(aUri)) |
|
337 { |
|
338 HBufC8* parentRtNodeLuid = ParentRtNodeLuidForRtNodeLC(aUri); |
|
339 if (parentRtNodeLuid->Compare(aLuid) == 0) |
|
340 { |
|
341 DEBUG_LOG(_L("Not found 1")); |
|
342 User::Leave(KErrNotFound); |
|
343 } |
|
344 DEBUG_LOG(_L("Not found 2")); |
|
345 User::Leave(KErrNotFound); |
|
346 CleanupStack::PopAndDestroy(); //parentRtNodeLuid |
|
347 } |
|
348 |
|
349 iStoreApi->DeleteRtNodeL(aLuid, aUri); |
|
350 iCallBack->SetStatusL(aStatusRef, KErrNone); |
|
351 } |
|
352 |
|
353 |
|
354 void CDmAdEngine::DoCompleteOutstandingCmdsL() |
|
355 { |
|
356 TRACE("CDmAdEngine::DoCompleteOutstandingCmdsL"); |
|
357 |
|
358 SaveRtNodesL(); |
|
359 } |
|
360 |
|
361 //=================================================================================================== |
|
362 |
|
363 CDmAdRtNode* CDmAdEngine::FindRtNodeInBuffer(const TDesC8& aUri) |
|
364 { |
|
365 TRACE("CDmAdEngine::FindRtNodeInBuffer"); |
|
366 |
|
367 CDmAdRtNode* rtNode = NULL; |
|
368 TInt countRtNodes = iRtNodes->Count(); |
|
369 for (TInt i=0; i < countRtNodes; i++) |
|
370 { |
|
371 if (iRtNodes->At(i)->Uri().Compare(aUri) == 0) |
|
372 { |
|
373 rtNode = iRtNodes->At(i); |
|
374 break; |
|
375 } |
|
376 } |
|
377 return rtNode; |
|
378 } |
|
379 |
|
380 CDmAdRtNode* CDmAdEngine::FindRtNodeInBufferByLuid(const TDesC8& aLuid, const TDesC8& aUri) |
|
381 { |
|
382 TRACE("CDmAdEngine::FindRtNodeInBufferByLuid"); |
|
383 |
|
384 CDmAdRtNode* rtNode = NULL; |
|
385 TInt countRtNodes = iRtNodes->Count(); |
|
386 for (TInt i=0; i < countRtNodes; i++) |
|
387 { |
|
388 if (iRtNodes->At(i)->Luid().Compare(aLuid) == 0 && |
|
389 iRtNodes->At(i)->AreUriTypesSame(aUri)) |
|
390 { |
|
391 rtNode = iRtNodes->At(i); |
|
392 break; |
|
393 } |
|
394 } |
|
395 return rtNode; |
|
396 } |
|
397 |
|
398 CDmAdRtNode* CDmAdEngine::RestoreRtNodeInBufferIfNotDoneL(const TDesC8& aUri, const TDesC8& aLuid) |
|
399 { |
|
400 TRACE("CDmAdEngine::RestoreRtNodeInBufferIfNotDoneL"); |
|
401 |
|
402 CDmAdRtNode* rtNode = FindRtNodeInBufferByLuid(aLuid, aUri); |
|
403 if (rtNode == NULL) |
|
404 { |
|
405 rtNode = FetchRtNodeInBufferL(aUri, aLuid); |
|
406 } |
|
407 return rtNode; |
|
408 } |
|
409 |
|
410 CDmAdRtNode* CDmAdEngine::FetchRtNodeInBufferL(const TDesC8& aUri, const TDesC8& aLuid) |
|
411 { |
|
412 TRACE("CDmAdEngine::FetchRtNodeInBufferL"); |
|
413 |
|
414 CDmAdRtNode* rtNode = CDmAdRtNode::NewL(aUri, aLuid, iCallBack, iRtNodeDataApi); |
|
415 CleanupStack::PushL(rtNode); |
|
416 |
|
417 iStoreApi->FetchRtNodeL(*rtNode); |
|
418 |
|
419 iRtNodes->AppendL(rtNode); |
|
420 CleanupStack::Pop(); //rtNode |
|
421 return rtNode; |
|
422 } |
|
423 |
|
424 void CDmAdEngine::CompleteCommandsL(CDmAdRtNode& aRtNode, TInt aStatus) |
|
425 { |
|
426 TRACE("CDmAdEngine::CompleteCommandsL"); |
|
427 |
|
428 TInt countCommands = aRtNode.Commands()->Count(); |
|
429 for (TInt cmd=0; cmd < countCommands; cmd++) |
|
430 { |
|
431 CDmAdCommand* command = aRtNode.Commands()->At(cmd); |
|
432 if (command->Status() == KErrNone) |
|
433 { |
|
434 if (!command->IsLeaf()) |
|
435 { |
|
436 if (aStatus == MSmlDmAdapter::EOk) |
|
437 { |
|
438 iCallBack->SetMappingL(aRtNode.Uri(), aRtNode.Luid()); |
|
439 } |
|
440 } |
|
441 iCallBack->SetStatusL(command->StatusRef(), aStatus); |
|
442 } |
|
443 else |
|
444 { |
|
445 iCallBack->SetStatusL(command->StatusRef(), command->Status()); |
|
446 } |
|
447 } |
|
448 } |
|
449 |
|
450 void CDmAdEngine::CompleteCommandsL(CArrayPtr<CDmAdRtNode>& aRtNodes, TInt aStatus) |
|
451 { |
|
452 TRACE("CDmAdEngine::CompleteCommandsL"); |
|
453 |
|
454 for (TInt i=0; i < aRtNodes.Count(); i++) |
|
455 { |
|
456 CDmAdRtNode* rtNode = aRtNodes.At(i); |
|
457 CompleteCommandsL(*rtNode, aStatus); |
|
458 } |
|
459 } |
|
460 |
|
461 void CDmAdEngine::BuildTopLevelRtNodesListLC(CArrayPtr<CDmAdRtNode>* aRtNodes, |
|
462 CArrayPtr<CDmAdRtNode>*& aTopLevelRtNodes) |
|
463 { |
|
464 CArrayPtr<CDmAdRtNode>* rtNodesList; |
|
465 rtNodesList = new (ELeave) CArrayPtrFlat<CDmAdRtNode>(4); |
|
466 CleanupStack::PushL(TCleanupItem(CDmAdRtNode::CleanupOperationDeleteCArrayPtr, |
|
467 rtNodesList)); |
|
468 |
|
469 for (TInt i=0; i < aRtNodes->Count(); i++) |
|
470 { |
|
471 CDmAdRtNode* rtNode = aRtNodes->At(i); |
|
472 if (iDdfApi->IsTopLevelRtNode(rtNode->Uri())) |
|
473 { |
|
474 rtNodesList->AppendL(rtNode); |
|
475 aRtNodes->Delete(i); |
|
476 i--; |
|
477 } |
|
478 } |
|
479 |
|
480 aTopLevelRtNodes = rtNodesList; |
|
481 } |
|
482 |
|
483 void CDmAdEngine::BuildChildRtNodesListLC(CArrayPtr<CDmAdRtNode>* aRtNodes, |
|
484 const TDesC8& aSomeParentUri, |
|
485 CArrayPtr<CDmAdRtNode>*& aChildRtNodes) |
|
486 { |
|
487 CArrayPtr<CDmAdRtNode>* rtNodesList; |
|
488 rtNodesList = new (ELeave) CArrayPtrFlat<CDmAdRtNode>(4); |
|
489 CleanupStack::PushL(TCleanupItem(CDmAdRtNode::CleanupOperationDeleteCArrayPtr, |
|
490 rtNodesList)); |
|
491 |
|
492 for (TInt i=0; i < aRtNodes->Count(); i++) |
|
493 { |
|
494 CDmAdRtNode* rtNode = aRtNodes->At(i); |
|
495 if (rtNode->IsSomeChild(aSomeParentUri)) |
|
496 { |
|
497 rtNodesList->AppendL(rtNode); |
|
498 aRtNodes->Delete(i); |
|
499 i--; |
|
500 } |
|
501 } |
|
502 |
|
503 aChildRtNodes = rtNodesList; |
|
504 } |
|
505 |
|
506 void CDmAdEngine::SaveRtNodesL(void) |
|
507 { |
|
508 TRACE("CDmAdEngine::SaveRtNodesL"); |
|
509 |
|
510 CArrayPtr<CDmAdRtNode>* topLevelRtNodes; |
|
511 BuildTopLevelRtNodesListLC(iRtNodes, topLevelRtNodes); |
|
512 |
|
513 TInt countRtNodes; |
|
514 countRtNodes = topLevelRtNodes->Count(); |
|
515 TInt i; |
|
516 for (i=0; i < countRtNodes; i++) |
|
517 { |
|
518 CDmAdRtNode* rtNode = topLevelRtNodes->At(i); |
|
519 CArrayPtr<CDmAdRtNode>* childRtNodes; |
|
520 BuildChildRtNodesListLC(iRtNodes, rtNode->Uri(), childRtNodes); |
|
521 |
|
522 TRAPD(err, iStoreApi->SaveTopLevelRtNodeL(*rtNode, *childRtNodes)); |
|
523 CompleteCommandsL(*rtNode, err); |
|
524 CompleteCommandsL(*childRtNodes, err); |
|
525 |
|
526 CleanupStack::PopAndDestroy(); //childRtNodes |
|
527 } |
|
528 CleanupStack::PopAndDestroy(); //topLevelRtNodes |
|
529 |
|
530 //child rtNodes without top level RtNode |
|
531 countRtNodes = iRtNodes->Count(); |
|
532 for (i=0; i < countRtNodes; i++) |
|
533 { |
|
534 CDmAdRtNode* rtNode = iRtNodes->At(i); |
|
535 TInt err = KErrNone; |
|
536 if (!rtNode->IsJustFetched()) |
|
537 { |
|
538 TRAP(err, iStoreApi->SaveChildLevelRtNodeL(*rtNode)); |
|
539 } |
|
540 CompleteCommandsL(*rtNode, err); |
|
541 } |
|
542 iRtNodes->ResetAndDestroy(); |
|
543 } |
|
544 |
|
545 TBool CDmAdEngine::FindRtNodeInStoreL(const TDesC8& aLuid, const TDesC8& aUri) |
|
546 { |
|
547 TRACE("CDmAdEngine::FindRtNodeInStoreL"); |
|
548 |
|
549 TBool ret = EFalse; |
|
550 |
|
551 if (iDdfApi->IsTopLevelRtNode(aUri)) |
|
552 { |
|
553 ret = iStoreApi->FindRtNodeL(aLuid, aUri); |
|
554 } |
|
555 else |
|
556 { |
|
557 HBufC8* parentRtNodeLuid = ParentRtNodeLuidForRtNodeLC(aUri); |
|
558 if (parentRtNodeLuid->Compare(aLuid) == 0) |
|
559 { |
|
560 ret = EFalse; |
|
561 } |
|
562 else |
|
563 { |
|
564 ret = iStoreApi->FindRtNodeL(aLuid, aUri); |
|
565 } |
|
566 CleanupStack::PopAndDestroy(); //parentRtNodeLuid |
|
567 } |
|
568 |
|
569 return ret; |
|
570 } |
|
571 |
|
572 HBufC8* CDmAdEngine::ParentRtNodeLuidForRtNodeLC(const TDesC8& aUri) |
|
573 { |
|
574 HBufC8* parentRtNodeUri = iDdfApi->ParentRtNodeUriForRtNodeLC(aUri); |
|
575 HBufC8* parentRtNodeLuid = iCallBack->GetLuidAllocL(*parentRtNodeUri); |
|
576 CleanupStack::PopAndDestroy(); // parentRtNodeUri |
|
577 CleanupStack::PushL(parentRtNodeLuid); |
|
578 return parentRtNodeLuid; |
|
579 } |