//Editor-Info: -*- C++ -*-
//
//Subject: TOVE-project / MTP3 protocol
//
//File: mtp3block_hmdc.cpp
//
//Version: $Revision: 1.11 $
//
//Date: $Date: 1998/10/19 18:14:33 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications and Multimedia
//
//Author:
//      Timo Pärnänen
//      Petteri Koponen
//
//Description:
//      See corresponding header file.
//
//Copyright:
//
//
//Licence:
//
//
//History:

#include "pf/messenge.h"
#include "pf/frame.h"
#include "mtp3defs.h"
#include "mtp3protocol.h"
#include "mtp3block_hmdc.h"
#include "mtp3state_hmdc_idle.h"

//
//Constructor: mtp3BlockHMDC
//
//Description:
//      Initializes member variables. The initial state is idle.
//

mtp3BlockHMDC :: mtp3BlockHMDC(mtp3Protocol *protocol_,
                               ss7Configure &configure_)
    : mtp3Colleague(protocol_, configure_)
{
    // Increment block's reference counter, beacause there is no proxy 
    // to block in main function
    incRefCount();
    changeState(mtp3_HMDC_Idle::instance());
    return;
}

//
//Destructor: mtp3BlockHMDC
//
//Description:
//      Empty.
//

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

void mtp3BlockHMDC :: toHMDT(pfMessenger *messenger_)
{
    _protocol->toHMDT(messenger_);
    return;
}

void mtp3BlockHMDC :: toHMRT(pfMessenger *messenger_)
{
    _protocol->toHMRT(messenger_);
    return;
}

bool mtp3BlockHMDC :: destinatedToThisSP(pfFrame &messageUnit_)
{
    bool result = 0;

    // Check destination point code  ++TODO++ error handling
    assert(messageUnit_.length() > MTP3_DESTINATION_POINT_CODE_OFFSET);
    pfUlong offSet = MTP3_DESTINATION_POINT_CODE_OFFSET;
    
    pfUlong LSB = messageUnit_.read(offSet++);
    pfUlong MSB = (messageUnit_.read(offSet) & MTP3_6_BITS) << 8;
    pfUlong DPC = MSB+LSB;

    if (DPC == _configure.getPointCode())
    {
        result = 1;
    }
    return result;
}
