
package uk.co.wingpath.modbus;

/**
* Interface used by {@link ModbusSlave} to communicate with a dynamic
* {@link ModbusModel} (such as {@link ModbusCache}) to ensure that values
* are up-to-date when required, and that values are forwarded to the device
* when they have been updated.
*/
public interface ModbusForwarder
{
    /**
    * Requests that cached values be updated by reading them from the device
    * if necessary. Any reads are done asynchronously, i.e. they may not be 
    * finished when this method returns.
    * @param address model address of first required value.
    * @param nvalues number of values required.
    * @param requestTime earliest acceptable set-time for the value to be
    * considered to be up-to-date. This is normally the time that a request
    * was received from a client (SNMP manager or Modbus master).
    * @param waiter waiter to be notified when the values are up-to-date.
    * @throws InterruptedException if the thread is interrupted
    */
    public void requires (int address, int nvalues, long requestTime,
            ModbusWaiter waiter)
        throws InterruptedException;

    /**
    * Requests that updated values be written to the device.
    * Writes are done asynchronously, i.e. they may not be finished when
    * this method returns.
    * @param address model address of first updated value.
    * @param nvalues number of updated values.
    * @param waiter waiter to be notified when the values have been written.
    * @throws InterruptedException if the thread is interrupted
    */
    public void updated (int address, int nvalues, ModbusWaiter waiter)
        throws InterruptedException;
}
