/*****************************************************************************
* 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
*
*****************************************************************************/
// ProtocolPPP.cpp: implementation of the CProtocolPPP class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ProtocolPPP.h"
#include "ObjectFactory.h"
#include "RegHelpers.h"
#include "resource.h"

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

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC(CProtocolPPP, CProtocol)

CProtocolPPP::CProtocolPPP(HKEY const hKeyRoot, CString const strRegPath, CConfigObject const * const pParent): CProtocol(hKeyRoot, strRegPath, pParent)
{
   try
   {
	   // Get parameters
	   AffirmThrow(GetParameters());

		// solve the identity crisis
	   SetIdentity(DXB_REGVAL_PROTOCOL_ENUM_PPP);
	   // Set our Display Name
	   CString szDisplayName;
	   AffirmThrow(szDisplayName.LoadString(IDS_DisplayName_Protocol));
	   SetDisplayName(szDisplayName);

	   // define our abilities
	   // we don't allow adding/deleting childs from the GUI. Defining the
	   // PPP protocol automatically creates the service which is simply 
	   // a holder object allowing us to create
	   SetAbility(CConfigObject::NOABILITIES);
	
	   // get our static config data
	   AffirmThrow(CProtocol::GetConfigData());

       m_astrServices.Copy(m_astrServicesAllowed);
      // Give birth to our children

       for (int i = 0; i < m_astrServices.GetSize(); i++)
       {
		   m_apChildren.SetAtGrow(i, NULL);

         // This registry path thingie needs a little explanation!
         //    Here's the layout so far:
         //       ...\DigiDxb?\Parameters\N           (where ? = the adapter instance, and
         //                                                  N = 0, 1, ... # of lines)
         //    The line service parameters reside at:
         //       ...\DigiDxb?\Parameters\XXXX\N      (where XXXX = the service name)
         //    So, pass in the hKey we were told to start at, and the XXXX\N reg path.

         CString strServiceRegPath = m_astrServices[i] + TEXT("\\") + strRegPath;
         AffirmThrow(NewConfigObject(&m_apChildren[i], CConfigObject::SERVICE, m_astrServices[i], hKeyRoot, strServiceRegPath, this));
         AffirmThrow(m_apChildren[i] != NULL);
      }

   }
   catch (CAffirmException ae)
   {
   }

}

CProtocolPPP::~CProtocolPPP()
{

}


BOOL CProtocolPPP::SetParameters()
{
	BOOL bSuccess = FALSE;
	try
	{
		AffirmThrow(CProtocol::SetParameters());
		bSuccess = TRUE;
	}
	catch(CAffirmException ae)
	{
	}
	return bSuccess;
}

BOOL CProtocolPPP::GetParameters()
{
	BOOL bSuccess = FALSE;
	try
	{
		AffirmThrow(CProtocol::GetParameters());
		bSuccess = TRUE;
	}
	catch(CAffirmException ae)
	{
	}
	return bSuccess;

}

BOOL CProtocolPPP::RemoveParameters(BOOL fRemoveKey)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(CProtocol::RemoveParameters(fRemoveKey));
      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

BOOL CProtocolPPP::BuildDisplayTree(CTreeNode * const pNode)
{
   BOOL fSuccess = FALSE;

   try
   {
      // TRACE("CConfigObject(%s)::BuildDisplayTree()\n", GetIdentity());
      // We don't have any setable parameters....
      // Don't add anything here, just have our children add their own nodes

      AffirmThrow(pNode != NULL);
      for (int i = 0; i < m_apChildren.GetSize(); i++)
      {
         AffirmThrow(m_apChildren[i] != NULL);
         AffirmThrow(m_apChildren[i]->BuildDisplayTree(pNode));
      }

      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}


// we don't have any pages of our own, but our children might
BOOL CProtocolPPP::AddWizardPages(CConfigWizSheet* const pSheet)
{
	BOOL bSuccess = FALSE;
	try
	{
		AffirmThrow(pSheet != NULL);
		// call the service to add its pages
		for (int i=0;i<GetChildCount();i++)
			AffirmThrow(m_apChildren[i]->AddWizardPages(pSheet));
		bSuccess = TRUE;

	}
	catch(CAffirmException ae)
	{
	}
	return bSuccess;
}
