|
1 // Copyright (c) 2007-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 // Drive publishing classes for USB Mass Storage. |
|
15 // RDriveMediaErrorPublisher, |
|
16 // RDriveStateChangedPublisher, |
|
17 // CDriveTransferPublisher, |
|
18 // CDriveWriteTransferPublisher, |
|
19 // CDriveReadTransferPublisher, |
|
20 // CUsbTransferPublisher, |
|
21 // CUsbReadTransferPublisher, |
|
22 // CUsbReadTransferPublisher. |
|
23 // |
|
24 // |
|
25 |
|
26 /** |
|
27 @file |
|
28 @internalTechnology |
|
29 */ |
|
30 |
|
31 #ifndef __DRIVEPUBLISHER_H__ |
|
32 #define __DRIVEPUBLISHER_H__ |
|
33 |
|
34 #include <e32base.h> // C Class Definitions, Cleanup Stack |
|
35 #include <e32def.h> // T Type Definitions |
|
36 #include <e32property.h> |
|
37 #include "usbmsshared.h" // Publish and subscribe property definitions |
|
38 |
|
39 //#define USB_TRANSFER_PUBLISHER |
|
40 #ifdef MSDC_MULTITHREADED |
|
41 // Bytes transferred can be measured at the USB interface or the drive interface. |
|
42 // Since read/write to the drive is performed by background threads we must publish |
|
43 // the bytes transferred at the USB interface. |
|
44 #ifndef USB_TRANSFER_PUBLISHER |
|
45 #define USB_TRANSFER_PUBLISHER |
|
46 #endif |
|
47 #endif |
|
48 |
|
49 // forward declaration |
|
50 class CMassStorageDrive; |
|
51 |
|
52 // typedefs |
|
53 typedef TFixedArray<CMassStorageDrive*, KUsbMsMaxDrives>& TRefMsDriveList; |
|
54 typedef const RArray<TInt>& TRefDriveMap; |
|
55 |
|
56 typedef TFixedArray<TInt64, KUsbMsMaxDrives>& TRefBytesTransferedList; |
|
57 |
|
58 //---------------------------------------------------------------------------- |
|
59 /** |
|
60 @internalTechnology |
|
61 |
|
62 Publishes the EUsbMsDriveState_MediaError property. |
|
63 */ |
|
64 class RDriveMediaErrorPublisher |
|
65 { |
|
66 public: |
|
67 RDriveMediaErrorPublisher(); |
|
68 ~RDriveMediaErrorPublisher(); |
|
69 |
|
70 void PublishError(TBool aError); |
|
71 |
|
72 private: |
|
73 /** |
|
74 Publish and subscribe property for EUsbMsDriveState_MediaError property |
|
75 */ |
|
76 RProperty iMediaErrorProperty; |
|
77 }; |
|
78 |
|
79 //---------------------------------------------------------------------------- |
|
80 /** |
|
81 @internalTechnology |
|
82 |
|
83 Publishes the EUsbMsDriveState_DriveStatus property value for a drive state change. |
|
84 The published drive state is mapped from the drive's mount state and drive state. |
|
85 */ |
|
86 |
|
87 class RDriveStateChangedPublisher |
|
88 { |
|
89 public: |
|
90 RDriveStateChangedPublisher(TRefMsDriveList aDrives, TRefDriveMap aDriveMap); |
|
91 ~RDriveStateChangedPublisher(); |
|
92 void DriveStateChanged(); |
|
93 |
|
94 private: |
|
95 /** |
|
96 Reference to the array of drives. The index into the array is a LUN. |
|
97 */ |
|
98 TRefMsDriveList iDrives; |
|
99 |
|
100 /** |
|
101 Reference to the drive map to convert LUN to Drive Number. |
|
102 */ |
|
103 TRefDriveMap iDriveMap; |
|
104 }; |
|
105 |
|
106 #ifndef USB_TRANSFER_PUBLISHER |
|
107 //---------------------------------------------------------------------------- |
|
108 // measure transfer of bytes at the drive interface |
|
109 //---------------------------------------------------------------------------- |
|
110 |
|
111 /** |
|
112 @internalTechnology |
|
113 |
|
114 Base class for Read and Write publihsers. |
|
115 */ |
|
116 class CDriveTransferPublisher : public CBase |
|
117 { |
|
118 protected: |
|
119 ~CDriveTransferPublisher(); |
|
120 |
|
121 CDriveTransferPublisher(TUsbMsDriveState_Subkey iSubKey, |
|
122 TRefMsDriveList aDrives); |
|
123 void ConstructL(); |
|
124 |
|
125 public: |
|
126 void StartTimer(); |
|
127 void StopTimer(); |
|
128 void DoPublishDataTransferredEvent(); |
|
129 |
|
130 private: |
|
131 virtual TUint GetBytesTransferred(TUint aLun) const = 0; |
|
132 |
|
133 // No of calls to wait without an data transfer from iTimer |
|
134 // before stopping the publish timer. |
|
135 enum {ETimerCancelDelay = 5}; |
|
136 |
|
137 static TInt PublishDataTransferredEvent(TAny* obj); |
|
138 TBool PublishDataTransferred(); |
|
139 |
|
140 protected: |
|
141 TUsbMsDriveState_Subkey iSubKey; |
|
142 /** |
|
143 Reference to the array of drives. The index into the array is a LUN. |
|
144 */ |
|
145 TRefMsDriveList iDrives; |
|
146 |
|
147 /** |
|
148 Publish and subscribe properties for tracking data transfer volume |
|
149 */ |
|
150 RProperty iProperty; |
|
151 |
|
152 private: |
|
153 /** |
|
154 An active object which triggers periodic updates to subscribers. |
|
155 */ |
|
156 CPeriodic* iTimer; |
|
157 |
|
158 /** |
|
159 Set to ETrue when iTimer is running, EFalse otherwise |
|
160 */ |
|
161 TBool iTimerRunning; |
|
162 |
|
163 /** |
|
164 Adds delay between data not being transferred and iTimer being cancelled |
|
165 */ |
|
166 TInt iTimerCancelCnt; |
|
167 }; |
|
168 |
|
169 //---------------------------------------------------------------------------- |
|
170 /** |
|
171 @internalTechnology |
|
172 |
|
173 Publishes EUsbMsDriveState_KBytesWritten property values for tracking data transfer write volume. |
|
174 */ |
|
175 class CDriveWriteTransferPublisher: public CDriveTransferPublisher |
|
176 { |
|
177 public: |
|
178 static CDriveWriteTransferPublisher* NewL(TRefMsDriveList aDrives); |
|
179 |
|
180 private: |
|
181 CDriveWriteTransferPublisher(TRefMsDriveList aDrives); |
|
182 |
|
183 TUint GetBytesTransferred(TUint aLun) const; |
|
184 }; |
|
185 |
|
186 |
|
187 //---------------------------------------------------------------------------- |
|
188 /** |
|
189 @internalTechnology |
|
190 |
|
191 Publishes EUsbMsDriveState_KBytesRead property value for tracking data transfer read volume. |
|
192 */ |
|
193 class CDriveReadTransferPublisher: public CDriveTransferPublisher |
|
194 { |
|
195 public: |
|
196 static CDriveReadTransferPublisher* NewL(TRefMsDriveList aDrives); |
|
197 |
|
198 private: |
|
199 CDriveReadTransferPublisher(TRefMsDriveList aDrives); |
|
200 |
|
201 TUint GetBytesTransferred(TUint aLun) const; |
|
202 }; |
|
203 |
|
204 #else |
|
205 //---------------------------------------------------------------------------- |
|
206 // measure bytes transfered at the USB interface |
|
207 //---------------------------------------------------------------------------- |
|
208 |
|
209 /** |
|
210 @internalTechnology |
|
211 |
|
212 Base class for Read and Write publihsers. |
|
213 */ |
|
214 class CUsbTransferPublisher : public CBase |
|
215 { |
|
216 protected: |
|
217 ~CUsbTransferPublisher(); |
|
218 |
|
219 CUsbTransferPublisher(TUsbMsDriveState_Subkey iSubKey, |
|
220 TRefBytesTransferedList aBytesTransferred); |
|
221 void ConstructL(); |
|
222 |
|
223 public: |
|
224 void StartTimer(); |
|
225 void StopTimer(); |
|
226 void DoPublishDataTransferredEvent(); |
|
227 |
|
228 private: |
|
229 TUint GetBytesTransferred(TUint aLun) const; |
|
230 |
|
231 // No of calls to wait without an data transfer from iTimer |
|
232 // before stopping the publish timer. |
|
233 enum {ETimerCancelDelay = 5}; |
|
234 |
|
235 static TInt PublishDataTransferredEvent(TAny* obj); |
|
236 TBool PublishDataTransferred(); |
|
237 |
|
238 protected: |
|
239 TUsbMsDriveState_Subkey iSubKey; |
|
240 /** |
|
241 Reference to the array of drives. The index into the array is a LUN. |
|
242 */ |
|
243 TRefBytesTransferedList iArray; |
|
244 |
|
245 /** |
|
246 Publish and subscribe properties for tracking data transfer volume |
|
247 */ |
|
248 RProperty iProperty; |
|
249 |
|
250 private: |
|
251 /** |
|
252 An active object which triggers periodic updates to subscribers. |
|
253 */ |
|
254 CPeriodic* iTimer; |
|
255 |
|
256 /** |
|
257 Set to ETrue when iTimer is running, EFalse otherwise |
|
258 */ |
|
259 TBool iTimerRunning; |
|
260 |
|
261 /** |
|
262 Adds delay between data not being transferred and iTimer being cancelled |
|
263 */ |
|
264 TInt iTimerCancelCnt; |
|
265 }; |
|
266 |
|
267 //---------------------------------------------------------------------------- |
|
268 /** |
|
269 @internalTechnology |
|
270 |
|
271 Publishes EUsbMsDriveState_KBytesWritten property values for tracking data transfer write volume. |
|
272 */ |
|
273 class CUsbWriteTransferPublisher: public CUsbTransferPublisher |
|
274 { |
|
275 public: |
|
276 static CUsbWriteTransferPublisher* NewL(TRefBytesTransferedList aBytesTransferred); |
|
277 |
|
278 private: |
|
279 CUsbWriteTransferPublisher(TRefBytesTransferedList aBytesTransferred); |
|
280 }; |
|
281 |
|
282 //---------------------------------------------------------------------------- |
|
283 /** |
|
284 @internalTechnology |
|
285 |
|
286 Publishes EUsbMsDriveState_KBytesRead property value for tracking data transfer read volume. |
|
287 */ |
|
288 class CUsbReadTransferPublisher: public CUsbTransferPublisher |
|
289 { |
|
290 public: |
|
291 static CUsbReadTransferPublisher* NewL(TRefBytesTransferedList aBytesTransferred); |
|
292 |
|
293 private: |
|
294 CUsbReadTransferPublisher(TRefBytesTransferedList aBytesTransferred); |
|
295 }; |
|
296 #endif |
|
297 |
|
298 #endif //__DRIVEPUBLISHER_H__ |