/*
*******************************************************************************
* Copyright (c) 1996-97 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.                                                                        *
*                                                                             *
*******************************************************************************

// Diagnostic.h : main header file for the DIAGNOSTIC application
//

Revision History:

   $History: Diagnostic.h $
 * 
 * *****************  Version 25  *****************
 * User: Rodgerb      Date: 2/14/97    Time: 9:52a
 * Updated in $/Components/Windows/NT/Sync/rev2diag
 * 
 * *****************  Version 24  *****************
 * User: Rodgerb      Date: 1/27/97    Time: 1:18p
 * Updated in $/Components/Windows/NT/Sync/rev2diag
 * 1) documentation
 * 2) added some new params to Physical layer stats
*/

#ifndef __AFXWIN_H__
	#error include 'stdafx.h' before including this file for PCH
#endif

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// CDiagApp:
// See Diagnostic.cpp for the implementation of this class
//

// m_RefreshInternal will be -1 when update in manual
const DWORD c_ManualRefresh = (DWORD)-1;
const DWORD c_ConstantRefresh = 0;

#include "dxbreg.h"		// New Dxb RegKeys
#include "RegNames.h" // WAN Links registry stuff
#include "RegINI.h" 	// SpyGlass reistry stuff
#include "config.h" 	// contains most all protocol non GUI stuff
											// it's used so much everywhere that I thought it best to
											// include it here

class CTraceMiniFrame;
class CDataSourceControl;

// override of CMultiDocTemplate done only to patch CreateNewDocument
// new documents created from this template are given data to start with
class CTraceMultiDocTemplate : public CMultiDocTemplate
{
	const CDataSource *m_pNewDocDataSource;
	CTraceMiniFrame *m_Properties;

	public :
		CTraceMultiDocTemplate(	UINT nIDResource,
														CRuntimeClass* pDocClass,
														CRuntimeClass* pFrameClass,
														CRuntimeClass* pViewClass);
  
		virtual CDocument *CreateNewDocument();
		void SetNewDocDataSource(CDataSourceControl *);
};

class CDataSourceControl;
const UINT c_RefreshMessage = WM_USER + 2345;

class CDiagApp : public CWinApp
{
	HANDLE m_hMutexOneInstance; // to prevent multiple instances of SpyGlass

	CArray<CAdapter *, CAdapter *> m_Adapters;
	
	// these doctemplate are not added to CWinApp's template list
	// new windows using these templates are created manually
	CMultiDocTemplate *m_pStatDocTemplate; // DocTemplate for all Stats windows
	CMultiDocTemplate *m_pDataSourceDocTemplate; // DocTemplate for all Summary windows
	
	CWinThread *m_RefreshThread;
	static UINT __cdecl RefreshThread(LPVOID);
	CEvent m_RefreshEvent;
	DWORD m_RefreshInterval;	// time in seconds of stat updates
														// update is done in OnIdle()
														// all windows displaying stats are updated, including
														// Summary windows and the active trace pane
														// since updates are in OnIdle the update interval
														// really mean that updates will occur no faster than
														// the value of m_RefreshInterval but could take much
														// longer depending on the frequency of OnIdle calls

	// routines documented in source file

	int GetSelectedItem() const;
	CDataSourceControl *GetControl();
	const CDataSourceControl *GetControl() const;
	CDataSource *GetDataSource();
	const CDataSource *GetDataSource() const;

// Attributes
	BOOL IsTracing() const;
	BOOL IsPaused() const;
	void ToggleTrace();
	void StopTrace();
	void UpdateActivePage(CDataSourceControl *);

	void MakeStatFrame();
	void NewDocDataSource(CDataSourceControl *);

	void UpdateAllDocuments(LPARAM lHint, CObject * = NULL);
public:
	CDiagApp();

// Attributes
	int GetNumAdapters() const { return (int)(m_Adapters.GetSize()); };
	CAdapter *GetAdapter(int index) { return m_Adapters[index]; };
	const CAdapter *operator[](int index) const { return m_Adapters[index]; };

// Operations
	BOOL LoadConfig();
	void OnRefreshMessage();
	void KillRefreshThread();

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDiagApp)
	public:
	virtual BOOL InitInstance();
	virtual int ExitInstance();
	virtual BOOL OnIdle(LONG lCount);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
		// Server object for document creation
	virtual ~CDiagApp();

	//{{AFX_MSG(CDiagApp)
	afx_msg void OnAppAbout();
	afx_msg void OnWindowCloseallstatisticswindows();
	afx_msg void OnUpdateWindowCloseallstatisticswindows(CCmdUI* pCmdUI);
	afx_msg void OnSpyglassRefreshUpdatenow();
	afx_msg void OnUpdateSpyglassRefreshUpdatenow(CCmdUI* pCmdUI);
	afx_msg void OnSpyglassRefresh(UINT);
	afx_msg void OnUpdateSpyglassRefresh(CCmdUI* pCmdUI);
	afx_msg void OnConfigChange(UINT, LONG);
	afx_msg void OnSelchangeRefresh();
	afx_msg void OnCaptureStarttrace();
	afx_msg void OnUpdateCaptureStarttrace(CCmdUI* pCmdUI);
	afx_msg void OnCaptureStoptrace();
	afx_msg void OnUpdateCaptureStoptrace(CCmdUI* pCmdUI);
	afx_msg void OnCapturePausetrace();
	afx_msg void OnUpdateCapturePausetrace(CCmdUI* pCmdUI);
	afx_msg void OnCaptureStopandview();
	afx_msg void OnUpdateCaptureStopandview(CCmdUI* pCmdUI);
	afx_msg void OnCaptureDisplaycatureddata();
	afx_msg void OnUpdateCaptureDisplaycatureddata(CCmdUI* pCmdUI);
	afx_msg void OnEditClearTracestatistics();
	afx_msg void OnUpdateEditClearTracestatistics(CCmdUI* pCmdUI);
	afx_msg void OnCaptureBuffersettings();
	afx_msg void OnCaptureSummaryinfo();
	afx_msg void OnUpdateCaptureSummaryinfo(CCmdUI* pCmdUI);
	afx_msg void OnCaptureDisplaystatistics();
	afx_msg void OnUpdateCaptureDisplaystatistics(CCmdUI* pCmdUI);
	afx_msg void OnEditClearstatistics();
	afx_msg void OnUpdateEditClearstatistics(CCmdUI* pCmdUI);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
private:
	BOOL LoadConfigNT4();
	BOOL LoadConfigNT5();
};


/////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
// CWindowPlacement 1996 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.

////////////////
// CWindowPlacement reads and writes WINDOWPLACEMENT 
// from/to application profile and CArchive.
//
class CWindowPlacement : public tagWINDOWPLACEMENT
{

public:
	CWindowPlacement();
	~CWindowPlacement();

	const CWindowPlacement& operator=(const tagWINDOWPLACEMENT& wp)
	{ memcpy(&length, &wp, length); return *this; };

// Read/write to app profile
	void GetProfileWP(LPCSTR lpKeyName);
	void WriteProfileWP(LPCSTR lpKeyName);

// Save/restore window pos (from app profile)
	void Save(LPCSTR lpKeyName, CWnd* pWnd);
	BOOL Restore(LPCSTR lpKeyName, CWnd* pWnd);

// Save/restore from archive
	friend CArchive& operator<<(CArchive& ar, const CWindowPlacement& wp);
	friend CArchive& operator>>(CArchive& ar, CWindowPlacement& wp);
};
