|
1 /* |
|
2 * Copyright (c) 2005-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 * @file |
|
16 * This contains CDataWrapper |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 /** |
|
23 @prototype |
|
24 @test |
|
25 */ |
|
26 |
|
27 #include "DataWrapper.h" |
|
28 |
|
29 _LIT(KDictionaryName, "name"); |
|
30 |
|
31 EXPORT_C CDataWrapper::CDataWrapper() |
|
32 /** |
|
33 * Constructor |
|
34 */ |
|
35 : iDataDictionary(NULL) |
|
36 , iTestBlockController(NULL) |
|
37 , iOutstanding(0) |
|
38 { |
|
39 } |
|
40 |
|
41 EXPORT_C CDataWrapper::~CDataWrapper() |
|
42 /** |
|
43 * Destructor |
|
44 */ |
|
45 { |
|
46 } |
|
47 |
|
48 EXPORT_C void CDataWrapper::SetTestBlockController(CTestBlockController* aTestBlockController) |
|
49 /** |
|
50 * Set the test block controller |
|
51 * |
|
52 * @param aTestBlockController - the controller |
|
53 * |
|
54 * @see CTestBlockController |
|
55 */ |
|
56 { |
|
57 iTestBlockController = aTestBlockController; |
|
58 } |
|
59 |
|
60 EXPORT_C void CDataWrapper::SetDataDictionary(CDataDictionary* aDataDictionary) |
|
61 /** |
|
62 * Set the data dictionary |
|
63 * |
|
64 * @param aDataDictionary - the data dictionary |
|
65 * |
|
66 * @see CDataDictionary |
|
67 */ |
|
68 { |
|
69 iDataDictionary = aDataDictionary; |
|
70 } |
|
71 |
|
72 // MDataAccess implementation |
|
73 EXPORT_C TBool CDataWrapper::GetBoolFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TBool& aResult) |
|
74 { |
|
75 return iTestBlockController?iTestBlockController->GetBoolFromConfig(aSectName, aKeyName, aResult):EFalse; |
|
76 } |
|
77 |
|
78 EXPORT_C TBool CDataWrapper::GetIntFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
79 { |
|
80 return iTestBlockController?iTestBlockController->GetIntFromConfig(aSectName, aKeyName, aResult):EFalse; |
|
81 } |
|
82 |
|
83 EXPORT_C TBool CDataWrapper::GetStringFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) |
|
84 { |
|
85 return iTestBlockController?iTestBlockController->GetStringFromConfig(aSectName, aKeyName, aResult):EFalse; |
|
86 } |
|
87 |
|
88 EXPORT_C TBool CDataWrapper::GetHexFromConfig(const TDesC& aSectName, const TDesC& aKeyName, TInt& aResult) |
|
89 { |
|
90 return iTestBlockController?iTestBlockController->GetHexFromConfig(aSectName, aKeyName, aResult):EFalse; |
|
91 } |
|
92 |
|
93 EXPORT_C TBool CDataWrapper::WriteBoolToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TBool& aValue) |
|
94 { |
|
95 return iTestBlockController?iTestBlockController->WriteBoolToConfig(aSectName, aKeyName, aValue):EFalse; |
|
96 } |
|
97 |
|
98 EXPORT_C TBool CDataWrapper::WriteIntToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TInt& aValue) |
|
99 { |
|
100 return iTestBlockController?iTestBlockController->WriteIntToConfig(aSectName, aKeyName, aValue):EFalse; |
|
101 } |
|
102 |
|
103 EXPORT_C TBool CDataWrapper::WriteStringToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TPtrC& aValue) |
|
104 { |
|
105 return iTestBlockController?iTestBlockController->WriteStringToConfig(aSectName, aKeyName, aValue):EFalse; |
|
106 } |
|
107 |
|
108 EXPORT_C TBool CDataWrapper::WriteHexToConfig(const TDesC& aSectName, const TDesC& aKeyName, const TInt& aValue) |
|
109 { |
|
110 return iTestBlockController?iTestBlockController->WriteHexToConfig(aSectName, aKeyName, aValue):EFalse; |
|
111 } |
|
112 |
|
113 EXPORT_C void CDataWrapper::ReadSharedDataL(const TDesC& aShareName, TDes& aSharedDataVal) |
|
114 { |
|
115 if( iTestBlockController ) |
|
116 { |
|
117 iTestBlockController->ReadSharedDataL(aShareName, aSharedDataVal); |
|
118 } |
|
119 } |
|
120 |
|
121 EXPORT_C void CDataWrapper::WriteSharedDataL(const TDesC& aShareName, TDesC& aSharedDataVal, TModeCopy aModeCopy) |
|
122 { |
|
123 if( iTestBlockController ) |
|
124 { |
|
125 iTestBlockController->WriteSharedDataL( aShareName, aSharedDataVal, aModeCopy ); |
|
126 } |
|
127 } |
|
128 |
|
129 EXPORT_C CTestExecuteLogger& CDataWrapper::Logger() |
|
130 { |
|
131 return iTestBlockController->Logger(); |
|
132 } |
|
133 |
|
134 EXPORT_C CDataWrapper* CDataWrapper::GetDataWrapperL(const TDesC& aSectionName) |
|
135 { |
|
136 CDataWrapper* dataWrapper = NULL; |
|
137 if( iDataDictionary ) |
|
138 { |
|
139 // Lookup the dictionary name in the ini file |
|
140 TPtrC dictionaryName; |
|
141 TBool res = GetStringFromConfig(aSectionName, KDictionaryName, dictionaryName ); |
|
142 if( KErrNone != res ) |
|
143 { |
|
144 // Retrieve the object from the dictionary |
|
145 dataWrapper = iDataDictionary->GetDataL(dictionaryName); |
|
146 } |
|
147 else |
|
148 { |
|
149 User::Leave( KErrBadName ); |
|
150 } |
|
151 } |
|
152 return dataWrapper; |
|
153 } |
|
154 |
|
155 EXPORT_C TAny* CDataWrapper::GetDataObjectL(const TDesC& aSectionName) |
|
156 { |
|
157 TAny* dataObject = NULL; |
|
158 if( iDataDictionary ) |
|
159 { |
|
160 // Lookup the dictionary name in the ini file |
|
161 TPtrC dictionaryName; |
|
162 TBool res = GetStringFromConfig(aSectionName, KDictionaryName, dictionaryName ); |
|
163 if( KErrNone != res ) |
|
164 { |
|
165 // Retrieve the object from the dictionary |
|
166 dataObject = iDataDictionary->GetObjectL(dictionaryName); |
|
167 } |
|
168 else |
|
169 { |
|
170 User::Leave( KErrBadName ); |
|
171 } |
|
172 } |
|
173 return dataObject; |
|
174 } |
|
175 |
|
176 EXPORT_C void CDataWrapper::SetDataObjectL(const TDesC& aSectionName, TAny* aObject) |
|
177 { |
|
178 if( iDataDictionary ) |
|
179 { |
|
180 // Lookup the dictionary name in the ini file |
|
181 TPtrC dictionaryName; |
|
182 TBool res = GetStringFromConfig(aSectionName, KDictionaryName, dictionaryName ); |
|
183 if( KErrNone != res ) |
|
184 { |
|
185 // Set the object in the wrapper |
|
186 iDataDictionary->SetObjectL(dictionaryName, aObject); |
|
187 } |
|
188 else |
|
189 { |
|
190 User::Leave( KErrBadName ); |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 // MTEFResult implementation |
|
196 EXPORT_C void CDataWrapper::SetError(const TInt aError) |
|
197 { |
|
198 if( iTestBlockController ) |
|
199 { |
|
200 iTestBlockController->SetError( aError ); |
|
201 } |
|
202 } |
|
203 |
|
204 EXPORT_C void CDataWrapper::SetAsyncError(const TInt aIndex, const TInt aError) |
|
205 { |
|
206 if( iTestBlockController ) |
|
207 { |
|
208 iTestBlockController->SetAsyncError( aIndex, aError ); |
|
209 } |
|
210 } |
|
211 |
|
212 EXPORT_C void CDataWrapper::SetBlockResult(const TVerdict aResult) |
|
213 { |
|
214 if( iTestBlockController ) |
|
215 { |
|
216 iTestBlockController->SetBlockResult( aResult ); |
|
217 } |
|
218 } |
|
219 |
|
220 EXPORT_C TVerdict CDataWrapper::BlockResult() |
|
221 { |
|
222 return iTestBlockController->BlockResult(); |
|
223 } |
|
224 |
|
225 // MActiveCallback implementation |
|
226 EXPORT_C void CDataWrapper::RunL(CActive* /*aActive*/, TInt /*aIndex*/) |
|
227 { |
|
228 // This should never be called, if it has been then warn the user! |
|
229 // They need to implement this function when using CActiveCallback's |
|
230 // and handle the request completion! |
|
231 SetBlockResult( EFail ); |
|
232 } |
|
233 |
|
234 EXPORT_C void CDataWrapper::DoCancel(CActive* /*aActive*/, TInt /*aIndex*/) |
|
235 { |
|
236 // This should never be called, if it has been then warn the user! |
|
237 // They need to implement this function when using CActiveCallback's |
|
238 // and handle the request cancellation! |
|
239 SetBlockResult( EFail ); |
|
240 } |