package cc;

import cc.idl.*;
import org.omg.CORBA.*;
import java.util.Hashtable;

class ServerImpl extends UDPSvrPOA {
    int clientsNumber = 0;
    
    private ORB orb;
    
    Hashtable hash = new Hashtable();
    
    public void setORB(ORB orb_val) {
        orb = orb_val; 
    }
    
    //public void request (String host, int port, float mbps, int size) {
    public int request (String host, int port, int size, int delay) {
        try{
            Sender sender = new Sender(host, port, size, delay);
            sender.start();
            
            hash.put(new Integer(clientsNumber), sender);
            
            return clientsNumber++;
        } catch (Exception e) {
            System.out.println("ERROR : " + e) ;
            e.printStackTrace(System.out);
        }
        return -1;
    }
    
	private Sender getSender (int id) { 
		return ((Sender) hash.get(new Integer(id))); 
	}
    public int getDelay (int id) { 
        return getSender(id).getDelay(); 
    }
    public int getSize (int id) { 
        return getSender(id).getSize();
    }
	public void setSize (int id, int size) { 
		getSender(id).setSize(size); 
	}
	    
	public void setDelay (int id, int delay) { 
		getSender(id).setDelay(delay);
	}
	
	public void stop (int id) { 
        getSender(id).stopStreaming();
        hash.remove(new Integer(id));
    }
	public void alive(int id) {
		getSender(id).alive();
	}

	public void requestPackets(int id, String listOfPackets) {
		getSender(id).requestPackets(listOfPackets);
	}
}
