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

00001 /*
00002 Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description:  
00028 */
00029 
00030 
00031 #include "FeatureChecker.h"
00032 #include <e32cons.h>
00033 
00034 void CFeatureChecker::ConstructL()
00035         {
00036         iFeatNotifier = CFeatureNotifier::NewL(*this);
00037         }
00038 
00039 CFeatureChecker* CFeatureChecker::NewL()
00040         {
00041         CFeatureChecker* self=new(ELeave)CFeatureChecker();
00042         CleanupStack::PushL(self);
00043         self->ConstructL();
00044         CleanupStack::Pop(self);
00045         return self;
00046         }
00047 
00051 CFeatureChecker::~CFeatureChecker()
00052         {
00053         delete iFeatNotifier;
00054         }
00055 
00059 void CFeatureChecker::NotifyFeatureL()
00060         {
00061         RFeatureUidArray featArray;
00062         CleanupClosePushL(featArray);
00063         TUid uidFeature;
00064 
00065         //Number of feature UIDs which are subscribed to for notification.
00066         const TInt KNumFeaturesforNotification(10);
00067 
00068         //Base feature UID for which notification requests are made. This is the same UID range which 
00069         //the user can use when adding features to the FeatMngrExample process.
00070         TUid KFeatureUidforNotification = {0x12000000};
00071         
00072         //Append the UIDs to featArray.
00073         for( int k=0; k<=KNumFeaturesforNotification; k++)
00074                 {
00075                 uidFeature.iUid = KFeatureUidforNotification.iUid + k;
00076                 featArray.Append(uidFeature);
00077                 }
00078         
00079         //Request notification for user defined features.
00080         User::LeaveIfError(iFeatNotifier->NotifyRequest(featArray));
00081         CleanupStack::PopAndDestroy(&featArray);
00082         }
00083 
00087 void CFeatureChecker::HandleNotifyError(TInt /*err*/)
00088         {
00089         }
00090 
00096 void CFeatureChecker::HandleNotifyChange(TFeatureChangeType aType, TFeatureEntry /*aFeature*/)
00097         {
00098         const TInt KFeatureChangeTypeMaxSize(45);
00099         TBuf<KFeatureChangeTypeMaxSize> changetype;
00100         switch(aType)
00101                 {
00102                 case EFeatureNoChange: 
00103                         _LIT(KNoChange, "Feature status not changed");
00104                         changetype.Copy(KNoChange);
00105                         break;
00106                 case EFeatureStatusUpdated :
00107                         _LIT(KStatusUpdated, "Feature status changed to enabled or disabled");
00108                         changetype.Copy(KStatusUpdated);
00109                         break;
00110                 case EFeatureDataUpdated: 
00111                         _LIT(KDataUpdated, "Feature data changed");
00112                         changetype.Copy(KDataUpdated);
00113                         break;
00114                 case EFeatureStatusDataUpdated: 
00115                         //not used in the current version.
00116                         _LIT(KStatusDataUpdated, "Feature status and data changed");
00117                         changetype.Copy(KStatusDataUpdated);
00118                         break;
00119                 case EFeatureRediscover: 
00120                         //not used in the current version.
00121                         _LIT(KFeatureRediscover, "Complex change occurred, reload all features");
00122                         changetype.Copy(KFeatureRediscover);
00123                         break;
00124                 case EFeatureFeatureCreated:
00125                         _LIT(KFeatureCreated, "New feature has been added to the system");
00126                         changetype.Copy(KFeatureCreated);
00127                         break;
00128                 case EFeatureFeatureDeleted: 
00129                         _LIT(KFeatureDeleted, "Feature has been deleted");
00130                         changetype.Copy(KFeatureDeleted);
00131                         break;
00132                 }
00133         //Print the change type as an infoprint.
00134         User::InfoPrint(changetype);
00135         }
00136 
00141 static void MainL()
00142         {
00143         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00144         CleanupStack::PushL(scheduler);
00145         CActiveScheduler::Install(scheduler);
00146         
00147         CFeatureChecker* featChecker = CFeatureChecker::NewL();
00148         CleanupStack::PushL(featChecker);
00149         //Issue feature change notification request.
00150         featChecker->NotifyFeatureL();
00151         CActiveScheduler::Start();
00152         
00153         CleanupStack::PopAndDestroy(featChecker);
00154         CleanupStack::PopAndDestroy(scheduler);
00155         }
00156 
00157 extern TInt E32Main()
00158         {
00159         // Create cleanup stack
00160         __UHEAP_MARK;
00161         CTrapCleanup* cleanup = CTrapCleanup::New();
00162         if(cleanup == NULL)
00163                 {
00164                 return KErrNoMemory;
00165                 }
00166         // Run application code inside TRAP harness.
00167         TRAPD(mainError, MainL());
00168         if(mainError != KErrNone)
00169                 {
00170                 _LIT(KUserPanic,"Failed to complete");  
00171                 User::Panic(KUserPanic, mainError);
00172                 }
00173         delete cleanup;
00174         __UHEAP_MARKEND;
00175         return KErrNone;
00176         }

Generated by  doxygen 1.6.2