//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / 
//
//File: 
//
//Version: $Revision: 1.9 $
//
//State: $State: Exp $
//
//Date: $Date: 1999/03/08 07:45:01 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Sami Raatikainen
//
//Description:
//
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 

#include "testclient.h"
#include <iostream.h>
#include "iface/mtpif/mtpdownprimitives.h"
#include "iface/mtpif/mtpupprimitives.h"
#include "testing/pducoder/bisupframecoding.h"

#include "pf/debug.h"

//----------------------------------------------------------------------

testClient :: testClient(void)
    : pfProtocol(),
      bisupClientInterface_skel(),
      _count(100),
      _counter(0)
{
    changeState(testClientState::instance());
    return;
}

testClient :: ~testClient(void)
{
    return;
}


/*
void testClient :: start(const msgSequence& msgList_)
{
    while (msgList_.length() > 0)
        _msgList.push_back(msgList_[0]);
    cout << "here working";
    sendNextFrame();
    return;
}
*/


void testClient :: start(CORBA_Long numberOfMessages)
{
    _count = numberOfMessages;
    sendNextFrame();
    return;
}


void testClient :: sendNextFrame(void)
{
    pfFrame testFrame;
    pfBoolean test = 1;
    
    _counter++;
    if (_counter <= _count)
    {
        mtpTRANSFERreq *messenger = new mtpTRANSFERreq;
        messenger->setDestinationPointCode(10);
        messenger->setOriginatingPointCode(20);
        messenger->setServiceInformationOctet(9);
        messenger->setSignallingLinkSelection(30);
        switch(_counter)
        {
            case 1:
                cout << "\nSending IAM..." << endl;
                makeIAM(testFrame);
                printFrame(testFrame);
                break;
            case 2:
                cout << "\nSending IAA..." << endl;
                makeIAA(testFrame);
                printFrame(testFrame);
                break;
            case 3:
                cout << "\nSending IAR..." << endl;
                makeIAR(testFrame);
                printFrame(testFrame);
                break;
            case 4:
                cout << "\nSending ANM..." << endl;
                makeANM(testFrame);
                printFrame(testFrame);
                break;
            case 5:
                cout << "\nSending REL..." << endl;
                makeREL(testFrame);
                printFrame(testFrame);
                break;
            case 6:
                cout << "\nSending RLC..." << endl;
                makeRLC(testFrame);
                printFrame(testFrame);
                break;
            default:
                cout << "\nAll messages sent... end of test!" << endl;
                test = 0;
        }
        messenger->setSignallingInformation(testFrame);
        if (test)
        {
            cout << "toA..." << endl;
            toA(messenger);
        }
    }
    return;
}

void testClient :: printFrame(pfFrame &frame_)
{
    debugOutputCout();
    debugFrame("Frame: ", frame_);
    debugOutputNull();
    return;
}

//----------------------------------------------------------------------

testClientState *testClientState :: _only = 0;

testClientState *testClientState :: instance(void)
{    
    if (_only == 0)
    {
        _only = new testClientState;
        assert(_only != 0);
    }
    return _only;
}

testClientState :: testClientState(void)
    : pfState(),
      mtpUpInputs()
{
    return;
}

testClientState :: ~testClientState(void)
{
    _only = 0;
    return;
}

void testClientState :: mtpTRANSFERindAct(mtpTRANSFERind *messenger_,
                                          pfProtocol *protocol_)
{
    cout << endl;
    cout << "--  TESTCLIENT, received mtpTRANSFERind: " << endl;

    pfFrame frame = messenger_->getSignallingInformation();
    
    ((testClient*)protocol_)->printFrame(frame);
    ((testClient*)protocol_)->sendNextFrame();
    return;
}
