using System;

namespace Minntech.Comm
{
	/// <summary>
	/// SimulatedSerialPort allows for testing of software that supports 
	/// serial devices without actually having the serial device hooked up
	/// </summary>
	public class SimulatedCommPort : CommDevices.ICommDevice
	{
		private const CommDevices.SupportedCommDevices	_device = CommDevices.SupportedCommDevices.CommPortSoftwareSimulation;
		private CommDevices.CommPortSettings			_settings;
		private bool									_isOpen = false;

		#region construct/init/dispose

		public SimulatedCommPort()
		{
		}
		public void Dispose()
		{
		}

		#endregion

		#region common serial device methods - implments ICommDevice

		public CommDevices.SupportedCommDevices		Device
		{
			get { return _device; }
		}
		public CommDevices.CommPortSettings			Settings
		{
			get { return this._settings;  }
			set { this._settings = value; }
		}
		public bool IsOpen	
		{
			get { return _isOpen ; }
		}
		public void	OpenCommPort()
		{
			_isOpen = true;
		}
		public void	CloseCommPort()
		{
			_isOpen = false;
		}
		public System.Windows.Forms.DialogResult			 ShowControlDialog()
		{
			//TODO: geoff, fill
			return System.Windows.Forms.DialogResult.OK;
		}
		public void WriteByte(Byte Value) 
		{
			//TODO: Geoff fill!
		}
		public void WriteString( string Value )
		{
			//TODO: Geoff fill!
		}

		#endregion

		public event CommDevices.DataArrivedEventHandler	 DataArrived;
		public event CommDevices.CommErrorEventHandler		 CommError;
		public event CommDevices.SettingsChangedEventHandler SettingsChanged;

		internal virtual void OnDataArrived ( CommDevices.DataArrivedEventArgs e )
		{
			DataArrived(this, e);
		}
		internal virtual void OnCommError ( CommDevices.CommErrorEventArgs e )
		{
			CommError(this, e);
		}
		internal virtual void OnSettingsChanged ( CommDevices.SettingsChangedEventArgs e )
		{
			SettingsChanged(this, e);
		}
	}
}
