os/kernelhwsrv/kernel/eka/debug/securityServer/src/c_process_pair.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2006-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 // Provides a helper class for process security management
    15 // 
    16 //
    17 
    18 #include <e32base.h>
    19 #include <e32base_private.h>
    20 
    21 // Required for logging
    22 #include <rm_debug_api.h>
    23 
    24 #include "c_process_pair.h"
    25 #include "rm_debug_logging.h"
    26 
    27 
    28 CProcessPair* CProcessPair::NewL(const TDesC& aProcessName, const TProcessId aProcessId)
    29 	{
    30 	CProcessPair* self=new (ELeave) CProcessPair();
    31 	CleanupStack::PushL(self);
    32 	self->ConstructL(aProcessName, aProcessId);
    33 	CleanupStack::Pop(self);
    34 	return self;
    35 	}
    36 
    37 void CProcessPair::ConstructL(const TDesC& aProcessName, const TProcessId aProcessId)
    38 	{
    39 	//allocate the process name buffer and fill with aProcessName
    40 	iProcessName = aProcessName.Alloc();
    41 	if(iProcessName == NULL)
    42 		User::Leave(KErrNoMemory);
    43 
    44 	LOG_MSG2( "CProcessPair::ConstructL() process name: %S", &TPtr8((TUint8*)iProcessName->Ptr(), 2*iProcessName->Length(), 2*iProcessName->Length()) );
    45 
    46 	//set process id
    47 	iProcessId = aProcessId;
    48 	}
    49 
    50 CProcessPair::CProcessPair()
    51 	{
    52 	}
    53 
    54 CProcessPair::~CProcessPair()
    55 	{
    56 	delete iProcessName;
    57 	}
    58 
    59 /**
    60 Check whether two CProcessPair objects are equal
    61 
    62 @param aProcessPair a CProcessPair object to match with this one
    63 
    64 @return ETrue is process id and name match, EFalse otherwise
    65 */
    66 TBool CProcessPair::operator==(const CProcessPair &aProcessPair) const
    67 	{
    68 	return Equals(*aProcessPair.iProcessName, aProcessPair.iProcessId);
    69 	}
    70 	
    71 /**
    72 Check whether this CProcessPair object has these values set
    73 
    74 @param aProcessName process name to check
    75 @param aProcessId process id to check
    76 
    77 @return ETrue is process id and name match, EFalse otherwise
    78 */
    79 TBool CProcessPair::Equals(const TDesC& aProcessName, const TProcessId aProcessId) const
    80 	{
    81 	return (ProcessIdMatches(aProcessId) && (ProcessNameMatches(aProcessName)));
    82 	}
    83 
    84 /**
    85 Check whether the process ids of two objects match
    86 
    87 @param aProcessPair a CProcessPair object to compare with this one
    88 
    89 @return ETrue is process id matches, EFalse otherwise
    90 */
    91 TBool CProcessPair::ProcessIdMatches(const CProcessPair &aProcessPair) const
    92 	{
    93 	return ProcessIdMatches(aProcessPair.iProcessId);
    94 	}
    95 
    96 /**
    97 Check whether two process ids match
    98 
    99 @param aProcessId a process ID to compare with this pair's process ID
   100 
   101 @return ETrue is process id matches, EFalse otherwise
   102 */
   103 TBool CProcessPair::ProcessIdMatches(const TProcessId &aProcessId) const
   104 	{
   105 	return iProcessId == aProcessId;
   106 	}
   107 
   108 /**
   109 Check whether the process names of two objects match in-case-sensitively
   110 
   111 @param aProcessPair a CProcessPair object to compare with this one
   112 
   113 @return ETrue is process names match, EFalse otherwise
   114 */
   115 TBool CProcessPair::ProcessNameMatches(const CProcessPair &aProcessPair) const
   116 	{
   117 	return ProcessNameMatches(*aProcessPair.iProcessName);
   118 	}
   119 
   120 /**
   121 Check whether two strings match in-case-sensitively
   122 
   123 @param aProcessName a process name to compare with this pair's process name
   124 
   125 @return ETrue is process names match, EFalse otherwise
   126 */
   127 TBool CProcessPair::ProcessNameMatches(const TDesC& aProcessName) const
   128 	{
   129 	TInt equal = iProcessName->CompareF(aProcessName);
   130 	return (equal == 0) ? ETrue : EFalse;
   131 	}
   132