examples/Base/resourcemanager/resourcemanager.cpp

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

Generated by  doxygen 1.6.2