//Editor-Info: -*- C++ -*-
//
//Subject: TOVE-project / MTP3 protocol
//
//File: mtp3state_hmdt_idle.cpp
//
//Version: $Revision: 1.10 $
//
//Date: $Date: 1998/09/01 09:27:39 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications and Multimedia
//
//Author:
//      Timo Pärnänen
//      Petteri Koponen
//
//Description:
//      See corresponding heder file.
//
//Copyright:
//
//
//Licence:
//
//
//History:

#include "pf/frame.h"
#include "mtp3defs.h"
#include "mtp3block_hmdt.h"
#include "mtp3state_hmdt_idle.h"

// implementations of constructors, destructor and singleton pattern

mtp3_HMDT_Idle *mtp3_HMDT_Idle::_only = 0;

mtp3_HMDT_Idle * mtp3_HMDT_Idle :: instance(void)
{
    if (_only == 0)
    {
        _only = new mtp3_HMDT_Idle;
    }
    return _only;
}

mtp3_HMDT_Idle :: mtp3_HMDT_Idle(void)
{
    return;
}

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

void mtp3_HMDT_Idle :: naalRECEIVED_MESSAGEindAct(
    naalRECEIVED_MESSAGEind *messenger_,
    pfProtocol *protocol_)
{     
    // extracts service indicator from message unit. getServiceIndicator()
    // returns != MTP3_CODING_OK in case of error => message will be
    // discarded, otherwise it will be sent to right functional entity or
    // level 4
    pfFrame messageUnit = messenger_->getMessageUnit();
    pfUlong serviceIndicator;
    mtp3BlockHMDT *block = (mtp3BlockHMDT *)protocol_;
    
    if (getServiceIndicator(messageUnit, serviceIndicator) != MTP3_CODING_OK)
    {
	cerr << "--not implemented--: Coding error --> discarded" << endl;
	// ++TODO++ (error handling code here)
    }
    else if (serviceIndicator == 0)
    {
        cerr << "--not implemented--: ";
        cerr << "Signalling Network Management Message --> discarded" << endl;
    }
    
    else if (serviceIndicator == 1)
    {
        cerr << "--not implemented--: ";
        cerr << "Signalling Network Testing and ";
        cerr << "Maintenance Message --> discarded" << endl;
	// ++TODO++ (pass message to SLTC block)
    }
    else if ((serviceIndicator >= 3) && (serviceIndicator <= 10))
    {
        pfUlong AALid = messenger_->getAALidentifier();
        block->toLevel4(messageUnit, serviceIndicator, AALid);
    }
    else
    {
        cerr << "--Invalid serviceIndicator-- :  message discarded" << endl;
	// discard message
    } 
    return;
}
