upnp/upnpstack/upnputils/inc/upnpuheapmark.h
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2005-2006 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:  Declares macros for heap checks
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef UPNPUHEAPMARK_H
       
    21 #define UPNPUHEAPMARK_H
       
    22 // INCLUDES
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 //variables
       
    27 const TBool KUpnpHeapChecksToHeapChecks = ETrue; //checks heap only if ETrue
       
    28 _LIT( KUpnpHeapChecksAllocInfo, "%D;%D" ); //panic category if heap checks fails
       
    29 const TInt KUpnpHeapChecksMaxAllocInfoLength = 21; //10 + 1 + 10
       
    30 const TInt KUpnpHeapChecksAllocPanicReason = 0; //panic reason if heap checks fails
       
    31 
       
    32 //functions
       
    33 static void UPnpHeapChecks( TInt aCells, TInt aBytes )
       
    34     {
       
    35     if ( aCells )
       
    36         {
       
    37         TBuf<KUpnpHeapChecksMaxAllocInfoLength> allocInfo;
       
    38         allocInfo.AppendFormat(  KUpnpHeapChecksAllocInfo(), aCells, aBytes );
       
    39         User::Panic( allocInfo, KUpnpHeapChecksAllocPanicReason );
       
    40         }
       
    41     }
       
    42 
       
    43 
       
    44 #define __UPNP_UHEAP_MARK     TInt cells_begin;                                     \
       
    45                               TInt bytes_begin;                                     \
       
    46                               RHeap& heap = User::Heap();                           \
       
    47                               if ( KUpnpHeapChecksToHeapChecks )                    \
       
    48                               {                                                     \
       
    49                               cells_begin = heap.AllocSize( bytes_begin );          \
       
    50                               }    
       
    51 
       
    52 #define __UPNP_UHEAP_MARKEND if ( KUpnpHeapChecksToHeapChecks )                     \
       
    53                               {                                                     \
       
    54                               TInt cells_end;                                       \
       
    55                               TInt bytes_end;                                       \
       
    56                               cells_end = heap.AllocSize( bytes_end );              \
       
    57                               UPnpHeapChecks( cells_end-cells_begin,                \
       
    58                                                           bytes_end-bytes_begin );  \
       
    59                               }    
       
    60     
       
    61 #endif // UPNPUHEAPMARK_H
       
    62 
       
    63 //end of file