using System;
using System.Collections;
using System.Text;
using Medivators.Common.Enums;
using Medivators.Common.Logging;
using Sax.Communications;

namespace Medivators.Comm
{
	public class CommDispatcher
	{
		private Hashtable _connections = null;

		#region singleton construct

		private static CommDispatcher _instance = null;
		private CommDispatcher()
		{
		}
		public static CommDispatcher GetInstance()
		{
			if (_instance == null)
				_instance = new CommDispatcher();
			return _instance;
		}

		#endregion 

		public SerialConnection GetCommConnection(CommPorts PortName)
		{
			if (_connections == null)
				_connections = new Hashtable();
			if (! _connections.ContainsKey(PortName.ToString()))
				_connections.Add(PortName.ToString(), new SerialConnection());

			Log.GetInstance().WriteLog(LogEntryType.DebugTrace, 
				" SerialConnection for Port " + 
				PortName.ToString() + 
				"Dispatched. IsOpen = " +
				((SerialConnection)_connections[PortName.ToString()]).IsOpen.ToString());

			return (SerialConnection)_connections[PortName.ToString()];
		}
	}
}
