|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Name : resourcecondition.cpp |
|
15 // Part of : System Startup / Condition |
|
16 // Implementation of ResourceCondition class |
|
17 // Version : %version: 1 % |
|
18 // This material, including documentation and any related computer |
|
19 // programs, is protected by copyright controlled by Nokia. All |
|
20 // rights are reserved. Copying, including reproducing, storing, |
|
21 // adapting or translating, any or all of this material requires the |
|
22 // prior written consent of Nokia. This material also contains |
|
23 // confidential information which may not be disclosed to others |
|
24 // without the prior written consent of Nokia. |
|
25 // Template version: 4.1 |
|
26 // Nokia Core OS * |
|
27 // File renamed from resourcecondition.cpp to conditionevaluate.cpp as part of Core OS transfer. |
|
28 // |
|
29 |
|
30 |
|
31 |
|
32 #include "conditionevaluate.h" |
|
33 #include "cndlogical.h" |
|
34 #include "cndfeature.h" |
|
35 #include "cndcentralrepository.h" |
|
36 #include "cndpublishsubscribe.h" |
|
37 #include "cndsystemwideproperty.h" |
|
38 |
|
39 CConditionEvaluate::CConditionEvaluate() |
|
40 { |
|
41 } |
|
42 |
|
43 EXPORT_C CConditionEvaluate::~CConditionEvaluate() |
|
44 { |
|
45 } |
|
46 |
|
47 EXPORT_C CConditionEvaluate* CConditionEvaluate::NewLC() |
|
48 { |
|
49 CConditionEvaluate* self = CConditionEvaluate::NewL(); |
|
50 CleanupStack::PushL(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 EXPORT_C CConditionEvaluate* CConditionEvaluate::NewL() |
|
55 { |
|
56 CConditionEvaluate* self = new (ELeave)CConditionEvaluate(); |
|
57 return self; |
|
58 } |
|
59 |
|
60 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnFeatureMatchL(TResourceReader& aReader) |
|
61 { |
|
62 const TInt featureId = aReader.ReadInt32(); |
|
63 return CCndFeature::NewL(ECompareValue, featureId); |
|
64 } |
|
65 |
|
66 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnFeatureL(TResourceReader& aReader) |
|
67 { |
|
68 const TInt featureId = aReader.ReadInt32(); |
|
69 const TUint32 aCndValue = aReader.ReadUint32(); |
|
70 return CCndFeature::NewL(ECompareFeatureData, featureId, aCndValue); |
|
71 } |
|
72 |
|
73 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnCentRepFlagL(TResourceReader& aReader) |
|
74 { |
|
75 const TInt repositoryId = aReader.ReadInt32(); |
|
76 const TUint32 key = aReader.ReadUint32(); |
|
77 const TInt mask = aReader.ReadInt32(); |
|
78 return CCndCentralRepository::NewL(ECompareBitwiseAnd, repositoryId, key, mask); |
|
79 } |
|
80 |
|
81 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnCentRepMatchL(TResourceReader& aReader) |
|
82 { |
|
83 const TInt repositoryId = aReader.ReadInt32(); |
|
84 const TUint32 key = aReader.ReadUint32(); |
|
85 const TInt value = aReader.ReadInt32(); |
|
86 return CCndCentralRepository::NewL(ECompareValue, repositoryId, key, value ); |
|
87 } |
|
88 |
|
89 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnPubSubFlagL(TResourceReader& aReader) |
|
90 { |
|
91 const TInt category = aReader.ReadInt32(); |
|
92 const TUint32 key = aReader.ReadUint32(); |
|
93 const TInt mask = aReader.ReadInt32(); |
|
94 |
|
95 return CCndPublishSubscribe::NewL(ECompareBitwiseAnd, category, key, mask); |
|
96 } |
|
97 |
|
98 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnPubSubMatchL(TResourceReader& aReader) |
|
99 { |
|
100 const TInt category = aReader.ReadInt32(); |
|
101 const TUint32 key = aReader.ReadUint32(); |
|
102 const TInt value = aReader.ReadInt32(); |
|
103 |
|
104 return CCndPublishSubscribe::NewL(ECompareValue, category, key, value); |
|
105 } |
|
106 |
|
107 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnSwpMatchL(TResourceReader& aReader) |
|
108 { |
|
109 const TUint32 key = aReader.ReadUint32(); |
|
110 const TInt value = aReader.ReadInt32(); |
|
111 |
|
112 return CCndSwp::NewL(ECompareValue, key, value); |
|
113 } |
|
114 |
|
115 CConditionEvaluateBase* CConditionEvaluate::ReadConditionOnSwpFlagL(TResourceReader& aReader) |
|
116 { |
|
117 const TUint32 key = aReader.ReadUint32(); |
|
118 const TInt mask = aReader.ReadInt32(); |
|
119 |
|
120 return CCndSwp::NewL(ECompareBitwiseAnd, key, mask); |
|
121 } |
|
122 |
|
123 CConditionEvaluateBase* CConditionEvaluate::ReadLogicalNotL(const CResourceFile& aResourceFile,TResourceReader& aReader, |
|
124 RArray<TUint32>& aUsedResourceIds) |
|
125 { |
|
126 const TUint32 resourceId = aReader.ReadUint32(); |
|
127 CConditionEvaluateBase* sub = DoEvaluateLC(aResourceFile, resourceId, aUsedResourceIds); |
|
128 CConditionEvaluateBase* retVal = new (ELeave) CLogicalNot(sub); |
|
129 CleanupStack::Pop(sub); // CLogicalNot owns it now |
|
130 return retVal; |
|
131 } |
|
132 |
|
133 CConditionEvaluateBase* CConditionEvaluate::ReadLogicalAndL(const CResourceFile& aResourceFile,TResourceReader& aReader, |
|
134 RArray<TUint32>& aUsedResourceIds) |
|
135 { |
|
136 const TUint32 lhsId = aReader.ReadUint32(); |
|
137 const TUint32 rhsId = aReader.ReadUint32(); |
|
138 |
|
139 CConditionEvaluateBase* lhs = DoEvaluateLC(aResourceFile, lhsId, aUsedResourceIds); |
|
140 CConditionEvaluateBase* rhs = DoEvaluateLC(aResourceFile, rhsId, aUsedResourceIds); |
|
141 CConditionEvaluateBase* retVal = new (ELeave) CLogicalAnd(lhs, rhs); |
|
142 CleanupStack::Pop(rhs); // CLogicalAnd owns it now |
|
143 CleanupStack::Pop(lhs); // CLogicalAnd owns it now |
|
144 |
|
145 return retVal; |
|
146 } |
|
147 |
|
148 CConditionEvaluateBase* CConditionEvaluate::ReadLogicalOrL(const CResourceFile& aResourceFile,TResourceReader& aReader, |
|
149 RArray<TUint32>& aUsedResourceIds) |
|
150 { |
|
151 const TUint32 lhsId = aReader.ReadUint32(); |
|
152 const TUint32 rhsId = aReader.ReadUint32(); |
|
153 CConditionEvaluateBase* lhs = DoEvaluateLC(aResourceFile, lhsId, aUsedResourceIds); |
|
154 CConditionEvaluateBase* rhs = DoEvaluateLC(aResourceFile, rhsId, aUsedResourceIds); |
|
155 CConditionEvaluateBase* retVal = new (ELeave) CLogicalOr(lhs, rhs); |
|
156 CleanupStack::Pop(rhs); // CLogicalOr owns it now |
|
157 CleanupStack::Pop(lhs); // CLogicalOr owns it now |
|
158 |
|
159 return retVal; |
|
160 } |
|
161 |
|
162 CConditionEvaluateBase* CConditionEvaluate::DoEvaluateLC(const CResourceFile& aResourceFile, const TInt aResourceId, |
|
163 RArray<TUint32>& aUsedResourceIds) |
|
164 { |
|
165 // Check for any recursive conditions |
|
166 TInt idx = aUsedResourceIds.FindReverse(aResourceId); |
|
167 if (0 <= idx) |
|
168 { |
|
169 //Leave in case of any recursive condition |
|
170 User::Leave(KErrCorrupt); |
|
171 } |
|
172 aUsedResourceIds.AppendL(aResourceId); |
|
173 |
|
174 HBufC8* buf = aResourceFile.AllocReadLC(aResourceId); |
|
175 TResourceReader reader; |
|
176 reader.SetBuffer(buf); |
|
177 |
|
178 TUint16 type = reader.ReadUint16(); |
|
179 CConditionEvaluateBase* retVal = NULL; |
|
180 |
|
181 switch (type) |
|
182 { |
|
183 case EFeatureFlag: |
|
184 retVal = ReadConditionOnFeatureMatchL(reader); |
|
185 break; |
|
186 case EFeatureFlagData: |
|
187 retVal = ReadConditionOnFeatureL(reader); |
|
188 break; |
|
189 case ECentRepFlag: |
|
190 retVal = ReadConditionOnCentRepFlagL(reader); |
|
191 break; |
|
192 case ECentRepIntVal: |
|
193 retVal = ReadConditionOnCentRepMatchL(reader); |
|
194 break; |
|
195 case EPubSubFlag: |
|
196 retVal = ReadConditionOnPubSubFlagL(reader); |
|
197 break; |
|
198 case EPubSubIntVal: |
|
199 retVal = ReadConditionOnPubSubMatchL(reader); |
|
200 break; |
|
201 case ELogicalNot: |
|
202 retVal = ReadLogicalNotL(aResourceFile, reader, aUsedResourceIds); |
|
203 break; |
|
204 case ELogicalAnd: |
|
205 retVal = ReadLogicalAndL(aResourceFile, reader, aUsedResourceIds); |
|
206 break; |
|
207 case ELogicalOr: |
|
208 retVal = ReadLogicalOrL(aResourceFile, reader, aUsedResourceIds); |
|
209 break; |
|
210 case ESwpIntVal: |
|
211 retVal = ReadConditionOnSwpMatchL(reader); |
|
212 break; |
|
213 case ESwpFlag: |
|
214 retVal = ReadConditionOnSwpFlagL(reader); |
|
215 break; |
|
216 default: |
|
217 User::Leave(KErrCorrupt); |
|
218 } |
|
219 |
|
220 aUsedResourceIds.Remove(aUsedResourceIds.Count() - 1); |
|
221 CleanupStack::PopAndDestroy(buf); |
|
222 CleanupStack::PushL(retVal); |
|
223 return retVal; |
|
224 } |
|
225 |
|
226 EXPORT_C TBool CConditionEvaluate::EvaluateL(const CResourceFile& aResourceFile, const TInt aResourceId) |
|
227 { |
|
228 RArray<TUint32> array; |
|
229 CleanupClosePushL(array); |
|
230 |
|
231 CConditionEvaluateBase* expr = DoEvaluateLC(aResourceFile, aResourceId, array); |
|
232 TBool retVal = expr->EvaluateL(); |
|
233 |
|
234 CleanupStack::PopAndDestroy(expr); |
|
235 CleanupStack::PopAndDestroy(&array); |
|
236 return retVal; |
|
237 } |