/*****************************************************************************
* Copyright (c) 1990-98 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
*
*****************************************************************************/
// Wan.cpp: implementation of the CWan class.
//
//////////////////////////////////////////////////////////////////////
// This is a support class that has all the line charactersistics related data
// handles the dialog that allows user to enter relevant data
#include "stdafx.h"
#include "Wan.h"
#include "regnames.h"
#include "reghelpers.h"
#include "WanConfig.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CWan::CWan()
{
	m_WAN.ext_baud = 56000;
	m_WAN.wan_baud = 0;
	m_WAN.wan_interface = 1;
	m_WAN.wan_maxframe = 2048;
	m_pPage = NULL;
}

CWan::~CWan()
{
	delete m_pPage;
}
// called from the parent object to remove keys
BOOL CWan::RemoveParameters(void)
{
	return(
		(RegDeleteKey(m_hKey,c_pszKeyWan) == ERROR_SUCCESS)?TRUE:FALSE);
}
// 
BOOL CWan::ReadWriteWanParams(REGMODE emode)
{
	HKEY hsubkey;
	//
	// open the FRAME RELAY section
	if (!RegCreateKey(m_hKey,c_pszKeyWan,&hsubkey))
		return FALSE;

	REGSTRUCT wan[] = {
		{c_pszGUIValueBaud,&(m_WAN.ext_baud)},
		{c_pszValueBaud,&(m_WAN.wan_baud)},
		{c_pszValueInterface,&(m_WAN.wan_interface)},
		{c_pszValueMaxFrame,&(m_WAN.wan_maxframe)}
	};

	ReadWriteRegItems(hsubkey,wan,sizeof(wan)/sizeof(wan[0]),emode);
	RegCloseKey(hsubkey);
	return TRUE;
}
// create a property page, set the necessary variables and return the ptr
CPropertyPage* CWan::GetWanConfigPage()
{
	if (m_pPage == NULL)
		m_pPage = (CPropertyPage*)new CWanConfig;
	ASSERT(m_pPage);
	if (m_pPage)
	{
		CWanConfig* pPage = (CWanConfig*)m_pPage;

		if (m_WAN.ext_baud)
			pPage->m_Baud = m_WAN.ext_baud;
		else
			pPage->m_Baud = m_WAN.wan_baud;

		pPage->m_ExternalClock = (m_WAN.ext_baud > 0)?0:1;
		if (m_WAN.wan_interface == 0x80000000)
			pPage->m_ElectricalInt = 3;
		else
			pPage->m_ElectricalInt =m_WAN.wan_interface;
	}
	return(m_pPage);
}
// called in response to OK button being pressed on the property page.
// This method should be called after GetWanConfigPage is called and the 
// holding sheet returns an IDOK result.
void CWan::WanConfigOnOk()
{
	ASSERT(m_pPage);
	if (m_pPage)
	{
		CWanConfig* pPage =(CWanConfig*)m_pPage;
		m_WAN.ext_baud = (pPage->m_ExternalClock == 0)?pPage->m_Baud:0;
		m_WAN.wan_baud = (pPage->m_ExternalClock == 0)?0:pPage->m_Baud;

		m_WAN.wan_interface = (pPage->m_ElectricalInt == 3)? 
			0x80000000 : pPage->m_ElectricalInt;
		delete m_pPage;
		m_pPage = NULL;
	}

}