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