realtimenetprots/sipfw/SIP/Server/src/TSIPMemAllocFailureSimulation.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name          : TSIPMemAllocFailureSimulation.cpp
       
    15 // Part of       : SIPServerCore
       
    16 // Version       : SIP/4.0 
       
    17 //
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 #include "TSIPMemAllocFailureSimulation.h"
       
    23 #include <f32file.h>
       
    24 
       
    25 
       
    26 _LIT(KIniFileName, "\\sip\\MemAllocFailureSimulation.ini");
       
    27 const TInt KParamBufferSize = 100;
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // TSIPMemAllocFailureSimulation::Start
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 TInt TSIPMemAllocFailureSimulation::Start()
       
    34 	{
       
    35 	TInt err = KErrNone;
       
    36 	
       
    37 	TBuf8<KParamBufferSize> buf;
       
    38 	err = ReadParamBufferFromFile(buf);
       
    39 	if (err != KErrNone) 
       
    40         {
       
    41         return err;
       
    42         }
       
    43 	TUint type;
       
    44 	TUint value;
       
    45 	err = ParseParams(buf,type,value); 
       
    46 	if (err != KErrNone)
       
    47         {
       
    48         return err;
       
    49         }
       
    50 
       
    51 	__UHEAP_SETFAIL (static_cast<RHeap::TAllocFail>(type),value);
       
    52 
       
    53 	return KErrNone;
       
    54 	}
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // TSIPMemAllocFailureSimulation::Stop
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void TSIPMemAllocFailureSimulation::Stop()
       
    61 	{
       
    62 	__UHEAP_RESET;
       
    63 	}
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // TSIPMemAllocFailureSimulation::ReadParamBufferFromFile
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 TInt TSIPMemAllocFailureSimulation::ReadParamBufferFromFile (TDes8& aDes)
       
    70 	{
       
    71 	RFs fileSession;
       
    72 	TInt err = fileSession.Connect();
       
    73 	if (err != KErrNone) 
       
    74         {
       
    75         return err;
       
    76         }
       
    77 	RFile file;
       
    78 	err = file.Open(fileSession, KIniFileName, EFileRead|EFileShareAny);
       
    79 	if (err != KErrNone)
       
    80 		{
       
    81 		fileSession.Close();
       
    82 		return err;
       
    83 		}
       
    84 	err = file.Read(aDes);
       
    85 	file.Close();
       
    86 	fileSession.Close();
       
    87 	return err;
       
    88 	}
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // TSIPMemAllocFailureSimulation::ParseParams
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 TInt TSIPMemAllocFailureSimulation::ParseParams (const TDesC8& aDes,
       
    95 												 TUint& aType,
       
    96 												 TUint& aValue)
       
    97 	{
       
    98 	TLex8 lex(aDes);
       
    99 	lex.SkipSpace();
       
   100 	TInt err = lex.Val(aType);
       
   101 	if (err != KErrNone)
       
   102         {
       
   103         return err;
       
   104         }
       
   105 	if (aType > RAllocator::EFailNext) 
       
   106         {
       
   107         return KErrCorrupt;
       
   108         }
       
   109 	lex.SkipSpace();
       
   110 	return lex.Val(aValue);
       
   111 	}