// WEBPIUTL.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

// Definition of PlugIn support classes :
//  CWebPlugInData, CWebPlugInRegistryData, CWebPlugInFactoryData
//
// This header must be included by the headers for the abstract mixin
// classes which define the registry interface.
//
//-----------------------------------------------------------------------------
// $Modtime:   24 Mar 1999 13:48:00  $  $Revision:   1.22  $  $Author:   davidh  $
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

#if !defined(__WEBPIUTL_H__)
#define __WEBPIUTL_H__

//System includes
#if !defined(__E32BASE_H__)
#include <e32base.h>
#endif
#if !defined(__E32STD_H__)
#include <e32std.h>
#endif
#if !defined(__S32STRM_H__)
#include <s32strm.h>
#endif
#if !defined(__APMSTD_H__)
#include <apmstd.h>
#endif

//Local includes
#if !defined(__WEBSVMOD_H__)
#include "websvmod.h"	//For logging requirements
#endif
#if !defined(__WEBPIDLL_H__)
#include "webpidll.h"		//For interfaces to PlugIns
#endif

//Forward declarations
class CWebPlugInData;
class CWebPlugInRegistryData;
class CWebPlugInFactoryData;
class CWebPlugInDLLData;
class CWebPlugInDLLList;
class TWebDateTime;


//-----------------------------------------------------------------------------
/* Convenient structs for passing function params into the Data classes
    and for storing blocks of data in arrays  */

// TPlugInParams - Used to pass Plug In data from the PI itself
struct TPlugInParams
	{
	const TVersion* iVersion;
	TWebPlugInType iType;
	TDesC* iPIName;
	TDesC* iPIVendor;
	TDesC* iPIMarkupLang;
	const TVersion* iPIMarkupLangVersion;
	TDesC* iPITagName;
	TDesC* iPIURL;
	TDesC* iPICopyright;
	TWebPlugInLoading iPILoading;
	const TDataType* iPIMimeType;
	TDesC* iPIResourceFileName;
	TDesC* iPIIniFileName;
	TBool iHasSettingsDialog;
	};

// TPlugInRegParams - Used to pass Plug In data associated with the registry
struct TPlugInRegParams
	{
	TBool iEnabled;
	CWebPlugInDLLData* iPIDLLData;
	TInt iPIDLLIndex;
	};

// TPlugInFactoryParams - Used to pass Plug In data associated with the factory
struct TPlugInFactoryParams
	{
	TInt iRefCount;
	};

// TPlugInAllParams - Used to pass all the Plug In data associated with a Plug In
struct TPlugInAllParams
	{
	CWebPlugInData* iData;
	CWebPlugInRegistryData* iRegData;
	CWebPlugInFactoryData* iFactData;
	};

// TPlugInDLLParams - Used to pass Plug In data associated with a DLL
struct TPlugInDLLParams
	{
	const TDesC* iPIDLLPath;
	const TWebDateTime* iPIDLLTimestamp;
	TInt iPIUIDType;
	TBool iPIIsCore;
	TBool iChecked;
	};

// TPlugInInstanceParams - Used to pass Plug In data associated with a pointer
// to a plug in
struct TPlugInInstanceParams
	{
	MWebPlugIn* iEngPtr;			//ptr to an engine PI
	MWebUIPlugIn* iUIPtr;	//ptr to a UI PI
	TPlugInAllParams iData;
	};

//-----------------------------------------------------------------------------

//A little class to allow us to externalize & internalize the TDateTime class
class TWebDateTime: public TDateTime
	{
public:
	TWebDateTime(TInt aYear,TMonth aMonth,TInt aDay,TInt aHour,TInt aMinute, TInt aSecond,TInt aMicroSecond);
	TWebDateTime(TDateTime aDateTime);
	TWebDateTime();
	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);
	};

 //-----------------------------------------------------------------------------

