os/kernelhwsrv/kernel/eka/debug/securityServer/src/c_process_pair.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.
sl@0
     1
// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// Provides a helper class for process security management
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32base.h>
sl@0
    19
#include <e32base_private.h>
sl@0
    20
sl@0
    21
// Required for logging
sl@0
    22
#include <rm_debug_api.h>
sl@0
    23
sl@0
    24
#include "c_process_pair.h"
sl@0
    25
#include "rm_debug_logging.h"
sl@0
    26
sl@0
    27
sl@0
    28
CProcessPair* CProcessPair::NewL(const TDesC& aProcessName, const TProcessId aProcessId)
sl@0
    29
	{
sl@0
    30
	CProcessPair* self=new (ELeave) CProcessPair();
sl@0
    31
	CleanupStack::PushL(self);
sl@0
    32
	self->ConstructL(aProcessName, aProcessId);
sl@0
    33
	CleanupStack::Pop(self);
sl@0
    34
	return self;
sl@0
    35
	}
sl@0
    36
sl@0
    37
void CProcessPair::ConstructL(const TDesC& aProcessName, const TProcessId aProcessId)
sl@0
    38
	{
sl@0
    39
	//allocate the process name buffer and fill with aProcessName
sl@0
    40
	iProcessName = aProcessName.Alloc();
sl@0
    41
	if(iProcessName == NULL)
sl@0
    42
		User::Leave(KErrNoMemory);
sl@0
    43
sl@0
    44
	LOG_MSG2( "CProcessPair::ConstructL() process name: %S", &TPtr8((TUint8*)iProcessName->Ptr(), 2*iProcessName->Length(), 2*iProcessName->Length()) );
sl@0
    45
sl@0
    46
	//set process id
sl@0
    47
	iProcessId = aProcessId;
sl@0
    48
	}
sl@0
    49
sl@0
    50
CProcessPair::CProcessPair()
sl@0
    51
	{
sl@0
    52
	}
sl@0
    53
sl@0
    54
CProcessPair::~CProcessPair()
sl@0
    55
	{
sl@0
    56
	delete iProcessName;
sl@0
    57
	}
sl@0
    58
sl@0
    59
/**
sl@0
    60
Check whether two CProcessPair objects are equal
sl@0
    61
sl@0
    62
@param aProcessPair a CProcessPair object to match with this one
sl@0
    63
sl@0
    64
@return ETrue is process id and name match, EFalse otherwise
sl@0
    65
*/
sl@0
    66
TBool CProcessPair::operator==(const CProcessPair &aProcessPair) const
sl@0
    67
	{
sl@0
    68
	return Equals(*aProcessPair.iProcessName, aProcessPair.iProcessId);
sl@0
    69
	}
sl@0
    70
	
sl@0
    71
/**
sl@0
    72
Check whether this CProcessPair object has these values set
sl@0
    73
sl@0
    74
@param aProcessName process name to check
sl@0
    75
@param aProcessId process id to check
sl@0
    76
sl@0
    77
@return ETrue is process id and name match, EFalse otherwise
sl@0
    78
*/
sl@0
    79
TBool CProcessPair::Equals(const TDesC& aProcessName, const TProcessId aProcessId) const
sl@0
    80
	{
sl@0
    81
	return (ProcessIdMatches(aProcessId) && (ProcessNameMatches(aProcessName)));
sl@0
    82
	}
sl@0
    83
sl@0
    84
/**
sl@0
    85
Check whether the process ids of two objects match
sl@0
    86
sl@0
    87
@param aProcessPair a CProcessPair object to compare with this one
sl@0
    88
sl@0
    89
@return ETrue is process id matches, EFalse otherwise
sl@0
    90
*/
sl@0
    91
TBool CProcessPair::ProcessIdMatches(const CProcessPair &aProcessPair) const
sl@0
    92
	{
sl@0
    93
	return ProcessIdMatches(aProcessPair.iProcessId);
sl@0
    94
	}
sl@0
    95
sl@0
    96
/**
sl@0
    97
Check whether two process ids match
sl@0
    98
sl@0
    99
@param aProcessId a process ID to compare with this pair's process ID
sl@0
   100
sl@0
   101
@return ETrue is process id matches, EFalse otherwise
sl@0
   102
*/
sl@0
   103
TBool CProcessPair::ProcessIdMatches(const TProcessId &aProcessId) const
sl@0
   104
	{
sl@0
   105
	return iProcessId == aProcessId;
sl@0
   106
	}
sl@0
   107
sl@0
   108
/**
sl@0
   109
Check whether the process names of two objects match in-case-sensitively
sl@0
   110
sl@0
   111
@param aProcessPair a CProcessPair object to compare with this one
sl@0
   112
sl@0
   113
@return ETrue is process names match, EFalse otherwise
sl@0
   114
*/
sl@0
   115
TBool CProcessPair::ProcessNameMatches(const CProcessPair &aProcessPair) const
sl@0
   116
	{
sl@0
   117
	return ProcessNameMatches(*aProcessPair.iProcessName);
sl@0
   118
	}
sl@0
   119
sl@0
   120
/**
sl@0
   121
Check whether two strings match in-case-sensitively
sl@0
   122
sl@0
   123
@param aProcessName a process name to compare with this pair's process name
sl@0
   124
sl@0
   125
@return ETrue is process names match, EFalse otherwise
sl@0
   126
*/
sl@0
   127
TBool CProcessPair::ProcessNameMatches(const TDesC& aProcessName) const
sl@0
   128
	{
sl@0
   129
	TInt equal = iProcessName->CompareF(aProcessName);
sl@0
   130
	return (equal == 0) ? ETrue : EFalse;
sl@0
   131
	}
sl@0
   132