28
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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: Service storage class.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "scpservicestorage.h"
|
|
20 |
#include "scplogger.h"
|
|
21 |
#include "scpservice.h"
|
|
22 |
#include "scpsubservice.h"
|
|
23 |
#include "scpsettinghandler.h"
|
|
24 |
|
|
25 |
const TInt KServiceIdCounterIncrement = 100;
|
|
26 |
|
|
27 |
// -----------------------------------------------------------------------------
|
|
28 |
// CScpServiceStorage::CScpServiceStorage
|
|
29 |
// -----------------------------------------------------------------------------
|
|
30 |
//
|
|
31 |
CScpServiceStorage::CScpServiceStorage( CScpSettingHandler& aSettingHandler ) :
|
|
32 |
iSettingHandler( aSettingHandler )
|
|
33 |
{
|
|
34 |
}
|
|
35 |
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
// CScpServiceStorage::NewL
|
|
38 |
// -----------------------------------------------------------------------------
|
|
39 |
//
|
|
40 |
CScpServiceStorage* CScpServiceStorage::NewL( CScpSettingHandler& aSettingHandler )
|
|
41 |
{
|
|
42 |
SCPLOGSTRING( "CScpServiceStorage::NewL" );
|
|
43 |
|
|
44 |
CScpServiceStorage* self = new ( ELeave ) CScpServiceStorage( aSettingHandler );
|
|
45 |
return self;
|
|
46 |
}
|
|
47 |
|
|
48 |
// -----------------------------------------------------------------------------
|
|
49 |
// CScpServiceStorage::~CScpServiceStorage
|
|
50 |
// -----------------------------------------------------------------------------
|
|
51 |
//
|
|
52 |
CScpServiceStorage::~CScpServiceStorage()
|
|
53 |
{
|
|
54 |
SCPLOGSTRING( "CScpServiceStorage::~CScpServiceStorage" );
|
|
55 |
|
|
56 |
iServiceItems.ResetAndDestroy();
|
|
57 |
iServiceItems.Close();
|
|
58 |
}
|
|
59 |
|
|
60 |
// -----------------------------------------------------------------------------
|
|
61 |
// CScpServiceStorage::CreateServiceL
|
|
62 |
// -----------------------------------------------------------------------------
|
|
63 |
//
|
|
64 |
CScpService& CScpServiceStorage::CreateServiceL(
|
|
65 |
TInt aServiceId,
|
|
66 |
CScpProfileHandler& aProfileHandler,
|
|
67 |
MCchServiceObserver& aServiceObserver )
|
|
68 |
{
|
|
69 |
SCPLOGSTRING( "CScpServiceStorage::CreateServiceL" );
|
|
70 |
|
|
71 |
CScpService* service( NULL );
|
|
72 |
|
|
73 |
// Check that the service id does not already exist
|
|
74 |
service = GetServiceByServiceId( aServiceId );
|
|
75 |
if( service )
|
|
76 |
{
|
|
77 |
User::Leave( KErrAlreadyExists );
|
|
78 |
}
|
|
79 |
|
|
80 |
TInt newId = GenerateNewInternalIdForService();
|
|
81 |
|
|
82 |
service = CScpService::NewL( newId,
|
|
83 |
aServiceId,
|
|
84 |
aProfileHandler,
|
|
85 |
*this,
|
|
86 |
aServiceObserver );
|
|
87 |
|
|
88 |
CleanupStack::PushL( service );
|
|
89 |
iServiceItems.AppendL( service );
|
|
90 |
CleanupStack::Pop( service );
|
|
91 |
|
|
92 |
CScpService* lastService = iServiceItems[ iServiceItems.Count() - 1 ];
|
|
93 |
return *lastService;
|
|
94 |
}
|
|
95 |
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
// CScpServiceStorage::GenerateNewServiceId
|
|
98 |
// -----------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
TInt CScpServiceStorage::GenerateNewInternalIdForService()
|
|
101 |
{
|
|
102 |
SCPLOGSTRING( "CScpServiceStorage::GenerateNewInternalIdForService" );
|
|
103 |
|
|
104 |
iServiceIdCounter += KServiceIdCounterIncrement;
|
|
105 |
|
|
106 |
return iServiceIdCounter;
|
|
107 |
}
|
|
108 |
|
|
109 |
// -----------------------------------------------------------------------------
|
|
110 |
// CScpServiceStorage::RemoveService
|
|
111 |
// -----------------------------------------------------------------------------
|
|
112 |
//
|
|
113 |
TInt CScpServiceStorage::RemoveService( TInt aId )
|
|
114 |
{
|
|
115 |
SCPLOGSTRING2( "CScpServiceStorage::RemoveService id: %d", aId );
|
|
116 |
|
|
117 |
for( TInt i=0; i<iServiceItems.Count(); i++)
|
|
118 |
{
|
|
119 |
CScpService* service = iServiceItems[ i ];
|
|
120 |
if( service && aId == service->Id() )
|
|
121 |
{
|
|
122 |
delete service;
|
|
123 |
iServiceItems.Remove( i );
|
|
124 |
return KErrNone;
|
|
125 |
}
|
|
126 |
}
|
|
127 |
|
|
128 |
return KErrNotFound;
|
|
129 |
}
|
|
130 |
|
|
131 |
// -----------------------------------------------------------------------------
|
|
132 |
// CScpServiceStorage::RemoveDisabledServices
|
|
133 |
// -----------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
void CScpServiceStorage::RemoveDisabledServices()
|
|
136 |
{
|
|
137 |
SCPLOGSTRING( "CScpServiceStorage::RemoveEmptyServices" );
|
|
138 |
|
|
139 |
RArray< TInt > subServiceIds;
|
|
140 |
RArray< TInt > removedServiceIds;
|
|
141 |
|
|
142 |
for( TInt i=0; i<iServiceItems.Count(); i++)
|
|
143 |
{
|
|
144 |
CScpService* service = iServiceItems[ i ];
|
|
145 |
if( service )
|
|
146 |
{
|
|
147 |
subServiceIds.Reset();
|
|
148 |
|
|
149 |
service->GetSubServiceIds( subServiceIds );
|
|
150 |
|
|
151 |
TBool remove( ETrue );
|
|
152 |
|
|
153 |
// Remove if there are no sub services
|
|
154 |
if( subServiceIds.Count() > 0 )
|
|
155 |
{
|
|
156 |
for ( TInt j=0; j<subServiceIds.Count(); j++ )
|
|
157 |
{
|
|
158 |
CScpSubService* subService =
|
|
159 |
service->GetSubService( subServiceIds[ j ] );
|
|
160 |
|
|
161 |
// Don't remove if there is at least one enabled or disconnecting
|
|
162 |
// sub service
|
|
163 |
if( subService && (
|
|
164 |
subService->EnableRequestedState() == CScpSubService::EScpEnabled ||
|
|
165 |
subService->State() == ECCHDisconnecting ) )
|
|
166 |
{
|
|
167 |
remove = EFalse;
|
|
168 |
}
|
|
169 |
else if ( subService )
|
|
170 |
{
|
|
171 |
service->RemoveSubService( subService->Id() );
|
|
172 |
}
|
|
173 |
}
|
|
174 |
}
|
|
175 |
|
|
176 |
if( remove )
|
|
177 |
{
|
|
178 |
removedServiceIds.Append( service->Id() );
|
|
179 |
}
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
for( TInt i=0; i<removedServiceIds.Count(); i++ )
|
|
184 |
{
|
|
185 |
RemoveService( removedServiceIds[ i ] );
|
|
186 |
}
|
|
187 |
|
|
188 |
removedServiceIds.Close();
|
|
189 |
subServiceIds.Close();
|
|
190 |
}
|
|
191 |
|
|
192 |
// -----------------------------------------------------------------------------
|
|
193 |
// CScpServiceStorage::GetService
|
|
194 |
// -----------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
CScpService* CScpServiceStorage::GetService( TInt aId ) const
|
|
197 |
{
|
|
198 |
SCPLOGSTRING2( "CScpServiceStorage::GetService id: %d", aId );
|
|
199 |
|
|
200 |
for( TInt i=0; i<iServiceItems.Count(); i++)
|
|
201 |
{
|
|
202 |
CScpService* service = iServiceItems[ i ];
|
|
203 |
if( aId == service->Id() )
|
|
204 |
{
|
|
205 |
return service;
|
|
206 |
}
|
|
207 |
}
|
|
208 |
|
|
209 |
return NULL;
|
|
210 |
}
|
|
211 |
|
|
212 |
// -----------------------------------------------------------------------------
|
|
213 |
// CScpServiceStorage::GetServiceByServiceId
|
|
214 |
// -----------------------------------------------------------------------------
|
|
215 |
//
|
|
216 |
CScpService* CScpServiceStorage::GetServiceByServiceId( TUint aServiceId ) const
|
|
217 |
{
|
|
218 |
SCPLOGSTRING2( "CScpServiceStorage::GetServiceByServiceId id: %d", aServiceId );
|
|
219 |
|
|
220 |
for( TInt i=0; i<iServiceItems.Count(); i++)
|
|
221 |
{
|
|
222 |
CScpService* service = iServiceItems[ i ];
|
|
223 |
if( aServiceId == service->ServiceId() )
|
|
224 |
{
|
|
225 |
return service;
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
return NULL;
|
|
230 |
}
|
|
231 |
|
|
232 |
// -----------------------------------------------------------------------------
|
|
233 |
// CScpServiceStorage::GetSubService
|
|
234 |
// -----------------------------------------------------------------------------
|
|
235 |
//
|
|
236 |
CScpSubService* CScpServiceStorage::GetSubService( TInt aId ) const
|
|
237 |
{
|
|
238 |
SCPLOGSTRING2( "CScpServiceStorage::GetSubService id: %d", aId );
|
|
239 |
|
|
240 |
CScpSubService* returnSubService( NULL );
|
|
241 |
|
|
242 |
RArray<TInt> subServiceIds;
|
|
243 |
for( TInt i=0; i<iServiceItems.Count() && !returnSubService; i++)
|
|
244 |
{
|
|
245 |
CScpService* service = iServiceItems[ i ];
|
|
246 |
|
|
247 |
subServiceIds.Reset();
|
|
248 |
service->GetSubServiceIds( subServiceIds );
|
|
249 |
|
|
250 |
for( TInt j=0; j<subServiceIds.Count(); j++)
|
|
251 |
{
|
|
252 |
returnSubService = service->GetSubService( subServiceIds[ j ] );
|
|
253 |
|
|
254 |
if( returnSubService )
|
|
255 |
{
|
|
256 |
if( returnSubService->Id() == aId )
|
|
257 |
{
|
|
258 |
break;
|
|
259 |
}
|
|
260 |
else
|
|
261 |
{
|
|
262 |
returnSubService = NULL;
|
|
263 |
}
|
|
264 |
}
|
|
265 |
}
|
|
266 |
}
|
|
267 |
|
|
268 |
subServiceIds.Close();
|
|
269 |
|
|
270 |
return returnSubService;
|
|
271 |
}
|
|
272 |
|
|
273 |
// -----------------------------------------------------------------------------
|
|
274 |
// CScpServiceStorage::GetServiceIds
|
|
275 |
// -----------------------------------------------------------------------------
|
|
276 |
//
|
|
277 |
void CScpServiceStorage::GetServiceIds( RArray<TInt>& aIds ) const
|
|
278 |
{
|
|
279 |
SCPLOGSTRING( "CScpServiceStorage::GetServiceIds" );
|
|
280 |
__ASSERT_DEBUG( aIds.Count() == 0, User::Panic( KNullDesC, KErrGeneral ) );
|
|
281 |
|
|
282 |
for( TInt i=0; i<iServiceItems.Count(); i++)
|
|
283 |
{
|
|
284 |
CScpService* service = iServiceItems[ i ];
|
|
285 |
aIds.Append( service->Id() );
|
|
286 |
}
|
|
287 |
}
|
|
288 |
|
|
289 |
// -----------------------------------------------------------------------------
|
|
290 |
// CScpServiceStorage::GetSubServiceIds
|
|
291 |
// -----------------------------------------------------------------------------
|
|
292 |
//
|
|
293 |
void CScpServiceStorage::GetSubServiceIds( RArray<TInt>& aIds ) const
|
|
294 |
{
|
|
295 |
SCPLOGSTRING( "CScpServiceStorage::GetSubServiceIds" );
|
|
296 |
__ASSERT_DEBUG( aIds.Count() == 0, User::Panic( KNullDesC, KErrGeneral ) );
|
|
297 |
|
|
298 |
RArray<TInt> subServiceIds;
|
|
299 |
|
|
300 |
for( TInt i=0; i<iServiceItems.Count(); i++ )
|
|
301 |
{
|
|
302 |
CScpService* service = iServiceItems[ i ];
|
|
303 |
|
|
304 |
subServiceIds.Reset();
|
|
305 |
service->GetSubServiceIds( subServiceIds );
|
|
306 |
|
|
307 |
for( TInt j=0; j<subServiceIds.Count(); j++ )
|
|
308 |
{
|
|
309 |
aIds.Append( subServiceIds[ j ] );
|
|
310 |
}
|
|
311 |
}
|
|
312 |
|
|
313 |
subServiceIds.Close();
|
|
314 |
}
|
|
315 |
|
|
316 |
// -----------------------------------------------------------------------------
|
|
317 |
// CScpServiceStorage::GetSubServiceIds
|
|
318 |
// -----------------------------------------------------------------------------
|
|
319 |
//
|
|
320 |
void CScpServiceStorage::GetSubServiceIds( TCCHSubserviceType aSubServiceType,
|
|
321 |
RArray<TInt>& aIds ) const
|
|
322 |
{
|
|
323 |
SCPLOGSTRING( "CScpServiceStorage::GetSubServiceIds" );
|
|
324 |
__ASSERT_DEBUG( aIds.Count() == 0, User::Panic( KNullDesC, KErrGeneral ) );
|
|
325 |
|
|
326 |
RArray< TInt > subServiceIds;
|
|
327 |
GetSubServiceIds( subServiceIds );
|
|
328 |
|
|
329 |
for( TInt i=0; i<subServiceIds.Count(); i++ )
|
|
330 |
{
|
|
331 |
CScpSubService* subService;
|
|
332 |
subService = GetSubService( subServiceIds[ i ] );
|
|
333 |
|
|
334 |
if( subService && subService->SubServiceType() == aSubServiceType )
|
|
335 |
{
|
|
336 |
aIds.Append( subService->Id() );
|
|
337 |
}
|
|
338 |
}
|
|
339 |
|
|
340 |
subServiceIds.Close();
|
|
341 |
}
|
|
342 |
|
|
343 |
// -----------------------------------------------------------------------------
|
|
344 |
// CScpServiceStorage::GetSubServiceIds
|
|
345 |
// -----------------------------------------------------------------------------
|
|
346 |
//
|
|
347 |
void CScpServiceStorage::GetSubServiceIds( TUint32 aProfileId,
|
|
348 |
TCCHSubserviceType aSubServiceType,
|
|
349 |
RArray<TInt>& aIds ) const
|
|
350 |
{
|
|
351 |
SCPLOGSTRING3( "CScpServiceStorage::GetSubServiceIds profileId: %d type: %d",
|
|
352 |
aProfileId, aSubServiceType );
|
|
353 |
__ASSERT_DEBUG( aIds.Count() == 0, User::Panic( KNullDesC, KErrGeneral ) );
|
|
354 |
|
|
355 |
RArray< TInt > subServiceIds;
|
|
356 |
GetSubServiceIds( subServiceIds );
|
|
357 |
|
|
358 |
for( TInt i=0; i<subServiceIds.Count(); i++ )
|
|
359 |
{
|
|
360 |
CScpSubService* subService;
|
|
361 |
subService = GetSubService( subServiceIds[ i ] );
|
|
362 |
|
|
363 |
if( subService &&
|
|
364 |
subService->SipProfileId() == aProfileId &&
|
|
365 |
( subService->SubServiceType() == aSubServiceType ||
|
|
366 |
aSubServiceType == ECCHUnknown ) )
|
|
367 |
{
|
|
368 |
aIds.Append( subService->Id() );
|
|
369 |
}
|
|
370 |
}
|
|
371 |
|
|
372 |
subServiceIds.Close();
|
|
373 |
}
|
|
374 |
|
|
375 |
// -----------------------------------------------------------------------------
|
|
376 |
// CScpServiceStorage::IsSubServiceEnabled
|
|
377 |
// -----------------------------------------------------------------------------
|
|
378 |
//
|
|
379 |
TBool CScpServiceStorage::IsSubServiceEnabled( TUint32 aProfileId ) const
|
|
380 |
{
|
|
381 |
SCPLOGSTRING2( "CScpServiceStorage::IsSubServiceEnabled profile id: %d",
|
|
382 |
aProfileId );
|
|
383 |
|
|
384 |
TBool result( EFalse );
|
|
385 |
RArray< TInt > subServiceIds;
|
|
386 |
|
|
387 |
GetSubServiceIds( aProfileId, ECCHUnknown, subServiceIds );
|
|
388 |
|
|
389 |
for( TInt i=0; i<subServiceIds.Count(); i++ )
|
|
390 |
{
|
|
391 |
CScpSubService* subService = GetSubService( subServiceIds[ i ] );
|
|
392 |
if( subService )
|
|
393 |
{
|
|
394 |
// Find at least one sub service that is still enabled
|
|
395 |
if( subService->EnableRequestedState() == CScpSubService::EScpEnabled )
|
|
396 |
{
|
|
397 |
result = ETrue;
|
|
398 |
break;
|
|
399 |
}
|
|
400 |
}
|
|
401 |
}
|
|
402 |
|
|
403 |
subServiceIds.Close();
|
|
404 |
return result;
|
|
405 |
}
|
|
406 |
|
|
407 |
// -----------------------------------------------------------------------------
|
|
408 |
// CScpServiceStorage::AreAllSubServicesDisconnected
|
|
409 |
// -----------------------------------------------------------------------------
|
|
410 |
//
|
|
411 |
TBool CScpServiceStorage::AreAllSubServicesDisconnected( TUint32 aProfileId ) const
|
|
412 |
{
|
|
413 |
SCPLOGSTRING2( "CScpServiceStorage::AreAllSubServicesDisconnected profile id: %d",
|
|
414 |
aProfileId );
|
|
415 |
|
|
416 |
TBool result( ETrue );
|
|
417 |
RArray< TInt > subServiceIds;
|
|
418 |
|
|
419 |
GetSubServiceIds( aProfileId, ECCHUnknown, subServiceIds );
|
|
420 |
|
|
421 |
for( TInt i=0; i<subServiceIds.Count(); i++ )
|
|
422 |
{
|
|
423 |
CScpSubService* subService = GetSubService( subServiceIds[ i ] );
|
|
424 |
if( subService )
|
|
425 |
{
|
|
426 |
// Find at least one sub service that has been disabled but
|
|
427 |
// it has not yet disconnected the service
|
|
428 |
if( subService->EnableRequestedState() == CScpSubService::EScpDisabled &&
|
|
429 |
subService->SubServiceDisconnected() == EFalse )
|
|
430 |
{
|
|
431 |
result = EFalse;
|
|
432 |
break;
|
|
433 |
}
|
|
434 |
}
|
|
435 |
}
|
|
436 |
|
|
437 |
subServiceIds.Close();
|
|
438 |
return result;
|
|
439 |
}
|
|
440 |
|
|
441 |
// -----------------------------------------------------------------------------
|
|
442 |
// CScpServiceStorage::SettingsHandler
|
|
443 |
// -----------------------------------------------------------------------------
|
|
444 |
//
|
|
445 |
CScpSettingHandler& CScpServiceStorage::SettingsHandler()
|
|
446 |
{
|
|
447 |
SCPLOGSTRING( "CScpServiceStorage::SettingsHandler" );
|
|
448 |
|
|
449 |
return iSettingHandler;
|
|
450 |
}
|
|
451 |
|
|
452 |
|
|
453 |
#ifdef _DEBUG
|
|
454 |
// -----------------------------------------------------------------------------
|
|
455 |
// CScpServiceStorage::GetDebugInfo
|
|
456 |
// -----------------------------------------------------------------------------
|
|
457 |
//
|
|
458 |
void CScpServiceStorage::GetDebugInfo( TDes& aInfo ) const
|
|
459 |
{
|
|
460 |
TInt serviceCount = iServiceItems.Count();
|
|
461 |
TInt subServiceCount( 0 );
|
|
462 |
TInt enabledSubServices( 0 );
|
|
463 |
|
|
464 |
for( TInt i=0; i<serviceCount; i++ )
|
|
465 |
{
|
|
466 |
CScpService* service = iServiceItems[ i ];
|
|
467 |
subServiceCount += service->SubServiceCount();
|
|
468 |
|
|
469 |
RArray<TInt> subServiceIds;
|
|
470 |
service->GetSubServiceIds( subServiceIds );
|
|
471 |
|
|
472 |
for( TInt j=0; j<subServiceIds.Count(); j++ )
|
|
473 |
{
|
|
474 |
CScpSubService* subService = service->GetSubService( subServiceIds[ j ] );
|
|
475 |
|
|
476 |
if( subService &&
|
|
477 |
subService->EnableRequestedState() == CScpSubService::EScpEnabled )
|
|
478 |
{
|
|
479 |
enabledSubServices++;
|
|
480 |
}
|
|
481 |
}
|
|
482 |
|
|
483 |
subServiceIds.Close();
|
|
484 |
}
|
|
485 |
|
|
486 |
TBuf< 255 > buffer;
|
|
487 |
buffer.Format( _L( "\nServices: %d\n SubServices: %d\n Enabled: %d\n" ),
|
|
488 |
serviceCount, subServiceCount, enabledSubServices );
|
|
489 |
|
|
490 |
aInfo.Append( buffer );
|
|
491 |
}
|
|
492 |
#endif
|
|
493 |
|
|
494 |
// End of File
|
|
495 |
|