//A little class to allow us to externalize & internalize the TVersion class
class TWebVersion: public TVersion
	{
public:
	TWebVersion(TInt aMajor,TInt aMinor,TInt aBuild);
	TWebVersion(TVersion aVersion);
	TWebVersion();
	TVersion Version();
	void ExternalizeL(RWriteStream& aStream) const;
	void InternalizeL(RReadStream& aStream);
	};

 //-----------------------------------------------------------------------------

//TWebPlugInParser - class to parse a delimited string into components
class TWebPlugInParser: public CBase
	{
	public:
		TWebPlugInParser();
		TWebPlugInParser(TWebPlugInParser& aParser);
		TWebPlugInParser(const TDesC& aString, const TChar aDelimiter);
		TWebPlugInParser& operator=(const TWebPlugInParser& aParser);
		TBool Contains (const TDesC& aTarget);
		TPtrC String() const;
		TChar Delimiter() const;

	private:
		TPtrC iString;
		TChar iDelimiter;
	};

class TWebPlugInParser8: public CBase
	{
	public:
		TWebPlugInParser8();
		TWebPlugInParser8(TWebPlugInParser8& aParser);
		TWebPlugInParser8(const TDesC8& aString, const TChar aDelimiter);
		TWebPlugInParser8& operator=(const TWebPlugInParser8& aParser);
		TBool Contains (const TDesC8& aTarget);
		TPtrC8 String() const;
		TChar Delimiter() const;

	private:
		TPtrC8 iString;
		TChar iDelimiter;
	};

//-----------------------------------------------------------------------------
/* Class CPlugInDllCleanupItem
A utility class for allowing a DLL to be unloaded in case of a leave by putting
a CPlugInDllCleanupItem onto the cleanup stack  */
class CPlugInDllCleanupItem: public CBase
	{
	public:
		CPlugInDllCleanupItem();
		~CPlugInDllCleanupItem();
		void SetParams(RLibrary* aLibrary, CWebPlugInDLLData* aDllData = NULL);
		void AllOK();
	private:
		CWebPlugInDLLData* iDllData;
		RLibrary* iLibrary;
		TBool iAllOK;
	};

//-----------------------------------------------------------------------------

/* Class CWebPlugInData
A utility class for holding all the data which the registry needs
to know about a particular plugin.  Is managed in the Registry
by a CWebPlugInList object.  */
class CWebPlugInData: public CBase
	{

public:

	static CWebPlugInData* NewL();
	static CWebPlugInData* NewL(const TPlugInParams aParams);
	static CWebPlugInData* NewL(CWebPlugInData* aPlugInData);  //a copy 'constructor'
	void InternalizeL(RReadStream& aStream);
    void ExternalizeL(RWriteStream& aStream) const;
	void Reset();
	~CWebPlugInData();
	
	//Getters
	IMPORT_C const TVersion* PIVersion() const;
	IMPORT_C TWebPlugInType Type() const;
	IMPORT_C TPtrC PIName() const;
	IMPORT_C TPtrC PIVendor() const;
	IMPORT_C TPtrC PIURL() const;
	IMPORT_C TPtrC PICopyright() const;
	IMPORT_C TPtrC PIMarkupLang() const;
	IMPORT_C const TVersion* PIMarkupLangVersion() const;
	IMPORT_C TPtrC PITagName() const;
	IMPORT_C TWebPlugInLoading PILoading() const;
	IMPORT_C const TDataType* PIMimeType() const;
	IMPORT_C TPtrC PIResourceFileName() const;
	IMPORT_C TPtrC PIIniFileName() const;
	IMPORT_C TBool PIHasSettingsDialog() const;


	//Setters
	TBool SetAllParamsFromDllL(MWebPlugInRegistrationAPI* aPlugInDll);
	TBool SetPIVersion(const TVersion& aValue) ;
	TBool SetType(const TWebPlugInType aValue) ;
	TBool SetPINameL(const TDesC& aValue) ;
	TBool SetPIVendorL(const TDesC& aValue) ;
	TBool SetPIMarkupLangL(const TDesC& aValue) ;
	TBool SetPIMarkupLangVersion(const TVersion& aValue) ;
	TBool SetPITagNameL(const TDesC& aValue) ;
	TBool SetPIURLL(const TDesC& aValue) ;
	TBool SetPICopyrightL(const TDesC& aValue) ;
	TBool SetPILoading(const TWebPlugInLoading aValue) ;
	TBool SetPIMimeType (const TDataType& aValue);
	TBool SetPIResourceFileNameL(const TDesC& aValue);
	TBool SetPIIniFileNameL(const TDesC& aValue);
	TBool SetPIHasSettingsDialog(const TBool aValue);


private:
	TVersion iPIVersion;
	TWebPlugInType iType;
	HBufC* iPIName;
	HBufC* iPIVendor;
	HBufC* iPIURL;
	HBufC* iPICopyright;
	HBufC* iPIMarkupLang;
	TVersion iPIMarkupLangVersion;
	HBufC* iPITagName;
	TWebPlugInLoading iLoading;
	TDataType iPIMimeType;
	HBufC* iPIResourceFileName;
	HBufC* iPIIniFileName;
	TBool iPIHasSettingsDialog;

	CWebPlugInData();
	void ConstructL();
	void ConstructL(const TPlugInParams aParams);

	};

