debugsrv/runmodedebug/securityserver/src/c_process_pair.cpp
changeset 45 185201be11b0
child 56 aa2539c91954
equal deleted inserted replaced
38:169364e7e4b4 45:185201be11b0
       
     1 // Copyright (c) 2006-2010 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         iProcessName(NULL)
       
    52 	{
       
    53 	}
       
    54 
       
    55 CProcessPair::~CProcessPair()
       
    56 	{
       
    57 	delete iProcessName;
       
    58 	}
       
    59 
       
    60 /**
       
    61 Check whether two CProcessPair objects are equal
       
    62 
       
    63 @param aProcessPair a CProcessPair object to match with this one
       
    64 
       
    65 @return 0 if process ids and names do not match, non-zero if they do
       
    66 */
       
    67 TBool CProcessPair::operator==(const CProcessPair &aProcessPair) const
       
    68 	{
       
    69 	return Equals(*aProcessPair.iProcessName, aProcessPair.iProcessId);
       
    70 	}
       
    71 	
       
    72 /**
       
    73 Check whether this CProcessPair object has these values set
       
    74 
       
    75 @param aProcessName process name to check
       
    76 @param aProcessId process id to check
       
    77 
       
    78 @return 0 if process ids and names do not match, non-zero if they do
       
    79 */
       
    80 TBool CProcessPair::Equals(const TDesC& aProcessName, const TProcessId aProcessId) const
       
    81 	{
       
    82 	return (ProcessIdMatches(aProcessId) && (ProcessNameMatches(aProcessName)));
       
    83 	}
       
    84 
       
    85 /**
       
    86 Check whether the process ids of two objects match
       
    87 
       
    88 @param aProcessPair a CProcessPair object to compare with this one
       
    89 
       
    90 @return 0 if process ids do not match, non-zero if they do
       
    91 */
       
    92 TBool CProcessPair::ProcessIdMatches(const CProcessPair &aProcessPair) const
       
    93 	{
       
    94 	return ProcessIdMatches(aProcessPair.iProcessId);
       
    95 	}
       
    96 
       
    97 /**
       
    98 Check whether two process ids match
       
    99 
       
   100 @param aProcessId a process ID to compare with this pair's process ID
       
   101 
       
   102 @return 0 if process ids do not match, non-zero if they do
       
   103 */
       
   104 TBool CProcessPair::ProcessIdMatches(const TProcessId &aProcessId) const
       
   105 	{
       
   106 	return iProcessId == aProcessId;
       
   107 	}
       
   108 
       
   109 /**
       
   110 Check whether the process names of two objects match in-case-sensitively
       
   111 
       
   112 @param aProcessPair a CProcessPair object to compare with this one
       
   113 
       
   114 @return 0 if process names do not match, non-zero if they do
       
   115 */
       
   116 TBool CProcessPair::ProcessNameMatches(const CProcessPair &aProcessPair) const
       
   117 	{
       
   118 	return ProcessNameMatches(*aProcessPair.iProcessName);
       
   119 	}
       
   120 
       
   121 /**
       
   122 Check whether two strings match in-case-sensitively
       
   123 
       
   124 @param aProcessName a process name to compare with this pair's process name
       
   125 
       
   126 @return 0 if process names do not match, non-zero if they do
       
   127 */
       
   128 TBool CProcessPair::ProcessNameMatches(const TDesC& aProcessName) const
       
   129 	{
       
   130 	return iProcessName->CompareF(aProcessName) == 0;
       
   131 	}
       
   132