00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "FeatMngrExample.h"
00032 #include <e32base.h>
00033 #include <e32std.h>
00034 #include <e32def.h>
00035 #include <e32cmn.h>
00036
00037
00038 _LIT(KNewline, "\n");
00039
00040 CFeatMngrExample* CFeatMngrExample::NewL(TInt aPriority)
00041 {
00042 CFeatMngrExample* self=new(ELeave)CFeatMngrExample(aPriority);
00043 CleanupStack::PushL(self);
00044 self->ConstructL();
00045 CleanupStack::Pop(self);
00046 return self;
00047 }
00048
00049 void CFeatMngrExample::ConstructL()
00050 {
00051
00052 _LIT(KTextConsoleTitle, "FeatureManager");
00053 iConsole = Console::NewL(KTextConsoleTitle, TSize(KConsFullScreen,KConsFullScreen));
00054 _LIT(KWelcome, "Welcome to the Feature Management Example\n");
00055 iConsole->Printf(KWelcome);
00056
00057
00058 _LIT(KProcessName, "FeatureChecker.exe");
00059 User::LeaveIfError(iProcess.Create(KProcessName, KNullDesC));
00060 iProcess.Resume();
00061
00062 User::LeaveIfError(iFeatControl.Open());
00063 }
00064
00065 CFeatMngrExample::CFeatMngrExample(TInt aPriority):CActive( aPriority )
00066 {
00067 CActiveScheduler::Add(this);
00068 }
00069
00073 CFeatMngrExample::~CFeatMngrExample()
00074 {
00075 Cancel();
00076 delete iConsole;
00077 iFeatControl.Close();
00078 iProcess.Close();
00079 }
00080
00081 void CFeatMngrExample::RunL()
00082 {
00083 TRAPD(err,ProcessKeyPressL(TChar(iConsole->KeyCode())));
00084 if(err != KErrNone)
00085 {
00086 iConsole->Printf(_L("Failed. Error: %d\r\n"),err);
00087 RequestCharacter();
00088 }
00089 }
00090
00095 void CFeatMngrExample::ProcessKeyPressL(TChar aChar)
00096 {
00097 switch(aChar)
00098 {
00099 case '1':
00100 {
00101 ListFeaturesL();
00102 break;
00103 }
00104 case '2':
00105 {
00106 AddL();
00107 break;
00108 }
00109 case '3':
00110 {
00111 UpdateL();
00112 break;
00113 }
00114 case '4':
00115 {
00116 EnableFeatureL();
00117 break;
00118 }
00119 case '5':
00120 {
00121 DeleteL();
00122 break;
00123 }
00124 case '6':
00125 {
00126 CheckFeatureSupportL();
00127 break;
00128 }
00129 default:
00130 CActiveScheduler::Stop();
00131 break;
00132 }
00133 }
00134
00139 void CFeatMngrExample::AddL()
00140 {
00141 _LIT(KFeat, "Enter the UID of the feature to be added.\n");
00142 _LIT(KSelectUIDL1, "Select any UID, but in order to receive notification from featurechecker.exe,\n");
00143 _LIT(KSelectUIDL2,"choose a UID from the range 12000000 to 1200001A.\n");
00144 _LIT(KSelectUIDL3, "Notification takes the form of an info message displayed at the top right\n");
00145 _LIT(KSelectUIDL4, "corner of the screen.\n");
00146 iConsole->Printf(KFeat);
00147 iConsole->Printf(KSelectUIDL1);
00148 iConsole->Printf(KSelectUIDL2);
00149 iConsole->Printf(KSelectUIDL3);
00150 iConsole->Printf(KSelectUIDL4);
00151 TUid uidFeature;
00152 uidFeature.iUid = GetUserInput(EFalse);
00153
00154 TBitFlags32 flags(0);
00155
00156 flags.Set( EFeatureSupported );
00157 flags.Set( EFeatureModifiable );
00158
00159 _LIT(KSetFeaturedata, "\nEnter an integer value to set the feature data\n");
00160 iConsole->Printf(KSetFeaturedata);
00161 TUint32 fdata = GetUserInput(ETrue);
00162 iConsole->Printf(KNewline);
00163 TFeatureEntry featureEntry(uidFeature ,flags, fdata);
00164 TInt featadded = User::LeaveIfError(iFeatControl.AddFeature(featureEntry));
00165 if(featadded == KErrNone)
00166 {
00167 _LIT(KFeatureAdded, "A new feature is added.\n");
00168 iConsole->Printf(KFeatureAdded);
00169 }
00170 RequestCharacter();
00171 }
00172
00177 void CFeatMngrExample::DeleteL()
00178 {
00179 _LIT(KUIDtoDelete, "Enter the UID of the feature to delete\n");
00180 iConsole->Printf(KUIDtoDelete);
00181 TUid uidFeature;
00182 uidFeature.iUid = GetUserInput(EFalse);
00183 iConsole->Printf(KNewline);
00184 TInt featdeleted = User::LeaveIfError(iFeatControl.DeleteFeature(uidFeature));
00185 if(featdeleted == KErrNone)
00186 {
00187 _LIT(KFeatDeleted, "The feature is deleted.\n");
00188 iConsole->Printf(KFeatDeleted);
00189 }
00190 RequestCharacter();
00191 }
00192
00197 void CFeatMngrExample::EnableFeatureL()
00198 {
00199 _LIT(KUIDtoEnable, "Enter the UID of the feature to enable/disable\n");
00200 iConsole->Printf(KUIDtoEnable);
00201 TUid uidFeature;
00202 uidFeature.iUid = GetUserInput(EFalse);
00203
00204 _LIT(KEnable, "\nPress e/d to enable/disable it\n");
00205 iConsole->Printf(KEnable);
00206 TChar ch = iConsole->Getch();
00207 if(ch == 'e')
00208 {
00209 User::LeaveIfError(iFeatControl.EnableFeature(uidFeature));
00210 }
00211 else if(ch == 'd')
00212 {
00213 User::LeaveIfError(iFeatControl.DisableFeature(uidFeature));
00214 }
00215 RequestCharacter();
00216 }
00217
00222 void CFeatMngrExample::CheckFeatureSupportL()
00223 {
00224 _LIT(KPrintUIDtoCheck, "Enter the UID to check if it is supported\n");
00225 iConsole->Printf(KPrintUIDtoCheck);
00226
00227 TUid uidFeature;
00228 uidFeature.iUid = GetUserInput(EFalse);
00229 iConsole->Printf(KNewline);
00230 User::LeaveIfError(iFeatControl.FeatureSupported(uidFeature));
00231
00232 TInt err = iFeatControl.FeatureSupported(uidFeature);
00233 if(err == KFeatureSupported)
00234 {
00235 _LIT(KFeatSupported, "\nThis feature is supported\n");
00236 iConsole->Printf(KFeatSupported);
00237 }
00238 else if(err == KFeatureUnsupported)
00239 {
00240 _LIT(KFeatNotsupported, "\nThis feature is not supported\n");
00241 iConsole->Printf(KFeatNotsupported);
00242 }
00243 else if(err == KErrNotFound)
00244 {
00245 _LIT(KFeatNotFound, "\nThis feature is not found\n");
00246 iConsole->Printf(KFeatNotFound);
00247 }
00248 else
00249 {
00250 _LIT(KErr, "Failed : %d");
00251 iConsole->Printf(KErr, err);
00252 }
00253
00254 RequestCharacter();
00255 }
00256
00260 void CFeatMngrExample::ListFeaturesL()
00261 {
00262 RFeatureUidArray supportedFeatures;
00263 CleanupClosePushL(supportedFeatures);
00264
00265 iFeatControl.ListSupportedFeatures(supportedFeatures);
00266 TInt featureCount = supportedFeatures.Count();
00267 _LIT(KFeatureCount, "The number of features present is : %d \n");
00268 iConsole->Printf(KFeatureCount, featureCount);
00269 for(int j=0; j< featureCount; j++)
00270 {
00271 _LIT(KFeatureUID, "Feature UID%d is %x \n");
00272 iConsole->Printf(KFeatureUID, (j+1), supportedFeatures[j]);
00273
00274 if((j+1)%12 == 0)
00275 {
00276 _LIT(KPress, "Press any key to continue\n");
00277 iConsole->Printf(KPress);
00278 iConsole->Getch();
00279 }
00280 }
00281 CleanupStack::PopAndDestroy(&supportedFeatures);
00282 RequestCharacter();
00283 }
00284
00292 TInt64 CFeatMngrExample::GetUserInput(TBool aDecimal)
00293 {
00294 TBufC<50> buf;
00295 TPtr ptr(buf.Des());
00296 TKeyCode ch = iConsole->Getch();
00297 while(ch != EKeyEnter)
00298 {
00299 _LIT(KChar, "%c");
00300 iConsole->Printf(KChar,ch);
00301 if(ch!= EKeyBackspace)
00302 {
00303 ptr.Append(ch);
00304 }
00305 ch=iConsole->Getch();
00306 }
00307 TInt64 value;
00308 TInt err;
00309 if(aDecimal)
00310 {
00311 err = TLex(ptr).Val(value);
00312 }
00313 else
00314 {
00315 err = TLex(ptr).Val(value, EHex);
00316 }
00317 if (err == KErrNone)
00318 {
00319 return value;
00320 }
00321 else
00322 {
00323 return KErrArgument;
00324 }
00325 }
00326
00330 void CFeatMngrExample::UpdateL()
00331 {
00332 _LIT(KFeatUpdate, "Enter the UID of the feature to be updated\n");
00333 iConsole->Printf(KFeatUpdate);
00334 TUid uidFeature;
00335 uidFeature.iUid = GetUserInput(EFalse);
00336
00337 _LIT(KSetFeaturedata, "\nEnter a number to set as the feature data\n");
00338 iConsole->Printf(KSetFeaturedata);
00339 TUint32 fdata = GetUserInput(ETrue);
00340 iConsole->Printf(KNewline);
00341
00342 User::LeaveIfError(iFeatControl.SetFeature(uidFeature , fdata));
00343 RequestCharacter();
00344 }
00345
00346
00347 void CFeatMngrExample::DoCancel()
00348 {
00349 iConsole->ReadCancel();
00350 }
00351
00352
00353 void CFeatMngrExample::RequestCharacter()
00354 {
00355 _LIT(KMenuL1,"\nSelect one option from the following:\n");
00356 _LIT(KMenuL2,"1.List the features currently present\n");
00357 _LIT(KMenuL3,"2.Add a feature\n");
00358 _LIT(KMenuL4,"3.Update a feature\n");
00359 _LIT(KMenuL5,"4.Enable/Disable a feature\n");
00360 _LIT(KMenuL6,"5.Delete a feature\n");
00361 _LIT(KMenuL7,"6.Check feature support\n");
00362 _LIT(KMenuL8,"Press any other key to exit\n");
00363
00364 iConsole->Printf(KMenuL1);
00365 iConsole->Printf(KMenuL2);
00366 iConsole->Printf(KMenuL3);
00367 iConsole->Printf(KMenuL4);
00368 iConsole->Printf(KMenuL5);
00369 iConsole->Printf(KMenuL6);
00370 iConsole->Printf(KMenuL7);
00371 iConsole->Printf(KMenuL8);
00372 iConsole->Printf(KNewline);
00373
00374 iConsole->Read(iStatus);
00375 if(!IsActive())
00376 {
00377 SetActive();
00378 }
00379 }
00380
00381 static void MainL()
00382 {
00383 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler();
00384 CleanupStack::PushL(scheduler);
00385 CActiveScheduler::Install(scheduler);
00386
00387 CFeatMngrExample* featMngr = CFeatMngrExample::NewL();
00388 CleanupStack::PushL(featMngr);
00389 featMngr->RequestCharacter();
00390 CActiveScheduler::Start();
00391
00392 CleanupStack::PopAndDestroy(featMngr);
00393 CleanupStack::PopAndDestroy(scheduler);
00394 }
00395
00396 extern TInt E32Main()
00397 {
00398
00399 __UHEAP_MARK;
00400 CTrapCleanup* cleanup = CTrapCleanup::New();
00401 if(cleanup == NULL)
00402 {
00403 return KErrNoMemory;
00404 }
00405
00406 TRAPD(mainError, MainL());
00407 if(mainError != KErrNone)
00408 {
00409 _LIT(KUserPanic,"Failed to complete");
00410 User::Panic(KUserPanic, mainError);
00411 }
00412 delete cleanup;
00413 __UHEAP_MARKEND;
00414 return KErrNone;
00415 }