/*******************************************************************************
 *  Copyright 2017-2018 Centre for Development of Advanced Computing(C-DAC), Pune
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *   http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package cdac.medinfo.sdk.dcm30_04.services.pdu;

import java.nio.ByteBuffer;
import java.util.EventObject;

import cdac.medinfo.sdk.dcm30_04.enums.EnumPDUType;




/**
 * The Class PDUEvent. This event is fired by network agent when the PDU is received.
 */
public class PDUEvent extends EventObject 
{

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;

	/** The pdu buffer. */
	ByteBuffer pduBuffer;

	/** The enum pdu type. */
	EnumPDUType enumPDUType = null;

	/**
	 * Instantiates a new pDU event.
	 * @param reader 
	 */
	public PDUEvent(Object reader)
	{
		super(reader);
	}

	/**
	 * Sets the PDU buffer.
	 * @param pdubuf Byte Buffer containing the data.
	 */
	public void setPDUBuffer(ByteBuffer pdubuf)
	{
		pduBuffer = pdubuf;
	}

	/**
	 * Gets the PDU buffer.
	 * @return ByteBuffer - byte buffer containing the data.
	 */
	public ByteBuffer getPDUBuffer()
	{
		return pduBuffer;
	}

	/**
	 * Sets the PDU type.
	 * @param bPDUType - the PDU type
	 */
	public void setPDUType(byte bPDUType)
	{
		switch(bPDUType)
		{
		case 1 : enumPDUType = EnumPDUType.ASSOCIATE_RQ;
		break;
		case 2 : enumPDUType = EnumPDUType.ASSOCIATE_AC;
		break;
		case 3 : enumPDUType = EnumPDUType.ASSOCIATE_RJ;
		break;
		case 4 : enumPDUType = EnumPDUType.P_DATA_TF;
		break;
		case 5 : enumPDUType = EnumPDUType.RELEASE_RQ;
		break;
		case 6 : enumPDUType = EnumPDUType.RELEASE_RP;
		break;
		case 7 : enumPDUType = EnumPDUType.ABORT;
		break;
		default : //throw InvalidPDUException();
		}
	}

	/**
	 * Gets the PDU type.
	 * @return EnumPDUType - the PDU type
	 */
	public EnumPDUType getPDUType()
	{
		return enumPDUType;
	}
}
