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 // CDriveManager and CMassStorageDrive classes for USB Mass Storage.
23 #ifndef __DRIVEMANAGER_H__
24 #define __DRIVEMANAGER_H__
26 #include <e32base.h> // C Class Definitions, Cleanup Stack
27 #include <e32def.h> // T Type Definitions
29 #include <e32property.h>
30 #include "usbmsshared.h" // KUsbMsMaxDrives
31 #include "drivepublisher.h"
33 // Forward declarations
40 Along with CDriveManager, this provides an interface between the generic SCSI
41 protocol component and the target drive unit. The CMassStorageDrive class is
42 instantiated by the drive manager, and contains a pointer to the associated
43 CProxyDrive that was registered by the Mass Storage File System.
45 class CMassStorageDrive : public CBase
49 The Drive Mount State Machine.
58 Not mounted, but SCSI started
66 Not unmounted, but SCSI stopped
72 The Drive Media State Machine.
77 The media is present and ready for access.
81 The media is currently being accessed by Mass Storage.
85 The media is present but is password-protected.
89 The media is not physically present.
98 CMassStorageDrive(RCriticalSection& aCritSec,
99 RDriveStateChangedPublisher& aDriveStateChangedPublisher);
101 ~CMassStorageDrive();
103 TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia = ETrue);
104 TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia = ETrue);
105 TInt Caps(TLocalDriveCapsV4& aCaps);
106 inline TMountState MountState() const;
107 TDriveState DriveState() const;
108 TDriveState CheckDriveState();
109 #ifndef USB_TRANSFER_PUBLISHER
110 inline TUint KBytesRead() const;
111 inline TUint KBytesWritten() const;
113 inline TInt SetMountDisconnected();
114 inline TInt SetMountConnecting();
115 inline TInt SetMountDisconnecting();
116 inline TInt SetMountConnected();
117 TInt SetMountConnected(CProxyDrive& aProxyDrive, TBool& aMediaChanged);
118 TInt SetCritical(TBool aCritical);
119 TBool IsMediaChanged(TBool aReset=EFalse);
120 TBool IsWholeMediaAccess();
122 #ifndef USBMSDRIVE_TEST
127 // Forward declaration
128 struct CLocalDriveRef;
130 TInt HandleCriticalError();
131 TInt ClearCriticalError();
132 TInt DoCaps(TLocalDriveCapsV4& aCaps);
133 void SetDriveState(TDriveState aNewState);
134 TInt SetMountState(TMountState aNewState, CLocalDriveRef* aLocalDrive=NULL);
135 CProxyDrive& SafeProxyDrive() const;
138 A Critical Section, shared by all instances of CMassStorageDrive, used to ensure
139 that iMountState and iProxyDrive are changed atomically.
141 RCriticalSection& iCritSec;
143 The Drive Mount state machine
145 TMountState iMountState;
147 #ifndef USB_TRANSFER_PUBLISHER
149 Cumulative bytes read
153 Cumulative bytes written
155 TInt64 iBytesWritten;
159 When Connected, references to CProxyDrive and TBusLocalDrive's Media Changed flag.
161 CLocalDriveRef* iLocalDrive;
163 Publisher for media errors.
165 RDriveMediaErrorPublisher iDriveMediaErrorPublisher;
167 Reference to publisher for tracking drive state changes.
169 RDriveStateChangedPublisher& iDriveStateChangedPublisher;
171 Indicates whether whole media access is permitted.
173 TBool iWholeMediaAccess;
180 Along with CMassStorageDrive, this provides an interface between the generic SCSI
181 protocol component and the target drive unit. This package is responsible for
182 maintaining the list of registered drives. The owner of the controller registers
183 each drive it wishes to make available to USB Mass Storage along with an
184 associated Logical Drive Unit identifier. The SCSI protocol contains a reference
185 to the drive manager in order to route the incoming request to a drive.
187 class CDriveManager : public CBase
191 The Logical Drive Unit Identifiers (LUN) must be in the range 0..7 due to the
192 fact that the status for all drives is encoded into one 32-bit word.
194 enum { KAllLuns = 0xff };
196 static CDriveManager* NewL(TRefDriveMap aDriveMap);
199 TInt RegisterDrive(CProxyDrive& aProxyDrive, TBool& aMediaChanged, TUint aLun);
200 TInt DeregisterDrive(TUint aLun);
201 CMassStorageDrive* Drive(TUint aLun, TInt& aError) const;
202 TInt Connect(TUint aLun);
203 TInt Disconnect(TUint aLun);
204 TBool IsMediaChanged(TUint aLun, TBool aReset=EFalse);
205 TInt SetCritical(TUint aLun, TBool aCritical);
208 // private default constructor to ensure that NewL is used
209 CDriveManager(const RArray<TInt>& aDriveMap);
214 The array of drives. The index into the array is a LUN.
216 TFixedArray<CMassStorageDrive*,KUsbMsMaxDrives> iDrives;
220 For converting LUN to Drive Number.
222 const RArray<TInt>& iDriveMap;
224 A resource owned by DriveManager but used by the Drive objects.
226 RCriticalSection iDriveCritSec;
229 Publisher for tracking drive state changes.
231 RDriveStateChangedPublisher* iDriveStateChangedPublisher;
234 #include "drivemanager.inl"
236 #endif //__DRIVEMANAGER_H__