idlehomescreen/inc/xnoomsyshandler.h
changeset 0 f72a12da539e
child 34 d05a55b217df
equal deleted inserted replaced
-1:000000000000 0:f72a12da539e
       
     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         };
       
    76 
       
    77 public: // Construction / destruction.
       
    78     /**
       
    79      * Two-phased constructor.
       
    80      */
       
    81     static CXnOomSysHandler* NewL();
       
    82 
       
    83     /**
       
    84      * Destructor.
       
    85      */
       
    86     virtual ~CXnOomSysHandler();
       
    87     
       
    88 public: // methods.
       
    89     /**
       
    90      * Checks if required amount of free memory is available on heap.
       
    91      * 
       
    92      * @param aAmount required amount of free memory (in Bytes - use some 
       
    93      * value from TMemPredefinedValues enumeration for your comfort)
       
    94      * @return ETrue if required memory is available on heap, otherwise EFalse
       
    95      */
       
    96     static TBool HeapAvailable( TInt aAmount = EMinNotDef );
       
    97 
       
    98     /**
       
    99      * Handle potential OOM failure.
       
   100      */
       
   101     void HandlePotentialOomL();
       
   102 
       
   103 private: // Constructors.
       
   104     /**
       
   105      * Symbian 2nd phase constructor.
       
   106      */
       
   107     void ConstructL();   
       
   108     
       
   109     /**
       
   110      * C++ constructor.
       
   111      */
       
   112     CXnOomSysHandler();
       
   113     
       
   114 private:     // functions
       
   115     /**
       
   116      * Check whether OOM dialog can be shown.
       
   117      * Prevents OOM dialogs popping up more often than
       
   118      * defined in KMinInterval (defined in .cpp).
       
   119      */
       
   120     TBool AllowDialog();
       
   121     
       
   122 private:    // Data.    
       
   123     /**
       
   124      * OOM dialog message.
       
   125      * 
       
   126      * Allocated early because memory might not
       
   127      * be available when HandlePotentialOomL is called.
       
   128     */
       
   129     HBufC* iMsg;    
       
   130     
       
   131     /**
       
   132      * Stored time stamp representing when dialog was last shown.
       
   133     */
       
   134     TInt64 iPreviousDialogPopupTime;
       
   135     };
       
   136 
       
   137 #endif // XNOOMSYSHANDLER_H