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

#include <OB/CORBA.h>
#include <OB/Util.h>

#include <Hello_skel_tie.h>
#include <Hello_impl_tie.h>

#include <stdlib.h>
#include <errno.h>

#ifdef HAVE_FSTREAM
#   include <fstream>
#else
#   include <fstream.h>
#endif

#ifndef HAVE_NO_EXPLICIT_TEMPLATES
template class Hello_skel_tie< Hello_impl_tie >;
#else
#ifdef HAVE_PRAGMA_DEFINE
#pragma define(Hello_skel_tie< Hello_impl_tie >)
#endif
#endif

int
main(int argc, char* argv[], char*[])
{
    try
    {
	//
	// Create ORB and BOA
	//
	CORBA_ORB_var orb = CORBA_ORB_init(argc, argv);
	CORBA_BOA_var boa = orb -> BOA_init(argc, argv);
	
	//
	// Create implementation object
	//
	Hello_var p = new Hello_skel_tie< Hello_impl_tie >(new Hello_impl_tie);
	
	//
	// Save reference
	//
	CORBA_String_var s = orb -> object_to_string(p);
	
	const char* refFile = "Hello.ref";
	ofstream out(refFile);
	if(out.fail())
	{
	    cerr << argv[0] << ": can't open `" << refFile << "': "
		 << strerror(errno) << endl;
	    return 1;
	}
	
	out << s << endl;
	out.close();
	
	//
	// Run implementation
	//
	boa -> impl_is_ready(CORBA_ImplementationDef::_nil());
    }
    catch(CORBA_SystemException& ex)
    {
	OBPrintException(ex);
	return 1;
    }

    return 0;
}

