os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cusbmassstoragecontroller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-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 // CUsbMassStorageController implementation.
    15 // 
    16 //
    17 
    18 /**
    19  @file
    20  @internalTechnology
    21 */
    22 
    23 #include "cusbmassstoragecontroller.h"
    24 #include "massstoragedebug.h"
    25 #include "scsiprot.h"
    26 #include "cbulkonlytransport.h"
    27 
    28 /**
    29 Destructor
    30 */
    31 CUsbMassStorageController::~CUsbMassStorageController()
    32 	{
    33 	delete iServer;
    34 	delete iProtocol;
    35 	delete iTransport;
    36 	delete iDriveManager;
    37 	}
    38 
    39 /**
    40 Creates the drive manager, transport, protocol and server
    41 
    42 @param aMaxDrives Maximum number of Mass Storage drives supported.
    43 */
    44 void CUsbMassStorageController::CreateL(RArray<TInt>& aDriveMapping)
    45 	{
    46 	__PRINT(_L("CUsbMassStorageController::CreateL In"));
    47 	iTransportLddFlag = EUsbcsc; // Create transport object using SC Ldd By default
    48 	//Save this value for use in the Reset method.
    49 	iMaxDrives = aDriveMapping.Count();
    50 	//Create and init drive manager
    51 	iDriveManager = CDriveManager::NewL(aDriveMapping);
    52 
    53 	//Create transport and protocol and initialize them
    54 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
    55 	iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
    56 	if (!iTransport)
    57 		User::Leave(KErrNoMemory);
    58 
    59 	iProtocol = CScsiProtocol::NewL(*iDriveManager);
    60 
    61 	//Create and start server
    62 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
    63 	iServer = CUsbMassStorageServer::NewLC(*this);
    64 	CleanupStack::Pop(iServer);
    65 	__PRINT(_L("CUsbMassStorageController::CreateL Out"));
    66 	}
    67 
    68 /**
    69 Returns a reference to the drive manager
    70 
    71 @return A reference to the drive manager
    72 */
    73 CDriveManager& CUsbMassStorageController::DriveManager()
    74 	{
    75 	return *iDriveManager;
    76 	}
    77 
    78 
    79 void CUsbMassStorageController::GetTransport(MTransportBase* &aTransport)
    80 	{
    81 	aTransport = iTransport; 
    82 	}
    83 
    84 /**
    85 Starts the transport and initializes the protocol.
    86 
    87 @param aConfig Reference to Mass Storage configuration data
    88 */
    89 TInt CUsbMassStorageController::Start(TMassStorageConfig& aConfig)
    90 	{
    91 	__PRINT(_L("CUsbMassStorageController::Start In"));
    92 	//Save this value for use in the Reset method.
    93 	iConfig = aConfig;
    94 
    95     __ASSERT_DEBUG(iTransport, User::Invariant());
    96 	if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
    97 		{
    98 		iTransportLddFlag = EUsbc; // If SC Ldd not present use the default USB Client Ldd
    99 		delete iTransport;
   100 		iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
   101 		if (!iTransport)
   102 			User::Leave(KErrNoMemory);
   103 		if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
   104 			return KErrNotFound;
   105 		}
   106 
   107 	TInt err = KErrNotReady;
   108 
   109 	if (iProtocol && iTransport)
   110 		{
   111 		iTransport->RegisterProtocol(*iProtocol);
   112 		iProtocol->RegisterTransport(iTransport);
   113 		__PRINT(_L("CUsbMassStorageController::Start: Starting"));
   114 		((CScsiProtocol*)iProtocol)->SetScsiParameters(aConfig);
   115 		err = iTransport->Start();
   116 		}
   117 
   118 	__PRINT(_L("CUsbMassStorageController::Start Out"));
   119 
   120 	return err;
   121 	}
   122 
   123 /**
   124 Stops the transport.
   125 */
   126 TInt CUsbMassStorageController::Stop()
   127 	{
   128 
   129 	__PRINT(_L("CUsbMassStorageController::Stop In"));
   130 	TInt err = KErrNotReady;
   131 	if (iTransport)
   132 		{
   133 		__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   134 		err = iTransport->Stop();
   135 		}
   136 	TInt i=0;
   137 	for (i=0; i<=iMaxDrives; ++i)
   138 		{
   139 		iDriveManager->SetCritical(i, EFalse);   //unset critical
   140 		}
   141 	__PRINT(_L("CUsbMassStorageController::Stop Out"));
   142 
   143 	return err;
   144 	}
   145 
   146 /**
   147 Delete the transport and protocol and start new ones.
   148 */
   149 void CUsbMassStorageController::Reset()
   150 	{
   151 
   152 	delete iProtocol;
   153 	iProtocol = NULL;
   154 
   155 	//Create transport and protocol and initialize them
   156 	__PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   157 
   158 	TRAPD(err,iProtocol = CScsiProtocol::NewL(*iDriveManager));
   159 	err = err;
   160 	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
   161 	iTransport->RegisterProtocol(*iProtocol);
   162 	iProtocol->RegisterTransport(iTransport);
   163 	}
   164