#!/bin/sh

MICORC=/dev/null
export MICORC

# run Naming Service

echo "Starting Naming Service ..."

rm -f nsd.ior
nsd --ior nsd.ior &
nsd_pid=$!

trap "kill $nsd_pid > /dev/null 2> /dev/null" 0

# wait for Naming Service to start

for i in 0 1 2 3 4 5 6 7 8 9 ; do
	if test -r nsd.ior ; then break ; else sleep 1 ; fi
done

# start Server Activator

echo "Starting MicoCCM Daemon ..."

rm -f ccmd.ior
mico-ccmd --ior ccmd.ior &
server_pid=$!

trap "kill $nsd_pid $server_pid > /dev/null 2> /dev/null" 0

# wait for Server Activator to start

for i in 0 1 2 3 4 5 6 7 8 9 ; do
	if test -r ccmd.ior ; then break ; else sleep 1 ; fi
done

echo "Loading HelloWorld component ..."

ccmload -ORBInitRef NameService=file://`pwd`/nsd.ior --ccmd file://`pwd`/ccmd.ior --ns HelloHome -v HelloHome ./hello.so

# run Client

echo "Running Client ..."

./client -ORBInitRef NameService=file://`pwd`/nsd.ior

