package nl.nikhef.sfp;

import java.io.IOException;
import java.util.Collection;

import nl.nikhef.sfp.i2c.I2CLink;

/**
 * Encapsulates the peripheral which reads the SFP device, not the SFP device itself.
 */
public interface SFPDevice extends Comparable<SFPDevice>
{
	/**
	 * Device serial.
	 */
	public String getSerial();

	/**
	 * Number of SFP 'bays' on the device.
	 * @return
	 */
	public int getBayCount();
	
	
	/**
	 * Get the serial number of the connected module.
	 * 
	 * @param bay	The bay number.
	 * 
	 * @return		the serial, or null if non is connected.
	 */
	public String getModuleSerial(int bay);
	
	/**
	 * Returns a I2CLink to the specified device.
	 * 
	 * @param bay			The bay number
	 * @return				The I2CLink
	 * @throws IOException	An IOException if the link could not be made
	 */
	public I2CLink getLink(int bay) throws IOException;
	
	/**
	 * Returns whether or not a specific module is present.
	 * 
	 * @param bay	The bay number
	 * @return		true - its present, false - its not present.
	 */
	public boolean isModulePresent(int bay);
	
	/**
	 * 
	 * @param sdl
	 */
	public void addDeviceListener(SFPDeviceListener sdl);
	
	public Collection<SFPDeviceListener> getDeviceListeners();
	
	public void removeDeviceListener(SFPDeviceListener sdl);

	/**
	 * Closes the device.
	 */
	public void shutdown();
	
	/**
	 * Call invoked by provider each second to check the module state.
	 */
	public void updateModules();

	/**
	 * Returns whether or not this module has digital diagnostics.
	 */
	public boolean hasDiagnostics(int bay);
	
}
