Update contrib.
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <d32usbdi_hubdriver.h>
19 #include <d32usbdescriptors.h>
20 #include <d32usbtransfers.h>
21 #include <e32property.h>
25 #include "rusbhostmsdevice.h"
26 #include "rusbhostmslogicalunit.h"
27 #include "rextfilesystem.h"
28 #include "cusbmsmountmanager.h"
30 #include "mdrivedisplay.h"
31 #include "cusbhostao.h"
38 _LIT(KHubDriverLddFileName, "usbhubdriver");
39 _LIT(KUsbdiLddFileName, "usbdi");
42 CUsbHost* CUsbHost::NewL()
45 CUsbHost* r = new (ELeave) CUsbHost();
46 CleanupStack::PushL(r);
54 void CUsbHost::ConstructL()
60 iUsbHostAo = CUsbHostAo::NewL(iHubDriver, iEvent, *this);
62 iMountManager = CUsbMsMountManager::NewL();
77 DismountAllFileSystemsL();
85 void CUsbHost::LoadFileSystemL()
89 User::LeaveIfError(fs.Connect());
90 CleanupClosePushL(fs);
91 _LIT(KFsNm, "elocal");
94 err = fs.AddFileSystem(KFsNm);
95 if (err != KErrAlreadyExists)
96 User::LeaveIfError(err);
98 err = fs.AddFileSystem(_L("ELOCAL"));
99 if (!(KErrAlreadyExists == err || KErrCorrupt == err))
100 User::LeaveIfError(err);
102 err = fs.AddProxyDrive(_L("usbhostms.pxy"));
103 if (!(KErrAlreadyExists == err || KErrCorrupt == err))
104 User::LeaveIfError(err);
106 CleanupStack::PopAndDestroy(&fs);
110 void CUsbHost::OpenHubL()
114 err = User::LoadLogicalDevice(KHubDriverLddFileName);
115 if (err != KErrAlreadyExists)
116 User::LeaveIfError(err);
118 err = User::LoadLogicalDevice(KUsbdiLddFileName);
119 if (err != KErrAlreadyExists)
120 User::LeaveIfError(err);
122 err = iHubDriver.Open();
123 User::LeaveIfError(err);
127 void CUsbHost::CloseHubL()
130 iHubDriver.StopHost();
133 TInt err1 = User::FreeLogicalDevice(KUsbdiLddFileName);
134 __ASSERT_DEBUG(err1==KErrNone, User::Panic(KUsbdiLddFileName, err1));
136 TInt err2 = User::FreeLogicalDevice(KHubDriverLddFileName);
137 __ASSERT_DEBUG(err2==KErrNone, User::Panic(KHubDriverLddFileName, err2));
139 User::LeaveIfError(err1);
140 User::LeaveIfError(err2);
144 TToken CUsbHost::OpenDeviceL()
147 CDevice* device = CDevice::NewL();
150 TRAPD(err, token = device->OpenDeviceL(iDeviceHandle, iHubDriver));
156 iMountManager->AddDeviceL(device);
161 void CUsbHost::CloseDeviceL()
164 CDevice* device = iMountManager->RemoveDeviceL(iDeviceHandle);
165 device->CloseDeviceL();
170 void CUsbHost::CloseAllDevicesL()
173 iMountManager->CloseAllDevicesL();
177 void CUsbHost::MountDeviceL()
180 iMountManager->MountDeviceL(iDeviceHandle);
184 void CUsbHost::DismountDeviceL()
187 iMountManager->DismountDeviceL(iDeviceHandle);
191 void CUsbHost::DismountAllFileSystemsL()
194 iMountManager->DismountL();
198 void CUsbHost::Start()
205 void CUsbHost::ProcessBusEventL()
209 __USBHOSTPRINT2(_L(">> CUsbHost RUsbHubDriver Event[%d] Device Handle = %d"),
210 iEvent.iEventType, iEvent.iDeviceHandle);
211 __USBHOSTPRINT2(_L("Error = %d reason = %x"),
212 iEvent.iError, iEvent.iReason);
214 iDeviceHandle = iEvent.iDeviceHandle;
215 RUsbHubDriver::TBusEvent::TEvent event = iEvent.iEventType;
217 if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
219 /* Jungo stack has attached the device */
220 TUint32 token = OpenDeviceL();
222 __USBHOSTPRINT(_L("CUsbHost: device attached"));
224 else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
226 TRAPD(err, DismountDeviceL());
228 User::LeaveIfError(err);
229 __USBHOSTPRINT(_L("CUsbHost: device removed"));
239 RUsbHubDriver::TBusEvent::TEvent CUsbHost::WaitForBusEvent()
242 TRequestStatus status;
243 RUsbHubDriver::TBusEvent event;
244 TBool eventReceived = EFalse;
247 iHubDriver.WaitForBusEvent(event, status);
248 __USBHOSTPRINT(_L("Waiting..."));
249 User::WaitForRequest(status);
250 __USBHOSTPRINT2(_L(">> CUsbHost RUsbHubDriver Event[%d] Device Handle = %d)"),
251 iEvent.iEventType, iEvent.iDeviceHandle);
252 __USBHOSTPRINT2(_L("Error = %d reason = %x"),
253 iEvent.iError, iEvent.iReason);
255 if (status != KErrNone)
257 __USBHOSTPRINT1(_L("Status error = %d"), status.Int());
259 iDeviceHandle = event.iDeviceHandle;
261 switch (event.iEventType)
263 case RUsbHubDriver::TBusEvent::EDeviceAttached:
264 case RUsbHubDriver::TBusEvent::EDeviceRemoved:
265 eventReceived = ETrue;
271 } while (!eventReceived);
272 return event.iEventType;
277 void CUsbHost::Cancel()
279 iHubDriver.CancelWaitForBusEvent();
283 void CUsbHost::DriveMap(TDriveMap& aDriveMap) const
286 iMountManager->DriveMap(aDriveMap);
290 void CUsbHost::DeviceMap(TInt aDeviceIndex, TDeviceMap& aDeviceMap) const
293 iMountManager->DeviceMap(aDeviceIndex, aDeviceMap);
297 TInt CUsbHost::DevicesNumber() const
299 return iMountManager->DevicesNumber();
303 CUsbHostDisp* CUsbHostDisp::NewL(MDriveDisplay& aDriveDisplay)
306 CUsbHostDisp* r = new (ELeave) CUsbHostDisp(aDriveDisplay);
307 CleanupStack::PushL(r);
314 void CUsbHostDisp::ConstructL()
317 CUsbHost::ConstructL();
321 CUsbHostDisp::CUsbHostDisp(MDriveDisplay& aDriveDisplay)
323 iDriveDisplay(aDriveDisplay)
329 CUsbHostDisp::~CUsbHostDisp()
334 void CUsbHostDisp::ProcessBusEventL()
336 CUsbHost::ProcessBusEventL();
339 iDriveDisplay.DriveListL();
342 TInt devicesNumber = DevicesNumber();
343 iDriveDisplay.DevicesNumber(devicesNumber);
345 // LUNs for each device
346 TDeviceMap deviceMap;
349 for (row = 0, deviceIndex = (devicesNumber - 1); deviceIndex >= 0 ; row++, deviceIndex--)
353 DeviceMap(deviceIndex, deviceMap);
356 iDriveDisplay.DeviceMapL(row, deviceIndex, deviceMap);
359 iDriveDisplay.DeviceMapClear(row);
361 // Display all Drives
365 iDriveDisplay.DriveMapL(driveMap);