cryptomgmtlibs/securitycommonutils/inc/ipcstream.inl
changeset 8 35751d3474b7
child 61 641f389e9157
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Library to add s32strm support for IPC (ie. stream via multiple IPC read/writes instead of
       
    16 * copying to a buffer and streaming to/from there.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23  @internalTechnology
       
    24  @prototype
       
    25 */
       
    26 
       
    27 #ifndef IPCSTREAM_INL
       
    28 #define IPCSTREAM_INL
       
    29 
       
    30 #include <scs/ipcstream.h>
       
    31 #include <scs/streamingarray.h>
       
    32 
       
    33 
       
    34 inline void WriteIntValueL(const RMessage2& aMessage, TInt aParam, TInt aValue)
       
    35 	{
       
    36 	TPckg<TInt> valuePak(aValue);
       
    37 	aMessage.WriteL(aParam, valuePak);
       
    38 	}
       
    39 
       
    40 template <class T>
       
    41 void WriteArraySizeL(const RMessage2& aMessage, TInt aParam, RPointerArray<T>& aArray)
       
    42 	{
       
    43 	TInt arraySize(0);
       
    44 	// If the array is not empty, calculate and return the required buffer size to externalize it. 
       
    45 	// Otherwise, return zero.
       
    46 	if(aArray.Count())
       
    47 		{
       
    48 		arraySize = ExternalizedBufferSizeL(aArray);
       
    49 		}
       
    50 	WriteIntValueL(aMessage, aParam, arraySize);
       
    51 	}
       
    52 
       
    53 template <class T>
       
    54 void WriteArraySizeL(const RMessage2& aMessage, TInt aParam, RArray<T>& aArray)
       
    55 	{
       
    56 	TInt arraySize(0); // if the array is empty, then zero length is returned
       
    57 	if(aArray.Count())
       
    58 		{ 
       
    59 		arraySize = ExternalizedBufferSizeL(aArray);
       
    60 		}
       
    61 	WriteIntValueL(aMessage, aParam, arraySize);
       
    62 	}
       
    63 
       
    64 template <class T>
       
    65 void WriteObjectSizeL(const RMessage2& aMessage, TInt aParam, const T* aObject)
       
    66 	{
       
    67 	// Calculate that how much buffer is needed to externalize the object
       
    68 	TInt entrySize(0);
       
    69 	if(aObject)
       
    70 		{
       
    71 		entrySize = GetObjectBufferSizeL(*aObject);
       
    72 		}
       
    73 	WriteIntValueL(aMessage, aParam, entrySize);
       
    74 	}
       
    75 
       
    76 template <class T>
       
    77 void WriteArrayDataL(const RMessage2& aMessage, TInt aParam, RPointerArray<T>& aArray)
       
    78 	{
       
    79 	if(!aArray.Count())
       
    80 		{
       
    81 		User::Leave(KErrAbort);
       
    82 		}
       
    83 	RIpcWriteStream ipcstream;
       
    84 	ipcstream.Open(aMessage, aParam);
       
    85 	CleanupClosePushL(ipcstream);
       
    86 	ExternalizePointersArrayL(aArray, ipcstream);
       
    87 	CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method
       
    88 	aArray.ResetAndDestroy(); // Reset the array to prevent it to be resent mistakenly.
       
    89 	}
       
    90 
       
    91 template <class T>
       
    92 void WriteArrayDataL(const RMessage2& aMessage, TInt aParam, RArray<T>& aArray)
       
    93 	{
       
    94 	if(!aArray.Count())
       
    95 		{
       
    96 		User::Leave(KErrAbort);
       
    97 		}
       
    98 	RIpcWriteStream ipcstream;
       
    99 	ipcstream.Open(aMessage, aParam);
       
   100 	CleanupClosePushL(ipcstream);
       
   101 	ExternalizeFixedLengthArrayL(aArray, ipcstream);
       
   102 	CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method
       
   103 	aArray.Reset(); // Reset the array to prevent it to be resent mistakenly.
       
   104 	}
       
   105 
       
   106 template <class T>
       
   107 void WriteObjectDataL(const RMessage2& aMessage, TInt aParam, const T* aObject)
       
   108 	{
       
   109 	if(!aObject)
       
   110 		{
       
   111 		User::Leave(KErrAbort);
       
   112 		}
       
   113 	RIpcWriteStream ipcstream;
       
   114 	ipcstream.Open(aMessage, aParam);
       
   115 	CleanupClosePushL(ipcstream);
       
   116 	ipcstream << *aObject;
       
   117 	CleanupStack::PopAndDestroy(&ipcstream); // Data is committed in Close method
       
   118 	}
       
   119 
       
   120 template <class T>
       
   121 T* ReadObjectFromMessageLC(const RMessage2& aMessage, TInt aSlot)
       
   122 	{
       
   123 	RIpcReadStream stream;
       
   124 	CleanupClosePushL(stream);
       
   125 	stream.Open(aMessage, aSlot);
       
   126 	T *object = T::NewL(stream);
       
   127 	CleanupStack::PopAndDestroy(&stream);
       
   128 	CleanupStack::PushL(object);
       
   129 	return object;
       
   130 	}
       
   131 
       
   132 #endif /* IPCSTREAM_INL */