epoc32/include/s32share.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 s32share.h
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // 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
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __S32SHARE_H__
       
    17 #define __S32SHARE_H__
       
    18 
       
    19 #include <s32buf.h>
       
    20 #include <s32strm.h>
       
    21 
       
    22 class TStreamExchange;
       
    23 /**
       
    24  * @publishedAll 
       
    25  * @released
       
    26  * Manages the position of a read mark or a write mark within a shared stream.
       
    27 
       
    28 A shared stream is one that shares its host with other streams. In practice, 
       
    29 the host is a stream buffer that is, itself, hosted by a file, an RFileBuf 
       
    30 object. 
       
    31 
       
    32 TStreamMark objects are owned by RShareBuf, one for reading and one for writing. 
       
    33 They re-direct read/write operations through a TStreamExchange object to the 
       
    34 RFileBuf object, which handles the actual file read and write operations.
       
    35 
       
    36 @see RFileBuf
       
    37 @see RShareBuf
       
    38 @see TStreamExchange  
       
    39 */
       
    40 class TStreamMark
       
    41 	{
       
    42 public:
       
    43 	inline TStreamMark();
       
    44 	inline TStreamMark(TStreamPos aPos);
       
    45 	inline TStreamMark& operator=(TStreamPos aPos);
       
    46 	inline operator TStreamMark*();
       
    47 	inline operator const TStreamMark*() const;
       
    48 //
       
    49 	inline TBool operator==(const TStreamMark& aMark) const;
       
    50 	inline TBool operator==(const TStreamMark* aPtr) const;
       
    51 	inline TBool operator!=(const TStreamMark& aMark) const;
       
    52 	inline TBool operator!=(const TStreamMark* aPtr) const;
       
    53 //
       
    54 	inline TBool IsEmpty() const;
       
    55 	inline void Clear();
       
    56 	inline TStreamPos Position() const;
       
    57 //
       
    58 	inline TBool IsWith(TStreamExchange& aHost) const;
       
    59 	inline TBool RelatesTo(TStreamExchange& aHost) const;
       
    60 	inline void Withdraw(TStreamExchange& aHost);
       
    61 	inline void ExtractL(TStreamExchange& aHost);
       
    62 //
       
    63 	inline TInt ReadL(TStreamExchange& aHost,TAny* aPtr,TInt aMaxLength);
       
    64 	IMPORT_C TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TRequestStatus& aStatus);
       
    65 	inline TInt ReadL(TStreamExchange& aHost,TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
    66 	inline TStreamTransfer ReadL(TStreamExchange& aHost,MStreamInput& anInput,TStreamTransfer aTransfer);
       
    67 	inline TInt ReadL(TStreamExchange& aHost,MStreamInput& anInput,TInt aMaxLength);
       
    68 	inline void ReadL(TStreamExchange& aHost,MStreamInput& anInput);
       
    69 //
       
    70 	inline void WriteL(TStreamExchange& aHost,const TAny* aPtr,TInt aLength);
       
    71 	IMPORT_C TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TRequestStatus& aStatus);
       
    72 	inline TInt WriteL(TStreamExchange& aHost,const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
    73 	inline TStreamTransfer WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TStreamTransfer aTransfer);
       
    74 	inline TInt WriteL(TStreamExchange& aHost,MStreamOutput& anOutput,TInt aMaxLength);
       
    75 	inline void WriteL(TStreamExchange& aHost,MStreamOutput& anOutput);
       
    76 //
       
    77 	inline void SeekL(TStreamExchange& aHost,TStreamPos aPos);
       
    78 	inline TStreamPos SeekL(TStreamExchange& aHost,TStreamLocation aLocation,TInt anOffset=0);
       
    79 	inline TStreamPos SeekL(TStreamExchange& aHost,TInt anOffset);
       
    80 //
       
    81 	inline TStreamPos TellL(TStreamExchange& aHost) const;
       
    82 private:
       
    83 	/** Constructs a default shared stream mark object.
       
    84 	
       
    85 	The position for the mark is uninitialised.
       
    86 	
       
    87 	An uninitialised mark means that a call to IsEmpty() returns true.
       
    88 	
       
    89 	@see IsEmpty() */
       
    90 	TStreamMark(const TStreamMark&);
       
    91 	TStreamMark& operator=(const TStreamMark&);
       
    92 private:
       
    93 	TStreamPos iPos;
       
    94 private:
       
    95 	inline TBool IsTracking(TStreamMark*const& aRef) const;
       
    96 	inline void Track(TStreamMark*const& aRef);
       
    97 private:
       
    98 	friend class TStreamExchange;
       
    99 private:
       
   100 	IMPORT_C static void __DbgChkPos(TStreamPos aPos);
       
   101 	};
       
   102 
       
   103 /**
       
   104  * @publishedAll 
       
   105  * @released
       
   106  * Manages access to a shared host buffer for shared stream buffers.
       
   107 
       
   108 The class maintains independent markers for the shared stream buffer that 
       
   109 has most recently read or written to the shared host buffer.
       
   110 
       
   111 This is the way in which multiple requests from the same shared stream buffer 
       
   112 are handled without the need for repeated seeking. The shared host buffer 
       
   113 only needs to seek when a new shared buffer needs to use it
       
   114 
       
   115 @see RShareBuf  
       
   116 */
       
   117 class TStreamExchange
       
   118 	{
       
   119 public:
       
   120 	inline TStreamExchange();
       
   121 	inline TStreamExchange(MStreamBuf* aHost);
       
   122 	inline void Share(MStreamBuf* aHost);
       
   123 	inline TBool IsActive() const;
       
   124 	IMPORT_C MStreamBuf* Host();
       
   125 	IMPORT_C MStreamBuf* HostL();
       
   126 	IMPORT_C void Release();
       
   127 //
       
   128 	IMPORT_C TInt SizeL() const;
       
   129 private:
       
   130 /** Used to identify the type of mark in a stream.
       
   131 
       
   132 The type is used by functions of this class and derived classes that perform 
       
   133 seek operations to marks within a stream.
       
   134 
       
   135 The type uses the ERead and EWrite enumeration values, as bit flags, to identify 
       
   136 the read and write marks respectively.
       
   137 
       
   138 ERead is an MStreamBuf::TRead enumerator. EWrite is an MStreamBuf::EWrite 
       
   139 enumerator.
       
   140 
       
   141 @see MStreamBuf::TRead
       
   142 @see MStreamBuf::TWrite */
       
   143 	typedef MStreamBuf::TMark TMark;
       
   144 private:
       
   145 	/** Constructs an empty object.
       
   146 	
       
   147 	Call Share() to prepare for access to a shared stream buffer. */
       
   148 	TStreamExchange(const TStreamExchange&);
       
   149 	TStreamExchange& operator=(const TStreamExchange&);
       
   150 //
       
   151 	IMPORT_C TBool RefersTo(const TStreamMark& aMark);
       
   152 	IMPORT_C void Drop(const TStreamMark& aMark);
       
   153 	IMPORT_C void GetL(TStreamMark& aMark);
       
   154 	IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark);
       
   155 	IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
       
   156 	IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark);
       
   157 	IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark);
       
   158 	IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
       
   159 	IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark);
       
   160 	IMPORT_C TStreamPos DoSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset);
       
   161 //
       
   162 	void PrepareForReadingL(TStreamMark& aMark);
       
   163 	void PrepareForWritingL(TStreamMark& aMark);
       
   164 //
       
   165 	TInt PrepareAndReadL(TAny* aPtr,TInt aMaxLength,TStreamMark& aMark);
       
   166 	TInt PrepareAndReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
       
   167 	TStreamTransfer PrepareAndReadL(MStreamInput& anInput,TStreamTransfer aTransfer,TStreamMark& aMark);
       
   168 	void PrepareAndWriteL(const TAny* aPtr,TInt aLength,TStreamMark& aMark);
       
   169 	TInt PrepareAndWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus,TStreamMark& aMark);
       
   170 	TStreamTransfer PrepareAndWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer,TStreamMark& aMark);
       
   171 	TStreamPos MarkSeekL(TStreamMark& aMark,TStreamLocation aLocation,TInt anOffset);
       
   172 //
       
   173 	inline MStreamBuf& BufL() const;
       
   174 	inline MStreamBuf& Buf() const;
       
   175 private:
       
   176 	MStreamBuf* iHost;
       
   177 	TStreamMark* iRMrk;
       
   178 	TStreamMark* iWMrk;
       
   179 private:
       
   180 	friend class TStreamMark;
       
   181 	};
       
   182 
       
   183 /**
       
   184  * @publishedAll 
       
   185  * @released
       
   186  * A shared stream buffer.
       
   187 
       
   188 This class is part of the framework used by CFileStore that allows multiple 
       
   189 stream buffers to concurrently access the single hosting file buffer, an RFileBuf 
       
   190 object.
       
   191 
       
   192 Each shared stream buffer maintains its own read and write positions.
       
   193 
       
   194 Read and write operations to RShareBuf are directed through separate TStreamMark 
       
   195 objects, one for read and one for write. The TStreamMark objects re-direct 
       
   196 read/write operations through a TStreamExchange object to the RFileBuf object, 
       
   197 which handles the actual file read and write operations. 
       
   198 
       
   199 This stream buffer can also be accessed through RShareReadStream and RShareWriteStream 
       
   200 objects.
       
   201 
       
   202 @see TStreamMark
       
   203 @see TStreamExchange
       
   204 @see RFileBuf
       
   205 @see RShareReadStream
       
   206 @see RShareWriteStream  
       
   207 */
       
   208 class RShareBuf : public MStreamBuf
       
   209 	{
       
   210 public:
       
   211 	IMPORT_C RShareBuf();
       
   212 	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos,TInt aMode=ERead|EWrite);
       
   213 	inline void Open(TStreamExchange& aHost,TInt aMode=ERead|EWrite);
       
   214 protected:
       
   215 	IMPORT_C void DoRelease();
       
   216 	IMPORT_C TInt DoReadL(TAny* aPtr,TInt aMaxLength);
       
   217 	IMPORT_C TInt DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
   218 	IMPORT_C TStreamTransfer DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer);
       
   219 	IMPORT_C void DoWriteL(const TAny* aPtr,TInt aLength);
       
   220 	IMPORT_C TInt DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus);
       
   221 	IMPORT_C TStreamTransfer DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer);
       
   222 	IMPORT_C TStreamPos DoSeekL(TMark aMark,TStreamLocation aLocation,TInt anOffset);
       
   223 private:
       
   224 	inline TStreamExchange& Host() const;
       
   225 private:
       
   226 	TStreamExchange* iHost;
       
   227 	TStreamMark iRMark;
       
   228 	TStreamMark iWMark;
       
   229 	};
       
   230 
       
   231 /**
       
   232  * @publishedAll 
       
   233  * @released
       
   234  * Supports the opening, for reading, of a stream which shares its host with other 
       
   235 streams.
       
   236 
       
   237 This is also called a shared read stream.
       
   238 
       
   239 The class uses a RShareBuf stream buffer.
       
   240 
       
   241 @see RShareBuf
       
   242 @see RFileBuf  
       
   243 */
       
   244 class RShareReadStream : public RReadStream
       
   245 	{
       
   246 public:
       
   247 	/** Constructs an empty shared read stream object.
       
   248 	
       
   249 	Call Open() to prepare the shared stream for reading.
       
   250 	
       
   251 	@see RShareReadStream::Open() */
       
   252 	RShareReadStream() {}
       
   253 	IMPORT_C RShareReadStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
       
   254 	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
       
   255 private:
       
   256 	RShareBuf iSource;
       
   257 	};
       
   258 
       
   259 /**
       
   260  * @publishedAll 
       
   261  * @released
       
   262  * Supports the opening, for writing, of a stream which shares its host with other 
       
   263 streams.
       
   264 
       
   265 This is also called a shared write stream.
       
   266 
       
   267 The class uses a RShareBuf stream buffer.
       
   268 
       
   269 @see RShareBuf
       
   270 @see RFileBuf  
       
   271 */
       
   272 class RShareWriteStream : public RWriteStream
       
   273 	{
       
   274 public:
       
   275 	/** Constructs an empty shared write stream object.
       
   276 	
       
   277 	Call Open() to prepare the shared stream for writing.
       
   278 	
       
   279 	@see RShareWriteStream::Open() */
       
   280 	RShareWriteStream() {}
       
   281 	inline RShareWriteStream(const MExternalizer<TStreamRef>& anExter);
       
   282 	IMPORT_C RShareWriteStream(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
       
   283 	IMPORT_C void Open(TStreamExchange& aHost,TStreamPos aPos=KStreamBeginning);
       
   284 private:
       
   285 	RShareBuf iSink;
       
   286 	};
       
   287 
       
   288 #include <s32share.inl>
       
   289 #endif