browserui/browser/BrowserAppSrc/BrowserAppEntryPoint.cpp
branchRCL_3
changeset 63 4baee4f15982
parent 32 92a061761a7b
equal deleted inserted replaced
62:5a044f6358c2 63:4baee4f15982
    14 * Description:
    14 * Description:
    15 *     Browser App Entry point
    15 *     Browser App Entry point
    16 *
    16 *
    17 *
    17 *
    18 */
    18 */
    19 
    19  
    20 
    20 
    21 #include "BrowserApplication.h"
    21 #include "BrowserApplication.h"
    22 #include <e32std.h>
    22 #include <e32std.h>
    23 #include <u32std.h>
    23 #include <u32std.h>
    24 #include <eikapp.h>
    24 #include <eikapp.h>
    25 #include <eikstart.h>
    25 #include <eikstart.h>
    26 #include <MemoryManager.h>
    26 #include <MemoryManager.h>
    27 #include <OOMMonitorSession.h>
    27 #include <avkon.rsg>
       
    28 #include <BrowserNG.rsg>
       
    29 #include <bautils.h>
       
    30 #include <f32file.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <hal.h>
       
    33 #include <barsc.h>
       
    34 
       
    35 _LIT(KBrowserResourceFile, "BrowserNG.rsc");  
       
    36 
    28 
    37 
    29 const int KFreeMemoryTarget = 6000000;
    38 const int KFreeMemoryTarget = 6000000;
    30 
    39 
       
    40 
    31 LOCAL_C CApaApplication* NewApplication( )
    41 LOCAL_C CApaApplication* NewApplication( )
    32     {
    42     {
    33     return new CBrowserApplication;
    43     return new CBrowserApplication; 
    34     }
    44     }
    35 
    45 
    36 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    37 // SetupThreadHeap - Called for heap creation of thread in this process.
    47 // SetupThreadHeap - Called for heap creation of thread in this process.
    38 // This approach used to keep correct heap for pointers held in static data objects
    48 // This approach used to keep correct heap for pointers held in static data objects
    61         }
    71         }
    62 
    72 
    63     return r;
    73     return r;
    64     }
    74     }
    65 
    75 
       
    76 
       
    77 // ---------------------------------------------------------------------------
       
    78 // GetUiUtilitiesResourceFilenameL
       
    79 // ---------------------------------------------------------------------------
       
    80 //
       
    81 TInt GetCorrectResourceFilenameL(TFileName& aResourceFileName)
       
    82     {
       
    83 
       
    84     TParse parse;
       
    85     parse.Set(KBrowserResourceFile, &KDC_APP_RESOURCE_DIR, NULL);
       
    86     aResourceFileName.Copy(parse.FullName());
       
    87     
       
    88     RFs fs;
       
    89     User::LeaveIfError(fs.Connect());
       
    90     CleanupClosePushL( fs );
       
    91     
       
    92     // Resource File Name on C:
       
    93     aResourceFileName.Insert( 0, TDriveUnit( EDriveC).Name() );
       
    94     // try to locate the localised resource
       
    95     BaflUtils::NearestLanguageFile( fs, aResourceFileName ); 
       
    96     
       
    97     // if the localised resource is found, the file name is changed to the localised name (z:\resources\webkit.r001)
       
    98     if( !BaflUtils::FileExists( fs, aResourceFileName ) )        {
       
    99     	
       
   100         aResourceFileName.Replace( 0, KMaxDriveName, TDriveUnit( EDriveZ ).Name() );
       
   101         // not found on c drive, try z try to locate the localised resource again
       
   102         BaflUtils::NearestLanguageFile( fs, aResourceFileName ); 
       
   103         	
       
   104         // if file was not found this time, there is no localised  resource with the name
       
   105         if (!BaflUtils::FileExists( fs, aResourceFileName ) )             {
       
   106             User::Leave(KErrNotFound);
       
   107             }
       
   108         }
       
   109     CleanupStack::PopAndDestroy( &fs );
       
   110     return KErrNone;
       
   111     }
       
   112 
       
   113 void ShowOOMDialogWithNotifierL()
       
   114     {
       
   115     
       
   116     TFileName resourceFileName;
       
   117     User::LeaveIfError(GetCorrectResourceFilenameL(resourceFileName));
       
   118 
       
   119     RFs fsSession;
       
   120     User::LeaveIfError(fsSession.Connect());
       
   121     CleanupClosePushL(fsSession);
       
   122 
       
   123     RResourceFile resFile;
       
   124     resFile.OpenL(fsSession,resourceFileName );
       
   125     resFile.ConfirmSignatureL(0);
       
   126 
       
   127     HBufC8* dataOkButtonBuffer = resFile.AllocReadLC(R_QTN_OK_BUTTON);
       
   128     HBufC8* dataOOMMessageBuffer = resFile.AllocReadLC(R_QTN_BROWSER_DIALOG_OOM);
       
   129     
       
   130     TPtrC16 OkButtonBuffer( ( TUint16* ) dataOkButtonBuffer->Ptr(),dataOkButtonBuffer->Length() / 2 );
       
   131     TPtrC16 OOMMessageBuffer( ( TUint16* ) dataOOMMessageBuffer->Ptr(),dataOOMMessageBuffer->Length() / 2 );
       
   132 
       
   133     _LIT(KTxtEmptyLine,"   ");
       
   134     _LIT(KTxtEmptyButton,"");
       
   135     
       
   136     RNotifier      notifier;
       
   137     TInt err = notifier.Connect();
       
   138     if(err == KErrNone)   {
       
   139             TInt           whichbutton(-1);
       
   140             TRequestStatus stat;
       
   141             notifier.Notify(OOMMessageBuffer,KTxtEmptyLine,OkButtonBuffer,KTxtEmptyButton,whichbutton,stat);
       
   142             User::WaitForRequest(stat);
       
   143         }    
       
   144     
       
   145     notifier.Close();
       
   146     
       
   147     //this will clear OkButtonBuffer and OOMMessageBuffer 
       
   148     CleanupStack::PopAndDestroy(2); 
       
   149     resFile.Close();
       
   150     CleanupStack::PopAndDestroy(&fsSession);
       
   151     
       
   152     }
       
   153 
    66 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
    67 // E32Main
   155 // E32Main
    68 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
    69 GLDEF_C TInt E32Main()
   157 GLDEF_C TInt E32Main()
    70     {
   158     { 
    71     ROomMonitorSession oomMs;
   159     //Initilize memory manager...
    72     TInt result = oomMs.Connect();
   160     MemoryManager::InitFastAllocator();   
    73     if ( result == KErrNone )
   161 	
    74         {
   162     TInt freeRAM = 0;
    75         result = oomMs.RequestFreeMemory( KFreeMemoryTarget );
   163     TInt r = HAL::Get(HAL::EMemoryRAMFree, freeRAM);
    76         oomMs.Close();
   164         
       
   165     if ((r != KErrNone)  || freeRAM < KFreeMemoryTarget)  
       
   166     	{
       
   167     		// create clean-up stack as none is created
       
   168             CTrapCleanup* cleanup=CTrapCleanup::New(); 
       
   169 			
       
   170             // Show OOM message through RNotifier ...
       
   171              TRAP_IGNORE(ShowOOMDialogWithNotifierL()); 
       
   172             
       
   173 			// destroy clean-up stack
       
   174             delete cleanup; 
       
   175             return KErrNoMemory;
    77         }
   176         }
    78 
       
    79     // initialize MemmoryManager
       
    80     MemoryManager::InitFastAllocator();    
       
    81     
   177     
    82     // run application event loop
   178      // Run application event loop
    83     return EikStart::RunApplication(NewApplication);
   179 	 return EikStart::RunApplication(NewApplication);
    84     }
   180     }
    85 
   181 
    86 //  End of File  
   182 //  End of File