//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / testing
//
//File: client.cpp
//
//Version: $Revision: 1.5 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/16 14:09:13 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author: Timo Pärnänen
//
//
//Description:
//
//
//Copyright:
//
//
//Licence:
//
//
//History: 

#include <typeinfo>
#include <iostream.h>
#include <string>

#include "pf/debug.h"
#include "pf/system.h"
#include "pf/naming.h"

#include "ORBacustest.h"

//
//Function: main
//

int main(int argc, char *argv[])
{
    if (argc != 4)
    {
        cout << "\nUSAGE: " << argv[0] << " <interface> -ORBnaming `cat /PATH/FILE.ior`" << endl;
        cout << "e.g. " << argv[0] << " s1 -ORBnaming `cat /projects/IORs/Naming.ior`\n" 
             << endl;
        exit(0);
    }
    pfSystem::init(argc, argv);

    string nameString = "ORBacustest/";
    nameString += argv[1];

    CosNaming_Name name =
	pfNaming::instance()->parseName(nameString);

    ORBacustest_var server;
    try
    {
        CORBA_Object_ptr obj = pfNaming::instance()->resolve(name);
        server = ORBacustest::_narrow(obj);    
    }
    catch (...)
    {
        debugUser("Resolve object reference failed");
        exit(-1);
    }

    try
    {
        int counter = 0;
        char c;
        cout << "x exits and t call test method from server" << endl;
        while (1)
        {
            cout << "input >";
            cin >> c;
            cout << endl;

            if (c == 't')
            {
                for (int i=0; i<200; i++)
                {
                    ++counter;
                    server->test();
                }
                debugPfUlong("counter", counter);
            }
            if (c == 'x')
            {
                break;
            }
        }
    }
#ifdef __GNUG__
    catch(CORBA_COMM_FAILURE& ex)
#else
    catch(CORBA_SystemException& ex)
#endif
    {
        OBPrintException(ex);
        return 1;
    }
    return 0;
}
