using System;
using Wayne.Lib;
namespace Wayne.ForecourtControl.OptBridge
{
///
/// The OPT object is used to communicate with an outdoor payment terminal connected to the forecourt server.
/// Only one client can control the interface, and the interface must be reserverd by the client before the write() method is accepted.
/// OnDataRead is also only signalled to the client that owns the reservation.
///
public interface IOpt
{
#region Properties
///
/// Logical terminal number / filling position.
///
int Id { get;}
///
/// Current state of the connection to the terminal. The Connection state will only be either Connected when
/// the terminal is online or Connecting if the terminal is not responding.
///
DeviceConnectionState ConnectionState { get;}
///
/// If the terminal is reserved, the clientId of the reserving IOptBridge client will be reported here.
/// If the terminal not is reserved, it will be 0.
///
int ReservedByClientId { get;}
#endregion
#region Events
///
/// Event signalling that the connection state of the terminal has changed.
///
event EventHandler OnConnectionStateChange;
///
/// Fired when data has been read from the terminal. Only the client that has reserved the terminal will receive this event.
///
event EventHandler OnDataRead;
#endregion
#region Methods
///
/// Reserves this device for exclusve control from this instance.
///
/// Callback delegate that will be invoked on completion.
/// User token object that will be returned in the completion callback
void ReserveAsync(EventHandler reserveCompleted, object userToken);
///
/// Cancel device reservation. This command is only allowed after a successful call to ReserveAsync() by the same client.
///
/// Callback delegate that will be invoked on completion.
/// User token object that will be returned in the completion callback
void UnreserveAsync(EventHandler unreserveCompleted, object userToken);
///
/// The data is transparently sent to the terminal, only appending protocol specific information. If waitForSendOk=false,
/// the request will complete as soon as the data has been sent to the forecourt server. If it is true, the request will
/// be complete after the data is actually sent to the terminal.
///
///
/// If this flag is set, the writeCompleted will not be invoked until the data is actually sent to the terminal.
///
///
void WriteAsync(byte[] terminalData, bool waitForSendOk, EventHandler writeCompleted, object userToken);
#endregion
}
}