os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cusbmassstoragecontroller.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cusbmassstoragecontroller.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,164 @@
     1.4 +// Copyright (c) 2004-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 + @file
    1.23 + @internalTechnology
    1.24 +*/
    1.25 +
    1.26 +#include "cusbmassstoragecontroller.h"
    1.27 +#include "massstoragedebug.h"
    1.28 +#include "scsiprot.h"
    1.29 +#include "cbulkonlytransport.h"
    1.30 +
    1.31 +/**
    1.32 +Destructor
    1.33 +*/
    1.34 +CUsbMassStorageController::~CUsbMassStorageController()
    1.35 +	{
    1.36 +	delete iServer;
    1.37 +	delete iProtocol;
    1.38 +	delete iTransport;
    1.39 +	delete iDriveManager;
    1.40 +	}
    1.41 +
    1.42 +/**
    1.43 +Creates the drive manager, transport, protocol and server
    1.44 +
    1.45 +@param aMaxDrives Maximum number of Mass Storage drives supported.
    1.46 +*/
    1.47 +void CUsbMassStorageController::CreateL(RArray<TInt>& aDriveMapping)
    1.48 +	{
    1.49 +	__PRINT(_L("CUsbMassStorageController::CreateL In"));
    1.50 +	iTransportLddFlag = EUsbcsc; // Create transport object using SC Ldd By default
    1.51 +	//Save this value for use in the Reset method.
    1.52 +	iMaxDrives = aDriveMapping.Count();
    1.53 +	//Create and init drive manager
    1.54 +	iDriveManager = CDriveManager::NewL(aDriveMapping);
    1.55 +
    1.56 +	//Create transport and protocol and initialize them
    1.57 +	__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
    1.58 +	iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
    1.59 +	if (!iTransport)
    1.60 +		User::Leave(KErrNoMemory);
    1.61 +
    1.62 +	iProtocol = CScsiProtocol::NewL(*iDriveManager);
    1.63 +
    1.64 +	//Create and start server
    1.65 +	__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
    1.66 +	iServer = CUsbMassStorageServer::NewLC(*this);
    1.67 +	CleanupStack::Pop(iServer);
    1.68 +	__PRINT(_L("CUsbMassStorageController::CreateL Out"));
    1.69 +	}
    1.70 +
    1.71 +/**
    1.72 +Returns a reference to the drive manager
    1.73 +
    1.74 +@return A reference to the drive manager
    1.75 +*/
    1.76 +CDriveManager& CUsbMassStorageController::DriveManager()
    1.77 +	{
    1.78 +	return *iDriveManager;
    1.79 +	}
    1.80 +
    1.81 +
    1.82 +void CUsbMassStorageController::GetTransport(MTransportBase* &aTransport)
    1.83 +	{
    1.84 +	aTransport = iTransport; 
    1.85 +	}
    1.86 +
    1.87 +/**
    1.88 +Starts the transport and initializes the protocol.
    1.89 +
    1.90 +@param aConfig Reference to Mass Storage configuration data
    1.91 +*/
    1.92 +TInt CUsbMassStorageController::Start(TMassStorageConfig& aConfig)
    1.93 +	{
    1.94 +	__PRINT(_L("CUsbMassStorageController::Start In"));
    1.95 +	//Save this value for use in the Reset method.
    1.96 +	iConfig = aConfig;
    1.97 +
    1.98 +    __ASSERT_DEBUG(iTransport, User::Invariant());
    1.99 +	if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
   1.100 +		{
   1.101 +		iTransportLddFlag = EUsbc; // If SC Ldd not present use the default USB Client Ldd
   1.102 +		delete iTransport;
   1.103 +		iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
   1.104 +		if (!iTransport)
   1.105 +			User::Leave(KErrNoMemory);
   1.106 +		if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
   1.107 +			return KErrNotFound;
   1.108 +		}
   1.109 +
   1.110 +	TInt err = KErrNotReady;
   1.111 +
   1.112 +	if (iProtocol && iTransport)
   1.113 +		{
   1.114 +		iTransport->RegisterProtocol(*iProtocol);
   1.115 +		iProtocol->RegisterTransport(iTransport);
   1.116 +		__PRINT(_L("CUsbMassStorageController::Start: Starting"));
   1.117 +		((CScsiProtocol*)iProtocol)->SetScsiParameters(aConfig);
   1.118 +		err = iTransport->Start();
   1.119 +		}
   1.120 +
   1.121 +	__PRINT(_L("CUsbMassStorageController::Start Out"));
   1.122 +
   1.123 +	return err;
   1.124 +	}
   1.125 +
   1.126 +/**
   1.127 +Stops the transport.
   1.128 +*/
   1.129 +TInt CUsbMassStorageController::Stop()
   1.130 +	{
   1.131 +
   1.132 +	__PRINT(_L("CUsbMassStorageController::Stop In"));
   1.133 +	TInt err = KErrNotReady;
   1.134 +	if (iTransport)
   1.135 +		{
   1.136 +		__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   1.137 +		err = iTransport->Stop();
   1.138 +		}
   1.139 +	TInt i=0;
   1.140 +	for (i=0; i<=iMaxDrives; ++i)
   1.141 +		{
   1.142 +		iDriveManager->SetCritical(i, EFalse);   //unset critical
   1.143 +		}
   1.144 +	__PRINT(_L("CUsbMassStorageController::Stop Out"));
   1.145 +
   1.146 +	return err;
   1.147 +	}
   1.148 +
   1.149 +/**
   1.150 +Delete the transport and protocol and start new ones.
   1.151 +*/
   1.152 +void CUsbMassStorageController::Reset()
   1.153 +	{
   1.154 +
   1.155 +	delete iProtocol;
   1.156 +	iProtocol = NULL;
   1.157 +
   1.158 +	//Create transport and protocol and initialize them
   1.159 +	__PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   1.160 +
   1.161 +	TRAPD(err,iProtocol = CScsiProtocol::NewL(*iDriveManager));
   1.162 +	err = err;
   1.163 +	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
   1.164 +	iTransport->RegisterProtocol(*iProtocol);
   1.165 +	iProtocol->RegisterTransport(iTransport);
   1.166 +	}
   1.167 +