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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
|
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<Request>(ITransporter transporter, Request request, String token);
/// <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>
/// Gets the last failed state exception/reason.
/// </summary>
Exception FailedStateException { get; }
/// <summary>
/// Gets or sets the generic protocol used to serialize/deserialize generic messages.
/// </summary>
GenericMessageProtocol GenericProtocol { get; set; }
/// <summary>
/// Registers a custom request handler.
/// </summary>
/// <typeparam name="Request">The type of the request.</typeparam>
/// <param name="callback">The callback.</param>
void RegisterRequestHandler<Request>(RequestHandlerCallbackDelegate<Request> callback) where Request : class;
/// <summary>
/// Unregisters a custom request handler.
/// </summary>
/// <typeparam name="Request">The type of the request.</typeparam>
/// <param name="callback">The callback.</param>
void UnregisterRequestHandler<Request>(RequestHandlerCallbackDelegate<Request> callback) where Request : class;
/// <summary>
/// Copies this instance request handlers to the specified instance.
/// </summary>
/// <param name="transporter">The transporter to copy the handlers to.</param>
void CopyRequestHandlers(ITransporter transporter);
/// <summary>
/// Sends a request.
/// </summary>
/// <param name="request">The request.</param>
/// <param name="config">Request configuration.</param>
/// <returns></returns>
Task<IMessage> SendRequest(IMessage request, TransportRequestConfig config = null);
/// <summary>
/// Sends the request.
/// </summary>
/// <param name="config">Request configuration.</param>
/// <returns></returns>
Task<MessageContainer> SendRequest(MessageContainer container, TransportRequestConfig config = null);
/// <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="config">Request configuration.</param>
/// <returns></returns>
Task<TangoMessage<Response>> SendRequest<Request, Response>(TangoMessage<Request> request, TransportRequestConfig config = null) where Request : IMessage<Request> where Response : IMessage<Response>;
/// <summary>
/// Sends a continuous request.
/// </summary>
/// <param name="container">The container.</param>
/// <param name="config">Request configuration.</param>
/// <returns></returns>
IObservable<MessageContainer> SendContinuousRequest(MessageContainer container, TransportContinuousRequestConfig config = null);
/// <summary>
/// Sends a request and expecting multiple response messages.
/// </summary>
/// <param name="config">Request configuration.</param>
/// <returns></returns>
IObservable<IMessage> SendContinuousRequest(IMessage request, TransportContinuousRequestConfig config = null);
/// <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="config">Request configuration.</param>
/// <returns></returns>
IObservable<TangoMessage<Response>> SendContinuousRequest<Request, Response>(TangoMessage<Request> request, TransportContinuousRequestConfig config = null) where Request : IMessage<Request> where Response : IMessage<Response>;
/// <summary>
/// Sends a generic request of any type.
/// </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="config">The configuration.</param>
/// <returns></returns>
Task<Response> SendGenericRequest<Request, Response>(Request request, TransportRequestConfig config = null) where Request : class where Response : class;
/// <summary>
/// Sends a generic response.
/// </summary>
/// <typeparam name="Response">The type of the response.</typeparam>
/// <param name="response">The response.</param>
/// <param name="token">The request token.</param>
/// <param name="config">The response configuration.</param>
/// <returns></returns>
Task SendGenericResponse<Response>(Response response, String token, TransportResponseConfig config = null) where Response : class;
/// <summary>
/// Sends a generic request and expecting multiple generic response messages.
/// </summary>
/// <typeparam name="Request">The type of the request.</typeparam>
/// <typeparam name="Response">The type of the response.</typeparam>
/// <param name="config">Request configuration.</param>
/// <returns></returns>
IObservable<Response> SendGenericContinuousRequest<Request, Response>(Request request, TransportContinuousRequestConfig config = null) where Request : class where Response : class;
/// <summary>
/// Sends the response.
/// </summary>
/// <param name="container">The container.</param>
/// <returns></returns>
Task SendResponse(MessageContainer container, TransportResponseConfig config = null);
/// <summary>
/// Sends the response.
/// </summary>
/// <param name="response">Request token.</param>
/// <param name="config">Response configuration.</param>
/// <returns></returns>
Task SendResponse(IMessage response, String token, TransportResponseConfig config = null);
/// <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.
/// </summary>
/// <typeparam name="Response">The type of the response.</typeparam>
/// <param name="response">The response.</param>
/// <param name="token">Request token.</param>
/// <param name="config">Response configuration.</param>
/// <returns></returns>
Task SendResponse<Response>(TangoMessage<Response> response, String token, TransportResponseConfig config = null) where Response : IMessage<Response>;
/// <summary>
/// Sends a general error response agnostic to the type of request.
/// </summary>
/// <param name="exception">The exception.</param>
/// <param name="token">Request token.</param>
/// <returns></returns>
Task SendErrorResponse(Exception exception, String token);
/// <summary>
/// Clears all message queues.
/// </summary>
void ClearQueues();
/// <summary>
/// Occurs when a new request message has been received.
/// </summary>
event EventHandler<RequestReceivedEventArgs> RequestReceived;
/// <summary>
/// Occurs when a new response message has been received.
/// </summary>
event EventHandler<MessageContainer> PendingResponseReceived;
/// <summary>
/// Occurs when a request has been sent.
/// </summary>
event EventHandler<IMessage> RequestSent;
/// <summary>
/// Occurs when a request response has been received.
/// </summary>
event EventHandler<IMessage> ResponseReceived;
/// <summary>
/// Occurs when a request has failed.
/// </summary>
event EventHandler<RequestFailedEventArgs> RequestFailed;
/// <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 the keep alive timeout.
/// </summary>
TimeSpan KeepAliveTimeout { get; set; }
/// <summary>
/// Gets or sets the keep alive retries.
/// </summary>
int KeepAliveRetries { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to auto respond to keep alive requests.
/// </summary>
bool EnableKeepAliveAutoResponse { 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; }
}
}
|