package cz.vutbr.feec.session.feedback;

import java.util.Vector;

import oldPackets.LMSPacket;
import oldPackets.LMVPacket;

import cz.vutbr.feec.packets.ttp.FTDPacket;
import cz.vutbr.feec.packets.ttp.FTIPacket;
import cz.vutbr.feec.packets.ttp.FTSPacket;
import cz.vutbr.feec.session.ISession;

abstract public class FeedbackSessionBase implements ISession, EventListener {

	protected ThreadInMulticast inMulticast;

	protected ThreadInUnicast inUnicast;

	protected ThreadOut outUnicast;
	
	protected FeedbackSessionStatus status = new FeedbackSessionStatus();

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

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

	public FeedbackSessionBase() {
	}

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

	public void start() {
		status.setRunning(true);
		inUnicast.startThread();
		inMulticast.startThread();
		outUnicast.startThread();
	}

	public void stop() {
		status.setRunning(false);
		inUnicast.stopThread();
		inMulticast.stopThread();
		outUnicast.stopThread();
	}

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

	}

	
	public void received(FTIPacket 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(FTDPacket packet) {
		for (EventListener l : rcvLtns) {
			l.sent(packet);
		}
	}

	
	public void sent(FTIPacket 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 status.isRunning();
	}
}
