//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project/CC
//
//File: cctstate.cpp
//
//Version: $Revision: 1.8 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/02 10:38:35 $
//
//Organisation:
//      University of Technology
// 
//Author:
//      Pasi Nummisalo
//
//Description:
//     
//
//Copyright:
//     University of Technology
//     Laboratory of Telecommunications and Multimedia 
//      
//Licence:
//     
//
//History:
//

#include "cctstate.h"
#include "cctstate_exception.h"
#include "cctdp_abandon.h"

ccTstate :: ccTstate(void)
    : ccState()
{
    return;
}

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

// **************************************************************
//
//Functions: Input functions for signalling up interface (from Down)
//

//
//Function: sigRELEASEindAct
//
//Description:
//   This function is called when a disconnect indication is
//   received from the terminating party (called party).
//   Common release handler for T-states.
//

void ccTstate :: sigRELEASEindAct(sigRELEASEind *release_,
                                  pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccDSS2T,ccCCT,"Base","RELEASEind");
#endif
    ccProtocol *ccprotocol = entryAction(protocol_);
    ccprotocol->saveData("releaseInd", release_);    
    exitAction(protocol_, ccTstateException::instance());
    return;
}

//
//Function: sigRELEASEconfAct
//
//Description: common RELEASEconf handler
//   This function is called when a RELEASEconf (RELEASE COMPLETE pdu)
//   primitive is received from the terminating party (called party).
//   Common release handler for T-states.
//

void ccTstate :: sigRELEASEconfAct(sigRELEASEconf *release_,
                                   pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccDSS2T,ccCCT,"Base","RELEASEconf");
#endif
    ccProtocol *ccprotocol = entryAction(protocol_);     
    ccprotocol->saveData("releaseConf", release_); 
    // ++TODO++ is this correct state?
    release_->print();
    exitAction(protocol_, ccTstateException::instance());
    return;
}


// **************************************************************
//
//Functions: Input functions for messages from O-side
//


//
//Function: ccRELEASEpduAct
//
//Description: common RELEASE handler
//    This function is called when a disconnect indication is
//    received from the originating party (calling party).
//    Common release handler for T-states.
//

void ccTstate :: ccRELEASEpduAct(ccRELEASEpdu *release_,
                                 ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCC,ccCCT,"Base","RELEASE");
#endif
    protocol_->saveData("release", release_);
    exitAction(protocol_, ccTdpAbandon::instance());
    return;
}

//
//Function: ccRELEASE_ACTIVEpduAct
//
//Description: 
//    Unexpected RELEASE_ACTIVE message form O side.
//    Release connection.
//

void ccTstate :: ccRELEASE_ACTIVEpduAct(ccRELEASE_ACTIVEpdu *release_,
                                        ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCC,ccCCT,"Base","RELEASE_ACTIVE");
#endif
    protocol_->saveData("releaseInd", release_);
    exitAction(protocol_, ccTdpAbandon::instance());

    return;
}

//
//Function: ccSETUPpduAct
//
//Description: 
//    Unexpected SETUP message form O side.
//    Release connection.
//

void ccTstate :: ccSETUPpduAct(ccSETUPpdu *,
                               ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCC,ccCCT,"Base","SETUP");
#endif
//++TODO++ cause value
    int cause = 0;

    pfStorage storage = pfStorage();
    storage.defineStorage(sigCauseStr);
    storage[sigCauseStr].defineInteger(sigCause_ValueStr);
    storage[sigCauseStr].setInteger(sigCause_ValueStr, cause);
    
    protocol_->setData("releaseInd", storage);

    exitAction(protocol_, ccTdpAbandon::instance());
    return;
}

//
//Function: ccALERTINGpduAct
//
//Description: 
//    Unexpected ALERTING message form O side.
//    Release connection.

void ccTstate :: ccALERTINGpduAct(ccALERTINGpdu *,
                                  ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCC,ccCCT,"Base","ALERTING");
#endif
//++TODO++ cause value
    int cause = 0;

    pfStorage storage = pfStorage();
    storage.defineStorage(sigCauseStr);
    storage[sigCauseStr].defineInteger(sigCause_ValueStr);
    storage[sigCauseStr].setInteger(sigCause_ValueStr, cause);
    
    protocol_->setData("releaseInd", storage);
    
    exitAction(protocol_, ccTdpAbandon::instance());
    return;
}

