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


// DigiHLC.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <afxdllx.h>

#include "AdapterHouston.h"
#include "AdapterPRIme.h"
#include "AdapterLondon.h"
#include "AdapterChaska.h"
#include "AdapterAcceleportXp.h"

#include "LineHouston.h"
#include "LineLondon.h"
#include "LineChaska.h"
#include "LineAcceleportXp.h"

#include "ProtocolSERIAL.h"

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


HINSTANCE g_hInstance = NULL;

static AFX_EXTENSION_MODULE DigiHLCDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
	// Remove this if you use lpReserved
	UNREFERENCED_PARAMETER(lpReserved);

	if (dwReason == DLL_PROCESS_ATTACH)
	{
		TRACE("DIGIHLC.DLL: Initializing!\n");
		
		g_hInstance = hInstance;
		
		// Extension DLL one-time initialization
		if (!AfxInitExtensionModule(DigiHLCDLL, hInstance))
			return 0;

		// Insert this DLL into the resource chain
		// NOTE: If this Extension DLL is being implicitly linked to by
		//  an MFC Regular DLL (such as an ActiveX Control)
		//  instead of an MFC application, then you will want to
		//  remove this line from DllMain and put it in a separate
		//  function exported from this Extension DLL.  The Regular DLL
		//  that uses this Extension DLL should then explicitly call that
		//  function to initialize this Extension DLL.  Otherwise,
		//  the CDynLinkLibrary object will not be attached to the
		//  Regular DLL's resource chain, and serious problems will
		//  result.

		new CDynLinkLibrary(DigiHLCDLL);
	}
	else if (dwReason == DLL_PROCESS_DETACH)
	{
		TRACE("DIGIHLC.DLL: Terminating!\n");
		// Terminate the library before destructors are called
		AfxTermExtensionModule(DigiHLCDLL);
	}
	return 1;   // ok
}

BOOL APIENTRY NewObj(CConfigObject const ** const ppObj, CString const & strName, HKEY const hKeyRoot, CString const & strRegPath, CConfigObject const * const pParent)
{
   BOOL fSuccess = FALSE;

   TRACE("DIGIHLC.DLL: NewObj(%s)\n", (LPCTSTR)strName);

   try
   {
      AffirmThrow(ppObj != NULL);
#if defined(_DEBUG)
      if (*ppObj != NULL) TRACE("*ppObj != NULL\n");
#endif

      static CString const strLine = TEXT("Line");
      static CString const strLineHouston = strLine + DXB_REGVAL_OPTION_ENUM_HOUSTON;
      static CString const strLinePrime   = strLine + DXB_REGVAL_OPTION_ENUM_PRIME;
      static CString const strLineLondon  = strLine + DXB_REGVAL_OPTION_ENUM_LONDON;
      static CString const strLineChaska  = strLine + DXB_REGVAL_OPTION_ENUM_CHASKA;
      static CString const strLineAccelePort2000 = strLine + DXB_REGVAL_OPTION_ENUM_ACCELEPORT_2000;

      CConfigObject * pNewObj = NULL;

           if (strName == DXB_REGVAL_OPTION_ENUM_HOUSTON)            pNewObj = new CAdapterHouston(hKeyRoot, strRegPath, pParent);
      else if (strName == strLineHouston)                            pNewObj = new CLineHouston(hKeyRoot, strRegPath, pParent);
      else if (strName == DXB_REGVAL_OPTION_ENUM_PRIME)              pNewObj = new CAdapterPRIme(hKeyRoot, strRegPath, pParent);
      else if (strName == strLinePrime)                              pNewObj = new CLineHouston(hKeyRoot, strRegPath, pParent);
      else if (strName == DXB_REGVAL_OPTION_ENUM_LONDON)             pNewObj = new CAdapterLondon(hKeyRoot, strRegPath, pParent);
      else if (strName == strLineLondon)                             pNewObj = new CLineLondon(hKeyRoot, strRegPath, pParent);
      else if (strName == DXB_REGVAL_OPTION_ENUM_CHASKA)             pNewObj = new CAdapterChaska(hKeyRoot, strRegPath, pParent);
      else if (strName == strLineChaska)                             pNewObj = new CLineChaska(hKeyRoot, strRegPath, pParent);
      else if (strName == DXB_REGVAL_OPTION_ENUM_ACCELEPORT_2000)    pNewObj = new CAdapterAcceleportXp(hKeyRoot, strRegPath, pParent);
      else if (strName == strLineAccelePort2000)                     pNewObj = new CLineAcceleportXp(hKeyRoot, strRegPath, pParent);
      else if (strName == DXB_REGVAL_PROTOCOL_ENUM_SERIAL)           pNewObj = new CProtocolSERIAL(hKeyRoot, strRegPath, pParent);
      else AffirmThrow(FALSE);

      AffirmThrow(pNewObj != NULL);
      *ppObj  = pNewObj;
      fSuccess = TRUE;
   }
   catch (CAffirmException ae)
   {
   }

   return fSuccess;
}

void APIENTRY DeleteObj(CConfigObject const ** const ppObj)
{
   TRACE("DIGIHLC.DLL: DeleteObj()\n");

   try
   {
      AffirmThrow(ppObj != NULL);
      AffirmThrow(*ppObj != NULL);

      delete *ppObj;
      *ppObj = NULL;
   }
   catch (CAffirmException ae)
   {
   }

   return;
}
