//                           UNCLASSIFIED
/*-------------------------------------------------------------------------
RAYTHEON PROPRIETARY: THIS DOCUMENT CONTAINS DATA OR INFORMATION
PROPRIETARY TO RAYTHEON COMPANY AND IS RESTRICTED TO USE ONLY BY PERSONS
AUTHORIZED BY RAYTHEON COMPANY IN WRITING TO USE IT. DISCLOSURE TO
UNAUTHORIZED PERSONS WOULD LIKELY CAUSE SUBSTANTIAL COMPETITIVE HARM TO
RAYTHEON COMPANY'S BUSINESS POSITION. NEITHER SAID DOCUMENT NOR ITS
CONTENTS SHALL BE FURNISHED OR DISCLOSED TO OR COPIED OR USED BY PERSONS
OUTSIDE RAYTHEON COMPANY WITHOUT THE EXPRESS WRITTEN APPROVAL OF RAYTHEON
COMPANY.

THIS PROPRIETARY NOTICE IS NOT APPLICABLE IF DELIVERED TO THE U.S.
GOVERNMENT.

UNPUBLISHED WORK - COPYRIGHT RAYTHEON COMPANY.
-------------------------------------------------------------------------*/

using Raytheon.Common;
using System;

namespace BitMeasurementManagerLib
{
   /// <summary>
   /// Singleton for holding onto message objects
   /// </summary>
   internal class BitMsgEndianControl
   {
      #region PublicMembers
      public struct HeaderDef
      {
         public int msgIdByteLocation;
         public int msgIdDataLen;
         public int secondaryMsgIdByteLocation;
         public int secondaryMsgIdDataLen;
         public uint secondaryMsgIdExpectedValue;
      };
      #endregion

      #region PrivateClassMembers
      // class variables
      private static BitMsgEndianControl _msgEndianControlInstance;
      private bool _shallWeSwap;
      private HeaderDef _headerDef;
      #endregion

      #region PrivateFuctions
      /// <summary>
      /// The constructor
      /// </summary>
      private BitMsgEndianControl(bool shallWeSwap, IniFile defFile)
      {
         _shallWeSwap = shallWeSwap;

         _headerDef.msgIdByteLocation = Convert.ToInt32(defFile.ReadValue("MSG_HEADER_DEF", "MSG_ID_LOCATION"));
         _headerDef.msgIdDataLen = Convert.ToInt32(defFile.ReadValue("MSG_HEADER_DEF", "MSG_ID_DATA_LEN"));
         _headerDef.secondaryMsgIdByteLocation = Convert.ToInt32(defFile.ReadValue("MSG_HEADER_DEF", "SECONDARY_MSG_ID_LOCATION"));
         _headerDef.secondaryMsgIdDataLen = Convert.ToInt32(defFile.ReadValue("MSG_HEADER_DEF", "SECONDARY_MSG_ID_DATA_LEN"));
         _headerDef.secondaryMsgIdExpectedValue = Convert.ToUInt32(defFile.ReadValue("MSG_HEADER_DEF", "SECONDARY_MSG_ID_EXPECTED_VALUE"), 16);
      }
      #endregion

      #region PublicFuctions

      /// <summary>
      /// The way to get access to this singleton
      /// <param name="shallWeSwap"></param>
      /// <returns>the instance to this class</returns>
      internal static BitMsgEndianControl Instance(bool shallWeSwap = true, IniFile defFile = null)
      {
         if (_msgEndianControlInstance == null)
         {
            _msgEndianControlInstance = new BitMsgEndianControl(shallWeSwap, defFile);
         }

         return _msgEndianControlInstance;
      }

      /// <summary>
      /// 
      /// </summary>
      /// <returns></returns>
      internal HeaderDef GetHeaderDef()
      {
         return _headerDef;
      }

      /// <summary>
      /// 
      /// </summary>
      /// <returns></returns>
      internal bool ShallWeSwap()
      {
         return _shallWeSwap;
      }
      #endregion
   }
}
