/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

static char sccsid_abort[] = "@(#)STDabort.c	1.11 10/19/92 13:47:02  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Robyne M. Sumpter
			Network Systems Division

	DATE WRITTEN:	7/25/90

	ROUTINE:	abort
	Version:	__ROr_STDabort

PURPOSE:
	This routine unbinds the instance

IN:
	instance - pointer to instance record.

OUT:
	instance - All fields are inaccessible -- pointer is freed.


CALLED ROUTINES:
	

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>
#include <elros/binds.h>
#include <elros/specifics.h>

#ifdef __RO_PLATFORM_ISODE
#   include <isode/psap2.h>
#   include <isode/pepsy/ACS-types.h>
#endif


int __ROr_STDabort(instance)
    __RO_Instance_Record *instance;

    {
	switch(instance->subsystem->platform)
	{

	    case __ROm_platform_ISODE:

#ifdef __RO_PLATFORM_ISODE
		if( __ROr_abort_ISODE( instance ) )
		    return( EXCEPTION );
 	    break;
#else
	    __RO_RETURN_RUNTIME(instance,__ROx_INTERNAL_ISODENOTLINKED);
#endif

	    case __ROm_platform_PURESOCKETS:

/*!!!!!!!!!  NOTE THIS JUST CALLS UNBIND !!!!!!!!!!!!!!*/
#ifdef __RO_PLATFORM_PURESOCKETS
		if( __ROr_unbind_SOCK( instance ) )
		    return( EXCEPTION );
 	    break;
#else
	    __RO_RETURN_RUNTIME(instance,__ROx_INTERNAL_PURESOCKETSNOTLINKED);
#endif

	    case __ROm_platform_MEM:
	    break;

	    case __ROm_platform_FILE:
		fclose(instance->subsystem->specific.file.infile);
		fclose(instance->subsystem->specific.file.outfile);
	    break;

	default:
	    __RO_RETURN_RUNTIME(instance,__ROx_INTERNAL_MUTUAL);
	
 	}


    return(__ROr_STDfree_instance(instance));
    }




#ifdef __RO_PLATFORM_ISODE

int __ROr_abort_ISODE( inst )
    __RO_Instance_Record *inst;
    {

    struct PSAPindication presentation_indication;
    char msgbuf[SA_SIZE],*msg=msgbuf;


   if (inst->except_state.entry)
      sprintf(msg,inst->except_state.entry->text,
		inst->except_state.customize
		? inst->except_state.customize
		: "???");
   else
      msg=NULL;
			/*
			 * Make the abort request.
			 */
    if( PUAbortRequest(
		     inst->subsystem->specific.isode.association,
/*	             msg, msg ? strlen(msg) : 0,*/
		     NULLPE, 0,
		     &presentation_indication) == NOTOK)
       __RO_RETURN_RUNTIME(inst,__ROx_BIND_UABORTFAILED)
    else
    {
#ifdef __RO_TASKING

	if( __ROr_ISODEwait_for_send(inst) )
	    return(EXCEPTION);
#endif
    }
  
  
    return(SUCCESS);
    }

#endif /* __RO_PLATFORM_ISODE */



