//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / TESTING
//
//File: client.cpp
//
//Version: $Revision: 1.2 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/16 14:11:30 $
//
//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.h>
#include <OB/CORBA.h>
#include "pf/system.h"
#include "pf/debug.h"
#include "pf/naming.h"
#include "mgmt/toveswitch_impl.h"
#include "mgmt/mgmtcommand.h"

void printUsage(char *name_)
{
    cerr << endl;
    cerr << "Usage: " << name_ << " <DPC> <OPC> ";
    cerr << " -ORBnaming `cat /projects/IORs/Naming.ior`" << endl;
    cerr << endl;
    cerr << "- DPC = Destination point code" << endl;
    cerr << "- OPC = Originating point code" << endl;
    exit(0);
}

//
// main function
//

int main(int argc, char *argv[])
{
    debugOutputCout();

    string commandName("mtpTRANSFERreq");

    if (argc < 5)
    {
        printUsage(argv[0]);
    }

    string DPC = argv[1];
    string OPC = argv[2];
    
    // INIT
    pfSystem::init(argc, argv);

    // Construct name for naming component
    string tmpName = OPC;
    tmpName += "/mtptest";

    CosNaming_Name name = pfNaming::parseName(tmpName);
    
    CORBA_Object_ptr tmp = 0;
    toveSwitch_switchInterface_ptr server;
    
    try
    {
        tmp = pfNaming::instance()->resolve(name);
        server = toveSwitch_switchInterface::_narrow(tmp);
    }
    catch (...)
    {
        debugUser("resolve in NS failed");
        exit(1);
    }
    
    mgmtCommand command(commandName);
    command.addParameter("DPC", DPC);
    command.addParameter("OPC", OPC);

    try
    {
	toveSwitch_ParameterList parameterList = command.getList();
        server->execute(commandName.c_str(), parameterList);
    }
    catch (...)
    {
        cerr << "Command >" << commandName << " < failed" << endl;
        exit(1);
    }

    return 0;
}


