os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/src/host_usbmsapp.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// USB Mass Storage Application - also used as an improvised boot loader mechanism
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file
sl@0
    22
*/
sl@0
    23
sl@0
    24
#include <e32test.h>
sl@0
    25
#include <f32file.h>
sl@0
    26
#include <d32usbdi_hubdriver.h>
sl@0
    27
sl@0
    28
#include "rusbhostmsdevice.h"
sl@0
    29
#include "rextfilesystem.h"
sl@0
    30
#include "cusbmsmountmanager.h"
sl@0
    31
#include "cusbhost.h"
sl@0
    32
#include "appdebug.h"
sl@0
    33
sl@0
    34
sl@0
    35
_LIT(KTxtApp,"USBHOSTMSAPP");
sl@0
    36
sl@0
    37
LOCAL_D RTest test(_L("MSAPP HOST TEST"));
sl@0
    38
sl@0
    39
sl@0
    40
GLDEF_C void RunAppL()
sl@0
    41
    {
sl@0
    42
	test.Title();
sl@0
    43
	test.Start(_L("Mass Storage Host Tests"));
sl@0
    44
sl@0
    45
    CUsbHost* host = CUsbHost::NewL();
sl@0
    46
sl@0
    47
    host->OpenHubL();
sl@0
    48
sl@0
    49
	test.Printf(_L("Build up bus events. Press any key to start consuming"));
sl@0
    50
	test.Getch();
sl@0
    51
sl@0
    52
    TInt deviceCount = 0;
sl@0
    53
    for (;;)
sl@0
    54
        {
sl@0
    55
        test.Next(_L("Wait for device attach"));
sl@0
    56
        RUsbHubDriver::TBusEvent::TEvent event = host->WaitForBusEvent();
sl@0
    57
sl@0
    58
        if (event == RUsbHubDriver::TBusEvent::EDeviceAttached)
sl@0
    59
            {
sl@0
    60
            /* Jungo stack has attached the device */
sl@0
    61
            TUint32 token = host->OpenDeviceL();
sl@0
    62
            host->MountDeviceL();
sl@0
    63
            deviceCount++;
sl@0
    64
            __PRINT1(_L("%d device(s) attached"), deviceCount);
sl@0
    65
            }
sl@0
    66
        else if (event == RUsbHubDriver::TBusEvent::EDeviceRemoved)
sl@0
    67
            {
sl@0
    68
            host->DismountDeviceL();
sl@0
    69
            host->CloseDeviceL();
sl@0
    70
sl@0
    71
            __PRINT1(_L("%d device(s) attached"), deviceCount);
sl@0
    72
sl@0
    73
            if (--deviceCount == 0)
sl@0
    74
                {
sl@0
    75
                break;
sl@0
    76
                }
sl@0
    77
            }
sl@0
    78
sl@0
    79
        else
sl@0
    80
            {
sl@0
    81
            // nothing to do
sl@0
    82
            }
sl@0
    83
        }
sl@0
    84
sl@0
    85
sl@0
    86
    test.Printf(_L("Press a key to dismount\n"));
sl@0
    87
sl@0
    88
    test.Getch();
sl@0
    89
sl@0
    90
    host->DismountAllFileSystemsL();
sl@0
    91
    host->CloseAllDevicesL();
sl@0
    92
    host->CloseHubL();
sl@0
    93
sl@0
    94
    delete host;
sl@0
    95
sl@0
    96
	// 1 sec delay for sessions to stop
sl@0
    97
	User::After(1000000);
sl@0
    98
sl@0
    99
    test.End();
sl@0
   100
    test.Close();
sl@0
   101
    }
sl@0
   102
sl@0
   103
sl@0
   104
sl@0
   105
GLDEF_C TInt E32Main()
sl@0
   106
	{
sl@0
   107
	__UHEAP_MARK;
sl@0
   108
	CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   109
    test(cleanup != NULL);
sl@0
   110
	TRAPD(error, RunAppL());
sl@0
   111
	__ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));
sl@0
   112
	delete cleanup;
sl@0
   113
	__UHEAP_MARKEND;
sl@0
   114
	return 0;
sl@0
   115
	}