messagingfw/msgsrvnstore/server/src/CMsvAttachmentWaiter.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 02 Feb 2010 10:12:21 +0200
changeset 3 28ae839b4c09
parent 0 8e480a14352b
permissions -rw-r--r--
Revision: 201003 Kit: 201005

// Copyright (c) 2004-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 "CMsvAttachmentWaiter.h"
#include <mmsvattachmentmanager.h>
#include "MSVSTORE.H"

CMsvAttachmentWaiter* CMsvAttachmentWaiter::NewL()
	{
	CMsvAttachmentWaiter* self = new(ELeave) CMsvAttachmentWaiter();
	return self;
	}
	
CMsvAttachmentWaiter::CMsvAttachmentWaiter()
	: CActive(EPriorityStandard)
	{
	CActiveScheduler::Add(this);
	}

CMsvAttachmentWaiter::~CMsvAttachmentWaiter()
	{
	Cancel();
	delete iStore;
	}	

void CMsvAttachmentWaiter::StartWaitingL(TRequestStatus& aStatus, CMsvStore* aStore, MMsvAttachmentManager* aAttachmentManager)
	{
	if( IsActive() )
		{
		aAttachmentManager->CancelRequest();
		User::Leave(KErrInUse);
		}
	
	aStatus = KRequestPending;
	iReportStatus = &aStatus;
	iStore = aStore;
	iAttachmentManager = aAttachmentManager;
	SetActive();
	}

void CMsvAttachmentWaiter::Reset()
	{
	iReportStatus = NULL;
	iAttachmentManager = NULL;
	delete iStore;
	iStore = NULL;
	}

void CMsvAttachmentWaiter::RunL()
	{
	User::LeaveIfError(iStatus.Int());
	iStore->CommitL();
	User::RequestComplete(iReportStatus, KErrNone);
	Reset();
	}
	
void CMsvAttachmentWaiter::DoCancel()
	{
	iAttachmentManager->CancelRequest();
	User::RequestComplete(iReportStatus, KErrCancel);
	Reset();
	}

TInt CMsvAttachmentWaiter::RunError(TInt aError)
	{
	User::RequestComplete(iReportStatus, aError);
	Reset();
	return KErrNone;
	}