featuremgmt/featuremgr/src/clientdll/featurenotifier.cpp
changeset 0 08ec8eefde2f
child 11 667e88a979d7
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <featmgr/featurenotifier.h>
       
    20 #include "featmgrdebug.h"
       
    21 #include <featmgr/featurecmn.h>
       
    22 #include "featmgrclient.h"
       
    23 
       
    24 // ============================= LOCAL FUNCTIONS ===============================
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // FindByUid
       
    28 // Returns Zero if UIDs do match.
       
    29 // -----------------------------------------------------------------------------
       
    30 //  
       
    31 static TInt FindByUid( const TUid* aFeature, const TUid& aItem )
       
    32     {
       
    33     if ( aFeature->iUid == aItem.iUid )
       
    34         {
       
    35         return 1;
       
    36         }
       
    37 
       
    38     return 0;
       
    39     }
       
    40 
       
    41     
       
    42 // ============================ MEMBER FUNCTIONS ===============================
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CFeatureNotifier::CFeatureNotifier()
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CFeatureNotifier::CFeatureNotifier( MFeatureObserver& aObserver ) :
       
    49     CActive( EPriorityStandard ),
       
    50     iObserver( aObserver )
       
    51     {
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CFeatureNotifier::NewL()
       
    56 // Two-phased constructor.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CFeatureNotifier* CFeatureNotifier::NewL( MFeatureObserver& aObserver )
       
    60     {
       
    61     CFeatureNotifier* self = new( ELeave ) CFeatureNotifier( aObserver );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL();
       
    64     CleanupStack::Pop( self );
       
    65     return self;
       
    66     }
       
    67     
       
    68 // -----------------------------------------------------------------------------
       
    69 // CFeatureNotifier::ConstructL
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void CFeatureNotifier::ConstructL()
       
    73     {
       
    74     FUNC_LOG
       
    75 
       
    76     iFeatMgrClient = new (ELeave) RFeatMgrClient;
       
    77     // Connect to Feature Manager server
       
    78     TInt err( iFeatMgrClient->Connect() );
       
    79     User::LeaveIfError(err);
       
    80 
       
    81     CActiveScheduler::Add( this );
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CFeatureNotifier::~CFeatureNotifier()
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C CFeatureNotifier::~CFeatureNotifier()
       
    89     {
       
    90     FUNC_LOG
       
    91     
       
    92     if( iFeatMgrClient )
       
    93     	{
       
    94     	iFeatMgrClient->RequestNotifyCancelAll();
       
    95         iFeatMgrClient->Close();
       
    96         delete iFeatMgrClient;
       
    97     	}
       
    98     Cancel();
       
    99 
       
   100     iFeatures.Close();
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CFeatureNotifier::NotifyRequest(TUid)
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C TInt CFeatureNotifier::NotifyRequest( TUid aFeature )
       
   108     {
       
   109     if(IsActive())
       
   110         {
       
   111         return KErrAlreadyExists;
       
   112         }
       
   113 
       
   114     iFeatures.Reset();
       
   115     iFeatures.Append( aFeature );
       
   116     TInt err = iFeatMgrClient->RequestNotification( iFeatures, iFeatureChanged, iStatus );
       
   117     if ( err == KErrNone )
       
   118     	{
       
   119         SetActive();
       
   120      	}
       
   121      	    
       
   122     return err;
       
   123     }
       
   124     
       
   125 // -----------------------------------------------------------------------------
       
   126 // CFeatureNotifier::NotifyRequest(RFeatureUidArray&)
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C TInt CFeatureNotifier::NotifyRequest( RFeatureUidArray& aFeatures )
       
   130     {
       
   131     if(IsActive())
       
   132         {
       
   133         return KErrAlreadyExists;
       
   134         }
       
   135 
       
   136     iFeatures.Reset();
       
   137     TInt count = aFeatures.Count();
       
   138     
       
   139     for(TInt i = 0; i < count; i++ )
       
   140         {
       
   141         // Do not append duplicate entries
       
   142         const TUid& uid( aFeatures[i] );
       
   143         TInt index = iFeatures.Find( uid, FindByUid );
       
   144         if( index == KErrNotFound )
       
   145             {
       
   146             iFeatures.Append( uid );
       
   147             }
       
   148         }
       
   149 
       
   150     TInt err = iFeatMgrClient->RequestNotification( iFeatures, iFeatureChanged, iStatus );
       
   151     if ( err == KErrNone )
       
   152     	{
       
   153         SetActive();
       
   154      	}
       
   155     
       
   156     return err;
       
   157     }
       
   158     
       
   159 // -----------------------------------------------------------------------------
       
   160 // CFeatureNotifier::NotifyCancel(TUid aFeature)
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 EXPORT_C TInt CFeatureNotifier::NotifyCancel( TUid aFeature )
       
   164     {
       
   165     TInt err( KErrNotFound );
       
   166     TInt count = iFeatures.Count();
       
   167     
       
   168     for(TInt i = 0; i < count; i++ )
       
   169         {
       
   170         if( iFeatures[i].iUid == aFeature.iUid )
       
   171             {
       
   172             err = iFeatMgrClient->RequestNotifyCancel( aFeature );
       
   173             
       
   174             if( err == KErrNone )
       
   175                 {
       
   176                 iFeatures.Remove( i );
       
   177                 // If this is the last feature in the list, then also cancel the Active Object
       
   178                 if( 0 == iFeatures.Count() )
       
   179                 	{
       
   180 	                Cancel();
       
   181                 	}
       
   182                 break;
       
   183                 }
       
   184             }
       
   185         }
       
   186 
       
   187     return err;
       
   188     }
       
   189     
       
   190 // -----------------------------------------------------------------------------
       
   191 // CFeatureNotifier::NotifyCancelAll()
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C TInt CFeatureNotifier::NotifyCancelAll()
       
   195     {
       
   196     iFeatures.Reset();
       
   197     TInt err = iFeatMgrClient->RequestNotifyCancelAll( );
       
   198    	Cancel();
       
   199     
       
   200     return err;
       
   201     }
       
   202 
       
   203 /**
       
   204  Gets the number of features in the server's array.
       
   205  This API is only for internal use and testing purposes.
       
   206 
       
   207  @return The number of features on the server for debug builds, otherwise it returns KErrNotSupported in release builds.
       
   208  @internalComponent
       
   209 */
       
   210 EXPORT_C TInt CFeatureNotifier::NumberOfNotifyFeatures()
       
   211     {
       
   212 #ifdef EXTENDED_FEATURE_MANAGER_TEST
       
   213     TInt count = iFeatMgrClient->NumberOfNotifyFeatures();
       
   214     return count;
       
   215 #else
       
   216     return KErrNotSupported;
       
   217 #endif
       
   218     }
       
   219 
       
   220 /**
       
   221  Gets the number of heap cells in the thread.
       
   222  This API is only for internal use and testing purposes.
       
   223 
       
   224  @return The number of heap cells for debug build, otherwise it returns KErrNotSupported in release builds.
       
   225  @internalComponent
       
   226 */
       
   227 EXPORT_C TInt CFeatureNotifier::CountAllocCells()
       
   228     {
       
   229 #ifdef EXTENDED_FEATURE_MANAGER_TEST
       
   230     TInt count = iFeatMgrClient->CountAllocCells();
       
   231     return count;
       
   232 #else
       
   233     return KErrNotSupported;
       
   234 #endif
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CFeatureNotifier::RunL()
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 void CFeatureNotifier::RunL( )
       
   242     {
       
   243     FUNC_LOG
       
   244 
       
   245     TInt status = iStatus.Int();
       
   246     if( status < 0 )
       
   247         {
       
   248         // Got an error
       
   249         if( status != KErrCancel )
       
   250             {
       
   251             iObserver.HandleNotifyError( status );
       
   252             }
       
   253         return;
       
   254         }
       
   255 
       
   256     // iStatus >= 0 means it contains the change type
       
   257     TFeatureChangeType changeType = static_cast<TFeatureChangeType>(status);
       
   258 
       
   259 	// If the feature was deleted, remove it from the array of features with notifications requested
       
   260     if( changeType == EFeatureFeatureDeleted )
       
   261     	{
       
   262         TInt index = iFeatures.Find( iFeatureChanged, FindByUid );
       
   263         if( index != KErrNotFound )
       
   264             {
       
   265             iFeatures.Remove( index );
       
   266             }
       
   267     	}
       
   268     // Should we validate whether iFeatureChanged matches 
       
   269     // to any UID in the array of requested features?
       
   270 
       
   271     TFeatureEntry feature( iFeatureChanged );
       
   272     if( iFeatures.Count() > 0 )
       
   273         {
       
   274         // Asynchronously resubscribe notify request
       
   275         iFeatMgrClient->ReRequestNotification( iFeatureChanged, iStatus );
       
   276         // Next inform client about changed feature 
       
   277         // Should we validate whether iFeatureChanged matches 
       
   278         // to any UID in the array of requested features
       
   279         iObserver.HandleNotifyChange( changeType, feature );
       
   280         // Set us active
       
   281         SetActive();
       
   282         }
       
   283     else
       
   284         {
       
   285         // All features with notifications requested were deleted,
       
   286         // so don't need to resubscribe notify request -
       
   287         // just notify client about the deleted feature
       
   288         iObserver.HandleNotifyChange( changeType, feature );
       
   289         }
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CFeatureNotifier::DoCancel()
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CFeatureNotifier::DoCancel( )
       
   297     {
       
   298     }
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CFeatureNotifier::RunError()
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 TInt CFeatureNotifier::RunError( TInt aError )
       
   305     {
       
   306     iObserver.HandleNotifyError( aError );
       
   307 
       
   308     return KErrNone;
       
   309     }
       
   310 
       
   311 //  End of File