using SIASUN.Autopilot.EventMessage;
using System;
using System.Threading;


namespace SIASUN.Autopilot.Device.EventMessage
{
    public sealed class EventMessages
    {
        public static EventMessages Instance = null;

        public event EventHandler<MessageEventArgs> newMessages;

        private EventMessages()
        {     
        }

        public static EventMessages GetSingleton()
        {
            if (Instance != null)
                return Instance;

            EventMessages temp = new EventMessages();
            Interlocked.CompareExchange(ref Instance, temp, null);
            return Instance;
        }

        public void Publish(string mfrom, string mtype, string message)
        {
            OnNewMessage(new MessageEventArgs(mfrom, mtype, message));
        }

        private void OnNewMessage(MessageEventArgs e)
        {
            e.Raise(this, ref newMessages);
        }

    }
}
