sl@0: // Copyright (c) 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: // USB Mass Storage Application - also used as an improvised boot loader mechanism sl@0: // sl@0: // sl@0: sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "rusbhostmsdevice.h" sl@0: #include "rextfilesystem.h" sl@0: #include "cusbmsmountmanager.h" sl@0: #include "cusbhost.h" sl@0: #include "appdebug.h" sl@0: sl@0: sl@0: _LIT(KTxtApp,"USBHOSTMSAPP"); sl@0: sl@0: LOCAL_D RTest test(_L("MSAPP HOST TEST")); sl@0: sl@0: sl@0: GLDEF_C void RunAppL() sl@0: { sl@0: test.Title(); sl@0: test.Start(_L("Mass Storage Host Tests")); sl@0: sl@0: CUsbHost* host = CUsbHost::NewL(); sl@0: sl@0: host->OpenHubL(); sl@0: sl@0: test.Printf(_L("Build up bus events. Press any key to start consuming")); sl@0: test.Getch(); sl@0: sl@0: TInt deviceCount = 0; sl@0: for (;;) sl@0: { sl@0: test.Next(_L("Wait for device attach")); sl@0: RUsbHubDriver::TBusEvent::TEvent event = host->WaitForBusEvent(); sl@0: sl@0: if (event == RUsbHubDriver::TBusEvent::EDeviceAttached) sl@0: { sl@0: /* Jungo stack has attached the device */ sl@0: TUint32 token = host->OpenDeviceL(); sl@0: host->MountDeviceL(); sl@0: deviceCount++; sl@0: __PRINT1(_L("%d device(s) attached"), deviceCount); sl@0: } sl@0: else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved) sl@0: { sl@0: host->DismountDeviceL(); sl@0: host->CloseDeviceL(); sl@0: sl@0: __PRINT1(_L("%d device(s) attached"), deviceCount); sl@0: sl@0: if (--deviceCount == 0) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: sl@0: else sl@0: { sl@0: // nothing to do sl@0: } sl@0: } sl@0: sl@0: sl@0: test.Printf(_L("Press a key to dismount\n")); sl@0: sl@0: test.Getch(); sl@0: sl@0: host->DismountAllFileSystemsL(); sl@0: host->CloseAllDevicesL(); sl@0: host->CloseHubL(); sl@0: sl@0: delete host; sl@0: sl@0: // 1 sec delay for sessions to stop sl@0: User::After(1000000); sl@0: sl@0: test.End(); sl@0: test.Close(); sl@0: } sl@0: sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: __UHEAP_MARK; sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: test(cleanup != NULL); sl@0: TRAPD(error, RunAppL()); sl@0: __ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error)); sl@0: delete cleanup; sl@0: __UHEAP_MARKEND; sl@0: return 0; sl@0: }