os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragecontroller.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 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 
    20 /**
    21  @file
    22  @internalTechnology
    23 */
    24 
    25 #include <e32base.h>
    26 #include <d32usbc.h>
    27 
    28 #include "mstypes.h"
    29 #include "msctypes.h"
    30 #include "testman.h"
    31 #include "drivemanager.h"
    32 
    33 #include "tscsiserverreq.h"
    34 #include "tscsiservercmds.h"
    35 #include "mserverprotocol.h"
    36 #include "cscsiserverprotocol.h"
    37 #include "mdevicetransport.h"
    38 #include "cbulkonlytransport.h"
    39 
    40 #include "cusbmassstorageserver.h"
    41 #include "cusbmassstoragecontroller.h"
    42 #include "debug.h"
    43 #include "msdebug.h"
    44 
    45 
    46 
    47 
    48 CUsbMassStorageController* CUsbMassStorageController::NewL()
    49     {
    50     __MSFNSLOG
    51 	CUsbMassStorageController* self = new (ELeave) CUsbMassStorageController();
    52 	CleanupStack::PushL(self);
    53 	self->ConstructL();
    54 	CleanupStack::Pop();
    55 	return self;
    56     }
    57 
    58 
    59 CUsbMassStorageController::CUsbMassStorageController()
    60     {
    61     }
    62 
    63 
    64 void CUsbMassStorageController::ConstructL()
    65 	{
    66 #ifdef MSDC_TESTMODE
    67     // TestParser for modifying client behaviour to create  BOT 13 Case device
    68     // exceptions conditions
    69     __TESTMODEPRINT("Test Mode is active");
    70     iTestParser = new (ELeave) TTestParser;
    71 #endif
    72 	}
    73 
    74 /**
    75 Destructor
    76 */
    77 CUsbMassStorageController::~CUsbMassStorageController()
    78 	{
    79     __MSFNLOG
    80 	delete iServer;
    81 	delete iProtocol;
    82 	delete iTransport;
    83 	delete iDriveManager;
    84 	}
    85 
    86 /**
    87 Creates the drive manager, transport, protocol and server
    88 
    89 @param aMaxDrives Maximum number of Mass Storage drives supported.
    90 */
    91 void CUsbMassStorageController::CreateL(const TLunToDriveMap& aDriveMapping)
    92 	{
    93     __MSFNLOG
    94 	//Create and init drive manager
    95 	iDriveManager = CDriveManager::NewL(aDriveMapping);
    96 
    97 	//Create transport and protocol and initialize them
    98 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
    99 #ifdef MSDC_TESTMODE
   100 	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this, iTestParser);
   101 	iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser);
   102 #else
   103 	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this);
   104 	iProtocol = CScsiServerProtocol::NewL(*iDriveManager);
   105 #endif
   106 	iTransport->RegisterProtocol(*iProtocol);
   107 	iProtocol->RegisterTransport(iTransport);
   108 
   109 	//Create and start server
   110 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
   111 	iServer = CUsbMassStorageServer::NewLC(*this);
   112 	CleanupStack::Pop(iServer);
   113 	}
   114 
   115 /**
   116 Returns a reference to the drive manager
   117 
   118 @return A reference to the drive manager
   119 */
   120 CDriveManager& CUsbMassStorageController::DriveManager()
   121 	{
   122     __MSFNLOG
   123 	return *iDriveManager;
   124 	}
   125 
   126 /**
   127 Starts the transport and initializes the protocol.
   128 
   129 @param aConfig Reference to Mass Storage configuration data
   130 */
   131 TInt CUsbMassStorageController::Start(const TMassStorageConfig& aConfig)
   132 	{
   133     __MSFNLOG
   134 	//Save this value for use in the Reset method.
   135 	iConfig = aConfig;
   136 	TInt err = KErrNotReady;
   137 	if (iProtocol && iTransport)
   138 		{
   139 		__PRINT(_L("CUsbMassStorageController::Start: Starting"));
   140 		iProtocol->SetParameters(aConfig);
   141 		err = iTransport->Start();
   142 		}
   143 	return err;
   144 	}
   145 
   146 /**
   147 Stops the transport.
   148 */
   149 TInt CUsbMassStorageController::Stop()
   150 	{
   151     __MSFNLOG
   152 	TInt err = KErrNotReady;
   153 	if (iTransport)
   154 		{
   155 		__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   156 		err = iTransport->Stop();
   157 		}
   158 
   159 	iDriveManager->SetCritical(CDriveManager::KAllLuns, EFalse);   //unset critical
   160 	return err;
   161 	}
   162 
   163 /**
   164 Delete the transport and protocol and start new ones.
   165 */
   166 void CUsbMassStorageController::Reset()
   167 	{
   168     __MSFNLOG
   169 	delete iProtocol;
   170 	iProtocol = NULL;
   171 
   172 	//Create transport and protocol and initialize them
   173 	__PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   174 
   175 #ifdef MSDC_TESTMODE
   176 	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser));
   177 #else
   178 	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager));
   179 #endif
   180 	err = err;
   181 	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
   182 	iTransport->RegisterProtocol(*iProtocol);
   183 	iProtocol->RegisterTransport(iTransport);
   184     iProtocol->SetParameters(iConfig);
   185 	}