/*****************************************************************************
* Copyright (c) 1990-99 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
*
*****************************************************************************/


// ProtocolSERIAL.cpp: implementation of the CProtocolSERIAL class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ProtocolSERIAL.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(CProtocolSERIAL, CProtocol)

CProtocolSERIAL::CProtocolSERIAL(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_SERIAL);

      // This object is never displayed in the tree, set a dummy name here
      CString strDisplayName = "SerialProtocol";
      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]));
      }

   }
   catch (CAffirmException ae)
   {
   }
}

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

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

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

   return fSuccess;
}

BOOL CProtocolSERIAL::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 CProtocolSERIAL::GetParameters(void)
{
   BOOL fSuccess = FALSE;

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

   return fSuccess;
}

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

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

   return fSuccess;
}

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

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

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

   return fSuccess;
}

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

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

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

   return fSuccess;
}

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

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

   return fSuccess;
}

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

   // No wizard pages for serial protocol
   try
   {
      AffirmThrow(FALSE);
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

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

   // No property pages for serial protocol
   try
   {
      AffirmThrow(FALSE);
   }
   catch (CAffirmException ae)
   {
   }

   return fThingsHaveChanged;
}
