// APSSES.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__APSSES_H__)
#define __APSSES_H__

#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif
#if !defined(__APSSERV_H__)
#include <apsserv.h>
#endif
#if !defined(__F32FILE_H__)
#include <f32file.h>
#endif
#if !defined(__APAID_H__)
#include <apaid.h>
#endif
#if !defined(__APSCLSV_H__)
#include "apsclsv.h"
#endif

// classes defined
class CApaAppListServSession;
//
// classes referenced
class CApaAppList;
class CApaAppData;
class CApaFileRecognizer;
class CApaScanningDataRecognizer;
class TDataType;
class CTypeStoreManager;
//


class CApaAppListServSession : public CSession
	{
public:
	// construct/destruct
	static CApaAppListServSession* NewL(RThread &aClient,CApaAppListServer* aServer);
	~CApaAppListServSession();
	//service request
	virtual void ServiceL(const RMessage &aMessage);
	void DispatchMessageL(const RMessage &aMessage);
private:
	CApaAppListServSession(RThread& aClient,CApaAppListServer* aServer, RFs& aFs);
	void ConstructL();
private:
	enum TAppListType {
		ENoList,
		EListAllApps,
		EListEmbeddedApps 
		};
	enum TAppListDocumentStart {
		EStart,
		EStartByDataType,
		EStartByUid,
		ECreateByUid
		};
private:
	void AppCount();
	void EmbedCount();
	void GetNextAppL();
	void InitList(TAppListType aType);
	void GetAppInfoL();
	void GetAppCapabilityL();
	void StartAppL();
	//
	// Data recognition stuff
	void RecognizeDataL();
	void RecognizeSpecificDataL();
	void DoRecognizeUnpackLC(HBufC*& aName, HBufC8*& aBuffer);
	//
	void AppForDataTypeL();
	void StartDocumentL(TAppListDocumentStart aStartType);
	TThreadId StartDocumentL(const TDesC& aFileName, TUid aUid, TApaCommand aCommand);
	TUid AppForDataTypeL(const TDataType& aDataType);
	void AppForDocumentL();
	TDataType RecognizeFileL(const TDesC& aFileName);
	void IsProgramL();
	//
	void IconForAppL();

	inline CApaAppList* AppList();
	inline CApaFileRecognizer* FileRecognizer();
	TBool FindAppInList(CApaAppData*& aApp,TApaAppEntry& aEntry,TUid aAppUid);
	TBool IsEmbeddable(CApaAppData* aApp);

	void GetConfidence();
	void SetConfidence();
	void GetBufSize();
	void SetBufSize();
	void GetDataTypesCountL();
	void GetDataTypesL();
	//
	void PanicClient(TApaClientPanic aPanic) const;
	void Write(const TAny* aPtr,const TDesC8& aDes,TInt anOffset=0);
private:
	CApaAppListServer* iServ;
	CApaAppData* iApp; // current app in list
	TInt iListCount; // the current value of the applist's update counter - so we can tell if it's changed
	TAppListType iListType;
	TInt iReserved1;
	TInt iReserved2;
	TTime iTypeStoreModified;
	RFs& iFs;
	TInt iMaxBufSize;
	CBufBase* iBuffer;
	};


//
// inlines
//

inline CApaAppList* CApaAppListServSession::AppList()
	{ return ((CApaAppListServer*)Server())->AppList(); }

inline CApaFileRecognizer* CApaAppListServSession::FileRecognizer()
	{ return ((CApaAppListServer*)Server())->FileRecognizer(); }

#endif