/*++
*******************************************************************************
* Copyright (c) 1999-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 copyrighted work of Digi International   *
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly   *
* prohibited.                                                                 *
*                                                                             *
* Restricted Rights Legend                                                    *
*                                                                             *
* Use, duplication, or disclosure by the Government is subject to             *
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in         *
* Technical Data and Computer Software clause at DFARS 252.227-7031 or        *
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -          *
* Restricted Rights at 48 CFR 52.227-19, as applicable.                       *
*                                                                             *
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343          *
*                                                                             *
*******************************************************************************

Module Name:

	DataSource.h

Abstract:

	// DataSource.h : header file

--*/

// CTracePage class's OnUpdate() responds to these messages
enum
{
	uavTraceFasterPeriod =			0x01, // update data displayed in page
	uavClearStatistics =				0x02 // user has cleared trace stats
};

// CDataSource states, each one corresponds to a item state displayed
// in CDataSourceView. These states are returned by CDataSourceControl
enum eDataSourceImage
{
	dsiNone, // no icon, CDataSource does not display any data
	dsiPlay, // a trace is currently running on this CDataSource
	dsiPause, // CDataSource's trace is suspended
	dsiStop, // CDataSource is not running a trace but is ready to do so
	dsiDisplay //	same as dsiStop but there is trace data ready to display from a
};

// columns in CDataSourceView
enum eDataSourceViewColumns
{
	dsvcName = 0, // daat source name, never changes
	dsvcProtocol, // FR, X.25, etc..., never changes, yet ...
	dsvcStatus, // is the line running or dead?
	dsvcAlarms, // alarms on a CSU style line?
	dsvcErrors, // error state or number of errors
	dsvcTxFrames, // number of frames tramsitted
	dsvcRxFrames, // number of frame received
	dsvcNumColumns
};

class CDataSourceControl
{
	// the datasource this class handles
	CDataSource *m_pDataSource;

	// m_pDataSource's trace stats is displayed in this CMiniFrame
	CTraceMiniFrame *m_pMiniFrame;

public :
	CDataSourceControl(CDataSource *ds)
		{ m_pDataSource = ds; m_pMiniFrame = NULL; };

	// Attributes to access data

// get m_pMiniFrame
	const CTraceMiniFrame *const GetMiniFrame() const { return m_pMiniFrame; };
	operator CTraceMiniFrame *() { return this == NULL ? NULL : m_pMiniFrame; };

// get m_pDataSource
	const CDataSource *GetDataSource() const { return m_pDataSource; };
	CDataSource *GetDataSource() { return m_pDataSource; };
	CDataSource *operator->() { return GetDataSource(); };

// get the CTraceSheet in m_pMiniFrame
	const CTraceSheet *GetTraceSheet() const;
	CTraceSheet *GetTraceSheet();

// get current state of m_pDataSource
	eDataSourceImage GetState() const;

	// Operations

// after a trace is started on m_pDataSource a CTraceMiniFrame is created
// to display the trace data
	BOOL CreateMiniFrame();

// destroys CTraceMiniFrame
	void KillTraceUI();

// after the user stops a trace the CTraceMiniFrame style & title are changed
	void OnStopTrace();

// closes the CTraceMiniFrame when the user displayes the trace data
// the CTraceMiniFrame object is not destroy after a trace is displayed
// references to the CTraceMiniFrame object is moved to the CDiagDoc object
	void OnNewDocument();
};

// just a basic dialog box
class CBufferSettings : public CDialog
{
// Construction
public:
	CBufferSettings(CWnd* pParent = NULL);   // standard constructor

// Dialog Data
	//{{AFX_DATA(CBufferSettings)
	enum { IDD = IDD_BufferSettings };
	CString	m_BufferSize;
	CString	m_FrameSize;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CBufferSettings)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CBufferSettings)
		// NOTE: the ClassWizard will add member functions here
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
// CDataSourceView view

class CTraceSheet;
class CTraceMiniFrame;

class CDataSourceView : public CListViewEx
{
	// is this view active, WM_ACTIVE
	BOOL m_IsActive;

