#!/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/src/com/ooc/CORBA/ORB.java
then
    top_srcdir=ob
elif test -f src/com/ooc/CORBA/ORB.java
then
    top_srcdir=.
elif test -f ../src/com/ooc/CORBA/ORB.java
then
    top_srcdir=..
elif test -f ../../src/com/ooc/CORBA/ORB.java
then
    top_srcdir=../..
elif test -f ../../../src/com/ooc/CORBA/ORB.java
then
    top_srcdir=../../..
elif test -f ../../../../src/com/ooc/CORBA/ORB.java
then
    top_srcdir=../../../..
else
    $echo "$0: can't find top-level directory"
    exit
fi

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

#
# Set Java CLASSPATH
#
if test "$windows" = "yes"
then
    CLASSPATH="$top_srcdir/demo/repository/classes;$CLASSPATH"
    CLASSPATH="$top_srcdir/lib;$CLASSPATH"
else
    CLASSPATH="$top_srcdir/demo/repository/classes:$CLASSPATH"
    CLASSPATH="$top_srcdir/lib:$CLASSPATH"
fi

export CLASSPATH

#
# 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
if test -n "$OB_CPP_DIST" -a -x $OB_CPP_DIST/ob/bin/irserv${exe}
then
    $OB_CPP_DIST/ob/bin/irserv${exe} --ior Interface.idl > $irref &
else
    irserv${exe} --ior Interface.idl > $irref &
fi
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 server
#
$echo
$echo "Waiting for server to start up... \c"
rm -f $ref
$JAVA repository.Server -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
$JAVA repository.Client

#
# Deactivate everything
#
deactivate
