// OPPRG.H
//
// Copyright (C) Symbian Ltd 1998
//

// MODULE - Messaging progress watching classes

#if !defined(__OPPRG_H__)
#define __OPPRG_H__

#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif

#if !defined(__MSVSTD_H__)
#include <MSVSTD.H>
#endif

// Forward declarations
class CMsvOperation;
//

//////////////////////////////////////////////////////////
// CMsvRemoteOperationProgress:							//
// Remote operation progress observer					//
//////////////////////////////////////////////////////////
// Simple timer which signals back to observer every x	//
// microseconds (x defined in NewL()) to update the		//
// progress												//
//////////////////////////////////////////////////////////

const TInt KRemoteOpProgressDefaultPeriod=250000; // every 1/4 seconds

class MMsvRemoteOperationProgressObserver
	{
public:
	virtual void UpdateRemoteOpProgressL()=0;
	};

class CMsvRemoteOperationProgress : public CTimer
	{
public:
	IMPORT_C static CMsvRemoteOperationProgress* NewL(MMsvRemoteOperationProgressObserver& aObserver, TInt aPeriod=KRemoteOpProgressDefaultPeriod);
private:
	CMsvRemoteOperationProgress(MMsvRemoteOperationProgressObserver& aObserver, TInt aPeriod);
	void ConstructL();
	void IssueRequest();
	void RunL();
private:
	MMsvRemoteOperationProgressObserver&	iObserver;
	TInt									iPeriod;
	};



///////////////////////////////////////////////////////////////
// CMsvOperationWatcher:									 //
// Remote operation watcher									 //
///////////////////////////////////////////////////////////////
// Simple active object which signals the observer			 //
// (MMsvOperationObserver) when an operation has been		 //
// completed.												 //
// In order for this to function correctly, the iStatus		 //
// (TRequestStatus) of the CMsvOperationWatcher must be		 //
// passed into the function which returns the operation		 //
// (so that the operation watcher RunL() is only called		 //
// when the operation completes.							 //
//															 //
// So for editing:											 //
//															 //
// 	CMapOpWatcher* opWatch=new(ELeave) CMapOpWatcher(*this); //
//	CleanupStack::PushL(opWatch);							 //
//	CMsvOperation* msvOp=mtmUi->EditL(opWatch->iStatus);	 //
//	...etc.													 //
//															 //
// Where this is a concrete MMsvOperationObserver, and mtmui //
// is a concrete CBaseMtmUi.								 //
///////////////////////////////////////////////////////////////

class MMsvOperationObserver
	{
public:
	virtual void OperationCompleted(CMsvOperation* aOperation, TInt aCompletionCode) = 0;
	};

class CMsvOperationWatcher : public CActive
	{
public:
	IMPORT_C CMsvOperationWatcher(MMsvOperationObserver& aObserver);
	IMPORT_C ~CMsvOperationWatcher();
	IMPORT_C void AddOperationL(CMsvOperation* anOperation);
	IMPORT_C TInt Count() const;
	IMPORT_C CMsvOperation* At(TInt anIndex) const;
	IMPORT_C CMsvOperation* Operation(TMsvOp aOperationId) const;
protected:	
	void ConstructL();
	TInt FindNextCompletedOperation() const;
	// From CActive
	virtual void DoCancel();
	virtual void RunL();
protected:
	CArrayPtrFlat<CMsvOperation>	iOperations;
	MMsvOperationObserver&			iObserver;
	};

#endif // __OPPRG_H__