package cz.vutbr.feec.session.gnp;

import java.util.Vector;

import cz.vutbr.feec.packets.ttp.FTAPacket;
import cz.vutbr.feec.packets.ttp.FTCPacket;
import cz.vutbr.feec.packets.ttp.FTSPacket;
import cz.vutbr.feec.packets.ttp.LMSPacket;
import cz.vutbr.feec.packets.ttp.LMVPacket;
import cz.vutbr.feec.session.ISession;

abstract public class GNPSessionStatus implements ISession, EventListener {

	protected ThreadInMulticast inMulticast;

	protected ThreadInUnicast inUnicast;

	protected ThreadOut outUnicast;

	protected boolean isRunning = false;

	private Vector<EventListener> rcvLtns = new Vector<EventListener>();

	public void addListener(EventListener listener) {
		rcvLtns.add(listener);
	}

	public GNPSessionStatus() {
	}

	protected void initThread() {
		inUnicast.setSession(this);
		inMulticast.setSession(this);
		outUnicast.setSession(this);
	}

	public void start() {
		isRunning = true;
		inUnicast.startThread();
		inMulticast.startThread();
		outUnicast.startThread();
	}

	public void stop() {
		isRunning = false;
		inUnicast.stopThread();
		inMulticast.stopThread();
		outUnicast.stopThread();
	}

	
	public void received(FTAPacket packet) {
		for (EventListener l : rcvLtns) {
			l.received(packet);
		}

	}

	
	public void received(FTCPacket packet) {
		for (EventListener l : rcvLtns) {
			l.received(packet);
		}
	}

	
	public void received(FTSPacket packet) {
		for (EventListener l : rcvLtns) {
			l.received(packet);
		}
	}

	
	public void received(LMSPacket packet) {
		for (EventListener l : rcvLtns) {
			l.received(packet);
		}
	}

	
	public void received(LMVPacket packet) {
		for (EventListener l : rcvLtns) {
			l.received(packet);
		}
	}

	
	public void sent(FTAPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public void sent(FTCPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public void sent(FTSPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public void sent(LMSPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public void sent(LMVPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public boolean isRunning() {
		return isRunning;
	}

}
