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@2: // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members williamr@2: // which accompanies this distribution, and is available williamr@2: // at the URL "http://www.symbianfoundation.org/legal/licencesv10.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: #ifndef __S32SHARE_H__ williamr@2: #define __S32SHARE_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: williamr@2: class TStreamExchange; williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * Manages the position of a read mark or a write mark within a shared stream. williamr@2: williamr@2: A shared stream is one that shares its host with other streams. In practice, williamr@2: the host is a stream buffer that is, itself, hosted by a file, an RFileBuf williamr@2: object. williamr@2: williamr@2: TStreamMark objects are owned by RShareBuf, one for reading and one for writing. williamr@2: They re-direct read/write operations through a TStreamExchange object to the williamr@2: RFileBuf object, which handles the actual file read and write operations. williamr@2: williamr@2: @see RFileBuf williamr@2: @see RShareBuf williamr@2: @see TStreamExchange williamr@2: */ williamr@2: class TStreamMark williamr@2: { williamr@2: public: williamr@2: inline TStreamMark(); williamr@2: inline TStreamMark(TStreamPos aPos); williamr@2: inline TStreamMark& operator=(TStreamPos aPos); williamr@2: inline operator TStreamMark*(); williamr@2: inline operator const TStreamMark*() const; williamr@2: // williamr@2: inline TBool operator==(const TStreamMark& aMark) const; williamr@2: inline TBool operator==(const TStreamMark* aPtr) const; williamr@2: inline TBool operator!=(const TStreamMark& aMark) const; williamr@2: inline TBool operator!=(const TStreamMark* aPtr) const; williamr@2: // williamr@2: inline TBool IsEmpty() const; williamr@2: inline void Clear(); williamr@2: inline TStreamPos Position() const; williamr@2: // williamr@2: inline TBool IsWith(TStreamExchange& aHost) const; williamr@2: inline TBool RelatesTo(TStreamExchange& aHost) const; williamr@2: inline void Withdraw(TStreamExchange& aHost); williamr@2: inline void ExtractL(TStreamExchange& aHost); williamr@2: // williamr@2: inline TInt ReadL(TStreamExchange& aHost,TAny* aPtr,TInt aMaxLength); williamr@2: IMPORT_C TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TRequestStatus& aStatus); williamr@2: inline TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus); williamr@2: inline TStreamTransfer ReadL(TStreamExchange& aHost,MStreamInput& anInput,TStreamTransfer aTransfer); williamr@2: inline TInt ReadL(TStreamExchange& aHost,MStreamInput& anInput,TInt aMaxLength); williamr@2: inline void ReadL(TStreamExchange& aHost,MStreamInput& anInput); williamr@2: // williamr@2: inline void WriteL(TStreamExchange& aHost,const TAny* aPtr,TInt aLength); williamr@2: IMPORT_C TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TRequestStatus& aStatus); williamr@2: inline TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus); williamr@2: inline TStreamTransfer WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TStreamTransfer aTransfer); williamr@2: inline TInt WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TInt aMaxLength); williamr@2: inline void WriteL(TStreamExchange& aHost,MStreamOutput& anOutput); williamr@2: // williamr@2: inline void SeekL(TStreamExchange& aHost,TStreamPos aPos); williamr@2: inline TStreamPos SeekL(TStreamExchange& aHost,TStreamLocation aLocation,TInt anOffset=0); williamr@2: inline TStreamPos SeekL(TStreamExchange& aHost,TInt anOffset); williamr@2: // williamr@2: inline TStreamPos TellL(TStreamExchange& aHost) const; williamr@2: private: 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: TStreamMark(const TStreamMark&); williamr@2: TStreamMark& operator=(const TStreamMark&); williamr@2: private: williamr@2: TStreamPos iPos; williamr@2: private: williamr@2: inline TBool IsTracking(TStreamMark*const& aRef) const; williamr@2: inline void Track(TStreamMark*const& aRef); williamr@2: private: williamr@2: friend class TStreamExchange; williamr@2: private: williamr@2: IMPORT_C static void __DbgChkPos(TStreamPos aPos); williamr@2: }; williamr@2: williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * Manages access to a shared host buffer for shared stream buffers. williamr@2: williamr@2: The class maintains independent markers for the shared stream buffer that williamr@2: has most recently read or written to the shared host buffer. williamr@2: williamr@2: This is the way in which multiple requests from the same shared stream buffer williamr@2: are handled without the need for repeated seeking. The shared host buffer williamr@2: only needs to seek when a new shared buffer needs to use it williamr@2: williamr@2: @see RShareBuf williamr@2: */ williamr@2: class TStreamExchange williamr@2: { williamr@2: public: williamr@2: inline TStreamExchange(); williamr@2: inline TStreamExchange(MStreamBuf* aHost); williamr@2: inline void Share(MStreamBuf* aHost); williamr@2: inline TBool IsActive() const; williamr@2: IMPORT_C MStreamBuf* Host(); williamr@2: IMPORT_C MStreamBuf* HostL(); williamr@2: IMPORT_C void Release(); williamr@2: // williamr@2: IMPORT_C TInt SizeL() const; williamr@2: private: williamr@2: /** Used to identify the type of mark in a stream. williamr@2: williamr@2: The type is used by functions of this class and derived classes that perform williamr@2: seek operations to marks within a stream. williamr@2: williamr@2: The type uses the ERead and EWrite enumeration values, as bit flags, to identify williamr@2: the read and write marks respectively. williamr@2: williamr@2: ERead is an MStreamBuf::TRead enumerator. EWrite is an MStreamBuf::EWrite williamr@2: enumerator. williamr@2: williamr@2: @see MStreamBuf::TRead williamr@2: @see MStreamBuf::TWrite */ williamr@2: typedef MStreamBuf::TMark TMark; williamr@2: private: williamr@2: /** Constructs an empty object. williamr@2: williamr@2: Call Share() to prepare for access to a shared stream buffer. */ williamr@2: TStreamExchange(const TStreamExchange&); williamr@2: TStreamExchange& operator=(const TStreamExchange&); williamr@2: // williamr@2: IMPORT_C TBool RefersTo(const TStreamMark& aMark); williamr@2: IMPORT_C void Drop(const TStreamMark& aMark); williamr@2: IMPORT_C void GetL(TStreamMark& aMark); williamr@2: IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark); williamr@2: IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark); williamr@2: IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark); williamr@2: IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark); williamr@2: IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark); williamr@2: IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark); williamr@2: IMPORT_C TStreamPos DoSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset); williamr@2: // williamr@2: void PrepareForReadingL(TStreamMark& aMark); williamr@2: void PrepareForWritingL(TStreamMark& aMark); williamr@2: // williamr@2: TInt PrepareAndReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark); williamr@2: TInt PrepareAndReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark); williamr@2: TStreamTransfer PrepareAndReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark); williamr@2: void PrepareAndWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark); williamr@2: TInt PrepareAndWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark); williamr@2: TStreamTransfer PrepareAndWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark); williamr@2: TStreamPos MarkSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset); williamr@2: // williamr@2: inline MStreamBuf& BufL() const; williamr@2: inline MStreamBuf& Buf() const; williamr@2: private: williamr@2: MStreamBuf* iHost; williamr@2: TStreamMark* iRMrk; williamr@2: TStreamMark* iWMrk; williamr@2: private: williamr@2: friend class TStreamMark; williamr@2: }; williamr@2: williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * A shared stream buffer. williamr@2: williamr@2: This class is part of the framework used by CFileStore that allows multiple williamr@2: stream buffers to concurrently access the single hosting file buffer, an RFileBuf williamr@2: object. williamr@2: williamr@2: Each shared stream buffer maintains its own read and write positions. williamr@2: williamr@2: Read and write operations to RShareBuf are directed through separate TStreamMark williamr@2: objects, one for read and one for write. The TStreamMark objects re-direct williamr@2: read/write operations through a TStreamExchange object to the RFileBuf object, williamr@2: which handles the actual file read and write operations. williamr@2: williamr@2: This stream buffer can also be accessed through RShareReadStream and RShareWriteStream williamr@2: objects. williamr@2: williamr@2: @see TStreamMark williamr@2: @see TStreamExchange williamr@2: @see RFileBuf williamr@2: @see RShareReadStream williamr@2: @see RShareWriteStream williamr@2: */ williamr@2: class RShareBuf : public MStreamBuf williamr@2: { williamr@2: public: williamr@2: IMPORT_C RShareBuf(); williamr@2: IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos,TInt aMode=ERead|EWrite); williamr@2: inline void Open(TStreamExchange& aHost,TInt aMode=ERead|EWrite); williamr@2: protected: williamr@2: IMPORT_C void DoRelease(); williamr@2: IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength); williamr@2: IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus); williamr@2: IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer); williamr@2: IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength); williamr@2: IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus); williamr@2: IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer); williamr@2: IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset); williamr@2: private: williamr@2: inline TStreamExchange& Host() const; williamr@2: private: williamr@2: TStreamExchange* iHost; williamr@2: TStreamMark iRMark; williamr@2: TStreamMark iWMark; williamr@2: }; williamr@2: williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * Supports the opening, for reading, of a stream which shares its host with other williamr@2: streams. williamr@2: williamr@2: This is also called a shared read stream. williamr@2: williamr@2: The class uses a RShareBuf stream buffer. williamr@2: williamr@2: @see RShareBuf williamr@2: @see RFileBuf williamr@2: */ williamr@2: class RShareReadStream : public RReadStream williamr@2: { williamr@2: public: williamr@2: /** Constructs an empty shared read stream object. williamr@2: williamr@2: Call Open() to prepare the shared stream for reading. williamr@2: williamr@2: @see RShareReadStream::Open() */ williamr@2: RShareReadStream() {} williamr@2: IMPORT_C RShareReadStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning); williamr@2: IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning); williamr@2: private: williamr@2: RShareBuf iSource; williamr@2: }; williamr@2: williamr@2: /** williamr@2: * @publishedAll williamr@2: * @released williamr@2: * Supports the opening, for writing, of a stream which shares its host with other williamr@2: streams. williamr@2: williamr@2: This is also called a shared write stream. williamr@2: williamr@2: The class uses a RShareBuf stream buffer. williamr@2: williamr@2: @see RShareBuf williamr@2: @see RFileBuf williamr@2: */ williamr@2: class RShareWriteStream : public RWriteStream williamr@2: { williamr@2: public: williamr@2: /** Constructs an empty shared write stream object. williamr@2: williamr@2: Call Open() to prepare the shared stream for writing. williamr@2: williamr@2: @see RShareWriteStream::Open() */ williamr@2: RShareWriteStream() {} williamr@2: inline RShareWriteStream(const MExternalizer& anExter); williamr@2: IMPORT_C RShareWriteStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning); williamr@2: IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning); williamr@2: private: williamr@2: RShareBuf iSink; williamr@2: }; williamr@2: williamr@2: #include williamr@2: #endif