messagingfw/msgsrvnstore/server/src/diskchange.cpp
changeset 0 8e480a14352b
child 10 30d6238592e8
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 "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 //
       
    15 
       
    16 #include "diskchange.h"
       
    17 #include "MSVPANIC.H"
       
    18 
       
    19 CMsvNotifyDiskChange::CMsvNotifyDiskChange(RFs& aFs, MMsvDiskChangeObserver& aObserver)
       
    20 : CMsgActive(EPriorityHigh), iFs(aFs), iObserver(aObserver)
       
    21 	{
       
    22 	CActiveScheduler::Add(this);
       
    23 	}
       
    24 
       
    25 CMsvNotifyDiskChange::~CMsvNotifyDiskChange()
       
    26 	{
       
    27 	Cancel();
       
    28 	}
       
    29 
       
    30 TInt CMsvNotifyDiskChange::Start(const TDriveUnit& aDrive, TUint aUniqueId)
       
    31 //
       
    32 // aDrive - The drive for which we want notifications
       
    33 // aUniqueId - The id we expect the drive to have
       
    34 //
       
    35 	{
       
    36 	__ASSERT_DEBUG(!IsActive(), PanicServer(EMsvDiskChangeNotiferActive));
       
    37 
       
    38 	iUniqueId = aUniqueId;
       
    39 
       
    40 	// Check if the drive is removable
       
    41 	TDriveInfo drive;
       
    42 	TInt error = iFs.Drive(drive, TInt(aDrive));
       
    43 	if (error != KErrNone)
       
    44 		return error;
       
    45 
       
    46 	iDrive = TInt(aDrive);
       
    47 
       
    48 	// Setup file system notification
       
    49 	iFs.NotifyChange(ENotifyDisk, iStatus);
       
    50 	SetActive();
       
    51 
       
    52 	// See if the disk is currently available
       
    53 	TVolumeInfo volume;
       
    54 	iDiskRemoved = iFs.Volume(volume, TInt(iDrive)) != KErrNone || iDiskMissing;
       
    55 
       
    56 	return KErrNone;
       
    57 	}
       
    58 
       
    59 void CMsvNotifyDiskChange::DoCancel()
       
    60 	{
       
    61 	iFs.NotifyChangeCancel();
       
    62 	}
       
    63 
       
    64 void CMsvNotifyDiskChange::DoRunL()
       
    65 	{
       
    66 	// Flag to indicate we should continue to notify of disk changes
       
    67 	TBool keepGoing = ETrue;
       
    68 
       
    69 	// Get disk details - If this fails assume it's missing
       
    70 	TVolumeInfo volume;
       
    71 	if (iFs.Volume(volume, TInt(iDrive)) != KErrNone || iDiskMissing)
       
    72 		{
       
    73 		if (!iDiskRemoved)
       
    74 			{
       
    75 			// The disk has been removed
       
    76 			keepGoing = iObserver.DiskRemoved(iDrive);
       
    77 			}
       
    78 
       
    79 		iDiskRemoved = ETrue;
       
    80 		}
       
    81 	else if (iDiskRemoved)
       
    82 		{
       
    83 		if (iUniqueId != volume.iUniqueID || iWrongId)
       
    84 			{
       
    85 			// The incorrect disk is being used
       
    86 			keepGoing = iObserver.DiskChanged(iDrive, volume.iUniqueID);
       
    87 			}
       
    88 		else
       
    89 			{
       
    90 			// The correct disk has been inserted
       
    91 			keepGoing = iObserver.DiskInserted(iDrive);
       
    92 			}
       
    93 
       
    94 		iDiskRemoved = EFalse;
       
    95 		}
       
    96 	
       
    97 	// Setup file system notification
       
    98 	if (keepGoing)
       
    99 		{
       
   100 		iFs.NotifyChange(ENotifyDisk, iStatus);
       
   101 		SetActive();
       
   102 		}
       
   103 	}
       
   104