sl@0
|
1 |
#ifndef __HOST_TRANSFERS_H
|
sl@0
|
2 |
#define __HOST_TRANSFERS_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 HostTransfers.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 <e32ver.h>
|
sl@0
|
28 |
#include <d32usbdescriptors.h>
|
sl@0
|
29 |
#include <d32usbtransfers.h>
|
sl@0
|
30 |
#include <d32usbdi.h>
|
sl@0
|
31 |
#include "testdebug.h"
|
sl@0
|
32 |
#include "ControlTransferRequests.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
namespace NUnitTesting_USBDI
|
sl@0
|
35 |
{
|
sl@0
|
36 |
|
sl@0
|
37 |
/**
|
sl@0
|
38 |
This class describes an interface to a class which wants to observe transfers
|
sl@0
|
39 |
*/
|
sl@0
|
40 |
class MTransferObserver
|
sl@0
|
41 |
{
|
sl@0
|
42 |
public:
|
sl@0
|
43 |
/**
|
sl@0
|
44 |
Called when a transfer with the supplied transfer identity has completed
|
sl@0
|
45 |
@param aTransferId the identity of the transfer
|
sl@0
|
46 |
@param aCompletionCode the error completion code for the asynchronous transfer
|
sl@0
|
47 |
*/
|
sl@0
|
48 |
virtual void TransferCompleteL(TInt aTransferId,TInt aCompletionCode) = 0;
|
sl@0
|
49 |
};
|
sl@0
|
50 |
|
sl@0
|
51 |
|
sl@0
|
52 |
/**
|
sl@0
|
53 |
This class describes a base class for a transfer
|
sl@0
|
54 |
*/
|
sl@0
|
55 |
class CBaseTransfer : public CActive
|
sl@0
|
56 |
{
|
sl@0
|
57 |
public:
|
sl@0
|
58 |
/**
|
sl@0
|
59 |
Destructor
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
virtual ~CBaseTransfer()
|
sl@0
|
62 |
{
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
/**
|
sl@0
|
66 |
Retrieve the identity of the transfer
|
sl@0
|
67 |
@return the transfer identity
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
TInt Identity() const
|
sl@0
|
70 |
{
|
sl@0
|
71 |
return iTransferIdentity;
|
sl@0
|
72 |
}
|
sl@0
|
73 |
|
sl@0
|
74 |
protected:
|
sl@0
|
75 |
/**
|
sl@0
|
76 |
Constructor
|
sl@0
|
77 |
*/
|
sl@0
|
78 |
CBaseTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,MTransferObserver& aObserver,TInt aTransferIdentity)
|
sl@0
|
79 |
: CActive(EPriorityStandard),
|
sl@0
|
80 |
iPipe(aPipe),
|
sl@0
|
81 |
iInterface(aInterface),
|
sl@0
|
82 |
iObserver(aObserver),
|
sl@0
|
83 |
iTransferIdentity(aTransferIdentity)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
CActiveScheduler::Add(this);
|
sl@0
|
86 |
}
|
sl@0
|
87 |
|
sl@0
|
88 |
/**
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
void SelfComplete()
|
sl@0
|
91 |
{
|
sl@0
|
92 |
iStatus = KRequestPending;
|
sl@0
|
93 |
TRequestStatus* s = &iStatus;
|
sl@0
|
94 |
User::RequestComplete(s,KErrNone);
|
sl@0
|
95 |
SetActive();
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
protected:
|
sl@0
|
99 |
/**
|
sl@0
|
100 |
*/
|
sl@0
|
101 |
virtual TInt RunError(TInt aError)
|
sl@0
|
102 |
{
|
sl@0
|
103 |
RDebug::Printf("<Error %d> a transfer RunL left",aError);
|
sl@0
|
104 |
return KErrNone;
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
/**
|
sl@0
|
108 |
*/
|
sl@0
|
109 |
void RunL()
|
sl@0
|
110 |
{
|
sl@0
|
111 |
LOG_FUNC
|
sl@0
|
112 |
|
sl@0
|
113 |
TInt completionCode(iStatus.Int());
|
sl@0
|
114 |
RDebug::Printf("Transfer err=%d",completionCode);
|
sl@0
|
115 |
|
sl@0
|
116 |
// Notify of transfer completion (successful or otherwise)
|
sl@0
|
117 |
iObserver.TransferCompleteL(iTransferIdentity,completionCode);
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
*/
|
sl@0
|
122 |
void DoCancel()
|
sl@0
|
123 |
{
|
sl@0
|
124 |
LOG_FUNC
|
sl@0
|
125 |
|
sl@0
|
126 |
// Will cancel all transfers on this pipe
|
sl@0
|
127 |
|
sl@0
|
128 |
Pipe().CancelAllTransfers();
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
protected:
|
sl@0
|
132 |
|
sl@0
|
133 |
/**
|
sl@0
|
134 |
Get the pipe object for the transfer
|
sl@0
|
135 |
@return a opened pipe for transfers
|
sl@0
|
136 |
*/
|
sl@0
|
137 |
RUsbPipe& Pipe()
|
sl@0
|
138 |
{
|
sl@0
|
139 |
return iPipe;
|
sl@0
|
140 |
}
|
sl@0
|
141 |
|
sl@0
|
142 |
/**
|
sl@0
|
143 |
Get the interface for the transfer
|
sl@0
|
144 |
@return the opened interface
|
sl@0
|
145 |
*/
|
sl@0
|
146 |
RUsbInterface& Interface()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
return iInterface;
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
/**
|
sl@0
|
152 |
Access the observer of the transfers
|
sl@0
|
153 |
@return the transfer observer
|
sl@0
|
154 |
*/
|
sl@0
|
155 |
MTransferObserver& Observer()
|
sl@0
|
156 |
{
|
sl@0
|
157 |
return iObserver;
|
sl@0
|
158 |
}
|
sl@0
|
159 |
|
sl@0
|
160 |
private:
|
sl@0
|
161 |
/**
|
sl@0
|
162 |
The usb pipe that will be used for the transfer and where
|
sl@0
|
163 |
the buffer pool is located.
|
sl@0
|
164 |
*/
|
sl@0
|
165 |
RUsbPipe& iPipe;
|
sl@0
|
166 |
|
sl@0
|
167 |
/**
|
sl@0
|
168 |
The interface that will be used for the transfer
|
sl@0
|
169 |
*/
|
sl@0
|
170 |
RUsbInterface& iInterface;
|
sl@0
|
171 |
|
sl@0
|
172 |
/**
|
sl@0
|
173 |
The observer for the transfers
|
sl@0
|
174 |
*/
|
sl@0
|
175 |
MTransferObserver& iObserver;
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
The identity of a transfer (not the type)
|
sl@0
|
179 |
*/
|
sl@0
|
180 |
TInt iTransferIdentity;
|
sl@0
|
181 |
};
|
sl@0
|
182 |
|
sl@0
|
183 |
/**
|
sl@0
|
184 |
This class represents a interrupt transfer to the device
|
sl@0
|
185 |
*/
|
sl@0
|
186 |
class CInterruptTransfer : public CBaseTransfer
|
sl@0
|
187 |
{
|
sl@0
|
188 |
public:
|
sl@0
|
189 |
/**
|
sl@0
|
190 |
C++ constructor, builds a interrupt transfer object with a transfer buffer of maximum fixed size.
|
sl@0
|
191 |
The caller must ensure that this instance can handle the transfer specified
|
sl@0
|
192 |
@param aPipe the pipe to be used for the transfer and buffer pool
|
sl@0
|
193 |
@param aTransferSize the required maximum size of the buffer to handle all transfers
|
sl@0
|
194 |
@param aObserver the observer of the transfer
|
sl@0
|
195 |
@param aTransferId a unique identity of the transfer
|
sl@0
|
196 |
*/
|
sl@0
|
197 |
CInterruptTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TInt aMaxTransferSize,MTransferObserver& aObserver,TInt aTransferId);
|
sl@0
|
198 |
|
sl@0
|
199 |
/**
|
sl@0
|
200 |
Destructor
|
sl@0
|
201 |
*/
|
sl@0
|
202 |
virtual ~CInterruptTransfer();
|
sl@0
|
203 |
|
sl@0
|
204 |
/**
|
sl@0
|
205 |
Poll for interrupt data queued by the device and transfer to host
|
sl@0
|
206 |
@param aSize the size of the data from requested from the client
|
sl@0
|
207 |
@return KErrNone if successful or system-wide error code
|
sl@0
|
208 |
*/
|
sl@0
|
209 |
TInt TransferInL(TInt aSize);
|
sl@0
|
210 |
|
sl@0
|
211 |
/**
|
sl@0
|
212 |
Register the transfer descriptor
|
sl@0
|
213 |
@return KErrNone if successful or system-wide error code
|
sl@0
|
214 |
*/
|
sl@0
|
215 |
TInt RegisterTransferDescriptor();
|
sl@0
|
216 |
|
sl@0
|
217 |
/**
|
sl@0
|
218 |
On successful completion of an interrupt 'in' transfer, obtain the polled data
|
sl@0
|
219 |
@return the interrupt data from the device
|
sl@0
|
220 |
*/
|
sl@0
|
221 |
TPtrC8 DataPolled();
|
sl@0
|
222 |
|
sl@0
|
223 |
private:
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
The transfer descriptor for interrupt transfers
|
sl@0
|
226 |
*/
|
sl@0
|
227 |
RUsbIntrTransferDescriptor iTransferDescriptor;
|
sl@0
|
228 |
};
|
sl@0
|
229 |
|
sl@0
|
230 |
/**
|
sl@0
|
231 |
This class represents a isochronous transfer to a device
|
sl@0
|
232 |
*/
|
sl@0
|
233 |
class CIsochTransfer : public CBaseTransfer
|
sl@0
|
234 |
{
|
sl@0
|
235 |
public:
|
sl@0
|
236 |
/**
|
sl@0
|
237 |
C++ constructor, builds a isochronous transfer object with a transfer buffer of maximum fixed size.
|
sl@0
|
238 |
The caller must ensure that this instance can handle the transfer specified
|
sl@0
|
239 |
@param aPipe the pipe to be used for the transfer and buffer pool
|
sl@0
|
240 |
@param aMaxPacketSize the maximum packet size to send
|
sl@0
|
241 |
@param aMaxNumPackets the maximum number of packets to be transfered on this pipe
|
sl@0
|
242 |
@param aObserver the observer of the transfer
|
sl@0
|
243 |
@param aTransferId a unique identity of the transfer
|
sl@0
|
244 |
*/
|
sl@0
|
245 |
CIsochTransfer(RUsbPipe& aPipe,RUsbInterface& aInterface,TUint16 aMaxPacketSize,
|
sl@0
|
246 |
TInt aMaxNumPackets,MTransferObserver& aObserver,TInt aTransferId);
|
sl@0
|
247 |
|
sl@0
|
248 |
/**
|
sl@0
|
249 |
Destructor
|
sl@0
|
250 |
*/
|
sl@0
|
251 |
virtual ~CIsochTransfer();
|
sl@0
|
252 |
|
sl@0
|
253 |
TInt RegisterTransferDescriptor();
|
sl@0
|
254 |
|
sl@0
|
255 |
/**
|
sl@0
|
256 |
Transfer the data to the device
|
sl@0
|
257 |
@param aIsochData the 8bit Isochronous data to transfer
|
sl@0
|
258 |
@return KErrNone if successful, or system wide error code
|
sl@0
|
259 |
*/
|
sl@0
|
260 |
TInt TransferOut();
|
sl@0
|
261 |
|
sl@0
|
262 |
/**
|
sl@0
|
263 |
Prepare the transfer before its sending
|
sl@0
|
264 |
@param aIsochData the 8bit Isochronous data to transfer
|
sl@0
|
265 |
@return KErrNone if successful, or system wide error code
|
sl@0
|
266 |
*/
|
sl@0
|
267 |
TInt PrepareTransfer(const TDesC8& aIsochData);
|
sl@0
|
268 |
|
sl@0
|
269 |
/**
|
sl@0
|
270 |
Start the IN transfer
|
sl@0
|
271 |
@param aPacketsExpected nb of expected packets
|
sl@0
|
272 |
@return KErrNone if successful, or system wide error code
|
sl@0
|
273 |
*/
|
sl@0
|
274 |
TInt TransferInL(TInt aPacketsExpected);
|
sl@0
|
275 |
|
sl@0
|
276 |
/**
|
sl@0
|
277 |
Store the polled data into internal buffer
|
sl@0
|
278 |
@param[int] aPacketsToBeRead nb of packets to be read
|
sl@0
|
279 |
@param[out] aDataPolled data being transfered
|
sl@0
|
280 |
@return ETrue if successful, EFalse otherwise
|
sl@0
|
281 |
*/
|
sl@0
|
282 |
TBool DataPolled(TUint aPacketsToBeRead, RBuf8& aDataPolled);
|
sl@0
|
283 |
|
sl@0
|
284 |
private:
|
sl@0
|
285 |
/**
|
sl@0
|
286 |
The transfer descriptor for isochronous transfers
|
sl@0
|
287 |
*/
|
sl@0
|
288 |
RUsbIsocTransferDescriptor iTransferDescriptor;
|
sl@0
|
289 |
|
sl@0
|
290 |
/**
|
sl@0
|
291 |
The maximum packet size for the respective isochronous endpoint
|
sl@0
|
292 |
*/
|
sl@0
|
293 |
TUint16 iMaxPacketSize;
|
sl@0
|
294 |
|
sl@0
|
295 |
};
|
sl@0
|
296 |
|
sl@0
|
297 |
|
sl@0
|
298 |
/**
|
sl@0
|
299 |
This class represents a bulk transfer to a device
|
sl@0
|
300 |
*/
|
sl@0
|
301 |
class CBulkTransfer : public CBaseTransfer
|
sl@0
|
302 |
{
|
sl@0
|
303 |
public:
|
sl@0
|
304 |
/**
|
sl@0
|
305 |
C++ constructor
|
sl@0
|
306 |
*/
|
sl@0
|
307 |
CBulkTransfer(RUsbPipe& aPipe,RUsbInterface& aUsbInterface,TInt aMaxTransferSize,
|
sl@0
|
308 |
MTransferObserver& aObserver,TInt aTransferId);
|
sl@0
|
309 |
|
sl@0
|
310 |
/**
|
sl@0
|
311 |
*/
|
sl@0
|
312 |
virtual ~CBulkTransfer();
|
sl@0
|
313 |
|
sl@0
|
314 |
/**
|
sl@0
|
315 |
*/
|
sl@0
|
316 |
void TransferOut(const TDesC8& aBulkData, TBool aUseZLPIfRequired = ETrue);
|
sl@0
|
317 |
|
sl@0
|
318 |
/**
|
sl@0
|
319 |
*/
|
sl@0
|
320 |
void TransferOut(const TDesC8& aBulkDataPattern, TUint aNumBytes, TBool aUseZLPIfRequired = ETrue);
|
sl@0
|
321 |
|
sl@0
|
322 |
/**
|
sl@0
|
323 |
*/
|
sl@0
|
324 |
void TransferOut(const TDesC8& aBulkDataPattern, TUint aStartPoint, TUint aNumBytes, TBool aUseZLPIfRequired);
|
sl@0
|
325 |
|
sl@0
|
326 |
/**
|
sl@0
|
327 |
*/
|
sl@0
|
328 |
void TransferIn(TInt aExpectedDataSize);
|
sl@0
|
329 |
|
sl@0
|
330 |
/**
|
sl@0
|
331 |
*/
|
sl@0
|
332 |
RUsbPipe& Pipe(){return CBaseTransfer::Pipe();};
|
sl@0
|
333 |
|
sl@0
|
334 |
RUsbBulkTransferDescriptor& TransferDescriptor(){return iTransferDescriptor;};
|
sl@0
|
335 |
|
sl@0
|
336 |
/**
|
sl@0
|
337 |
*/
|
sl@0
|
338 |
TPtrC8 DataPolled();
|
sl@0
|
339 |
|
sl@0
|
340 |
private:
|
sl@0
|
341 |
/**
|
sl@0
|
342 |
The transfer descriptor for bulk transfers
|
sl@0
|
343 |
*/
|
sl@0
|
344 |
RUsbBulkTransferDescriptor iTransferDescriptor;
|
sl@0
|
345 |
};
|
sl@0
|
346 |
|
sl@0
|
347 |
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
#endif
|
sl@0
|
351 |
|
sl@0
|
352 |
|