First public contribution.
1 #ifndef __TEST_DEVICE_BASE_H
2 #define __TEST_DEVICE_BASE_H
5 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
12 * Initial Contributors:
13 * Nokia Corporation - initial contribution.
18 * @file TestDeviceBase.h
28 #include "UsbClientStateWatcher.h"
29 #include "ep0reader.h"
30 #include "BaseTestCase.h"
33 namespace NUnitTesting_USBDI
36 // Forward declarations
39 class CSoftwareConnectTimer;
40 class CRemoteWakeupTimer;
43 This class represents a test USB device. There is only one configuration supported
44 for this representation
46 class RUsbTestDevice : public MUsbClientStateObserver,
47 public MRequestHandler
54 virtual ~RUsbTestDevice();
57 RUsbTestDevice(CBaseTestCase* aTestCase);
62 Requests error/reports from this test device
63 @param aObserverStatus the status of the entity that requests error reports
66 void SubscribeToReports(TRequestStatus& aOberverStatus);
69 Cancel request for any errors from operations from this device
72 void CancelSubscriptionToReports();
82 Close this device, releaseing all resources
88 Sets specific information for the device
89 @param aClassCode the class code that is specified by the standard
90 00h Use class information in the Interface Descriptors
91 02h Communications and CDC Control (together with interface descriptor)
93 DCh Diagnostic Device (together with interface descriptors)
94 EFh Miscellaneous (together with interface descriptors)
95 FFh Vendor Specific (together with interface descriptors)
96 @param aSubClassCode the subclass code specified by the USB org
97 @param aDeviceProtocol
100 TInt SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol);
103 Set the USB specification that this device complies to
104 @param aSpecification the specificatio nnumber
107 TInt SetUsbSpecification(TUint16 aSpecification);
110 Set the information for the vendor of this device
111 @param aVendorId the identity number for the vendor
114 TInt SetVendor(TUint16 aVendorId);
117 Set the product information
118 @param aProductId the identity of the product
119 @param aProductString the string used to describe the product
120 @param aManufacturerString the string used to describe the manufacturer
121 @param aSerialNumberString the product serial number as string
124 TInt SetProduct(TUint16 aProductId,const TDesC16& aProductString,const TDesC16& aManufacturerString,
125 const TDesC16& aSerialNumberString);
128 Establishes the configuration string for the device
129 @param aConfigString the string for the configuration
132 TInt SetConfigurationString(const TDesC16& aConfigString);
135 Adds an test interface to the test device
136 @param aInterface a pointer to the interface
139 void AddInterface(CInterfaceBase* aInterface);
142 Access the interfacefor this device identified by the interface index number
143 @param aIndex the index of the interface
144 @return the interface
147 CInterfaceBase& Interface(TInt aIndex);
150 Software connect this test device to the host bus.
151 The device must already by physically connected.
154 void SoftwareConnect();
157 Software dis-connect this test device from the host bus.
158 The device can be left physically connected
161 void SoftwareDisconnect();
164 Perform a remote wake-up for the device
170 Notifies the test case of any errors in operations for this test device
171 @param aCompletionCode the error code to complete the test case with
174 void ReportError(TInt aCompletionCode);
177 Sends a zero length data packet to acknowledge the request
180 void AcknowledgeRequestReceived();
182 public: // From MUsbClientStateObserver
185 Called when the device has changed state
186 @param aNewState will hold the new state the device has been placed into by the host
187 @param aChangeCompletionCode the operation comletion code
189 void StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode);
191 public: // From MRequestHandler
194 Process control requests from device endpoint 0
195 @param aRequest the control request value
196 @param aValue a parameter value for the request
197 @param aIndex an index parameter for the request
198 @param aDataReqLength the length of the data to be returned to the host
199 @param aPayload the data payload sent to the device by the host in a data phase
202 virtual TInt ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,
203 TUint16 aDataReqLength,const TDesC8& aPayload);
208 Constructor, build a test device
214 Start listening for control requests sent by the host
217 void StartEp0Reading();
220 Stop reading control requests from endpoint 0
223 void StopEp0Reading();
226 Derived devices will be notified through this function when the device has changed state
227 and this base class has performed basic functionality
228 @param aNewState the new state of the device
231 virtual void OnStateChangeL(TUsbcDeviceState aNewState) = 0;
236 RDevUsbcClient iClientDriver; // The USB client driver object
239 The device can have many interfaces offering different functions (part functions)
240 They are kept and owned by the device
242 RPointerArray<CInterfaceBase> iInterfaces;
245 The watcher of states for the USB client
247 CUsbClientStateWatcher* iStateWatcher;
248 TUsbcDeviceState iCurrentState;
251 The information about the capabilities of the device.
252 This is mostly hardware specific information
254 TUsbDeviceCaps iDeviceCaps;
257 The control endpoint 0, reading device directed requests
259 CDeviceEndpoint0* iDeviceEp0;
262 The timer required perform any connect, disconnect or re-connections
264 CSoftwareConnectTimer* iConnectTimer;
267 The timer that performs any remote wakeups
269 CRemoteWakeupTimer* iWakeupTimer;
273 TRequestStatus* iObserverStatus;
280 CBaseTestCase* iTestCase;