//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / TESTING
//
//File: switchtestmain.cpp
//
//Version: $Revision: 1.3 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/07/09 13:14:02 $
//
//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 "sf/orbscheduler.h"
#include "pf/system.h"
#include "pf/debug.h"

#include "switchtestimpl.h"


void printUsage(char *name_)
{
    cerr << endl;
    cerr << "Usage: " << name_ << " [p PORT] [c POINT CODE] ";
    cerr << " -ORBnaming `cat /projects/IORs/Naming.ior`" << endl;
    cerr << endl;
    cerr << "- [p PORT]  Port number" << endl;
    cerr << "- [c POINT CODE]  Point code value of the switch" << endl;
    cerr << endl;
    cerr << "Default values: PORT = 0, POINT CODE = 10" << endl;
    exit(0);
}

//
// main function
//

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

    string port = "0";
    string pointCode = "10";
    int count = 1;

    while (count < argc)
    {
        switch (*argv[count++])
        {
            case 'p':
                port = argv[count++];
                break;
            case 'c':
                pointCode = argv[count++];
                break;
            case '-':
                if (strcmp(argv[--count], "-ORBnaming") != 0)
                {
                    printUsage(argv[0]);
                }
                else
                {
                    count += 2;
                }
                break;
            case 'h':
            default :
                printUsage(argv[0]);
                break;
        }
    }

    try
    {
        //
        // pfSystem must be instantiated with the sfORBScheduler instance
        // as the parameter, otherwise it will use sfFIFOScheduler as its
        // default scheduler.
        //
        sfScheduler *scheduler = sfORBScheduler::instance();
        pfSystem::instance(scheduler);
        
        sfORBScheduler::initORB(argc, argv);
    }
    catch (...)
    {
        cout << "ORB initialization failed !" << endl;
        exit(1);
    }


    switchTestImpl switchimpl(pointCode, port);

    cout << "Switch test server started" << endl;
    pfSystem::instance()->run();

    return 0;
}


