using Google.Protobuf; using System; using System.Collections.Generic; using System.Linq; using System.Reactive; using System.Reactive.Linq; using System.Text; using System.Threading.Tasks; using Tango.Transport.Adapters; using Tango.PMR; using Tango.PMR.Common; using System.Collections.ObjectModel; using Tango.PMR.Integration; namespace Tango.Transport { public delegate void RequestHandlerCallbackDelegate(ITransporter transporter, Request request, String token); /// /// Represents a transportation engine which can send and receive message using a Transport adapter. /// /// public interface ITransporter : ITransportComponent { /// /// Gets or sets the used to read and write raw data. /// ITransportAdapter Adapter { get; set; } /// /// Gets or sets the transport encoder used to encode and decode tango messages. /// ITransportEncoder Encoder { get; set; } /// /// Gets the last failed state exception/reason. /// Exception FailedStateException { get; } /// /// Gets or sets the generic protocol used to serialize/deserialize generic messages. /// GenericMessageProtocol GenericProtocol { get; set; } /// /// Registers a custom request handler. /// /// The type of the request. /// The callback. void RegisterRequestHandler(RequestHandlerCallbackDelegate callback) where Request : class; /// /// Unregisters a custom request handler. /// /// The type of the request. /// The callback. void UnregisterRequestHandler(RequestHandlerCallbackDelegate callback) where Request : class; /// /// Copies this instance request handlers to the specified instance. /// /// The transporter to copy the handlers to. void CopyRequestHandlers(ITransporter transporter); /// /// Sends a request. /// /// The request. /// Request configuration. /// Task SendRequest(IMessage request, TransportRequestConfig config = null); /// /// Sends the request. /// /// Request configuration. /// Task SendRequest(MessageContainer container, TransportRequestConfig config = null); /// /// Sends a request. /// /// The type of the request. /// The type of the response. /// The request. /// Request configuration. /// Task> SendRequest(TangoMessage request, TransportRequestConfig config = null) where Request : IMessage where Response : IMessage; /// /// Sends a continuous request. /// /// The container. /// Request configuration. /// IObservable SendContinuousRequest(MessageContainer container, TransportContinuousRequestConfig config = null); /// /// Sends a request and expecting multiple response messages. /// /// Request configuration. /// IObservable SendContinuousRequest(IMessage request, TransportContinuousRequestConfig config = null); /// /// Sends a request and expecting multiple response messages. /// /// The type of the request. /// The type of the response. /// Request configuration. /// IObservable> SendContinuousRequest(TangoMessage request, TransportContinuousRequestConfig config = null) where Request : IMessage where Response : IMessage; /// /// Sends a generic request of any type. /// /// The type of the request. /// The type of the response. /// The request. /// The configuration. /// Task SendGenericRequest(Request request, TransportRequestConfig config = null) where Request : class where Response : class; /// /// Sends a generic response. /// /// The type of the response. /// The response. /// The request token. /// The response configuration. /// Task SendGenericResponse(Response response, String token, TransportResponseConfig config = null) where Response : class; /// /// Sends a generic request and expecting multiple generic response messages. /// /// The type of the request. /// The type of the response. /// Request configuration. /// IObservable SendGenericContinuousRequest(Request request, TransportContinuousRequestConfig config = null) where Request : class where Response : class; /// /// Sends the response. /// /// The container. /// Task SendResponse(MessageContainer container, TransportResponseConfig config = null); /// /// Sends the response. /// /// Request token. /// Response configuration. /// Task SendResponse(IMessage response, String token, TransportResponseConfig config = null); /// /// Sends a response. /// /// The type of the response. /// The response. /// Task SendResponse(TangoMessage response) where Response : IMessage; /// /// Sends a response. /// /// The type of the response. /// The response. /// Request token. /// Response configuration. /// Task SendResponse(TangoMessage response, String token, TransportResponseConfig config = null) where Response : IMessage; /// /// Sends a general error response agnostic to the type of request. /// /// The exception. /// Request token. /// Task SendErrorResponse(Exception exception, String token); /// /// Clears all message queues. /// void ClearQueues(); /// /// Occurs when a new request message has been received. /// event EventHandler RequestReceived; /// /// Occurs when a new response message has been received. /// event EventHandler PendingResponseReceived; /// /// Occurs when a request has been sent. /// event EventHandler RequestSent; /// /// Occurs when a request response has been received. /// event EventHandler ResponseReceived; /// /// Occurs when a request has failed. /// event EventHandler RequestFailed; /// /// Gets or sets the default request timeout. /// TimeSpan RequestTimeout { get; set; } /// /// Gets or sets a value indicating whether to use a keep alive mechanism. /// bool UseKeepAlive { get; set; } /// /// Gets or sets the keep alive timeout. /// TimeSpan KeepAliveTimeout { get; set; } /// /// Gets or sets the keep alive retries. /// int KeepAliveRetries { get; set; } /// /// Gets or sets a value indicating whether to auto respond to keep alive requests. /// bool EnableKeepAliveAutoResponse { get; set; } /// /// Gets or sets a value indicating whether the transporter will get in to a failed state if the has failed. /// bool FailsWithAdapter { get; set; } } }