OutputListener.cs 843 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. namespace sccdlib
  4. {
  5. public class OutputListener : IOutputListener
  6. {
  7. Queue<Event> queue = new Queue<Event>();
  8. List<string> ports = new List<string>();
  9. public OutputListener (string[] port_names)
  10. {
  11. foreach (string port_name in port_names)
  12. {
  13. this.ports.Add (port_name);
  14. }
  15. }
  16. public void add (Event output_event)
  17. {
  18. if (this.ports.Count == 0 || this.ports.Contains (output_event.getPort ())) {
  19. this.queue.Enqueue (output_event);
  20. }
  21. }
  22. public Event fetch ()
  23. {
  24. if (this.queue.Count > 0)
  25. return this.queue.Dequeue ();
  26. return null;
  27. }
  28. }
  29. }