//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project
//
//File: unirsnprotocol.cpp
//
//Version: $Revision: 1.12 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/14 06:56:32 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications Software and Multimedia
//
//Author:
//      Jari Pusa
//
//Description:
//
//
//Copyright:
//
//
//Licence:
//
//
//History: 

#include "unirsnprotocol.h"

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

#include "unidefs.h"
#include "unistrings.h"
#include "unirsnstate.h"
#include "unitimeouts.h"
#include "unipdu.h"
#include "uniprimitives.h"

pfConduit uniRSNProtocol :: create(void)
{
    uniRSNProtocol *protocol = new uniRSNProtocol;
    pfConduit proxy(protocol);
    return proxy;
}
    
uniRSNProtocol :: uniRSNProtocol(void)
    : pfProtocol(),
      pfStorage()
{
    defineTimer(uniT316Str, uniT316timeout::create(), uniT316expire);
    defineStorage(uniRSNConnectIDsStr);
    defineStorage(uniRSNSavedRESTARTStr);
    defineInteger(uniRSNTimeoutsStr);
    
    changeToNullState();
    return;
}

uniRSNProtocol :: uniRSNProtocol(const uniRSNProtocol &other_)
    : pfProtocol(other_)
{    
    changeToNullState();
    return;
}

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

pfProtocol *uniRSNProtocol :: cloneImplementation(void) const
{
    uniRSNProtocol *protocol = new uniRSNProtocol;
    return protocol;
}

//
// Method: sendRESTARTpdu
//
// Description:
//     This method with a parameter `storage_' is meant to be
//     called first. It saves the given RESTART Request.
//     Then, if there was no response, the unparamerized
//     shall be called. sendRESETconf uses the same saved
//     information.
//

void uniRSNProtocol :: sendRESTARTpdu(void)
{
    sendRESTARTpdu((*this)[uniRSNSavedRESTARTStr]);
    return;
}

void uniRSNProtocol :: sendRESTARTpdu(pfStorage &storage_)
{
    uniRESTARTpdu *pdu = uniRESTARTpdu::create();
    setStorage(uniRSNSavedRESTARTStr, storage_);
    pdu->copyIfPresent(storage_, uniRestartIndicatorStr);
    pdu->copyIfPresent(storage_, uniConnectionIdentifierStr);
    toA(pdu);
    return;
}

//
// Method: sendRESET_ERRORind
//
// Description:
//

void uniRSNProtocol :: sendRESET_ERRORind(pfUlong reason_, pfUlong callState_)
{
    uniRESET_ERRORind *primitive =
        uniRESET_ERRORind::create(reason_, callState_);
    toA(primitive);
    return;
}

//
// Method: sendRESETconf
//
// Description:
//     Sends a RESETconf primitive into CoOrd. All necessary information
//     for this primitive is got from saved RESTARTpdu. This means that
//     sendRESTART method must be called first.
//

void uniRSNProtocol :: sendRESETconf(void)
{
    uniRESETconf *primitive = uniRESETconf::create();
    pfStorage &pdu = (*this)[uniRSNSavedRESTARTStr];
    primitive->copyIfPresent(pdu, uniRestartIndicatorStr);
    primitive->copyIfPresent(pdu, uniConnectionIdentifierStr);
    toA(primitive);
    return;
}

//
// Method: changeToXState
//
// Description:
//     State changes.
//

void uniRSNProtocol :: changeToNullState(void)
{
    changeState(uniRSNNullState::instance());
    return;
}

void uniRSNProtocol :: changeToRestartRequestState(void)
{
    changeState(uniRSNRestartRequestState::instance());
    return;
}

