/*****************************************************************************
* 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
*
*****************************************************************************/


// ProtocolPOTS.cpp: implementation of the CProtocolPOTS class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ProtocolPOTS.h"
#include "ObjectFactory.h"

#include "Resource.h"

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

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

IMPLEMENT_DYNAMIC(CProtocolPOTS, CProtocol)

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

      // Solve our identity crisis
      SetIdentity(DXB_REGVAL_PROTOCOL_ENUM_POTS);

      // Set our display name
      CString strDisplayName;
      AffirmThrow(strDisplayName.LoadString(IDS_DisplayName_POTS));
      SetDisplayName(strDisplayName);

      // Set what we can do
      SetAbility(CConfigObject::NOABILITIES);

      // Get our static config data
      AffirmThrow(GetConfigData());

      m_astrServices.Copy(m_astrServicesAllowed);

      // Give birth to our children
      for (int i = 0; i < m_astrServices.GetSize(); i++)
      {
         AffirmThrow(AddChild(m_astrServices[i]));
      }

      // Init config mode stuff
      m_pwsSheet = NULL;

      for (i = 0; i < ElementCount(m_apWizPages); i++)
      {
         m_apWizPages[i] = NULL;
      }
   }
   catch (CAffirmException ae)
   {
   }
}

CProtocolPOTS::~CProtocolPOTS()
{
   try
   {
      for (int i = 0; i < ElementCount(m_apWizPages); i++)
      {
         if (m_apWizPages[i] != NULL) delete m_apWizPages[i];
      }
   }
   catch (CAffirmException ae)
   {
   }
}

BOOL CProtocolPOTS::AddChild(void)
{
   BOOL fSuccess = FALSE;

   try
   {
      // Currently unimplemented
      AffirmThrow(FALSE);
      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

BOOL CProtocolPOTS::AddChild(CString const & strChild)
{
   BOOL fSuccess = FALSE;

   try
   {
      INT_PTR iNewChild = m_apChildren.Add(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 = strChild + TEXT("\\") + m_strRegPath;
      AffirmThrow(NewConfigObject(&m_apChildren[iNewChild], CConfigObject::SERVICE, strChild, m_hKeyRoot, strServiceRegPath, this));
      AffirmThrow(m_apChildren[iNewChild] != NULL);

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

   return fSuccess;
}

//////////////////////////////////////////////////////////////////////
// Get/Set parameters
//////////////////////////////////////////////////////////////////////

BOOL CProtocolPOTS::GetParameters(void)
{
   BOOL fSuccess = FALSE;

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

   return fSuccess;
}

BOOL CProtocolPOTS::SetParameters(void)
{
   BOOL fSuccess = FALSE;

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

   return fSuccess;
}

//////////////////////////////////////////////////////////////////////
// Config data
//////////////////////////////////////////////////////////////////////

BOOL CProtocolPOTS::GetConfigData(void)
{
   BOOL fSuccess = FALSE;

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

   return fSuccess;
}

//////////////////////////////////////////////////////////////////////
// UI config methods
//////////////////////////////////////////////////////////////////////

BOOL CProtocolPOTS::AddWizardPages(CConfigWizSheet * const pSheet)
{
   BOOL fSuccess = FALSE;

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

   return fSuccess;
}

BOOL CProtocolPOTS::RemoveWizardPages(CConfigWizSheet * const pSheet)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(pSheet != NULL);

      if (m_pwsSheet != NULL)
      {
         AffirmThrow(m_pwsSheet == pSheet);

         for (int i = 0; i < ElementCount(m_apWizPages); i++)
         {
            if (m_apWizPages[i] != NULL) m_pwsSheet->RemovePage(m_apWizPages[i]);
         }
      }

      AffirmThrow(CProtocol::RemoveWizardPages(pSheet));

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

   return fSuccess;
}

BOOL CProtocolPOTS::NextWizardPage(int const nState)
{
   BOOL fSuccess = FALSE;

   try
   {
      switch (nState)
      {
         case WP_MODEMNAT: break;
         default: AffirmThrow(FALSE); break;
      }

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

   return fSuccess;
}

BOOL CProtocolPOTS::DoProperties(void)
{
   BOOL fThingsHaveChanged = FALSE;

   try
   {
      AffirmThrow(FALSE);
   }
   catch (CAffirmException ae)
   {
   }

   return fThingsHaveChanged;
}
