persistentstorage/store/USTRM/US_BUF.CPP
changeset 51 7d4490026038
parent 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
40:b8bdbc8f59c7 51:7d4490026038
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 1998-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 #include "US_STD.H"
    16 #include "US_STD.H"
    17 
    17 
    18 EXPORT_C TInt MStreamBuf::Synch()
       
    19 
       
    20 
       
    21 /** Synchronises the stream buffer with the stream, returning any error.
    18 /** Synchronises the stream buffer with the stream, returning any error.
    22 
    19 
    23 In effect, this ensures that buffered data is delivered to the stream.
    20 In effect, this ensures that buffered data is delivered to the stream.
    24 
    21 
    25 This function calls SynchL() inside a TRAPD harness and returns the leave 
    22 This function calls SynchL() inside a TRAPD harness and returns the leave 
    27 
    24 
    28 @return KErrNone, if successful; otherwise one of the other system wide error 
    25 @return KErrNone, if successful; otherwise one of the other system wide error 
    29 codes.
    26 codes.
    30 @see MStreamBuf::SynchL()
    27 @see MStreamBuf::SynchL()
    31 @see MStreamBuf::DoSynchL() */
    28 @see MStreamBuf::DoSynchL() */
       
    29 EXPORT_C TInt MStreamBuf::Synch()
    32 	{
    30 	{
    33 	TRAPD(r,SynchL());
    31 	TRAPD(r,SynchL());
    34 	return r;
    32 	return r;
    35 	}
    33 	}
    36 
    34 
    37 EXPORT_C void MStreamBuf::Close()
       
    38 /** Closes the stream buffer.
    35 /** Closes the stream buffer.
    39 
    36 
    40 This function attempts to synchronise buffered data with the stream before 
    37 This function attempts to synchronise buffered data with the stream before 
    41 freeing any resources. All errors are ignored.
    38 freeing any resources. All errors are ignored.
    42 
    39 
    43 @see MStreamBuf::Synch()
    40 @see MStreamBuf::Synch()
    44 @see MStreamBuf::Release() */
    41 @see MStreamBuf::Release() */
       
    42 EXPORT_C void MStreamBuf::Close()
    45 	{
    43 	{
    46 	Synch();
    44 	Synch();
    47 	Release();
    45 	Release();
    48 	}
    46 	}
    49 
    47 
       
    48 /** Puts a cleanup item for this object onto the cleanup stack.
       
    49 
       
    50 This allows allocated resources to be cleaned up if a subsequent leave occurs. */
    50 EXPORT_C void MStreamBuf::PushL()
    51 EXPORT_C void MStreamBuf::PushL()
    51 /** Puts a cleanup item for this object onto the cleanup stack.
       
    52 
       
    53 This allows allocated resources to be cleaned up if a subsequent leave occurs. */
       
    54 	{
    52 	{
    55 	CleanupReleasePushL(*this);
    53 	CleanupReleasePushL(*this);
    56 	}
    54 	}
    57 
    55 
    58 EXPORT_C TInt MStreamBuf::Read(TDes8& aDes,TRequestStatus& aStatus)
       
    59 /** Reads data, asynchronously, from the stream buffer into the specified descriptor; 
    56 /** Reads data, asynchronously, from the stream buffer into the specified descriptor; 
    60 request completion is guaranteed, even if request initiation fails.
    57 request completion is guaranteed, even if request initiation fails.
    61 
    58 
    62 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
    59 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
    63 to implement this behaviour. The maximum number of bytes to be read is the 
    60 to implement this behaviour. The maximum number of bytes to be read is the 
    68 asynchronous request.
    65 asynchronous request.
    69 @return The maximum number of bytes to be read, as used in this request. This 
    66 @return The maximum number of bytes to be read, as used in this request. This 
    70 value can be different to the maximum length of the descriptor; this is dependent 
    67 value can be different to the maximum length of the descriptor; this is dependent 
    71 on the implementation.
    68 on the implementation.
    72 @see MStreamBuf::DoReadL() */
    69 @see MStreamBuf::DoReadL() */
       
    70 EXPORT_C TInt MStreamBuf::Read(TDes8& aDes,TRequestStatus& aStatus)
    73 	{
    71 	{
    74 	return Read(aDes,aDes.MaxLength(),aStatus);
    72 	return Read(aDes,aDes.MaxLength(),aStatus);
    75 	}
    73 	}
    76 
    74 
    77 EXPORT_C TInt MStreamBuf::Read(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
       
    78 /** Reads data, asynchronously, from the stream buffer into the specified descriptor; 
    75 /** Reads data, asynchronously, from the stream buffer into the specified descriptor; 
    79 request completion is guaranteed, even if request initiation fails.
    76 request completion is guaranteed, even if request initiation fails.
    80 
    77 
    81 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
    78 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
    82 to implement this behaviour.
    79 to implement this behaviour.
    87 asynchronous request.
    84 asynchronous request.
    88 @return The maximum number of bytes to be read, as used in this request. This 
    85 @return The maximum number of bytes to be read, as used in this request. This 
    89 can be different to the value supplied in aMaxLength; this is dependent on 
    86 can be different to the value supplied in aMaxLength; this is dependent on 
    90 the implementation.
    87 the implementation.
    91 @see MStreamBuf::DoReadL() */
    88 @see MStreamBuf::DoReadL() */
       
    89 EXPORT_C TInt MStreamBuf::Read(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
    92 	{
    90 	{
    93 	TInt len=0;
    91 	TInt len=0;
    94 	TRAPD(r,len=DoReadL(aDes,aMaxLength,aStatus));
    92 	TRAPD(r,len=DoReadL(aDes,aMaxLength,aStatus));
    95 	if (r!=KErrNone)
    93 	if (r!=KErrNone)
    96 		{
    94 		{
    98 		User::RequestComplete(stat,r);
    96 		User::RequestComplete(stat,r);
    99 		}
    97 		}
   100 	return len;
    98 	return len;
   101 	}
    99 	}
   102 
   100 
   103 EXPORT_C TInt MStreamBuf::ReadL(TDes8& aDes,TRequestStatus& aStatus)
       
   104 /** Reads data, asynchronously, from the stream buffer into the specified descriptor.
   101 /** Reads data, asynchronously, from the stream buffer into the specified descriptor.
   105 
   102 
   106 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
   103 The function calls the virtual function DoReadL(TDes8&,TInt,TRequestStatus&) 
   107 to implement this behaviour. The maximum number of bytes to be read is the 
   104 to implement this behaviour. The maximum number of bytes to be read is the 
   108 maximum length of the descriptor.
   105 maximum length of the descriptor.
   114 asynchronous request.
   111 asynchronous request.
   115 @return The maximum number of bytes to be read, as used in this request. This 
   112 @return The maximum number of bytes to be read, as used in this request. This 
   116 value can be different to the maximum length of the descriptor; this is dependent 
   113 value can be different to the maximum length of the descriptor; this is dependent 
   117 on the implementation.
   114 on the implementation.
   118 @see MStreamBuf::DoReadL() */
   115 @see MStreamBuf::DoReadL() */
       
   116 EXPORT_C TInt MStreamBuf::ReadL(TDes8& aDes,TRequestStatus& aStatus)
   119 	{
   117 	{
   120 	return DoReadL(aDes,aDes.MaxLength(),aStatus);
   118 	return DoReadL(aDes,aDes.MaxLength(),aStatus);
   121 	}
   119 	}
   122 
   120 
   123 EXPORT_C TInt MStreamBuf::ReadL(MStreamInput& anInput,TInt aMaxLength)
       
   124 /** Reads data from the stream buffer into the specified data sink.
   121 /** Reads data from the stream buffer into the specified data sink.
   125 
   122 
   126 The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) 
   123 The function uses the virtual function DoReadL(MStreamInput&,TStreamTransfer) 
   127 to implement this behaviour.
   124 to implement this behaviour.
   128 
   125 
   129 @param anInput The data sink which is the target for the read operation.
   126 @param anInput The data sink which is the target for the read operation.
   130 @param aMaxLength The maximum amount of data available to be read.
   127 @param aMaxLength The maximum amount of data available to be read.
   131 @return The amount of data that was not consumed. */
   128 @return The amount of data that was not consumed. */
       
   129 EXPORT_C TInt MStreamBuf::ReadL(MStreamInput& anInput,TInt aMaxLength)
   132 	{
   130 	{
   133 	return aMaxLength-DoReadL(anInput,TStreamTransfer(aMaxLength)).Left();
   131 	return aMaxLength-DoReadL(anInput,TStreamTransfer(aMaxLength)).Left();
   134 	}
   132 	}
   135 
   133 
   136 EXPORT_C TInt MStreamBuf::Write(const TDesC8& aDes,TRequestStatus& aStatus)
       
   137 /** Writes data, asynchronously, from the specified descriptor into the stream buffer; 
   134 /** Writes data, asynchronously, from the specified descriptor into the stream buffer; 
   138 request completion is guaranteed, even if request initiation fails.
   135 request completion is guaranteed, even if request initiation fails.
   139 
   136 
   140 The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) 
   137 The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) 
   141 to implement this behaviour. The maximum number of bytes to be written is 
   138 to implement this behaviour. The maximum number of bytes to be written is 
   147 asynchronous request.
   144 asynchronous request.
   148 @return The maximum number of bytes to be written, as used in this request. 
   145 @return The maximum number of bytes to be written, as used in this request. 
   149 This can be different to the value supplied in aMaxLength; this is dependent 
   146 This can be different to the value supplied in aMaxLength; this is dependent 
   150 on the implementation.
   147 on the implementation.
   151 @see MStreamBuf::DoWriteL() */
   148 @see MStreamBuf::DoWriteL() */
       
   149 EXPORT_C TInt MStreamBuf::Write(const TDesC8& aDes,TRequestStatus& aStatus)
   152 	{
   150 	{
   153 	return Write(aDes,aDes.Length(),aStatus);
   151 	return Write(aDes,aDes.Length(),aStatus);
   154 	}
   152 	}
   155 
   153 
       
   154 //
       
   155 // Write up to aMaxLength bytes with guaranteed completion.
       
   156 //
   156 EXPORT_C TInt MStreamBuf::Write(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   157 EXPORT_C TInt MStreamBuf::Write(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   157 //
       
   158 // Write up to aMaxLength bytes with guaranteed completion.
       
   159 //
       
   160 	{
   158 	{
   161 	TInt len=0;
   159 	TInt len=0;
   162 	TRAPD(r,len=DoWriteL(aDes,aMaxLength,aStatus));
   160 	TRAPD(r,len=DoWriteL(aDes,aMaxLength,aStatus));
   163 	if (r!=KErrNone)
   161 	if (r!=KErrNone)
   164 		{
   162 		{
   166 		User::RequestComplete(stat,r);
   164 		User::RequestComplete(stat,r);
   167 		}
   165 		}
   168 	return len;
   166 	return len;
   169 	}
   167 	}
   170 
   168 
   171 EXPORT_C TInt MStreamBuf::WriteL(const TDesC8& aDes,TRequestStatus& aStatus)
       
   172 /** Writes data, asynchronously, from the specified descriptor into the stream buffer.
   169 /** Writes data, asynchronously, from the specified descriptor into the stream buffer.
   173 
   170 
   174 The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) 
   171 The function calls the virtual function DoWriteL(const TDesC8&,TInt,TRequestStatus&) 
   175 to implement this behaviour. The maximum number of bytes to be written is 
   172 to implement this behaviour. The maximum number of bytes to be written is 
   176 the value of the maximum length of the descriptor.
   173 the value of the maximum length of the descriptor.
   183 asynchronous request.
   180 asynchronous request.
   184 @return The maximum number of bytes to be written, as used in this request. 
   181 @return The maximum number of bytes to be written, as used in this request. 
   185 This can be different to the maximum length of the descriptor; this is dependent 
   182 This can be different to the maximum length of the descriptor; this is dependent 
   186 on the implementation.
   183 on the implementation.
   187 @see MStreamBuf::DoWriteL() */
   184 @see MStreamBuf::DoWriteL() */
       
   185 EXPORT_C TInt MStreamBuf::WriteL(const TDesC8& aDes,TRequestStatus& aStatus)
   188 	{
   186 	{
   189 	return DoWriteL(aDes,aDes.Length(),aStatus);
   187 	return DoWriteL(aDes,aDes.Length(),aStatus);
   190 	}
   188 	}
   191 
   189 
   192 EXPORT_C TInt MStreamBuf::WriteL(MStreamOutput& anOutput,TInt aMaxLength)
       
   193 /** Writes data into the stream buffer from the specified data source.
   190 /** Writes data into the stream buffer from the specified data source.
   194 
   191 
   195 The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) 
   192 The function calls the virtual function DoWriteL(MStreamOutput&,TStreamTransfer) 
   196 to implement this behaviour.
   193 to implement this behaviour.
   197 
   194 
   198 @param anOutput The data source for the write operation.
   195 @param anOutput The data source for the write operation.
   199 @param aMaxLength The maximum amount of data available to be written.
   196 @param aMaxLength The maximum amount of data available to be written.
   200 @return The amount of data that was not consumed. */
   197 @return The amount of data that was not consumed. */
       
   198 EXPORT_C TInt MStreamBuf::WriteL(MStreamOutput& anOutput,TInt aMaxLength)
   201 	{
   199 	{
   202 	return aMaxLength-DoWriteL(anOutput,TStreamTransfer(aMaxLength)).Left();
   200 	return aMaxLength-DoWriteL(anOutput,TStreamTransfer(aMaxLength)).Left();
   203 	}
   201 	}
   204 
   202 
   205 EXPORT_C void MStreamBuf::DoRelease()
       
   206 /** Frees resources before abandoning the stream buffer.
   203 /** Frees resources before abandoning the stream buffer.
   207 
   204 
   208 It is called by Release().
   205 It is called by Release().
   209 
   206 
   210 This implementation is empty, but classes derived from MStreamBuf can provide 
   207 This implementation is empty, but classes derived from MStreamBuf can provide 
   211 their own implementation, if necessary.
   208 their own implementation, if necessary.
   212 
   209 
   213 @see MStreamBuf::Release() */
   210 @see MStreamBuf::Release() */
   214 	{}
   211 EXPORT_C void MStreamBuf::DoRelease()
   215 
   212 	{	
   216 EXPORT_C void MStreamBuf::DoSynchL()
   213 	}
       
   214 
   217 /** Synchronises the stream buffer with the stream, leaving if any error occurs.
   215 /** Synchronises the stream buffer with the stream, leaving if any error occurs.
   218 
   216 
   219 In effect, this ensures that buffered data is delivered to the stream.
   217 In effect, this ensures that buffered data is delivered to the stream.
   220 
   218 
   221 It is called by SynchL().
   219 It is called by SynchL().
   222 
   220 
   223 This implementation is empty, but classes derived from MStreamBuf can provide 
   221 This implementation is empty, but classes derived from MStreamBuf can provide 
   224 their own implementation, if necessary.
   222 their own implementation, if necessary.
   225 
   223 
   226 @see MStreamBuf::SynchL() */
   224 @see MStreamBuf::SynchL() */
   227 	{}
   225 EXPORT_C void MStreamBuf::DoSynchL()
   228 
   226 	{
       
   227 	}
       
   228 
       
   229 #pragma BullseyeCoverage off
       
   230 
       
   231 //
       
   232 // Cannot read from this stream buffer.
       
   233 //
   229 EXPORT_C TInt MStreamBuf::DoReadL(TAny*,TInt)
   234 EXPORT_C TInt MStreamBuf::DoReadL(TAny*,TInt)
   230 //
       
   231 // Cannot read from this stream buffer.
       
   232 //
       
   233 	{
   235 	{
   234 	Panic(EStreamCannotRead);
   236 	Panic(EStreamCannotRead);
   235 	return TInt();
   237 	return TInt();
   236 	}
   238 	}
   237 
   239 
   238 EXPORT_C TInt MStreamBuf::DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   240 //
       
   241 // Cannot write to this stream buffer.
       
   242 //
       
   243 EXPORT_C void MStreamBuf::DoWriteL(const TAny*,TInt)
       
   244 	{
       
   245 	Panic(EStreamCannotWrite);
       
   246 	}
       
   247 
       
   248 //
       
   249 // This stream buffer does not support seeking.
       
   250 //
       
   251 EXPORT_C TStreamPos MStreamBuf::DoSeekL(TMark,TStreamLocation,TInt)
       
   252 	{
       
   253 	Panic(EStreamCannotSeek);
       
   254 	TStreamPos streamPos(-1);
       
   255 	return streamPos;
       
   256 	}
       
   257 
       
   258 #pragma BullseyeCoverage on
       
   259 
   239 /** Reads data from the stream buffer into the specified descriptor.
   260 /** Reads data from the stream buffer into the specified descriptor.
   240 
   261 
   241 This function is called by ReadL(TDes8&,TInt,TRequestStatus&).
   262 This function is called by ReadL(TDes8&,TInt,TRequestStatus&).
   242 
   263 
   243 This implementation deals with the request synchronously, and completes the 
   264 This implementation deals with the request synchronously, and completes the 
   256 asynchronous request.
   277 asynchronous request.
   257 @return The maximum number of bytes to be read, as used in this request. This 
   278 @return The maximum number of bytes to be read, as used in this request. This 
   258 implementation uses, and returns, the value supplied in aMaxLength. Other 
   279 implementation uses, and returns, the value supplied in aMaxLength. Other 
   259 implementations may choose to use a different value.
   280 implementations may choose to use a different value.
   260 @see MStreamBuf::ReadL() */
   281 @see MStreamBuf::ReadL() */
       
   282 EXPORT_C TInt MStreamBuf::DoReadL(TDes8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   261 	{
   283 	{
   262 	__ASSERT_DEBUG(aMaxLength<=aDes.MaxLength(),Panic(EStreamReadBeyondEnd));
   284 	__ASSERT_DEBUG(aMaxLength<=aDes.MaxLength(),Panic(EStreamReadBeyondEnd));
   263 	aDes.SetLength(DoReadL((TUint8*)aDes.Ptr(),aMaxLength));
   285 	aDes.SetLength(DoReadL((TUint8*)aDes.Ptr(),aMaxLength));
   264 	TRequestStatus* stat=&aStatus;
   286 	TRequestStatus* stat=&aStatus;
   265 	User::RequestComplete(stat,KErrNone);
   287 	User::RequestComplete(stat,KErrNone);
   266 	return aMaxLength;
   288 	return aMaxLength;
   267 	}
   289 	}
   268 
   290 
   269 EXPORT_C TStreamTransfer MStreamBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer)
       
   270 /** Reads data from the stream into the specified data sink.
   291 /** Reads data from the stream into the specified data sink.
   271 
   292 
   272 It is called by ReadL(MStreamInput&,TStreamTransfer).
   293 It is called by ReadL(MStreamInput&,TStreamTransfer).
   273 
   294 
   274 This implementation calls the sink's ReadFromL() function, which performs 
   295 This implementation calls the sink's ReadFromL() function, which performs 
   280 @param anInput The target data sink.
   301 @param anInput The target data sink.
   281 @param aTransfer A stream transfer object defining the amount of data available 
   302 @param aTransfer A stream transfer object defining the amount of data available 
   282 to be read.
   303 to be read.
   283 @return A stream transfer object defining the amount of data that was not consumed.
   304 @return A stream transfer object defining the amount of data that was not consumed.
   284 @see MStreamInput::ReadFromL() */
   305 @see MStreamInput::ReadFromL() */
       
   306 EXPORT_C TStreamTransfer MStreamBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer)
   285 	{
   307 	{
   286 	return anInput.ReadFromL(*this,aTransfer);
   308 	return anInput.ReadFromL(*this,aTransfer);
   287 	}
   309 	}
   288 
   310 
   289 EXPORT_C void MStreamBuf::DoWriteL(const TAny*,TInt)
       
   290 //
       
   291 // Cannot write to this stream buffer.
       
   292 //
       
   293 	{
       
   294 	Panic(EStreamCannotWrite);
       
   295 	}
       
   296 
       
   297 EXPORT_C TInt MStreamBuf::DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
       
   298 /** Writes data from the specified descriptor into this stream buffer.
   311 /** Writes data from the specified descriptor into this stream buffer.
   299 
   312 
   300 This function is called by WriteL(const TDesC8&,TInt,TRequestStatus&).
   313 This function is called by WriteL(const TDesC8&,TInt,TRequestStatus&).
   301 
   314 
   302 This implementation deals with the request synchronously, and completes the 
   315 This implementation deals with the request synchronously, and completes the 
   314 asynchronous request.
   327 asynchronous request.
   315 @return The maximum number of bytes to be written, as used in this request. 
   328 @return The maximum number of bytes to be written, as used in this request. 
   316 This implementation uses, and returns, the value supplied in aMaxLength. Other 
   329 This implementation uses, and returns, the value supplied in aMaxLength. Other 
   317 implementations may choose to use a different value.
   330 implementations may choose to use a different value.
   318 @see MStreamBuf::WriteL() */
   331 @see MStreamBuf::WriteL() */
       
   332 EXPORT_C TInt MStreamBuf::DoWriteL(const TDesC8& aDes,TInt aMaxLength,TRequestStatus& aStatus)
   319 	{
   333 	{
   320 	__ASSERT_DEBUG(aMaxLength<=aDes.Length(),Panic(EStreamWriteBeyondEnd));
   334 	__ASSERT_DEBUG(aMaxLength<=aDes.Length(),Panic(EStreamWriteBeyondEnd));
   321 	DoWriteL(aDes.Ptr(),aMaxLength);
   335 	DoWriteL(aDes.Ptr(),aMaxLength);
   322 	TRequestStatus* stat=&aStatus;
   336 	TRequestStatus* stat=&aStatus;
   323 	User::RequestComplete(stat,KErrNone);
   337 	User::RequestComplete(stat,KErrNone);
   324 	return aMaxLength;
   338 	return aMaxLength;
   325 	}
   339 	}
   326 
   340 
       
   341 //
       
   342 // Default implementation turning around to anOutput.
       
   343 //
   327 EXPORT_C TStreamTransfer MStreamBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer)
   344 EXPORT_C TStreamTransfer MStreamBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer)
   328 //
       
   329 // Default implementation turning around to anOutput.
       
   330 //
       
   331 	{
   345 	{
   332 	return anOutput.WriteToL(*this,aTransfer);
   346 	return anOutput.WriteToL(*this,aTransfer);
   333 	}
   347 	}
   334 
   348 
   335 EXPORT_C TStreamPos MStreamBuf::DoSeekL(TMark,TStreamLocation,TInt)
   349 /** Sets the pointers that mark out the read and write areas within the intermediate 
   336 //
   350 buffer to null. */
   337 // This stream buffer does not support seeking.
       
   338 //
       
   339 	{
       
   340 	Panic(EStreamCannotSeek);
       
   341 	TStreamPos streamPos(-1);
       
   342 	return streamPos;
       
   343 	}
       
   344 
       
   345 EXPORT_C TStreamBuf::TStreamBuf()
   351 EXPORT_C TStreamBuf::TStreamBuf()
   346 	: iRPtr(NULL),iREnd(NULL),iWPtr(NULL),iWEnd(NULL)
   352 	: iRPtr(NULL),iREnd(NULL),iWPtr(NULL),iWEnd(NULL)
   347 /** Sets the pointers that mark out the read and write areas within the intermediate 
   353 	{
   348 buffer to null. */
   354 	}
   349 	{}
   355 
   350 
       
   351 EXPORT_C void TStreamBuf::SetBuf(TArea anArea,TUint8* aPtr,TUint8* anEnd)
       
   352 /** Sets the start and end points of the read and/or the write area within the intermediate 
   356 /** Sets the start and end points of the read and/or the write area within the intermediate 
   353 buffer.
   357 buffer.
   354 
   358 
   355 A start point is always within an area; an end point is always the first byte 
   359 A start point is always within an area; an end point is always the first byte 
   356 beyond the end of an area.
   360 beyond the end of an area.
   361 otherwise the function raises a STORE-Stream 17 panic.
   365 otherwise the function raises a STORE-Stream 17 panic.
   362 @param aPtr The start point.
   366 @param aPtr The start point.
   363 @param anEnd The end point.
   367 @param anEnd The end point.
   364 @see MStreamBuf::TRead
   368 @see MStreamBuf::TRead
   365 @see MStreamBuf::TWrite */
   369 @see MStreamBuf::TWrite */
       
   370 EXPORT_C void TStreamBuf::SetBuf(TArea anArea,TUint8* aPtr,TUint8* anEnd)
   366 	{
   371 	{
   367 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   372 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   368 	if (anArea&ERead)
   373 	if (anArea&ERead)
   369 		SetBuf(ERead,aPtr,anEnd);
   374 		SetBuf(ERead,aPtr,anEnd);
   370 	if (anArea&EWrite)
   375 	if (anArea&EWrite)
   371 		SetBuf(EWrite,aPtr,anEnd);
   376 		SetBuf(EWrite,aPtr,anEnd);
   372 	}
   377 	}
   373 
   378 
   374 EXPORT_C void TStreamBuf::SetPtr(TArea anArea,TUint8* aPtr)
       
   375 /** Sets the start point of the read and/or the write area within the intermediate 
   379 /** Sets the start point of the read and/or the write area within the intermediate 
   376 buffer.
   380 buffer.
   377 
   381 
   378 A start point is always within an area.
   382 A start point is always within an area.
   379 
   383 
   382 by the ERead and EWrite bits. Only these bits can be set, otherwise the function 
   386 by the ERead and EWrite bits. Only these bits can be set, otherwise the function 
   383 raises a STORE-Stream 17 panic.
   387 raises a STORE-Stream 17 panic.
   384 @param aPtr The start point.
   388 @param aPtr The start point.
   385 @see MStreamBuf::TRead
   389 @see MStreamBuf::TRead
   386 @see MStreamBuf::TWrite */
   390 @see MStreamBuf::TWrite */
       
   391 EXPORT_C void TStreamBuf::SetPtr(TArea anArea,TUint8* aPtr)
   387 	{
   392 	{
   388 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   393 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   389 	if (anArea&ERead)
   394 	if (anArea&ERead)
   390 		SetPtr(ERead,aPtr);
   395 		SetPtr(ERead,aPtr);
   391 	if (anArea&EWrite)
   396 	if (anArea&EWrite)
   392 		SetPtr(EWrite,aPtr);
   397 		SetPtr(EWrite,aPtr);
   393 	}
   398 	}
   394 
   399 
       
   400 //
       
   401 // Set the end pointer for the buffer area(s) indicated by anArea.
       
   402 //
   395 EXPORT_C void TStreamBuf::SetEnd(TArea anArea,TUint8* anEnd)
   403 EXPORT_C void TStreamBuf::SetEnd(TArea anArea,TUint8* anEnd)
   396 //
       
   397 // Set the end pointer for the buffer area(s) indicated by anArea.
       
   398 //
       
   399 	{
   404 	{
   400 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   405 	__ASSERT_ALWAYS(!(anArea&~(ERead|EWrite)),Panic(EStreamAreaInvalid));
   401 	if (anArea&ERead)
   406 	if (anArea&ERead)
   402 		SetEnd(ERead,anEnd);
   407 		SetEnd(ERead,anEnd);
   403 	if (anArea&EWrite)
   408 	if (anArea&EWrite)
   404 		SetEnd(EWrite,anEnd);
   409 		SetEnd(EWrite,anEnd);
   405 	}
   410 	}
   406 
   411 
   407 EXPORT_C TUint8* TStreamBuf::Ptr(TArea anArea) const
       
   408 /** Gets the current start point of the read or write area within the intermediate 
   412 /** Gets the current start point of the read or write area within the intermediate 
   409 buffer.
   413 buffer.
   410 
   414 
   411 @param anArea The area within the intermediate buffer for which the start 
   415 @param anArea The area within the intermediate buffer for which the start 
   412 point is to be fetched. This can be either the read area or the write area, 
   416 point is to be fetched. This can be either the read area or the write area, 
   413 as indicated by the ERead and EWrite bits. Only one of these can be set, otherwise 
   417 as indicated by the ERead and EWrite bits. Only one of these can be set, otherwise 
   414 the function raises a STORE-Stream 17 panic.
   418 the function raises a STORE-Stream 17 panic.
   415 @return The start point.
   419 @return The start point.
   416 @see MStreamBuf::TRead
   420 @see MStreamBuf::TRead
   417 @see MStreamBuf::TWrite */
   421 @see MStreamBuf::TWrite */
       
   422 EXPORT_C TUint8* TStreamBuf::Ptr(TArea anArea) const
   418 	{
   423 	{
   419 	if (anArea==ERead)
   424 	if (anArea==ERead)
   420 		return Ptr(ERead);
   425 		return Ptr(ERead);
   421 //
   426 //
   422 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   427 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   423 	return Ptr(EWrite);
   428 	return Ptr(EWrite);
   424 	}
   429 	}
   425 
   430 
   426 EXPORT_C TUint8* TStreamBuf::End(TArea anArea) const
       
   427 /** Gets the current end point of the read or write area within the intermediate 
   431 /** Gets the current end point of the read or write area within the intermediate 
   428 buffer.
   432 buffer.
   429 
   433 
   430 An end point is always the first byte beyond the end of an area.
   434 An end point is always the first byte beyond the end of an area.
   431 
   435 
   432 @param anArea The area within the intermediate buffer for which the end point 
   436 @param anArea The area within the intermediate buffer for which the end point 
   433 is to be fetched. This can be either the read area or the write area, as indicated 
   437 is to be fetched. This can be either the read area or the write area, as indicated 
   434 by the ERead and EWrite bits. Only one of these can be set, otherwise the 
   438 by the ERead and EWrite bits. Only one of these can be set, otherwise the 
   435 function raises a STORE-Stream 17 panic.
   439 function raises a STORE-Stream 17 panic.
   436 @return The end point. */
   440 @return The end point. */
       
   441 EXPORT_C TUint8* TStreamBuf::End(TArea anArea) const
   437 	{
   442 	{
   438 	if (anArea==ERead)
   443 	if (anArea==ERead)
   439 		return End(ERead);
   444 		return End(ERead);
   440 //
   445 //
   441 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   446 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   442 	return End(EWrite);
   447 	return End(EWrite);
   443 	}
   448 	}
   444 
   449 
   445 EXPORT_C TInt TStreamBuf::Avail(TArea anArea) const
       
   446 /** Gets the number of bytes available in the read or write area within the intermediate 
   450 /** Gets the number of bytes available in the read or write area within the intermediate 
   447 buffer.
   451 buffer.
   448 
   452 
   449 @param anArea The area within the intermediate buffer for which the number 
   453 @param anArea The area within the intermediate buffer for which the number 
   450 of available bytes is to be fetched. This can be either the read area or the 
   454 of available bytes is to be fetched. This can be either the read area or the 
   451 write area, as indicated by the ERead and EWrite bits. Only one of these can 
   455 write area, as indicated by the ERead and EWrite bits. Only one of these can 
   452 be set, otherwise the function raises a STORE-Stream 17 panic.
   456 be set, otherwise the function raises a STORE-Stream 17 panic.
   453 @return The number of bytes available. */
   457 @return The number of bytes available. */
       
   458 EXPORT_C TInt TStreamBuf::Avail(TArea anArea) const
   454 	{
   459 	{
   455 	if (anArea==ERead)
   460 	if (anArea==ERead)
   456 		return Avail(ERead);
   461 		return Avail(ERead);
   457 //
   462 //
   458 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   463 	__ASSERT_ALWAYS(anArea==EWrite,Panic(EStreamAreaInvalid));
   459 	return Avail(EWrite);
   464 	return Avail(EWrite);
   460 	}
   465 	}
   461 
   466 
   462 EXPORT_C TInt TStreamBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
       
   463 /** Reads data from the intermediate buffer into the specified memory location.
   467 /** Reads data from the intermediate buffer into the specified memory location.
   464 
   468 
   465 The function calls the virtual function UnderfLowL() to give concrete implementations 
   469 The function calls the virtual function UnderfLowL() to give concrete implementations 
   466 the chance to refill the intermediate buffer, and satisfy the caller's requirements.
   470 the chance to refill the intermediate buffer, and satisfy the caller's requirements.
   467 
   471 
   472 the intermediate buffer.
   476 the intermediate buffer.
   473 @param aMaxLength The maximum number of bytes to be read.
   477 @param aMaxLength The maximum number of bytes to be read.
   474 @return The number of bytes read. This may be less than the amount requested.
   478 @return The number of bytes read. This may be less than the amount requested.
   475 @see MStreamBuf::ReadL()
   479 @see MStreamBuf::ReadL()
   476 @see MStreamBuf::DoReadL() */
   480 @see MStreamBuf::DoReadL() */
       
   481 EXPORT_C TInt TStreamBuf::DoReadL(TAny* aPtr,TInt aMaxLength)
   477 	{
   482 	{
   478 	__ASSERT_DEBUG(aMaxLength>=0,Panic(EStreamReadLengthNegative));
   483 	__ASSERT_DEBUG(aMaxLength>=0,Panic(EStreamReadLengthNegative));
   479 	__ASSERT_DEBUG(aMaxLength>0,Panic(EStreamReadNoTransfer));
   484 	__ASSERT_DEBUG(aMaxLength>0,Panic(EStreamReadNoTransfer));
   480 	__ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead));
   485 	__ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead));
   481 	TInt left=aMaxLength;
   486 	TInt left=aMaxLength;
   503 		} while (avail>0);
   508 		} while (avail>0);
   504 	__ASSERT_DEBUG(avail==0&&Avail(ERead)==0,Panic(EStreamUnderflowInBreach));
   509 	__ASSERT_DEBUG(avail==0&&Avail(ERead)==0,Panic(EStreamUnderflowInBreach));
   505 	return aMaxLength-left;
   510 	return aMaxLength-left;
   506 	}
   511 	}
   507 
   512 
   508 EXPORT_C TStreamTransfer TStreamBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer)
       
   509 /** Reads data from the intermediate buffer and, if necessary, any remaining data 
   513 /** Reads data from the intermediate buffer and, if necessary, any remaining data 
   510 from the stream to the specified target stream input object.
   514 from the stream to the specified target stream input object.
   511 
   515 
   512 It is called by ReadL(MStreamInput&,TStreamTransfer).
   516 It is called by ReadL(MStreamInput&,TStreamTransfer).
   513 
   517 
   523 @param aTransfer A stream transfer object defining the amount of data available 
   527 @param aTransfer A stream transfer object defining the amount of data available 
   524 to be written.
   528 to be written.
   525 @return The amount of data that was not consumed.
   529 @return The amount of data that was not consumed.
   526 @see MStreamInput::ReadFromL()
   530 @see MStreamInput::ReadFromL()
   527 @see MStreamInput::PushL() */
   531 @see MStreamInput::PushL() */
       
   532 EXPORT_C TStreamTransfer TStreamBuf::DoReadL(MStreamInput& anInput,TStreamTransfer aTransfer)
   528 	{
   533 	{
   529 	__ASSERT_DEBUG(aTransfer>0,Panic(EStreamReadNoTransfer));
   534 	__ASSERT_DEBUG(aTransfer>0,Panic(EStreamReadNoTransfer));
   530 	__ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead));
   535 	__ASSERT_DEBUG(Ptr(ERead)!=NULL||End(ERead)==NULL,Panic(EStreamCannotRead));
   531 	__ASSERT_DEBUG(Avail(ERead)>=0,User::Invariant());
   536 	__ASSERT_DEBUG(Avail(ERead)>=0,User::Invariant());
   532 	TInt len=aTransfer[Avail(ERead)];
   537 	TInt len=aTransfer[Avail(ERead)];
   542 	if (aTransfer>0)
   547 	if (aTransfer>0)
   543 		aTransfer=anInput.ReadFromL(*this,aTransfer);
   548 		aTransfer=anInput.ReadFromL(*this,aTransfer);
   544 	return aTransfer;
   549 	return aTransfer;
   545 	}
   550 	}
   546 
   551 
   547 EXPORT_C void TStreamBuf::DoWriteL(const TAny* aPtr,TInt aLength)
       
   548 /** Writes data from the specified memory location into the intermediate buffer.
   552 /** Writes data from the specified memory location into the intermediate buffer.
   549 
   553 
   550 The function calls the virtual function OverfLowL() to give concrete implementations 
   554 The function calls the virtual function OverfLowL() to give concrete implementations 
   551 the chance to forward the intermediate buffer content to its destination.
   555 the chance to forward the intermediate buffer content to its destination.
   552 
   556 
   557 to the intermediate buffer.
   561 to the intermediate buffer.
   558 @param aLength The number of bytes to be written.
   562 @param aLength The number of bytes to be written.
   559 @return The number of bytes written.
   563 @return The number of bytes written.
   560 @see MStreamBuf::WriteL()
   564 @see MStreamBuf::WriteL()
   561 @see MStreamBuf::DoWriteL() */
   565 @see MStreamBuf::DoWriteL() */
       
   566 EXPORT_C void TStreamBuf::DoWriteL(const TAny* aPtr,TInt aLength)
   562 	{
   567 	{
   563 	__ASSERT_DEBUG(aLength>=0,Panic(EStreamWriteLengthNegative));
   568 	__ASSERT_DEBUG(aLength>=0,Panic(EStreamWriteLengthNegative));
   564 	__ASSERT_DEBUG(aLength>0,Panic(EStreamWriteNoTransfer));
   569 	__ASSERT_DEBUG(aLength>0,Panic(EStreamWriteNoTransfer));
   565 	__ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite));
   570 	__ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite));
   566 	TInt avail=Avail(EWrite);
   571 	TInt avail=Avail(EWrite);
   586 		OverflowL();
   591 		OverflowL();
   587 		avail=Avail(EWrite);
   592 		avail=Avail(EWrite);
   588 		};
   593 		};
   589 	}
   594 	}
   590 
   595 
       
   596 //
       
   597 // Default implementation filling the buffer before turning around to anOutput.
       
   598 //
   591 EXPORT_C TStreamTransfer TStreamBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer)
   599 EXPORT_C TStreamTransfer TStreamBuf::DoWriteL(MStreamOutput& anOutput,TStreamTransfer aTransfer)
   592 //
       
   593 // Default implementation filling the buffer before turning around to anOutput.
       
   594 //
       
   595 	{
   600 	{
   596 	__ASSERT_DEBUG(aTransfer>0,Panic(EStreamWriteNoTransfer));
   601 	__ASSERT_DEBUG(aTransfer>0,Panic(EStreamWriteNoTransfer));
   597 	__ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite));
   602 	__ASSERT_DEBUG(Ptr(EWrite)!=NULL||End(EWrite)==NULL,Panic(EStreamCannotWrite));
   598 	__ASSERT_DEBUG(Avail(EWrite)>=0,User::Invariant());
   603 	__ASSERT_DEBUG(Avail(EWrite)>=0,User::Invariant());
   599 	TInt len=aTransfer[Avail(EWrite)];
   604 	TInt len=aTransfer[Avail(EWrite)];