Example #1
0
 /// <summary>
 /// Sends the sentence to all our clients.
 /// If it is needed to make distinctions for what needs to be sent to which client, create
 /// multiple server instances. This will allow for proper filtering.
 /// </summary>
 /// <param name="source">The original source of the message, used i.e. for logging</param>
 /// <param name="sentence">The sentence to send</param>
 public override void SendSentence(NmeaSinkAndSource source, NmeaSentence sentence)
 {
     lock (_activeParsers)
     {
         // Clone, because in case of an error, the list may change
         var parsers = _activeParsers.ToList();
         foreach (var parser in parsers)
         {
             try
             {
                 parser.SendSentence(source, sentence);
             }
             catch (IOException x)
             {
                 FireOnParserError($"Error sending message to {parser.InterfaceName}: {x.Message}", NmeaError.PortClosed);
             }
         }
     }
 }
Example #2
0
        private void ParserOnParserError(NmeaSinkAndSource source, string message, NmeaError errorCode)
        {
            if (errorCode == NmeaError.PortClosed)
            {
                Task t = Task.Run(() =>
                {
                    lock (_lock)
                    {
                        _activeParsers.Remove(source);
                    }

                    // Can't do this synchronously, as it would cause a deadlock
                    source.StopDecode();
                });
                _serverTasks.Enqueue(t);
                _serverControlEvent.Set();
            }

            FireOnParserError(message, errorCode);
        }
Example #3
0
 private void ForwardDecoded(NmeaSinkAndSource source, NmeaSentence sentence)
 {
     DispatchSentenceEvents(sentence);
 }
Example #4
0
 /// <inheritdoc />
 public override void SendSentence(NmeaSinkAndSource source, NmeaSentence sentence)
 {
 }