/*
*******************************************************************************
* Copyright (c) 1996-2000 Digi International Inc., All Rights Reserved        *
*                                                                             *
* This  software  contains  proprietary  and  confidential   information   of *
* Digi International  Inc.   By  accepting  transfer  of this copy, Recipient *
* agrees to retain this software in  confidence,  to  prevent  disclosure  to *
* others,  and  to make no  use of this software other than that for which it *
* was delivered.  This is an unpublished copyright work  Digi   International *
* Inc.    Except   as   permitted   by  federal  law,  17 USC 117, copying is *
* strictly prohibited.                                                        *
*                                                                             *
* Digi  International  Inc.  CONFIDENTIAL  -   (Digi    International    Inc. *
* Confidential  when   combined   with   the   aggregated  modules  for  this *
* product) OBJECT CODE ONLY SOURCE MATERIALS                                  *
*                                                                             *
* (C) COPYRIGHT Digi International Inc. 1996-97                               *
*                                                                             *
* All Rights Reserved                                                         *
*                                                                             *
* US   Government   Users   Restricted   Rights   -   Use,   duplication   or *
* disclosure  restricted by GSA ADP Schedule Contract with Digi International *
* Inc.                                                                        *
*                                                                             *
*******************************************************************************

// StatDoc.h : header file
//

*/

/////////////////////////////////////////////////////////////////////////////
// CStatDoc document

inline void AFXAPI DestructElements(CFR_PROTOCOL_ERRORS **pElements, int nCount)
{
	for (int i = 0; i < nCount; i++)
		delete pElements[i];
}

inline void AFXAPI DestructElements(CFR_PLL_STATS **pElements, int nCount)
{
	for (int i = 0; i < nCount; i++)
		delete pElements[i];
}

inline void AFXAPI DestructElements(CFR_INJ_MANG **pElements, int nCount)
{
	for (int i = 0; i < nCount; i++)
		delete pElements[i];
}

inline void AFXAPI DestructElements(CMODEM_STATUS **pElements, int nCount)
{
	for (int i = 0; i < nCount; i++)
		delete pElements[i];
}

inline void AFXAPI DestructElements(CMODEM_EXT_STATUS **pElements, int nCount)
{
	for (int i = 0; i < nCount; i++)
		delete pElements[i];
}

enum
{
	uavUpdateStats = 1,
	uavGetUpdateCircuits = 2,
	uavUpdateIdle = 0x1,
	uavNewComment = 0x2,
	uavStateChange = 0x4
};

class CStatDoc : public CDocument
{
	eDataSourceStatus m_LastStatus;

	CWAN m_WanStats;
	CWAN m_ClearWanStats;

	CWANLINESTATUS m_WanLineStatus;
	CWANLINESTATUS m_ClearWanLineStatus;

	DWORD m_ByteRate;
	_timeb m_LastTime;
	_timeb m_StartTime;
	double m_LastInterval;

	DWORD m_StartFPS[2];
	DWORD m_StartBPS[2];

	DWORD m_LastFPS[2];
	DWORD m_LastBPS[2];
	DWORD m_Overflow[2];

protected:
	CDataSource *m_pDataSource; // reference pointer to data source

// ************************************************
// protocol specific trace and stats pane used by the frame windows
// used to create them
	CRuntimeClass *m_RtC; // CRuntimeClass of pane
// ************************************************


	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

	const CSXB_USER_IOCTL *GetStatType(const type_info& Type, int index = -1) const
		{ return m_pDataSource->GetStatType(Type, index); };

public:
	CStatDoc();           // protected constructor used by dynamic creation
	DECLARE_DYNCREATE(CStatDoc)

	DWORD m_AverageFPS[2];
	DWORD m_AverageBPS[2];

	DWORD m_FPS[2];
	DWORD m_BPS[2];
	DWORD m_LU[2];

	const CWAN& GetWAN() const { return m_WanStats; };
	const CWANLINESTATUS& GetLineStatus() const {return m_WanLineStatus;}

// Attributes
public:
	CDataSource *GetDataSource()
		{ ASSERT(m_pDataSource != NULL); return m_pDataSource; };
	const CDataSource *GetDataSource() const
		{ ASSERT(m_pDataSource != NULL); return m_pDataSource; };

// Operations
	BOOL SetDataSource(CDataSource *ds)
		{ m_pDataSource = ds; return OnNewDocument(); };

	CRuntimeClass *GetStatPane() const
		{ return m_RtC; };

public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CStatDoc)
	public:
	virtual void Serialize(CArchive& ar);   // overridden for document i/o
	protected:
	virtual BOOL OnNewDocument();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CStatDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif
	virtual void OnIdle();

	// Generated message map functions
protected:
	//{{AFX_MSG(CStatDoc)
	afx_msg void OnEditClearstatistics();
	afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
	afx_msg void OnSelchangeDataSource();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
// CTraceDoc document

