messagingfw/msgsrvnstore/server/src/cmsvdiskchangenotifier.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Mon, 04 Oct 2010 00:49:39 +0300
changeset 54 bb1b421e3b9e
parent 0 8e480a14352b
permissions -rw-r--r--
Revision: 201037 Kit: 201039

// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
// All rights reserved.
// This component and the accompanying materials are made available
// under the terms of "Eclipse Public License v1.0"
// which accompanies this distribution, and is available
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
//
// Initial Contributors:
// Nokia Corporation - initial contribution.
//
// Contributors:
//
// Description:
//

#include "cmsvdiskchangenotifier.h"

CMsvDiskChangeNotifier::CMsvDiskChangeNotifier(const TDriveUnit& aDrive, MMsvDiskChangeObserver& aObserver) 
:CActive(EPriorityHigh), iObserver(aObserver)
	{
	iDrive = TInt(aDrive);
	CActiveScheduler::Add(this);
	}

CMsvDiskChangeNotifier::~CMsvDiskChangeNotifier()
	{
	Cancel();
	iFs.Close();
	delete iDrivePath;
	iDrivePath = NULL;
	}

CMsvDiskChangeNotifier* CMsvDiskChangeNotifier::NewL(const TDriveUnit& aDrive, MMsvDiskChangeObserver& aObserver)
	{
	CMsvDiskChangeNotifier* self = new(ELeave) CMsvDiskChangeNotifier(aDrive, aObserver);
	CleanupStack::PushL(self);
	
	self->ConstructL();
	
	CleanupStack::Pop(self);
	return self;
	}

void CMsvDiskChangeNotifier::ConstructL()
	{
	User::LeaveIfError(iFs.Connect());
	iDrivePath = HBufC16::NewL(KMaxDriveName+2);
	iDrivePath->Des().Append(iDrive.Name());
	iDrivePath->Des().Append(_L("\\"));
	}
	
void CMsvDiskChangeNotifier::Start()
	{
	iFs.NotifyChange(ENotifyDisk, iStatus, *iDrivePath);
	SetActive();
	}

void CMsvDiskChangeNotifier::DoCancel()
	{
	iFs.NotifyChangeCancel();
	}

void CMsvDiskChangeNotifier::RunL()
	{
	TVolumeInfo volume;
	TInt error = iFs.Volume(volume, TInt(iDrive));
	if(KErrNone == error)
		{
		iObserver.DiskInserted(iDrive);
		}
	else if(KErrNotReady == error)
		{
		iObserver.DiskRemoved(iDrive);
		}
	else
		{
		iObserver.DiskChanged(iDrive);
		}
	
	if(!IsActive())
		{
		iFs.NotifyChange(ENotifyDisk, iStatus, *iDrivePath);
		SetActive();
		}
	}