//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project/CC
//
//File: ccostate.cpp
//
//Version: $Revision: 1.14 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/12/16 16:50:57 $
//
//Organisation:
//      University of Technology
// 
//Author:
//      Pasi Nummisalo
//
//Description:
//     Common input handling for O side states
//
//Copyright:
//      Copyright 1999 Helsinki University of Technology
//      ALL RIGHTS RESERVED BETWEEN JANUARY 1996 AND JUNE 1999.
//      
//Licence:
//     
//
//History:
//

#include "ccostate.h"
#include "ccodp_abandon.h"
#include "ccostate_exception.h"
#include "protocol/uni/unidefs.h"
#include "pf/debug.h"
#include "pf/error.h"

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

ccOstate :: ~ccOstate(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 originating party (calling party).
//   Common release handler for O-states.
//

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

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

void ccOstate :: sigRELEASEconfAct(sigRELEASEconf *release_,
                                   pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccDSS2,ccCC,"Base","RELEASEconf");
#endif
    ccProtocol *ccprotocol = entryAction(protocol_);     
    ccprotocol->saveData("releaseConf", release_); 
    exitAction(ccprotocol, ccOdpAbandon::instance());
    return;
}

// **************************************************************
//
//Functions: Input functions for messages from T side
//


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

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

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

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

    return;
}

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

void ccOstate :: ccSETUPpduAct(ccSETUPpdu *,
                               ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCCT,ccCC,"Base","SETUP");
#endif
    int cause = uniCauseValue_IncompatibleDestination;

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

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

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

void ccOstate :: ccALERTINGpduAct(ccALERTINGpdu *,
                                  ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCCT,ccCC,"Base","ALERTING");
#endif

    int cause = uniCauseValue_IncompatibleDestination;

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

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



// **************************************************************
//
//Functions: Input functions for fabric messages
//

//
//Function: swSuccessMessageAct
//
//Description:
//   Must be implemented in state select Route, this
//   method presents an error case.

void ccOstate :: swSuccessMessageAct(swSuccessMessage *messenger_, 
                                     pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccVE,ccCC,"Base","swSuccessMessage");
    debugUser("**Unexpected message from FCF**");
#endif
    THROW_CALL_REJECTED

    return;
}

//
//Function: swFailureMessageAct
//
//Description:
//   Must be implemented in state select Route, this
//   method presents an error case.

void ccOstate :: swFailureMessageAct(swFailureMessage *messenger_, 
                                     pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccVE,ccCC,"Base","swFailureMessage");
    debugUser("**Unexpected message from FCF**");
#endif
    THROW_CALL_REJECTED

    return;
} 
