|
1 /* |
|
2 * Copyright (c) 2009 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 #include "CdlExplorer.h" |
|
18 #include "CdlRefs.h" |
|
19 |
|
20 const TInt KGranularity = 4; |
|
21 |
|
22 NONSHARABLE_CLASS(CInstArray) : public CArrayPtrFlat<CCdlInstance> |
|
23 { |
|
24 public: |
|
25 CInstArray(); |
|
26 ~CInstArray(); |
|
27 }; |
|
28 |
|
29 CInstArray::CInstArray() |
|
30 : CArrayPtrFlat<CCdlInstance>(KGranularity) |
|
31 { |
|
32 } |
|
33 |
|
34 CInstArray::~CInstArray() |
|
35 { |
|
36 ResetAndDestroy(); |
|
37 } |
|
38 |
|
39 // |
|
40 // CCdlInstanceExplorerBase |
|
41 // |
|
42 |
|
43 EXPORT_C CCdlInstanceExplorerBase::~CCdlInstanceExplorerBase() |
|
44 { |
|
45 delete iSubLayer; |
|
46 } |
|
47 |
|
48 EXPORT_C CArrayPtr<CCdlInstance>* CCdlInstanceExplorerBase::FindLC(TUid aCdlUid) |
|
49 { |
|
50 CArrayPtr<CCdlInstance>* insts = new(ELeave) CInstArray; |
|
51 CleanupStack::PushL(insts); |
|
52 |
|
53 // first try to add instances giving them no sublayer & record best found along the way |
|
54 CCdlRefs* refs = CdlEngine::FindInstancesLC(aCdlUid); |
|
55 |
|
56 CCdlRefs::TIterator pRef = refs->Begin(); |
|
57 // if we don't have a sub-layer, find one and remove refs that we manage to load |
|
58 if (!iSubLayer) |
|
59 { |
|
60 for (; pRef != refs->End();) |
|
61 { |
|
62 TCdlRef ref = *pRef; |
|
63 TRAPD(err, TryAddL(ref, NULL, insts)); |
|
64 if (!err) |
|
65 { |
|
66 // try to create instance without validity check to see if it's a good sub-layer |
|
67 CCdlInstance* sub = NULL; |
|
68 TRAP_IGNORE({sub = CreateInstanceLC(ref, NULL); CleanupStack::Pop();}); |
|
69 if (sub) |
|
70 { |
|
71 if (!iSubLayer || iSubLayer->Interface().iApiSize < sub->Interface().iApiSize) |
|
72 { |
|
73 delete iSubLayer; |
|
74 iSubLayer = sub; |
|
75 } |
|
76 else |
|
77 { |
|
78 delete sub; |
|
79 } |
|
80 } |
|
81 // delete good refs from the array, so that instances aren't loaded twice |
|
82 refs->Delete(pRef); // Delete moves pRef to next entry |
|
83 } |
|
84 else |
|
85 { |
|
86 // leave failed refs in the array for retry |
|
87 ++pRef; |
|
88 } |
|
89 } |
|
90 } |
|
91 |
|
92 // try to add the instances that failed first time around |
|
93 for (pRef = refs->Begin(); pRef != refs->End(); ++pRef) |
|
94 { |
|
95 TRAP_IGNORE(TryAddL(*pRef, iSubLayer, insts)); |
|
96 } |
|
97 |
|
98 CleanupStack::PopAndDestroy(refs); |
|
99 |
|
100 return insts; |
|
101 } |
|
102 |
|
103 void CCdlInstanceExplorerBase::TryAddL(const TCdlRef& aRef, const CCdlInstance* aSubLayer, CArrayPtr<CCdlInstance>* aInstances) |
|
104 { |
|
105 CCdlInstance* inst = CreateInstanceLC(aRef, aSubLayer); |
|
106 if (!CallIsValid(*inst)) |
|
107 { |
|
108 CleanupStack::PopAndDestroy(inst); |
|
109 return; |
|
110 } |
|
111 |
|
112 TInt count = aInstances->Count(); |
|
113 for (TInt ii=0; ii<count; ii++) |
|
114 { |
|
115 CCdlInstance*& otherInst = aInstances->At(ii); |
|
116 switch (CallCompare(*otherInst, *inst)) |
|
117 { |
|
118 case ECdlInstancesNotComparable: |
|
119 break; |
|
120 |
|
121 case EFirstCdlInstanceBetter: |
|
122 { |
|
123 // a better instance already exists |
|
124 CleanupStack::PopAndDestroy(inst); |
|
125 return; |
|
126 } |
|
127 |
|
128 case ESecondCdlInstanceBetter: |
|
129 default: |
|
130 { |
|
131 // replace the existing instance |
|
132 delete otherInst; |
|
133 otherInst = inst; |
|
134 CleanupStack::Pop(inst); |
|
135 return; |
|
136 } |
|
137 } |
|
138 } |
|
139 |
|
140 // No comparable instance has been found - add this |
|
141 aInstances->AppendL(inst); |
|
142 CleanupStack::Pop(inst); |
|
143 } |
|
144 |
|
145 |
|
146 |
|
147 // |
|
148 // CdlExplorerUtils |
|
149 // |
|
150 |
|
151 EXPORT_C CCdlRefs* CdlExplorerUtils::CreateRefsLC(const CCdlInstance& aSingleInstance) |
|
152 { |
|
153 CCdlRefs* refs = CCdlRefs::NewLC(); |
|
154 refs->AppendL(aSingleInstance.Ref()); |
|
155 return refs; |
|
156 } |
|
157 |
|
158 EXPORT_C CCdlRefs* CdlExplorerUtils::CreateRefsLC(const CCdlInstance& aHomeInstance, const TCdlArray<TCdlRef>& aRefs) |
|
159 { |
|
160 CCdlRefs* refs = CCdlRefs::NewLC(); |
|
161 refs->AppendL(*aHomeInstance.Ref().iName, aRefs); |
|
162 return refs; |
|
163 } |
|
164 |
|
165 |
|
166 |
|
167 |