28
|
1 |
/*
|
|
2 |
* Copyright (c) 2006-2010 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: cch client api implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "cchimpl.h"
|
|
21 |
#include "cchlogger.h"
|
|
22 |
#include "cch.h"
|
|
23 |
#include "cchserviceimpl.h"
|
|
24 |
|
|
25 |
#ifdef CCHAPI_USE_CCHUI
|
|
26 |
#include "cchuiprivateapi.h"
|
|
27 |
#endif
|
|
28 |
|
|
29 |
// EXTERNAL DATA STRUCTURES
|
|
30 |
// None
|
|
31 |
|
|
32 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
33 |
// None
|
|
34 |
|
|
35 |
// CONSTANTS
|
|
36 |
// None
|
|
37 |
|
|
38 |
// MACROS
|
|
39 |
// None
|
|
40 |
|
|
41 |
// LOCAL CONSTANTS AND MACROS
|
|
42 |
// None
|
|
43 |
|
|
44 |
// MODULE DATA STRUCTURES
|
|
45 |
// None
|
|
46 |
|
|
47 |
// LOCAL FUNCTION PROTOTYPES
|
|
48 |
// None
|
|
49 |
|
|
50 |
// FORWARD DECLARATIONS
|
|
51 |
// None
|
|
52 |
|
|
53 |
// ============================= LOCAL FUNCTIONS =============================
|
|
54 |
|
|
55 |
// ============================ MEMBER FUNCTIONS =============================
|
|
56 |
|
|
57 |
// ---------------------------------------------------------------------------
|
|
58 |
// CCchImpl::CCchImpl
|
|
59 |
// C++ default constructor can NOT contain any code, that might leave.
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
CCchImpl::CCchImpl()
|
|
63 |
: CActive ( EPriorityStandard ),
|
|
64 |
iCchUi(0),
|
|
65 |
iConnectivityDialogsAllowed( EFalse )
|
|
66 |
{
|
|
67 |
CActiveScheduler::Add( this );
|
|
68 |
}
|
|
69 |
|
|
70 |
// ---------------------------------------------------------------------------
|
|
71 |
// CCchImpl::destructor
|
|
72 |
// ---------------------------------------------------------------------------
|
|
73 |
//
|
|
74 |
CCchImpl::~CCchImpl()
|
|
75 |
{
|
|
76 |
CCHLOGSTRING( "CCchImpl::~CCchImpl: IN" );
|
|
77 |
|
|
78 |
delete iCchUi;
|
|
79 |
|
|
80 |
iCchServiceImpls.ResetAndDestroy();
|
|
81 |
iCchServiceImpls.Close();
|
|
82 |
Cancel();
|
|
83 |
|
|
84 |
iCchClient.Close();
|
|
85 |
iCchServer.Close();
|
|
86 |
|
|
87 |
CCHLOGSTRING( "CCchImpl::~CCchImpl: OUT" );
|
|
88 |
}
|
|
89 |
|
|
90 |
// ---------------------------------------------------------------------------
|
|
91 |
// CCchImpl::ConstructL
|
|
92 |
// Symbian 2nd phase constructor can leave.
|
|
93 |
// ---------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CCchImpl::ConstructL( CCch& aCch )
|
|
96 |
{
|
|
97 |
CCHLOGSTRING( "CCchImpl::ConstructL: IN" );
|
|
98 |
|
|
99 |
User::LeaveIfError( iCchServer.Connect() );
|
|
100 |
User::LeaveIfError( iCchClient.Open( iCchServer ) );
|
|
101 |
|
|
102 |
#ifdef CCHAPI_USE_CCHUI
|
|
103 |
iCchUi = CCchUiPrivateApi::NewL( aCch );
|
|
104 |
#endif
|
|
105 |
|
|
106 |
iCchClient.RegisterToServer( iStatus );
|
|
107 |
SetActive();
|
|
108 |
|
|
109 |
CCHLOGSTRING( "CCchImpl::ConstructL: OUT" );
|
|
110 |
}
|
|
111 |
|
|
112 |
// ---------------------------------------------------------------------------
|
|
113 |
// CCchImpl::NewL
|
|
114 |
// Two-phased constructor.
|
|
115 |
// ---------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
CCchImpl* CCchImpl::NewL( CCch& aCch )
|
|
118 |
{
|
|
119 |
CCHLOGSTRING( "CCchImpl::NewL: IN" );
|
|
120 |
CCchImpl* self =
|
|
121 |
CCchImpl::NewLC( aCch );
|
|
122 |
CleanupStack::Pop( self );
|
|
123 |
CCHLOGSTRING( "CCchImpl::NewL: OUT" );
|
|
124 |
return self;
|
|
125 |
}
|
|
126 |
|
|
127 |
// ---------------------------------------------------------------------------
|
|
128 |
// CCchImpl::NewLC
|
|
129 |
// Two-phased constructor.
|
|
130 |
// ---------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
CCchImpl* CCchImpl::NewLC( CCch& aCch )
|
|
133 |
{
|
|
134 |
CCHLOGSTRING( "CCchImpl::NewLC: IN" );
|
|
135 |
CCchImpl* self =
|
|
136 |
new (ELeave) CCchImpl( );
|
|
137 |
CleanupStack::PushL( self );
|
|
138 |
self->ConstructL( aCch );
|
|
139 |
CCHLOGSTRING( "CCchImpl::NewLC: OUT" );
|
|
140 |
return self;
|
|
141 |
}
|
|
142 |
|
|
143 |
// ---------------------------------------------------------------------------
|
|
144 |
// CCchImpl::NewLC
|
|
145 |
// Returns the RCCHClient
|
|
146 |
// ---------------------------------------------------------------------------
|
|
147 |
//
|
|
148 |
RCCHClient& CCchImpl::CchClient( )
|
|
149 |
{
|
|
150 |
CCHLOGSTRING( "CCchImpl::CchClient: IN OUT" );
|
|
151 |
return iCchClient;
|
|
152 |
}
|
|
153 |
|
|
154 |
// ---------------------------------------------------------------------------
|
|
155 |
// CCchImpl::GetService
|
|
156 |
// ---------------------------------------------------------------------------
|
|
157 |
//
|
|
158 |
CCchService* CCchImpl::GetService( TInt aId )
|
|
159 |
{
|
|
160 |
CCHLOGSTRING( "CCchImpl::GetService: IN" );
|
|
161 |
|
|
162 |
CCchServiceImpl* cchServiceImpl = NULL;
|
|
163 |
|
|
164 |
TInt idx = FindService( aId );
|
|
165 |
if( idx == KErrNotFound )
|
|
166 |
{
|
|
167 |
TInt error = KErrNone;
|
|
168 |
TRAP( error, cchServiceImpl = GetServiceL( aId ) );
|
|
169 |
}
|
|
170 |
else
|
|
171 |
{
|
|
172 |
cchServiceImpl = iCchServiceImpls[ idx ];
|
|
173 |
}
|
|
174 |
CCHLOGSTRING( "CCchImpl::GetService: OUT" );
|
|
175 |
return cchServiceImpl;
|
|
176 |
}
|
|
177 |
|
|
178 |
// ---------------------------------------------------------------------------
|
|
179 |
// CCchImpl::GetServiceL
|
|
180 |
// ---------------------------------------------------------------------------
|
|
181 |
//
|
|
182 |
CCchServiceImpl* CCchImpl::GetServiceL( TInt aId )
|
|
183 |
{
|
|
184 |
CCchServiceImpl* cchServiceImpl = NULL;
|
|
185 |
|
|
186 |
CArrayFixFlat<TCCHService>* cchServices =
|
|
187 |
new ( ELeave ) CArrayFixFlat<TCCHService>( 1 );
|
|
188 |
CleanupStack::PushL( cchServices );
|
|
189 |
if( KErrNone == GetCchServicesL( aId, ECCHUnknown , *cchServices ) )
|
|
190 |
{
|
|
191 |
if( cchServices->Count() )
|
|
192 |
{
|
|
193 |
TCCHService service = cchServices->At( 0 );
|
|
194 |
cchServiceImpl = CCchServiceImpl::NewL( *this,
|
|
195 |
service.iServiceId,
|
|
196 |
*iCchUi );
|
|
197 |
|
|
198 |
TInt error = iCchServiceImpls.Append( cchServiceImpl );
|
|
199 |
if( error == KErrNone )
|
|
200 |
{
|
|
201 |
cchServiceImpl = iCchServiceImpls[ iCchServiceImpls.Count() - 1 ];
|
|
202 |
}
|
|
203 |
else
|
|
204 |
{
|
|
205 |
delete cchServiceImpl;
|
|
206 |
cchServiceImpl = NULL;
|
|
207 |
}
|
|
208 |
}
|
|
209 |
}
|
|
210 |
cchServices->Reset();
|
|
211 |
CleanupStack::PopAndDestroy( cchServices );
|
|
212 |
return cchServiceImpl;
|
|
213 |
}
|
|
214 |
|
|
215 |
|
|
216 |
// ---------------------------------------------------------------------------
|
|
217 |
// CCchImpl::GetCchServiceL
|
|
218 |
// ---------------------------------------------------------------------------
|
|
219 |
//
|
|
220 |
TInt CCchImpl::GetCchServicesL( TInt aServiceId, TCCHSubserviceType aType,
|
|
221 |
CArrayFixFlat<TCCHService>& aServices )
|
|
222 |
{
|
|
223 |
TServiceSelection selection( aServiceId, aType, ECchInitial );
|
|
224 |
TRequestStatus status = KErrNone;
|
|
225 |
|
|
226 |
iCchClient.GetServicesL( selection, aServices, status );
|
|
227 |
//even the cchclient api seems to be asynchronous,
|
|
228 |
//this method is completed immediately
|
|
229 |
User::WaitForRequest( status );
|
|
230 |
return status.Int();
|
|
231 |
}
|
|
232 |
|
|
233 |
// ---------------------------------------------------------------------------
|
|
234 |
// CCchImpl::GetServiceIdsL
|
|
235 |
// ---------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CCchImpl::GetServiceIdsL( RArray<TInt>& aIds )
|
|
238 |
{
|
|
239 |
CCHLOGSTRING( "CCchImpl::GetServiceIdsL: IN" );
|
|
240 |
|
|
241 |
TRequestStatus status( KErrNone );
|
|
242 |
CArrayFixFlat<TCCHService>* cchServices = new (ELeave) CArrayFixFlat<TCCHService>(1);
|
|
243 |
CleanupStack::PushL( cchServices );
|
|
244 |
|
|
245 |
iCchClient.GetServicesL( *cchServices, status );
|
|
246 |
|
|
247 |
//even the cchclient api seems to be asynchronous,
|
|
248 |
//this method is completed immediately
|
|
249 |
User::WaitForRequest( status );
|
|
250 |
if( KErrNone == status.Int() )
|
|
251 |
{
|
|
252 |
for ( TInt i = 0; i < cchServices->Count(); i++ )
|
|
253 |
{
|
|
254 |
TCCHService service = cchServices->At( i );
|
|
255 |
User::LeaveIfError( aIds.Append( service.iServiceId ) );
|
|
256 |
}
|
|
257 |
}
|
|
258 |
else
|
|
259 |
{
|
|
260 |
User::Leave( status.Int() );
|
|
261 |
}
|
|
262 |
CleanupStack::PopAndDestroy( cchServices );
|
|
263 |
|
|
264 |
CCHLOGSTRING( "CCchImpl::GetServiceIdsL: OUT" );
|
|
265 |
}
|
|
266 |
|
|
267 |
// ---------------------------------------------------------------------------
|
|
268 |
// CCchImpl::GetServiceIds
|
|
269 |
// ---------------------------------------------------------------------------
|
|
270 |
//
|
|
271 |
TInt CCchImpl::GetServiceIds( RArray<TInt>& aIds )
|
|
272 |
{
|
|
273 |
TRAPD( err, GetServiceIdsL( aIds ) );
|
|
274 |
|
|
275 |
return err;
|
|
276 |
}
|
|
277 |
|
|
278 |
// ---------------------------------------------------------------------------
|
|
279 |
// CCchImpl::GetServices
|
|
280 |
// ---------------------------------------------------------------------------
|
|
281 |
//
|
|
282 |
TInt CCchImpl::GetServices( TCCHSubserviceType aType,
|
|
283 |
RPointerArray<CCchService>& aServices )
|
|
284 |
{
|
|
285 |
TInt err = KErrNone;
|
|
286 |
TRAP( err, GetServicesL( aType, aServices ) );
|
|
287 |
return err;
|
|
288 |
}
|
|
289 |
|
|
290 |
// ---------------------------------------------------------------------------
|
|
291 |
// CCchImpl::GetServicesL
|
|
292 |
// ---------------------------------------------------------------------------
|
|
293 |
//
|
|
294 |
void CCchImpl::GetServicesL( TCCHSubserviceType aType,
|
|
295 |
RPointerArray<CCchService>& aServices )
|
|
296 |
{
|
|
297 |
CCHLOGSTRING( "CCchImpl::GetServicesL: IN" );
|
|
298 |
|
|
299 |
CleanupClosePushL( aServices ); // CS: 1
|
|
300 |
|
|
301 |
TInt error = KErrNone;
|
|
302 |
TServiceSelection selection( 0, aType, ECchInitial );
|
|
303 |
|
|
304 |
CCchServiceImpl* cchServiceImpl = NULL;
|
|
305 |
CArrayFixFlat<TCCHService>* cchServices;
|
|
306 |
cchServices = new (ELeave) CArrayFixFlat<TCCHService>(1);
|
|
307 |
CleanupStack::PushL( cchServices ); // CS: 2
|
|
308 |
error = GetCchServicesL( 0, aType, *cchServices );
|
|
309 |
|
|
310 |
if( KErrNone == error )
|
|
311 |
{
|
|
312 |
for ( TInt i = 0; i < cchServices->Count(); i++ )
|
|
313 |
{
|
|
314 |
TCCHService service = cchServices->At( i );
|
|
315 |
TInt idx = FindService( service.iServiceId );
|
|
316 |
|
|
317 |
if( KErrNotFound == idx )
|
|
318 |
{
|
|
319 |
cchServiceImpl = CCchServiceImpl::NewLC( *this, // CS: 3
|
|
320 |
service.iServiceId, *iCchUi );
|
|
321 |
iCchServiceImpls.AppendL( cchServiceImpl );
|
|
322 |
CleanupStack::Pop( cchServiceImpl ); // CS: 2
|
|
323 |
}
|
|
324 |
else
|
|
325 |
{
|
|
326 |
cchServiceImpl = iCchServiceImpls[ idx ];
|
|
327 |
}
|
|
328 |
|
|
329 |
aServices.AppendL( cchServiceImpl );
|
|
330 |
}
|
|
331 |
}
|
|
332 |
|
|
333 |
cchServices->Reset();
|
|
334 |
CleanupStack::PopAndDestroy( cchServices ); // CS: 1
|
|
335 |
User::LeaveIfError( error );
|
|
336 |
CleanupStack::Pop( &aServices ); // CS: 0
|
|
337 |
|
|
338 |
CCHLOGSTRING( "CCchImpl::GetServicesL: OUT" );
|
|
339 |
}
|
|
340 |
|
|
341 |
// ---------------------------------------------------------------------------
|
|
342 |
// CCCHServiceHandler::FindService
|
|
343 |
// ---------------------------------------------------------------------------
|
|
344 |
//
|
|
345 |
TInt CCchImpl::FindService( TInt aServiceId ) const
|
|
346 |
{
|
|
347 |
TBool exist = EFalse;
|
|
348 |
TInt index = KErrNotFound;
|
|
349 |
CCHLOGSTRING2( "CCchImpl::FindService: serviceId %d", aServiceId );
|
|
350 |
for ( TInt i = 0; i < iCchServiceImpls.Count() && !exist; i++ )
|
|
351 |
{
|
|
352 |
exist = iCchServiceImpls[i]->ServiceId() == aServiceId;
|
|
353 |
index = i;
|
|
354 |
}
|
|
355 |
return !exist ? KErrNotFound : index;
|
|
356 |
}
|
|
357 |
|
|
358 |
// ---------------------------------------------------------------------------
|
|
359 |
// CCCHServiceHandler::ConnectivityDialogsAllowed
|
|
360 |
// ---------------------------------------------------------------------------
|
|
361 |
//
|
|
362 |
TBool CCchImpl::ConnectivityDialogsAllowed() const
|
|
363 |
{
|
|
364 |
CCHLOGSTRING( "CCchImpl::ConnectivityDialogsAllowed" );
|
|
365 |
CCHLOGSTRING2( " --> iConnectivityDialogsAllowed=%d",
|
|
366 |
iConnectivityDialogsAllowed );
|
|
367 |
|
|
368 |
return iConnectivityDialogsAllowed;
|
|
369 |
}
|
|
370 |
|
|
371 |
// ---------------------------------------------------------------------------
|
|
372 |
// CCCHServiceHandler::SetConnectivityDialogsAllowed
|
|
373 |
// ---------------------------------------------------------------------------
|
|
374 |
//
|
|
375 |
void CCchImpl::SetConnectivityDialogsAllowed(
|
|
376 |
TBool aConnectivityDialogsAllowed )
|
|
377 |
{
|
|
378 |
iConnectivityDialogsAllowed = aConnectivityDialogsAllowed;
|
|
379 |
}
|
|
380 |
|
|
381 |
// ---------------------------------------------------------------------------
|
|
382 |
// CCCHServiceHandler::CchUiApi
|
|
383 |
// ---------------------------------------------------------------------------
|
|
384 |
//
|
|
385 |
MCchUi& CCchImpl::CchUiApi() const
|
|
386 |
{
|
|
387 |
return *iCchUi;
|
|
388 |
}
|
|
389 |
|
|
390 |
// ---------------------------------------------------------------------------
|
|
391 |
// CCchImpl::DoCancel
|
|
392 |
// ---------------------------------------------------------------------------
|
|
393 |
//
|
|
394 |
void CCchImpl::DoCancel()
|
|
395 |
{
|
|
396 |
CCHLOGSTRING( "CCchImpl::DoCancel: IN" );
|
|
397 |
iCchClient.RegisterToServerCancel();
|
|
398 |
CCHLOGSTRING( "CCchImpl::DoCancel: OUT" );
|
|
399 |
}
|
|
400 |
|
|
401 |
// ---------------------------------------------------------------------------
|
|
402 |
// CCchImpl::RunL
|
|
403 |
// ---------------------------------------------------------------------------
|
|
404 |
//
|
|
405 |
void CCchImpl::RunL()
|
|
406 |
{
|
|
407 |
CCHLOGSTRING( "CCchImpl::RunL: IN" );
|
|
408 |
if ( iStatus.Int() == KErrServerTerminated )
|
|
409 |
{
|
|
410 |
// clean
|
|
411 |
Cancel();
|
|
412 |
iCchClient.Close();
|
|
413 |
iCchServer.Close();
|
|
414 |
|
|
415 |
// create new
|
|
416 |
User::LeaveIfError( iCchServer.Connect() );
|
|
417 |
User::LeaveIfError( iCchClient.Open( iCchServer ) );
|
|
418 |
|
|
419 |
iCchClient.RegisterToServer( iStatus );
|
|
420 |
SetActive();
|
|
421 |
}
|
|
422 |
CCHLOGSTRING( "CCchImpl::RunL: OUT" );
|
|
423 |
}
|
|
424 |
|
|
425 |
// ---------------------------------------------------------------------------
|
|
426 |
// CCchImpl::RunL
|
|
427 |
// ---------------------------------------------------------------------------
|
|
428 |
//
|
|
429 |
TInt CCchImpl::RunError( TInt /*aError*/ )
|
|
430 |
{
|
|
431 |
return KErrNone;
|
|
432 |
}
|
|
433 |
|
|
434 |
// End of File
|