// MiniCadExternals.cpp
//
// Copyright 1999 Diehl Graphsoft, Inc.
// All Rights Reserved.
//
// BRIEF_DESCRIPTION_OF_WHAT_IS_IN_THIS_FILE.
//
// SourceSafe information for this version:
//    $Revision: 2 $
//    $Date: 9/22/00 2:41 PM $
//    $Author: Jeff $


#include "StdHeaders.h"

#include "MiniCadExternals.h"
#include "CallbackIDs.h"
#include "CallbackParamTypes.h"
#include "MiniCadCallBacks.h"

// This must follow all header files.
#undef THIS_FILE
DECLARE_THIS_FILE



// =========================================================================================
// == XCall constructors and destructor

extern "C" {

//#if GS_USE_D0_RETURNS
//	#pragma pointers_in_D0
//#endif

	typedef long (*ExternalNameToIDPtr)(ConstStr31Param fileName);
	typedef GenericFunctionPtr (*OpenXCodePtr)(long extCodeInfoID, lboolean_t needsResourceFileOpen);
	typedef void (*CloseXCodePtr)(long extCodeInfoID);

//#if GS_USE_D0_RETURNS
//	#pragma pointers_in_A0
//#endif

}

//-------------------------------------------------------------------
XCall::XCall(CallBackPtr cbp, ConstStr31Param externalName, Boolean needsResourceFileOpen)
	: fCBB(cbp)
//
//	Constructor for XCall class.
//
{
	GenericFunctionPtr f1 = CallRetrieverProc(fCBB.rPtr, kcbExternalNameToID);
	GenericFunctionPtr f2 = CallRetrieverProc(fCBB.rPtr, kcbOpenXCode);

	if (f1) {
		fCodeID = (*(ExternalNameToIDPtr) f1)(externalName);
		fnPtr = f2 ? (*(OpenXCodePtr) f2)(fCodeID, needsResourceFileOpen) : nil;
	}
	else {
		fCodeID = -1;
		fnPtr = nil;
	}
}

//-------------------------------------------------------------------
XCall::XCall(CallBackPtr cbp, long externalID, Boolean needsResourceFileOpen)
	: fCBB(cbp)
//
//	Constructor for XCall class.
//
{
	GenericFunctionPtr f = CallRetrieverProc(fCBB.rPtr, kcbOpenXCode);
	
	fnPtr = f ? (*(OpenXCodePtr) f)(externalID, needsResourceFileOpen) : nil;
	fCodeID = externalID;
}

//-------------------------------------------------------------------
XCall::~XCall()
//
//	Destructor for XCall class.
//
{
	GenericFunctionPtr f = CallRetrieverProc(fCBB.rPtr, kcbCloseXCode);
	
	if (f && fCodeID != -1) (*(CloseXCodePtr) f)(fCodeID);
}

