#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 in("ior.dat");
	char ior[MAXBUF];
	in.getline(ior, MAXBUF);
	in.close();

	// convert the stringified IOR to an object reference
	CORBA::Object_var object = orb->string_to_object(ior);

	// Locate object. Give the full POA name and the servant ID.
	Math_var math = Math::_narrow(object);

	//
	// Use the object
	//

	// Add
	CORBA::Double x = math->add(2.4, 8.4);

	// sub
	CORBA::Double y = math->sub(2.4, 8.4);

	// Print out the result
	cout << "2.4 + 8.4 = " << x << ", 2.4 - 8.4 = " << y << endl;

    } catch(const CORBA::Exception& e) {
	cerr << e << endl;
	return 1;
    }

    return 0;
}
