messagingfw/msgsrvnstore/server/src/CMsvAttachmentWaiter.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Fri, 19 Feb 2010 23:18:09 +0200
branchRCL_3
changeset 6 fe71b07a6401
parent 0 8e480a14352b
permissions -rw-r--r--
Revision: 201003 Kit: 201007

// 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;
	}