os/persistentdata/persistentstorage/store/INC/S32SHARE.H
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/store/INC/S32SHARE.H	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,289 @@
     1.4 +// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __S32SHARE_H__
    1.20 +#define __S32SHARE_H__
    1.21 +
    1.22 +#include <s32buf.h>
    1.23 +#include <s32strm.h>
    1.24 +
    1.25 +class TStreamExchange;
    1.26 +/**
    1.27 + * @publishedAll 
    1.28 + * @released
    1.29 + * Manages the position of a read mark or a write mark within a shared stream.
    1.30 +
    1.31 +A shared stream is one that shares its host with other streams. In practice, 
    1.32 +the host is a stream buffer that is, itself, hosted by a file, an RFileBuf 
    1.33 +object. 
    1.34 +
    1.35 +TStreamMark objects are owned by RShareBuf, one for reading and one for writing. 
    1.36 +They re-direct read/write operations through a TStreamExchange object to the 
    1.37 +RFileBuf object, which handles the actual file read and write operations.
    1.38 +
    1.39 +@see RFileBuf
    1.40 +@see RShareBuf
    1.41 +@see TStreamExchange  
    1.42 +*/
    1.43 +class TStreamMark
    1.44 +	{
    1.45 +public:
    1.46 +	inline TStreamMark();
    1.47 +	inline TStreamMark(TStreamPos aPos);
    1.48 +	inline TStreamMark& operator=(TStreamPos aPos);
    1.49 +	inline operator TStreamMark*();
    1.50 +	inline operator const TStreamMark*() const;
    1.51 +//
    1.52 +	inline TBool operator==(const TStreamMark& aMark) const;
    1.53 +	inline TBool operator==(const TStreamMark* aPtr) const;
    1.54 +	inline TBool operator!=(const TStreamMark& aMark) const;
    1.55 +	inline TBool operator!=(const TStreamMark* aPtr) const;
    1.56 +//
    1.57 +	inline TBool IsEmpty() const;
    1.58 +	inline void Clear();
    1.59 +	inline TStreamPos Position() const;
    1.60 +//
    1.61 +	inline TBool IsWith(TStreamExchange& aHost) const;
    1.62 +	inline TBool RelatesTo(TStreamExchange& aHost) const;
    1.63 +	inline void Withdraw(TStreamExchange& aHost);
    1.64 +	inline void ExtractL(TStreamExchange& aHost);
    1.65 +//
    1.66 +	inline TInt ReadL(TStreamExchange& aHost,TAny* aPtr,TInt aMaxLength);
    1.67 +	IMPORT_C TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TRequestStatus& aStatus);
    1.68 +	inline TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
    1.69 +	inline TStreamTransfer ReadL(TStreamExchange& aHost,MStreamInput& anInput,TStreamTransfer aTransfer);
    1.70 +	inline TInt ReadL(TStreamExchange& aHost,MStreamInput& anInput,TInt aMaxLength);
    1.71 +	inline void ReadL(TStreamExchange& aHost,MStreamInput& anInput);
    1.72 +//
    1.73 +	inline void WriteL(TStreamExchange& aHost,const TAny* aPtr,TInt aLength);
    1.74 +	IMPORT_C TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TRequestStatus& aStatus);
    1.75 +	inline TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
    1.76 +	inline TStreamTransfer WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TStreamTransfer aTransfer);
    1.77 +	inline TInt WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TInt aMaxLength);
    1.78 +	inline void WriteL(TStreamExchange& aHost,MStreamOutput& anOutput);
    1.79 +//
    1.80 +	inline void SeekL(TStreamExchange& aHost,TStreamPos aPos);
    1.81 +	inline TStreamPos SeekL(TStreamExchange& aHost,TStreamLocation aLocation,TInt anOffset=0);
    1.82 +	inline TStreamPos SeekL(TStreamExchange& aHost,TInt anOffset);
    1.83 +//
    1.84 +	inline TStreamPos TellL(TStreamExchange& aHost) const;
    1.85 +private:
    1.86 +	/** Constructs a default shared stream mark object.
    1.87 +	
    1.88 +	The position for the mark is uninitialised.
    1.89 +	
    1.90 +	An uninitialised mark means that a call to IsEmpty() returns true.
    1.91 +	
    1.92 +	@see IsEmpty() */
    1.93 +	TStreamMark(const TStreamMark&);
    1.94 +	TStreamMark& operator=(const TStreamMark&);
    1.95 +private:
    1.96 +	TStreamPos iPos;
    1.97 +private:
    1.98 +	inline TBool IsTracking(TStreamMark*const& aRef) const;
    1.99 +	inline void Track(TStreamMark*const& aRef);
   1.100 +private:
   1.101 +	friend class TStreamExchange;
   1.102 +private:
   1.103 +	IMPORT_C static void __DbgChkPos(TStreamPos aPos);
   1.104 +	};
   1.105 +
   1.106 +/**
   1.107 + * @publishedAll 
   1.108 + * @released
   1.109 + * Manages access to a shared host buffer for shared stream buffers.
   1.110 +
   1.111 +The class maintains independent markers for the shared stream buffer that 
   1.112 +has most recently read or written to the shared host buffer.
   1.113 +
   1.114 +This is the way in which multiple requests from the same shared stream buffer 
   1.115 +are handled without the need for repeated seeking. The shared host buffer 
   1.116 +only needs to seek when a new shared buffer needs to use it
   1.117 +
   1.118 +@see RShareBuf  
   1.119 +*/
   1.120 +class TStreamExchange
   1.121 +	{
   1.122 +public:
   1.123 +	inline TStreamExchange();
   1.124 +	inline TStreamExchange(MStreamBuf* aHost);
   1.125 +	inline void Share(MStreamBuf* aHost);
   1.126 +	inline TBool IsActive() const;
   1.127 +	IMPORT_C MStreamBuf* Host();
   1.128 +	IMPORT_C MStreamBuf* HostL();
   1.129 +	IMPORT_C void Release();
   1.130 +//
   1.131 +	IMPORT_C TInt SizeL() const;
   1.132 +private:
   1.133 +/** Used to identify the type of mark in a stream.
   1.134 +
   1.135 +The type is used by functions of this class and derived classes that perform 
   1.136 +seek operations to marks within a stream.
   1.137 +
   1.138 +The type uses the ERead and EWrite enumeration values, as bit flags, to identify 
   1.139 +the read and write marks respectively.
   1.140 +
   1.141 +ERead is an MStreamBuf::TRead enumerator. EWrite is an MStreamBuf::EWrite 
   1.142 +enumerator.
   1.143 +
   1.144 +@see MStreamBuf::TRead
   1.145 +@see MStreamBuf::TWrite */
   1.146 +	typedef MStreamBuf::TMark TMark;
   1.147 +private:
   1.148 +	/** Constructs an empty object.
   1.149 +	
   1.150 +	Call Share() to prepare for access to a shared stream buffer. */
   1.151 +	TStreamExchange(const TStreamExchange&);
   1.152 +	TStreamExchange& operator=(const TStreamExchange&);
   1.153 +//
   1.154 +	IMPORT_C TBool RefersTo(const TStreamMark& aMark);
   1.155 +	IMPORT_C void Drop(const TStreamMark& aMark);
   1.156 +	IMPORT_C void GetL(TStreamMark& aMark);
   1.157 +	IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark);
   1.158 +	IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
   1.159 +	IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark);
   1.160 +	IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark);
   1.161 +	IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
   1.162 +	IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark);
   1.163 +	IMPORT_C TStreamPos DoSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset);
   1.164 +//
   1.165 +	void PrepareForReadingL(TStreamMark& aMark);
   1.166 +	void PrepareForWritingL(TStreamMark& aMark);
   1.167 +//
   1.168 +	TInt PrepareAndReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark);
   1.169 +	TInt PrepareAndReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
   1.170 +	TStreamTransfer PrepareAndReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark);
   1.171 +	void PrepareAndWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark);
   1.172 +	TInt PrepareAndWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
   1.173 +	TStreamTransfer PrepareAndWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark);
   1.174 +	TStreamPos MarkSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset);
   1.175 +//
   1.176 +	inline MStreamBuf& BufL() const;
   1.177 +	inline MStreamBuf& Buf() const;
   1.178 +private:
   1.179 +	MStreamBuf* iHost;
   1.180 +	TStreamMark* iRMrk;
   1.181 +	TStreamMark* iWMrk;
   1.182 +private:
   1.183 +	friend class TStreamMark;
   1.184 +	};
   1.185 +
   1.186 +/**
   1.187 + * @publishedAll 
   1.188 + * @released
   1.189 + * A shared stream buffer.
   1.190 +
   1.191 +This class is part of the framework used by CFileStore that allows multiple 
   1.192 +stream buffers to concurrently access the single hosting file buffer, an RFileBuf 
   1.193 +object.
   1.194 +
   1.195 +Each shared stream buffer maintains its own read and write positions.
   1.196 +
   1.197 +Read and write operations to RShareBuf are directed through separate TStreamMark 
   1.198 +objects, one for read and one for write. The TStreamMark objects re-direct 
   1.199 +read/write operations through a TStreamExchange object to the RFileBuf object, 
   1.200 +which handles the actual file read and write operations. 
   1.201 +
   1.202 +This stream buffer can also be accessed through RShareReadStream and RShareWriteStream 
   1.203 +objects.
   1.204 +
   1.205 +@see TStreamMark
   1.206 +@see TStreamExchange
   1.207 +@see RFileBuf
   1.208 +@see RShareReadStream
   1.209 +@see RShareWriteStream  
   1.210 +*/
   1.211 +class RShareBuf : public MStreamBuf
   1.212 +	{
   1.213 +public:
   1.214 +	IMPORT_C RShareBuf();
   1.215 +	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos,TInt aMode=ERead|EWrite);
   1.216 +	inline void Open(TStreamExchange& aHost,TInt aMode=ERead|EWrite);
   1.217 +protected:
   1.218 +	IMPORT_C void DoRelease();
   1.219 +	IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength);
   1.220 +	IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
   1.221 +	IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer);
   1.222 +	IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength);
   1.223 +	IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
   1.224 +	IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer);
   1.225 +	IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
   1.226 +private:
   1.227 +	inline TStreamExchange& Host() const;
   1.228 +private:
   1.229 +	TStreamExchange* iHost;
   1.230 +	TStreamMark iRMark;
   1.231 +	TStreamMark iWMark;
   1.232 +	};
   1.233 +
   1.234 +/**
   1.235 + * @publishedAll 
   1.236 + * @released
   1.237 + * Supports the opening, for reading, of a stream which shares its host with other 
   1.238 +streams.
   1.239 +
   1.240 +This is also called a shared read stream.
   1.241 +
   1.242 +The class uses a RShareBuf stream buffer.
   1.243 +
   1.244 +@see RShareBuf
   1.245 +@see RFileBuf  
   1.246 +*/
   1.247 +class RShareReadStream : public RReadStream
   1.248 +	{
   1.249 +public:
   1.250 +	/** Constructs an empty shared read stream object.
   1.251 +	
   1.252 +	Call Open() to prepare the shared stream for reading.
   1.253 +	
   1.254 +	@see RShareReadStream::Open() */
   1.255 +	RShareReadStream() {}
   1.256 +	IMPORT_C RShareReadStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
   1.257 +	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
   1.258 +private:
   1.259 +	RShareBuf iSource;
   1.260 +	};
   1.261 +
   1.262 +/**
   1.263 + * @publishedAll 
   1.264 + * @released
   1.265 + * Supports the opening, for writing, of a stream which shares its host with other 
   1.266 +streams.
   1.267 +
   1.268 +This is also called a shared write stream.
   1.269 +
   1.270 +The class uses a RShareBuf stream buffer.
   1.271 +
   1.272 +@see RShareBuf
   1.273 +@see RFileBuf  
   1.274 +*/
   1.275 +class RShareWriteStream : public RWriteStream
   1.276 +	{
   1.277 +public:
   1.278 +	/** Constructs an empty shared write stream object.
   1.279 +	
   1.280 +	Call Open() to prepare the shared stream for writing.
   1.281 +	
   1.282 +	@see RShareWriteStream::Open() */
   1.283 +	RShareWriteStream() {}
   1.284 +	inline RShareWriteStream(const MExternalizer<TStreamRef>& anExter);
   1.285 +	IMPORT_C RShareWriteStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
   1.286 +	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
   1.287 +private:
   1.288 +	RShareBuf iSink;
   1.289 +	};
   1.290 +
   1.291 +#include <s32share.inl>
   1.292 +#endif