idlehomescreen/inc/xnoomsyshandler.h
branchRCL_3
changeset 83 5456b4e8b3a8
equal deleted inserted replaced
82:5f0182e07bfb 83:5456b4e8b3a8
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Helper system for handling Out-Of-Memory cases.
       
    16 *
       
    17 */
       
    18 
       
    19 #ifndef XNOOMSYSHANDLER_H
       
    20 #define XNOOMSYSHANDLER_H
       
    21 
       
    22 // System includes
       
    23 #include <e32base.h>
       
    24 
       
    25 // Forward declarations
       
    26 
       
    27 // Macros
       
    28 
       
    29 // Bytes to kilobytes
       
    30 #define B2KB(val_in_bytes) (TInt)( val_in_bytes / 1024 )
       
    31 // Kilobytes to bytes 
       
    32 #define KB2B(val_in_kbytes) (TInt)( val_in_kbytes * 1024 )
       
    33 
       
    34 #define WIDGET_MIN_MEM  CXnOomSysHandler::EMem1MB
       
    35 #define VIEW_MIN_MEM    CXnOomSysHandler::EMem4MB
       
    36 
       
    37 /**
       
    38  *  Class helper for handling (and preventing) out-of-memory failures
       
    39  *
       
    40  *  This Class has only some static method. 
       
    41  *  E.g. for showing error popup window or for checking of available memory on
       
    42  *  the heap. etc.
       
    43  *
       
    44  *  @ingroup group_xnlayoutengine
       
    45  *  @lib xn3layoutengine.lib
       
    46  *  @since S60 5.0
       
    47  */
       
    48 NONSHARABLE_CLASS( CXnOomSysHandler ) : public CBase
       
    49     {
       
    50 public:     // data types
       
    51 
       
    52     /**
       
    53      * Enumeration of predefined values of memory amount for possible use 
       
    54      */
       
    55     enum TMemPredefinedValues
       
    56         {
       
    57 #ifdef _DEBUG
       
    58         EMemOutOfRangeTest = 209715200,
       
    59 #endif
       
    60         EMinNotDef = 0,
       
    61         EMem1kB = 1024,
       
    62         EMem2kB = 2048,
       
    63         EMem4kB = 4096,
       
    64         EMem8kB = 8192,
       
    65         EMem16kB = 16384,
       
    66         EMem32kB = 32768,
       
    67         EMem64kB = 65536,
       
    68         EMem128kB = 131072,
       
    69         EMem256kB = 262144,
       
    70         EMem512kB = 524288,
       
    71         EMem1MB = 1024000,
       
    72         EMem2MB = 2048000,
       
    73         EMem3MB = 3072000,
       
    74         EMem4MB = 4096000,
       
    75         EMem6MB = 6144000 
       
    76         };
       
    77 
       
    78 public: // Construction / destruction.
       
    79     /**
       
    80      * Two-phased constructor.
       
    81      */
       
    82     static CXnOomSysHandler* NewL();
       
    83 
       
    84     /**
       
    85      * Destructor.
       
    86      */
       
    87     virtual ~CXnOomSysHandler();
       
    88     
       
    89 public: // methods.
       
    90     /**
       
    91      * Checks if required amount of free memory is available on heap.
       
    92      * 
       
    93      * @param aAmount required amount of free memory (in Bytes - use some 
       
    94      * value from TMemPredefinedValues enumeration for your comfort)
       
    95      * @return ETrue if required memory is available on heap, otherwise EFalse
       
    96      */
       
    97     static TBool HeapAvailable( TInt aAmount = EMinNotDef );
       
    98 
       
    99     /**
       
   100      * Handle potential OOM failure.
       
   101      */
       
   102     void HandlePotentialOomL();
       
   103 
       
   104 private: // Constructors.
       
   105     /**
       
   106      * Symbian 2nd phase constructor.
       
   107      */
       
   108     void ConstructL();   
       
   109     
       
   110     /**
       
   111      * C++ constructor.
       
   112      */
       
   113     CXnOomSysHandler();
       
   114     
       
   115 private:     // functions
       
   116     /**
       
   117      * Check whether OOM dialog can be shown.
       
   118      * Prevents OOM dialogs popping up more often than
       
   119      * defined in KMinInterval (defined in .cpp).
       
   120      */
       
   121     TBool AllowDialog();
       
   122     
       
   123 private:    // Data.    
       
   124     /**
       
   125      * OOM dialog message.
       
   126      * 
       
   127      * Allocated early because memory might not
       
   128      * be available when HandlePotentialOomL is called.
       
   129     */
       
   130     HBufC* iMsg;    
       
   131     
       
   132     /**
       
   133      * Stored time stamp representing when dialog was last shown.
       
   134     */
       
   135     TInt64 iPreviousDialogPopupTime;
       
   136     };
       
   137 
       
   138 #endif // XNOOMSYSHANDLER_H