38 |
42 |
39 void CMMCMonitorPlugin::ConstructL() // second-phase constructor |
43 void CMMCMonitorPlugin::ConstructL() // second-phase constructor |
40 { |
44 { |
41 WRITELOG( "CMMCMonitorPlugin::ConstructL" ); |
45 WRITELOG( "CMMCMonitorPlugin::ConstructL" ); |
42 |
46 |
|
47 User::LeaveIfError( iFs.Connect() ); |
|
48 |
43 iMMCMonitor = CMMCMonitorAO::NewL(); |
49 iMMCMonitor = CMMCMonitorAO::NewL(); |
44 iMountTask = CMMCMountTaskAO::NewL(); |
50 iMountTask = CMMCMountTaskAO::NewL(); |
45 iUsbMonitor = CMMCUsbAO::NewL(); |
51 iUsbMonitor = CMMCUsbAO::NewL(); |
46 iMdEClient = NULL; |
52 iMdEClient = NULL; |
47 } |
53 } |
118 aHarvesterPluginFactory, CActive::EPriorityHigh, alreadyWaited ) ); |
126 aHarvesterPluginFactory, CActive::EPriorityHigh, alreadyWaited ) ); |
119 alreadyWaited = ETrue; |
127 alreadyWaited = ETrue; |
120 } |
128 } |
121 } |
129 } |
122 |
130 |
|
131 if( hdMediaId == 0 ) |
|
132 { |
|
133 // Try to fetch internall mass storage media id again if it was not mounted |
|
134 hdMediaId = iMountTask->GetInternalDriveMediaId(); |
|
135 } |
|
136 |
123 // scan mass storage to catch all chances even if battery dies during operation that should be catched |
137 // scan mass storage to catch all chances even if battery dies during operation that should be catched |
124 if( hdMediaId ) |
138 if( hdMediaId ) |
125 { |
139 { |
126 TBool exists( EFalse ); |
140 TBool exists( EFalse ); |
127 TRAP_IGNORE( exists= iMdEClient->GetMediaL( hdMediaId, driveLetter, presentState ) ); |
141 TRAP_IGNORE( exists= iMdEClient->GetMediaL( hdMediaId, driveLetter, presentState ) ); |
205 { |
219 { |
206 return; |
220 return; |
207 } |
221 } |
208 if( aMediaID != 0 && aEventType == EMounted) |
222 if( aMediaID != 0 && aEventType == EMounted) |
209 { |
223 { |
210 RFs fs; |
|
211 const TInt err = fs.Connect(); |
|
212 if ( err != KErrNone ) |
|
213 { |
|
214 delete mountData; |
|
215 return; |
|
216 } |
|
217 |
|
218 TUint status; |
224 TUint status; |
219 TInt drive; |
225 TInt drive; |
220 fs.CharToDrive( aDriveChar, drive ); |
226 iFs.CharToDrive( aDriveChar, drive ); |
221 if( DriveInfo::GetDriveStatus( fs, drive, status ) == KErrNone ) |
227 if( DriveInfo::GetDriveStatus( iFs, drive, status ) == KErrNone ) |
222 { |
228 { |
223 //The "Out of disk space" mde query uses the MdE_Preferences table |
229 //The "Out of disk space" mde query uses the MdE_Preferences table |
224 if( !(status & DriveInfo::EDriveInternal) ) |
230 if( !(status & DriveInfo::EDriveInternal) ) |
225 { |
231 { |
226 iMdEClient->AddMemoryCard( aMediaID ); |
232 iMdEClient->AddMemoryCard( aMediaID ); |
227 } |
233 } |
228 } |
234 } |
229 |
|
230 fs.Close(); |
|
231 } |
235 } |
232 |
236 |
233 mountData->iDrivePath.Append( aDriveChar ); |
237 mountData->iDrivePath.Append( aDriveChar ); |
234 mountData->iDrivePath.Append( KColon ); |
238 mountData->iDrivePath.Append( KColon ); |
235 mountData->iMediaID = aMediaID; |
239 mountData->iMediaID = aMediaID; |
252 } |
260 } |
253 if( mountData->iMediaID ) |
261 if( mountData->iMediaID ) |
254 { |
262 { |
255 WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EDismounted" ); |
263 WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EDismounted" ); |
256 mountData->iMountType = TMountData::EUnmount; |
264 mountData->iMountType = TMountData::EUnmount; |
|
265 if( !iMountTask->IsActive() ) |
|
266 { |
|
267 iMountTask->SetPriority( KHarvesterPriorityMonitorPlugin ); |
|
268 } |
257 iMountTask->StartUnmount( *mountData ); |
269 iMountTask->StartUnmount( *mountData ); |
258 } |
270 } |
259 } |
271 } |
260 break; |
272 break; |
261 |
273 |
262 case EFormatted: |
274 case EFormatted: |
263 { |
275 { |
264 WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EFormatted" ); |
276 WRITELOG( "CMMCMonitorPlugin::MountEvent with parameter EFormatted" ); |
265 mountData->iMountType = TMountData::EFormat; |
277 mountData->iMountType = TMountData::EFormat; |
|
278 if( !iMountTask->IsActive() ) |
|
279 { |
|
280 iMountTask->SetPriority( KHarvesterPriorityMonitorPlugin ); |
|
281 } |
266 iMountTask->StartUnmount( *mountData ); |
282 iMountTask->StartUnmount( *mountData ); |
267 } |
283 } |
268 break; |
284 break; |
269 |
285 |
270 default: |
286 default: |
277 } |
293 } |
278 |
294 |
279 void CMMCMonitorPlugin::StartMonitoringAllMMCsL( RArray<TMdEMediaInfo>& aMedias ) |
295 void CMMCMonitorPlugin::StartMonitoringAllMMCsL( RArray<TMdEMediaInfo>& aMedias ) |
280 { |
296 { |
281 WRITELOG( "CMMCMonitorPlugin::StartMonitoringAllMMCs" ); |
297 WRITELOG( "CMMCMonitorPlugin::StartMonitoringAllMMCs" ); |
282 |
298 |
283 RFs fs; |
|
284 User::LeaveIfError( fs.Connect() ); |
|
285 CleanupClosePushL( fs ); |
|
286 |
|
287 TDriveInfo driveInfo; |
299 TDriveInfo driveInfo; |
288 TDriveList driveList; |
300 TDriveList driveList; |
289 TInt numOfElements( 0 ); |
301 TInt numOfElements( 0 ); |
290 DriveInfo::GetUserVisibleDrives( fs, |
302 DriveInfo::GetUserVisibleDrives( iFs, |
291 driveList, |
303 driveList, |
292 numOfElements, |
304 numOfElements, |
293 KDriveAttExclude | KDriveAttRemote | KDriveAttRom ); |
305 KDriveAttExclude | KDriveAttRemote | KDriveAttRom ); |
|
306 |
|
307 #ifdef __WINSCW__ |
|
308 TFileName systemPath = PathInfo::GetPath( PathInfo::EPhoneMemoryRootPath ); |
|
309 TInt systemDriveNum( -1 ); |
|
310 iFs.CharToDrive( systemPath[0], systemDriveNum ); |
|
311 #endif |
294 |
312 |
295 TInt i( 0 ); |
313 TInt i( 0 ); |
296 TChar drive; |
314 TChar drive; |
297 const TInt acount = driveList.Length(); |
315 const TInt acount = driveList.Length(); |
298 const TInt mediaCount = aMedias.Count(); |
316 const TInt mediaCount = aMedias.Count(); |
300 |
318 |
301 // set removed medias to not present |
319 // set removed medias to not present |
302 for ( i = 0; i < mediaCount; i++ ) |
320 for ( i = 0; i < mediaCount; i++ ) |
303 { |
321 { |
304 TInt driveNum(0); |
322 TInt driveNum(0); |
305 fs.CharToDrive( aMedias[i].iDrive, driveNum ); |
323 iFs.CharToDrive( aMedias[i].iDrive, driveNum ); |
306 TUint32 mediaId = FSUtil::MediaID( fs, driveNum ); |
324 TUint32 mediaId = FSUtil::MediaID( iFs, driveNum ); |
307 if ( mediaId != aMedias[i].iMediaId ) |
325 if ( mediaId != aMedias[i].iMediaId ) |
308 { |
326 { |
309 iMdEClient->SetMediaL( aMedias[i].iMediaId, aMedias[i].iDrive, EFalse ); |
327 iMdEClient->SetMediaL( aMedias[i].iMediaId, aMedias[i].iDrive, EFalse ); |
310 } |
328 } |
311 } |
329 } |
312 |
330 |
313 for ( i = 0; i < acount; i++ ) |
331 for ( i = 0; i < acount; i++ ) |
314 { |
332 { |
|
333 #ifdef __WINSCW__ |
|
334 if ( i == systemDriveNum ) |
|
335 { |
|
336 continue; |
|
337 } |
|
338 #endif |
|
339 |
315 if ( driveList[i] > 0 ) |
340 if ( driveList[i] > 0 ) |
316 { |
341 { |
317 TUint driveStatus( 0 ); |
342 TUint driveStatus( 0 ); |
318 DriveInfo::GetDriveStatus( fs, i, driveStatus ); |
343 DriveInfo::GetDriveStatus( iFs, i, driveStatus ); |
319 |
344 |
320 if ( driveStatus & DriveInfo::EDriveUsbMemory ) |
345 if ( driveStatus & DriveInfo::EDriveUsbMemory ) |
321 { |
346 { |
322 driveList[i] = 0; |
347 driveList[i] = 0; |
323 continue; |
348 continue; |
324 } |
349 } |
325 |
350 |
326 fs.Drive( driveInfo, i ); |
351 iFs.Drive( driveInfo, i ); |
327 if ( driveInfo.iDriveAtt & KDriveAttRemovable && driveInfo.iType != EMediaNotPresent ) |
352 if ( ((driveInfo.iDriveAtt & KDriveAttRemovable) || (driveInfo.iDriveAtt & KDriveAttLogicallyRemovable) || |
|
353 (driveInfo.iType == EMediaHardDisk && driveStatus & DriveInfo::EDriveInternal) ) && |
|
354 (driveInfo.iType != EMediaNotPresent) ) |
328 { |
355 { |
329 count++; // DEBUG INFO |
356 count++; // DEBUG INFO |
330 |
357 |
331 fs.DriveToChar( i, drive ); |
358 iFs.DriveToChar( i, drive ); |
332 |
359 |
333 // set media id to MdE |
360 // set media id to MdE |
334 TUint32 mediaId = FSUtil::MediaID( fs, i ); |
361 TUint32 mediaId = FSUtil::MediaID( iFs, i ); |
335 if ( mediaId != 0 ) |
362 if ( mediaId != 0 ) |
336 { |
363 { |
337 iMdEClient->SetMediaL( mediaId, drive, ETrue ); |
364 iMdEClient->SetMediaL( mediaId, drive, ETrue ); |
338 |
365 |
339 AddNotificationPathL( drive ); |
366 AddNotificationPathL( drive ); |
340 } |
367 } |
341 } |
368 } |
342 } |
369 } |
343 } |
370 } |
344 |
371 |
345 CleanupStack::PopAndDestroy( &fs ); |
|
346 |
|
347 WRITELOG1( "CMMCMonitorPlugin::StartMonitoringAllMMCs found %d MMCs", count ); |
372 WRITELOG1( "CMMCMonitorPlugin::StartMonitoringAllMMCs found %d MMCs", count ); |
348 } |
373 } |
|
374 |