#include "Math_c.hh"
#include <fstream.h>

const int MAXBUF = 1024;

int main(int argc, char* const* argv) 
{
    try {

	//
	// The following is not application specific
	//

	// Initialize the ORB.
	CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

	//
	// Get access to object
	//

	// Read object reference from file
	ifstream iin("ior.dat");
	char ior[MAXBUF];
	iin.getline(ior, MAXBUF);
	iin.close();

	// convert the stringified IOR to an object reference
	CORBA::Object_var iobject = orb->string_to_object(ior);

	// Locate object. Give the full POA name and the servant ID.
	Math::Bst_var bst = Math::Bst::_narrow(iobject);

	//
	// Use the objects
	//

	// Get math object ref
	Math::Std_var m = bst->getit(2);
	CORBA::Long x = m->inc(4);
	CORBA::Long y = m->inc(6);
	cout << "2: inc(4) = " << x << ", inc(6) = " << y << endl;

	// Get math object ref seq
	Math::Bst::StdSeq_var list = bst->getthem(5);
	for (CORBA::ULong i = 0; i < list->length(); i++) {
	    x = list[i]->inc(0);
	    y = list[i]->inc(10);
	    cout << i << ": inc(0) = " << x << ", inc(10) = " << y << endl;
	}

    } catch(const CORBA::Exception& e) {
	cerr << e << endl;
	return 1;
    }

    return 0;
}