	// images used to display item state
	CImageList m_iList;

// Attributes
	// return index of selected item in list control
	int GetSelectedItem() const;

// Operations
	// set selected item in list control
	void SetSelectedItem(int);

	// draw's a item in the list control
	void DrawItem(CDC *, int, BOOL);

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

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDataSourceView)
	public:
	virtual void OnInitialUpdate();
	protected:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
	virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~CDataSourceView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

	// Generated message map functions
protected:
	//{{AFX_MSG(CDataSourceView)
	afx_msg void OnItemchanged(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnDblclk(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSelchangeDataSource();
	afx_msg void OnGetdispinfo(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnKeydown(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnUpdateDataSourceBox(CCmdUI* pCmdUI);
	//}}AFX_MSG
	afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CTraceSheet

class CTracePage;
class CTraceSheet : public CPropertySheet
{
	const CTraceData *m_TraceData;

	DECLARE_DYNAMIC(CTraceSheet)
	
	virtual void AddTracePages() { VERIFY(FALSE); };	
// Construction
public:
	CTraceSheet(CTraceData *, UINT nIDCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);
	CTraceSheet(CTraceData *, LPCTSTR pszCaption, CWnd* pParentWnd = NULL, UINT iSelectPage = 0);

// Attributes
public:
	const CTraceData *GetTraceData() const { return m_TraceData; };

	CTracePage *GetTracePage(int i);
	CTracePage *GetActiveTracePage();

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTraceSheet)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

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

	// Generated message map functions
protected:
	//{{AFX_MSG(CTraceSheet)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CTraceMiniFrame frame

class CTraceMiniFrame : public CMiniFrameWnd
{
	CTraceSheet *m_TraceSheet;
	CDataSource *m_DataSource;

	DECLARE_DYNCREATE(CTraceMiniFrame)
protected:
	CTraceMiniFrame();     // protected constructor used by dynamic creation
public:
	CTraceMiniFrame(CDataSource *ds) : CMiniFrameWnd()
		{ m_DataSource = ds; m_TraceSheet = ds->CreateTraceSheet(); };

	CTraceMiniFrame(CTraceSheet *ts) : CMiniFrameWnd()
		{ m_DataSource = NULL; m_TraceSheet = ts; };

// Attributes
public:
	CTraceSheet *operator->() { return m_TraceSheet; };
	CTraceSheet *GetTraceSheet() { return m_TraceSheet; };
	CDataSource *GetDataSource() { return m_DataSource; };

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTraceMiniFrame)
	protected:
	virtual void PostNcDestroy();
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~CTraceMiniFrame();

	// Generated message map functions
	//{{AFX_MSG(CTraceMiniFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnClose();
	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// CTracePage dialog

class CTracePage : public CPropertyPage
{
	DECLARE_DYNCREATE(CTracePage)

	virtual void OnUpdate(WPARAM) { VERIFY(FALSE); };

// Construction
public:
	CTracePage() : CPropertyPage() {};
	CTracePage(UINT nIDTemplate, UINT nIDCaption = 0) : 
		CPropertyPage(nIDTemplate, nIDCaption) {};
	CTracePage(LPCTSTR lpszTemplateName, UINT nIDCaption = 0) :
		CPropertyPage(lpszTemplateName, nIDCaption) {};

// Attributes
public:
	const CTraceData *GetTraceData() const
		{ return dynamic_cast<CTraceSheet *>(GetParent())->GetTraceData(); };

// Operations
public:

// Dialog Data
	//{{AFX_DATA(CTracePage)
		// NOTE - ClassWizard will add data members here.
		//    DO NOT EDIT what you see in these blocks of generated code !
	//}}AFX_DATA


// Overrides
	// ClassWizard generate virtual function overrides
	//{{AFX_VIRTUAL(CTracePage)
	public:
	virtual BOOL OnSetActive();
	//}}AFX_VIRTUAL

// Implementation
protected:
	// Generated message map functions
	//{{AFX_MSG(CTracePage)
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

};

/////////////////////////////////////////////////////////////////////////////
