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