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 CommPortSimulation: ICommDevice
	{
		private const SupportedCommDevices	_device = SupportedCommDevices.CommPortSoftwareSimulation;
		private CommPortSettings			_settings;
		private bool									_isOpen = false;

		#region construct/init/dispose

		public CommPortSimulation()
		{
		}
		public void Dispose()
		{
		}

		#endregion

		#region common COMM device methods - implments ICommDevice

		public SupportedCommDevices		Device
		{
			get { return _device; }
		}
		public 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 DataArrivedEventHandler	 DataArrived;
		public event CommErrorEventHandler		 CommError;
		public event SettingsChangedEventHandler SettingsChanged;

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