messagingfw/msgsrvnstore/server/src/cmsvdiskchangenotifier.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2008-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 "cmsvdiskchangenotifier.h"
       
    17 
       
    18 CMsvDiskChangeNotifier::CMsvDiskChangeNotifier(const TDriveUnit& aDrive, MMsvDiskChangeObserver& aObserver) 
       
    19 :CActive(EPriorityHigh), iObserver(aObserver)
       
    20 	{
       
    21 	iDrive = TInt(aDrive);
       
    22 	CActiveScheduler::Add(this);
       
    23 	}
       
    24 
       
    25 CMsvDiskChangeNotifier::~CMsvDiskChangeNotifier()
       
    26 	{
       
    27 	Cancel();
       
    28 	iFs.Close();
       
    29 	delete iDrivePath;
       
    30 	iDrivePath = NULL;
       
    31 	}
       
    32 
       
    33 CMsvDiskChangeNotifier* CMsvDiskChangeNotifier::NewL(const TDriveUnit& aDrive, MMsvDiskChangeObserver& aObserver)
       
    34 	{
       
    35 	CMsvDiskChangeNotifier* self = new(ELeave) CMsvDiskChangeNotifier(aDrive, aObserver);
       
    36 	CleanupStack::PushL(self);
       
    37 	
       
    38 	self->ConstructL();
       
    39 	
       
    40 	CleanupStack::Pop(self);
       
    41 	return self;
       
    42 	}
       
    43 
       
    44 void CMsvDiskChangeNotifier::ConstructL()
       
    45 	{
       
    46 	User::LeaveIfError(iFs.Connect());
       
    47 	iDrivePath = HBufC16::NewL(KMaxDriveName+2);
       
    48 	iDrivePath->Des().Append(iDrive.Name());
       
    49 	iDrivePath->Des().Append(_L("\\"));
       
    50 	}
       
    51 	
       
    52 void CMsvDiskChangeNotifier::Start()
       
    53 	{
       
    54 	iFs.NotifyChange(ENotifyDisk, iStatus, *iDrivePath);
       
    55 	SetActive();
       
    56 	}
       
    57 
       
    58 void CMsvDiskChangeNotifier::DoCancel()
       
    59 	{
       
    60 	iFs.NotifyChangeCancel();
       
    61 	}
       
    62 
       
    63 void CMsvDiskChangeNotifier::RunL()
       
    64 	{
       
    65 	TVolumeInfo volume;
       
    66 	TInt error = iFs.Volume(volume, TInt(iDrive));
       
    67 	if(KErrNone == error)
       
    68 		{
       
    69 		iObserver.DiskInserted(iDrive);
       
    70 		}
       
    71 	else if(KErrNotReady == error)
       
    72 		{
       
    73 		iObserver.DiskRemoved(iDrive);
       
    74 		}
       
    75 	else
       
    76 		{
       
    77 		iObserver.DiskChanged(iDrive);
       
    78 		}
       
    79 	
       
    80 	if(!IsActive())
       
    81 		{
       
    82 		iFs.NotifyChange(ENotifyDisk, iStatus, *iDrivePath);
       
    83 		SetActive();
       
    84 		}
       
    85 	}
       
    86 
       
    87