//                           UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY
WARNING - THIS DOCUMENT CONTAINS TECHNICAL DATA WHOSE EXPORT OR DISCLOSURE
TO NON-U.S. PERSONS, WHEREVER LOCATED, IS RESTRICTED BY THE INTERNATIONAL
TRAFFIC IN ARMS REGULATIONS (ITAR) (22 C.F.R. SECTIONS 120-130). VIOLATIONS
ARE SUBJECT TO SEVERE CRIMINAL PENALTIES.

DISTRIBUTION STATEMENT F: FURTHER DISSEMINATION ONLY AS DIRECTED BY MISSILE
DEFENSE AGENCY, MDA/GMY NEXT GENERATION INTERCEPTOR PROJECT OFFICE
(DATE OF DETERMINATION 14 JUNE 2021) OR HIGHER DOD AUTHORITY.
OTHER REQUESTS FOR THIS DOCUMENT SHALL BE REFERRED TO: MISSILE DEFENSE
AGENCY, CONTRACTS DIRECTORATE, ATTN: GMY-K, BLDG. 5222 MARTIN ROAD,
REDSTONE ARSENAL, AL 35898.

WARNING - THIS DOCUMENT CONTAINS TECHNICAL DATA WHOSE EXPORT IS RESTRICTED
BY THE ARMS EXPORT CONTROL ACT (TITLE 22, U.S.C., SEC 2751, ET SEQ.) OR 
THE EXPORT ADMINISTRATION ACT OF 1979 (TITLE 50, U.S.C., APP.2401 ET SEQ), 
AS AMENDED. VIOLATIONS OF THESE EXPORT LAWS ARE SUBJECT TO SEVERE CRIMINAL 
PENALTIES. DISSEMINATE IN ACCORDANCE WITH PROVISIONS OF 
DOD DIRECTIVE 5230.25

DESTRUCTION NOTICE - FOR CLASSIFIED DOCUMENTS FOLLOW THE PROCEDURES IN 
DOD 5220.22-M,
NATIONAL INDUSTRIAL SECURITY PROGRAM OPERATING MANUAL, FEBRUARY 2006, 
INCORPORATING CHANGE 1, MARCH 28, 2013, CHAPTER 5, SECTION 7, OR 
DODM 5200.01-VOLUME 3, DOD INFORMATION SECURITY PROGRAM: PROTECTION OF 
CLASSIFIED INFORMATION, ENCLOSURE 3, SECTION 17. FOR CONTROLLED 
UNCLASSIFIED INFORMATION FOLLOW THE PROCEDURES IN DODM 5200.01-VOLUME 4, 
INFORMATION SECURITY PROGRAM: CONTROLLED UNCLASSIFIED INFORMATION
-------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;

using Raytheon.Instruments;
using static MeasurementManagerLib.BitMeasurementManager;

namespace MeasurementManagerLib
{
   /// <summary>
   /// 
   /// </summary>
   public class MalMeasurementLibManager : IDisposable
   {
      public FpgaMeasurementManager FpgaMeasurementManager { get; set; }
      public PowerSupplyMeasurementManager PowerSupplyMeasurementManager { get; set; }
      public SwitchMeasurementManager SwitchMeasurementManager { get; set; }
      public BitMeasurementManager BitMeasurementManager { get; set; }
      public BitGenSoftMeasurementManager BitGenSoftMeasurementManager { get; set; }
      public ChillerCartMeasurementManager ChillerMeasurementManager { get; set; }
      public DioMeasurementManager DioMeasurementManager { get; set; }
      public JtagMeasurementManager JtagMeasurementManager { get; set; }
      public VideoRecorderMeasurementManager VideoRecorderMeasurementManager { get; set; }
      public RelayMeasurementManager RelayMeasurementManager { get; set; }
      public RfMeasurementManager RfMeasurementManager { get; set; }
      public SpaceChamberLSPSMeasurementManager SpaceChamberLSPSMeasurementManager { get; set; }
      public TelemetryMeasurementManager TelemetryMeasurementManager { get; set; }
      public CryoMeasurementManager CryoMeasurementManager { get; set; }
      public OpticalBenchMeasurementManager OpticalBenchMeasurementManager { get; set; }

