sl@0: /*
sl@0: * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: * All rights reserved.
sl@0: * This component and the accompanying materials are made available
sl@0: * under the terms of the License "Eclipse Public License v1.0"
sl@0: * which accompanies this distribution, and is available
sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: *
sl@0: * Initial Contributors:
sl@0: * Nokia Corporation - initial contribution.
sl@0: *
sl@0: * Contributors:
sl@0: *
sl@0: * Description: 
sl@0: *
sl@0: */
sl@0: 
sl@0: 
sl@0: #include "swicertstore.h"
sl@0: static const EnumEntry enumDetailsForTBool[] =
sl@0: {
sl@0:     { "false", false},
sl@0:     { "true", true},
sl@0:     { "EFalse", false},
sl@0:     { "ETrue", true},
sl@0: 	{ 0,0 }
sl@0: };
sl@0: 
sl@0: EncDecContainerItem *SwiCertStoreEntry::Factory()
sl@0: {
sl@0: 	return new SwiCertStoreEntry;
sl@0: }
sl@0: 
sl@0: SwiCertStoreEntry::SwiCertStoreEntry()
sl@0: 	: CertStoreEntry(true),
sl@0: 	  iCapabilitySet("CapabilitySet"), 
sl@0: 	  iTmpFlags("Mandatory/SystemUpgrade"),
sl@0: 	  iMandatory("Mandatory", enumDetailsForTBool),
sl@0: 	  iSystemUpgrade("SystemUpgrade", enumDetailsForTBool)
sl@0: {
sl@0: 	// We only need to initialise EncDecObject members which wrap non-class types
sl@0: 	iTmpFlags.Value() = 0;
sl@0: }
sl@0: 
sl@0: SwiCertStoreEntry::~SwiCertStoreEntry()
sl@0: {
sl@0: }
sl@0: 
sl@0: const int KMandatoryMask = 0x01;
sl@0: const int KSystemUpgradeMask = 0x02;
sl@0: 
sl@0: void SwiCertStoreEntry::Encode(REncodeWriteStream &aWriteStream)
sl@0: {
sl@0: 	CertStoreEntry::Encode(aWriteStream);
sl@0: 	aWriteStream << iCapabilitySet;
sl@0: 	if(aWriteStream.HumanReadable())
sl@0: 		{
sl@0: 		// Write the Mandatory and SystemUpgrade fields
sl@0: 		aWriteStream << iMandatory;
sl@0: 		aWriteStream << iSystemUpgrade;
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		// Encode the Mandatory and SystemUpgrade values and write the binary field
sl@0: 		TUint8 tmp = 0;
sl@0: 		if(iMandatory.Value())
sl@0: 			{
sl@0: 			tmp |= KMandatoryMask;
sl@0: 			}
sl@0: 		
sl@0: 		if(iSystemUpgrade.Value())
sl@0: 			{
sl@0: 			tmp |= KSystemUpgradeMask;
sl@0: 			}
sl@0: 		
sl@0: 		iTmpFlags.Value() = tmp;
sl@0: 		aWriteStream << iTmpFlags;
sl@0: 		}
sl@0: 
sl@0: }
sl@0: 
sl@0: void SwiCertStoreEntry::Decode(RDecodeReadStream &aReadStream)
sl@0: {
sl@0: 	CertStoreEntry::Decode(aReadStream);
sl@0: 	aReadStream >> iCapabilitySet;
sl@0: 
sl@0: 	if(aReadStream.HumanReadable())
sl@0: 		{
sl@0: 		// Read the Mandatory and SystemUpgrade fields
sl@0: 		if(aReadStream.PeakToken() == iMandatory.Name())
sl@0: 			{
sl@0: 			aReadStream >> iMandatory;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			iMandatory.SetValue("false");
sl@0: 			}
sl@0: 			if(aReadStream.PeakToken() == iSystemUpgrade.Name())
sl@0: 			{
sl@0: 			aReadStream >> iSystemUpgrade;
sl@0: 			}
sl@0: 		else
sl@0: 			{
sl@0: 			iSystemUpgrade.SetValue("false");
sl@0: 			}
sl@0: 		}
sl@0: 	else
sl@0: 		{
sl@0: 		// Read the binary field and decode the Mandatory and SystemUpgrade values
sl@0: 		aReadStream >> iTmpFlags;
sl@0: 		iMandatory.SetValue((iTmpFlags.Value() & KMandatoryMask) != 0);
sl@0: 		iSystemUpgrade.SetValue((iTmpFlags.Value() & KSystemUpgradeMask) != 0);
sl@0: 		}
sl@0: }
sl@0: 
sl@0: SwiCertStoreEntry& SwiCertStoreEntry::operator= (const SwiCertStoreEntry& aRhs)
sl@0: {
sl@0: 	if(this == &aRhs) return *this; // handle self assignment
sl@0: 
sl@0: 	// Copy base class members
sl@0: 	CertStoreEntry::operator=(*static_cast<const CertStoreEntry *>(&aRhs));
sl@0: 
sl@0: 	// Copy our additional members
sl@0: 	iCapabilitySet = aRhs.iCapabilitySet;
sl@0: 	// iTmpFlags does not need copying
sl@0: 	iMandatory = aRhs.iMandatory;
sl@0: 	iSystemUpgrade = aRhs.iSystemUpgrade;
sl@0: 
sl@0: 	return *this;
sl@0: }
sl@0: 
sl@0: 
sl@0: // End of file