class CTraceDoc : public CDocument
{
protected:
	CTraceDoc();           // protected constructor used by dynamic creation
	DECLARE_DYNCREATE(CTraceDoc)

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTraceDoc)
	public:
	virtual void Serialize(CArchive& ar);   // overridden for document i/o
	virtual BOOL CanCloseFrame(CFrameWnd* pFrame);
	protected:
	virtual BOOL OnNewDocument();
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CTraceDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif
	virtual void OnIdle();

	// Generated message map functions
protected:
	//{{AFX_MSG(CTraceDoc)
	afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
	afx_msg void OnUpdateFileClose(CCmdUI* pCmdUI);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

class CFRStatDoc : public CStatDoc
{
	CFR_LINK_ERRORS m_LinkErrors;
	CFR_LINK_ERRORS m_ClearLinkErrors;

	CFR_LINK_STATS m_LinkStats;
	CFR_LINK_STATS m_ClearLinkStats;

	CFR_LMI_STATS m_LMIStats;
	CFR_LMI_STATS m_ClearLMIStats;

	CArray<CFR_PROTOCOL_ERRORS *, CFR_PROTOCOL_ERRORS *> m_ProtocolErrors;
	CArray<CFR_PROTOCOL_ERRORS *, CFR_PROTOCOL_ERRORS *> m_ClearProtocolErrors;

	CArray<CFR_PLL_STATS *, CFR_PLL_STATS *> m_PllStats;
	CArray<CFR_PLL_STATS *, CFR_PLL_STATS *> m_ClearPllStats;

	CArray<CFR_INJ_MANG *, CFR_INJ_MANG *> m_InjManager;
	CArray<CFR_INJ_MANG *, CFR_INJ_MANG *> m_ClearInjManager;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

	void UpdateSelChange(int);

public:
	CFRStatDoc();
	DECLARE_DYNCREATE(CFRStatDoc)

// Attributes
public:
	const CFR_LINK_ERRORS& GetLinkErrors() const { return m_LinkErrors; };
	const CFR_LINK_STATS& GetLinkStats() const { return m_LinkStats; };
	const CFR_LMI_STATS& GetLMIStats() const { return m_LMIStats; };
	const CFR_PROTOCOL_ERRORS& GetProtocolErrors(int index) const { return *m_ProtocolErrors[index]; };
	const CFR_PLL_STATS& GetPllStats(int index) const { return *m_PllStats[index]; };
	const CFR_INJ_MANG& GetInjManager(int index) const { return *m_InjManager[index]; };

// Operations
	void SelChange(int);

public:

// Implementation
public:
	virtual ~CFRStatDoc() {};

	virtual BOOL OnNewDocument();
};


class CHlcStatDoc : public CStatDoc
{
	CDS1_STATUS m_Ds1Status;
	CDS1_STATUS m_ClearDs1Status;

	CDS1_EXT_STATUS m_Ds1ExtStatus;
	CDS1_EXT_STATUS m_ClearDs1ExtStatus;

	CBRI_STATUS m_BriStatus;
	CBRI_STATUS m_ClearBriStatus;
	CDCHAN_EXT_STATUS m_DChanExtStatus;
	CBRI_CONFIG m_BriConfig;

	CArray<CMODEM_STATUS *, CMODEM_STATUS *> m_ModemStatus;
	CArray<CMODEM_STATUS *, CMODEM_STATUS *> m_ClearModemStatus;

	CArray<CMODEM_EXT_STATUS *, CMODEM_EXT_STATUS *> m_ModemExtStatus;
	CArray<CMODEM_EXT_STATUS *, CMODEM_EXT_STATUS *> m_ClearModemExtStatus;

	void UpdateSelChange(int);

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

public:
	CHlcStatDoc();
	DECLARE_DYNCREATE(CHlcStatDoc)

// Attributes
public:
	const CDS1_STATUS& GetDs1Status() const {return m_Ds1Status;}
	const CDS1_EXT_STATUS& GetDs1ExtStatus() const {return m_Ds1ExtStatus;}
	const CBRI_STATUS& GetBriStatus() const {return m_BriStatus;}
	const CMODEM_STATUS& GetModemStatus(int index) const { return *m_ModemStatus[index]; }
	const CMODEM_EXT_STATUS& GetModemExtStatus(int index) const { return *m_ModemExtStatus[index]; }
	const CDCHAN_EXT_STATUS& GetDChanExtStatus() const {return m_DChanExtStatus;}
	const CBRI_CONFIG& GetBriConfig() const {return m_BriConfig;}

// Operations
	void SelChange(int);

public:

// Implementation
public:
	virtual ~CHlcStatDoc() {};

	virtual BOOL OnNewDocument();
};


class CPriStatDoc : public CHlcStatDoc
{
public:
	CPriStatDoc();
	DECLARE_DYNCREATE(CPriStatDoc)

// Attributes
public:

public:

// Implementation
public:
	virtual ~CPriStatDoc() {};
};


class CBriStatDoc : public CHlcStatDoc
{

public:
	CBriStatDoc();
	DECLARE_DYNCREATE(CBriStatDoc)

// Attributes
public:

// Implementation
public:
	virtual ~CBriStatDoc() {};
};

