diff -r 675a964f4eb5 -r 35751d3474b7 cryptomgmtlibs/securitycommonutils/inc/ipcstream.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cryptomgmtlibs/securitycommonutils/inc/ipcstream.inl Thu Sep 10 14:01:51 2009 +0300 @@ -0,0 +1,132 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of the License "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: +* Library to add s32strm support for IPC (ie. stream via multiple IPC read/writes instead of +* copying to a buffer and streaming to/from there. +* +*/ + + +/** + @file + @internalTechnology + @prototype +*/ + +#ifndef IPCSTREAM_INL +#define IPCSTREAM_INL + +#include +#include + + +inline void WriteIntValueL(const RMessage2& aMessage, TInt aParam, TInt aValue) + { + TPckg valuePak(aValue); + aMessage.WriteL(aParam, valuePak); + } + +template +void WriteArraySizeL(const RMessage2& aMessage, TInt aParam, RPointerArray& aArray) + { + TInt arraySize(0); + // If the array is not empty, calculate and return the required buffer size to externalize it. + // Otherwise, return zero. + if(aArray.Count()) + { + arraySize = ExternalizedBufferSizeL(aArray); + } + WriteIntValueL(aMessage, aParam, arraySize); + } + +template +void WriteArraySizeL(const RMessage2& aMessage, TInt aParam, RArray& aArray) + { + TInt arraySize(0); // if the array is empty, then zero length is returned + if(aArray.Count()) + { + arraySize = ExternalizedBufferSizeL(aArray); + } + WriteIntValueL(aMessage, aParam, arraySize); + } + +template +void WriteObjectSizeL(const RMessage2& aMessage, TInt aParam, const T* aObject) + { + // Calculate that how much buffer is needed to externalize the object + TInt entrySize(0); + if(aObject) + { + entrySize = GetObjectBufferSizeL(*aObject); + } + WriteIntValueL(aMessage, aParam, entrySize); + } + +template +void WriteArrayDataL(const RMessage2& aMessage, TInt aParam, RPointerArray& aArray) + { + if(!aArray.Count()) + { + User::Leave(KErrAbort); + } + RIpcWriteStream ipcstream; + ipcstream.Open(aMessage, aParam); + CleanupClosePushL(ipcstream); + ExternalizePointersArrayL(aArray, ipcstream); + CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method + aArray.ResetAndDestroy(); // Reset the array to prevent it to be resent mistakenly. + } + +template +void WriteArrayDataL(const RMessage2& aMessage, TInt aParam, RArray& aArray) + { + if(!aArray.Count()) + { + User::Leave(KErrAbort); + } + RIpcWriteStream ipcstream; + ipcstream.Open(aMessage, aParam); + CleanupClosePushL(ipcstream); + ExternalizeFixedLengthArrayL(aArray, ipcstream); + CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method + aArray.Reset(); // Reset the array to prevent it to be resent mistakenly. + } + +template +void WriteObjectDataL(const RMessage2& aMessage, TInt aParam, const T* aObject) + { + if(!aObject) + { + User::Leave(KErrAbort); + } + RIpcWriteStream ipcstream; + ipcstream.Open(aMessage, aParam); + CleanupClosePushL(ipcstream); + ipcstream << *aObject; + CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method + } + +template +T* ReadObjectFromMessageLC(const RMessage2& aMessage, TInt aSlot) + { + RIpcReadStream stream; + CleanupClosePushL(stream); + stream.Open(aMessage, aSlot); + T *object = T::NewL(stream); + CleanupStack::PopAndDestroy(&stream); + CleanupStack::PushL(object); + return object; + } + +#endif /* IPCSTREAM_INL */