os/kernelhwsrv/kerneltest/e32test/usbho/t_usbdi/inc/FDFActor.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 #ifndef __FDF_ACTOR_H
     2 #define __FDF_ACTOR_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 FDFActor.h
    19 * @internalComponent
    20 * 
    21 *
    22 */
    23 
    24 
    25 
    26 #include <e32base.h>
    27 #include <e32hashtab.h>
    28 #include <d32usbdescriptors.h>
    29 #include <d32usbdi_hubdriver.h>
    30 #include <d32usbdi.h>
    31 #include <d32otgdi.h>
    32 #include <e32test.h>
    33 
    34 extern RTest gtest;
    35 
    36 namespace NUnitTesting_USBDI
    37 	{
    38 
    39 /**
    40 This class describes an observer for USB bus events reported from the acting
    41 Function Driver Framework (Hub Driver)
    42 */	
    43 class MUsbBusObserver
    44 	{
    45 public:
    46 
    47 /**
    48 Called when a usb client device was connected to the host and has a bus address
    49 @param aDeviceHandle the unique handle to the device
    50 */
    51 	virtual void DeviceInsertedL(TUint aDeviceHandle) = 0;
    52 	
    53 /**
    54 Called when a previously connected usb device has disconnected from the bus
    55 @param aDeviceHandle the handle to the device that has just disconnected.
    56 	   This handle will (after this function) now be void
    57 */
    58 	virtual void DeviceRemovedL(TUint aDeviceHandle) = 0;
    59 	
    60 /**
    61 Called when there has been a error on the bus as seen by the Hub Driver
    62 @param aError the bus error code
    63 */
    64 	virtual void BusErrorL(TInt aError) = 0;
    65 	
    66 /**
    67 Called when the device has changed state
    68 @param aPreviousState the previous state of the device
    69 @param aNewState the now new observerd state of the device
    70 @param aCompletionCode the comletion code of state change
    71 */
    72 	virtual void DeviceStateChangeL(RUsbDevice::TDeviceState aPreviousState,RUsbDevice::TDeviceState aNewState,
    73 		TInt aCompletionCode) = 0;
    74 	};
    75 
    76 
    77 
    78 
    79 /**
    80 This class represents the host side object for a USB test device.  This means a device that
    81 is connected to the bus.
    82 */
    83 class CUsbTestDevice : public CActive
    84 	{
    85 public:
    86 /**
    87 Construct a USB bus connected device
    88 @param aHubDriver the USB hub driver object
    89 @param aDeviceHandle the unique handle value to the device
    90 @param aObserver the 
    91 */
    92 	static CUsbTestDevice* NewL(RUsbHubDriver& aHubDriver,TUint aDeviceHandle,MUsbBusObserver& aObserver);	
    93 	
    94 /**
    95 Destructor
    96 */
    97 	~CUsbTestDevice();
    98 	
    99 /**
   100 Obtain the USB specification that this device complies to
   101 @return the usb compliance specification
   102 */
   103 	TUint16 DeviceSpec() const;
   104 	
   105 /**
   106 Obtain the Identity of the product
   107 @return the product identity
   108 */
   109 	TUint16 ProductId() const;
   110 	
   111 /**
   112 Obtain the Identity of the vendor
   113 @return the vendor identity
   114 */
   115 	TUint16 VendorId() const;
   116 	
   117 /**
   118 Obtain the product string for the connected device
   119 @return the device's product string
   120 */
   121 	const TDesC16& Product() const;
   122 	
   123 /**
   124 Obtani the configuration string for the connected device
   125 @return the device's configuration string
   126 */
   127 	const TDesC16& ConfigurationString() const;
   128 	
   129 /**
   130 Obtain the serial number of the connected device
   131 @return the device's serial number
   132 */
   133 	const TDesC16& SerialNumber() const;
   134 	
   135 /**
   136 Obtain the manufacturer of the connected device
   137 @return the manufacturer as string
   138 */
   139 	const TDesC16& Manufacturer() const;
   140 	
   141 /**
   142 Access the raw referrence to the USB device API object
   143 @return a referrence to the RUsbDevice object
   144 */
   145 	RUsbDevice& Device();
   146 	
   147 /**
   148 Access the device descriptor
   149 @return a referrence to the device descriptor
   150 */	
   151 const TUsbDeviceDescriptor& DeviceDescriptor() const;
   152 
   153 /**
   154 Access the configuration descriptor
   155 @return a referrence to the configuration descriptor
   156 */
   157 const TUsbConfigurationDescriptor& ConfigurationDescriptor() const;
   158 
   159 
   160 protected:
   161 
   162 /**
   163 Constructor, build a host side usb test object
   164 @param aHubDriver the USB host hub driver
   165 @param aHandle the unique handle to the usb device
   166 @param aObserver the observer of usb host bus events
   167 */
   168 	CUsbTestDevice(RUsbHubDriver& aHubDriver,TUint aHandle,MUsbBusObserver& aObserver);
   169 	
   170 /**
   171 2nd phase construction
   172 */
   173 	void ConstructL();
   174 	
   175 protected: // From CActive
   176 
   177 /**
   178 Cancels the current asynchronous activity of this test device
   179 */
   180 	void DoCancel();
   181 	
   182 /**
   183 */
   184 	void RunL();
   185 	
   186 /** 
   187 */
   188 	TInt RunError(TInt aError);
   189 	
   190 private:
   191 	RUsbHubDriver& iDriver;
   192 	RUsbDevice::TDeviceState iCurrentState;
   193 	TUint iHandle;
   194 	RUsbDevice iDevice;
   195 	TUsbDeviceDescriptor iDeviceDescriptor;
   196 	TUsbConfigurationDescriptor iConfigDescriptor;
   197 	TUint16 iDeviceSpec;
   198 	TUint16 iPid;
   199 	TUint16 iVid;
   200 	
   201 /**
   202 The observer of events on the bus bus, noticed by the host hub driver
   203 */	
   204 	MUsbBusObserver& iObserver;	
   205 	
   206 /**
   207 The string for the configuration
   208 */
   209 	TUsbStringDescriptor* iConfigStringDesc;
   210 	TBuf8<255> iConfigStringData;
   211 	TBuf16<128> iConfigString;
   212 	
   213 /**
   214 The string for the manufacturer
   215 */
   216 	TUsbStringDescriptor* iManufacturerStringDesc;
   217 	TBuf8<255> iManufacturerStringData;
   218 	TBuf16<128> iManufacturerString;
   219 	
   220 /**
   221 The string for the product name
   222 */
   223 	TUsbStringDescriptor* iProductStringDesc;
   224 	TBuf8<255> iProductStringData;
   225 	TBuf16<128> iProductString;
   226 	
   227 /**
   228 The string for the serial number
   229 */
   230 	TUsbStringDescriptor* iSerialNumberDesc;
   231 	TBuf8<255> iSerialNumberStringData;
   232 	TBuf16<128> iSerialNumber;
   233 	};
   234 	
   235 /**
   236 This class represents a minimal version of the Function driver framework.
   237 This will usually manage more than one device but only one device can currently be supported.
   238 The actual FDF has well defined responsibilities but this actor FDF will be controlled by the
   239 current test case running.
   240 */
   241 class CActorFDF : public CActive
   242 	{
   243 public:
   244 
   245 /**
   246 Factory construction of the acting Function Driver Framework
   247 @param aNotifier the notifier 
   248 */
   249 	static CActorFDF* NewL(MUsbBusObserver& aObserver);
   250 	virtual ~CActorFDF();
   251 
   252 	void Monitor();
   253 	
   254 	CUsbTestDevice& DeviceL(TUint aDeviceHandle);
   255 	
   256 private:
   257 	CActorFDF(MUsbBusObserver& aObserver);
   258 	void ConstructL();
   259 		
   260 private:
   261 	void DoCancel();
   262 	void RunL();
   263 	TInt RunError(TInt aError);
   264 
   265 
   266 private:
   267 	RUsbHubDriver iDriver;
   268 	RHashMap<TUint,CUsbTestDevice*> iDevices;
   269 	RUsbHubDriver::TBusEvent iBusEvent;
   270 	MUsbBusObserver& iObserver;	
   271 	RProcess iOtgUsbMan;	 	
   272 	};	
   273 	
   274 	
   275 	}
   276 
   277 
   278 #endif