/*****************************************************************/
/**                                                             **/
/**             (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_log7[] = "@(#)log7.c	1.8 10/20/92 05:54:45  LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		James A. Guse
			Network Systems Division

	DATE WRITTEN:	11/30/90

PURPOSE:
	These routines log things to the level 7 log files.


*/

#include <elros/instance.h>
#include <elros/typecodes.h>

#define FLUSHFILE fflush(__ROv_global_debug_state.log7file)

#define LABELLINE(inst,line,file,instvar) \
  fprintf(__ROv_global_debug_state.log7file,"A%8.8x:%5d %s %s\n", \
  inst,line,file,instvar)

extern __RO_Debugstate __ROv_global_debug_state;


int __ROr_log7statement(instance,title_string,inst_string,line,file)

   __RO_Instance_Record *instance;
   char *title_string;
   char *inst_string;
   int line;
   char *file;

{
   int i;

   if (__ROr_Logging7on(instance))
   {
      if (!__ROv_global_debug_state.log7file)
         __RO_RETURN_RUNTIME(instance,__ROx_LOG_7NOFILE)
      LABELLINE(instance,line,file,inst_string);
      fprintf(__ROv_global_debug_state.log7file,"A%8.8x:      %s\n",
              instance,title_string);
      FLUSHFILE;
   }
   return(SUCCESS);
}

int __ROr_log7operation(instance,title_string,inst_string,
			internal,iid,lid,line,file)

   __RO_Instance_Record *instance;
   char *title_string;
   char *inst_string;
   int internal;
   long *iid;
   long *lid;
   int line;
   char *file;

{
   int i;

   if (__ROr_Logging7on(instance))
   {
      if (!__ROv_global_debug_state.log7file)
         __RO_RETURN_RUNTIME(instance,__ROx_LOG_7NOFILE)
      LABELLINE(instance,line,file,inst_string);
      fprintf(__ROv_global_debug_state.log7file,"A%8.8x:      %s %s",
		instance,title_string,instance->give_table[internal].text);
      fprintf(__ROv_global_debug_state.log7file,"(invoke_ID=");
      if (iid)
         fprintf(__ROv_global_debug_state.log7file,"%ld",*iid);
      else
         fprintf(__ROv_global_debug_state.log7file,"none");
      if (instance->give_table[internal].operation_class == __RO_INVOKE)
      {
         fprintf(__ROv_global_debug_state.log7file,",linked_ID=");
         if (lid)
            fprintf(__ROv_global_debug_state.log7file,"%ld",*lid);
         else
            fprintf(__ROv_global_debug_state.log7file,"none");
      }
      fprintf(__ROv_global_debug_state.log7file,")\n");
      FLUSHFILE;
   }
   return(SUCCESS);
}

int __ROr_log7type(instance,var_string,var_value,print_routine)

   __RO_Instance_Record *instance;
   char *var_string;
   void *var_value;
   int (*print_routine)();

{
   int i;
   char lead_string[20];

   if (__ROr_Logging7on(instance))
   {
      if (!__ROv_global_debug_state.log7file)
         __RO_RETURN_RUNTIME(instance,__ROx_LOG_7NOFILE)
      sprintf(lead_string,"A%8.8x:      ",instance);
      print_routine(__ROv_global_debug_state.log7file,var_value,var_string,1,lead_string);
      FLUSHFILE;
   }
   return(SUCCESS);
}

int __ROr_log7new(instance)

   __RO_Instance_Record *instance;

{
   if (__ROr_Logging7on(instance))
   {
      if (!__ROv_global_debug_state.log7file)
         __RO_RETURN_RUNTIME(instance,__ROx_LOG_7NOFILE)
      fprintf(__ROv_global_debug_state.log7file,"N%8.8x:\n",instance);
      FLUSHFILE;
   }
   return(SUCCESS);
}

int __ROr_log7comment(instance,text)

   __RO_Instance_Record *instance;
   char *text;

{
   if (__ROr_Logging7on(instance))
   {
      if (!__ROv_global_debug_state.log7file)
         __RO_RETURN_RUNTIME(instance,__ROx_LOG_7NOFILE)
      fprintf(__ROv_global_debug_state.log7file,"C%8.8x:   %s\n",instance,text);
      FLUSHFILE;
   }
   return(SUCCESS);
}


