messagingfw/wappushfw/tpush/RefTestAgent/RTAParser/rightscriteriaexpiry.cpp
changeset 0 8e480a14352b
child 30 3a6baaa22be8
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 "rightscriteriaexpiry.h"
       
    19 
       
    20 
       
    21 using namespace ReferenceTestAgent;
       
    22 
       
    23 
       
    24 CRightsCriteriaExpiry* CRightsCriteriaExpiry::NewL(TInt aDay, TMonth aMonth, TInt aYear)
       
    25 	{
       
    26 	CRightsCriteriaExpiry* self = new (ELeave) CRightsCriteriaExpiry(aDay, aMonth, aYear);
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CRightsCriteriaExpiry* CRightsCriteriaExpiry::NewL(RReadStream& aStream)
       
    31 	{
       
    32 	CRightsCriteriaExpiry* self = new (ELeave) CRightsCriteriaExpiry;
       
    33 	CleanupStack::PushL(self);
       
    34 	self->InternalizeL(aStream);
       
    35 	CleanupStack::Pop(self);
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 CRightsCriteriaExpiry::CRightsCriteriaExpiry()
       
    40 	{
       
    41 	}
       
    42 
       
    43 CRightsCriteriaExpiry::CRightsCriteriaExpiry(TInt aDay, TMonth aMonth, TInt aYear) :
       
    44 iExpire(aYear, aMonth, aDay, 23, 59, 59, 999999)
       
    45 	{
       
    46 	}
       
    47 
       
    48 CRightsCriteriaExpiry::~CRightsCriteriaExpiry()
       
    49 	{
       
    50 	}
       
    51 
       
    52 TInt CRightsCriteriaExpiry::Evaluate()
       
    53 	{
       
    54 	TTime expiry(iExpire);
       
    55 	TTime now;
       
    56 	now.HomeTime();
       
    57 	
       
    58 	if(expiry < now)
       
    59 		{
       
    60 		return KErrCANoPermission;
       
    61 		}
       
    62 	else	
       
    63 		{
       
    64 		return KErrNone;	
       
    65 		}
       
    66 	}
       
    67 	
       
    68 void CRightsCriteriaExpiry::ExecuteL()
       
    69 	{
       
    70 	User::LeaveIfError(Evaluate());	
       
    71 	}
       
    72 	
       
    73 
       
    74 TBool CRightsCriteriaExpiry::IsStateless() const
       
    75 	{
       
    76 	return ETrue;	
       
    77 	}
       
    78 
       
    79 ECriteriaType CRightsCriteriaExpiry::Type() const
       
    80 	{
       
    81 	return ECriteriaExpiry;
       
    82 	}
       
    83 
       
    84 MCriteria* CRightsCriteriaExpiry::CopyL() const
       
    85 	{
       
    86 	return CRightsCriteriaExpiry::NewL(iExpire.Day(), iExpire.Month(), iExpire.Year());
       
    87 	}
       
    88 		
       
    89 TBool CRightsCriteriaExpiry::Merge(MCriteria& aCriteria)
       
    90 	{
       
    91 	CRightsCriteriaExpiry& expiryCriteria = reinterpret_cast<CRightsCriteriaExpiry&>(aCriteria);
       
    92 	TTime currentExpiry(iExpire);
       
    93 	TTime mergedExpiry(expiryCriteria.Expiry());
       
    94 	if(mergedExpiry > currentExpiry)
       
    95 		{
       
    96 		iExpire = expiryCriteria.Expiry();
       
    97 		}
       
    98 	return ETrue;
       
    99 	}
       
   100 
       
   101 TDateTime& CRightsCriteriaExpiry::Expiry()
       
   102 	{
       
   103 	return iExpire;
       
   104 	}
       
   105 
       
   106 void CRightsCriteriaExpiry::InternalizeL(RReadStream& aStream)
       
   107 	{
       
   108 	TPckg <TDateTime> timePckg(iExpire);
       
   109 	aStream.ReadL(timePckg);
       
   110 	}
       
   111 	
       
   112 void CRightsCriteriaExpiry::ExternalizeL(RWriteStream& aStream)
       
   113 	{
       
   114 	TPckg <TDateTime> timePckg(iExpire);
       
   115 	aStream.WriteL(timePckg);
       
   116 	}
       
   117 
       
   118 void CRightsCriteriaExpiry::WriteDescription(RFile& aFile)
       
   119 	{
       
   120 	TBuf <20> dateText;
       
   121 	TBuf8 <20> dateText8;
       
   122 	TTime expiry(iExpire);
       
   123 	TRAPD(err, expiry.FormatL(dateText, _L("%1%/1%2%/2%3")));
       
   124 	
       
   125 	dateText8.Copy(dateText);
       
   126 	if(err == KErrNone)
       
   127 		{
       
   128 		aFile.Write(_L8("Expiry "));
       
   129 		aFile.Write(dateText8);
       
   130 		}
       
   131 	aFile.Write(_L8("\r\n"));
       
   132 	}