First public contribution.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 #include <featmgr/featurenotifier.h>
20 #include "featmgrdebug.h"
21 #include <featmgr/featurecmn.h>
22 #include "featmgrclient.h"
24 // ============================= LOCAL FUNCTIONS ===============================
26 // -----------------------------------------------------------------------------
28 // Returns Zero if UIDs do match.
29 // -----------------------------------------------------------------------------
31 static TInt FindByUid( const TUid* aFeature, const TUid& aItem )
33 if ( aFeature->iUid == aItem.iUid )
42 // ============================ MEMBER FUNCTIONS ===============================
44 // -----------------------------------------------------------------------------
45 // CFeatureNotifier::CFeatureNotifier()
46 // -----------------------------------------------------------------------------
48 CFeatureNotifier::CFeatureNotifier( MFeatureObserver& aObserver ) :
49 CActive( EPriorityStandard ),
50 iObserver( aObserver )
54 // -----------------------------------------------------------------------------
55 // CFeatureNotifier::NewL()
56 // Two-phased constructor.
57 // -----------------------------------------------------------------------------
59 EXPORT_C CFeatureNotifier* CFeatureNotifier::NewL( MFeatureObserver& aObserver )
61 CFeatureNotifier* self = new( ELeave ) CFeatureNotifier( aObserver );
62 CleanupStack::PushL( self );
64 CleanupStack::Pop( self );
68 // -----------------------------------------------------------------------------
69 // CFeatureNotifier::ConstructL
70 // -----------------------------------------------------------------------------
72 void CFeatureNotifier::ConstructL()
76 iFeatMgrClient = new (ELeave) RFeatMgrClient;
77 // Connect to Feature Manager server
78 TInt err( iFeatMgrClient->Connect() );
81 delete iFeatMgrClient;
84 User::LeaveIfError(err);
86 CActiveScheduler::Add( this );
89 // -----------------------------------------------------------------------------
90 // CFeatureNotifier::~CFeatureNotifier()
91 // -----------------------------------------------------------------------------
93 EXPORT_C CFeatureNotifier::~CFeatureNotifier()
99 iFeatMgrClient->RequestNotifyCancelAll();
100 iFeatMgrClient->Close();
101 delete iFeatMgrClient;
108 // -----------------------------------------------------------------------------
109 // CFeatureNotifier::NotifyRequest(TUid)
110 // -----------------------------------------------------------------------------
112 EXPORT_C TInt CFeatureNotifier::NotifyRequest( TUid aFeature )
116 return KErrAlreadyExists;
120 TInt err=iFeatures.Append( aFeature );
125 err = iFeatMgrClient->RequestNotification( iFeatures, iFeatureChanged, iStatus );
126 if ( err == KErrNone )
138 // -----------------------------------------------------------------------------
139 // CFeatureNotifier::NotifyRequest(RFeatureUidArray&)
140 // -----------------------------------------------------------------------------
142 EXPORT_C TInt CFeatureNotifier::NotifyRequest( RFeatureUidArray& aFeatures )
146 return KErrAlreadyExists;
150 TInt count = aFeatures.Count();
152 for(TInt i = 0; i < count; i++ )
154 // Do not append duplicate entries
155 const TUid& uid( aFeatures[i] );
156 TInt index = iFeatures.Find( uid, FindByUid );
157 if( index == KErrNotFound )
159 err=iFeatures.Append( uid );
168 err = iFeatMgrClient->RequestNotification( iFeatures, iFeatureChanged, iStatus );
169 if ( err == KErrNone )
180 // -----------------------------------------------------------------------------
181 // CFeatureNotifier::NotifyCancel(TUid aFeature)
182 // -----------------------------------------------------------------------------
184 EXPORT_C TInt CFeatureNotifier::NotifyCancel( TUid aFeature )
186 TInt err( KErrNotFound );
187 TInt count = iFeatures.Count();
189 for(TInt i = 0; i < count; i++ )
191 if( iFeatures[i].iUid == aFeature.iUid )
193 err = iFeatMgrClient->RequestNotifyCancel( aFeature );
195 if( err == KErrNone )
197 iFeatures.Remove( i );
198 // If this is the last feature in the list, then also cancel the Active Object
199 if( 0 == iFeatures.Count() )
211 // -----------------------------------------------------------------------------
212 // CFeatureNotifier::NotifyCancelAll()
213 // -----------------------------------------------------------------------------
215 EXPORT_C TInt CFeatureNotifier::NotifyCancelAll()
218 TInt err = iFeatMgrClient->RequestNotifyCancelAll( );
225 Gets the number of features in the server's array.
226 This API is only for internal use and testing purposes.
228 @return The number of features on the server for debug builds, otherwise it returns KErrNotSupported in release builds.
231 EXPORT_C TInt CFeatureNotifier::NumberOfNotifyFeatures()
233 #ifdef EXTENDED_FEATURE_MANAGER_TEST
234 TInt count = iFeatMgrClient->NumberOfNotifyFeatures();
237 return KErrNotSupported;
242 Gets the number of heap cells in the thread.
243 This API is only for internal use and testing purposes.
245 @return The number of heap cells for debug build, otherwise it returns KErrNotSupported in release builds.
248 EXPORT_C TInt CFeatureNotifier::CountAllocCells()
250 #ifdef EXTENDED_FEATURE_MANAGER_TEST
251 TInt count = iFeatMgrClient->CountAllocCells();
254 return KErrNotSupported;
258 // -----------------------------------------------------------------------------
259 // CFeatureNotifier::RunL()
260 // -----------------------------------------------------------------------------
262 void CFeatureNotifier::RunL( )
266 TInt status = iStatus.Int();
270 if( status != KErrCancel )
272 iObserver.HandleNotifyError( status );
277 // iStatus >= 0 means it contains the change type
278 TFeatureChangeType changeType = static_cast<TFeatureChangeType>(status);
280 // If the feature was deleted, remove it from the array of features with notifications requested
281 if( changeType == EFeatureFeatureDeleted )
283 TInt index = iFeatures.Find( iFeatureChanged, FindByUid );
284 if( index != KErrNotFound )
286 iFeatures.Remove( index );
289 // Should we validate whether iFeatureChanged matches
290 // to any UID in the array of requested features?
292 TFeatureEntry feature( iFeatureChanged );
293 if( iFeatures.Count() > 0 )
295 // Asynchronously resubscribe notify request
296 iFeatMgrClient->ReRequestNotification( iFeatureChanged, iStatus );
297 // Next inform client about changed feature
298 // Should we validate whether iFeatureChanged matches
299 // to any UID in the array of requested features
300 iObserver.HandleNotifyChange( changeType, feature );
306 // All features with notifications requested were deleted,
307 // so don't need to resubscribe notify request -
308 // just notify client about the deleted feature
309 iObserver.HandleNotifyChange( changeType, feature );
313 // -----------------------------------------------------------------------------
314 // CFeatureNotifier::DoCancel()
315 // -----------------------------------------------------------------------------
317 void CFeatureNotifier::DoCancel( )
321 // -----------------------------------------------------------------------------
322 // CFeatureNotifier::RunError()
323 // -----------------------------------------------------------------------------
325 TInt CFeatureNotifier::RunError( TInt aError )
327 iObserver.HandleNotifyError( aError );