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


// LineChaska.cpp: implementation of the CLineChaska class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "LineChaska.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(CLineChaska, CLine)

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

      if (m_strProtocol != DXB_REGVAL_PROTOCOL_ENUM_POTS)
      {
         TRACE("Line protocol was set to: %s\n", m_strProtocol);
         m_strProtocol = DXB_REGVAL_PROTOCOL_ENUM_POTS;
         TRACE("Overriding line protocol with: %s\n", m_strProtocol);
      }

      // Solve our identity crisis
      // NOTE: Lines do not have identities!

      // Set our display name
      CString strDisplayName;
      strDisplayName.Format(IDS_DisplayName_LineFormat, (GetLineNumber() + 1));
      SetDisplayName(strDisplayName);

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

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

      // Give birth to our children
      AffirmThrow(AddChild());
   }
   catch (CAffirmException ae)
   {
   }
}

CLineChaska::~CLineChaska()
{
   try
   {
   }
   catch (CAffirmException ae)
   {
   }
}

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

   try
   {
      Affirm(m_apChildren.GetSize() == 0);

      INT_PTR iNewChild = m_apChildren.Add(NULL);
      AffirmThrow(iNewChild == 0);

      // 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 protocol parameters reside at the same level.
      //    So, pass in the hKey and path we were given.

      AffirmThrow(NewConfigObject(&m_apChildren[iNewChild], CConfigObject::PROTOCOL, m_strProtocol, m_hKeyRoot, m_strRegPath, this));
      AffirmThrow(m_apChildren[iNewChild] != NULL);

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

   return fSuccess;
}

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

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

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

   return fSuccess;
}

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

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

   return fSuccess;
}

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

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

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

   return fSuccess;
}

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

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

   try
   {
      AffirmThrow(pSheet != NULL);

      AffirmThrow(m_apChildren[0] != NULL);
      AffirmThrow(m_apChildren[0]->AddWizardPages(pSheet));

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

   return fSuccess;
}

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

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

   return fSuccess;
}

CString CLineChaska::GetInformationText(void)
{
   CString strInfo = TEXT("");

   try
   {
      AffirmThrow(m_apChildren[0] != NULL);
      strInfo.Format(IDS_Information_LineFormat, m_apChildren[0]->GetDisplayName());
   }
   catch (CAffirmException ae)
   {
   }

   return strInfo;
}

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

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

   return fThingsHaveChanged;
}
