/*-=-=-=-=-=-=-=-=-=-=-=- RCCL/RCI Notice of Copyright -=-=-=-=-=-=-=-=-=-=-*
 *									    *
 *	Copyright (C) 1991 by John E. Lloyd.				    *
 *									    *
 *	Information on copyright permissions, as well as a complete	    *
 *	disclaimer of warranty, is given in the file COPYRIGHT.		    *
 *									    *
 *-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
/*---------------------------------------------------------------------------
 *		
 * MODULE NAME:	levelCheck
 *
 * DESCRIPTION:	Check if we are in the planning task or not.
 *
 * AUTHOR/DATE:	John Lloyd, Fall 1989
 *
 * MODIFICATION HISTORY:
 *
 *--------------------------------------------------------------------------*/

#include "../h/errorCodes.h"

/* These routines are called in lots of places. We make the two external
   references (to rciTaskId and rciAbort()) static pointers so that we
   don't load in all of RCI just because some utility routine happens
   to call these functions. */
static int *rciTaskIdp;
static int (*abortFxn)();
static int initDone = 0;

levelCheckInit(tip,fxn)
int *tip;
int (*fxn)();
{
	initDone = 1;
	rciTaskIdp = tip;
	abortFxn = fxn;
	requestFlagInit (&initDone);
}

planningLevelCheck(fxnName)
char *fxnName;
{
	/* Internal routine to verify that a routine is in fact being
	   called from the planning level, and abort if it is not */

	int status;
	/* MS Disable check to prevent shutdown under linux.
           Consequences ?????? */
	if (initDone && (status = *rciTaskIdp) != 0)
	 { 
	   /* MS */
	   rciPrintf("Planning level check would call abortFxn\n");
	   return(1);
	   /*
	   (*abortFxn)(EFatal, "%s called from control level\n", fxnName);
	   return (0);
	   */
	 }
	
	return (1);
}

controlLevelCheck(fxnName)
char *fxnName;
{
	/* Internal routine to verify that a routine is in fact being
	   called from the control level, and abort if it is not */

	if (initDone && (*rciTaskIdp) == 0)
	 { (*abortFxn)(EFatal, "%s called from planning level\n", fxnName);
	   return (0);
	 }
	return (1);
}
