messagingfw/wappushfw/tpush/RefTestAgent/RTAParser/rightscriteriacount.cpp
changeset 0 8e480a14352b
child 22 d2c4c66342f3
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2004-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 //
       
    15 
       
    16 #include <s32strm.h>
       
    17 #include <caf/caf.h>
       
    18 #include "rightscriteriacount.h"
       
    19 
       
    20 
       
    21 using namespace ReferenceTestAgent;
       
    22 
       
    23 
       
    24 CRightsCriteriaCount* CRightsCriteriaCount::NewL(TInt aCount)
       
    25 	{
       
    26 	CRightsCriteriaCount* self = new (ELeave) CRightsCriteriaCount(aCount);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CRightsCriteriaCount* CRightsCriteriaCount::NewL(RReadStream& aStream)
       
    31 	{
       
    32 	CRightsCriteriaCount* self = new (ELeave) CRightsCriteriaCount;
       
    33 	CleanupStack::PushL(self);
       
    34 	self->InternalizeL(aStream);
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 CRightsCriteriaCount::CRightsCriteriaCount()
       
    40 	{
       
    41 	}
       
    42 
       
    43 CRightsCriteriaCount::CRightsCriteriaCount(TInt aCount) : iCount(aCount)
       
    44 	{
       
    45 	}
       
    46 
       
    47 CRightsCriteriaCount::~CRightsCriteriaCount()
       
    48 	{
       
    49 	}
       
    50 
       
    51 TInt CRightsCriteriaCount::Evaluate()
       
    52 	{
       
    53 	TInt err = KErrNone;
       
    54 	if(iCount == 0)
       
    55 		{
       
    56 		err = KErrCANoPermission;
       
    57 		}
       
    58 	return err;
       
    59 	}
       
    60 	
       
    61 void CRightsCriteriaCount::ExecuteL()
       
    62 	{
       
    63 	if(iCount > 0)
       
    64 		{
       
    65 		iCount--;
       
    66 		}
       
    67 	else
       
    68 		{
       
    69 		User::Leave(KErrCANoPermission);	
       
    70 		}
       
    71 	}
       
    72 
       
    73 TBool CRightsCriteriaCount::IsStateless() const
       
    74 	{
       
    75 	return EFalse;	
       
    76 	}
       
    77 	
       
    78 ECriteriaType CRightsCriteriaCount::Type() const
       
    79 	{
       
    80 	return ECriteriaCount;
       
    81 	}
       
    82 	
       
    83 TInt CRightsCriteriaCount::Count() const
       
    84 	{
       
    85 	return iCount;	
       
    86 	}
       
    87 	
       
    88 MCriteria* CRightsCriteriaCount::CopyL() const
       
    89 	{
       
    90 	return CRightsCriteriaCount::NewL(iCount);		
       
    91 	}
       
    92 
       
    93 TBool CRightsCriteriaCount::Merge(MCriteria& aCriteria)
       
    94 	{
       
    95 	CRightsCriteriaCount& countCriteria = reinterpret_cast<CRightsCriteriaCount&>(aCriteria);
       
    96 	iCount += countCriteria.Count();
       
    97 	return ETrue;
       
    98 	}
       
    99 	
       
   100 	
       
   101 void CRightsCriteriaCount::InternalizeL(RReadStream& aStream)
       
   102 	{
       
   103 	iCount = aStream.ReadInt32L();
       
   104 	}
       
   105 	
       
   106 void CRightsCriteriaCount::ExternalizeL(RWriteStream& aStream)
       
   107 	{
       
   108 	aStream.WriteInt32L(iCount);
       
   109 	}
       
   110 
       
   111 void CRightsCriteriaCount::WriteDescription(RFile& aFile)
       
   112 	{
       
   113 	TBuf8 <10> count;
       
   114 	count.Num(iCount);
       
   115 	aFile.Write(_L8("Count = "));
       
   116 	aFile.Write(count);
       
   117 	aFile.Write(_L8("\r\n"));
       
   118 	}