//-----------------------------------------------------------------------------

/* Class CWebPlugInRegistryData
A class which stores data about a PlugIn which only concerns the
registry.   A registered PI will have a CWebPlugInData and a
CWebPlugInRegistryData object 
associated with it.  The CWebPlugInRegistryData is the data
which is persisted between registry sessions.*/
class CWebPlugInRegistryData: public CBase
	{
public:
	static CWebPlugInRegistryData* NewL(CWebServicesModel* aWebServices);
	static CWebPlugInRegistryData* NewL(CWebServicesModel* aWebServices, TPlugInRegParams aParams);
	static CWebPlugInRegistryData* NewL(CWebPlugInRegistryData* aPlugInRegistryData);  //a copy 'constructor'
	void InternalizeL(RReadStream& aStream, CWebPlugInDLLList* aDllList);
    void ExternalizeL(RWriteStream& aStream, CWebPlugInDLLList* aDllList) const;

	~CWebPlugInRegistryData();
	
	//Getters
	IMPORT_C CWebServicesModel* Services() const;
	IMPORT_C TBool Enabled() const;
	IMPORT_C CWebPlugInDLLData* PIDLLData() const;
	IMPORT_C TInt PIDLLIndex() const;
	
	//Setters
	TBool SetEnabled(TBool aValue) ;
	TBool SetPIDLLData(CWebPlugInDLLData* aValue);
	TBool SetPIDLLIndex(const TInt aValue);
	
private:
	CWebServicesModel* iWebServices;
	CWebPlugInDLLData* iPIDllData;		//Reference to DLL data
	TBool iEnabled;		//Is PI enabled 
	TInt iPIDLLIndex;		//Index of PI in the DLL
	

	CWebPlugInRegistryData(CWebServicesModel* aWebServices);
	void ConstructL();
	void ConstructL(TPlugInRegParams aParams);

	__DECLARE_LOG;	
	};

//-----------------------------------------------------------------------------

/* Class CWebPlugInFactoryData
A class which stores data about loaded Plug Ins */
class CWebPlugInFactoryData: public CBase
	{
public:
	static CWebPlugInFactoryData* NewL(CWebServicesModel* aWebServices);
	static CWebPlugInFactoryData* NewL(CWebServicesModel* aWebServices, TPlugInFactoryParams aParams);

	~CWebPlugInFactoryData();
	
	//Getters
	IMPORT_C CWebServicesModel* Services() const;
	IMPORT_C TInt PIRefCount() const;

	//Setters
	TBool SetPIRefCount(const TInt aValue) ;

	//Utils
	IMPORT_C TBool FindPtr(TInt& aIndex, TAny* aPtrTarget) const;
	IMPORT_C void AddPtrL(TPlugInInstanceParams aInstance);
	IMPORT_C void RemovePtr (TAny* aPtr);
	IMPORT_C void RemovePtrByIndex (TInt aIndex);
	IMPORT_C MWebPlugIn* PIReferenceEngPtr(TInt aIndex) const;
	IMPORT_C MWebUIPlugIn* PIReferenceUIPtr(TInt aIndex) const;
	IMPORT_C TPlugInAllParams PIReferenceData(TInt aIndex) const;
	TInt IncrementRefCount();
	TInt DecrementRefCount();

private:
	CWebServicesModel* iWebServices;
	TBool iRefCount;			//Number of references to this PlugIn
	CArrayFixFlat<TPlugInInstanceParams>* iPIInstancePtrs;		//List of all the pointers to PIs of this type

private:
	CWebPlugInFactoryData(CWebServicesModel* aWebServices);
	void ConstructL();
	void ConstructL(TPlugInFactoryParams aParams);

	__DECLARE_LOG;	
	};

