|
1 /* |
|
2 * Copyright (c) 2002-2004 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: Implementation of customization components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "TestDmCallback.h" |
|
23 #include "StifLogger.h" |
|
24 |
|
25 // EXTERNAL DATA STRUCTURES |
|
26 //extern ?external_data; |
|
27 |
|
28 // EXTERNAL FUNCTION PROTOTYPES |
|
29 //extern ?external_function( ?arg_type,?arg_type ); |
|
30 |
|
31 // CONSTANTS |
|
32 //const ?type ?constant_var = ?constant; |
|
33 |
|
34 // MACROS |
|
35 //#define ?macro ?macro_def |
|
36 |
|
37 // LOCAL CONSTANTS AND MACROS |
|
38 //const ?type ?constant_var = ?constant; |
|
39 //#define ?macro_name ?macro_def |
|
40 |
|
41 // MODULE DATA STRUCTURES |
|
42 //enum ?declaration |
|
43 //typedef ?declaration |
|
44 |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 //?type ?function_name( ?arg_type, ?arg_type ); |
|
47 |
|
48 // FORWARD DECLARATIONS |
|
49 //class ?FORWARD_CLASSNAME; |
|
50 |
|
51 // ============================= LOCAL FUNCTIONS =============================== |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 // ============================ MEMBER FUNCTIONS =============================== |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CTestDmCallback::CTestDmCallback |
|
60 // C++ default constructor can NOT contain any code, that |
|
61 // might leave. |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CTestDmCallback::CTestDmCallback( CStifLogger *aLog ) |
|
65 : iLog( aLog ) |
|
66 , iMappingURI( 16 ) |
|
67 , iMappingLuid( 16 ) |
|
68 // RPointerArray<CBufBase> iResultObjects; |
|
69 , iResultTypes( 16 ) |
|
70 // RArray<TInt> iStatusArray; |
|
71 { |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CTestDmCallback::ConstructL |
|
76 // Symbian 2nd phase constructor can leave. |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void CTestDmCallback::ConstructL() |
|
80 { |
|
81 // CDesC8ArrayFlat *iMappingURI; |
|
82 // CDesC8ArrayFlat:: *iMappingURI; |
|
83 // CDesC8ArrayFlat *iMappingLuid; |
|
84 |
|
85 /* Containers for results */ |
|
86 // RPointerArray<CBufBase> iResultObjects; |
|
87 // CDesC8ArrayFlat *iResultTypes; |
|
88 |
|
89 /* Container for status */ |
|
90 // RArray<TInt> iStatusArray; |
|
91 } |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CTestDmCallback::NewL |
|
95 // Two-phased constructor. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 CTestDmCallback* CTestDmCallback::NewL( CStifLogger *aLog ) |
|
99 { |
|
100 CTestDmCallback* self = new( ELeave ) CTestDmCallback( aLog ); |
|
101 |
|
102 CleanupStack::PushL( self ); |
|
103 self->ConstructL(); |
|
104 CleanupStack::Pop(); |
|
105 |
|
106 return self; |
|
107 } |
|
108 |
|
109 |
|
110 // Destructor |
|
111 CTestDmCallback::~CTestDmCallback() |
|
112 { |
|
113 |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CTestDmCallback::?member_function |
|
119 // ?implementation_description |
|
120 // (other items were commented in a header). |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 /*?type CTestDmCallback::?member_function( |
|
124 ?arg_type arg, |
|
125 ?arg_type arg ) |
|
126 { |
|
127 |
|
128 ?code |
|
129 |
|
130 } |
|
131 */ |
|
132 |
|
133 void CTestDmCallback::SetResultsL( |
|
134 TInt aResultsRef, |
|
135 CBufBase& aObject, |
|
136 const TDesC8& aType ) |
|
137 { |
|
138 TPtrC8 obj = aObject.Ptr( 0 ).Left( 120 ); |
|
139 iLog->Log( _L8( "SetResults, ref=%d, object='%S', type='%S'" ), aResultsRef, &obj, &aType ); |
|
140 if (aResultsRef < 0 || aResultsRef >= iResultObjects.Count() || aResultsRef >= iResultTypes.Count()) |
|
141 { |
|
142 User::Leave( KErrArgument ); |
|
143 } |
|
144 |
|
145 //sf- iResultObjects[ aResultsRef ]->Copy( aObject ); |
|
146 iResultObjects[ aResultsRef ]->Reset(); |
|
147 //sf- iResultObjects[ aResultsRef ]->InsertL( 0, aObject.Ptr( 0 ) ); |
|
148 for (TInt i = 0 ; i < aObject.Size() ; ) |
|
149 { |
|
150 TPtrC8 ptr = aObject.Ptr( i ); |
|
151 iResultObjects[ aResultsRef ]->InsertL( i, ptr ); |
|
152 i += ptr.Length(); |
|
153 } |
|
154 //sf- iResultTypes[ aResultsRef ] = aType; |
|
155 iResultTypes.Delete( aResultsRef ); |
|
156 iResultTypes.InsertL( aResultsRef, aType ); |
|
157 } |
|
158 |
|
159 void CTestDmCallback::SetStatusL( TInt aStatusRef, |
|
160 MSmlDmAdapter::TError aErrorCode ) |
|
161 { |
|
162 iLog->Log( _L8( "SetStatusL, ref=%d, code=%d" ), aStatusRef, aErrorCode ); |
|
163 if (aStatusRef < 0 || aStatusRef >= iStatusArray.Count() ) |
|
164 { |
|
165 User::Leave( KErrArgument ); |
|
166 } |
|
167 |
|
168 iStatusArray[ aStatusRef ] = aErrorCode; |
|
169 } |
|
170 |
|
171 void CTestDmCallback::SetMappingL( const TDesC8& aURI, const TDesC8& aLUID ) |
|
172 { |
|
173 TPtrC8 ptrUri = aURI; |
|
174 TPtrC8 ptrLuid = aLUID.Left( 80 ); |
|
175 iLog->Log( _L8( "SetMappingL, aURI='%S', aLUID='%S'" ), &ptrUri, &ptrLuid ); |
|
176 |
|
177 TInt idx = FindMappingURI( aURI ); |
|
178 if (idx < 0) |
|
179 { |
|
180 iMappingURI.AppendL( aURI ); |
|
181 iMappingLuid.AppendL( aLUID ); |
|
182 } |
|
183 else |
|
184 { |
|
185 //sf- iMappingLuid[ idx ] = aLUID; |
|
186 iMappingLuid.Delete( idx ); |
|
187 iMappingLuid.InsertL( idx, aLUID ); |
|
188 } |
|
189 } |
|
190 |
|
191 HBufC8* CTestDmCallback::GetLuidAllocL( const TDesC8& aURI ) |
|
192 { |
|
193 iLog->Log( _L8( "GetLuidAllocL, aURI='%S'" ), &aURI ); |
|
194 HBufC8* ptr = GetLuidL( aURI ).AllocL(); |
|
195 return ptr; |
|
196 /* HBufC8* ptr = 0; |
|
197 TInt idx = FindMappingURI( aURI ); |
|
198 if (idx < 0) |
|
199 { |
|
200 ptr = HBufC8::NewL(2); |
|
201 } |
|
202 else |
|
203 { |
|
204 ptr = iMappingLuid[ idx ].AllocL(); |
|
205 } |
|
206 |
|
207 return ptr; |
|
208 */ } |
|
209 |
|
210 TPtrC8 CTestDmCallback::GetLuidL( const TDesC8& aURI ) |
|
211 { |
|
212 iLog->Log( _L8( "GetLuidL, aURI='%S'" ), &aURI ); |
|
213 TPtrC8 ptr; |
|
214 TInt idx = FindMappingURI( aURI ); |
|
215 if (idx < 0) |
|
216 { |
|
217 ptr.Set( KNullDesC8 ); |
|
218 } |
|
219 else |
|
220 { |
|
221 ptr.Set( iMappingLuid[ idx ] ); |
|
222 } |
|
223 |
|
224 return ptr; |
|
225 } |
|
226 |
|
227 |
|
228 /* New functions */ |
|
229 |
|
230 TInt CTestDmCallback::FindMappingURI( const TDesC8& aURI ) |
|
231 { |
|
232 TInt idx = iMappingURI.Count() - 1; |
|
233 while (idx >= 0 && iMappingURI[ idx ] != aURI) |
|
234 { |
|
235 idx--; |
|
236 } |
|
237 return idx; |
|
238 } |
|
239 |
|
240 TInt CTestDmCallback::GetNewResultsRefL( ) |
|
241 { |
|
242 CBufBase* obj = CBufFlat::NewL( 100 ); |
|
243 obj->Reset(); |
|
244 |
|
245 CleanupStack::PushL( obj ); |
|
246 User::LeaveIfError( iResultObjects.Append( obj ) ); |
|
247 CleanupStack::Pop( obj ); |
|
248 iResultTypes.AppendL( KNullDesC8 ); |
|
249 |
|
250 TInt ref = iResultObjects.Count() - 1; |
|
251 return ref; |
|
252 } |
|
253 |
|
254 TInt CTestDmCallback::GetNewStatusRefL( ) |
|
255 { |
|
256 User::LeaveIfError( iStatusArray.Append( -1 ) ); |
|
257 |
|
258 TInt ref = iStatusArray.Count() - 1; |
|
259 return ref; |
|
260 } |
|
261 /*TInt CTestDmCallback::GetResultsL( TInt aResultsRef, ) |
|
262 CBufBase& aObject, |
|
263 const TDesC8& aType ) |
|
264 { |
|
265 |
|
266 } |
|
267 */ |
|
268 |
|
269 CBufBase& CTestDmCallback::GetResultsObjectL( TInt aResultsRef ) |
|
270 { |
|
271 if (aResultsRef < 0 || aResultsRef >= iResultObjects.Count() ) |
|
272 { |
|
273 User::Leave( KErrArgument ); |
|
274 } |
|
275 return *iResultObjects[ aResultsRef ]; |
|
276 } |
|
277 |
|
278 TPtrC8 CTestDmCallback::GetResultsTypeL( TInt aResultsRef ) |
|
279 { |
|
280 if (aResultsRef < 0 || aResultsRef >= iResultTypes.Count() ) |
|
281 { |
|
282 User::Leave( KErrArgument ); |
|
283 } |
|
284 return iResultTypes[aResultsRef]; |
|
285 } |
|
286 |
|
287 MSmlDmAdapter::TError CTestDmCallback::GetStatusL( TInt aStatusRef ) |
|
288 { |
|
289 if (aStatusRef < 0 || aStatusRef >= iStatusArray.Count() ) |
|
290 { |
|
291 User::Leave( KErrArgument ); |
|
292 } |
|
293 return (MSmlDmAdapter::TError ) iStatusArray[aStatusRef]; |
|
294 } |
|
295 |
|
296 void CTestDmCallback::FreeResultsRefsL( ) |
|
297 { |
|
298 iResultObjects.ResetAndDestroy(); |
|
299 iResultTypes.Reset(); |
|
300 } |
|
301 |
|
302 void CTestDmCallback::FreeStatusRefsL( ) |
|
303 { |
|
304 iStatusArray.Reset(); |
|
305 } |
|
306 |
|
307 |
|
308 /* |
|
309 // ========================== OTHER EXPORTED FUNCTIONS ========================= |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // ?function_name implements... |
|
313 // ?implementation_description. |
|
314 // Returns: ?value_1: ?description |
|
315 // ?value_n: ?description |
|
316 // ?description |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 ?type ?function_name( |
|
320 ?arg_type arg, // ?description |
|
321 ?arg_type arg ) // ?description |
|
322 { |
|
323 |
|
324 ?code |
|
325 |
|
326 } |
|
327 */ |
|
328 // End of File |