// AGSSESS.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//


#if !defined(__E32STD_H__)
#include <e32std.h>
#endif

#if !defined(__S32STD_H__)
#include <s32std.h>
#endif

#if !defined(__S32MEM_H__)
#include <s32mem.h>
#endif


#if !defined(__AGSMAIN_H__)
#include "agsmain.h"
#endif

#if !defined(__AGMXTAB_H__)
#include "agmxtab.h"
#endif

#if !defined(__AGNSERV_H__)
#include "agnserv.h"
#endif

#if !defined(__AGSTRANS_H__)
#include "agstrans.h"
#endif



#if !defined(__AGSSESS_H__)
#define __AGSSESS_H__


class CAgnSortEntryTable;


// CAgnServerSession

class CAgnServerSession : public CSession
	{
public:
	enum TNotifyType {ENone, EEntry, ETodoList};
public:
	CAgnServerSession(RThread &aClient, CAgnServer* aServer);
	~CAgnServerSession();
	static CAgnServerSession* NewL(RThread &aClient, CAgnServer* aServer);
	void ConstructL();
	virtual void ServiceL(const RMessage &aMessage);
	TBool DispatchMessageL(const RMessage &aMessage);
	void NotifyChange(TNotifyType aType);
	void NotifyChangeL(TNotifyType aType, TAgnEntryTransaction aTransaction);
protected:
	void PanicClient(TInt aPanic) const;	// Panic the client
private:
	HBufC* ReadClientDesL(TInt aDesNum);
	TAgnFilter* InternalizeAgnFilterL(RReadStream& aStream);
	void OpenAgendaL();
	void CloseAgendaL();
	void StreamIDL();
	void GetReadStreamL();
	void GetExclusiveAccessL();
	void LockFileL();
	void UnlockFileL();
	void FetchEntryL();
	void TransmitBufferL();
	void GetInstanceExtractorL();
	void GetDayListFromExtractorL();
	void GetDayDateTimeListFromExtractorL();
	void FetchLiteEntryL();
	void GetSymbolInstanceListL();
	void UpdateEntryL();
	void AddEntryL();
	void DeleteEntryL();
	void CommitL();
	void RollbackL();
	void LogL();
	void CheckNotifyL();
	void SetModelTextFormatL();
	void GetModelTextFormatL();
	void SaveTodoListsL();
	void FetchTodoListL();
	void FetchTodoListByUidL();
	void RefreshTodoListListL();
	void UpdateTodoListL();
	void AddTodoListL();
	void DeleteTodoListL();
	void ChangeTodoListOrderL();
	void GetPercentageLoadedL();
	void GetAddEntrySizesL();
	void NextAlarmL();
	void PreviousDayWithInstanceL();
	void NextDayWithInstanceL();
	void GetLastSynchronizedDateL();
	void SetLastSynchronizedDateL();
	void GetObserverControllerStreamIdL();
	void CreateEntryIteratorL();
	void EntryIteratorNextL();
	void EntryIteratorPositionL();
	void EntryIteratorStatsL();
	void CreateDateIteratorL();
	void DateIteratorPreviousL();
	void DateIteratorNextL();
	void DateIteratorAtStartL();
	void DateIteratorAtEndL();
	void DateIteratorCurrentKeyL();
	void DateIteratorCurrentElementL();
	void DateIteratorGotoL();
	void DateIteratorGotoLessOrEqualL();
	void ResetTransactionList();
	void FetchEntryByGUIDL();
	void FetchEntryByUIDL();
	void TransferReadStreamL();
	void TransferWriteStreamL();
	void CreateNewStreamL();
	void EntryCount();
	void IndexCount();
	void BuildIndexL();
	void TypeByUniqueId();
	void HasUniqueIdBeenDeleted();
	void UniqueIdLastChangedDate();
	void GetUniqueId();
	void GetTodoUniqueId();
	void CompactFile();
	void CompactionStatus();
	void DeleteEntryByUidL();
	void DeleteTodoListByUidL();
	void UpdateSyncIterL();
	void SetBufferedStoring();
	void BufferedStoring();
	void GetNumEntriesToTidyL();
	void SetDefaultDisplayTimes();
private:
	TBool IsEntryValidToTidy(const CAgnSortEntry* aSortEntry, TAgnDate aTidyStartDate, TAgnDate aTidyEndDate);
	void DeleteEntryL(CAgnEntry* aEntry);
	void DoTransferReadStreamL(TStreamId aId);

private:
	CAgnServer* iAgnServer;
	CAgnEntryModel* iModel;
	CAgnServFile* iAgnFile;
	CAgnTransactionList* iTransactionList;

	TBool					iHasLock;
	CBufFlat*				iBuffer;	// used to transmiting streams to client
	TAgnInstanceExtractor*	iExtractor; // local copy of instance extractor
	TAgnFilter*				iFilter;	// filter to use for extraction
	TAgnDate				iToday;
	TTime					iLogTime;
	TNotifyType				iNotifyRequired;
	RMessage				iNotifyMessage;	// Complete this when an update arrives
	TBool					iNotifyPending;

	TAgnEntryIter*			iEntryIter;	
	TAgnEntryDateIterator*	iDateIter;
	TAgnEntryInfoFilter		iTidyInfoFilter;

	// Keep a note of which indexes are required
	TBool					iModelIndex;
	TBool					iUidIndex;

	// Temporary sizes used for transferring new entries
	TUint iEntryStreamSize;
	TUint iTextStreamSize;
	};



#endif

