#!/bin/sh
# **********************************************************************
#
# Copyright (c) 1999
# Object Oriented Concepts, Inc.
# Billerica, MA, USA
#
# All Rights Reserved
#
# **********************************************************************

#
# Try to find top-level directory
#
if test -f ob/include/OB/CORBA.h
then
    top_srcdir=ob
elif test -f include/OB/CORBA.h
then
    top_srcdir=.
elif test -f ../include/OB/CORBA.h
then
    top_srcdir=..
elif test -f ../../include/OB/CORBA.h
then
    top_srcdir=../..
elif test -f ../../../include/OB/CORBA.h
then
    top_srcdir=../../..
elif test -f ../../../../include/OB/CORBA.h
then
    top_srcdir=../../../..
else
    $echo "$0: can't find top-level directory"
    exit
fi

#
# Run standard init script
#
. $top_srcdir/../config/sh.init

#
# The name of reference file
#
irref=Repository.ref
ref=Interface.ref

#
# Function to deactivate the interface repository and test server
#
repid=0
srvid=0
deactivate()
{
    if test $repid -ne 0
    then
	kill $repid
    fi

    if test $srvid -ne 0
    then
        kill $srvid
    fi

    exit
}
trap deactivate 1 2 3 4 5 6 7 8 10 12 13 14 15

#
# Start interface repository
#
$echo
$echo "Waiting for interface repository to start up... \c"
rm -f $irref
$top_srcdir/bin/irserv${exe} --ior Interface.idl > $irref &
repid=$!
count=0
while test ! -s $irref -a $count -lt 6
do
    sleep 1
    count=`expr $count + 1`
done
if test ! -s $irref
then
    $echo "Failed!"
    $echo "(Interface repository was not started)"
    exit
else
    $echo "OK!"
fi

#
# Start test server
#
$echo
$echo "Waiting for server to start up... \c"
rm -f $ref
./server${exe} -ORBservice InterfaceRepository `cat $irref` &
srvid=$!
count=0
while test ! -s $ref -a $count -lt 6
do
    sleep 1
    count=`expr $count + 1`
done
if test ! -s $ref
then
    $echo "Failed!"
    $echo "(Server was not started)"
    exit
else
    $echo "OK!"
fi

#
# Start test client
#
# Setting the interface repository is not necessary, since the client
# asks the server for this information,
#
$echo
$top_srcdir/demo/repository/client${exe}

#
# Deactivate everything
#
deactivate
