persistentstorage/store/USTRM/US_FLTR.CPP
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "US_STD.H"
       
    17 
       
    18 EXPORT_C TStreamFilter::TStreamFilter()
       
    19 	: iHost(NULL),iMode(0)
       
    20 /** Constructs an empty stream filter object. */
       
    21 	{}
       
    22 
       
    23 EXPORT_C void TStreamFilter::EmitL(const TAny* aPtr,TInt aLength)
       
    24 /** Writes data from the specified memory location directly to the host without 
       
    25 filtering.
       
    26 
       
    27 This is useful for sending any final data, when flushing the filter as part 
       
    28 of DoSynchL().
       
    29 
       
    30 In debug mode: the filter must be in write mode, otherwise the function raises 
       
    31 a STORE-Stream 11 panic. 
       
    32 
       
    33 In debug mode, a host stream must have been set before calling this function, 
       
    34 otherwise it raises a STORE-Stream 0 panic.
       
    35 
       
    36 @param aPtr A pointer to the memory location from which data is to be written 
       
    37 to the host stream.
       
    38 @param aLength The number of bytes to be written.
       
    39 @see DoSynchL() */
       
    40 	{
       
    41 	__ASSERT_DEBUG(iMode&EWrite,Panic(EStreamCannotWrite));
       
    42 	__ASSERT_DEBUG(iHost!=NULL,Panic(EStreamNotOpen));
       
    43 	iHost->WriteL(aPtr,aLength);
       
    44 	}
       
    45 
       
    46 EXPORT_C void TStreamFilter::DoRelease()
       
    47 /** Frees the host stream's resources.
       
    48 
       
    49 @see MStreamBuf::DoRelease() */
       
    50 	{
       
    51 	if (iHost!=NULL&&(iMode&EAttached))
       
    52 		iHost->Release();
       
    53 	iHost=NULL;
       
    54 	}
       
    55 
       
    56 EXPORT_C void TStreamFilter::DoSynchL()
       
    57 /** Synchronizes the host's intermediate buffer with its stream, leaving if any 
       
    58 error occurs.
       
    59 
       
    60 @see MStreamBuf::DoSynchL() */
       
    61 	{
       
    62 	if (iHost!=NULL&&(iMode&EAttached))
       
    63 		iHost->SynchL();
       
    64 	}
       
    65 
       
    66 EXPORT_C TInt TStreamFilter::DoReadL(TAny* aPtr,TInt aMaxLength)
       
    67 /** Reads data from the host stream through the filter into the specified memory 
       
    68 location.
       
    69 
       
    70 In debug mode: the filter must be in read mode, otherwise the function raises 
       
    71 a STORE-Stream 10 panic.
       
    72 
       
    73 In debug mode, a host stream must have been set before calling this function, 
       
    74 otherwise it raises a STORE-Stream 0 panic.
       
    75 
       
    76 @param aPtr A pointer to the target memory location for the filtered data.
       
    77 @param aMaxLength The maximum number of bytes to be read. In debug mode: if 
       
    78 this value is negative then the function raises a STORE-Stream 1 panic; if 
       
    79 this value is zero, then the function raises a STORE-Stream 3 panic.
       
    80 @return The number of bytes read. */
       
    81 	{
       
    82 	__ASSERT_DEBUG(aMaxLength>=0,Panic(EStreamReadLengthNegative));
       
    83 	__ASSERT_DEBUG(aMaxLength>0,Panic(EStreamReadNoTransfer));
       
    84 	__ASSERT_DEBUG(iMode&ERead,Panic(EStreamCannotRead));
       
    85 	__ASSERT_DEBUG(iHost!=NULL,Panic(EStreamNotOpen));
       
    86 	TFilterInput input(*this,aPtr,aMaxLength);
       
    87 	do
       
    88 		{
       
    89 		iHost->ReadL(input);
       
    90 		} while (!(input.Done()||input.Eof()));
       
    91 	return aMaxLength-input.Left();
       
    92 	}
       
    93 
       
    94 EXPORT_C void TStreamFilter::DoWriteL(const TAny* aPtr,TInt aLength)
       
    95 /** Writes data to the host stream through the filter from the specified memory 
       
    96 location.
       
    97 
       
    98 In debug mode: the filter must be in write mode, otherwise the function raises 
       
    99 a STORE-Stream 11 panic.
       
   100 
       
   101 In debug mode, a host stream must have been set before calling this function, 
       
   102 otherwise it raises a STORE-Stream 0 panic.
       
   103 
       
   104 @param aPtr A pointer to the source memory location.
       
   105 @param aLength The number of bytes to be written. In debug mode: if this value 
       
   106 is negative then the function raises a STORE-Stream 1 panic; if this value 
       
   107 is zero, then the function raises a STORE-Stream 7 panic. */
       
   108 	{
       
   109 	__ASSERT_DEBUG(aLength>=0,Panic(EStreamWriteLengthNegative));
       
   110 	__ASSERT_DEBUG(aLength>0,Panic(EStreamWriteNoTransfer));
       
   111 	__ASSERT_DEBUG(iMode&EWrite,Panic(EStreamCannotWrite));
       
   112 	__ASSERT_DEBUG(iHost!=NULL,Panic(EStreamNotOpen));
       
   113 	TFilterOutput output(*this,aPtr,aLength);
       
   114 	do
       
   115 		{
       
   116 		iHost->WriteL(output);
       
   117 		} while (!output.Done());
       
   118 	}
       
   119 
       
   120 EXPORT_C void TStreamFilter::__DbgChkMode(TInt aMode)
       
   121 //
       
   122 // Check mode allows either reading or writing, but not both.
       
   123 //
       
   124 	{
       
   125 	__ASSERT_ALWAYS((aMode&(ERead|EWrite))&&(aMode&(ERead|EWrite))!=(ERead|EWrite),Panic(EStreamModeInvalid));
       
   126 	}
       
   127