class CModemStatDoc : public CHlcStatDoc
{

public:
	CModemStatDoc();
	DECLARE_DYNCREATE(CModemStatDoc)

// Attributes
public:

// Implementation
public:
	virtual ~CModemStatDoc() {};
};


class CSnaStatDoc : public CStatDoc
{
	CWANLINESTATUS m_WanLineStatus;
	CWANLINESTATUS m_ClearWanLineStatus;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

//	void UpdateSelChange(int);

public:
	CSnaStatDoc();
	DECLARE_DYNCREATE(CSnaStatDoc)

// Attributes
public:
	const CWANLINESTATUS& GetLineStatus() const {return m_WanLineStatus;}

// Operations
//	void SelChange(int);

public:

// Implementation
public:
	virtual ~CSnaStatDoc() {};

	virtual BOOL OnNewDocument();
};

class CX25StatDoc : public CStatDoc
{
	CLAPB m_ClearLapbStats;
	CLAPB m_LapbStats;

	CX25 m_X25Stats;
	CX25 m_ClearX25Stats;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

public:
	CX25StatDoc();
	DECLARE_DYNCREATE(CX25StatDoc)

// Attributes
public:

// Operations
public:
	const CLAPB& GetLAPB() const { return m_LapbStats; };
	const CX25& GetX25() const { return m_X25Stats; };

// Implementation
public:
	virtual ~CX25StatDoc() {};

	virtual BOOL OnNewDocument();
};

class CPPPStatDoc : public CStatDoc
{
	CWANLINESTATUS m_WanLineStatus;
	CWANLINESTATUS m_ClearWanLineStatus;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

public:
	CPPPStatDoc();
	DECLARE_DYNCREATE(CPPPStatDoc)

// Attributes
public:
	const CWANLINESTATUS& GetLineStatus() const {return m_WanLineStatus;}


public:

// Implementation
public:
	virtual ~CPPPStatDoc() {};

	virtual BOOL OnNewDocument();
};


class CPPPCsuStatDoc : public CStatDoc
{

public:
	CPPPCsuStatDoc();
	DECLARE_DYNCREATE(CPPPCsuStatDoc)

	CRfc1406 m_Rfc1406Stats;
	CRfc1406 m_ClearRfc1406Stats;

	CIfaceState m_IfaceState;
	CIfaceState m_ClearIfaceState;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

// Attributes
public:
	const CRfc1406& GetRfc1406() const {return m_Rfc1406Stats;};
	const CIfaceState& GetIfaceState() const {return m_IfaceState;};

// Implementation
public:
	virtual ~CPPPCsuStatDoc() {};
};


class CFRCsuStatDoc : public CStatDoc
{
	CFR_LINK_ERRORS m_LinkErrors;
	CFR_LINK_ERRORS m_ClearLinkErrors;

	CFR_LINK_STATS m_LinkStats;
	CFR_LINK_STATS m_ClearLinkStats;

	CFR_LMI_STATS m_LMIStats;
	CFR_LMI_STATS m_ClearLMIStats;

	CRfc1406 m_Rfc1406Stats;
	CRfc1406 m_ClearRfc1406Stats;

	CIfaceState m_IfaceState;
	CIfaceState m_ClearIfaceState;

	CArray<CFR_PROTOCOL_ERRORS *, CFR_PROTOCOL_ERRORS *> m_ProtocolErrors;
	CArray<CFR_PROTOCOL_ERRORS *, CFR_PROTOCOL_ERRORS *> m_ClearProtocolErrors;

	CArray<CFR_PLL_STATS *, CFR_PLL_STATS *> m_PllStats;
	CArray<CFR_PLL_STATS *, CFR_PLL_STATS *> m_ClearPllStats;

	CArray<CFR_INJ_MANG *, CFR_INJ_MANG *> m_InjManager;
	CArray<CFR_INJ_MANG *, CFR_INJ_MANG *> m_ClearInjManager;

	virtual void ClearProtocolStats();
	virtual void GetProtocolStats();

	void UpdateSelChange(int);

public:
	CFRCsuStatDoc();
	DECLARE_DYNCREATE(CFRCsuStatDoc)

// Attributes
public:
	const CRfc1406& GetRfc1406() const {return m_Rfc1406Stats;};
	const CIfaceState& GetIfaceState() const {return m_IfaceState;};
	const CFR_LINK_ERRORS& GetLinkErrors() const { return m_LinkErrors; };
	const CFR_LINK_STATS& GetLinkStats() const { return m_LinkStats; };
	const CFR_LMI_STATS& GetLMIStats() const { return m_LMIStats; };
	const CFR_PROTOCOL_ERRORS& GetProtocolErrors(int index) const { return *m_ProtocolErrors[index]; };
	const CFR_PLL_STATS& GetPllStats(int index) const { return *m_PllStats[index]; };
	const CFR_INJ_MANG& GetInjManager(int index) const { return *m_InjManager[index]; };

// Operations
	void SelChange(int);

public:

// Implementation
public:
	virtual ~CFRCsuStatDoc() {};

	virtual BOOL OnNewDocument();
};

