#######################################################################
#
# waitForAttrValue
#
# Description:
#       Wait for an attrbute to contain a value before returning.
#       A timeout (seconds) must be specified.  If it doesn't occur
#       within the timeout period, we exit with code 1.
#       Otherwise, we exit with code 0.
#
# Input positional parameters:
#     $1. the class of the object
#     $2. The attribute you are searching for
#     $3. The target i.e. spooler or supervisor name
#     $4. The answer that you expect
#
# Author:
#       Alan Hlava
#
#######################################################################
if [ $# -ne 5 ]
then
        echo "usage: $0 <objclass> <attr> <name> <value> <timeout>"
        exit 1
fi

SLEEP=5
TIME=$5

(( loops = TIME / SLEEP ))

if [[ $loops -eq 0 ]]
then
   loops=1
fi

while [[ $loops -gt 0 ]]
do
	ANS=`$PD_PATH/pdls -c $1 -r $2 $3`
	# check the return of the pdls
	if [ $? != 0 ]
	then
		reportError "$0: pdls failure"
		exit 1
	fi
	LOC_ANS=`echo $ANS | sed -e 's/.* = //'`

	# test to see if pdls returned what we expected - return 0 if yes
	# the value from the command line allowing pattern matching.
	case "${LOC_ANS}" in
		$4)
			# success - pdls result matched test pattern
			exit 0;;
	esac

	sleep $SLEEP
	(( loops = loops - 1 ))
done 2> /dev/null

exit 1
#
#    Version      Date     Time    Owner   Comment
# ------------- -------- -------- -------- ----------------------------
# V             06/28/94 16:49:54 nrjbehrs Creation
# V1.2          06/29/94 11:50:56 nrjbehrs made timeout accurate
# V1.3          06/29/94 16:58:09 nrjbehrs add sleep 5
# V1.4          08/03/94 11:18:17 nrjbehrs rework pause
