package cz.vutbr.feec.sim.ha;

import java.util.Vector;


import cz.vutbr.feec.simlib.Proc;
import cz.vutbr.feec.simlib.ProcComposite;
import cz.vutbr.feec.simlib.net.InetAddress;
import cz.vutbr.feec.simlib.net.Socket;

public class FTMHost extends ProcComposite{

	/** Socket s unikatni adresou, ktera patri vyhradne tomuto sitovemu prvku. */
	private InetAddress addr;

	/** Stav, ktery se muze vykreslovat. */
	private FTHostState sessionState;

	/** Proces, obsluhujici prichozi pakety z kanalu. */
	private FeedbackInFT inputInterface;

	/** The mc feedback out process. */
	private FeedbackOutFT outputInterface;
	
	/** Socket pro multicast. */
	private FeedbackInFT multicastInterface;
	
	private Vector<FTHost> vectorOfFTHost;

	/**
	 * Instantiates a new FT Host.
	 * 
	 * @param multicastSock the multicast socket
	 * @param localSock the localhost socket
	
	 */
	
	public FTMHost(FTHostState state) {
		
		// create state
		this.sessionState = state;
		this.addr = sessionState.getUnicastAddr();
		
		// sockets and its port binding
		Socket sockIn = new Socket(addr, (int)sessionState.getPortIn());
		Socket sockOut = new Socket(addr, (int)sessionState.getPortOut());
		Socket sockMulticast = new Socket(addr, (int)sessionState.getPortMulticast());
		
		// create processes
		inputInterface = new FeedbackInFT(sessionState, sockIn);
		outputInterface = new FeedbackOutFT(sessionState, sockOut);
		multicastInterface = new FeedbackInFT(sessionState,sockMulticast);
		
		// bind addr to process - zajisti ze budou pakety dorucovany pro dany
		// proces
		getLocalAddress().registerAddressOwner(inputInterface);
		getLocalAddress().registerAddressOwner(outputInterface);
		getLocalAddress().registerAddressOwner(multicastInterface);
		
		// add into collection of processes which will be used by simulation
		addProcess(inputInterface);
		addProcess(outputInterface);
		addProcess(multicastInterface);
		
	}

	public FTHostState getSessionState() {
		return sessionState;
	}

	public InetAddress getLocalAddress() {
		return addr;
	}
	public void setFTgroup(Vector<FTHost> ft) {
		this.vectorOfFTHost = ft;
	}

	

}
