namespace PythonPlot
{


  /// <summary>
  /// Singleton class that handles a PlotClient and returns the interface for remote plotting
  /// </summary>
  public sealed class PlotManager
  {
    public static ushort Port = 5555;
    public static string Ipaddress = "localhost";

    private PythonPlot.PlotClient m_plotClient = null;

    /// <summary>
    /// Get a reference to the PlotClient interface
    /// </summary>
    public PythonPlot.PlotClient Plot
    {
      get
      {
        return m_plotClient;
      }
    }

    /// <summary>
    /// Set/Get the enable flag of the plot client
    /// </summary>
    public bool Enable
    {
      get
      {
        return m_plotClient.Enable;
      }

      set
      {
        m_plotClient.Enable = value;
      }
    }

    private PlotManager(int port = 5555, string ipaddress = "localhost")
    {
      m_plotClient = new PythonPlot.PlotClient(port, ipaddress);
      m_plotClient.Start();
      m_plotClient.Reset();
    }

    ~PlotManager()
    {
      m_plotClient.Stop();
    }

    /// <summary>
    /// Return an instance of the PlotManager
    /// </summary>
    public static PlotManager Instance { get { return Nested.instance; } }

    private class Nested
    {
      // Explicit static constructor to tell C# compiler
      // not to mark type as beforefieldinit
      static Nested()
      {
      }

      internal static readonly PlotManager instance = new PlotManager(Port, Ipaddress);
    }
  }

}