using DTS.Common.Interface.DASFactory; using System.Collections.Generic; namespace DTS.DASLib.Service.StateMachine { public class GlobalStatusInformation : IStatusInfo { private static readonly object MyLock = new object(); private List _unitsInRealtime = new List(); /// /// returns an array of all devices that are known to be in realtime /// /// public IDASCommunication[] GetUnitsInRealtime() { lock (MyLock) { return _unitsInRealtime.ToArray(); } } /// /// adds a device to the list of units known to be in realtime /// /// public void AddUnitInRealtime(IDASCommunication device) { lock (MyLock) { if (_unitsInRealtime.Contains(device)) { return; } _unitsInRealtime.Add(device); } } private List _unitsInArm = new List(); /// /// returns an array of units known to be in arm /// /// public IDASCommunication[] GetUnitsInArm() { lock (MyLock) { return _unitsInArm.ToArray(); } } /// /// adds a device to the list of devices known to be in arm /// /// public void AddUnitInArm(IDASCommunication device) { lock (MyLock) { if (_unitsInArm.Contains(device)) { return; } _unitsInArm.Add(device); } } private List _unitsAtLowPower = new List(); /// /// returns an array of all known devices that are at low power /// /// public IDASCommunication[] GetUnitsAtLowPower() { lock (MyLock) { return _unitsAtLowPower.ToArray(); } } /// /// adds a unit to the list of units currently at low power /// removes from high power list if present in it /// /// public void AddUnitAtLowPower(IDASCommunication das) { lock (MyLock) { if (_unitsAtLowPower.Contains(das)) { return; } _unitsAtLowPower.Add(das); if (!_unitsAtHighPower.Contains(das)) { return; } _unitsAtHighPower.Remove(das); } } private List _unitsAtHighPower = new List(); /// /// returns an array of all units that are known to be at high power /// /// public IDASCommunication[] GetUnitsAtHighPower() { lock (MyLock) { return _unitsAtHighPower.ToArray(); } } /// /// adds unit to the list of devices known to be at high power /// removes from the low power list if present /// /// public void AddUnitAtHighPower(IDASCommunication das) { lock (MyLock) { if (_unitsAtHighPower.Contains(das)) { return; } _unitsAtHighPower.Add(das); if (!_unitsAtLowPower.Contains(das)) { return; } _unitsAtLowPower.Remove(das); } } /// /// whether excitation is on or off, currently this is just /// controlled by Configure->TurnOffExcitation and Configure->PrepareForDiagnostics /// the status is only changed currently if all units successfully switch to low power or vice versa /// public bool ExcitationOn { get; set; } = false; /// /// resets all status back to defaults /// public void Reset() { ExcitationOn = false; lock (MyLock) { _unitsAtHighPower.Clear(); _unitsAtLowPower.Clear(); _unitsInRealtime.Clear(); _unitsInArm.Clear(); } } } }