package nl.nikhef.sfp;

import java.io.IOException;

import nl.nikhef.sfp.i2c.I2CLink;
import nl.nikhef.sfp.i2c.SimI2CLink;
import nl.nikhef.sfp.i2c.VirtualI2CLink;

public class VirtualSFPDevice extends SFPDeviceBase {

	private final String _serial;
	private final int    _bays;
	private I2CLink[]	 _links;
	
	
	public VirtualSFPDevice(String serial, int bays) {
		_serial = serial;
		_bays = bays;
		_links = new I2CLink[_bays];


	}
	
	@Override
	public String getSerial() {
		return _serial;
	}

	@Override
	public int getBayCount() {
		return _bays;
	}

	@Override
	public I2CLink getLink(int bay) throws IOException {
		if (!isModulePresent(bay)) return null;
		return _links[bay];
	}

	@Override
	public boolean isModulePresent(int bay) {
		if (bay < 0 || bay > getBayCount()) return false;
		return _links[bay] != null;
	}
	


	@Override
	public void shutdown() {
	}

	@Override
	public void updateModules()
	{
		if (_links[0] != null) return;
		for (int bay = 0; bay < _links.length; bay++)
		{
			_links[bay] = new VirtualI2CLink(String.format("Virtual_%d", bay));
			sdlMgr.getProxy().sfpModuleStateChanged(this, bay);
		}
	}

	
}