      public IInstrumentManager InstrumentManager { get; set; }

      ~MalMeasurementLibManager()
      {
         Dispose(false);
      }

      /// <summary>
      /// 
      /// </summary>
      /// <param name="disposing"></param>
      protected virtual void Dispose(bool disposing)
      {
      }

      #region PublicFunctions
      /// <summary>
      /// 
      /// </summary>
      /// <param name=""></param>
      public MalMeasurementLibManager(IInstrumentManager instrumentManager)
      {
         InstrumentManager = instrumentManager;
      }

      /// <summary>
      /// Dispose of all resources
      /// </summary>
      public void Dispose()
      {
         Dispose(true);
      }

      /// <summary>
      /// Initialize the BIT interface manager
      /// </summary>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeBitMeasurementManager(string measurementDefFile, string comDeviceName, string comNodeName, string binDataLogFilename, string asciiDataLogFileName, MessageReceivedDelegate callback)
      {
         // create the object once no matter how many times the host calls this
         if (BitMeasurementManager == null)
         {
            BitMeasurementManager = new BitMeasurementManager(InstrumentManager, measurementDefFile, comDeviceName, comNodeName, binDataLogFilename, asciiDataLogFileName, callback);
         }
      }

      /// <summary>
      /// Initialize the BIT interface manager
      /// </summary>
      /// <param name="instrumentDefFilePath"></param>
      /// <param name="instrumentName"></param>
      /// <param name="testType"></param>
      public void InitializeBitGenSoftMeasurementManager(List<string> instrumentNames)
      {
         if (BitGenSoftMeasurementManager == null)
         {
            BitGenSoftMeasurementManager = new BitGenSoftMeasurementManager(InstrumentManager, instrumentNames);
         }
      }

      /// <summary>
      /// Initialize the Chiller interface manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="chillerName"></param>
      /// <param name="flowMeeterName"></param>
      /// <param name="tempSensorName"></param>
      /// <param name="errorLog"></param>
      public void InitializeChillerCartMeasurementManager(string chillerName, string flowMeeterName, string tempSensorName, string errorLog)
      {
         // create the object once no matter how many times the host calls this
         if (ChillerMeasurementManager == null)
         {
            ChillerMeasurementManager = new ChillerCartMeasurementManager(InstrumentManager, chillerName, flowMeeterName, tempSensorName, errorLog);
         }
      }

      /// <summary>
      /// Initialize the Dio interface manager
      /// </summary>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeDioMeasurementManager()
      {
         // create the object once no matter how many times the host calls this
         if (DioMeasurementManager == null)
         {
            DioMeasurementManager = new DioMeasurementManager(InstrumentManager);
         }
      }

      /// <summary>
      /// Initialize the Jtag interface manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="instrumentName"></param>
      /// <param name="measurementDefFile"></param>
      /// <param name="errorLogFileName"></param>
      public void InitializeJtagMeasurementManager(string instrumentName, string measurementDefFile)
      {
         // create the object once no matter how many times the host calls this
         if (JtagMeasurementManager == null)
         {
            JtagMeasurementManager = new JtagMeasurementManager(InstrumentManager, instrumentName, measurementDefFile);
         }
      }

      /// <summary>
      /// Initialize the fpga communication manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="instrumentNames"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeFpgaMeasurementManager(List<string> instrumentNames, string instrumentDefFile)
      {
         // create the object once no matter how many times the host calls this
         if (FpgaMeasurementManager == null)
         {
            FpgaMeasurementManager = new FpgaMeasurementManager(InstrumentManager, instrumentNames, instrumentDefFile);
         }
      }

      /// <summary>
      /// Initialize the power system and connect to the power supplies
      /// </summary>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializePowerSupplyMeasurementManager()
      {
         // create the object once no matter how many times the host calls this
         if (PowerSupplyMeasurementManager == null)
         {
            PowerSupplyMeasurementManager = new PowerSupplyMeasurementManager(InstrumentManager);
         }
      }

      /// <summary>
      /// Initialize the relay manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="instrumentNames"></param>
      /// <param name="configFileName"></param>
      public void InitializeRelayMeasurementManager(List<string> instrumentNames, string configFileName)
      {
         // create the object once no matter how many times the host calls this
         if (RelayMeasurementManager == null)
         {
            RelayMeasurementManager = new RelayMeasurementManager(InstrumentManager, instrumentNames, configFileName);
         }
      }

