os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/cusbmassstoragecontroller.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // CUsbMassStorageController implementation.
23 #include "cusbmassstoragecontroller.h"
24 #include "massstoragedebug.h"
26 #include "cbulkonlytransport.h"
31 CUsbMassStorageController::~CUsbMassStorageController()
40 Creates the drive manager, transport, protocol and server
42 @param aMaxDrives Maximum number of Mass Storage drives supported.
44 void CUsbMassStorageController::CreateL(RArray<TInt>& aDriveMapping)
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);
53 //Create transport and protocol and initialize them
54 __PRINT(_L("CUsbMassStorageController::CreateL: Creating transport and protocol"));
55 iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
57 User::Leave(KErrNoMemory);
59 iProtocol = CScsiProtocol::NewL(*iDriveManager);
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"));
69 Returns a reference to the drive manager
71 @return A reference to the drive manager
73 CDriveManager& CUsbMassStorageController::DriveManager()
75 return *iDriveManager;
79 void CUsbMassStorageController::GetTransport(MTransportBase* &aTransport)
81 aTransport = iTransport;
85 Starts the transport and initializes the protocol.
87 @param aConfig Reference to Mass Storage configuration data
89 TInt CUsbMassStorageController::Start(TMassStorageConfig& aConfig)
91 __PRINT(_L("CUsbMassStorageController::Start In"));
92 //Save this value for use in the Reset method.
95 __ASSERT_DEBUG(iTransport, User::Invariant());
96 if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
98 iTransportLddFlag = EUsbc; // If SC Ldd not present use the default USB Client Ldd
100 iTransport = CBulkOnlyTransport::NewL(iMaxDrives, *this, iTransportLddFlag);
102 User::Leave(KErrNoMemory);
103 if ((iTransport->InitialiseTransportL((TInt) iTransportLddFlag)) != KErrNone)
107 TInt err = KErrNotReady;
109 if (iProtocol && iTransport)
111 iTransport->RegisterProtocol(*iProtocol);
112 iProtocol->RegisterTransport(iTransport);
113 __PRINT(_L("CUsbMassStorageController::Start: Starting"));
114 ((CScsiProtocol*)iProtocol)->SetScsiParameters(aConfig);
115 err = iTransport->Start();
118 __PRINT(_L("CUsbMassStorageController::Start Out"));
126 TInt CUsbMassStorageController::Stop()
129 __PRINT(_L("CUsbMassStorageController::Stop In"));
130 TInt err = KErrNotReady;
133 __PRINT(_L("CUsbMassStorageController::Stop: Stopping"));
134 err = iTransport->Stop();
137 for (i=0; i<=iMaxDrives; ++i)
139 iDriveManager->SetCritical(i, EFalse); //unset critical
141 __PRINT(_L("CUsbMassStorageController::Stop Out"));
147 Delete the transport and protocol and start new ones.
149 void CUsbMassStorageController::Reset()
155 //Create transport and protocol and initialize them
156 __PRINT(_L("CUsbMassStorageController::Reset: Creating protocol"));
158 TRAPD(err,iProtocol = CScsiProtocol::NewL(*iDriveManager));
160 __ASSERT_DEBUG(err==KErrNone, User::Invariant());
161 iTransport->RegisterProtocol(*iProtocol);
162 iProtocol->RegisterTransport(iTransport);