kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/cusbmassstoragecontroller.cpp
changeset 300 1d28c8722707
parent 0 a41df078684a
equal deleted inserted replaced
293:0659d0e1a03c 300:1d28c8722707
     1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // CUsbMassStorageController implementation.
    14 // CUsbMassStorageController implementation.
    15 // 
    15 //
    16 //
    16 //
    17 
    17 
    18 
    18 
    19 
    19 
    20 /**
    20 /**
    38 #include "cbulkonlytransport.h"
    38 #include "cbulkonlytransport.h"
    39 
    39 
    40 #include "cusbmassstorageserver.h"
    40 #include "cusbmassstorageserver.h"
    41 #include "cusbmassstoragecontroller.h"
    41 #include "cusbmassstoragecontroller.h"
    42 #include "debug.h"
    42 #include "debug.h"
    43 #include "msdebug.h"
       
    44 
       
    45 
       
    46 
    43 
    47 
    44 
    48 CUsbMassStorageController* CUsbMassStorageController::NewL()
    45 CUsbMassStorageController* CUsbMassStorageController::NewL()
    49     {
    46     {
    50     __MSFNSLOG
    47     CUsbMassStorageController* self = new (ELeave) CUsbMassStorageController();
    51 	CUsbMassStorageController* self = new (ELeave) CUsbMassStorageController();
    48     CleanupStack::PushL(self);
    52 	CleanupStack::PushL(self);
    49     self->ConstructL();
    53 	self->ConstructL();
    50     CleanupStack::Pop();
    54 	CleanupStack::Pop();
    51     return self;
    55 	return self;
       
    56     }
    52     }
    57 
    53 
    58 
    54 
    59 CUsbMassStorageController::CUsbMassStorageController()
    55 CUsbMassStorageController::CUsbMassStorageController()
    60     {
    56     {
    61     }
    57     }
    62 
    58 
    63 
    59 
    64 void CUsbMassStorageController::ConstructL()
    60 void CUsbMassStorageController::ConstructL()
    65 	{
    61     {
    66 #ifdef MSDC_TESTMODE
    62 #ifdef MSDC_TESTMODE
    67     // TestParser for modifying client behaviour to create  BOT 13 Case device
    63     // TestParser for modifying client behaviour to create  BOT 13 Case device
    68     // exceptions conditions
    64     // exceptions conditions
    69     __TESTMODEPRINT("Test Mode is active");
    65     __TESTMODEPRINT("Test Mode is active");
    70     iTestParser = new (ELeave) TTestParser;
    66     iTestParser = new (ELeave) TTestParser;
    71 #endif
    67 #endif
    72 	}
    68     }
    73 
    69 
    74 /**
    70 /**
    75 Destructor
    71 Destructor
    76 */
    72 */
    77 CUsbMassStorageController::~CUsbMassStorageController()
    73 CUsbMassStorageController::~CUsbMassStorageController()
    78 	{
    74     {
    79     __MSFNLOG
    75     delete iServer;
    80 	delete iServer;
    76     delete iProtocol;
    81 	delete iProtocol;
    77     delete iTransport;
    82 	delete iTransport;
    78     delete iDriveManager;
    83 	delete iDriveManager;
    79     }
    84 	}
       
    85 
    80 
    86 /**
    81 /**
    87 Creates the drive manager, transport, protocol and server
    82 Creates the drive manager, transport, protocol and server
    88 
    83 
    89 @param aMaxDrives Maximum number of Mass Storage drives supported.
    84 @param aMaxDrives Maximum number of Mass Storage drives supported.
    90 */
    85 */
    91 void CUsbMassStorageController::CreateL(const TLunToDriveMap& aDriveMapping)
    86 void CUsbMassStorageController::CreateL(const TLunToDriveMap& aDriveMapping)
    92 	{
    87     {
    93     __MSFNLOG
    88     //Create and init drive manager
    94 	//Create and init drive manager
    89     iDriveManager = CDriveManager::NewL(aDriveMapping);
    95 	iDriveManager = CDriveManager::NewL(aDriveMapping);
       
    96 
    90 
    97 	//Create transport and protocol and initialize them
    91     //Create transport and protocol and initialize them
    98 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
    92     __PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
    99 #ifdef MSDC_TESTMODE
    93 #ifdef MSDC_TESTMODE
   100 	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this, iTestParser);
    94     iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this, iTestParser);
   101 	iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser);
    95     iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser);
   102 #else
    96 #else
   103 	iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this);
    97     iTransport = CBulkOnlyTransport::NewL(aDriveMapping.Count(), *this);
   104 	iProtocol = CScsiServerProtocol::NewL(*iDriveManager);
    98     iProtocol = CScsiServerProtocol::NewL(*iDriveManager);
   105 #endif
    99 #endif
   106 	iTransport->RegisterProtocol(*iProtocol);
   100     iTransport->RegisterProtocol(*iProtocol);
   107 	iProtocol->RegisterTransport(iTransport);
   101     iProtocol->RegisterTransport(iTransport);
   108 
   102 
   109 	//Create and start server
   103     //Create and start server
   110 	__PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
   104     __PRINT(_L("CUsbMassStorageController::CreateL: Creating server"));
   111 	iServer = CUsbMassStorageServer::NewLC(*this);
   105     iServer = CUsbMassStorageServer::NewLC(*this);
   112 	CleanupStack::Pop(iServer);
   106     CleanupStack::Pop(iServer);
   113 	}
   107     }
   114 
   108 
   115 /**
   109 /**
   116 Returns a reference to the drive manager
   110 Returns a reference to the drive manager
   117 
   111 
   118 @return A reference to the drive manager
   112 @return A reference to the drive manager
   119 */
   113 */
   120 CDriveManager& CUsbMassStorageController::DriveManager()
   114 CDriveManager& CUsbMassStorageController::DriveManager()
   121 	{
   115     {
   122     __MSFNLOG
   116     return *iDriveManager;
   123 	return *iDriveManager;
   117     }
   124 	}
       
   125 
   118 
   126 /**
   119 /**
   127 Starts the transport and initializes the protocol.
   120 Starts the transport and initializes the protocol.
   128 
   121 
   129 @param aConfig Reference to Mass Storage configuration data
   122 @param aConfig Reference to Mass Storage configuration data
   130 */
   123 */
   131 TInt CUsbMassStorageController::Start(const TMassStorageConfig& aConfig)
   124 TInt CUsbMassStorageController::Start(const TMassStorageConfig& aConfig)
   132 	{
   125     {
   133     __MSFNLOG
   126     //Save this value for use in the Reset method.
   134 	//Save this value for use in the Reset method.
   127     iConfig = aConfig;
   135 	iConfig = aConfig;
   128     TInt err = KErrNotReady;
   136 	TInt err = KErrNotReady;
   129     if (iProtocol && iTransport)
   137 	if (iProtocol && iTransport)
   130         {
   138 		{
   131         __PRINT(_L("CUsbMassStorageController::Start: Starting"));
   139 		__PRINT(_L("CUsbMassStorageController::Start: Starting"));
   132         iProtocol->SetParameters(aConfig);
   140 		iProtocol->SetParameters(aConfig);
   133         err = iTransport->Start();
   141 		err = iTransport->Start();
   134         }
   142 		}
   135     return err;
   143 	return err;
   136     }
   144 	}
       
   145 
   137 
   146 /**
   138 /**
   147 Stops the transport.
   139 Stops the transport.
   148 */
   140 */
   149 TInt CUsbMassStorageController::Stop()
   141 TInt CUsbMassStorageController::Stop()
   150 	{
   142     {
   151     __MSFNLOG
   143     TInt err = KErrNotReady;
   152 	TInt err = KErrNotReady;
   144     if (iTransport)
   153 	if (iTransport)
   145         {
   154 		{
   146         __PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   155 		__PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
   147         err = iTransport->Stop();
   156 		err = iTransport->Stop();
   148         }
   157 		}
       
   158 
   149 
   159 	iDriveManager->SetCritical(CDriveManager::KAllLuns, EFalse);   //unset critical
   150     iDriveManager->SetCritical(CDriveManager::KAllLuns, EFalse);   //unset critical
   160 	return err;
   151     return err;
   161 	}
   152     }
   162 
   153 
   163 /**
   154 /**
   164 Delete the transport and protocol and start new ones.
   155 Delete the transport and protocol and start new ones.
   165 */
   156 */
   166 void CUsbMassStorageController::Reset()
   157 void CUsbMassStorageController::Reset()
   167 	{
   158     {
   168     __MSFNLOG
   159     delete iProtocol;
   169 	delete iProtocol;
   160     iProtocol = NULL;
   170 	iProtocol = NULL;
       
   171 
   161 
   172 	//Create transport and protocol and initialize them
   162     //Create transport and protocol and initialize them
   173 	__PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   163     __PRINT(_L("CUsbMassStorageController::Reset: Creating  protocol"));
   174 
   164 
   175 #ifdef MSDC_TESTMODE
   165 #ifdef MSDC_TESTMODE
   176 	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser));
   166     TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager, iTestParser));
   177 #else
   167 #else
   178 	TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager));
   168     TRAPD(err,iProtocol = CScsiServerProtocol::NewL(*iDriveManager));
   179 #endif
   169 #endif
   180 	err = err;
   170     err = err;
   181 	__ASSERT_DEBUG(err==KErrNone, User::Invariant());
   171     __ASSERT_DEBUG(err==KErrNone, User::Invariant());
   182 	iTransport->RegisterProtocol(*iProtocol);
   172     iTransport->RegisterProtocol(*iProtocol);
   183 	iProtocol->RegisterTransport(iTransport);
   173     iProtocol->RegisterTransport(iTransport);
   184     iProtocol->SetParameters(iConfig);
   174     iProtocol->SetParameters(iConfig);
   185 	}
   175     }