os/kernelhwsrv/kernel/eka/euser/us_trp.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 1994-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 the License "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 // e32\euser\us_trp.cpp
    15 // 
    16 //
    17 
    18 #include "us_std.h"
    19 #include "us_data.h"
    20 
    21 
    22 
    23 
    24 EXPORT_C TTrapHandler::TTrapHandler()
    25 /**
    26 Default constructor.
    27 */
    28 	{}
    29 
    30 
    31 #ifndef __LEAVE_EQUALS_THROW__
    32 
    33 EXPORT_C void TTrap::UnTrap()
    34 //
    35 // Pop the current trap frame
    36 //
    37 	{
    38 
    39 	TTrapHandler *pH=Exec::PopTrapFrame()->iHandler;
    40 	if (pH!=NULL)
    41 		pH->UnTrap();
    42 	}
    43 
    44 
    45 #else //__LEAVE_EQUALS_THROW__
    46 
    47 EXPORT_C void User::Leave(TInt aReason)
    48 /**
    49 Leaves the currently executing function, unwinds the call stack, and returns
    50 from the most recently entered trap harness.
    51 
    52 @param aReason The value returned from the most recent call to TRAP or TRAPD.
    53                This is known as the reason code and, typically, it gives the
    54                reason for the environment or user error causing this leave
    55                to occur.
    56               
    57 @see TRAP
    58 @see TRAPD              
    59 */
    60 	{
    61 #ifdef __USERSIDE_THREAD_DATA__
    62 	Exec::LeaveStart();
    63 	TTrapHandler* pH = GetTrapHandler();
    64 #else
    65 	TTrapHandler* pH = Exec::LeaveStart();
    66 #endif
    67 	if (pH)
    68 		pH->Leave(aReason);	// causes things on the cleanup stack to be cleaned up
    69 	throw XLeaveException(aReason);
    70 	}
    71 
    72 #endif // !__LEAVE_EQUALS_THROW__
    73 
    74 
    75 // Private declaration to prevent def file branching
    76 #ifndef __SUPPORT_CPP_EXCEPTIONS__
    77 class XLeaveException
    78 	{
    79 public:
    80 	IMPORT_C TInt GetReason() const;
    81 	};
    82 #endif //__SUPPORT_CPP_EXCEPTIONS__
    83 
    84 #if !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__)
    85 EXPORT_C TInt XLeaveException::GetReason() const
    86 	{
    87 #ifdef __SUPPORT_CPP_EXCEPTIONS__
    88 	Exec::LeaveEnd();
    89 	return iR;
    90 #else // !__SUPPORT_CPP_EXCEPTIONS__
    91 	return KErrNone;
    92 #endif //__SUPPORT_CPP_EXCEPTIONS__
    93 	}
    94 #elif defined(__LEAVE_EQUALS_THROW__) && defined(__SYMC__)
    95 EXPORT_C TInt XLeaveException::GetReason() const
    96 	{
    97 #ifdef __SUPPORT_CPP_EXCEPTIONS__
    98 	Exec::LeaveEnd();
    99 	return iR;
   100 #else // !__SUPPORT_CPP_EXCEPTIONS__
   101 	return KErrNone;
   102 #endif //__SUPPORT_CPP_EXCEPTIONS__
   103 	}
   104 #endif	// !defined(__LEAVE_EQUALS_THROW__) || !defined(__WINS__)
   105 
   106 EXPORT_C void User::LeaveNoMemory()
   107 /**
   108 Leaves with the specific reason code KErrNoMemory.
   109 
   110 @see KErrNoMemory
   111 */
   112 	{
   113 
   114 	User::Leave(KErrNoMemory);
   115 	}
   116 
   117 
   118 
   119 
   120 EXPORT_C TInt User::LeaveIfError(TInt aReason)
   121 /**
   122 Leaves or returns with a specified reason code.
   123 
   124 If the reason code is negative the function leaves, and the reason code is 
   125 returned through the trap harness.
   126 
   127 If the reason code is zero or positive, the function simply returns with the 
   128 reason value.
   129 
   130 @param aReason The reason code.
   131 
   132 @return If the function returns, the reason code which is either zero or positive.
   133 */
   134 	{
   135 
   136 	if (aReason<0)
   137 		User::Leave(aReason);
   138 	return(aReason);
   139 	}
   140 
   141 
   142 
   143 
   144 EXPORT_C TAny * User::LeaveIfNull(TAny *aPtr)
   145 /**
   146 Leaves with the reason code KErrNoMemory, if the specified pointer is NULL. 
   147 
   148 If the pointer is not NULL, the function simply returns with the value of 
   149 the pointer.
   150 
   151 @param aPtr The pointer to be tested.
   152 
   153 @return If the function returns, the value of aPtr.
   154 */
   155 	{
   156 
   157 	if (aPtr==NULL)
   158 		User::LeaveNoMemory();
   159 	return(aPtr);
   160 	}
   161