aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Transport/ITransporter.cs
blob: 1861ae6a3424bf1a5e55a1cbed748384e1226c87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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;

namespace Tango.Transport
{
    /// <summary>
    /// Represents a transportation engine which can send and receive <see cref="TangoMessage{T}"/> message using a <see cref="ITransportAdapter">Transport adapter</see>.
    /// </summary>
    /// <seealso cref="Tango.Transport.ITransportComponent" />
    public interface ITransporter : ITransportComponent
    {
        /// <summary>
        /// Gets or sets the <see cref="ITransportAdapter"/> used to read and write raw data.
        /// </summary>
        ITransportAdapter Adapter { get; set; }

        /// <summary>
        /// Gets or sets the transport encoder used to encode and decode tango messages.
        /// </summary>
        ITransportEncoder Encoder { get; set; }

        /// <summary>
        /// Sends a request.
        /// </summary>
        /// <typeparam name="Request">The type of the request.</typeparam>
        /// <typeparam name="Response">The type of the response.</typeparam>
        /// <param name="request">The request.</param>
        /// <param name="timeout">Optional timeout. If not specified will use the <see cref="RequestTimeout"/>.</param>
        /// <returns></returns>
        Task<TangoMessage<Response>> SendRequest<Request, Response>(TangoMessage<Request> request, TimeSpan? timeout = null) where Request : IMessage<Request> where Response : IMessage<Response>;

        /// <summary>
        /// Sends a request and expecting multiple response messages.
        /// </summary>
        /// <typeparam name="Request">The type of the request.</typeparam>
        /// <typeparam name="Response">The type of the response.</typeparam>
        /// <param name="request">The request.</param>
        /// <returns></returns>
        IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request, TimeSpan? timeout = null) where Request : IMessage<Request> where Response : IMessage<Response>;

        /// <summary>
        /// Sends a response.
        /// </summary>
        /// <typeparam name="Response">The type of the response.</typeparam>
        /// <param name="response">The response.</param>
        /// <returns></returns>
        Task SendResponse<Response>(TangoMessage<Response> response) where Response : IMessage<Response>;

        /// <summary>
        /// Sends a response for the specified token.
        /// </summary>
        /// <typeparam name="Response">The type of the response.</typeparam>
        /// <param name="response">The response.</param>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        Task SendResponse<Response>(TangoMessage<Response> response, String token, bool? completed = null, ErrorCode? errorCode = null) where Response : IMessage<Response>;

        /// <summary>
        /// Occurs when a new request message has been received.
        /// </summary>
        event EventHandler<MessageContainer> RequestReceived;

        /// <summary>
        /// Gets or sets the default request timeout.
        /// </summary>
        TimeSpan RequestTimeout { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to use a keep alive mechanism.
        /// </summary>
        bool UseKeepAlive { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the transporter will get in to a failed state if the <see cref="Adapter"/> has failed.
        /// </summary>
        bool FailsWithAdapter { get; set; }
    }
}