//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project/CC
//
//File: ccostate_null.cpp
//
//Version: $Revision: 1.18 $
//
//State: $State: Exp $
//
//Date: $Date: 1999/03/05 16:31:13 $
//
//Organisation:
//      University of Technology
// 
//Author:
//      Pasi Nummisalo
//
//Description:
//     See header.
//
//Copyright:
//     University of Technology
//     Laboratory of Telecommunications and Multimedia 
//      
//Licence:
//     
//
//History:
//

#include "protocol/cc/ccprotocol.h"
#include "ccodp_attempt.h"
#include "iface/sigif/sigupprimitives.h"
#include "ccostate_null.h"
#include "pf/error.h"

ccOstateNull *ccOstateNull :: _only = 0;

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

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

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

//
//Function: proceed
//
//Description:  
//   Disconnect and clearing of a previous call.
//
//

void ccOstateNull :: proceed(ccProtocol *protocol_)
{
#if CC_DEBUG
traceState(ccCC,"Null");
#endif
    
    // Fabric stuff
    if (protocol_->isDataConnectionActive() != 0)
    {
#if CC_DEBUG
traceSend(ccCC,ccVE,"Null","disconnect");
#endif
        protocol_->disconnect();
        // Release signalling
        releaseAction(protocol_);
    }
    else
    {
        // Release signalling
        releaseAction(protocol_);
    }
    
    return;
}

//
//Function: sigSETUPindAct
//
//Description:
//    Indication of desire to place outgoing call.
//      
//

void ccOstateNull :: sigSETUPindAct(sigSETUPind *messenger_,
                                    pfProtocol *protocol_)
{    
#if CC_DEBUG
traceInput(ccDSS2, ccCC, "Null", "SETUPind");
#endif

    ccProtocol *ccprotocol = entryAction(protocol_);

    // copy setup messenger content (storage)         
    ccprotocol->saveData("setup", messenger_);
        
    // Notification to manager (is this correct place?)
    // toveManager::instance()->callEstablished((long) ccprotocol->getId());
    
    // To DP:Origination Attempt
    exitAction(ccprotocol, ccOdpAttempt::instance()); 
     
    return;
}

//
//Function: sigRELEASEconfAct
//
//Description:
//    Answer to RELEASEreq    
//

void ccOstateNull :: sigRELEASEconfAct(sigRELEASEconf *,
                                       pfProtocol *protocol_)
{
#if CC_DEBUG
traceInput(ccDSS2,ccCC,"Null","RELEASEconf");
#endif    
    
    // ......................................
    //             (null)
    // RELEASEconf--->
    //             (null)
    // [<--RELEASEresp]
    //           (destroyed)
    
    ccProtocol *ccprotocol = entryAction(protocol_);
    sendReadyForDeletionMessage(ccprotocol);
    return;
}

//
//Function: ccRELEASE_ACTIVEpduAct
//
//Description: 
//    Unexpected RELEASE_ACTIVE message form T side: ignore
//

void ccOstateNull :: ccRELEASE_ACTIVEpduAct(ccRELEASE_ACTIVEpdu *release_,
                                            ccProtocol *protocol_)
{
#if CC_DEBUG    
traceInput(ccCCT,ccCC,"Null","RELEASE_ACTIVE");
#endif
    // Do nothing, we are just starting or allready released. 
    return;
}



