usbmgmt/usbmgr/usbman/server/INC/CUsbDevice.h
changeset 0 c9bc50fca66e
child 15 f92a4f87e424
equal deleted inserted replaced
-1:000000000000 0:c9bc50fca66e
       
     1 /**
       
     2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 * Implements the main object of Usbman that manages all the USB Classes
       
    16 * and the USB Logical Device (via CUsbDeviceStateWatcher).
       
    17 * 
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 
       
    23 /**
       
    24  @file
       
    25 */
       
    26 
       
    27 #ifndef __CUSBDEVICE_H__
       
    28 #define __CUSBDEVICE_H__
       
    29 
       
    30 #include <usbstates.h>
       
    31 #include <musbclasscontrollernotify.h>
       
    32 #include <ecom/ecom.h>
       
    33 #include <d32usbc.h>
       
    34 #include <e32std.h>
       
    35 #include <usb/usblogger.h>
       
    36 #include <musbmanextensionpluginobserver.h>
       
    37 
       
    38 class CUsbDeviceStateWatcher;
       
    39 class CUsbClassControllerBase;
       
    40 class CUsbServer;
       
    41 class MUsbDeviceNotify;
       
    42 class CPersonality;
       
    43 class CUsbmanExtensionPlugin;
       
    44 
       
    45 const TUid KUidUsbPlugIns = {0x101fbf21};
       
    46 
       
    47 /**
       
    48  * The CUsbDevice class
       
    49  *
       
    50  * Implements the main object of Usbman that manages all the USB Classes
       
    51  * and the USB Logical Device (via CUsbDeviceStateWatcher).
       
    52  * It owns one instance of CUsbDeviceStateWatcher and an instance of each USB 
       
    53  * Class Controller (CUsbClassControllerBase derived).
       
    54  * It also owns an instance of RDevUsbcClient, a handle on the logical device
       
    55  * driver for USB for Symbian OS.
       
    56  * It implements the MUsbClassControllerNotify mixin so all Usb Class
       
    57  * Controllers can notify it of any changes in their state.
       
    58  *
       
    59  * CUsbDevice is an active object which starts and stops Usb Class Controllers
       
    60  * asynchronously, one by one. Its RunL function will be called after each
       
    61  * start/stop.
       
    62  */
       
    63 NONSHARABLE_CLASS(CUsbDevice) : public CActive, public MUsbClassControllerNotify, public MUsbmanExtensionPluginObserver
       
    64 	{
       
    65 public:
       
    66 	class TUsbDeviceDescriptor
       
    67 		{
       
    68 	public:
       
    69 		TUint8	iLength;
       
    70 		TUint8  iDescriptorType;
       
    71 		TUint16	iBcdUsb;
       
    72 		TUint8  iDeviceClass;
       
    73 		TUint8  iDeviceSubClass;
       
    74 		TUint8  iDeviceProtocol;
       
    75 		TUint8  iMaxPacketSize;
       
    76 		TUint16 iIdVendor;
       
    77 		TUint16	iIdProduct;
       
    78 		TUint16	iBcdDevice;
       
    79 		TUint8  iManufacturer;
       
    80 		TUint8  iProduct;
       
    81 		TUint8  iSerialNumber;
       
    82 		TUint8  iNumConfigurations;
       
    83 		};
       
    84 
       
    85 public:
       
    86 	static CUsbDevice* NewL(CUsbServer& aUsbServer);
       
    87 	virtual ~CUsbDevice();
       
    88 
       
    89  	void EnumerateClassControllersL();
       
    90 	void AddClassControllerL(CUsbClassControllerBase* aClassController, TLinearOrder<CUsbClassControllerBase> order);
       
    91 
       
    92 	void RegisterObserverL(MUsbDeviceNotify& aObserver);
       
    93 	void DeRegisterObserver(MUsbDeviceNotify& aObserver);
       
    94 
       
    95 	void StartL();
       
    96 	void Stop();
       
    97 
       
    98 	inline TInt LastError() const;
       
    99 	inline RDevUsbcClient& UsbBus();
       
   100 	inline TUsbDeviceState DeviceState() const;
       
   101 	inline TUsbServiceState ServiceState() const;
       
   102 	inline TBool isPersonalityCfged() const;
       
   103 	
       
   104 	void SetServiceState(TUsbServiceState aState);
       
   105 	void SetDeviceState(TUsbcDeviceState aState);
       
   106 
       
   107 	void BusEnumerationCompleted();
       
   108 	void BusEnumerationFailed(TInt aError);
       
   109 	
       
   110 	void TryStartL(TInt aPersonalityId);
       
   111 	TInt CurrentPersonalityId() const;
       
   112 	const RPointerArray<CPersonality>& Personalities() const;
       
   113 	const CPersonality* GetPersonality(TInt aPersonalityId) const;
       
   114 	void ValidatePersonalitiesL();
       
   115 	void ReadPersonalitiesL();
       
   116 	void SetDefaultPersonalityL();
       
   117 	void LoadFallbackClassControllersL();
       
   118 	
       
   119 public: // From CActive
       
   120 	void RunL();
       
   121 	void DoCancel();
       
   122 	TInt RunError(TInt aError);
       
   123 
       
   124 public: // Inherited from MUsbClassControllerNotify
       
   125 	CUsbClassControllerIterator* UccnGetClassControllerIteratorL();
       
   126 	void UccnError(TInt aError);
       
   127 
       
   128 public: // from MUsbmanExtensionPluginObserver
       
   129 	RDevUsbcClient& MuepoDoDevUsbcClient();
       
   130 	void MuepoDoRegisterStateObserverL(MUsbDeviceNotify& aObserver);
       
   131 
       
   132 protected:
       
   133 	CUsbDevice(CUsbServer& aUsbServer);
       
   134 	void ConstructL();
       
   135 	void StartCurrentClassController();
       
   136 	void StopCurrentClassController();
       
   137 
       
   138 private:
       
   139 	void SetDeviceDescriptorL();
       
   140 	void SetUsbDeviceSettingsL(TUsbDeviceDescriptor& aDeviceDescriptor);
       
   141 	void SetUsbDeviceSettingsDefaultsL(TUsbDeviceDescriptor& aDeviceDescriptor);
       
   142 	void SelectClassControllersL();
       
   143 	void SetCurrentPersonalityL(TInt aPersonalityId);
       
   144 	void SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor);
       
   145 	void ResourceFileNameL(TFileName& aFileName);
       
   146 	void CreateClassControllersL(const RArray<TUid>& aClassUids);
       
   147 	void ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray);
       
   148 	TInt PowerUpAndConnect();	
       
   149 #ifdef __FLOG_ACTIVE
       
   150 	void PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor);
       
   151 #endif
       
   152 	void InstantiateExtensionPluginsL();
       
   153 private:
       
   154 	RPointerArray<CUsbClassControllerBase> iSupportedClasses;
       
   155 	RPointerArray<MUsbDeviceNotify> iObservers;
       
   156 	RPointerArray<CUsbmanExtensionPlugin> iExtensionPlugins;
       
   157 	TUsbDeviceState  iDeviceState;
       
   158 	TUsbServiceState iServiceState;
       
   159 	TInt iLastError;
       
   160 	RDevUsbcClient iLdd;
       
   161 	CUsbDeviceStateWatcher* iDeviceStateWatcher;
       
   162 	CUsbServer& iUsbServer;
       
   163 	CUsbClassControllerIterator* iUsbClassControllerIterator;
       
   164 	const CPersonality* iCurrentPersonality;
       
   165 	RPointerArray<CPersonality> iSupportedPersonalities;
       
   166 	RArray<TUid> iSupportedClassUids;
       
   167 	TBool iPersonalityCfged;
       
   168 	TBool iUdcSupportsCableDetectWhenUnpowered;
       
   169 	HBufC16* iDefaultSerialNumber;
       
   170 	
       
   171 	REComSession* iEcom;	//	Not to be deleted, only closed!
       
   172 	};
       
   173 
       
   174 #include "CUsbDevice.inl"
       
   175 
       
   176 #endif
       
   177