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


#include "stdafx.h"
#include "DChanExtConfig.h"


BOOL SDChanExtConfig::Get(HKEY const hKey)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(hKey != NULL);

      HKEY hDChan = NULL;
      AffirmThrow(RegCreateKey(hKey, DXB_REGKEY_DCHAN, &hDChan));
      AffirmThrow(hDChan != NULL);

      try
      {
         REGVALUE aRegVals[] = 
         {
            { DXB_REGVAL_DCHAN_MODE,            &Data.mode,            sizeof(Data.mode),            REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_ADDRESS_TYPE,    &Data.address_type,    sizeof(Data.address_type),    REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_NUMBERING_PLAN,  &Data.numbering_plan,  sizeof(Data.numbering_plan),  REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_SUBADDRESS_TYPE, &Data.subaddress_type, sizeof(Data.subaddress_type), REG_DWORD, 0 },
         };

         AffirmThrow(RegReadMultipleValues(hDChan, aRegVals, ElementCount(aRegVals)));

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

      RegCloseKey(hDChan);
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

BOOL SDChanExtConfig::Set(HKEY const hKey)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(hKey != NULL);

      HKEY hDChan = NULL;
      AffirmThrow(RegCreateKey(hKey, DXB_REGKEY_DCHAN, &hDChan));
      AffirmThrow(hDChan != NULL);

      try
      {
         REGVALUE aRegVals[] = 
         {
            { DXB_REGVAL_DCHAN_MODE,            (void *)Data.mode,            sizeof(Data.mode),            REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_ADDRESS_TYPE,    (void *)Data.address_type,    sizeof(Data.address_type),    REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_NUMBERING_PLAN,  (void *)Data.numbering_plan,  sizeof(Data.numbering_plan),  REG_DWORD, 0 },
            { DXB_REGVAL_DCHAN_SUBADDRESS_TYPE, (void *)Data.subaddress_type, sizeof(Data.subaddress_type), REG_DWORD, 0 },
         };

         AffirmThrow(RegWriteMultipleValues(hDChan, aRegVals, ElementCount(aRegVals)));

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

      RegCloseKey(hDChan);
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

BOOL SDChanExtConfig::Remove(HKEY const hKey)
{
   BOOL fSuccess = FALSE;

   try
   {
      AffirmThrow(hKey != NULL);
      AffirmThrow(RegDelKey(hKey, DXB_REGKEY_DCHAN));
      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}
