williamr@2: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: // Class TStreamMark williamr@2: inline TStreamMark::TStreamMark() williamr@2: : iPos(KStreamBeginning-1) williamr@2: /** Constructs a default shared stream mark object. williamr@2: williamr@2: The position for the mark is uninitialised. williamr@2: williamr@2: An uninitialised mark means that a call to IsEmpty() returns true. williamr@2: williamr@2: @see IsEmpty() */ williamr@2: {} williamr@2: inline TStreamMark::TStreamMark(TStreamPos aPos) williamr@2: : iPos(aPos) williamr@2: /** Constructs the shared stream mark object, setting the mark to the specified williamr@2: stream position. williamr@2: williamr@2: An initialised mark means that a call to IsEmpty() returns false. williamr@2: williamr@2: @param aPos The stream position williamr@2: @see IsEmpty() */ williamr@2: { williamr@2: #if defined (_DEBUG) williamr@2: __DbgChkPos(aPos); williamr@2: #endif williamr@2: } williamr@2: inline TStreamMark& TStreamMark::operator=(TStreamPos aPos) williamr@2: /** Assigns the specified stream position value to this shared stream mark object. williamr@2: williamr@2: @param aPos The stream position value to be assigned. williamr@2: @return A reference to this shared stream mark object. */ williamr@2: { williamr@2: #if defined (_DEBUG) williamr@2: __DbgChkPos(aPos); williamr@2: #endif williamr@2: iPos=aPos; williamr@2: return *this; williamr@2: } williamr@2: inline TStreamMark::operator TStreamMark*() williamr@2: {return this;} williamr@2: inline TStreamMark::operator const TStreamMark*() const williamr@2: {return this;} williamr@2: inline TBool TStreamMark::operator==(const TStreamMark& aMark) const williamr@2: /** Tests whether this object and the specified referenced shared stream mark object williamr@2: are the same object. williamr@2: williamr@2: @param aMark A reference to a shared stream mark object. williamr@2: @return True, if the two objects are the same object; false, otherwise. */ williamr@2: {return this==&aMark;} williamr@2: inline TBool TStreamMark::operator==(const TStreamMark* aPtr) const williamr@2: {return this==aPtr;} williamr@2: inline TBool TStreamMark::operator!=(const TStreamMark& aMark) const williamr@2: /** Tests whether this object and the specified shared stream mark object are different williamr@2: objects. williamr@2: williamr@2: @param aMark A pointer to a shared stream mark object. williamr@2: @return True, if the two objects are different objects; false, otherwise. */ williamr@2: {return this!=&aMark;} williamr@2: inline TBool TStreamMark::operator!=(const TStreamMark* aPtr) const williamr@2: {return this!=aPtr;} williamr@2: inline TBool TStreamMark::IsEmpty() const williamr@2: /** Tests whether this mark object is uninitialised. williamr@2: williamr@2: @return True, if this mark object is uninitialised; false, otherwise. */ williamr@2: {return iPos=KStreamBeginning||aHost.RefersTo(*this);} williamr@2: inline void TStreamMark::Withdraw(TStreamExchange& aHost) williamr@2: /** Instructs the shared streaming manager to remove any reference it has to this williamr@2: mark object. williamr@2: williamr@2: @param aHost The object that manages shared streaming. */ williamr@2: {aHost.Drop(*this);} williamr@2: inline void TStreamMark::ExtractL(TStreamExchange& aHost) williamr@2: /** Refreshes this mark from the mark in the host stream buffer and tells the shared williamr@2: streaming manager to drop any reference it has to to this mark object. williamr@2: williamr@2: @param aHost The object that manages shared streaming. */ williamr@2: {aHost.GetL(*this);} williamr@2: inline TInt TStreamMark::ReadL(TStreamExchange& aHost,TAny* aPtr,TInt aMaxLength) williamr@2: /** Reads data from the shared stream into the specified memory location. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aPtr A pointer to the target memory location for the data read from williamr@2: the shared stream. williamr@2: @param aMaxLength The maximum number of bytes to be read. williamr@2: @return The number of bytes read. */ williamr@2: {return aHost.DoReadL(aPtr,aMaxLength,*this);} williamr@2: inline TInt TStreamMark::ReadL(TStreamExchange& aHost,TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus) williamr@2: /** Reads data, asynchronously, from the shared stream into the specified descriptor. williamr@2: williamr@2: If the function leaves, then no read request will have been initiated. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aDes The target descriptor for the data read from the shared stream. williamr@2: @param aMaxLength The maximum number of bytes to be read. williamr@2: @param aStatus The request status that indicates the completion status of this williamr@2: asynchronous request. williamr@2: @return The maximum number of bytes to be read, as used in this request. This williamr@2: can be different to the value supplied in aMaxLength; this is dependent on williamr@2: the implementation of the underlying stream. */ williamr@2: {return aHost.DoReadL(aDes,aMaxLength,aStatus,*this);} williamr@2: inline TStreamTransfer TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput,TStreamTransfer aTransfer) williamr@2: /** Reads data from the shared stream into the specified data sink. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anInput The sink which is the target for the read operation. williamr@2: @param aTransfer Defines the amount of data available to be read from the shared williamr@2: stream. williamr@2: @return The amount of data that was not consumed. */ williamr@2: {return aHost.DoReadL(anInput,aTransfer,*this);} williamr@2: inline TInt TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput,TInt aMaxLength) williamr@2: /** Reads data from the shared stream into the specified data sink. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anInput The sink which is the target for the read operation. williamr@2: @param aMaxLength The maximum amount of data available to be read from the williamr@2: shared stream. williamr@2: @return The amount of data that was not consumed. */ williamr@2: {return aMaxLength-aHost.DoReadL(anInput,TStreamTransfer(aMaxLength),*this).Left();} williamr@2: inline void TStreamMark::ReadL(TStreamExchange& aHost,MStreamInput& anInput) williamr@2: /** Reads data from the shared stream into the specified data sink. williamr@2: williamr@2: No explicit limit is placed on the amount of data that can be read. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anInput The sink which is the target for the read operation. */ williamr@2: {aHost.DoReadL(anInput,KStreamUnlimited,*this);} williamr@2: inline void TStreamMark::WriteL(TStreamExchange& aHost,const TAny* aPtr,TInt aLength) williamr@2: /** Writes data from the specified memory location into the shared stream. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aPtr A pointer to the memory location from which data is to be written williamr@2: to the shared stream. williamr@2: @param aLength The number of bytes to be written. */ williamr@2: {aHost.DoWriteL(aPtr,aLength,*this);} williamr@2: inline TInt TStreamMark::WriteL(TStreamExchange& aHost,const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus) williamr@2: /** Writes data, asynchronously, from the specified descriptor into the shared williamr@2: stream. williamr@2: williamr@2: If the function leaves, then no write request will have been initiated. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aDes The source descriptor for the data to be written into the shared williamr@2: stream. williamr@2: @param aMaxLength The maximum number of bytes to be written. williamr@2: @param aStatus The request status that indicates the completion status of this williamr@2: asynchronous request. williamr@2: @return The maximum number of bytes to be written, as used in this request. williamr@2: This can be different to the value supplied in aMaxLength; this is dependent williamr@2: on the implementation. */ williamr@2: {return aHost.DoWriteL(aDes,aMaxLength,aStatus,*this);} williamr@2: inline TStreamTransfer TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TStreamTransfer aTransfer) williamr@2: /** Writes data into the shared stream from the specified data source. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anOutput The data source for the write operation. williamr@2: @param aTransfer Defines the amount of data to be pulled from the output stream williamr@2: object. williamr@2: @return A stream transfer object defining the amount of data that was not consumed. */ williamr@2: {return aHost.DoWriteL(anOutput,aTransfer,*this);} williamr@2: inline TInt TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TInt aMaxLength) williamr@2: /** Writes data into the shared stream from the specified data source williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anOutput The data source for the write operation. williamr@2: @param aMaxLength The maximum amount of data available to be written. williamr@2: @return The amount of data that was not consumed. */ williamr@2: {return aMaxLength-aHost.DoWriteL(anOutput,TStreamTransfer(aMaxLength),*this).Left();} williamr@2: inline void TStreamMark::WriteL(TStreamExchange& aHost,MStreamOutput& anOutput) williamr@2: /** Writes data into the shared stream from the specified data source. williamr@2: williamr@2: No explicit limit is placed on the amount of data that can be written. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anOutput The data source for the write operation. */ williamr@2: {aHost.DoWriteL(anOutput,KStreamUnlimited,*this);} williamr@2: inline void TStreamMark::SeekL(TStreamExchange& aHost,TStreamPos aPos) williamr@2: {aHost.DoSeekL(*this,EStreamBeginning,aPos.Offset());} williamr@2: inline TStreamPos TStreamMark::SeekL(TStreamExchange& aHost,TStreamLocation aLocation,TInt anOffset) williamr@2: /** Moves the position of the mark in the host stream. williamr@2: williamr@2: The new position is calculated by adding the specified offset to one of: williamr@2: williamr@2: the position of the beginning of the host stream williamr@2: williamr@2: the position of the end of the host stream williamr@2: williamr@2: the position of the current mark. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aLocation The location in the host stream on which the calculation of williamr@2: the new position is based. williamr@2: @param anOffset The offset value. williamr@2: @return The new position of the mark. */ williamr@2: {return aHost.DoSeekL(*this,aLocation,anOffset);} williamr@2: inline TStreamPos TStreamMark::SeekL(TStreamExchange& aHost,TInt anOffset) williamr@2: /** Moves the position of the mark in the host stream. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param anOffset The amount by which the position of the mark is to be moved williamr@2: relative to the existing position of the mark. williamr@2: @return The new position of the mark. */ williamr@2: {return aHost.DoSeekL(*this,EStreamMark,anOffset);} williamr@2: inline TStreamPos TStreamMark::TellL(TStreamExchange& aHost) const williamr@2: /** Gets the position of the mark within the host stream. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @return The stream position. */ williamr@2: {return aHost.DoSeekL(CONST_CAST(TStreamMark&,*this),EStreamMark,0);} williamr@2: williamr@2: // Class TStreamExchange williamr@2: inline TStreamExchange::TStreamExchange() williamr@2: : iHost(NULL),iRMrk(NULL),iWMrk(NULL) williamr@2: /** Constructs an empty object. williamr@2: williamr@2: Call Share() to prepare for access to a shared stream buffer. */ williamr@2: {} williamr@2: inline TStreamExchange::TStreamExchange(MStreamBuf* aHost) williamr@2: : iHost(aHost),iRMrk(NULL),iWMrk(NULL) williamr@2: /** Constructs the object, specifying the stream buffer that will act as the shared williamr@2: host. williamr@2: williamr@2: @param aHost A pointer to a stream buffer that will act as the shared host. */ williamr@2: {} williamr@2: inline void TStreamExchange::Share(MStreamBuf* aHost) williamr@2: /** Tells the object to use the specified stream buffer that will act as the shared williamr@2: host. williamr@2: williamr@2: @param aHost A pointer to a stream buffer that will act as the shared host. */ williamr@2: {iHost=aHost;} williamr@2: inline TBool TStreamExchange::IsActive() const williamr@2: /** Tests whether this object is using a stream buffer that is acting as shared williamr@2: host. williamr@2: williamr@2: @return True, if this object is using a shared host ; false, otherwise. */ williamr@2: {return iHost!=NULL;} williamr@2: williamr@2: // Class RShareBuf williamr@2: inline void RShareBuf::Open(TStreamExchange& aHost,TInt aMode) williamr@2: /** Prepares the shared stream buffer for streaming. williamr@2: williamr@2: The function sets the read mark and/or the write mark to the beginning of williamr@2: the host stream. williamr@2: williamr@2: @param aHost The object that manages shared streaming. williamr@2: @param aMode The streaming mode. This can be read and/or write, as indicated williamr@2: by the ERead and EWrite bits. williamr@2: @see MStreamBuf::TRead williamr@2: @see MStreamBuf::TWrite williamr@2: @see KStreamBeginning */ williamr@2: {Open(aHost,KStreamBeginning,aMode);} williamr@2: williamr@2: // Class RShareWriteStream williamr@2: inline RShareWriteStream::RShareWriteStream(const MExternalizer& anExter) williamr@2: : RWriteStream(anExter) williamr@2: {} williamr@4: