//Editor-Info: -*- C++ -*-
//
//Subject: TOVE project / SIGINFO
//
//File: siginfos.cpp
//
//Version: $Revision: 1.15 $
//
//State: $State: Exp $
//
//Date: $Date: 1998/10/19 18:11:58 $
//
//Organisation:
//      Helsinki University of Technology
//      Laboratory of Telecommunications and Multimedia
//
//Author:
//      Timo Pärnänen
//
//Description:
//      See corresponding header file 
//
//Copyright:
//
//
//Licence:
//
//
//History: 

#include "siginfos.h"
#include "pf/bytes.h"

sigInfo :: sigInfo(void)
    : _isContentValid(1),
      _isPresent(0),
      _isMandatory(0),
      _isAllowed(0),
      _ieCodingStandard(0),
      _ieInstructionFlag(0),
      _ieActionIndicator(0)
{
    return;
}

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

//
//Function: verifyIEcontent
//
//Description
//    Default action for very information element procedure
//

bool sigInfo :: verifyIEcontent(void)
{
    return _isContentValid;
}

//
//Functions: set and get methods
//
//Description
//    Set and get methods for base class attributes
//

void sigInfo :: setIEpresent(void)
{
    _isPresent = 1;
    return;    
}

bool sigInfo :: isIEpresent(void) const
{
    return _isPresent;
}

void sigInfo :: setIEmandatory(void)
{
    _isMandatory = 1;
    return;    
}

bool sigInfo :: isIEmandatory(void) const
{
    return _isMandatory;
}

void sigInfo :: setIEallowed(void)
{
    _isAllowed = 1;
    return;
}

bool sigInfo :: isIEallowed(void) const
{
    return _isAllowed;
}

void sigInfo :: setIEinvalidContent(void)
{
    _isContentValid = 0;
    return;
}

bool sigInfo :: isIEcontentValid(void) const
{
    return _isContentValid;
}

void sigInfo :: setIEcodingStandard(long ieCodingStandard_)
{
    _ieCodingStandard = ieCodingStandard_;
    return;
}

long sigInfo :: getIEcodingStandard(void) const
{
    return _ieCodingStandard;
}

void sigInfo :: setIEinstructionFlag(long ieInstructionFlag_)
{
    _ieInstructionFlag = ieInstructionFlag_;
    return;    
}

long sigInfo :: getIEinstructionFlag(void) const
{
    return _ieInstructionFlag;
}

void sigInfo :: setIEactionIndicator(long ieActionIndicator_)
{
    _ieActionIndicator = ieActionIndicator_;
    return;    
}

long sigInfo :: getIEactionIndicator(void) const
{
    return _ieActionIndicator;
}

// ----------------------------------------------------------------------

sigPhoneNumber :: sigPhoneNumber(void)
    : sigInfo(),
      _type(0),
      _plan(0),
      _number(0),
      _length(0)
{
    return;    
}

sigPhoneNumber :: ~sigPhoneNumber(void)
{
    delete [] _number;
    return;    
}

//
//Functions: verifyIEcontent methods
//
//Description
//    Method for verifying the content of informationelement. This mean
//    that method checks is field values of information element in allowed
//    range.
//

bool sigPhoneNumber :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        switch(_type)
        {
            case B0000_0000 : // unknown
                break;            
            case B0000_0001 : // international
                break;                
            case B0000_0010 : // national 
                break;
            case B0000_0011 : // network specific
                break;
            case B0000_0100 : // subscriber
                break;
            case B0000_0110 : // abbreviated
                break;            
            default :
                _isContentValid = 0;                
                break;
        }
        switch(_plan) // Now ONLY ISDN numbering plan is allowed !!
        {
            case B0000_0000 : // unknown
                _isContentValid = 0;
                break;            
            case B0000_0001 : // ISDN numbering plan
                break;                
            case B0000_0010 : // NSAP addressing
                _isContentValid = 0;
                break;
            case B0000_1001 : // private numbering plan
                _isContentValid = 0;
                break;
            default :
                _isContentValid = 0;
                break;
        }        
    }
    return _isContentValid;
}

//
//Functions: methods for handling class attributes
//
//Description
//    Information elements has declared set and get methods for its
//    fields (attributes) and additionally there is few more intelligent
//    methods for fields.
//

bool sigPhoneNumber :: isEqual(char *number_)
{
    bool equal = 0;
    if (strcmp(number_, _number) == 0)
    {
        equal = 1;
    }
    return equal;
}
void sigPhoneNumber :: setType(long type_)
{
    _type = type_;
    return;    
}

long sigPhoneNumber :: getType(void) const
{
    return _type;
}

void sigPhoneNumber :: setPlan(long plan_)
{
    _plan = plan_;
    return;    
}

long sigPhoneNumber :: getPlan(void) const
{
    return _plan;
}

void sigPhoneNumber :: setNumber(char *number_) 
{
    _length = strlen(number_);
    _number = new char[_length + 1];
    strcpy(_number, number_);
    return;
}

char *sigPhoneNumber :: getNumber(void) const
{
    return _number;
}

long sigPhoneNumber :: getLength(void) const
{
    return _length;
}

// ----------------------------------------------------------------------

sigSubAddress :: sigSubAddress(void)
    : sigPhoneNumber()
{
    return;    
}

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

bool sigSubAddress :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        switch(_type)
        {
            case B0000_0000 : // NSAP
                break;            
            case B0000_0001 : // user-specified ATM endsystem address
                break;                
            case B0000_0010 : // user-specified
                break;
            default :
                _isContentValid = 0;                
                break;
        }
    }
    return _isContentValid;
}

// ----------------------------------------------------------------------

sigPeakCellRate :: sigPeakCellRate(void)
    : _forwardCLP0(-1),
      _backwardCLP0(-1),
      _forwardCLP1(-1),
      _backwardCLP1(-1)
{
    return;
}

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

//
//Function: verifyContent
//
//Description:
//    Forward and backward values for CLP 1 are mandatories.
//    If values for CLP 0 was not set, CLP 1 values is used for CLP 0.
//    (Q.2931 / page 50)
//

bool sigPeakCellRate :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        if (_forwardCLP1 == -1 || _backwardCLP1 == -1)
        {
            _isContentValid = 0;
        }
        else
        {
            if (_forwardCLP0 == -1)
            {
                _forwardCLP0 = _forwardCLP1;
            }            
            if (_backwardCLP0 == -1)
            {
                _backwardCLP0 = _backwardCLP1;            
            }
        }
    }
    return _isContentValid;
}

void sigPeakCellRate :: setForwardCLP0(long forwardCLP0_)
{
    _forwardCLP0 = forwardCLP0_;
    return;
}

long sigPeakCellRate :: getForwardCLP0(void) const
{
    return _forwardCLP0;
}

void sigPeakCellRate :: setBackwardCLP0(long backwardCLP0_)
{
    _backwardCLP0 = backwardCLP0_;
    return;
}

long sigPeakCellRate :: getBackwardCLP0(void) const
{
    return _backwardCLP0;
}

void sigPeakCellRate :: setForwardCLP1(long forwardCLP1_)
{
    _forwardCLP1 = forwardCLP1_;    
    return;
}

long sigPeakCellRate :: getForwardCLP1(void) const
{
    return _forwardCLP1;
}

void sigPeakCellRate :: setBackwardCLP1(long backwardCLP1_)
{
    _backwardCLP1 = backwardCLP1_;    
    return;
}

long sigPeakCellRate :: getBackwardCLP1(void) const
{
    return _backwardCLP1;
}

// ----------------------------------------------------------------------

sigBroadbandBearerCapability :: sigBroadbandBearerCapability(void)
    : _bearerClass(0),
      _trafficType(-1),
      _timingRequirements(-1),
      _susceptibleToClipping(0),
      _userPlaneConnectionConfig(0)
{        
    return;    
}

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

