/*****************************************************************************
* Copyright (c) 2000 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 "E1R2Config.h"


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

   try
   {
      AffirmThrow(hKey != NULL);

      HKEY hE1R2 = NULL;
      AffirmThrow(RegCreateKey(hKey, DXB_REGKEY_E1R2, &hE1R2));
      AffirmThrow(hE1R2 != NULL);

      try
      {
         REGVALUE aRegVals[] = 
         {
            { DXB_REGVAL_E1R2_SIGNALLING,       &Data.reserved_0,          sizeof(Data.reserved_0),         REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_SWITCH_TYPE,		&Data.r2_switch_type,      sizeof(Data.r2_switch_type),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_METHOD,			&Data.r2_method,	       sizeof(Data.r2_method),		    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_CD_BITS,			&Data.r2_cd_bits,	       sizeof(Data.r2_cd_bits),		    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MAX_DNIS,			&Data.max_dnis_digits,     sizeof(Data.max_dnis_digits),    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MIN_DNIS,			&Data.min_dnis_digits,     sizeof(Data.min_dnis_digits),    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MAX_ANI,			&Data.max_ani_digits,	   sizeof(Data.max_ani_digits),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MIN_ANI,			&Data.min_ani_digits,      sizeof(Data.min_ani_digits),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_SEND_ANI,			&Data.send_ani_digits,     sizeof(Data.send_ani_digits),    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_ANI_SIGNAL,		&Data.ani_digit_signal,	   sizeof(Data.ani_digit_signal),   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_ANSWER_SIGNAL,	&Data.answer_signal,	   sizeof(Data.answer_signal),		REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_BUSY_SIGNAL,		&Data.busy_signal,		   sizeof(Data.busy_signal),		REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_OUTGOING_TYPE,	&Data.outgoing_type,	   sizeof(Data.outgoing_type),		REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_END_DNIS_SIGNAL,	&Data.end_dnis_signal,	   sizeof(Data.end_dnis_signal),	REG_DWORD,         0        },
		 };

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

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

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

   return fSuccess;
}

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

   try
   {
      AffirmThrow(hKey != NULL);

      HKEY hE1R2 = NULL;
      AffirmThrow(RegCreateKey(hKey, DXB_REGKEY_E1R2, &hE1R2));
      AffirmThrow(hE1R2 != NULL);

      try
      {
         REGVALUE aRegVals[] = 
         {
			{ DXB_REGVAL_E1R2_SIGNALLING,       (void *)Data.reserved_0,		  sizeof(Data.reserved_0),         REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_SWITCH_TYPE,		(void *)Data.r2_switch_type,      sizeof(Data.r2_switch_type),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_METHOD,			(void *)Data.r2_method,			  sizeof(Data.r2_method),		   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_CD_BITS,			(void *)Data.r2_cd_bits,          sizeof(Data.r2_cd_bits),         REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MAX_DNIS,			(void *)Data.max_dnis_digits,     sizeof(Data.max_dnis_digits),    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MIN_DNIS,			(void *)Data.min_dnis_digits,     sizeof(Data.min_dnis_digits),    REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MAX_ANI,			(void *)Data.max_ani_digits,	  sizeof(Data.max_ani_digits),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_MIN_ANI,			(void *)Data.min_ani_digits,	  sizeof(Data.min_ani_digits),     REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_ANI_SIGNAL,		(void *)Data.ani_digit_signal,	  sizeof(Data.ani_digit_signal),   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_SEND_ANI,			(void *)Data.send_ani_digits,	  sizeof(Data.send_ani_digits),	   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_ANSWER_SIGNAL,	(void *)Data.answer_signal,		  sizeof(Data.answer_signal),	   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_BUSY_SIGNAL,		(void *)Data.busy_signal,		  sizeof(Data.busy_signal),		   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_OUTGOING_TYPE,	(void *)Data.outgoing_type,		  sizeof(Data.outgoing_type),	   REG_DWORD,         0        },
			{ DXB_REGVAL_E1R2_END_DNIS_SIGNAL,	(void *)Data.end_dnis_signal,	  sizeof(Data.end_dnis_signal),	   REG_DWORD,         0        },
         };

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

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

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

   return fSuccess;
}

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

   try
   {
      AffirmThrow(hKey != NULL);

      HKEY hE1R2 = NULL;
      AffirmThrow(RegCreateKey(hKey, DXB_REGKEY_E1R2, &hE1R2));
      AffirmThrow(hE1R2 != NULL);

      try
      {
         static TCHAR const * const aRegVals[] = 
         {
			DXB_REGVAL_E1R2_SIGNALLING,
			DXB_REGVAL_E1R2_SWITCH_TYPE,
			DXB_REGVAL_E1R2_METHOD,
			DXB_REGVAL_E1R2_CD_BITS,
			DXB_REGVAL_E1R2_MAX_DNIS,
			DXB_REGVAL_E1R2_MIN_DNIS,
			DXB_REGVAL_E1R2_MAX_ANI,
			DXB_REGVAL_E1R2_MIN_ANI,
			DXB_REGVAL_E1R2_ANI_SIGNAL,
			DXB_REGVAL_E1R2_SEND_ANI,
			DXB_REGVAL_E1R2_ANSWER_SIGNAL,
			DXB_REGVAL_E1R2_BUSY_SIGNAL,
			DXB_REGVAL_E1R2_OUTGOING_TYPE,
			DXB_REGVAL_E1R2_END_DNIS_SIGNAL,
         };

         for (int i = 0; i < ElementCount(aRegVals); i++)
         {
            Affirm(RegDelValue(hE1R2, aRegVals[i]));
         }

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

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

   return fSuccess;
}