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