//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / NNI SSCF protocol
//
//File: nsscfstate1_1_1.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 "nsscfstate1_1_1.h"
#include "nsscfprotocol.h"
#include "iface/aaif/aadownprimitives.h"
#include "iface/naalif/naalupprimitives.h"
#include "pf/frame.h"


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

nsscfOutOfService_Idle *nsscfOutOfService_Idle :: _only = 0;

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


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

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


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: naalSTARTreqAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: naalSTARTreqAct(naalSTARTreq *,
                                               pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    nsscf->sendAaESTABLISHreq();
    nsscf->sendMaalREPORTind(LBC_EMPTY, UBC_ALN);
    nsscf->timerT2start();
    nsscf->toNsscfAlignment_OutgoingConnectionPending();
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: naalRETRIEVE_BSNTreqAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: naalRETRIEVE_BSNTreqAct(
    naalRETRIEVE_BSNTreq *,
    pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    pfUlong bsnt = nsscf->getBSNT();
    if (bsnt == NSSCF_NO_BSNT_AVAILABLE)
    {
        nsscf->sendNaalBSNT_NOT_RETRIEVABLEconf();
    }
    else
    {
        nsscf->sendNaalBSNTconf(bsnt);
    }
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: naalRETRIEVAL_REQUEST_AND_FSNCreqAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: naalRETRIEVAL_REQUEST_AND_FSNCreqAct(
    naalRETRIEVAL_REQUEST_AND_FSNCreq *messenger_,
    pfProtocol *protocol_)
{
    ((nsscfProtocol *) protocol_)->sendAaRETRIEVEreq(messenger_->getFSNC());
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: aaESTABLISHindAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: aaESTABLISHindAct(
    aaESTABLISHind *,
    pfProtocol *protocol_)
{
    nsscfProtocol *nsscf = (nsscfProtocol *) protocol_;
    if (nsscf->isLPO() != 0)
    {
        releaseConnection(nsscf, nsscfPOpdu, 0);
    }
    else
    {
        releaseConnection(nsscf, nsscfOOSpdu, 0);
    }
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: aaRETRIEVEindAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: aaRETRIEVEindAct(
    aaRETRIEVEind *messenger_,
    pfProtocol *protocol_)
{
    pfFrame frame = messenger_->getMessageUnit();
    if (frame.length() > NSSCF_PDU_LENGTH)
    {
        ((nsscfProtocol *) protocol_)->sendNaalRETRIEVED_MESSAGESind(frame);
    }
    return;
}


////////////////////////////////////////////////////////////////////
// void nsscfOutOfService_Idle :: aaRETRIEVE_COMPLETEindAct()
// Implemented as in Q.2140 page 46 SDL description

void nsscfOutOfService_Idle :: aaRETRIEVE_COMPLETEindAct(
    aaRETRIEVE_COMPLETEind *,
    pfProtocol *protocol_)
{
    ((nsscfProtocol *) protocol_)->sendNaalRETRIEVAL_COMPLETEind();
    return;
}

