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