#! /usr/bin/csh -f
#

#ident  "@(#)vts_cmsconfig  1.1  98/12/03  SMI"

#
# Copyright (c) 1998, by Sun Microsystems, Inc.
# All rights reserved.
#
# vts_cmsconfig pri_time pri_retry name number attribute [ "value" ]
#
# Purpose:		This function can be used to get or set an attribute 
#			value of the object named "name number" using cmsconfig.
#			If cmsconfig returns the error code 2, this function 
#			will continue re-call cmsconfig after pri_time
#			for no of pri_retry times.
#
# Mandatory Parameters:
# pri_time          	- sleep time between each retry
# pri_retry          	- no of pri_retry
# name          	- class name of CMS Object setting attribute
# number        	- instance number of CMS Object setting attribute
# attribute     	- attribute to be set or read
#
# Optional Parameter
# value         	- value that attribute is to be set to
#
# Returns:
# value		- value of attribute requested
#
# Error Codes:
# Return 0 on success, non-zero otherwise
#
#if( $ret_val != 0 && $ret_val != 2) then



# setenv CMSHOME /opt/SUNWcms
# setenv LD_LIBRARY_PATH /opt/SUNWcms/lib
setenv CMSHOME  /usr/platform/SUNW,Ultra-4FT/SUNWcms
setenv LD_LIBRARY_PATH /usr/platform/SUNW,Ultra-4FT/SUNWcms/lib
set path = (/usr/platform/SUNW,Ultra-4FT/SUNWcms /usr/platform/SUNW,Ultra-4FT/SUNWcms/lib $path)
set logfile = "/opt/SUNWvts/bin/fttest/vstftcpu.log"
set tmpfile = "/opt/SUNWvts/bin/fttest/ftcpu.tmp"

set no_arg = $#argv

if( $no_arg > 6 ) then
    echo 1 > $logfile
    echo "Usage: vts_cmsconfig <pri_time> <pri_retry> <name> <number> <attribute>[<value>]" > $logfile
    exit 1
endif


echo "vts_cmsconfig-1: No of arg is $no_arg" >> $tmpfile

set pri_time="$1"
set pri_retry="$2"

set name="$3"
set number="$4"
set attribute="$5"
if( $no_arg == 6 ) then
   set value = "$6"
endif

set command="cmsconfig -wm $name -n $number -a $attribute"

set ret_value=2
while ( $ret_value == 2 )
   if($pri_retry >= 0) then
	if ($no_arg == 5) then
		echo "vts_cms-2: eval $command -q" >> $tmpfile
#		set ret_string=`eval "$command -q" >& /dev/null`
		set ret_string=`eval "$command -q"`
		set ret_value = $status
	else
#		set ret_string = `eval "$command -v $value" >& /dev/null`
		set ret_string = `eval "$command -v $value"`
		set ret_value = $status
	endif
	echo "vts_cms-3: ret_string is $ret_string" >> $tmpfile
	echo "vts_cms-3: ret_val is $ret_value" >> $tmpfile
	echo ""
	if($ret_value == 2) then 
	   sleep $pri_time
	endif
    endif
    @ pri_retry--
    echo "vts_cms-4: pri_retry is $pri_retry" >> $tmpfile
    echo ""
end

echo $ret_value > $logfile
echo $ret_string >> $logfile

if ($no_arg == 5) then
	echo $ret_string
endif
exit $ret_value
