sl@0
|
1 |
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Class implementation of the drive publishing classes -
|
sl@0
|
15 |
// RDriveMediaErrorPublisher,
|
sl@0
|
16 |
// RDriveStateChangedPublisher,
|
sl@0
|
17 |
// CDriveTransferPublisher,
|
sl@0
|
18 |
// CDriveWriteTransferPublisher,
|
sl@0
|
19 |
// CDriveReadTransferPublisher,
|
sl@0
|
20 |
// CUsbTransferPublisher,
|
sl@0
|
21 |
// CUsbReadTransferPublisher,
|
sl@0
|
22 |
// CUsbReadTransferPublisher.
|
sl@0
|
23 |
//
|
sl@0
|
24 |
//
|
sl@0
|
25 |
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
@file
|
sl@0
|
28 |
@internalTechnology
|
sl@0
|
29 |
*/
|
sl@0
|
30 |
|
sl@0
|
31 |
#include "massstoragedebug.h"
|
sl@0
|
32 |
#include "drivepublisher.h"
|
sl@0
|
33 |
#include "drivemanager.h"
|
sl@0
|
34 |
|
sl@0
|
35 |
|
sl@0
|
36 |
//
|
sl@0
|
37 |
// Use Lookup table to translate from the internal pair of state variables
|
sl@0
|
38 |
// to the externally published drive state code.
|
sl@0
|
39 |
//
|
sl@0
|
40 |
LOCAL_D const TUint8 table[][5] =
|
sl@0
|
41 |
{
|
sl@0
|
42 |
//TMountState=EDisconnected
|
sl@0
|
43 |
{EUsbMsDriveState_Disconnected,
|
sl@0
|
44 |
EUsbMsDriveState_Disconnected,
|
sl@0
|
45 |
EUsbMsDriveState_Disconnected,
|
sl@0
|
46 |
EUsbMsDriveState_Disconnected,
|
sl@0
|
47 |
EUsbMsDriveState_Disconnected},
|
sl@0
|
48 |
//TMountState=EConnecting
|
sl@0
|
49 |
{EUsbMsDriveState_Connecting,
|
sl@0
|
50 |
EUsbMsDriveState_Connecting,
|
sl@0
|
51 |
EUsbMsDriveState_Connecting,
|
sl@0
|
52 |
EUsbMsDriveState_Connecting,
|
sl@0
|
53 |
EUsbMsDriveState_Connecting},
|
sl@0
|
54 |
//TMountState=EConnected
|
sl@0
|
55 |
//EIdle,EActive,ELocked,EMediaNotPresent,EErrDisMounted
|
sl@0
|
56 |
{EUsbMsDriveState_Connected,
|
sl@0
|
57 |
EUsbMsDriveState_Active,
|
sl@0
|
58 |
EUsbMsDriveState_Locked,
|
sl@0
|
59 |
EUsbMsDriveState_MediaNotPresent,
|
sl@0
|
60 |
EUsbMsDriveState_Removed},
|
sl@0
|
61 |
//TMountState=EDisconnecting
|
sl@0
|
62 |
{EUsbMsDriveState_Disconnecting,
|
sl@0
|
63 |
EUsbMsDriveState_Disconnecting,
|
sl@0
|
64 |
EUsbMsDriveState_Disconnecting,
|
sl@0
|
65 |
EUsbMsDriveState_Disconnecting,
|
sl@0
|
66 |
EUsbMsDriveState_Disconnecting}
|
sl@0
|
67 |
};
|
sl@0
|
68 |
|
sl@0
|
69 |
|
sl@0
|
70 |
//----------------------------------------------------------------------------
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
Constructor
|
sl@0
|
73 |
*/
|
sl@0
|
74 |
RDriveMediaErrorPublisher::RDriveMediaErrorPublisher()
|
sl@0
|
75 |
{
|
sl@0
|
76 |
__FNLOG("RDriveMediaErrorPublisher::RDriveMediaErrorPublisher()");
|
sl@0
|
77 |
|
sl@0
|
78 |
_LIT_SECURITY_POLICY_PASS(KMassStorageReadPolicy);
|
sl@0
|
79 |
_LIT_SECURITY_POLICY_S0(KMassStorageWritePolicy, KUsbMsDriveState_Category.iUid);
|
sl@0
|
80 |
|
sl@0
|
81 |
TInt result = RProperty::Define(EUsbMsDriveState_MediaError, RProperty::EInt,
|
sl@0
|
82 |
KMassStorageReadPolicy, KMassStorageWritePolicy);
|
sl@0
|
83 |
|
sl@0
|
84 |
__ASSERT_DEBUG(result == KErrAlreadyExists || result == KErrNone, User::Invariant());
|
sl@0
|
85 |
|
sl@0
|
86 |
result = iMediaErrorProperty.Attach(KUsbMsDriveState_Category, EUsbMsDriveState_MediaError);
|
sl@0
|
87 |
__ASSERT_DEBUG(result == KErrNone, User::Invariant());
|
sl@0
|
88 |
}
|
sl@0
|
89 |
|
sl@0
|
90 |
|
sl@0
|
91 |
RDriveMediaErrorPublisher::~RDriveMediaErrorPublisher()
|
sl@0
|
92 |
{
|
sl@0
|
93 |
__FNLOG("RDriveStatePublisher::~RDriveStatePublisher()");
|
sl@0
|
94 |
|
sl@0
|
95 |
iMediaErrorProperty.Close();
|
sl@0
|
96 |
RProperty::Delete(KUsbMsDriveState_Category, EUsbMsDriveState_MediaError);
|
sl@0
|
97 |
}
|
sl@0
|
98 |
|
sl@0
|
99 |
/**
|
sl@0
|
100 |
Publishing method
|
sl@0
|
101 |
|
sl@0
|
102 |
Publishes the Media Error property event
|
sl@0
|
103 |
|
sl@0
|
104 |
@param aError ETrue if drive media has an error else EFalse for no error
|
sl@0
|
105 |
*/
|
sl@0
|
106 |
void RDriveMediaErrorPublisher::PublishError(TBool aError)
|
sl@0
|
107 |
{
|
sl@0
|
108 |
__PRINT1(_L("<< RDriveMediaErrorPublisher::PublishError %x"), aError);
|
sl@0
|
109 |
|
sl@0
|
110 |
TInt oldValue;
|
sl@0
|
111 |
iMediaErrorProperty.Get(oldValue);
|
sl@0
|
112 |
|
sl@0
|
113 |
if (oldValue != aError)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
User::LeaveIfError(iMediaErrorProperty.Set(aError));
|
sl@0
|
116 |
}
|
sl@0
|
117 |
}
|
sl@0
|
118 |
|
sl@0
|
119 |
//----------------------------------------------------------------------------
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
Constructor
|
sl@0
|
122 |
|
sl@0
|
123 |
@param aDrives
|
sl@0
|
124 |
@param aDriveMap
|
sl@0
|
125 |
*/
|
sl@0
|
126 |
RDriveStateChangedPublisher::RDriveStateChangedPublisher(TRefMsDriveList aDrives,
|
sl@0
|
127 |
TRefDriveMap aDriveMap)
|
sl@0
|
128 |
:
|
sl@0
|
129 |
iDrives(aDrives),
|
sl@0
|
130 |
iDriveMap(aDriveMap)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
__FNLOG("RDriveStateChangedPublisher::RDriveStateChangedPublisher()");
|
sl@0
|
133 |
|
sl@0
|
134 |
_LIT_SECURITY_POLICY_PASS(KMassStorageReadPolicy);
|
sl@0
|
135 |
_LIT_SECURITY_POLICY_S0(KMassStorageWritePolicy, KUsbMsDriveState_Category.iUid);
|
sl@0
|
136 |
|
sl@0
|
137 |
TInt result = RProperty::Define(KUsbMsDriveState_Category,
|
sl@0
|
138 |
EUsbMsDriveState_DriveStatus, RProperty::EByteArray,
|
sl@0
|
139 |
KMassStorageReadPolicy, KMassStorageWritePolicy,
|
sl@0
|
140 |
KUsbMsMaxDrives*2);
|
sl@0
|
141 |
__ASSERT_DEBUG(result == KErrAlreadyExists || result == KErrNone, User::Invariant());
|
sl@0
|
142 |
result = result; // remove urel warning
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
|
sl@0
|
146 |
RDriveStateChangedPublisher::~RDriveStateChangedPublisher()
|
sl@0
|
147 |
{
|
sl@0
|
148 |
__FNLOG("RDriveStateChangedPublisher::~RDriveStateChangedPublisher()");
|
sl@0
|
149 |
|
sl@0
|
150 |
RProperty::Delete(KUsbMsDriveState_Category, EUsbMsDriveState_DriveStatus);
|
sl@0
|
151 |
}
|
sl@0
|
152 |
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
Publishing method
|
sl@0
|
156 |
|
sl@0
|
157 |
Sends a property event on behalf of CMassStorageDrive, with the mountstate and drivestate
|
sl@0
|
158 |
values encoded into one 32-bit word.
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
void RDriveStateChangedPublisher::DriveStateChanged()
|
sl@0
|
161 |
{
|
sl@0
|
162 |
__FNLOG("RDriveStateChangedPublisher::DriveStateChanged");
|
sl@0
|
163 |
|
sl@0
|
164 |
|
sl@0
|
165 |
TUsbMsDrivesStatus allDrivesStatus;
|
sl@0
|
166 |
for(TUint8 i=0; i<KUsbMsMaxDrives && iDrives[i]; i++)
|
sl@0
|
167 |
{
|
sl@0
|
168 |
allDrivesStatus.Append(iDriveMap[i]);
|
sl@0
|
169 |
|
sl@0
|
170 |
CMassStorageDrive::TMountState ms = iDrives[i]->MountState();
|
sl@0
|
171 |
CMassStorageDrive::TDriveState ds = iDrives[i]->DriveState();
|
sl@0
|
172 |
TInt driveStatus = EUsbMsDriveState_Error;
|
sl@0
|
173 |
if((TUint8)ds < sizeof(table[0]) && (TUint8)ms < sizeof(table)/sizeof(table[0]))
|
sl@0
|
174 |
{
|
sl@0
|
175 |
driveStatus = table[ms][ds];
|
sl@0
|
176 |
__PRINT3(_L("ms=%d ds=%d %d"), ms, ds, driveStatus);
|
sl@0
|
177 |
}
|
sl@0
|
178 |
allDrivesStatus.Append(driveStatus);
|
sl@0
|
179 |
}
|
sl@0
|
180 |
|
sl@0
|
181 |
__PRINT1(_L("Publishing EUsbMsDriveState_DriveStatus for %d drives\n"),
|
sl@0
|
182 |
allDrivesStatus.Length()/2);
|
sl@0
|
183 |
|
sl@0
|
184 |
if(KErrNone != RProperty::Set(KUsbMsDriveState_Category,
|
sl@0
|
185 |
EUsbMsDriveState_DriveStatus,
|
sl@0
|
186 |
allDrivesStatus))
|
sl@0
|
187 |
{
|
sl@0
|
188 |
__ASSERT_DEBUG(EFalse,User::Invariant());
|
sl@0
|
189 |
}
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
|
sl@0
|
193 |
//----------------------------------------------------------------------------
|
sl@0
|
194 |
#ifndef USB_TRANSFER_PUBLISHER
|
sl@0
|
195 |
/**
|
sl@0
|
196 |
Private default constructor to ensure that NewL is used
|
sl@0
|
197 |
|
sl@0
|
198 |
@param aSubKey
|
sl@0
|
199 |
@param aDrives
|
sl@0
|
200 |
*/
|
sl@0
|
201 |
CDriveTransferPublisher::CDriveTransferPublisher(
|
sl@0
|
202 |
TUsbMsDriveState_Subkey aSubKey,
|
sl@0
|
203 |
TRefMsDriveList aDrives)
|
sl@0
|
204 |
:
|
sl@0
|
205 |
iSubKey(aSubKey),
|
sl@0
|
206 |
iDrives(aDrives)
|
sl@0
|
207 |
{
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
|
sl@0
|
211 |
void CDriveTransferPublisher::ConstructL()
|
sl@0
|
212 |
{
|
sl@0
|
213 |
__FNLOG("CDriveTransferPublisher::ConstructL");
|
sl@0
|
214 |
|
sl@0
|
215 |
_LIT_SECURITY_POLICY_PASS(KMassStorageReadPolicy);
|
sl@0
|
216 |
_LIT_SECURITY_POLICY_S0(KMassStorageWritePolicy, KUsbMsDriveState_Category.iUid);
|
sl@0
|
217 |
|
sl@0
|
218 |
TInt r = RProperty::Define(iSubKey, RProperty::EByteArray,
|
sl@0
|
219 |
KMassStorageReadPolicy, KMassStorageWritePolicy,
|
sl@0
|
220 |
KUsbMsMaxDrives*sizeof(TInt));
|
sl@0
|
221 |
|
sl@0
|
222 |
if (r != KErrAlreadyExists)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
User::LeaveIfError(r);
|
sl@0
|
225 |
}
|
sl@0
|
226 |
|
sl@0
|
227 |
User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, iSubKey));
|
sl@0
|
228 |
|
sl@0
|
229 |
// Create the EDataTransferred timer
|
sl@0
|
230 |
iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
|
sl@0
|
231 |
iTimerRunning = EFalse;
|
sl@0
|
232 |
}
|
sl@0
|
233 |
|
sl@0
|
234 |
|
sl@0
|
235 |
/**
|
sl@0
|
236 |
Destructor
|
sl@0
|
237 |
*/
|
sl@0
|
238 |
CDriveTransferPublisher::~CDriveTransferPublisher()
|
sl@0
|
239 |
{
|
sl@0
|
240 |
__FNLOG("CDriveTransferPublisher::~CDriveTransferPublisher");
|
sl@0
|
241 |
|
sl@0
|
242 |
if(iTimer)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
iTimer->Cancel();
|
sl@0
|
245 |
}
|
sl@0
|
246 |
delete iTimer;
|
sl@0
|
247 |
|
sl@0
|
248 |
iProperty.Close();
|
sl@0
|
249 |
|
sl@0
|
250 |
RProperty::Delete(KUsbMsDriveState_Category, iSubKey);
|
sl@0
|
251 |
}
|
sl@0
|
252 |
|
sl@0
|
253 |
|
sl@0
|
254 |
/**
|
sl@0
|
255 |
A static wrapper for the DoPublishDataTransferredEvent member function
|
sl@0
|
256 |
for use as a timer callback function.
|
sl@0
|
257 |
|
sl@0
|
258 |
@param obj 'this' pointer
|
sl@0
|
259 |
@return not used in CPeriodic callback (see TCallback)
|
sl@0
|
260 |
*/
|
sl@0
|
261 |
TInt CDriveTransferPublisher::PublishDataTransferredEvent(TAny* obj)
|
sl@0
|
262 |
{
|
sl@0
|
263 |
__FNLOG("CDrivePublisher::PublishDataTransferredEvent");
|
sl@0
|
264 |
static_cast<CDriveTransferPublisher*>(obj)->DoPublishDataTransferredEvent();
|
sl@0
|
265 |
return 1;
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
|
sl@0
|
269 |
/**
|
sl@0
|
270 |
Update the data transferred properties if the counts have changed since
|
sl@0
|
271 |
the last update.
|
sl@0
|
272 |
*/
|
sl@0
|
273 |
void CDriveTransferPublisher::DoPublishDataTransferredEvent()
|
sl@0
|
274 |
{
|
sl@0
|
275 |
if (PublishDataTransferred())
|
sl@0
|
276 |
{
|
sl@0
|
277 |
// some data has been transfered so reset the counter
|
sl@0
|
278 |
iTimerCancelCnt = ETimerCancelDelay;
|
sl@0
|
279 |
}
|
sl@0
|
280 |
|
sl@0
|
281 |
// Update the cancel count if no data was transferred the last
|
sl@0
|
282 |
// (few) times this has been called
|
sl@0
|
283 |
if (--iTimerCancelCnt == 0)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
StopTimer();
|
sl@0
|
286 |
iTimerCancelCnt = ETimerCancelDelay;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
}
|
sl@0
|
289 |
|
sl@0
|
290 |
|
sl@0
|
291 |
/**
|
sl@0
|
292 |
Update the data transferred properties if the counts have changed since
|
sl@0
|
293 |
the last update.
|
sl@0
|
294 |
*/
|
sl@0
|
295 |
TBool CDriveTransferPublisher::PublishDataTransferred()
|
sl@0
|
296 |
{
|
sl@0
|
297 |
__FNLOG("CDriveWriteTransferPublisher::PublishDataTransferred");
|
sl@0
|
298 |
|
sl@0
|
299 |
TUsbMsBytesTransferred bytesTransferred;
|
sl@0
|
300 |
TBool dataTransferred = EFalse;
|
sl@0
|
301 |
|
sl@0
|
302 |
for (TInt i=0; i < iDrives.Count() && iDrives[i]; i++)
|
sl@0
|
303 |
{
|
sl@0
|
304 |
bytesTransferred[i] = GetBytesTransferred(i);
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
// Update the properties only if they have changed
|
sl@0
|
308 |
// (or if there's an error reading the old value.)
|
sl@0
|
309 |
// Possible optimisation: keep a copy of the value
|
sl@0
|
310 |
// as a member variable so we don't need the Get.
|
sl@0
|
311 |
TUsbMsBytesTransferred oldValue;
|
sl@0
|
312 |
|
sl@0
|
313 |
if ((iProperty.Get(oldValue) != KErrNone) || (oldValue != bytesTransferred))
|
sl@0
|
314 |
{
|
sl@0
|
315 |
#ifdef __PRINT3
|
sl@0
|
316 |
for (TInt j=0; j < iDrives.Count() && iDrives[j]; j++)
|
sl@0
|
317 |
{
|
sl@0
|
318 |
if(oldValue[j] != bytesTransferred[j])
|
sl@0
|
319 |
{
|
sl@0
|
320 |
__PRINT3(_L("CDrivePublisher: KBytes[%d] %d->%d\n"), j, oldValue[j], bytesTransferred[j]);
|
sl@0
|
321 |
}
|
sl@0
|
322 |
}
|
sl@0
|
323 |
#endif
|
sl@0
|
324 |
if (KErrNone != iProperty.Set(bytesTransferred))
|
sl@0
|
325 |
{
|
sl@0
|
326 |
__ASSERT_DEBUG(EFalse, User::Invariant());
|
sl@0
|
327 |
}
|
sl@0
|
328 |
dataTransferred = ETrue;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
return dataTransferred;
|
sl@0
|
332 |
}
|
sl@0
|
333 |
|
sl@0
|
334 |
|
sl@0
|
335 |
/**
|
sl@0
|
336 |
Starts timer to periodically publish results.
|
sl@0
|
337 |
If the timer is not yet running then start it.
|
sl@0
|
338 |
*/
|
sl@0
|
339 |
void CDriveTransferPublisher::StartTimer()
|
sl@0
|
340 |
{
|
sl@0
|
341 |
__FNLOG("CDrivePublisher::StartTimer");
|
sl@0
|
342 |
|
sl@0
|
343 |
if (!iTimerRunning)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
// EDataTransferred event every second
|
sl@0
|
346 |
const TTimeIntervalMicroSeconds32 interval = 1 * 1000 * 1000;
|
sl@0
|
347 |
TCallBack callback(PublishDataTransferredEvent, this);
|
sl@0
|
348 |
__PRINT(_L("Starting timer"));
|
sl@0
|
349 |
iTimer->Start(interval, interval, callback);
|
sl@0
|
350 |
iTimerRunning = ETrue;
|
sl@0
|
351 |
}
|
sl@0
|
352 |
}
|
sl@0
|
353 |
|
sl@0
|
354 |
|
sl@0
|
355 |
/**
|
sl@0
|
356 |
Ensure that the Timer is stopped
|
sl@0
|
357 |
*/
|
sl@0
|
358 |
void CDriveTransferPublisher::StopTimer()
|
sl@0
|
359 |
{
|
sl@0
|
360 |
__FNLOG("CDrivePublisher::StopTimer");
|
sl@0
|
361 |
|
sl@0
|
362 |
if (iTimerRunning)
|
sl@0
|
363 |
{
|
sl@0
|
364 |
__PRINT(_L("Stopping timer"));
|
sl@0
|
365 |
iTimer->Cancel();
|
sl@0
|
366 |
iTimerRunning = EFalse;
|
sl@0
|
367 |
}
|
sl@0
|
368 |
}
|
sl@0
|
369 |
|
sl@0
|
370 |
|
sl@0
|
371 |
//----------------------------------------------------------------------------
|
sl@0
|
372 |
/**
|
sl@0
|
373 |
Constructor for Write property
|
sl@0
|
374 |
|
sl@0
|
375 |
@param aDrives
|
sl@0
|
376 |
*/
|
sl@0
|
377 |
CDriveWriteTransferPublisher* CDriveWriteTransferPublisher::NewL(TRefMsDriveList aDrives)
|
sl@0
|
378 |
{
|
sl@0
|
379 |
__FNLOG("CDriveWriteTransferPublisher::NewL");
|
sl@0
|
380 |
|
sl@0
|
381 |
CDriveWriteTransferPublisher* self = new (ELeave) CDriveWriteTransferPublisher(aDrives);
|
sl@0
|
382 |
CleanupStack::PushL(self);
|
sl@0
|
383 |
self->ConstructL();
|
sl@0
|
384 |
CleanupStack::Pop();
|
sl@0
|
385 |
return self;
|
sl@0
|
386 |
}
|
sl@0
|
387 |
|
sl@0
|
388 |
|
sl@0
|
389 |
/**
|
sl@0
|
390 |
Constructor
|
sl@0
|
391 |
|
sl@0
|
392 |
@param aDrives
|
sl@0
|
393 |
*/
|
sl@0
|
394 |
CDriveWriteTransferPublisher::CDriveWriteTransferPublisher(TRefMsDriveList aDrives)
|
sl@0
|
395 |
:
|
sl@0
|
396 |
CDriveTransferPublisher(EUsbMsDriveState_KBytesWritten, aDrives)
|
sl@0
|
397 |
{
|
sl@0
|
398 |
}
|
sl@0
|
399 |
|
sl@0
|
400 |
|
sl@0
|
401 |
/**
|
sl@0
|
402 |
Transfer function for Write property
|
sl@0
|
403 |
|
sl@0
|
404 |
@param aLun
|
sl@0
|
405 |
*/
|
sl@0
|
406 |
TUint CDriveWriteTransferPublisher::GetBytesTransferred(TUint aLun) const
|
sl@0
|
407 |
{
|
sl@0
|
408 |
return iDrives[aLun]->KBytesWritten();
|
sl@0
|
409 |
}
|
sl@0
|
410 |
|
sl@0
|
411 |
|
sl@0
|
412 |
//----------------------------------------------------------------------------
|
sl@0
|
413 |
/**
|
sl@0
|
414 |
Constructor for Read property
|
sl@0
|
415 |
|
sl@0
|
416 |
@param aDrives
|
sl@0
|
417 |
*/
|
sl@0
|
418 |
CDriveReadTransferPublisher* CDriveReadTransferPublisher::NewL(TRefMsDriveList aDrives)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
__FNLOG("CDriveWriteTransferPublisher::NewL");
|
sl@0
|
421 |
|
sl@0
|
422 |
CDriveReadTransferPublisher* self = new (ELeave) CDriveReadTransferPublisher(aDrives);
|
sl@0
|
423 |
CleanupStack::PushL(self);
|
sl@0
|
424 |
self->ConstructL();
|
sl@0
|
425 |
CleanupStack::Pop();
|
sl@0
|
426 |
return self;
|
sl@0
|
427 |
}
|
sl@0
|
428 |
|
sl@0
|
429 |
|
sl@0
|
430 |
/**
|
sl@0
|
431 |
Constructor
|
sl@0
|
432 |
|
sl@0
|
433 |
@param aDrives
|
sl@0
|
434 |
*/
|
sl@0
|
435 |
CDriveReadTransferPublisher::CDriveReadTransferPublisher(TRefMsDriveList aDrives)
|
sl@0
|
436 |
:
|
sl@0
|
437 |
CDriveTransferPublisher(EUsbMsDriveState_KBytesRead, aDrives)
|
sl@0
|
438 |
{
|
sl@0
|
439 |
}
|
sl@0
|
440 |
|
sl@0
|
441 |
|
sl@0
|
442 |
/**
|
sl@0
|
443 |
Transfer function for Read property
|
sl@0
|
444 |
|
sl@0
|
445 |
@param aLun
|
sl@0
|
446 |
*/
|
sl@0
|
447 |
TUint CDriveReadTransferPublisher::GetBytesTransferred(TUint aLun) const
|
sl@0
|
448 |
{
|
sl@0
|
449 |
return iDrives[aLun]->KBytesRead();
|
sl@0
|
450 |
}
|
sl@0
|
451 |
|
sl@0
|
452 |
|
sl@0
|
453 |
//----------------------------------------------------------------------------
|
sl@0
|
454 |
#else
|
sl@0
|
455 |
/**
|
sl@0
|
456 |
Private default constructor to ensure that NewL is used
|
sl@0
|
457 |
|
sl@0
|
458 |
@param aSubKey
|
sl@0
|
459 |
@param aArray
|
sl@0
|
460 |
*/
|
sl@0
|
461 |
CUsbTransferPublisher::CUsbTransferPublisher(
|
sl@0
|
462 |
TUsbMsDriveState_Subkey aSubKey,
|
sl@0
|
463 |
TRefBytesTransferedList aArray)
|
sl@0
|
464 |
:
|
sl@0
|
465 |
iSubKey(aSubKey),
|
sl@0
|
466 |
iArray(aArray)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
}
|
sl@0
|
469 |
|
sl@0
|
470 |
|
sl@0
|
471 |
void CUsbTransferPublisher::ConstructL()
|
sl@0
|
472 |
{
|
sl@0
|
473 |
__FNLOG("CUsbTransferPublisher::ConstructL");
|
sl@0
|
474 |
|
sl@0
|
475 |
_LIT_SECURITY_POLICY_PASS(KMassStorageReadPolicy);
|
sl@0
|
476 |
_LIT_SECURITY_POLICY_S0(KMassStorageWritePolicy, KUsbMsDriveState_Category.iUid);
|
sl@0
|
477 |
|
sl@0
|
478 |
TInt r = RProperty::Define(iSubKey, RProperty::EByteArray,
|
sl@0
|
479 |
KMassStorageReadPolicy, KMassStorageWritePolicy,
|
sl@0
|
480 |
KUsbMsMaxDrives*sizeof(TInt));
|
sl@0
|
481 |
|
sl@0
|
482 |
if (r != KErrAlreadyExists)
|
sl@0
|
483 |
{
|
sl@0
|
484 |
User::LeaveIfError(r);
|
sl@0
|
485 |
}
|
sl@0
|
486 |
|
sl@0
|
487 |
// Attach to the properties here. Only do this once, continuously attaching
|
sl@0
|
488 |
// will currently cause a memory leak
|
sl@0
|
489 |
User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, iSubKey));
|
sl@0
|
490 |
|
sl@0
|
491 |
// Create the EDataTransferred timer
|
sl@0
|
492 |
iTimer = CPeriodic::NewL(CActive::EPriorityStandard);
|
sl@0
|
493 |
iTimerRunning = EFalse;
|
sl@0
|
494 |
}
|
sl@0
|
495 |
|
sl@0
|
496 |
|
sl@0
|
497 |
/**
|
sl@0
|
498 |
Destructor
|
sl@0
|
499 |
*/
|
sl@0
|
500 |
CUsbTransferPublisher::~CUsbTransferPublisher()
|
sl@0
|
501 |
{
|
sl@0
|
502 |
__FNLOG("CUsbTransferPublisher::~CDriveTransferPublisher");
|
sl@0
|
503 |
|
sl@0
|
504 |
if(iTimer)
|
sl@0
|
505 |
{
|
sl@0
|
506 |
iTimer->Cancel();
|
sl@0
|
507 |
}
|
sl@0
|
508 |
delete iTimer;
|
sl@0
|
509 |
|
sl@0
|
510 |
iProperty.Close();
|
sl@0
|
511 |
|
sl@0
|
512 |
RProperty::Delete(KUsbMsDriveState_Category, iSubKey);
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
|
sl@0
|
516 |
/**
|
sl@0
|
517 |
A static wrapper for the DoPublishDataTransferredEvent member function
|
sl@0
|
518 |
for use as a timer callback function.
|
sl@0
|
519 |
|
sl@0
|
520 |
@param obj 'this' pointer
|
sl@0
|
521 |
@return not used in CPeriodic callback (see TCallback)
|
sl@0
|
522 |
*/
|
sl@0
|
523 |
TInt CUsbTransferPublisher::PublishDataTransferredEvent(TAny* obj)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
__FNLOG("CUsbTransferPublisher::PublishDataTransferredEvent");
|
sl@0
|
526 |
static_cast<CUsbTransferPublisher*>(obj)->DoPublishDataTransferredEvent();
|
sl@0
|
527 |
return 1;
|
sl@0
|
528 |
}
|
sl@0
|
529 |
|
sl@0
|
530 |
|
sl@0
|
531 |
/**
|
sl@0
|
532 |
Update the data transferred properties if the counts have changed since
|
sl@0
|
533 |
the last update.
|
sl@0
|
534 |
*/
|
sl@0
|
535 |
void CUsbTransferPublisher::DoPublishDataTransferredEvent()
|
sl@0
|
536 |
{
|
sl@0
|
537 |
if (PublishDataTransferred())
|
sl@0
|
538 |
{
|
sl@0
|
539 |
// some data has been transfered so reset the counter
|
sl@0
|
540 |
iTimerCancelCnt = ETimerCancelDelay;
|
sl@0
|
541 |
}
|
sl@0
|
542 |
|
sl@0
|
543 |
// Update the cancel count if no data was transferred the last
|
sl@0
|
544 |
// (few) times this has been called
|
sl@0
|
545 |
if (--iTimerCancelCnt == 0)
|
sl@0
|
546 |
{
|
sl@0
|
547 |
StopTimer();
|
sl@0
|
548 |
iTimerCancelCnt = ETimerCancelDelay;
|
sl@0
|
549 |
}
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
|
sl@0
|
553 |
/**
|
sl@0
|
554 |
Update the data transferred properties if the counts have changed since
|
sl@0
|
555 |
the last update.
|
sl@0
|
556 |
*/
|
sl@0
|
557 |
TBool CUsbTransferPublisher::PublishDataTransferred()
|
sl@0
|
558 |
{
|
sl@0
|
559 |
__FNLOG("CUsbWriteTransferPublisher::PublishDataTransferred");
|
sl@0
|
560 |
|
sl@0
|
561 |
TUsbMsBytesTransferred bytesTransferred;
|
sl@0
|
562 |
TBool dataTransferred = EFalse;
|
sl@0
|
563 |
|
sl@0
|
564 |
for (TInt i = 0; i < iArray.Count(); i++)
|
sl@0
|
565 |
{
|
sl@0
|
566 |
bytesTransferred[i] = GetBytesTransferred(i);
|
sl@0
|
567 |
}
|
sl@0
|
568 |
|
sl@0
|
569 |
// Update the properties only if they have changed
|
sl@0
|
570 |
// (or if there's an error reading the old value.)
|
sl@0
|
571 |
// Possible optimisation: keep a copy of the value
|
sl@0
|
572 |
// as a member variable so we don't need the Get.
|
sl@0
|
573 |
TUsbMsBytesTransferred oldValue;
|
sl@0
|
574 |
|
sl@0
|
575 |
if ((iProperty.Get(oldValue) != KErrNone) || (oldValue != bytesTransferred))
|
sl@0
|
576 |
{
|
sl@0
|
577 |
#ifdef __PRINT3
|
sl@0
|
578 |
// trace of the bytes transferred
|
sl@0
|
579 |
for (TInt j=0; j < iArray.Count(); j++)
|
sl@0
|
580 |
{
|
sl@0
|
581 |
if(oldValue[j] != bytesTransferred[j])
|
sl@0
|
582 |
{
|
sl@0
|
583 |
__PRINT3(_L("CDrivePublisher: KBytes[%d] %d->%d\n"), j, oldValue[j], bytesTransferred[j]);
|
sl@0
|
584 |
}
|
sl@0
|
585 |
}
|
sl@0
|
586 |
#endif
|
sl@0
|
587 |
if (KErrNone != iProperty.Set(bytesTransferred))
|
sl@0
|
588 |
{
|
sl@0
|
589 |
__ASSERT_DEBUG(EFalse, User::Invariant());
|
sl@0
|
590 |
}
|
sl@0
|
591 |
dataTransferred = ETrue;
|
sl@0
|
592 |
}
|
sl@0
|
593 |
|
sl@0
|
594 |
return dataTransferred;
|
sl@0
|
595 |
}
|
sl@0
|
596 |
|
sl@0
|
597 |
|
sl@0
|
598 |
/**
|
sl@0
|
599 |
Starts timer to periodically publish results.
|
sl@0
|
600 |
If the timer is not yet running then start it.
|
sl@0
|
601 |
*/
|
sl@0
|
602 |
void CUsbTransferPublisher::StartTimer()
|
sl@0
|
603 |
{
|
sl@0
|
604 |
__FNLOG("CUsbTransferPublisher::StartTimer");
|
sl@0
|
605 |
|
sl@0
|
606 |
if (!iTimerRunning)
|
sl@0
|
607 |
{
|
sl@0
|
608 |
// EDataTransferred event every second
|
sl@0
|
609 |
const TTimeIntervalMicroSeconds32 interval = 1 * 1000 * 1000;
|
sl@0
|
610 |
TCallBack callback(PublishDataTransferredEvent, this);
|
sl@0
|
611 |
__PRINT(_L("Starting timer"));
|
sl@0
|
612 |
iTimer->Start(interval, interval, callback);
|
sl@0
|
613 |
iTimerRunning = ETrue;
|
sl@0
|
614 |
}
|
sl@0
|
615 |
}
|
sl@0
|
616 |
|
sl@0
|
617 |
|
sl@0
|
618 |
/**
|
sl@0
|
619 |
Ensure that the Timer is stopped
|
sl@0
|
620 |
*/
|
sl@0
|
621 |
void CUsbTransferPublisher::StopTimer()
|
sl@0
|
622 |
{
|
sl@0
|
623 |
__FNLOG("CUsbTransferPublisher::StopTimer");
|
sl@0
|
624 |
|
sl@0
|
625 |
if (iTimerRunning)
|
sl@0
|
626 |
{
|
sl@0
|
627 |
__PRINT(_L("Stopping timer"));
|
sl@0
|
628 |
iTimer->Cancel();
|
sl@0
|
629 |
iTimerRunning = EFalse;
|
sl@0
|
630 |
}
|
sl@0
|
631 |
}
|
sl@0
|
632 |
|
sl@0
|
633 |
|
sl@0
|
634 |
//----------------------------------------------------------------------------
|
sl@0
|
635 |
/**
|
sl@0
|
636 |
Constructor for Write property
|
sl@0
|
637 |
|
sl@0
|
638 |
@param aArray
|
sl@0
|
639 |
*/
|
sl@0
|
640 |
CUsbWriteTransferPublisher* CUsbWriteTransferPublisher::NewL(TRefBytesTransferedList aArray)
|
sl@0
|
641 |
{
|
sl@0
|
642 |
__FNLOG("CUsbWriteTransferPublisher::NewL");
|
sl@0
|
643 |
|
sl@0
|
644 |
CUsbWriteTransferPublisher* self = new (ELeave) CUsbWriteTransferPublisher(aArray);
|
sl@0
|
645 |
CleanupStack::PushL(self);
|
sl@0
|
646 |
self->ConstructL();
|
sl@0
|
647 |
CleanupStack::Pop();
|
sl@0
|
648 |
return self;
|
sl@0
|
649 |
}
|
sl@0
|
650 |
|
sl@0
|
651 |
|
sl@0
|
652 |
CUsbWriteTransferPublisher::CUsbWriteTransferPublisher(
|
sl@0
|
653 |
TRefBytesTransferedList aArray)
|
sl@0
|
654 |
:
|
sl@0
|
655 |
CUsbTransferPublisher(EUsbMsDriveState_KBytesWritten, aArray)
|
sl@0
|
656 |
{
|
sl@0
|
657 |
}
|
sl@0
|
658 |
|
sl@0
|
659 |
|
sl@0
|
660 |
//----------------------------------------------------------------------------
|
sl@0
|
661 |
/**
|
sl@0
|
662 |
Constructor for Read property
|
sl@0
|
663 |
|
sl@0
|
664 |
@param aArray
|
sl@0
|
665 |
*/
|
sl@0
|
666 |
CUsbReadTransferPublisher* CUsbReadTransferPublisher::NewL(TRefBytesTransferedList aArray)
|
sl@0
|
667 |
{
|
sl@0
|
668 |
__FNLOG("CUsbWriteTransferPublisher::NewL");
|
sl@0
|
669 |
|
sl@0
|
670 |
CUsbReadTransferPublisher* self = new (ELeave) CUsbReadTransferPublisher(aArray);
|
sl@0
|
671 |
CleanupStack::PushL(self);
|
sl@0
|
672 |
self->ConstructL();
|
sl@0
|
673 |
CleanupStack::Pop();
|
sl@0
|
674 |
return self;
|
sl@0
|
675 |
}
|
sl@0
|
676 |
|
sl@0
|
677 |
|
sl@0
|
678 |
CUsbReadTransferPublisher::CUsbReadTransferPublisher(
|
sl@0
|
679 |
TRefBytesTransferedList aArray)
|
sl@0
|
680 |
:
|
sl@0
|
681 |
CUsbTransferPublisher(EUsbMsDriveState_KBytesRead, aArray)
|
sl@0
|
682 |
{
|
sl@0
|
683 |
}
|
sl@0
|
684 |
#endif // USB_TRANSFER_PUBLISHER
|