kerneltest/f32test/shostmassstorage/msman/src/host_usbmsapp.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // USB Mass Storage Application - also used as an improvised boot loader mechanism
       
    15 // 
       
    16 //
       
    17 
       
    18 
       
    19 
       
    20 /**
       
    21  @file
       
    22 */
       
    23 
       
    24 #include <e32test.h>
       
    25 #include <f32file.h>
       
    26 #include <d32usbdi_hubdriver.h>
       
    27 
       
    28 #include "rusbhostmsdevice.h"
       
    29 #include "rextfilesystem.h"
       
    30 #include "cusbmsmountmanager.h"
       
    31 #include "cusbhost.h"
       
    32 #include "appdebug.h"
       
    33 
       
    34 
       
    35 _LIT(KTxtApp,"USBHOSTMSAPP");
       
    36 
       
    37 LOCAL_D RTest test(_L("MSAPP HOST TEST"));
       
    38 
       
    39 
       
    40 GLDEF_C void RunAppL()
       
    41     {
       
    42 	test.Title();
       
    43 	test.Start(_L("Mass Storage Host Tests"));
       
    44 
       
    45     CUsbHost* host = CUsbHost::NewL();
       
    46 
       
    47     host->OpenHubL();
       
    48 
       
    49 	test.Printf(_L("Build up bus events. Press any key to start consuming"));
       
    50 	test.Getch();
       
    51 
       
    52     TInt deviceCount = 0;
       
    53     for (;;)
       
    54         {
       
    55         test.Next(_L("Wait for device attach"));
       
    56         RUsbHubDriver::TBusEvent::TEvent event = host->WaitForBusEvent();
       
    57 
       
    58         if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
       
    59             {
       
    60             /* Jungo stack has attached the device */
       
    61             TUint32 token = host->OpenDeviceL();
       
    62             host->MountDeviceL();
       
    63             deviceCount++;
       
    64             __PRINT1(_L("%d device(s) attached"), deviceCount);
       
    65             }
       
    66         else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
       
    67             {
       
    68             host->DismountDeviceL();
       
    69             host->CloseDeviceL();
       
    70 
       
    71             __PRINT1(_L("%d device(s) attached"), deviceCount);
       
    72 
       
    73             if (--deviceCount == 0)
       
    74                 {
       
    75                 break;
       
    76                 }
       
    77             }
       
    78 
       
    79         else
       
    80             {
       
    81             // nothing to do
       
    82             }
       
    83         }
       
    84 
       
    85 
       
    86     test.Printf(_L("Press a key to dismount\n"));
       
    87 
       
    88     test.Getch();
       
    89 
       
    90     host->DismountAllFileSystemsL();
       
    91     host->CloseAllDevicesL();
       
    92     host->CloseHubL();
       
    93 
       
    94     delete host;
       
    95 
       
    96 	// 1 sec delay for sessions to stop
       
    97 	User::After(1000000);
       
    98 
       
    99     test.End();
       
   100     test.Close();
       
   101     }
       
   102 
       
   103 
       
   104 
       
   105 GLDEF_C TInt E32Main()
       
   106 	{
       
   107 	__UHEAP_MARK;
       
   108 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   109     test(cleanup != NULL);
       
   110 	TRAPD(error, RunAppL());
       
   111 	__ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));
       
   112 	delete cleanup;
       
   113 	__UHEAP_MARKEND;
       
   114 	return 0;
       
   115 	}