//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / NNI SSCF protocol
//
//File: nsscfstate2_1_2.cpp
//
//Version: $Revision: 1.8 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/05/26 14:29:50 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications and Multimedia
//
//Author:
//      Juhana Räsänen
//
//Description:
//      See corresponding header file
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//
//Licence:
//
//
//History: 


#include <assert.h>
#include "nsscfstate2_1_2.h"
#include "nsscfprotocol.h"
#include "iface/aaif/aaupprimitives.h"
#include "iface/naalif/naaldownprimitives.h"
#include "pf/frame.h"


//
// Variable: nsscfAlignment_Idle :: _only
// Function: nsscfAlignment_Idle :: instance()
//
// Description:
//     Implements the singleton pattern used for actual states
//

nsscfAlignment_Idle *nsscfAlignment_Idle :: _only = 0;

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


nsscfAlignment_Idle :: nsscfAlignment_Idle(void)
    : nsscfState()
{
    return;
}

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


////////////////////////////////////////////////////////////////////
// void nsscfAlignment_Idle :: naalSTOPreqAct()
// Implemented as in Q.2140 page 50 SDL description

void nsscfAlignment_Idle :: naalSTOPreqAct(naalSTOPreq *,
                                           pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    nsscf->sendMaalREPORTind(LBC_EMPTY, UBC_OOS);
    nsscf->timerT1stop();
    nsscf->timerT2stop();
    nsscf->setUPSnormal();
    nsscf->toNsscfOutOfService_Idle();
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfAlignment_Idle :: aaESTABLISHindAct()
// Implemented as in Q.2140 page 50 SDL description

void nsscfAlignment_Idle :: aaESTABLISHindAct(aaESTABLISHind *messenger_,
                                              pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    nsscfPDU pdu = nsscf->decodePDU(messenger_->getSSCOP_UU());
    if ((pdu != nsscfEMpdu) && (pdu != nsscfNMpdu))
    {
        releaseConnection(nsscf, nsscfPEpdu, 0);
        nsscf->sendMaalREPORTind(LBC_LR, UBC_EMPTY, R_PE);
    }
    else
    {
        nsscf->sendAaESTABLISHresp();
        nsscf->sendMaalPROVINGind();
        nsscf->timerT1stop();
        nsscf->setC1(pdu);
        nsscf->setNotInService();
        nsscf->timerT3start();
        nsscf->toNsscfProving_DataTransferReady();
    }
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfAlignment_Idle :: maalRELEASEreqAct()
// Implemented as in Q.2140 page 51 SDL description

void nsscfAlignment_Idle :: maalRELEASEreqAct(maalRELEASEreq *,
                                              pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    nsscf->sendNaalOUT_OF_SERVICEind();
    nsscf->timerT1stop();
    nsscf->timerT2stop();
    nsscf->setUPSnormal();
    nsscf->toNsscfOutOfService_Idle();
    return;
}



////////////////////////////////////////////////////////////////////
// void nsscfAlignment_Idle :: nsscfT1timeoutAct()
// Implemented as in Q.2140 page 51 SDL description

void nsscfAlignment_Idle :: nsscfT1timeoutAct(nsscfProtocol *protocol_)
{
    protocol_->sendAaESTABLISHreq();
    protocol_->toNsscfAlignment_OutgoingConnectionPending();
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfAlignment_Idle :: nsscfT2timeoutAct()
// Implemented as in Q.2140 page 51 SDL description

void nsscfAlignment_Idle :: nsscfT2timeoutAct(nsscfProtocol *protocol_)
{
    protocol_->sendNaalOUT_OF_SERVICEind();
    protocol_->sendMaalREPORTind(LBC_LR, UBC_OOS, R_ANS);
    protocol_->timerT1stop();
    protocol_->setUPSnormal();
    protocol_->toNsscfOutOfService_Idle();
    return;
}

