1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/src/host_usbmsapp.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,115 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// USB Mass Storage Application - also used as an improvised boot loader mechanism
1.18 +//
1.19 +//
1.20 +
1.21 +
1.22 +
1.23 +/**
1.24 + @file
1.25 +*/
1.26 +
1.27 +#include <e32test.h>
1.28 +#include <f32file.h>
1.29 +#include <d32usbdi_hubdriver.h>
1.30 +
1.31 +#include "rusbhostmsdevice.h"
1.32 +#include "rextfilesystem.h"
1.33 +#include "cusbmsmountmanager.h"
1.34 +#include "cusbhost.h"
1.35 +#include "appdebug.h"
1.36 +
1.37 +
1.38 +_LIT(KTxtApp,"USBHOSTMSAPP");
1.39 +
1.40 +LOCAL_D RTest test(_L("MSAPP HOST TEST"));
1.41 +
1.42 +
1.43 +GLDEF_C void RunAppL()
1.44 + {
1.45 + test.Title();
1.46 + test.Start(_L("Mass Storage Host Tests"));
1.47 +
1.48 + CUsbHost* host = CUsbHost::NewL();
1.49 +
1.50 + host->OpenHubL();
1.51 +
1.52 + test.Printf(_L("Build up bus events. Press any key to start consuming"));
1.53 + test.Getch();
1.54 +
1.55 + TInt deviceCount = 0;
1.56 + for (;;)
1.57 + {
1.58 + test.Next(_L("Wait for device attach"));
1.59 + RUsbHubDriver::TBusEvent::TEvent event = host->WaitForBusEvent();
1.60 +
1.61 + if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
1.62 + {
1.63 + /* Jungo stack has attached the device */
1.64 + TUint32 token = host->OpenDeviceL();
1.65 + host->MountDeviceL();
1.66 + deviceCount++;
1.67 + __PRINT1(_L("%d device(s) attached"), deviceCount);
1.68 + }
1.69 + else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
1.70 + {
1.71 + host->DismountDeviceL();
1.72 + host->CloseDeviceL();
1.73 +
1.74 + __PRINT1(_L("%d device(s) attached"), deviceCount);
1.75 +
1.76 + if (--deviceCount == 0)
1.77 + {
1.78 + break;
1.79 + }
1.80 + }
1.81 +
1.82 + else
1.83 + {
1.84 + // nothing to do
1.85 + }
1.86 + }
1.87 +
1.88 +
1.89 + test.Printf(_L("Press a key to dismount\n"));
1.90 +
1.91 + test.Getch();
1.92 +
1.93 + host->DismountAllFileSystemsL();
1.94 + host->CloseAllDevicesL();
1.95 + host->CloseHubL();
1.96 +
1.97 + delete host;
1.98 +
1.99 + // 1 sec delay for sessions to stop
1.100 + User::After(1000000);
1.101 +
1.102 + test.End();
1.103 + test.Close();
1.104 + }
1.105 +
1.106 +
1.107 +
1.108 +GLDEF_C TInt E32Main()
1.109 + {
1.110 + __UHEAP_MARK;
1.111 + CTrapCleanup* cleanup = CTrapCleanup::New();
1.112 + test(cleanup != NULL);
1.113 + TRAPD(error, RunAppL());
1.114 + __ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));
1.115 + delete cleanup;
1.116 + __UHEAP_MARKEND;
1.117 + return 0;
1.118 + }