diff -r 000000000000 -r d0791faffa3f backupandrestore/backupengine/inc/sbexternalisablearray.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/backupandrestore/backupengine/inc/sbexternalisablearray.inl Tue Feb 02 01:11:40 2010 +0200 @@ -0,0 +1,86 @@ +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// externalisablearray.inl +// Templated RArray for serialising and deserialising simple (flat) classes +// for transmission inside descriptors over IPC +// +// + +/** + @file + @publishedPartner + @released +*/ + +namespace conn + { + template inline RExternalisableArray* RExternalisableArray::InternaliseL(const TDesC8& aExternalisedArray) + /** + Internalises an RArray of objects passed via IPC from a descriptor + + @param aExternalisedArray The descriptor passed via IPC that contains the flattened array to internalise + @return Pointer to a newly created RExternalisableArray + */ + { + RExternalisableArray* self = new (ELeave) RExternalisableArray; + + CleanupStack::PushL(self); + + TUint8* unpackPtr = const_cast(aExternalisedArray.Ptr()); + TInt elementCount = *reinterpret_cast(unpackPtr); + + // point to the start of the packed elements + unpackPtr += sizeof(TInt); + + for (TInt index = 0; index < elementCount; index++) + { + User::LeaveIfError(self->Append(*reinterpret_cast(unpackPtr))); + unpackPtr += sizeof(T); + } + + CleanupStack::Pop(self); + + return self; + } + + template inline HBufC8* RExternalisableArray::ExternaliseL() + /** + Externalises an RArray of objects (not pointers) into a descriptor so that the RArray + may be passed via IPC + + @return Pointer to the created HBufC8 + */ + { + // calculate the flattened size of the array + TInt elementSize = sizeof(T); + TInt count = RArray::Count(); + TInt totalPackedSize = sizeof(TInt) + (sizeof(T) * count); // TInt stores the number of elements to be packed + + // create the HBufC8 to be returned + HBufC8* externalisedArray = HBufC8::NewL(totalPackedSize); + + TPtr8 buffer = externalisedArray->Des(); + + // Append the number of entries to the beginning of the array + buffer.Append(reinterpret_cast(&count), sizeof(TInt)); + + // bitwise copy each entry into the buffer + for (TInt index = 0; index < count; index++) + { + buffer.Append(reinterpret_cast(&(*this)[index]), elementSize); + } + + return externalisedArray; + } + }