|
1 /* |
|
2 * Copyright (c) 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 the License "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: AHLE client interface API definition. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include "AHLEInterface.h" |
|
22 |
|
23 |
|
24 |
|
25 // ================= MEMBER FUNCTIONS ======================= |
|
26 |
|
27 CAHLEInterface* CAHLEInterface::NewL( TAHLENewType aNewType, |
|
28 const TDesC& aDatabase, |
|
29 TUint aPrimarySize, |
|
30 TUint aSecondarySize, |
|
31 TAHLEScore aAdaptationSpeed ) |
|
32 { |
|
33 CAHLEInterface* apiObject = new (ELeave) CAHLEInterface; |
|
34 CleanupStack::PushL( apiObject ); |
|
35 apiObject->ConstructL( aNewType, aDatabase, aPrimarySize, aSecondarySize, aAdaptationSpeed ); |
|
36 CleanupStack::Pop(); |
|
37 return apiObject; |
|
38 } |
|
39 |
|
40 EXPORT_C CAHLEInterface* CAHLEInterface::NewL( const TDesC& aDatabase, |
|
41 TUint aPrimarySize, |
|
42 TUint aSecondarySize, |
|
43 TAHLEScore aAdaptationSpeed ){ |
|
44 return NewL( EAHLENewAllArgs, aDatabase, aPrimarySize, aSecondarySize, aAdaptationSpeed ); |
|
45 } |
|
46 |
|
47 EXPORT_C CAHLEInterface* CAHLEInterface::NewL( const TDesC& aDatabase ){ |
|
48 return NewL( EAHLENewDbOnlyArgs, aDatabase, 0, 0, 0); |
|
49 } |
|
50 |
|
51 EXPORT_C CAHLEInterface* CAHLEInterface::NewL(){ |
|
52 return NewL( EAHLENewNoArgs, KAHLEInterfaceDummyFile, 0, 0, 0); |
|
53 } |
|
54 |
|
55 EXPORT_C CAHLEInterface* CAHLEInterface::NewL( TUint aPrimarySize ){ |
|
56 return NewL( EAHLENewPrimarySizeOnlyArgs, KAHLEInterfaceDummyFile, aPrimarySize, 0, 0); |
|
57 } |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CAHLEInterface::InitializeAHLE |
|
62 // Creates the AHLE client if needed. |
|
63 // Throws exception on failure. This is where the AHLE client finally gets created. |
|
64 // We defer it as long as possible. |
|
65 // ----------------------------------------------------------------------------- |
|
66 void CAHLEInterface::InitializeAHLEL() |
|
67 { |
|
68 //If already done return quickly. |
|
69 if (iAHLE) return; |
|
70 |
|
71 TUint aPrimarySize = 0; |
|
72 TUint aSecondarySize = 0; |
|
73 TAHLEScore aAdaptationSpeed = 0; |
|
74 |
|
75 //Fire the correct contructor. It should map to the CAHLEInterface contructor. |
|
76 switch (iNewType) |
|
77 { |
|
78 case EAHLENewNoArgs: |
|
79 iAHLE = CAHLE::NewL(); |
|
80 break; |
|
81 |
|
82 case EAHLENewAllArgs: |
|
83 iAHLE = CAHLE::NewL( *iDatabase, iPrimarySize, iSecondarySize, iAdaptationSpeed); |
|
84 break; |
|
85 |
|
86 case EAHLENewDbOnlyArgs: |
|
87 iAHLE = CAHLE::NewL( *iDatabase ); |
|
88 break; |
|
89 |
|
90 case EAHLENewPrimarySizeOnlyArgs: |
|
91 //The actual value will be added by the initialization later. We |
|
92 //can't change the AHLE constructors. |
|
93 iDeferPrimarySize = iPrimarySize; |
|
94 iAHLE = CAHLE::NewL(); |
|
95 break; |
|
96 |
|
97 default: |
|
98 iAHLE = CAHLE::NewL(); |
|
99 } |
|
100 |
|
101 //Do the deferred reconfigure. It was not done earlier, the values |
|
102 //were cached for now. Note that the values could have been set in the |
|
103 //constructor as well as here. The trick is to keep track of which |
|
104 //ones to set here. If the deferred one was set use it. Otherwise use |
|
105 //the one just read in with GetConfiguration() |
|
106 |
|
107 iAHLE->GetConfigurationL( aPrimarySize, aSecondarySize, aAdaptationSpeed ); |
|
108 iAHLE->ReconfigureL( iDeferPrimarySize ? iDeferPrimarySize : aPrimarySize, |
|
109 iDeferSecondarySize ? iDeferSecondarySize : aSecondarySize, |
|
110 iDeferAdaptationSpeed ? iDeferAdaptationSpeed: aAdaptationSpeed ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // Idle Callback Function |
|
115 // Called when the thread is not busy. The code will be initialized |
|
116 // now. If it was initialized explicitly bu other code than this call |
|
117 // won't do very much. In any case this will always return false. It |
|
118 // doesn't need to run a second time since it will run to completion. |
|
119 // ----------------------------------------------------------------------------- |
|
120 TInt CAHLEInterface::AHLEInitializationCB(TAny* thisObj) |
|
121 { |
|
122 ((CAHLEInterface*)thisObj)->InitializeAHLEL(); |
|
123 return EFalse; |
|
124 } |
|
125 |
|
126 |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CAHLEInterface::CAHLEInterface |
|
130 // ----------------------------------------------------------------------------- |
|
131 CAHLEInterface::CAHLEInterface() |
|
132 { |
|
133 iAHLE = NULL; |
|
134 iDatabase = NULL; |
|
135 |
|
136 iPrimarySize = 0; |
|
137 iSecondarySize = 0; |
|
138 iAdaptationSpeed = 0; |
|
139 |
|
140 iDeferPrimarySize = 0; |
|
141 iDeferSecondarySize = 0; |
|
142 iDeferAdaptationSpeed = 0; |
|
143 } |
|
144 |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CAHLEInterface::~CAHLEInterface |
|
148 // C++ destructor |
|
149 // ----------------------------------------------------------------------------- |
|
150 CAHLEInterface::~CAHLEInterface() |
|
151 { |
|
152 if(iIdle != NULL) |
|
153 { |
|
154 iIdle->Cancel(); |
|
155 } |
|
156 delete iIdle; |
|
157 delete iAHLE; |
|
158 delete iDatabase; |
|
159 } |
|
160 |
|
161 |
|
162 // ----------------------------------------------------------------------------- |
|
163 // CAHLEInterface::IsConnected |
|
164 // Check if the client has been connected to the server. Note that if the actual |
|
165 // AHLE client has not been created yet we ARE considered connected. Otherwise we |
|
166 // would need to connect almost immediately. |
|
167 // ----------------------------------------------------------------------------- |
|
168 EXPORT_C TBool CAHLEInterface::IsConnected() |
|
169 { |
|
170 return (iAHLE ? iAHLE->IsConnected(): ETrue); |
|
171 } |
|
172 |
|
173 |
|
174 // --------------------------------------------------------- |
|
175 // CAHLEInterface::ConstructL |
|
176 // Light weight constructor. Real work is deferred until later. |
|
177 // An active idle object is created to do the construction when |
|
178 // things are not busy. If it is done by a task that explicitly |
|
179 // requires the AHLE client it will not need to run. |
|
180 // --------------------------------------------------------- |
|
181 void CAHLEInterface::ConstructL( TAHLENewType aNewType, |
|
182 const TDesC& aDatabase, |
|
183 TUint aPrimarySize, |
|
184 TUint aSecondarySize, |
|
185 TAHLEScore aAdaptationSpeed ) |
|
186 { |
|
187 iAHLE = NULL; |
|
188 iPrimarySize = aPrimarySize; |
|
189 iSecondarySize = aSecondarySize; |
|
190 iAdaptationSpeed = aAdaptationSpeed; |
|
191 iDatabase = aDatabase.Alloc(); |
|
192 iNewType = aNewType; |
|
193 iIdle = CIdle::NewL(CActive::EPriorityIdle); |
|
194 iIdle->Start(TCallBack(AHLEInitializationCB, this)); |
|
195 } |
|
196 |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CAHLEInterface::SetObserverL |
|
200 // ----------------------------------------------------------------------------- |
|
201 EXPORT_C void CAHLEInterface::SetObserverL( const MAHLEClientObserver* aClientObs ) |
|
202 { |
|
203 InitializeAHLEL(); |
|
204 iAHLE->SetObserverL(aClientObs); |
|
205 } |
|
206 |
|
207 |
|
208 // --------------------------------------------------------- |
|
209 // CAHLEInterface::Reconfigure |
|
210 // --------------------------------------------------------- |
|
211 EXPORT_C TInt CAHLEInterface::ReconfigureL( TUint aPrimarySize, |
|
212 TUint aSecondarySize, |
|
213 TAHLEScore aAdaptationSpeed ) |
|
214 { |
|
215 InitializeAHLEL(); |
|
216 return iAHLE->ReconfigureL(aPrimarySize, aSecondarySize, aAdaptationSpeed ); |
|
217 } |
|
218 |
|
219 |
|
220 // --------------------------------------------------------- |
|
221 // CAHLEInterface::GetConfiguration |
|
222 // --------------------------------------------------------- |
|
223 EXPORT_C void CAHLEInterface::GetConfigurationL( TUint& aPrimarySize, |
|
224 TUint& aSecondarySize, |
|
225 TAHLEScore& aAdaptationSpeed ) |
|
226 { |
|
227 InitializeAHLEL(); |
|
228 iAHLE->GetConfigurationL(aPrimarySize, aSecondarySize, aAdaptationSpeed ); |
|
229 } |
|
230 |
|
231 |
|
232 // ---------------------------------------------------------------- |
|
233 // CAHLEInterface::GetParameters |
|
234 // ---------------------------------------------------------------- |
|
235 EXPORT_C TInt CAHLEInterface::GetParameters( TAHLESortOrder& /* aOrder */ ) const |
|
236 { |
|
237 return KErrNotSupported; |
|
238 } |
|
239 |
|
240 |
|
241 // ---------------------------------------------------------------- |
|
242 // CAHLEInterface::GetParameters |
|
243 // ---------------------------------------------------------------- |
|
244 EXPORT_C TInt CAHLEInterface::GetParameters( TAHLESortOrder& /* aOrder */, |
|
245 TAny* /* aReserved */ ) const |
|
246 { |
|
247 return KErrNotSupported; |
|
248 } |
|
249 |
|
250 |
|
251 // ---------------------------------------------------------------- |
|
252 // CAHLEInterface::SetParameters |
|
253 // ---------------------------------------------------------------- |
|
254 EXPORT_C TInt CAHLEInterface::SetParameters( TAHLESortOrder /* aOrder */ ) |
|
255 { |
|
256 return KErrNotSupported; |
|
257 } |
|
258 |
|
259 EXPORT_C TInt CAHLEInterface::SetParameters( TAHLESortOrder /* aOrder */, |
|
260 TAny* /* aReserved */ ) |
|
261 { |
|
262 return KErrNotSupported; |
|
263 } |
|
264 |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CAHLEInterface::NewAccessL |
|
268 // --------------------------------------------------------- |
|
269 EXPORT_C TInt CAHLEInterface::NewAccessL( const TDesC& aItem, |
|
270 const TDesC& aItemName ) |
|
271 { |
|
272 InitializeAHLEL(); |
|
273 return (iAHLE->NewAccessL(aItem, aItemName)); |
|
274 } |
|
275 |
|
276 |
|
277 EXPORT_C void CAHLEInterface::NewAccessL( TRequestStatus& aStatus, |
|
278 const TDesC& aItem, |
|
279 const TDesC& aItemName ) |
|
280 { |
|
281 InitializeAHLEL(); |
|
282 iAHLE->NewAccessL(aStatus, aItem, aItemName); |
|
283 } |
|
284 |
|
285 |
|
286 // ---------------------------------------------------------------- |
|
287 // CAHLEInterface::AdaptiveListL |
|
288 // ---------------------------------------------------------------- |
|
289 EXPORT_C TInt CAHLEInterface::AdaptiveListL( CDesCArray& aItems, |
|
290 CDesCArray& aItemNames, |
|
291 const TInt aSize, |
|
292 const TDesC& aMatch, |
|
293 const TAHLEState aState ) |
|
294 { |
|
295 InitializeAHLEL(); |
|
296 return (iAHLE->AdaptiveListL( aItems, aItemNames, aSize, aMatch, aState )); |
|
297 } |
|
298 |
|
299 |
|
300 // --------------------------------------------------------- |
|
301 // CAHLEInterface::OrderByScoreL |
|
302 // --------------------------------------------------------- |
|
303 // |
|
304 EXPORT_C TInt CAHLEInterface::OrderByScoreL( CDesCArray& aItems, |
|
305 CDesCArray& aItemsSorted ) |
|
306 { |
|
307 InitializeAHLEL(); |
|
308 return (iAHLE->OrderByScoreL( aItems, aItemsSorted )); |
|
309 } |
|
310 |
|
311 EXPORT_C TInt CAHLEInterface::OrderByScoreL( CDesCArray& /* aItems */, |
|
312 RArray<TInt>& /* aSortOrder */ ) |
|
313 { |
|
314 return KErrNotSupported; |
|
315 } |
|
316 |
|
317 |
|
318 // --------------------------------------------------------- |
|
319 // CAHLEInterface::RemoveL |
|
320 // --------------------------------------------------------- |
|
321 EXPORT_C TInt CAHLEInterface::RemoveL( const TDesC& aItem ) |
|
322 { |
|
323 InitializeAHLEL(); |
|
324 return (iAHLE->RemoveL( aItem )); |
|
325 } |
|
326 |
|
327 EXPORT_C void CAHLEInterface::RemoveL( const TDesC& aItem, |
|
328 TRequestStatus& aStatus ) |
|
329 { |
|
330 InitializeAHLEL(); |
|
331 iAHLE->RemoveL( aItem, aStatus ); |
|
332 } |
|
333 |
|
334 EXPORT_C void CAHLEInterface::RemoveL( const CDesCArray& aItems, |
|
335 TRequestStatus &aStatus) |
|
336 { |
|
337 InitializeAHLEL(); |
|
338 iAHLE->RemoveL( aItems, aStatus ); |
|
339 } |
|
340 |
|
341 EXPORT_C TInt CAHLEInterface::RemoveL(const CDesCArray& aItems ) |
|
342 { |
|
343 InitializeAHLEL(); |
|
344 return (iAHLE->RemoveL( aItems )); |
|
345 } |
|
346 |
|
347 |
|
348 // --------------------------------------------------------- |
|
349 // CAHLEInterface::RemoveMatching |
|
350 // --------------------------------------------------------- |
|
351 EXPORT_C TInt CAHLEInterface::RemoveMatchingL( const TDesC& aMatch ) |
|
352 { |
|
353 InitializeAHLEL(); |
|
354 return (iAHLE->RemoveMatchingL( aMatch )); |
|
355 } |
|
356 |
|
357 EXPORT_C void CAHLEInterface::RemoveMatchingL( const TDesC& aMatch, |
|
358 TRequestStatus& aStatus ) |
|
359 { |
|
360 InitializeAHLEL(); |
|
361 iAHLE->RemoveMatchingL( aMatch, aStatus); |
|
362 } |
|
363 |
|
364 |
|
365 // --------------------------------------------------------- |
|
366 // CAHLEInterface::Rename |
|
367 // --------------------------------------------------------- |
|
368 EXPORT_C TInt CAHLEInterface::RenameL( const TDesC& aItem, |
|
369 const TDesC& aNewName ) |
|
370 { |
|
371 InitializeAHLEL(); |
|
372 return (iAHLE->RenameL( aItem, aNewName )); |
|
373 } |
|
374 |
|
375 |
|
376 // --------------------------------------------------------- |
|
377 // CAHLEInterface::GetName |
|
378 // --------------------------------------------------------- |
|
379 // |
|
380 EXPORT_C TInt CAHLEInterface::GetNameL( const TDesC& /* aItem */, |
|
381 TDesC& /* aName */ ) |
|
382 { |
|
383 return KErrNotSupported; |
|
384 } |
|
385 |
|
386 |
|
387 // --------------------------------------------------------- |
|
388 // CAHLEInterface::Clear |
|
389 // --------------------------------------------------------- |
|
390 EXPORT_C TInt CAHLEInterface::Clear() |
|
391 { |
|
392 //Exception may be thrown but is not expected. Return something |
|
393 //harmless in that case. |
|
394 TRAPD( error, InitializeAHLEL()); |
|
395 return (error ? 0 : iAHLE->Clear()); |
|
396 } |
|
397 |
|
398 |
|
399 // --------------------------------------------------------- |
|
400 // CAHLEInterface::Flush |
|
401 // --------------------------------------------------------- |
|
402 EXPORT_C TInt CAHLEInterface::Flush() |
|
403 { |
|
404 //Exception may be thrown but is not expected. Return something |
|
405 //harmless in that case. |
|
406 TRAPD( error, InitializeAHLEL()); |
|
407 return (error ? 0 : iAHLE->Flush()); |
|
408 } |
|
409 |