os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragecontroller.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragecontroller.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,185 @@
     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 +// CUsbMassStorageController implementation.
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +
    1.22 +
    1.23 +/**
    1.24 + @file
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +
    1.28 +#include <e32base.h>
    1.29 +#include <d32usbc.h>
    1.30 +
    1.31 +#include "mstypes.h"
    1.32 +#include "msctypes.h"
    1.33 +#include "testman.h"
    1.34 +#include "drivemanager.h"
    1.35 +
    1.36 +#include "tscsiserverreq.h"
    1.37 +#include "tscsiservercmds.h"
    1.38 +#include "mserverprotocol.h"
    1.39 +#include "cscsiserverprotocol.h"
    1.40 +#include "mdevicetransport.h"
    1.41 +#include "cbulkonlytransport.h"
    1.42 +
    1.43 +#include "cusbmassstorageserver.h"
    1.44 +#include "cusbmassstoragecontroller.h"
    1.45 +#include "debug.h"
    1.46 +#include "msdebug.h"
    1.47 +
    1.48 +
    1.49 +
    1.50 +
    1.51 +CUsbMassStorageController* CUsbMassStorageController::NewL()
    1.52 +    {
    1.53 +    __MSFNSLOG
    1.54 +	CUsbMassStorageController* self = new (ELeave) CUsbMassStorageController();
    1.55 +	CleanupStack::PushL(self);
    1.56 +	self->ConstructL();
    1.57 +	CleanupStack::Pop();
    1.58 +	return self;
    1.59 +    }
    1.60 +
    1.61 +
    1.62 +CUsbMassStorageController::CUsbMassStorageController()
    1.63 +    {
    1.64 +    }
    1.65 +
    1.66 +
    1.67 +void CUsbMassStorageController::ConstructL()
    1.68 +	{
    1.69 +#ifdef MSDC_TESTMODE
    1.70 +    // TestParser for modifying client behaviour to create  BOT 13 Case device
    1.71 +    // exceptions conditions
    1.72 +    __TESTMODEPRINT("Test Mode is active");
    1.73 +    iTestParser = new (ELeave) TTestParser;
    1.74 +#endif
    1.75 +	}
    1.76 +
    1.77 +/**
    1.78 +Destructor
    1.79 +*/
    1.80 +CUsbMassStorageController::~CUsbMassStorageController()
    1.81 +	{
    1.82 +    __MSFNLOG
    1.83 +	delete iServer;
    1.84 +	delete iProtocol;
    1.85 +	delete iTransport;
    1.86 +	delete iDriveManager;
    1.87 +	}
    1.88 +
    1.89 +/**
    1.90 +Creates the drive manager, transport, protocol and server
    1.91 +
    1.92 +@param aMaxDrives Maximum number of Mass Storage drives supported.
    1.93 +*/
    1.94 +void CUsbMassStorageController::CreateL(const TLunToDriveMap& aDriveMapping)
    1.95 +	{
    1.96 +    __MSFNLOG
    1.97 +	//Create and init drive manager
    1.98 +	iDriveManager = CDriveManager::NewL(aDriveMapping);
    1.99 +
   1.100 +	//Create transport and protocol and initialize them
   1.101 +	__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
   1.102 +#ifdef MSDC_TESTMODE
   1.103 +	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this, iTestParser);
   1.104 +	iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser);
   1.105 +#else
   1.106 +	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this);
   1.107 +	iProtocol = CScsiServerProtocol::NewL(*iDriveManager);
   1.108 +#endif
   1.109 +	iTransport->RegisterProtocol(*iProtocol);
   1.110 +	iProtocol->RegisterTransport(iTransport);
   1.111 +
   1.112 +	//Create and start server
   1.113 +	__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
   1.114 +	iServer = CUsbMassStorageServer::NewLC(*this);
   1.115 +	CleanupStack::Pop(iServer);
   1.116 +	}
   1.117 +
   1.118 +/**
   1.119 +Returns a reference to the drive manager
   1.120 +
   1.121 +@return A reference to the drive manager
   1.122 +*/
   1.123 +CDriveManager& CUsbMassStorageController::DriveManager()
   1.124 +	{
   1.125 +    __MSFNLOG
   1.126 +	return *iDriveManager;
   1.127 +	}
   1.128 +
   1.129 +/**
   1.130 +Starts the transport and initializes the protocol.
   1.131 +
   1.132 +@param aConfig Reference to Mass Storage configuration data
   1.133 +*/
   1.134 +TInt CUsbMassStorageController::Start(const TMassStorageConfig& aConfig)
   1.135 +	{
   1.136 +    __MSFNLOG
   1.137 +	//Save this value for use in the Reset method.
   1.138 +	iConfig = aConfig;
   1.139 +	TInt err = KErrNotReady;
   1.140 +	if (iProtocol && iTransport)
   1.141 +		{
   1.142 +		__PRINT(_L("CUsbMassStorageController::Start: Starting"));
   1.143 +		iProtocol->SetParameters(aConfig);
   1.144 +		err = iTransport->Start();
   1.145 +		}
   1.146 +	return err;
   1.147 +	}
   1.148 +
   1.149 +/**
   1.150 +Stops the transport.
   1.151 +*/
   1.152 +TInt CUsbMassStorageController::Stop()
   1.153 +	{
   1.154 +    __MSFNLOG
   1.155 +	TInt err = KErrNotReady;
   1.156 +	if (iTransport)
   1.157 +		{
   1.158 +		__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   1.159 +		err = iTransport->Stop();
   1.160 +		}
   1.161 +
   1.162 +	iDriveManager->SetCritical(CDriveManager::KAllLuns, EFalse);   //unset critical
   1.163 +	return err;
   1.164 +	}
   1.165 +
   1.166 +/**
   1.167 +Delete the transport and protocol and start new ones.
   1.168 +*/
   1.169 +void CUsbMassStorageController::Reset()
   1.170 +	{
   1.171 +    __MSFNLOG
   1.172 +	delete iProtocol;
   1.173 +	iProtocol = NULL;
   1.174 +
   1.175 +	//Create transport and protocol and initialize them
   1.176 +	__PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   1.177 +
   1.178 +#ifdef MSDC_TESTMODE
   1.179 +	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser));
   1.180 +#else
   1.181 +	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager));
   1.182 +#endif
   1.183 +	err = err;
   1.184 +	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
   1.185 +	iTransport->RegisterProtocol(*iProtocol);
   1.186 +	iProtocol->RegisterTransport(iTransport);
   1.187 +    iProtocol->SetParameters(iConfig);
   1.188 +	}