author | Mike Kinghan <mikek@symbian.org> |
Thu, 23 Sep 2010 11:57:02 +0100 | |
branch | GCC_SURGE |
changeset 267 | 9b718307b8ec |
parent 0 | a41df078684a |
permissions | -rw-r--r-- |
0 | 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 |
// CDriveManager and CMassStorageDrive classes for USB Mass Storage. |
|
15 |
// |
|
16 |
// |
|
17 |
||
18 |
||
19 |
||
20 |
/** |
|
21 |
@file |
|
22 |
@internalTechnology |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef DRIVEMANAGER_H |
|
26 |
#define DRIVEMANAGER_H |
|
27 |
||
28 |
#include "d32locd.h" |
|
29 |
||
30 |
// Forward declarations |
|
31 |
class CDriveManager; |
|
32 |
class RDriveMediaErrorPublisher; |
|
33 |
class RDriveStateChangedPublisher; |
|
34 |
class TLocalDriveCapsV4; |
|
35 |
class CProxyDrive; |
|
36 |
||
37 |
||
38 |
||
39 |
class TMediaParams |
|
40 |
{ |
|
41 |
public: |
|
267
9b718307b8ec
Fix for Bug 3739 - [GCCE] In-class initialization of const member is an error in drivemanger.h
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
42 |
enum |
9b718307b8ec
Fix for Bug 3739 - [GCCE] In-class initialization of const member is an error in drivemanger.h
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
43 |
{ |
9b718307b8ec
Fix for Bug 3739 - [GCCE] In-class initialization of const member is an error in drivemanger.h
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
44 |
KDefaultBlockSize = 0x200 |
9b718307b8ec
Fix for Bug 3739 - [GCCE] In-class initialization of const member is an error in drivemanger.h
Mike Kinghan <mikek@symbian.org>
parents:
0
diff
changeset
|
45 |
}; |
0 | 46 |
|
47 |
void Init(TLocalDriveCapsV4& aCaps); |
|
48 |
||
49 |
TUint32 NumBlocks() const {return iNumBlocks;} |
|
50 |
TUint64 Size() const {return iSize;}; |
|
51 |
TUint32 BlockSize() const {return KDefaultBlockSize;} |
|
52 |
TBool IsWriteProtected() const {return iMediaAtt & KMediaAttWriteProtected ? ETrue : EFalse;} |
|
53 |
TBool IsLocked() const {return iMediaAtt & KMediaAttLocked ? ETrue : EFalse;} |
|
54 |
||
55 |
private: |
|
56 |
TLocalDriveCapsV4 iCaps; |
|
57 |
||
58 |
TUint32 iNumBlocks; |
|
59 |
TInt64 iSize; |
|
60 |
TUint iMediaAtt; |
|
61 |
}; |
|
62 |
||
63 |
||
64 |
/** |
|
65 |
A private structure that, when Connected, holds references to |
|
66 |
the CProxyDrive and the corresponding TBusLocalDrive's Media Changed flag. |
|
67 |
*/ |
|
68 |
class TLocalDriveRef |
|
69 |
{ |
|
70 |
public: |
|
71 |
/** |
|
72 |
The Drive Media State Machine. |
|
73 |
*/ |
|
74 |
enum TDriveState |
|
75 |
{ |
|
76 |
/** |
|
77 |
The media is present and ready for access. |
|
78 |
*/ |
|
79 |
EIdle, |
|
80 |
/** |
|
81 |
The media is currently being accessed by Mass Storage. |
|
82 |
*/ |
|
83 |
EActive, |
|
84 |
/** |
|
85 |
The media is present but is password-protected. |
|
86 |
*/ |
|
87 |
ELocked, |
|
88 |
/** |
|
89 |
The media is not physically present. |
|
90 |
*/ |
|
91 |
EMediaNotPresent, |
|
92 |
/** |
|
93 |
No drive. |
|
94 |
*/ |
|
95 |
EErrDisMounted |
|
96 |
}; |
|
97 |
||
98 |
||
99 |
TLocalDriveRef(CProxyDrive& aProxyDrive, |
|
100 |
TBool& aMediaChanged, |
|
101 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher); |
|
102 |
||
103 |
void SetDriveState(TDriveState aState); |
|
104 |
TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia); |
|
105 |
TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia); |
|
106 |
TBool IsMediaChanged(TBool aReset); |
|
107 |
TInt SetCritical(TBool aCritical); |
|
108 |
TDriveState DriveState() const; |
|
109 |
TInt Caps(TLocalDriveCapsV4& aInfo); |
|
110 |
||
111 |
private: |
|
112 |
static TBool IsActive(TDriveState aDriveState); |
|
113 |
||
114 |
private: |
|
115 |
CProxyDrive& iProxyDrive; |
|
116 |
||
117 |
TBool& iMediaChanged; |
|
118 |
/** |
|
119 |
The Drive Media state machine |
|
120 |
*/ |
|
121 |
TDriveState iDriveState; |
|
122 |
||
123 |
/** |
|
124 |
Reference to publisher for tracking drive state changes. |
|
125 |
*/ |
|
126 |
RDriveStateChangedPublisher& iDriveStateChangedPublisher; |
|
127 |
}; |
|
128 |
||
129 |
||
130 |
inline TLocalDriveRef::TLocalDriveRef(CProxyDrive& aProxyDrive, |
|
131 |
TBool& aMediaChanged, |
|
132 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher) |
|
133 |
: iProxyDrive(aProxyDrive), |
|
134 |
iMediaChanged(aMediaChanged), |
|
135 |
iDriveState(EIdle), |
|
136 |
iDriveStateChangedPublisher(aDriveStateChangedPublisher) |
|
137 |
{ |
|
138 |
} |
|
139 |
||
140 |
||
141 |
inline TBool TLocalDriveRef::IsActive(TLocalDriveRef::TDriveState aDriveState) |
|
142 |
{ |
|
143 |
return aDriveState==TLocalDriveRef::EActive; |
|
144 |
} |
|
145 |
||
146 |
||
147 |
inline TLocalDriveRef::TDriveState TLocalDriveRef::DriveState() const |
|
148 |
{ |
|
149 |
return iDriveState; |
|
150 |
} |
|
151 |
||
152 |
||
153 |
/** |
|
154 |
@internalTechnology |
|
155 |
||
156 |
Along with CDriveManager, this provides an interface between the generic SCSI |
|
157 |
protocol component and the target drive unit. The CMassStorageDrive class is |
|
158 |
instantiated by the drive manager, and contains a pointer to the associated |
|
159 |
CProxyDrive that was registered by the Mass Storage File System. |
|
160 |
*/ |
|
161 |
class CMassStorageDrive: public CBase |
|
162 |
{ |
|
163 |
public: |
|
164 |
/** |
|
165 |
The Drive Mount State Machine. |
|
166 |
*/ |
|
167 |
enum TMountState |
|
168 |
{ |
|
169 |
/** |
|
170 |
Unmounted |
|
171 |
*/ |
|
172 |
EDisconnected, |
|
173 |
/** |
|
174 |
Not mounted, but SCSI started |
|
175 |
*/ |
|
176 |
EConnecting, |
|
177 |
/** |
|
178 |
Mounted |
|
179 |
*/ |
|
180 |
EConnected, |
|
181 |
/** |
|
182 |
Not unmounted, but SCSI stopped |
|
183 |
*/ |
|
184 |
EDisconnecting |
|
185 |
}; |
|
186 |
||
187 |
public: |
|
188 |
static CMassStorageDrive* NewL(RCriticalSection& aCritSec, |
|
189 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher); |
|
190 |
~CMassStorageDrive(); |
|
191 |
||
192 |
private: |
|
193 |
void ConstructL(); |
|
194 |
CMassStorageDrive(RCriticalSection& aCritSec, |
|
195 |
RDriveStateChangedPublisher& aDriveStateChangedPublisher); |
|
196 |
||
197 |
public: |
|
198 |
||
199 |
TInt Read(const TInt64& aPos, TInt aLength, TDes8& aBuf, TBool aWholeMedia = ETrue); |
|
200 |
TInt Write(const TInt64& aPos, TDesC8& aBuf, TBool aWholeMedia = ETrue); |
|
201 |
||
202 |
TMountState MountState() const; |
|
203 |
TLocalDriveRef::TDriveState DriveState() const; |
|
204 |
TLocalDriveRef::TDriveState CheckDriveState(); |
|
205 |
void SetMountDisconnected(); |
|
206 |
void SetMountConnecting(); |
|
207 |
void SetMountDisconnecting(); |
|
208 |
void SetMountConnected(); |
|
209 |
void SetMountConnectedL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, RDriveStateChangedPublisher& aDriveStateChangedPublisher); |
|
210 |
TInt SetCritical(TBool aCritical); |
|
211 |
TBool IsMediaChanged(TBool aReset=EFalse); |
|
212 |
||
213 |
const TMediaParams& MediaParams() const {return iMediaParams;} |
|
214 |
||
215 |
private: |
|
216 |
TInt HandleCriticalError(); |
|
217 |
TInt ClearCriticalError(); |
|
218 |
TInt DoCaps(TLocalDriveCapsV4& aCaps); |
|
219 |
void SetDriveState(TLocalDriveRef::TDriveState aNewState); |
|
220 |
void SetMountState(TMountState aNewState, TBool aCriticalSection = EFalse); |
|
221 |
||
222 |
private: |
|
223 |
/** |
|
224 |
A Critical Section, shared by all instances of CMassStorageDrive, used to ensure |
|
225 |
that iMountState and iProxyDrive are changed atomically. |
|
226 |
*/ |
|
227 |
RCriticalSection& iCritSec; |
|
228 |
/** |
|
229 |
The Drive Mount state machine |
|
230 |
*/ |
|
231 |
TMountState iMountState; |
|
232 |
||
233 |
/** |
|
234 |
When Connected, references to CProxyDrive and TBusLocalDrive's Media Changed flag. |
|
235 |
*/ |
|
236 |
TLocalDriveRef* iLocalDrive; |
|
237 |
/** |
|
238 |
Publisher for media errors. |
|
239 |
*/ |
|
240 |
RDriveMediaErrorPublisher* iDriveMediaErrorPublisher; |
|
241 |
/** |
|
242 |
Reference to publisher for tracking drive state changes. |
|
243 |
*/ |
|
244 |
RDriveStateChangedPublisher& iDriveStateChangedPublisher; |
|
245 |
||
246 |
TMediaParams iMediaParams; |
|
247 |
}; |
|
248 |
||
249 |
||
250 |
/** |
|
251 |
@internalTechnology |
|
252 |
||
253 |
Along with CMassStorageDrive, this provides an interface between the generic SCSI |
|
254 |
protocol component and the target drive unit. This package is responsible for |
|
255 |
maintaining the list of registered drives. The owner of the controller registers |
|
256 |
each drive it wishes to make available to USB Mass Storage along with an |
|
257 |
associated Logical Drive Unit identifier. The SCSI protocol contains a reference |
|
258 |
to the drive manager in order to route the incoming request to a drive. |
|
259 |
*/ |
|
260 |
class CDriveManager : public CBase |
|
261 |
{ |
|
262 |
public: |
|
263 |
/** |
|
264 |
The Logical Drive Unit Identifiers (LUN) must be in the range 0..7 due to the |
|
265 |
fact that the status for all drives is encoded into one 32-bit word. |
|
266 |
*/ |
|
267 |
enum { KAllLuns = 0xff }; |
|
268 |
||
269 |
static CDriveManager* NewL(const TLunToDriveMap& aDriveMap); |
|
270 |
~CDriveManager(); |
|
271 |
||
272 |
void RegisterDriveL(CProxyDrive& aProxyDrive, TBool& aMediaChanged, TLun aLun); |
|
273 |
void DeregisterDrive(TLun aLun); |
|
274 |
CMassStorageDrive* Drive(TLun aLun) const; |
|
275 |
||
276 |
void Connect(); |
|
277 |
void Connect(TLun aLun); |
|
278 |
||
279 |
void Disconnect(); |
|
280 |
void Disconnect(TLun aLun); |
|
281 |
||
282 |
TBool IsMediaChanged(TLun aLun, TBool aReset = EFalse); |
|
283 |
TInt SetCritical(TLun aLun, TBool aCritical); |
|
284 |
||
285 |
TLun MaxLun() const; |
|
286 |
||
287 |
private: |
|
288 |
// private default constructor to ensure that NewL is used |
|
289 |
CDriveManager(TLun aLun); |
|
290 |
void ConstructL(const TLunToDriveMap& aDriveMap); |
|
291 |
||
292 |
private: |
|
293 |
/** |
|
294 |
The array of drives. The index into the array is a LUN. |
|
295 |
*/ |
|
296 |
TMsDriveList iDrives; |
|
297 |
||
298 |
/** |
|
299 |
Publisher for tracking drive state changes. |
|
300 |
*/ |
|
301 |
RDriveStateChangedPublisher* iDriveStateChangedPublisher; |
|
302 |
||
303 |
TLun iMaxLun; |
|
304 |
/** |
|
305 |
A resource owned by DriveManager but used by the Drive objects. |
|
306 |
*/ |
|
307 |
RCriticalSection iDriveCritSec; |
|
308 |
}; |
|
309 |
||
310 |
#include "drivemanager.inl" |
|
311 |
||
312 |
#endif // DRIVEMANAGER_H |