//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project
//
//File: gsmptest.cpp
//
//Version: $Revision: 1.7 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/03 15:05:03 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Harri Sunila
//
//Description:
//      A simple program to test GSMP. Creates separate CPCS-adapter,
//      Adjcency Protocol and GSMP Protocol conduits and interconnects them.
//      Starts the Adjacency Protocol to send SYN message on specific VPI/VCI
//      pair in specific port. Creates also a GSMP Factory.
//
//Copyright:
//
//
//Licence:
//
//
//History: 

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

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

#include "pf/exception.h"
#include "sf/exception.h"
#include "testconfigcontrol.h"


void usage(const char *name_)
{
    cerr << "Usage: " << name_
         << " [t] [p] [v VCI]" << endl;
    cerr << "       t: Trace on" << endl;
    cerr << "       p: Port" << endl;
    cerr << "       v: Use given VCI" << endl;
    cerr << endl;
    exit(0);
    return;
}

int main(int argc, char *argv[])
{
    if (argc < 1)
    {
        usage(argv[0]);
    }
	   
    pfSystem::init(argc, argv);

    int count = 1;

    int port = 0;
    int vci = 15;
    
    while (count < argc)
    {
        switch (*argv[count])
	{
	    case 't':
              debugOutputCout();
	      break;
            case 'p':
              count++;
              if (count == argc)
              {
                  usage(argv[0]);
              }
              port = atoi(argv[count]);
              break;

	    case 'v':
	      count++;
	      if (count == argc)
	      {
		  usage(argv[0]);
	      }
	      vci = atoi(argv[count]);
	      break;
	    default:
	      usage(argv[0]);
	      break;
	}
	count++;
    }
    
    try
    {
        // Setup GSMP Protocol
        testConfigControl config;
        cout << "Setting up GSMP Protocol" << endl;
	config.setupGSMP(port, vci);

        config.sendSwitchConfigurationRequest();
        config.sendAllPortsConfigurationRequest();
	
	// Run the system
	cout << "running..." << endl << endl;
	pfSystem::instance()->run();
    }
    catch (sfException &exception)
    {
        exception.printInfo();
    }
    catch (pfException &exception)
    {
        exception.printInfo();
    }
    return 0;
}


