IOutgoing.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using Edge.Core.Parser;
  2. using Edge.Core.Parser.BinaryParser.MessageEntity;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Threading;
  7. using System.Threading.Tasks;
  8. namespace Edge.Core.Processor
  9. {
  10. public interface IOutgoing<TRaw, TMessage> where TMessage : MessageBase
  11. {
  12. /// <summary>
  13. /// should fire this event when a new message is on writing
  14. /// </summary>
  15. event EventHandler<OutgoingEventArg<TMessage>> OnWriting;
  16. /// <summary>
  17. ///
  18. /// </summary>
  19. /// <param name="request">request to remote peer, which should trigger a response from remote peer.</param>
  20. /// <param name="responseCapture">predict of response correlated to request, first is the request, 2nd is the pending for capture response</param>
  21. /// <param name="callback">when response catpured, or timed out, this callback will be called, first parameter is the request, 2nd is the captured response or null for timed out case</param>
  22. /// <param name="timeout">time out, by ms</param>
  23. void WriteAsync(TMessage request, Func<TMessage, TMessage, bool> responseCapture, Action<TMessage, TMessage> callback, int timeout);
  24. /// <summary>
  25. /// Send an outgoing message to remote device and wait an incoming (responding) message.
  26. /// </summary>
  27. /// <param name="request">request to remote peer, which should trigger a response from remote peer.</param>
  28. /// <param name="responseCapture">predict of response correlated to request, first is the request, 2nd is the pending for capture response</param>
  29. /// <param name="timeout">time out, by ms</param>
  30. /// <returns>a response from remote device</returns>
  31. Task<TMessage> WriteAsync(TMessage request, Func<TMessage, TMessage, bool> responseCapture, int timeout);
  32. void Write(TMessage message);
  33. /// <summary>
  34. ///
  35. /// </summary>
  36. /// <param name="message"></param>
  37. /// <param name="redirectParameter"></param>
  38. void Write(TMessage message, object extraControlParameter);
  39. }
  40. public class OutgoingEventArg<T> : EventArgs
  41. {
  42. public T Message { get; set; }
  43. public object ExtraControlParameter { get; set; }
  44. }
  45. //public class BinaryOutgoing<TMessage> : Outgoing<byte[], TMessage> where TMessage : MessageTemplateBase
  46. //{
  47. // public BinaryOutgoing(ICommunicator<byte[], TMessage> communicator) : base(communicator)
  48. // {
  49. // }
  50. // public override void Write(TMessage message)
  51. // {
  52. // }
  53. //}
  54. }