//-----------------------------------------------------------------------------

/* Class CWebPlugInDLLData
A class which stores data about the DLLs which store Plug Ins */
class CWebPlugInDLLData: public CBase
	{
public:
	static CWebPlugInDLLData* NewL(CWebServicesModel* aWebServices);
	static CWebPlugInDLLData* NewL(CWebServicesModel* aWebServices, TPlugInDLLParams aParams);
	void InternalizeL(RReadStream& aStream);
    void ExternalizeL(RWriteStream& aStream) const;

	~CWebPlugInDLLData();
	
	//Getters
	IMPORT_C CWebServicesModel* Services() const;
	IMPORT_C TPtrC PIDLLPath() const;
	IMPORT_C const TWebDateTime* PIDLLTimestamp() const;
	IMPORT_C TBool IsLoaded() const;
	IMPORT_C RLibrary Library() const;
	IMPORT_C TInt PIUIDType() const;
	IMPORT_C TBool PIIsCore() const;
	IMPORT_C TBool Checked() const;

	//Setters
	TBool SetPIDLLPathL(const TDesC& aValue) ;
	TBool SetPIDLLTimestamp(const TWebDateTime& aValue);
	TBool SetIsLoaded(const TBool aValue);
	TBool SetLibrary(const RLibrary aValue);
	TBool SetPIUIDType(const TInt aValue) ;
	TBool SetPIIsCore(const TBool aValue) ;
	TBool SetChecked(const TBool aValue) ;

	//Utilities
	IMPORT_C TBool FindPtr(TInt& aIndex, TAny* aPtrTarget) const;
	IMPORT_C void AddPtrL(TPlugInInstanceParams aInstance);
	IMPORT_C void RemovePtr (TAny* aPtr);
	IMPORT_C void RemovePtrByIndex (TInt aIndex);
	IMPORT_C MWebPlugIn* PIReferenceEngPtr(TInt aIndex) const;
	IMPORT_C MWebUIPlugIn* PIReferenceUIPtr(TInt aIndex) const;
	IMPORT_C TPlugInAllParams PIReferenceData(TInt aIndex) const;
	IMPORT_C TInt NumRefs() const;
	
private:
	CWebServicesModel* iWebServices;
	//persisted data
	HBufC* iPIDLLPath;		//Path to DLL
	TWebDateTime iPIDLLTimestamp;		//Timestamp of DLL
	//non-persisted data
	CArrayFixFlat<TPlugInInstanceParams>* iPIInstancePtrs;		//List of all the pointers to PIs in this DLL
	TBool iIsLoaded;			//Is this DLL currently loaded
	TBool iChecked;			//Has this DLL been checked in the current registration process?
	RLibrary iLibrary;			//The library relating to this DLL
	TInt iPIUIDType;		//The (second) UID of this DLL - i.e. the UID which defines the type of the PI
	TBool iPIIsCore;		//Does this DLL hold core PIs?

private:
	CWebPlugInDLLData(CWebServicesModel* aWebServices);
	void ConstructL();
	void ConstructL(TPlugInDLLParams aParams);

	__DECLARE_LOG;	
	};


#endif // __WEBPIUTL_H__
