examples/Base/resourcemanager/resourcemanager.cpp

00001 // Copyright (c) 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 // Demonstrates the Resource Manager's user side API, RBusDevResManUs
00015 
00016 #include <e32cons.h>
00017 #include <d32resmanus.h>
00018 
00019 _LIT(KTxtExampleCode,"PRM Example");
00020 _LIT(KTxtFailed,"\nFailed with error : %d \n");
00021 _LIT(KTxtPressAnyKey," \nPress any key to continue\n");
00022 _LIT(KEnterResourceIdValue,"\nEnter the resource ID - any number other than zero: ");
00023 _LIT(KTxtStateChange,"\nState of the resource after the change: %d");
00024 _LIT(KPrintNoOfClients,"\nNumber of clients is %d \n");
00025 _LIT(KTxtOptionNotSupported,"\nThis option is not supported\n");
00031 _LIT8(KClient,"resourcemanager");
00032 TClientName gName(KClient);
00033 
00034 //Indicates whether kernel-side (as well as user-side) clients are included in the request.
00035 const TBool gIsKernelClient = EFalse;
00036 
00037 //Holds the resource ID selected by the user
00038 TUint gResourceId;
00039 
00044 RBusDevResManUs gChannel;
00045 
00046 CConsoleBase* gConsole;
00047 
00048 TUint gNumClients = 0; //The number of resource manager clients
00049 TUint gNumResources = 0; //The number of available resources
00050 
00056 TInt gReadValue = 0;
00057 
00061 TUint GetUserInput()
00062         {
00063         TBufC<50> buf;
00064         TPtr ptr(buf.Des());
00065         TKeyCode ch = gConsole->Getch();
00066         while(ch != EKeyEnter)
00067                 {
00068                 _LIT(KChar, "%c");
00069                 gConsole->Printf(KChar,ch);
00070                 if(ch!= EKeyBackspace)
00071                         {
00072                         ptr.Append(ch);
00073                         }
00074                 ch=gConsole->Getch();                           
00075                 }
00076         TUint value;
00077 
00078         TUint err = TLex(ptr).Val(value, EDecimal);
00079         
00080         if(value == 0)
00081                 {
00082                 gConsole->Printf(KTxtOptionNotSupported);
00083                 return (TUint)KErrNotSupported;;
00084                 }
00085         else
00086                 {
00087                 if (err == (TUint)KErrNone)
00088                         {
00089                         return value;
00090                         }
00091                 else 
00092                         {
00093                         return (TUint)KErrNotSupported;; // Error condition - could not parse input to number.
00094                         }
00095                 }
00096         }
00097 
00101 void GetNoOfResources()
00102         {
00103         _LIT(KTxtOption,"\nGet the number of resources \n");
00104         gConsole->Printf(KTxtOption);
00105         TInt err=gChannel.GetNoOfResources(gNumResources);
00106         if(err != KErrNone)
00107                 {
00108                 gConsole->Printf(KTxtFailed,err);
00109                 }
00110         else
00111                 {
00112                 _LIT(KPrintNoOfResources,"\nNumber of resources = %d \n");
00113                 gConsole->Printf(KPrintNoOfResources,gNumResources);
00114                 }
00115         }
00116 
00121 void GetResourceInfo()
00122         {
00123         _LIT(KTxtOption,"\nGet information about a particular resource...\n");
00124         gConsole->Printf(KTxtOption);
00125         //Request the user to select a resource
00126         gConsole->Printf(KEnterResourceIdValue);
00127         gResourceId = GetUserInput(); 
00128         if(gResourceId != (TUint)KErrNotSupported)
00129                 {
00130                 /*
00131                 The name of the resource is held in an 8 bit buffer. In order to print this value as a string, 
00132                 it must be converted to a 16 bit buffer. One character is left to hold the 'Null' character to mark the end of
00133                 the string.
00134                 */ 
00135                 TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name; //maximum resource length defined in d32resmanus.h 
00136                 // retrieve information about the selected resource
00137                 TResourceInfoBuf *info = new TResourceInfoBuf();
00138                 TInt err=gChannel.GetResourceInfo(gResourceId,info);
00139                 if(err!= KErrNone)
00140                         {
00141                         gConsole->Printf(KTxtFailed,err);
00142                         }
00143                 else
00144                         {
00145                         name.Copy((*info)().iName); //Copy the name of the resource into the Unicode buffer.
00146                         name.PtrZ(); //Append a zero terminator to the buffer.
00147                         _LIT(KPrintResourceInfo,"\nResource id = %d \t Resource name = %S \n");
00148                         gConsole->Printf(KPrintResourceInfo,gResourceId ,&name);
00149                         }
00150                 delete info;
00151                 }
00152         }
00153         
00157 void GetAllResourcesInfoL()
00158         {
00159         _LIT(KTxtOption,"\nGet information about all the resources...\n");
00160         gConsole->Printf(KTxtOption);
00161         //Find the number of resources available
00162         GetNoOfResources();
00163         /*
00164         Construct an array of TResourceInfoBuf objects.
00165         TResourceInfo holds all the information about a resource.
00166         */
00167         TInt err;
00168         RSimplePointerArray<TResourceInfoBuf> resPtrs(gNumResources);
00169         for(TUint i=0;i<gNumResources;i++)
00170                 {
00171                 TResourceInfoBuf* info = new TResourceInfoBuf;
00172                 if((err=resPtrs.Insert(info, i))!=KErrNone)
00173                         {
00174                         gConsole->Printf(KTxtFailed,err);
00175                         }
00176                 }
00177         //Retrieve information about all the available resources
00178         if((err=gChannel.GetAllResourcesInfo(&resPtrs,gNumResources))!=KErrNone)
00179                 {
00180                 gConsole->Printf(KTxtFailed,err);
00181                 }
00182         /*
00183         The name of the resource is held in an 8 bit buffer. In order to print this value as a string, 
00184         it must be converted to a 16 bit buffer. One character is left to hold the 'Null' character to mark the end of
00185         the string.
00186         */ 
00187         TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
00188         for(TUint i=0; i<gNumResources; i++)
00189                 {
00190                 TResourceInfoBuf* currentInfo = resPtrs[i];
00191                 name.Copy((*currentInfo)().iName);//Copy the name of the resource into the Unicode buffer.
00192                 name.PtrZ();//Append a zero terminator to the buffer.
00193                 _LIT(KPrintResourceInfo,"Resource id = %d, name = %S \n");
00194                 gConsole->Printf(KPrintResourceInfo,(*currentInfo)().iId,&name);
00195                 if(i%5 == 0 && i!= 0) //Print 5 resources at a time.
00196                         {
00197                         gConsole->Printf(KTxtPressAnyKey);
00198                         TChar tchar = gConsole->Getch();
00199                         }
00200                 delete currentInfo;
00201                 }
00202         resPtrs.Close(); //Close the R class
00203         }
00204 
00208 void GetResourceState()
00209         {
00210         _LIT(KTxtOption,"\nGet the state of a particular resource... \n");
00211         gConsole->Printf(KTxtOption);
00212         //Enter a resource value.
00213         gConsole->Printf(KEnterResourceIdValue);
00214         gResourceId = GetUserInput(); 
00215         if(gResourceId != (TUint)KErrNotSupported)
00216                 {
00217                 TRequestStatus getResourceStatus;
00231                 TBool isCached = EFalse;
00232                 TInt levelOwnerId = 0;
00233                 gChannel.GetResourceState(getResourceStatus,gResourceId,isCached,&gReadValue,&levelOwnerId);
00234                 User::WaitForRequest(getResourceStatus);
00235                 if(getResourceStatus.Int() != KErrNone)
00236                         {
00237                         gConsole->Printf(KTxtFailed,getResourceStatus.Int());
00238                         }
00239                 else
00240                         {
00241                         _LIT(KPrintResourceState,"\nResource state is %d\n");
00242                         gConsole->Printf(KPrintResourceState,gReadValue);
00243                         _LIT(KTxtLevelOwnerId,"\nId of the client which owns this resource is %d");
00244                         gConsole->Printf(KTxtLevelOwnerId,levelOwnerId);
00245                         }
00246                 }
00247         }
00248 
00252 void GetNumClientsUsingResource()
00253         {
00254         _LIT(KTxtOption,"\nGet the number of clients using a particular resource... \n");
00255         gConsole->Printf(KTxtOption);
00256         GetNoOfResources(); //Get the total number of resources available
00257         //Ask the user to select a resource.
00258         gConsole->Printf(KEnterResourceIdValue);
00259         gResourceId = GetUserInput(); 
00260         if(gResourceId != (TUint)KErrNotSupported)
00261                 {
00262                 _LIT(KPrintNoOfClientsUsingResource,"\nNumber of  clients using resource : %d\n");
00263                 gNumClients = 0; //This should be initialised to '0' otherwise the API returns KErrArgument
00264                 TInt err=gChannel.GetNumClientsUsingResource(gResourceId, gNumClients, gIsKernelClient);
00265                 if((err == KErrArgument && gNumClients == 0) || err == KErrNone)
00266                         {
00267                         gConsole->Printf(KPrintNoOfClientsUsingResource,gNumClients);
00268                         }
00269                 else
00270                         {
00271                         gConsole->Printf(KTxtFailed,err);
00272                         }
00273                 }
00274         }
00275 
00279 void GetNumResourcesInUseByClient()
00280         {
00281         _LIT(KTxtOption,"\nGet the number of resources in use by a particular client \n");
00282         gConsole->Printf(KTxtOption);
00283         _LIT(KTxtClientName,"Name of the client used in this option is resourcemanager ");
00284         gConsole->Printf(KTxtClientName);
00285         //Gets the number of resources used by the client, by passing in the client's name.
00286         TInt err=gChannel.GetNumResourcesInUseByClient(gName, gNumResources, gIsKernelClient);
00287         if(err!=KErrNone)
00288                 {
00289                 gConsole->Printf(KTxtFailed,err);
00290                 }
00291         else
00292                 {
00293                 _LIT(KPrintNumResourcesInUseByClient,"\nNumber of resources in use by client :  %d\n");
00294                 gConsole->Printf(KPrintNumResourcesInUseByClient,gNumResources);
00295                 }
00296         }
00297         
00301 void GetInfoOnResourcesInUseByClientL()
00302         {
00303         _LIT(KTxtOption,"\nGet information about all the resources in use by client... \n");
00304         gConsole->Printf(KTxtOption);
00305 
00306         //Get number of resources in use by the client.
00307         GetNumResourcesInUseByClient();
00308 
00309         if(gNumResources!= 0)
00310                 {
00311                 /*
00312                 Construct an array of TResourceInfoBuf objects.
00313                 TResourceInfo holds all the information about a resource.
00314                 */
00315                 RSimplePointerArray<TResourceInfoBuf> resPtrs(gNumResources);
00316 
00317                 for(TUint i=0;i<gNumResources;i++)
00318                         {
00319                         TResourceInfoBuf *info = new TResourceInfoBuf();
00320                         TInt err=resPtrs.Insert(info, i);
00321                         if(err!= KErrNone)
00322                                 {
00323                                 gConsole->Printf(KTxtFailed,err);
00324                                 }
00325                         }
00326                 //Gets information about all the resources
00327                 TInt err=gChannel.GetInfoOnResourcesInUseByClient(gName, gNumResources, &resPtrs);
00328                 if(err!= KErrNone)
00329                         {
00330                         gConsole->Printf(KTxtFailed,err);
00331                         }
00332                 else
00333                         {
00334                         /*
00335                         The name of the resource is held in an 8 bit buffer. In order to print this value as a string, 
00336                         it must be converted to a 16 bit buffer. One character is left to hold the 'Null' character to mark the end of
00337                         the string.
00338                         */ 
00339                         TBuf16<MAX_RESOURCE_NAME_LENGTH+1>name;
00340                         _LIT(KPrintResourceInfo,"\nResource %d name = %S \n");
00341                         for(TUint i=0; i<gNumResources; i++)
00342                                 {
00343                                 TResourceInfoBuf* currRes = resPtrs[i];
00344                                 name.Copy((*currRes)().iName);//Copy the name of the resource into the Unicode buffer.
00345                                 name.PtrZ();//Append a zero terminator to the buffer.
00346                                 gConsole->Printf(KPrintResourceInfo,i,&name);
00347                                 if(i%5 == 0) //Print 5 resources at a time.
00348                                         {
00349                                         gConsole->Printf(KTxtPressAnyKey);
00350                                         TChar tchar = gConsole->Getch();
00351                                         }
00352                                 }
00353                         }
00354                 resPtrs.Close();
00355                 }
00356         }
00357 
00361 void GetInfoOnClientsUsingResourceL()
00362         {
00363         _LIT(KTxtOption,"\nGet information about all clients using a particular resource... \n");
00364         gConsole->Printf(KTxtOption);
00365 
00366         //Get the number of clients using a particular resource
00367         GetNumClientsUsingResource();
00368 
00369         if(gNumClients!= 0)
00370                 {
00371                 //Construct an array of TClientInfoBuf objects. TClientInfo consists of the client name and ID.
00372                 RSimplePointerArray<TClientInfoBuf> resPtrs(gNumClients);
00373                 for(TUint i=0;i<gNumClients;i++)
00374                         {
00375                         TClientInfoBuf *info = new TClientInfoBuf();
00376                         TInt err=resPtrs.Insert(info, i);
00377                         if(err!= KErrNone)
00378                                 {
00379                                 gConsole->Printf(KTxtFailed,err);
00380                                 }
00381                         }
00382                 TInt err=gChannel.GetInfoOnClientsUsingResource(gResourceId, gNumClients, &resPtrs, gIsKernelClient);
00383                 if(err!= KErrNone)
00384                         {
00385                         gConsole->Printf(KTxtFailed,err);
00386                         }
00387                 else
00388                         {
00389                         //Print information about all the clients using this resource.
00390                         _LIT(KPrintClientName,"Client name %d = %S, ID=%d\n");
00391                         for(TUint i=0;i<gNumClients;i++)
00392                                 {
00393                                 TClientInfoBuf* currInfoBuf = resPtrs[i];
00394                                 TClientInfo currInfo=(*currInfoBuf)();
00395                                 TBuf16<sizeof(TClientName)> name;
00396                                 name.Copy(currInfo.iName);
00397                                 gConsole->Printf(KPrintClientName,i,&name,currInfo.iId);
00398                                 }
00399                         }
00400                 resPtrs.Close();
00401                 }
00402         }
00403 
00407 void GetNamesOfAllClientsL()
00408         {
00409         _LIT(KTxtOption,"\nGet the names of all clients... \n");
00410 
00411         gConsole->Printf(KTxtOption);
00412 
00413         //Gets the number of clients
00414         TInt err=gChannel.GetNoOfClients(gNumClients, gIsKernelClient);
00415 
00416         //Creates an array of client names
00417         RSimplePointerArray<TClientName> resPtrs(gNumClients);
00418         if(err != KErrNone)
00419                 {
00420                 gConsole->Printf(KTxtFailed,err);
00421                 }
00422         else
00423                 {
00424                 gConsole->Printf(KPrintNoOfClients,gNumClients);
00425                 for(TUint i=0;i<gNumClients;i++)
00426                         {
00427                         TClientName *info = new TClientName();
00428                         if((err=resPtrs.Insert(info, i))!= KErrNone)
00429                                 {
00430                                 gConsole->Printf(KTxtFailed,err);
00431                                 }
00432                         }
00433                 }
00434 
00435         // Gets the names of all clients
00436         if((err=gChannel.GetNamesAllClients(&resPtrs, gNumClients, gIsKernelClient)) != KErrNone)
00437                 {
00438                 gConsole->Printf(KTxtFailed,err);
00439                 }
00440         else
00441                 {
00442                 _LIT(KPrintNamesOfAllClients,"\nNames of all clients\n");
00443                 _LIT(KPrintClientName,"Client name : %S\n");
00444                 gConsole->Printf(KPrintNamesOfAllClients);
00445                 for(TUint i=0;i<gNumClients;i++)
00446                         {
00447                         TClientName *currName = resPtrs[i];
00448                         TBuf16<sizeof(TClientName)> name;
00449                         name.Copy(*currName);
00450                         gConsole->Printf(KPrintClientName,&name);
00451                         delete currName;
00452                         }
00453                 }
00454         resPtrs.Close();
00455         }
00456 
00460 TInt ChangeStateOfResource()
00461         {
00462         _LIT(KTxtOption,"\nChange the state of a particular resource... \n");
00463         gConsole->Printf(KTxtOption);
00464 
00465         //Gets the current state of the resource
00466         GetResourceState();
00467         TInt newLevel = gReadValue + 2; //new (random) state value
00468         TRequestStatus changeResourceStatus;
00469         gChannel.ChangeResourceState(changeResourceStatus,gResourceId,newLevel);
00470         User::WaitForRequest(changeResourceStatus);
00471         if(changeResourceStatus.Int() != KErrNone)
00472                 {
00473                 _LIT(KTxtChangeOfStateFailed,"\nChange of state failed with return value %d\n");
00474                 gConsole->Printf(KTxtChangeOfStateFailed,changeResourceStatus.Int());
00475                 }
00476         else
00477                 {
00478                 gConsole->Printf(KTxtStateChange,newLevel);
00479                 }
00480         return changeResourceStatus.Int();
00481         }
00482 
00486 void RequestNotification()
00487         {
00488         _LIT(KTxtOption,"\nRequest resource manager to notify the client about changes to the state of a resource... \n");
00489         gConsole->Printf(KTxtOption);
00490 
00491         //Verify whether ChangeResourceState() is supported. If not, then notification cannot be issued
00492         TInt ret = ChangeStateOfResource();
00493         if(ret == KErrNone)
00494                 {
00495                 TRequestStatus notificationStatus;
00496                 //Requests notification for any change in the resource state
00497                 gChannel.RequestNotification(notificationStatus, gResourceId);
00498                 TInt newLevel = gReadValue + 2;
00499 
00500                 //Change the resource state.
00501                 TRequestStatus changeResourceStatus;
00502                 gChannel.ChangeResourceState(changeResourceStatus,gResourceId,newLevel);
00503                 User::WaitForRequest(changeResourceStatus);
00504                 gConsole->Printf(KTxtStateChange,newLevel);
00505                 User::WaitForRequest(notificationStatus);               
00506                 if(notificationStatus.Int() != KErrNone)
00507                         {
00508                         _LIT(KTxtNotificationFailed,"\nRequest Notification for any change in the state of a resource failed with %d");
00509                         gConsole->Printf(KTxtNotificationFailed,notificationStatus.Int());
00510                         }
00511                 else
00512                         {
00513                         
00514                         _LIT(KTxtNotificationSuccess,"\nRequest Notification for any change in the state of a resource is successful");
00515                         gConsole->Printf(KTxtNotificationSuccess);
00516                         }
00517                 }
00518         else
00519                 {
00520                 _LIT(KTxtNotificationNotSupported,"User notification for this resource is not supported");
00521                 gConsole->Printf(KTxtNotificationNotSupported);
00522                 }
00523         }
00524         
00525 void GetPowerResourceInfoL()
00526         {
00527         _LIT(KPrintSubMenu,"GetPowerResourceInfo was chosen\n");
00528         _LIT(KPrintSubMenu1," \nDemonstrate the Get Power Resource APIs\n \
00529                 *****************************************************\n \
00530                 Option 1:GetNoOfResources\n   \
00531                 Option 2:GetResourceInfo\n   \
00532                 Option 3:GetAllResourcesInfo\n \
00533                 Option 4:GetResourceState\n ");
00534         _LIT(KPrintSubMenu2, "\t \tOption 5:GetNumClientsUsingResource \n \
00535                 Option 6:GetNumResourcesInUseByClient\n \
00536                 Option 7:GetInfoOnResourcesInUseByClient\n \
00537                 Option 8:GetInfoOnClientsUsingResource\n  \
00538                 Option 9:GetNamesOfAllClients\n \
00539                 ******************************************************\n " );
00540         gConsole->ClearScreen();
00541         gConsole->Printf(KPrintSubMenu);
00542         _LIT(KTxtPressMainESC," \nPress 'ESC' key to go back to the Main Menu\n");
00543         gConsole->Printf(KTxtPressMainESC);
00544         gConsole->Printf(KPrintSubMenu1);
00545         gConsole->Printf(KPrintSubMenu2);
00546         _LIT(KChooseSubMenuOption,"\nSelect an option 1 - 9 : ");
00547         gConsole->Printf(KChooseSubMenuOption);
00548         TChar tchar = gConsole->Getch();        
00549         while (tchar != EKeyEscape)
00550                 {               
00551                 switch(tchar)
00552                         {               
00553                         case '1':
00554                                 {
00555                                 GetNoOfResources();
00556                                 break;
00557                                 }
00558                         case '2':
00559                                 {
00560                                 GetResourceInfo();
00561                                 break;
00562                                 }
00563                         case '3':
00564                                 {
00565                                 GetAllResourcesInfoL();
00566                                 break;
00567                                 }
00568                         case '4':
00569                                 {
00570                                 GetResourceState();
00571                                 break;
00572                                 }
00573                         case '5':
00574                                 {
00575                                 GetNumClientsUsingResource();
00576                                 break;
00577                                 }
00578                         case '6':
00579                                 {
00580                                 GetNumResourcesInUseByClient();
00581                                 break;
00582                                 }
00583                         case '7':
00584                                 {
00585                                 GetInfoOnResourcesInUseByClientL();
00586                                 break;
00587                                 }
00588                         case '8':
00589                                 {
00590                                 GetInfoOnClientsUsingResourceL();
00591                                 break;
00592                                 }
00593                         case '9':
00594                                 {
00595                                 GetNamesOfAllClientsL();
00596                                 break;
00597                                 }
00598                         default:
00599                                 {
00600                                 if(tchar == EKeyEscape)
00601                                         {
00602                                         tchar = 'a'; //Any value can be assigned, so that it goes back to the main menu
00603                                         }
00604                                 else
00605                                         {
00606                                         gConsole->Printf(KTxtOptionNotSupported);
00607                                         }
00608                                 break;
00609                                 }
00610                         }
00611                 gConsole->Printf(KTxtPressAnyKey);
00612                 tchar = gConsole->Getch();      
00613                 gConsole->Printf(KTxtPressMainESC);
00614                 gConsole->Printf(KPrintSubMenu1);
00615                 gConsole->Printf(KPrintSubMenu2);
00616                 gConsole->Printf(KChooseSubMenuOption); 
00617                 tchar = gConsole->Getch();              
00618                 }
00619         }
00620 
00621 void DoStartL()
00622         {
00623         TInt err= gChannel.Open(gName); // 'gName' contains the name of client
00624         _LIT(KPrintEnterPRMExample,"Power Resource Manager example\n");
00625         gConsole->Printf(KPrintEnterPRMExample);
00626         if (err!=KErrNone)
00627                 {
00628                 _LIT(KTxtCommonFailure,"\n Note: The application cannot demonstrate the features without a defined PSL \
00629                         (Platform Specific Layer) and the necessary ldd and pdd. \n");
00630                 gConsole->Printf(KTxtCommonFailure);
00631                 gConsole->Printf(KTxtFailed, err);
00632                 _LIT(KTxtPressAnyKeyToCloseApp,"Press any key to close the application ");
00633                 gConsole->Printf(KTxtPressAnyKeyToCloseApp);
00634                 gConsole->Getch();
00635                 }
00636         else
00637                 {
00638                 const TUint8 KNoOfGetStateRequests = 5; //The maximum number of get state asynchronous requests
00639                 const TUint8 KNoOfSetStateRequests = 4; //The maximum number of set state asynchronous requests
00640                 const TUint8 KNoOfNotifyRequests = 7;  //The maximum number of notification requests
00649                 err=gChannel.Initialise(KNoOfGetStateRequests,KNoOfSetStateRequests,KNoOfNotifyRequests);
00650                 if (err!=KErrNone)
00651                         {
00652                         gConsole->Printf(KTxtFailed, err);
00653                         }
00654                 _LIT(KTxtPressAnyKey,"Press any key to continue");
00655                 gConsole->Printf(KTxtPressAnyKey);
00656                 _LIT(KTxtPressESC," \nPress the 'ESC' key to exit\n");
00657                 gConsole->Printf(KTxtPressESC);
00658                 _LIT(KPrintMainMenu,"\nOptions for various Power Resource Manager Features \n \
00659                         **************************************\n \
00660                         1:GetPowerResourceInfo \n \
00661                         2:ChangeStateOfResource \n \
00662                         3:RequestNotification \n \
00663                         **************************************\n \n");
00664                 TChar tchar = gConsole->Getch();        
00665                 //make a choice
00666                 while (tchar != EKeyEscape)
00667                         {
00668                         gConsole->Printf(KPrintMainMenu);
00669                         _LIT(KChooseMainMenuOption,"Select option 1 - 3 : ");
00670                         gConsole->Printf(KChooseMainMenuOption);
00671                         tchar = gConsole->Getch();                      
00672                         switch(tchar)
00673                                 {
00674                                 case '1':
00675                                         {       
00676                                         GetPowerResourceInfoL();
00677                                         break;
00678                                         }
00679                                 case '2':
00680                                         {
00681                                         ChangeStateOfResource();
00682                                         break;
00683                                         }
00684                                 case '3':
00685                                         {
00686                                         RequestNotification();
00687                                         break;
00688                                         }
00689                                 default:
00690                                         {
00691                                         if(tchar == EKeyEscape)
00692                                                 {
00693                                                 _LIT(KPrintExitMenu,"\nExit the Menu\n");
00694                                                 gConsole->Printf(KPrintExitMenu);
00695                                                 }
00696                                         else
00697                                                 {
00698                                                 gConsole->Printf(KTxtOptionNotSupported);
00699                                                 }
00700                                         break;
00701                                         }
00702                                 }                       
00703                         }
00704                 gChannel.Close();
00705                 }
00706         }
00707 void callExampleL() // Initialise and call example code under cleanup stack.
00708         {
00709         gConsole=Console::NewL(KTxtExampleCode,TSize(KConsFullScreen,KConsFullScreen));
00710         CleanupStack::PushL(gConsole);
00711         DoStartL(); // Perform example function.
00712         CleanupStack::PopAndDestroy(gConsole); // delete the gConsole.
00713         }
00714 
00715 extern TInt E32Main()
00716         {
00717         __UHEAP_MARK;
00718         CTrapCleanup* cleanup=CTrapCleanup::New(); // Create clean-up stack.
00719         if(cleanup!=NULL)
00720                 {
00721                 TRAPD (error,callExampleL());
00722                 __ASSERT_ALWAYS(!error,User::Panic(KTxtExampleCode,error));
00723                 }
00724         delete cleanup; // Delete clean-up stack.
00725         __UHEAP_MARKEND;
00726         return KErrNone;
00727         }

Generated by  doxygen 1.6.2