examples/Base/FeatMngrExample/FeatureChecker/src/FeatureChecker.cpp

00001 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "FeatureChecker.h"
00017 #include <e32cons.h>
00018 
00019 void CFeatureChecker::ConstructL()
00020         {
00021         iFeatNotifier = CFeatureNotifier::NewL(*this);
00022         }
00023 
00024 CFeatureChecker* CFeatureChecker::NewL()
00025         {
00026         CFeatureChecker* self=new(ELeave)CFeatureChecker();
00027         CleanupStack::PushL(self);
00028         self->ConstructL();
00029         CleanupStack::Pop(self);
00030         return self;
00031         }
00032 
00036 CFeatureChecker::~CFeatureChecker()
00037         {
00038         delete iFeatNotifier;
00039         }
00040 
00044 void CFeatureChecker::NotifyFeatureL()
00045         {
00046         RFeatureUidArray featArray;
00047         CleanupClosePushL(featArray);
00048         TUid uidFeature;
00049 
00050         //Number of feature UIDs which are subscribed to for notification.
00051         const TInt KNumFeaturesforNotification(10);
00052 
00053         //Base feature UID for which notification requests are made. This is the same UID range which 
00054         //the user can use when adding features to the FeatMngrExample process.
00055         TUid KFeatureUidforNotification = {0x12000000};
00056         
00057         //Append the UIDs to featArray.
00058         for( int k=0; k<=KNumFeaturesforNotification; k++)
00059                 {
00060                 uidFeature.iUid = KFeatureUidforNotification.iUid + k;
00061                 featArray.Append(uidFeature);
00062                 }
00063         
00064         //Request notification for user defined features.
00065         User::LeaveIfError(iFeatNotifier->NotifyRequest(featArray));
00066         CleanupStack::PopAndDestroy(&featArray);
00067         }
00068 
00072 void CFeatureChecker::HandleNotifyError(TInt /*err*/)
00073         {
00074         }
00075 
00081 void CFeatureChecker::HandleNotifyChange(TFeatureChangeType aType, TFeatureEntry /*aFeature*/)
00082         {
00083         const TInt KFeatureChangeTypeMaxSize(45);
00084         TBuf<KFeatureChangeTypeMaxSize> changetype;
00085         switch(aType)
00086                 {
00087                 case EFeatureNoChange: 
00088                         _LIT(KNoChange, "Feature status not changed");
00089                         changetype.Copy(KNoChange);
00090                         break;
00091                 case EFeatureStatusUpdated :
00092                         _LIT(KStatusUpdated, "Feature status changed to enabled or disabled");
00093                         changetype.Copy(KStatusUpdated);
00094                         break;
00095                 case EFeatureDataUpdated: 
00096                         _LIT(KDataUpdated, "Feature data changed");
00097                         changetype.Copy(KDataUpdated);
00098                         break;
00099                 case EFeatureStatusDataUpdated: 
00100                         //not used in the current version.
00101                         _LIT(KStatusDataUpdated, "Feature status and data changed");
00102                         changetype.Copy(KStatusDataUpdated);
00103                         break;
00104                 case EFeatureRediscover: 
00105                         //not used in the current version.
00106                         _LIT(KFeatureRediscover, "Complex change occurred, reload all features");
00107                         changetype.Copy(KFeatureRediscover);
00108                         break;
00109                 case EFeatureFeatureCreated:
00110                         _LIT(KFeatureCreated, "New feature has been added to the system");
00111                         changetype.Copy(KFeatureCreated);
00112                         break;
00113                 case EFeatureFeatureDeleted: 
00114                         _LIT(KFeatureDeleted, "Feature has been deleted");
00115                         changetype.Copy(KFeatureDeleted);
00116                         break;
00117                 }
00118         //Print the change type as an infoprint.
00119         User::InfoPrint(changetype);
00120         }
00121 
00126 static void MainL()
00127         {
00128         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00129         CleanupStack::PushL(scheduler);
00130         CActiveScheduler::Install(scheduler);
00131         
00132         CFeatureChecker* featChecker = CFeatureChecker::NewL();
00133         CleanupStack::PushL(featChecker);
00134         //Issue feature change notification request.
00135         featChecker->NotifyFeatureL();
00136         CActiveScheduler::Start();
00137         
00138         CleanupStack::PopAndDestroy(featChecker);
00139         CleanupStack::PopAndDestroy(scheduler);
00140         }
00141 
00142 extern TInt E32Main()
00143         {
00144         // Create cleanup stack
00145         __UHEAP_MARK;
00146         CTrapCleanup* cleanup = CTrapCleanup::New();
00147         if(cleanup == NULL)
00148                 {
00149                 return KErrNoMemory;
00150                 }
00151         // Run application code inside TRAP harness.
00152         TRAPD(mainError, MainL());
00153         if(mainError != KErrNone)
00154                 {
00155                 _LIT(KUserPanic,"Failed to complete");  
00156                 User::Panic(KUserPanic, mainError);
00157                 }
00158         delete cleanup;
00159         __UHEAP_MARKEND;
00160         return KErrNone;
00161         }

Generated by  doxygen 1.6.2