os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/app/husbconsapp.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/app/husbconsapp.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,161 @@
     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 <e32cons.h>
    1.28 +#include <hal.h>
    1.29 +#include <f32file.h>
    1.30 +
    1.31 +#include "rusbhostmsdevice.h"
    1.32 +#include "rusbhostmslogicalunit.h"
    1.33 +
    1.34 +#include <d32usbdi_hubdriver.h>
    1.35 +#include "usbtypes.h"
    1.36 +#include "rextfilesystem.h"
    1.37 +#include "cusbmsmountmanager.h"
    1.38 +
    1.39 +#include "mdrivedisplay.h"
    1.40 +#include "cusbhostao.h"
    1.41 +#include "cusbhost.h"
    1.42 +
    1.43 +#include "rusbotgsession.h"
    1.44 +
    1.45 +#include "cdisplay.h"
    1.46 +#include "husbconsapp.h"
    1.47 +#include "tmslog.h"
    1.48 +
    1.49 +
    1.50 +_LIT(KTxtApp,"HOST USB CONSOLE APP");
    1.51 +
    1.52 +
    1.53 +
    1.54 +CHeartBeat* CHeartBeat::NewLC(CDisplay& aDisplay)
    1.55 +	{
    1.56 +	CHeartBeat* me = new(ELeave) CHeartBeat(aDisplay);
    1.57 +	CleanupStack::PushL(me);
    1.58 +	me->ConstructL();
    1.59 +	return me;
    1.60 +	}
    1.61 +
    1.62 +
    1.63 +CHeartBeat::CHeartBeat(CDisplay& aDisplay)
    1.64 +:   CActive(0),
    1.65 +    iDisplay(aDisplay)
    1.66 +	{}
    1.67 +
    1.68 +
    1.69 +void CHeartBeat::ConstructL()
    1.70 +	{
    1.71 +	CActiveScheduler::Add(this);
    1.72 +	iTimer.CreateLocal();
    1.73 +	RunL();
    1.74 +	}
    1.75 +
    1.76 +
    1.77 +CHeartBeat::~CHeartBeat()
    1.78 +	{
    1.79 +	Cancel();
    1.80 +	}
    1.81 +
    1.82 +
    1.83 +void CHeartBeat::DoCancel()
    1.84 +	{
    1.85 +    iTimer.Cancel();
    1.86 +	}
    1.87 +
    1.88 +
    1.89 +void CHeartBeat::RunL()
    1.90 +	{
    1.91 +	SetActive();
    1.92 +	// Print RAM usage & up time
    1.93 +	iUpTime++;
    1.94 +    iDisplay.UpTime(iUpTime);
    1.95 +
    1.96 +	TInt mem=0;
    1.97 +	if (HAL::Get(HALData::EMemoryRAMFree, mem)==KErrNone)
    1.98 +		{
    1.99 +        iDisplay.MemoryFree(mem);
   1.100 +		}
   1.101 +	iTimer.After(iStatus, 1000000);
   1.102 +	}
   1.103 +
   1.104 +
   1.105 +GLDEF_C void RunAppL()
   1.106 +    {
   1.107 +    __MSFNSLOG
   1.108 +    CActiveScheduler* sched = new(ELeave) CActiveScheduler;
   1.109 +    CleanupStack::PushL(sched);
   1.110 +    CActiveScheduler::Install(sched);
   1.111 +
   1.112 +    RFs fs;
   1.113 +    User::LeaveIfError(fs.Connect());
   1.114 +    CleanupClosePushL(fs);
   1.115 +
   1.116 +    RUsbOtgSession usbOtgSession;
   1.117 +    TInt err = usbOtgSession.Connect();
   1.118 +    User::LeaveIfError(err);
   1.119 +
   1.120 +    CConsoleBase* console;
   1.121 +	console = Console::NewL(KTxtApp, TSize(KConsFullScreen,KConsFullScreen));
   1.122 +	CleanupStack::PushL(console);
   1.123 +
   1.124 +    CDisplay* display = CDisplay::NewLC(fs, *console);
   1.125 +	CMessageKeyProcessor::NewLC(*display, usbOtgSession);
   1.126 +    CHeartBeat::NewLC(*display);
   1.127 +
   1.128 +    display->Menu();
   1.129 +    display->DriveListL();
   1.130 +
   1.131 +
   1.132 +    CUsbHostDisp* usbHost = CUsbHostDisp::NewL(*display);
   1.133 +    CleanupStack::PushL(usbHost);
   1.134 +
   1.135 +    usbHost->Start();
   1.136 +
   1.137 +    // *************************************************************************
   1.138 +    // Start Active Scheduler
   1.139 +    // *************************************************************************
   1.140 +    CActiveScheduler::Start();
   1.141 +
   1.142 +	// 1 sec delay for sessions to stop
   1.143 +	User::After(1000000);
   1.144 +    CleanupStack::PopAndDestroy(usbHost);
   1.145 +    CleanupStack::PopAndDestroy();  // CPeriodUpdate
   1.146 +    CleanupStack::PopAndDestroy();  // CMessageKeyProcessor
   1.147 +    CleanupStack::PopAndDestroy();  // CDisplay
   1.148 +    CleanupStack::PopAndDestroy(console);
   1.149 +    CleanupStack::PopAndDestroy();  // fs
   1.150 +    CleanupStack::PopAndDestroy(sched);
   1.151 +    }
   1.152 +
   1.153 +
   1.154 +
   1.155 +GLDEF_C TInt E32Main()
   1.156 +	{
   1.157 +	__UHEAP_MARK;
   1.158 +	CTrapCleanup* cleanup = CTrapCleanup::New();
   1.159 +	TRAPD(error, RunAppL());
   1.160 +	__ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));
   1.161 +	delete cleanup;
   1.162 +	__UHEAP_MARKEND;
   1.163 +	return 0;
   1.164 +	}