blob: a4c04132daa9e95dcb47ea94393fb1f4852f43a0 [file] [log] [blame]
Jan Tattermuscha7fff862015-02-13 11:08:08 -08001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Craig Tiller190d3602015-02-18 09:23:38 -08004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
Craig Tiller190d3602015-02-18 09:23:38 -08008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller190d3602015-02-18 09:23:38 -080010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
Jan Tattermuscha7fff862015-02-13 11:08:08 -080016
17#endregion
18
Jan Tattermuscha7608b02015-02-03 17:54:38 -080019using System;
Jan Tattermusch30868622015-02-19 09:22:33 -080020using Grpc.Core.Internal;
Jan Tattermuschc0b37212015-03-13 08:35:41 -070021using Grpc.Core.Utils;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080022
Jan Tattermusch30868622015-02-19 09:22:33 -080023namespace Grpc.Core
Jan Tattermuscha7608b02015-02-03 17:54:38 -080024{
Jan Tattermuscha5272b62015-04-30 11:56:46 -070025 /// <summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070026 /// Details about a client-side call to be invoked.
Jan Tattermuscha5272b62015-04-30 11:56:46 -070027 /// </summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070028 /// <typeparam name="TRequest">Request message type for the call.</typeparam>
29 /// <typeparam name="TResponse">Response message type for the call.</typeparam>
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070030 public struct CallInvocationDetails<TRequest, TResponse>
Jan Tattermuscha7608b02015-02-03 17:54:38 -080031 {
Jan Tattermuscha7608b02015-02-03 17:54:38 -080032 readonly Channel channel;
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070033 readonly string method;
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070034 readonly string host;
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070035 readonly Marshaller<TRequest> requestMarshaller;
36 readonly Marshaller<TResponse> responseMarshaller;
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070037 CallOptions options;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080038
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070039 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070040 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070041 /// </summary>
42 /// <param name="channel">Channel to use for this call.</param>
43 /// <param name="method">Method to call.</param>
44 /// <param name="options">Call options.</param>
Jan Tattermusch5c371f82015-08-05 14:55:17 -070045 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, CallOptions options) :
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070046 this(channel, method, null, options)
47 {
48 }
49
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070050 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070051 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070052 /// </summary>
53 /// <param name="channel">Channel to use for this call.</param>
54 /// <param name="method">Method to call.</param>
55 /// <param name="host">Host that contains the method. if <c>null</c>, default host will be used.</param>
56 /// <param name="options">Call options.</param>
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070057 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, string host, CallOptions options) :
58 this(channel, method.FullName, host, method.RequestMarshaller, method.ResponseMarshaller, options)
Jan Tattermusch075dde42015-03-11 18:21:00 -070059 {
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070060 }
61
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070062 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070063 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070064 /// </summary>
65 /// <param name="channel">Channel to use for this call.</param>
66 /// <param name="method">Qualified method name.</param>
67 /// <param name="host">Host that contains the method.</param>
68 /// <param name="requestMarshaller">Request marshaller.</param>
69 /// <param name="responseMarshaller">Response marshaller.</param>
70 /// <param name="options">Call options.</param>
Jan Tattermusch5c371f82015-08-05 14:55:17 -070071 public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options)
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070072 {
Jan Tattermusch7a3ee6a2016-02-18 10:36:02 -080073 this.channel = GrpcPreconditions.CheckNotNull(channel, "channel");
74 this.method = GrpcPreconditions.CheckNotNull(method, "method");
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070075 this.host = host;
Jan Tattermusch7a3ee6a2016-02-18 10:36:02 -080076 this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
77 this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070078 this.options = options;
Jan Tattermusch8ce5e8b2015-02-05 10:56:49 -080079 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -080080
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070081 /// <summary>
82 /// Get channel associated with this call.
83 /// </summary>
Jan Tattermuscha7608b02015-02-03 17:54:38 -080084 public Channel Channel
85 {
86 get
87 {
88 return this.channel;
89 }
90 }
91
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070092 /// <summary>
93 /// Gets name of method to be called.
94 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070095 public string Method
Jan Tattermuscha7608b02015-02-03 17:54:38 -080096 {
97 get
98 {
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070099 return this.method;
100 }
101 }
102
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700103 /// <summary>
104 /// Get name of host.
105 /// </summary>
Jan Tattermuschcc97fed2015-08-05 00:44:29 -0700106 public string Host
107 {
108 get
109 {
110 return this.host;
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800111 }
112 }
113
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700114 /// <summary>
115 /// Gets marshaller used to serialize requests.
116 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -0700117 public Marshaller<TRequest> RequestMarshaller
118 {
119 get
120 {
121 return this.requestMarshaller;
122 }
123 }
124
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700125 /// <summary>
126 /// Gets marshaller used to deserialized responses.
127 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -0700128 public Marshaller<TResponse> ResponseMarshaller
129 {
130 get
131 {
132 return this.responseMarshaller;
133 }
134 }
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700135
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700136 /// <summary>
137 /// Gets the call options.
138 /// </summary>
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700139 public CallOptions Options
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800140 {
141 get
142 {
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700143 return options;
Jan Tattermusch0846b682015-07-23 17:02:12 -0700144 }
145 }
Jan Tattermusch9698b5b2015-08-10 16:40:19 -0700146
147 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -0700148 /// Returns new instance of <see cref="CallInvocationDetails{TRequest, TResponse}"/> with
Jan Tattermusch9698b5b2015-08-10 16:40:19 -0700149 /// <c>Options</c> set to the value provided. Values of all other fields are preserved.
150 /// </summary>
151 public CallInvocationDetails<TRequest, TResponse> WithOptions(CallOptions options)
152 {
153 var newDetails = this;
154 newDetails.options = options;
155 return newDetails;
156 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800157 }
158}