//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / TESTING
//
//File: testconfig.cpp
//
//Version: $Revision: 1.9 $
//
//State: $State: Exp $
//
//Date: $Date: 1999/03/02 12:21:44 $
//
//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_ << " <pointCode> <portNumber>";
    cerr << " -ORBnaming `cat /work/Naming/Naming.ior`" << endl;
    cerr << endl;
    exit(0);
}

//
// main function
//

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

    if (argc != 5 || *argv[1] == 'h')
    {
        printUsage(argv[0]);
    }

    pfSystem::init(argc, argv);

    // Construct name for naming component
    string tmpName = argv[1];
    tmpName += "/config";

    CosNaming_Name name = pfNaming::parseName(tmpName);
    
    CORBA_Object_ptr tmp = 0;
    toveSwitch_switchInterface_ptr server;

    string port(argv[2]);

    try
    {
        tmp = pfNaming::instance()->resolve(name);
        server = toveSwitch_switchInterface::_narrow(tmp);
    }
    catch (...)
    {
        debugUser("resolve in NS failed");
        exit(1);
    }

/****
    mgmtCommand command1("port");
    command1.addParameter("port", port);
    command1.addParameter("type", "FSR155");
 
    try
    {
        toveSwitch_ParameterList parameterList1 = command1.getList();
        server->execute(command1.getCommandName().c_str(),  parameterList1);
    }
    catch (...)
    {
        debugUser("add port failed");
        exit(0);
    }
****/

    mgmtCommand command2("addLink");
    command2.addParameter("port", port);
    command2.addParameter("type", "UNI");
    command2.addParameter("link", "1");
    
    try
    {
	toveSwitch_ParameterList parameterList2 = command2.getList();
        server->execute(command2.getCommandName().c_str(), parameterList2);
    }
    catch (...)
    {
        debugUser("addlink failed");
        exit(0);
    }    
    return 0;
}


