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: #define __INCLUDE_CAPABILITY_NAMES__ sl@0: #include "capabilityset.h" sl@0: sl@0: CapabilitySet::CapabilitySet() sl@0: { sl@0: memset(iCaps,0,sizeof(iCaps)); sl@0: } sl@0: sl@0: #if 0 sl@0: // Not currently used or tested sl@0: CapabilitySet::CapabilitySet(const CapabilitySet &aRef) sl@0: { sl@0: memcpy(iCaps, aRef.iCaps, sizeof(iCaps)); sl@0: } sl@0: #endif sl@0: sl@0: CapabilitySet &CapabilitySet::operator=(const CapabilitySet &aRhs) sl@0: { sl@0: BULLSEYE_OFF sl@0: if(this == &aRhs) return *this; // handle self assignment sl@0: BULLSEYE_RESTORE sl@0: memcpy(iCaps, aRhs.iCaps, sizeof(iCaps)); sl@0: return *this; sl@0: } sl@0: sl@0: sl@0: void CapabilitySet::AddCapability(TCapability aCapability) sl@0: { sl@0: BULLSEYE_OFF sl@0: if((TUint32)aCapability>=(TUint32)ECapability_HardLimit) sl@0: { sl@0: dbg << Log::Indent() << "Illegal capabaility value " << aCapability << Log::Endl(); sl@0: FatalError(); sl@0: } sl@0: BULLSEYE_RESTORE sl@0: sl@0: TInt index = aCapability>>3; sl@0: TUint8 mask = (TUint8)(1<<(aCapability&7)); sl@0: //mask &= ((TUint8*)&AllSupportedCapabilities)[index]; sl@0: ((TUint8*)iCaps)[index] |= mask; sl@0: } sl@0: sl@0: TBool CapabilitySet::HasCapability(TCapability aCapability) const sl@0: { sl@0: BULLSEYE_OFF sl@0: if((TUint32)aCapability>=(TUint32)ECapability_HardLimit) sl@0: { sl@0: FatalError(); sl@0: } sl@0: BULLSEYE_RESTORE sl@0: sl@0: return (((TUint8*)iCaps)[aCapability>>3]>>(aCapability&7))&1; sl@0: } sl@0: sl@0: sl@0: void EncodeHuman(REncodeWriteStream& aStream,const CapabilitySet &aCapSet) sl@0: { sl@0: aStream.WriteCStr(" { "); sl@0: for(TUint32 cap=0; cap < ECapability_Limit; ++cap) sl@0: { sl@0: if(aCapSet.HasCapability(TCapability(cap))) sl@0: { sl@0: aStream.WriteCStr(CapabilityNames[cap]); sl@0: aStream.WriteSpace(); sl@0: } sl@0: } sl@0: sl@0: for(TUint32 cap=ECapability_Limit; cap < ECapability_HardLimit; ++cap) sl@0: { sl@0: if(aCapSet.HasCapability(TCapability(cap))) sl@0: { sl@0: EncodeHuman(aStream, TUint32(cap)); sl@0: aStream.WriteSpace(); sl@0: } sl@0: } sl@0: sl@0: aStream.WriteByte('}'); sl@0: } sl@0: sl@0: void DecodeHuman(RDecodeReadStream& aStream, CapabilitySet &aCapSet) sl@0: { sl@0: aStream.CheckName("{"); sl@0: while(aStream.PeakToken() != "}") sl@0: { sl@0: AutoIndent ai(prog); sl@0: // We process PeakToken so if it is not valid we can call sl@0: // DecodeHuman TUint32 to read the next token and process it sl@0: // as a number. sl@0: prog << Log::Indent() << "Parsing capability '" << aStream.PeakToken() << "'" << Log::Endl(); sl@0: TUint32 cap; sl@0: for(cap=0; cap < ECapability_Limit; ++cap) sl@0: { sl@0: if(aStream.PeakToken() == CapabilityNames[cap]) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: if(cap < ECapability_Limit) sl@0: { sl@0: // The token was ok, so read/discard it. sl@0: aStream.ReadNextToken(); sl@0: } sl@0: else sl@0: { sl@0: // Fallback to decoding as a number sl@0: prog<< Log::Indent() << "WARNING: Unknown capability '" << aStream.PeakToken() << "' attempting to decode as a bit number..." << Log::Endl(); sl@0: DecodeHuman(aStream, cap); sl@0: prog << Log::Indent() << "Decoded as " << cap << Log::Endl(); sl@0: } sl@0: aCapSet.AddCapability(TCapability(cap)); sl@0: } sl@0: aStream.CheckName("}"); sl@0: } sl@0: sl@0: sl@0: void CapabilitySet::ExternalizeL(RWriteStream &aStream) const sl@0: { sl@0: TPckg capsPckg(iCaps); sl@0: aStream << capsPckg; sl@0: } sl@0: sl@0: void CapabilitySet::InternalizeL(RReadStream &aStream) sl@0: { sl@0: TPckg capsPckg(iCaps); sl@0: aStream >> capsPckg; sl@0: } sl@0: sl@0: sl@0: sl@0: // End of file