      /// <summary>
      /// Initializes Rf Measurement Manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="switchInstrumentNames"></param>
      /// <param name="powerMeeterName"></param>
      /// <param name="signalGeneratorName"></param>
      /// <param name="specAnalyzerName"></param>
      /// <param name="configFileName"></param>
      public void InitializeRfMeasurementManager(List<string> switchInstrumentNames, string powerMeeterName, string signalGeneratorName, string specAnalyzerName, string configFileName)
      {
         // create the object once no matter how many times the host calls this
         if (RfMeasurementManager == null)
         {
            RfMeasurementManager = new RfMeasurementManager(InstrumentManager, switchInstrumentNames, powerMeeterName, signalGeneratorName, specAnalyzerName, configFileName);
         }
      }

      /// <summary>
      /// Initializes Space Chamber LSPS Measurement Manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="lspsChamber"></param>
      /// <param name="netCdfData"></param>
      public void InitializeSpaceChamberLSPSMeasurementManager(string lspsChamber, string netCdfData)
      {
         // create the object once no matter how many times the host calls this
         if (SpaceChamberLSPSMeasurementManager == null)
         {
            SpaceChamberLSPSMeasurementManager = new SpaceChamberLSPSMeasurementManager(InstrumentManager, lspsChamber, netCdfData);
         }
      }

      /// <summary>
      /// Initializes Switch Measurement Manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="switchCardNames"></param>
      /// <param name="dmmName"></param>
      /// <param name="scopeName"></param>
      /// <param name="configFileName"></param>
      public void InitializeSwitchMeasurementManager()
      {
         // create the object once no matter how many times the host calls this
         if (SwitchMeasurementManager == null)
         {
            SwitchMeasurementManager = new SwitchMeasurementManager(InstrumentManager);
         }
      }

      /// <summary>
      /// Initialize the video recorder manager
      /// </summary>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeVideoRecorderMeasurementManager(string deviceName)
      {
         // create the object once no matter how many times the host calls this
         if (VideoRecorderMeasurementManager == null)
         {
            VideoRecorderMeasurementManager = new VideoRecorderMeasurementManager(InstrumentManager, deviceName);
         }
      }

      /// <summary>
      /// Initializes Cryo Measurement Manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="commDeviceName"></param>
      /// <param name="serialDeviceName"></param>
      /// <param name="isThereHardware"></param>
      /// <param name="errorLogFileName"></param>
      public void InitializeCryoMeasurementManager(string commDeviceName, string serialDeviceName, bool isThereHardware, string errorLogFileName)
      {
         // create the object once no matter how many times the host calls this
         if (CryoMeasurementManager == null)
         {
            CryoMeasurementManager = new CryoMeasurementManager(InstrumentManager, commDeviceName, serialDeviceName, isThereHardware, errorLogFileName);
         }
      }

      /// <summary>
      /// Initializes Optical Bench Measurement Manager
      /// </summary>
      /// <param name="InstrumentManager"></param>
      /// <param name="instrumentName"></param>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeOpticalBenchMeasurementManager(string instrumentName, string measurementDefFile, string instrumentDefFile)
      {
         // create the object once no matter how many times the host calls this
         if (OpticalBenchMeasurementManager == null)
         {
            OpticalBenchMeasurementManager = new OpticalBenchMeasurementManager(InstrumentManager, instrumentName, measurementDefFile, instrumentDefFile);
         }
      }

      /// <summary>
      /// initializes Telemetry Measurement Manager for multiple instruments
      /// </summary>
      /// <param name="measurementDefFile"></param>
      /// <param name="instrumentDefFile"></param>
      public void InitializeTelemetryMeasurementManager(List<string> instrumentNames, string telemetryMalFile)
      {

         // create the object once no matter how many times the host calls this
         if (TelemetryMeasurementManager == null)
         {
            TelemetryMeasurementManager = new TelemetryMeasurementManager(InstrumentManager, instrumentNames, telemetryMalFile);
         }
      }

      #endregion
   }
}