bool sigBroadbandBearerCapability :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        switch(_bearerClass)
        {
            case B0000_0001 : // BCOB-A
                break;                
            case B0000_0011 : // BCOB-C
                break;
            case B0001_0000 : // BCOB-X
                break;            
            default :
                _isContentValid = 0;                
                break;
        }
        switch(_trafficType)
        {
            case B0000_0000 : // no indication
                break;            
            case B0000_0001 : // constant bit rate
                break;                
            case B0000_0010 : // variable bit rate
                break;
            default :
                _isContentValid = 0;
                break;
        }
        switch(_timingRequirements)
        {
            case B0000_0000 : // no indication
                break;            
            case B0000_0001 : // end-to-end timing required
                break;                
            case B0000_0010 : // end-to-end timing not required
                break;
            default :
                _isContentValid = 0;
                break;
        }                
        switch(_susceptibleToClipping)
        {
            case B0000_0000 : // not susceptible to clipping
                break;            
            case B0000_0001 : // susceptible to clipping
                break;
            default :
                _isContentValid = 0;
                break;
        }                
        switch(_userPlaneConnectionConfig)
        {
            case B0000_0000 : // point-to-point
                break;            
            case B0000_0001 : // point-to-multipoint
                break;
            default :
                _isContentValid = 0;
                break;
        }                
    }
    return _isContentValid;
}

void sigBroadbandBearerCapability :: copyAttributes(
    sigBroadbandBearerCapability &other_)
{
    _bearerClass = other_._bearerClass;
    _trafficType = other_._trafficType;
    _timingRequirements = other_._timingRequirements;
    _susceptibleToClipping = other_._susceptibleToClipping;
    _userPlaneConnectionConfig = other_._userPlaneConnectionConfig;
    return;
}

void sigBroadbandBearerCapability :: setBearerClass(long bearerClass_)
{
    _bearerClass = bearerClass_;
    return;
}

sigBearerClass sigBroadbandBearerCapability :: getBearerClass(void) const
{
    return _bearerClass;
}

void sigBroadbandBearerCapability :: setTrafficType(long trafficType_)
{
    _trafficType = trafficType_; 
    return;
}

long sigBroadbandBearerCapability :: getTrafficType(void) const
{
    return _trafficType;
}

void sigBroadbandBearerCapability :: setTimingRequirements(
    long timingRequirements_)
{
    _timingRequirements = timingRequirements_;
    return;
}    

long sigBroadbandBearerCapability :: getTimingRequirements(void) const
{
    return _timingRequirements;
}

void sigBroadbandBearerCapability :: setSusceptibleToClipping(
    long susceptibleToClipping_)
{
    _susceptibleToClipping = susceptibleToClipping_;
    return;
}

long sigBroadbandBearerCapability :: getSusceptibleToClipping(void) const
{
    return _susceptibleToClipping;
}

void sigBroadbandBearerCapability :: setUserPlaneConnectionConfig(
    long userPlaneConnectionConfig_)
{
    _userPlaneConnectionConfig = userPlaneConnectionConfig_;
    return;
}

long sigBroadbandBearerCapability :: getUserPlaneConnectionConfig(void) const
{
    return _userPlaneConnectionConfig;
}

// ----------------------------------------------------------------------

sigCause :: sigCause(void)
    : _location(0),
      _causeValue(0)
{
    return;    
}

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

void sigCause :: setLocation(long location_)
{
    _location = location_;    
    return;
}

long sigCause :: getLocation(void) const
{
    return _location;
}

void sigCause :: setCauseValue(long causeValue_)
{
    _causeValue = causeValue_;    
    return;
}

long sigCause :: getCauseValue(void) const
{
    return _causeValue;
}

// ----------------------------------------------------------------------

sigQualityOfService :: sigQualityOfService(void)
    : _qosClassForward(0),
      _qosClassBackward(0)
{
    return;    
}

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

//
//Function: verifyContent
//
//Description:
//    Only null (unspecified) values are allowed for QOS class.
//    (Q.2931 / page 72)
//

bool sigQualityOfService :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        if (_qosClassForward != 0 || _qosClassBackward != 0)
        {
            _isContentValid = 0;
        }
    }
    return _isContentValid;
}

void sigQualityOfService :: setQosClassForward(long qosClassForward_)
{
    _qosClassForward = qosClassForward_;
    return;
}

long sigQualityOfService :: getQosClassForward(void) const
{
    return _qosClassForward;
}

