/*****************************************************************/
/**                                                             **/
/**             (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_sendP_bool[] = "@(#)sendP_bool.c	1.23 10/20/92 06:01:24 LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		Robyne M. Sumpter	
			Network Systems Division

	DATE WRITTEN:	7/9/90

	ROUTINE:	__ROr_sendP_Boolean	

PURPOSE:
	Load the asn.1 value of the boolean into the buffer.  If the
	send buffer is full, send it using the send_data routine.

IN:
	instance - send_data function to call
	value - Value of the boolean to be encoded.
	valuelength - Length of the un-encoded boolean in octets.
	maxlength - Maximum encoded length of the boolean.
	maxlength2 - Unused.

OUT:
	
	instance - Send state is updated.
		Send state buffer is loaded with octet and possibly sent.
		Exception state is updated. 
	


CALLED ROUTINES:
	__ROr_encP_length	

	
MODIFICATION HISTORY:


*/


#include <elros/instance.h>
#include <elros/sendP_element.h>
#include <elros/enc_dcd.h>
#include <elros/encP_length.h>

#define CURRENT_TYPE_LENGTHS_FIELD	Boolean_lengths

int __ROr_BERsendP_Boolean( instance, value, valuelength, maxlength, maxlength2)

   __RO_Instance_Record		*instance;
   void			*value;
   unsigned long	*valuelength; 
   unsigned long	*maxlength;
   unsigned long	*maxlength2;

   {

   unsigned long	length = 1;
   int	i;
   unsigned char Octet = 0x00;
   unsigned char *value_ptr;
	

		/* encP_length will ensure that there is enough 	*/
		/* buffer space for the encoding of the length 	*/
		/* and the value.				*/
   __ROr_encP_length( instance, &length );
   

		/* Determine if the value is non zero */
   for( value_ptr = (unsigned char *)value, i = *valuelength-1;  
	!(*value_ptr & 0xff) && i > 0;
        i--, value_ptr++ );

   if( *value_ptr )
      Octet = 0xff;
   else
      Octet = 0x00;

   __ROr_sendP_1element( instance, &Octet );

   return(SUCCESS);

}

