//Editor-Info: -*- C++ -*-
//
//Subject: TOVE/CC testing
//
//File: cctest.cpp 
//
//Version: $Revision: 1.20 $
//
//Date: $Date: 1998/12/16 14:08:12 $
//
//Organisation:
//      University of Technology
// 
//Author:
//      Pasi Nummisalo
//
//Description:
//      Main for the switch controller signalling binary.
//
//Copyright:
//     University of Technology
//     Laboratory of Telecommunications and Multimedia 
//      
//Licence:
//     
//
//History:
//

#include "protocol/cc/ccprotocol.h"
#include "protocol/cc/cccrossconnectormux.h"

#include "protocol/uni/unidefs.h"
#include "protocol/uni/unistrings.h"
#include "protocol/uni/unipdu.h"
#include "protocol/uni/unicoordprotocol.h"
#include "protocol/uni/unitransporter.h"
#include "protocol/uni/uniprotocol.h"
#include "protocol/uni/unimode.h"
#include "iface/sigif/sigdownprimitives.h"
#include "pf/frame.h"
#include "pf/messenge.h"
#include "pf/system.h"
#include "pf/mux.h"
#include "pf/exception.h"
#include "pf/factory.h"

#include "protocol/cc/ccdebug.h"
#include "mgmt/toveswitch_impl.h"
#include "mgmt/toveswitch.h"
#include "sw/switchbuilder.h"

void initSwitch(pfBoolean traceOn_);
void initLink(pfId linkId_, string hostName_, int localPort_, int remotePort_,
              pfBoolean traceOn_);

string hostName;
int localPort;
int remotePort;
string ThostName;
int TlocalPort;
int TremotePort;
pfBoolean useIN = 0;

string name;

void usage(void)
{
    cerr << "Usage: " << endl;
    cerr << name << " [-ORBnaming `cat file.ior`]"
         << " host OlocalPort OremotePort Thost TlocalPort TremotePort"
         << endl;
    cerr << "Example (host iines):" << endl;
    cerr << name << " -ORBnaming `cat /projects/IORs/Naming.ior`"
         << " hessu 4444 5555 hessu 6666 7777"
         << endl;
    
    exit(1);
}

main(int argc, char **argv)
{
    try
    {
        name = argv[0];

        if (argc < 7)
        {
            usage();
        }
        
        pfSystem::init(argc, argv);

        if (argc == 9)
        {
            useIN = 1;
            // Main UI server
            toveSwitch_switchInterface_var server = new toveSwitch_impl;
        }
        else
        {
            useIN = 0;
            toveSwitchBuilder::instance()->setCORBAnotInUse();
        }

        
        {
            hostName = argv[1];
            localPort = atoi(argv[2]);
            remotePort = atoi(argv[3]);
            ThostName = argv[4];
            TlocalPort = atoi(argv[5]);
            TremotePort = atoi(argv[6]);

            int trace = 0;
            
            //toveSwitchBuilder::instance()->setGSMPnotInUse();
            
            
            toveSwitchBuilder::instance()->initSwitch(0,86,trace);

            int linkIdBase = 1;
            
            toveSwitchBuilder::instance()->createUDPlink(linkIdBase,
                                                         hostName,
                                                         localPort,
                                                         remotePort,
                                                         trace);
            
            toveSwitchBuilder::instance()->createUDPlink(linkIdBase+1,
                                                         ThostName,
                                                         TlocalPort,
                                                         TremotePort,
                                                         trace);
            
           
        }

        //
        // Run implementation (DON'T call impl_is_ready!)
        //	
        pfSystem::instance()->run();       
    }
    catch (pfException &e)
    {
        e.printInfo();
    }
    catch (sfException &e)
    {
        e.printInfo();
    }
    
    return 0;
}

