sl@0: #ifndef __TEST_DEVICE_BASE_H sl@0: #define __TEST_DEVICE_BASE_H sl@0: sl@0: /* sl@0: * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * @file TestDeviceBase.h sl@0: * @internalComponent sl@0: * sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "UsbClientStateWatcher.h" sl@0: #include "ep0reader.h" sl@0: #include "BaseTestCase.h" sl@0: #include sl@0: sl@0: namespace NUnitTesting_USBDI sl@0: { sl@0: sl@0: // Forward declarations sl@0: sl@0: class CInterfaceBase; sl@0: class CSoftwareConnectTimer; sl@0: class CRemoteWakeupTimer; sl@0: sl@0: /** sl@0: This class represents a test USB device. There is only one configuration supported sl@0: for this representation sl@0: */ sl@0: class RUsbTestDevice : public MUsbClientStateObserver, sl@0: public MRequestHandler sl@0: { sl@0: public: sl@0: /** sl@0: Destructor sl@0: */ sl@0: sl@0: virtual ~RUsbTestDevice(); sl@0: sl@0: // ctor sl@0: RUsbTestDevice(CBaseTestCase* aTestCase); sl@0: sl@0: void ResetState(); sl@0: sl@0: /** sl@0: Requests error/reports from this test device sl@0: @param aObserverStatus the status of the entity that requests error reports sl@0: */ sl@0: sl@0: void SubscribeToReports(TRequestStatus& aOberverStatus); sl@0: sl@0: /** sl@0: Cancel request for any errors from operations from this device sl@0: */ sl@0: sl@0: void CancelSubscriptionToReports(); sl@0: sl@0: /** sl@0: Open a basic device sl@0: @leave KErrNoMemory sl@0: */ sl@0: sl@0: void OpenL(); sl@0: sl@0: /** sl@0: Close this device, releaseing all resources sl@0: */ sl@0: sl@0: void Close(); sl@0: sl@0: /** sl@0: Sets specific information for the device sl@0: @param aClassCode the class code that is specified by the standard sl@0: 00h Use class information in the Interface Descriptors sl@0: 02h Communications and CDC Control (together with interface descriptor) sl@0: 09h Hub sl@0: DCh Diagnostic Device (together with interface descriptors) sl@0: EFh Miscellaneous (together with interface descriptors) sl@0: FFh Vendor Specific (together with interface descriptors) sl@0: @param aSubClassCode the subclass code specified by the USB org sl@0: @param aDeviceProtocol sl@0: */ sl@0: sl@0: TInt SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol); sl@0: sl@0: /** sl@0: Set the USB specification that this device complies to sl@0: @param aSpecification the specificatio nnumber sl@0: */ sl@0: sl@0: TInt SetUsbSpecification(TUint16 aSpecification); sl@0: sl@0: /** sl@0: Set the information for the vendor of this device sl@0: @param aVendorId the identity number for the vendor sl@0: */ sl@0: sl@0: TInt SetVendor(TUint16 aVendorId); sl@0: sl@0: /** sl@0: Set the product information sl@0: @param aProductId the identity of the product sl@0: @param aProductString the string used to describe the product sl@0: @param aManufacturerString the string used to describe the manufacturer sl@0: @param aSerialNumberString the product serial number as string sl@0: */ sl@0: sl@0: TInt SetProduct(TUint16 aProductId,const TDesC16& aProductString,const TDesC16& aManufacturerString, sl@0: const TDesC16& aSerialNumberString); sl@0: sl@0: /** sl@0: Establishes the configuration string for the device sl@0: @param aConfigString the string for the configuration sl@0: */ sl@0: sl@0: TInt SetConfigurationString(const TDesC16& aConfigString); sl@0: sl@0: /** sl@0: Adds an test interface to the test device sl@0: @param aInterface a pointer to the interface sl@0: */ sl@0: sl@0: void AddInterface(CInterfaceBase* aInterface); sl@0: sl@0: /** sl@0: Access the interfacefor this device identified by the interface index number sl@0: @param aIndex the index of the interface sl@0: @return the interface sl@0: */ sl@0: sl@0: CInterfaceBase& Interface(TInt aIndex); sl@0: sl@0: /** sl@0: Software connect this test device to the host bus. sl@0: The device must already by physically connected. sl@0: */ sl@0: sl@0: void SoftwareConnect(); sl@0: sl@0: /** sl@0: Software dis-connect this test device from the host bus. sl@0: The device can be left physically connected sl@0: */ sl@0: sl@0: void SoftwareDisconnect(); sl@0: sl@0: /** sl@0: Perform a remote wake-up for the device sl@0: */ sl@0: sl@0: void RemoteWakeup(); sl@0: sl@0: /** sl@0: Notifies the test case of any errors in operations for this test device sl@0: @param aCompletionCode the error code to complete the test case with sl@0: */ sl@0: sl@0: void ReportError(TInt aCompletionCode); sl@0: sl@0: /** sl@0: Sends a zero length data packet to acknowledge the request sl@0: */ sl@0: sl@0: void AcknowledgeRequestReceived(); sl@0: sl@0: public: // From MUsbClientStateObserver sl@0: sl@0: /** sl@0: Called when the device has changed state sl@0: @param aNewState will hold the new state the device has been placed into by the host sl@0: @param aChangeCompletionCode the operation comletion code sl@0: */ sl@0: void StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode); sl@0: sl@0: public: // From MRequestHandler sl@0: sl@0: /** sl@0: Process control requests from device endpoint 0 sl@0: @param aRequest the control request value sl@0: @param aValue a parameter value for the request sl@0: @param aIndex an index parameter for the request sl@0: @param aDataReqLength the length of the data to be returned to the host sl@0: @param aPayload the data payload sent to the device by the host in a data phase sl@0: */ sl@0: sl@0: virtual TInt ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex, sl@0: TUint16 aDataReqLength,const TDesC8& aPayload); sl@0: sl@0: protected: sl@0: sl@0: /** sl@0: Constructor, build a test device sl@0: */ sl@0: sl@0: RUsbTestDevice(); sl@0: sl@0: /** sl@0: Start listening for control requests sent by the host sl@0: */ sl@0: sl@0: void StartEp0Reading(); sl@0: sl@0: /** sl@0: Stop reading control requests from endpoint 0 sl@0: */ sl@0: sl@0: void StopEp0Reading(); sl@0: sl@0: /** sl@0: Derived devices will be notified through this function when the device has changed state sl@0: and this base class has performed basic functionality sl@0: @param aNewState the new state of the device sl@0: */ sl@0: sl@0: virtual void OnStateChangeL(TUsbcDeviceState aNewState) = 0; sl@0: sl@0: sl@0: protected: sl@0: sl@0: RDevUsbcClient iClientDriver; // The USB client driver object sl@0: sl@0: /** sl@0: The device can have many interfaces offering different functions (part functions) sl@0: They are kept and owned by the device sl@0: */ sl@0: RPointerArray iInterfaces; sl@0: sl@0: /** sl@0: The watcher of states for the USB client sl@0: */ sl@0: CUsbClientStateWatcher* iStateWatcher; sl@0: TUsbcDeviceState iCurrentState; sl@0: sl@0: /** sl@0: The information about the capabilities of the device. sl@0: This is mostly hardware specific information sl@0: */ sl@0: TUsbDeviceCaps iDeviceCaps; sl@0: sl@0: /** sl@0: The control endpoint 0, reading device directed requests sl@0: */ sl@0: CDeviceEndpoint0* iDeviceEp0; sl@0: sl@0: /** sl@0: The timer required perform any connect, disconnect or re-connections sl@0: */ sl@0: CSoftwareConnectTimer* iConnectTimer; sl@0: sl@0: /** sl@0: The timer that performs any remote wakeups sl@0: */ sl@0: CRemoteWakeupTimer* iWakeupTimer; sl@0: sl@0: /** sl@0: */ sl@0: TRequestStatus* iObserverStatus; sl@0: sl@0: /** sl@0: A Aux buffer sl@0: */ sl@0: HBufC8* iAuxBuffer; sl@0: sl@0: CBaseTestCase* iTestCase; sl@0: sl@0: RProcess iOtgUsbMan; sl@0: }; sl@0: sl@0: sl@0: } sl@0: sl@0: sl@0: #endif