void sigQualityOfService :: setQosClassBackward(long qosClassBackward_)
{
    _qosClassBackward = qosClassBackward_;
    return;
}

long sigQualityOfService :: getQosClassBackward(void) const
{
    return _qosClassBackward;
}

// ----------------------------------------------------------------------

sigCallState :: sigCallState(void)
    : _stateValue(0)
{
    return;    
}

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

//
//Function: verifyContent
//
//Description:
//    (Q.2931 / page 60)
//

bool sigCallState :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        if (_stateValue == 5 || (_stateValue > 12 && _stateValue < 25 ) ||
            _stateValue > 25)
        {
            _isContentValid = 0;
        }
    }
    return _isContentValid;
}

void sigCallState :: setStateValue(long stateValue_)
{
    _stateValue = stateValue_;
    return;
}

long sigCallState :: getStateValue(void) const
{
    return _stateValue;
}

// ----------------------------------------------------------------------

sigConnectionIdentifier :: sigConnectionIdentifier(void)
    : _vpAssociatedSignalling(0),
      _preferredExclusive(0),
      _vpci(-1),
      _vci(-1)
{
    return;
}

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

const sigConnectionIdentifier &sigConnectionIdentifier :: operator =
    (const sigConnectionIdentifier &other_)
{
    if (this != &other_) // if not x = x situation
    {
        _vpAssociatedSignalling = other_._vpAssociatedSignalling;
        _preferredExclusive = other_._preferredExclusive;
        _vpci = other_._vpci;
        _vci = other_._vci;        
    }
    return *this;
}

bool sigConnectionIdentifier :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        switch(_vpAssociatedSignalling)
        {
            case B0000_0000 : // VP-associated signalling
                break;            
            case B0000_0001 : // explicit indication of VPCI
                break;                
            default :
                _isContentValid = 0;                
                break;
        }
        switch(_preferredExclusive)
        {
            case B0000_0000 : // exclusive VPCI; exclusive VCI
                break;            
            case B0000_0001 : // exclusive VPCI; any VCI
                break;                
            default :
                _isContentValid = 0;
                break;
        }
        if (_vci < 32) // not used for on-demand user plane connection
        {
            _isContentValid = 0;            
        }
    }
    return _isContentValid;
}

void sigConnectionIdentifier :: setVPassociatedSignalling(
    long vpAssociatedSignalling_)
{
   _vpAssociatedSignalling = vpAssociatedSignalling_;
    return;
}

long sigConnectionIdentifier :: getVPassociatedSignalling(void) const
{
    return _vpAssociatedSignalling;
}

void sigConnectionIdentifier :: setPreferredExclusive(long preferredExclusive_)
{
    _preferredExclusive = preferredExclusive_;
    return;
}

long sigConnectionIdentifier :: getPreferredExclusive(void) const
{
    return _preferredExclusive;
}
        
void sigConnectionIdentifier :: setVPCI(long vpci_)
{
    _vpci = vpci_;
    return;
}

long sigConnectionIdentifier :: getVPCI(void) const
{
    return _vpci;
}

void sigConnectionIdentifier :: setVCI(long vci_)
{
    _vci = vci_;
    return;
}

long sigConnectionIdentifier :: getVCI(void) const
{
    return _vci;
}

// ----------------------------------------------------------------------

sigRestartIndicator :: sigRestartIndicator(void)
    : _class(0)
{
    return;
}

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

//
//Function: verifyContent
//
//Description:
//    (Q.2931 / page 74)
//

bool sigRestartIndicator :: verifyIEcontent(void)
{
    if (_isContentValid != 0)
    {
        switch (_class)
        {
            case B0000_0000 : // indicated virtual channel
                break;
            case B0000_0001 : // see Q.2931 / page 74 
                break;        
            case B0000_0010 : // see Q.2931 / page 74 
                break;
            default :               
                _isContentValid = 0;
                break;
        }
    }
    return _isContentValid;
}

void sigRestartIndicator :: setClass(long class_)
{
    _class = class_;
    return;
}

long sigRestartIndicator :: getClass(void) const
{
    return _class;
}

// ----------------------------------------------------------------------

sigUnImplementedIE :: sigUnImplementedIE(void)
{
    return;
}

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