sl@0
|
1 |
#ifndef __ENDPOINT_READER_H
|
sl@0
|
2 |
#define __ENDPOINT_READER_H
|
sl@0
|
3 |
|
sl@0
|
4 |
/*
|
sl@0
|
5 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
6 |
* All rights reserved.
|
sl@0
|
7 |
* This component and the accompanying materials are made available
|
sl@0
|
8 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
9 |
* which accompanies this distribution, and is available
|
sl@0
|
10 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Initial Contributors:
|
sl@0
|
13 |
* Nokia Corporation - initial contribution.
|
sl@0
|
14 |
*
|
sl@0
|
15 |
* Contributors:
|
sl@0
|
16 |
*
|
sl@0
|
17 |
* Description:
|
sl@0
|
18 |
* @file endpointreader.h
|
sl@0
|
19 |
* @internalComponent
|
sl@0
|
20 |
*
|
sl@0
|
21 |
*
|
sl@0
|
22 |
*/
|
sl@0
|
23 |
|
sl@0
|
24 |
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <e32base.h>
|
sl@0
|
27 |
#include <d32usbc.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
namespace NUnitTesting_USBDI
|
sl@0
|
30 |
{
|
sl@0
|
31 |
|
sl@0
|
32 |
/*
|
sl@0
|
33 |
* The buffer to read control packet data into
|
sl@0
|
34 |
* Low-speed 8bytes
|
sl@0
|
35 |
* High-speed 8,16,32 or 64bytes
|
sl@0
|
36 |
* Full-speed 64bytes
|
sl@0
|
37 |
*/
|
sl@0
|
38 |
|
sl@0
|
39 |
const TInt KFullSpeedPacketSize = 64;
|
sl@0
|
40 |
|
sl@0
|
41 |
/**
|
sl@0
|
42 |
This class describes a handler for bytes received from the endpoint
|
sl@0
|
43 |
*/
|
sl@0
|
44 |
class MEndpointDataHandler
|
sl@0
|
45 |
{
|
sl@0
|
46 |
public:
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
Called when data is read from an endpoint
|
sl@0
|
49 |
@param aEndpointNumber the number of the endpoint that was read from
|
sl@0
|
50 |
@param aData the data read from the endpoint (valid data if the completion code is KErrNone)
|
sl@0
|
51 |
@param aCompletionCode the completion code for the read
|
sl@0
|
52 |
*/
|
sl@0
|
53 |
virtual void DataReceivedFromEndpointL(TEndpointNumber aEndpointNumber,const TDesC8& aData) = 0;
|
sl@0
|
54 |
|
sl@0
|
55 |
/**
|
sl@0
|
56 |
Called when the read operation from the endpoint completes with an error
|
sl@0
|
57 |
@param aEndpointNumber the number of the endpoint read from
|
sl@0
|
58 |
@param aErrorCode the operation error completion code
|
sl@0
|
59 |
*/
|
sl@0
|
60 |
virtual void EndpointReadError(TEndpointNumber aEndpointNumber,TInt aErrorCode) = 0;
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
|
sl@0
|
64 |
/**
|
sl@0
|
65 |
This class describes a general asyncronous endpoint reader
|
sl@0
|
66 |
*/
|
sl@0
|
67 |
class CEndpointReader : public CActive
|
sl@0
|
68 |
{
|
sl@0
|
69 |
public:
|
sl@0
|
70 |
enum TCompletionAction
|
sl@0
|
71 |
{
|
sl@0
|
72 |
ENone,
|
sl@0
|
73 |
EHaltEndpoint,
|
sl@0
|
74 |
ERepeatedRead,
|
sl@0
|
75 |
};
|
sl@0
|
76 |
/**
|
sl@0
|
77 |
Constructor, build a reader that reads byte data from the specified endpoint number
|
sl@0
|
78 |
@param aClientDriver the driver channel to the usb client driver
|
sl@0
|
79 |
@param aEndpoint the endpoint number to read from
|
sl@0
|
80 |
*/
|
sl@0
|
81 |
CEndpointReader(RDevUsbcClient& aClientDriver,TEndpointNumber aEndpoint);
|
sl@0
|
82 |
|
sl@0
|
83 |
/**
|
sl@0
|
84 |
Destructor
|
sl@0
|
85 |
*/
|
sl@0
|
86 |
virtual ~CEndpointReader();
|
sl@0
|
87 |
|
sl@0
|
88 |
/**
|
sl@0
|
89 |
Return data buffer used for Reads - could be NULL!
|
sl@0
|
90 |
@return data buffer
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
TPtr8 Buffer();
|
sl@0
|
93 |
|
sl@0
|
94 |
/**
|
sl@0
|
95 |
Return the result of the last recorded validation result!
|
sl@0
|
96 |
@return that result
|
sl@0
|
97 |
*/
|
sl@0
|
98 |
TBool IsValid();
|
sl@0
|
99 |
|
sl@0
|
100 |
/**
|
sl@0
|
101 |
Return the number of bytes read so far on a repeated (asynchronous)'Read'
|
sl@0
|
102 |
@return that number of bytes
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
TUint NumBytesReadSoFar();
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
Read a data packet from the endpoint specified
|
sl@0
|
108 |
@param aHandler a pointer to the handler of the data that will be read from the host
|
sl@0
|
109 |
*/
|
sl@0
|
110 |
void ReadPacketL(MEndpointDataHandler* aHandler);
|
sl@0
|
111 |
|
sl@0
|
112 |
/**
|
sl@0
|
113 |
Read the specified number of bytes from the endpoint
|
sl@0
|
114 |
@param aByteCount the number of bytes to read
|
sl@0
|
115 |
*/
|
sl@0
|
116 |
void ReadL(TInt aByteCount);
|
sl@0
|
117 |
|
sl@0
|
118 |
/**
|
sl@0
|
119 |
Read the specified number of bytes (or fewer id a short packet arrives) from the endpoint
|
sl@0
|
120 |
@param aByteCount the number of bytes to read
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
void ReadUntilShortL(TInt aByteCount);
|
sl@0
|
123 |
|
sl@0
|
124 |
/**
|
sl@0
|
125 |
Read the specified number of bytes from the endpoint
|
sl@0
|
126 |
Flag the need to halt the endpoint when the read has completed
|
sl@0
|
127 |
@param aByteCount the number of bytes to read
|
sl@0
|
128 |
*/
|
sl@0
|
129 |
void ReadAndHaltL(TInt aByteCount);
|
sl@0
|
130 |
|
sl@0
|
131 |
/**
|
sl@0
|
132 |
Read a specified number of bytes from the endpoint in sections,
|
sl@0
|
133 |
performing a new 'Read' for each section.
|
sl@0
|
134 |
After each 'Read' use the data pattern to validate the results.
|
sl@0
|
135 |
Expect the data pattern to be repeated in its entirety until
|
sl@0
|
136 |
the total number of bytes have been sent.
|
sl@0
|
137 |
@param aDataPattern the data pattern to be used for validation
|
sl@0
|
138 |
@param aNumBytesPerRead the number of bytes to ask for at each 'Read'
|
sl@0
|
139 |
@param aTotalNumBytes the total number of bytes to read
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
void RepeatedReadAndValidateL(const TDesC8& aDataPattern, TUint aNumBytesPerRead, TUint aTotalNumBytes);
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
Send an acknowledgment back to the host
|
sl@0
|
145 |
This will be a zero length DATA1 packet
|
sl@0
|
146 |
@return KErrNone if successful otherwise a system wide error code
|
sl@0
|
147 |
*/
|
sl@0
|
148 |
TInt Acknowledge();
|
sl@0
|
149 |
|
sl@0
|
150 |
protected:
|
sl@0
|
151 |
/**
|
sl@0
|
152 |
Cancels the reading from the host
|
sl@0
|
153 |
*/
|
sl@0
|
154 |
void DoCancel();
|
sl@0
|
155 |
|
sl@0
|
156 |
/**
|
sl@0
|
157 |
*/
|
sl@0
|
158 |
virtual void RunL();
|
sl@0
|
159 |
|
sl@0
|
160 |
/**
|
sl@0
|
161 |
The framework error function from RunL
|
sl@0
|
162 |
@param aError the error from a RunL leave
|
sl@0
|
163 |
@return KErrNone
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
TInt RunError(TInt aError);
|
sl@0
|
166 |
|
sl@0
|
167 |
protected:
|
sl@0
|
168 |
/**
|
sl@0
|
169 |
The channel to use to communicate to the client driver
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
RDevUsbcClient& iClientDriver;
|
sl@0
|
172 |
|
sl@0
|
173 |
/**
|
sl@0
|
174 |
The endpoint number that this reader will read from
|
sl@0
|
175 |
*/
|
sl@0
|
176 |
TEndpointNumber iEndpoint;
|
sl@0
|
177 |
|
sl@0
|
178 |
/**
|
sl@0
|
179 |
The handler for Endpoint zero requests received
|
sl@0
|
180 |
*/
|
sl@0
|
181 |
MEndpointDataHandler* iHandler;
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
The buffer for the data read from the endpoint
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
HBufC8* iDataBuffer;
|
sl@0
|
187 |
TPtr8 iDataPtr;
|
sl@0
|
188 |
|
sl@0
|
189 |
/**
|
sl@0
|
190 |
The buffer for the data read from the endpoint
|
sl@0
|
191 |
*/
|
sl@0
|
192 |
HBufC8* iValidationPatternBuffer;
|
sl@0
|
193 |
TPtr8 iValidationPatternPtr;
|
sl@0
|
194 |
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Competion Action
|
sl@0
|
197 |
*/
|
sl@0
|
198 |
TCompletionAction iCompletionAction;
|
sl@0
|
199 |
|
sl@0
|
200 |
/**
|
sl@0
|
201 |
Needed if completion action is ERepeatedRead
|
sl@0
|
202 |
*/
|
sl@0
|
203 |
TUint iRepeatedReadTotalNumBytes;
|
sl@0
|
204 |
TUint iRepeatedReadNumBytesPerRead;
|
sl@0
|
205 |
TUint iNumBytesReadSoFar;
|
sl@0
|
206 |
TUint iDataPatternLength;
|
sl@0
|
207 |
TBool iIsValid;
|
sl@0
|
208 |
};
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
}
|
sl@0
|
212 |
|
sl@0
|
213 |
#endif
|
sl@0
|
214 |
|
sl@0
|
215 |
|
sl@0
|
216 |
|