#!/bin/bash

#set -x

#--------------------------------------------------------------------------
# Command:   traceLevel
#
# Purpose:   Sets the CIMOM trace level one of several valid values:
#		TRACE  - Function level tracing, i.e. function entries/exits
#		FDEBUG - Field level debug tracing, i.e. official field support
#		DEBUG  - Debug level tracing, i.e. voluminous development stuff
#
# Usage:    tracelevel <newLevel>
#		where newLevel is one of the above values
#--------------------------------------------------------------------------

showUsage()
{
  echo
  echo  "Usage: "
  echo  "  traceLevel [newLevel | query]"
  echo  "  	where newLevel is the new trace level and one of these valid values:"
  echo  "               TRACE       function level tracing"
  echo  "               FDEBUG      field debug trace level"
  echo  "               DEBUG       debug trace level - most voluminous level"
  echo  " "
}


#--------------------------------------------------------------------------
# If valid command line, invoke the command...
#--------------------------------------------------------------------------
CMD=$0

if [ $# -lt 1 -o $# -gt 1 ]; then
    showUsage
    exit 1
fi

TRACE_LEVEL=$1

/opt/hsc/bin/hscSignal 220 $TRACE_LEVEL

CMD_RC=$?

#--------------------------------------------------------------------------
#  Check the results...
#--------------------------------------------------------------------------

if [ $TRACE_LEVEL = "query" ] ; then
  	CURRENT_TRACE_LEVEL=UNKNOWN
        case $CMD_RC in
		1)  CURRENT_TRACE_LEVEL=TRACE
			;;
		2)  CURRENT_TRACE_LEVEL=FDEBUG
		;;
		3)  CURRENT_TRACE_LEVEL=DEBUG
		;;
	esac
	echo "The current trace level is " $CURRENT_TRACE_LEVEL

else
	if [ "$CMD_RC" -ne 0 ]; then
		echo "Unable to set trace level to :  $TRACE_LEVEL"
		showUsage
  	fi
fi

exit 0
