1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitycommonutils/source/ipcstream/ipcbuf.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,98 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +* Library to add s32strm support for IPC (ie. stream via multiple IPC read/writes instead of
1.19 +* copying to a buffer and streaming to/from there.
1.20 +*
1.21 +*/
1.22 +
1.23 +
1.24 +/**
1.25 + @file
1.26 +*/
1.27 +#include "ipcbuf.h"
1.28 +
1.29 +
1.30 +EXPORT_C void RIpcBuf::Open(const RMessagePtr2& aMessage, TInt aMessageSlot)
1.31 + {
1.32 + iMessage = aMessage;
1.33 + iMessageSlot = aMessageSlot;
1.34 + iReadPos = 0;
1.35 + iWritePos = 0;
1.36 + }
1.37 +
1.38 +EXPORT_C TStreamPos RIpcBuf::DoSeekL(TMark aMark, TStreamLocation aLocation, TInt anOffset)
1.39 + {
1.40 +
1.41 + TInt size = iMessage.GetDesLengthL(iMessageSlot);
1.42 +
1.43 + switch (aLocation)
1.44 + {
1.45 + case EStreamBeginning:
1.46 + // do nothing
1.47 + break;
1.48 +
1.49 + case EStreamMark:
1.50 + if (aMark&ERead)
1.51 + {
1.52 + anOffset += iReadPos;
1.53 + }
1.54 + else if (aMark&EWrite)
1.55 + {
1.56 + anOffset += iWritePos;
1.57 + }
1.58 + break;
1.59 +
1.60 + case EStreamEnd:
1.61 + anOffset += size;
1.62 + break;
1.63 +
1.64 + default:
1.65 + User::Panic(KIpcBufPanic, EIpcBufSeekUnknownLocation);
1.66 + break;
1.67 + }
1.68 +
1.69 + // offset can't be negative or greater than size
1.70 + if (anOffset > size || anOffset < 0)
1.71 + {
1.72 + User::Panic(KIpcBufPanic, EIpcBufSeekBadOffset);
1.73 + }
1.74 +
1.75 + if (aMark&ERead)
1.76 + {
1.77 + iReadPos = anOffset;
1.78 + }
1.79 + else if (aMark&EWrite)
1.80 + {
1.81 + iWritePos = anOffset;
1.82 + }
1.83 +
1.84 + return TStreamPos(anOffset);
1.85 + }
1.86 +
1.87 +EXPORT_C TInt RIpcBuf::DoReadL(TAny *aPtr, TInt aMaxLength)
1.88 + {
1.89 + TPtr8 ptr((TUint8*)aPtr, aMaxLength);
1.90 + iMessage.ReadL(iMessageSlot, ptr, iReadPos);
1.91 + TInt len = ptr.Length();
1.92 + iReadPos += len;
1.93 + return len;
1.94 + }
1.95 +
1.96 +EXPORT_C void RIpcBuf::DoWriteL(const TAny* aPtr,TInt aLength)
1.97 + {
1.98 + TPtr8 ptr((TUint8*)aPtr, aLength, aLength);
1.99 + iMessage.WriteL(iMessageSlot, ptr, iWritePos);
1.100 + iWritePos += aLength;
1.101 + }