blob: 98db8546144bf95c03cc3a134eef653f0241c593 [file] [log] [blame]
Jan Tattermuscha7fff862015-02-13 11:08:08 -08001#region Copyright notice and license
2
Craig Tiller6169d5f2016-03-31 07:46:18 -07003// Copyright 2015, Google Inc.
Jan Tattermuscha7fff862015-02-13 11:08:08 -08004// All rights reserved.
Craig Tiller190d3602015-02-18 09:23:38 -08005//
Jan Tattermuscha7fff862015-02-13 11:08:08 -08006// Redistribution and use in source and binary forms, with or without
7// modification, are permitted provided that the following conditions are
8// met:
Craig Tiller190d3602015-02-18 09:23:38 -08009//
Jan Tattermuscha7fff862015-02-13 11:08:08 -080010// * Redistributions of source code must retain the above copyright
11// notice, this list of conditions and the following disclaimer.
12// * Redistributions in binary form must reproduce the above
13// copyright notice, this list of conditions and the following disclaimer
14// in the documentation and/or other materials provided with the
15// distribution.
16// * Neither the name of Google Inc. nor the names of its
17// contributors may be used to endorse or promote products derived from
18// this software without specific prior written permission.
Craig Tiller190d3602015-02-18 09:23:38 -080019//
Jan Tattermuscha7fff862015-02-13 11:08:08 -080020// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32#endregion
33
Jan Tattermuscha7608b02015-02-03 17:54:38 -080034using System;
Jan Tattermusch30868622015-02-19 09:22:33 -080035using Grpc.Core.Internal;
Jan Tattermuschc0b37212015-03-13 08:35:41 -070036using Grpc.Core.Utils;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080037
Jan Tattermusch30868622015-02-19 09:22:33 -080038namespace Grpc.Core
Jan Tattermuscha7608b02015-02-03 17:54:38 -080039{
Jan Tattermuscha5272b62015-04-30 11:56:46 -070040 /// <summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070041 /// Details about a client-side call to be invoked.
Jan Tattermuscha5272b62015-04-30 11:56:46 -070042 /// </summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070043 /// <typeparam name="TRequest">Request message type for the call.</typeparam>
44 /// <typeparam name="TResponse">Response message type for the call.</typeparam>
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070045 public struct CallInvocationDetails<TRequest, TResponse>
Jan Tattermuscha7608b02015-02-03 17:54:38 -080046 {
Jan Tattermuscha7608b02015-02-03 17:54:38 -080047 readonly Channel channel;
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070048 readonly string method;
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070049 readonly string host;
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -070050 readonly Marshaller<TRequest> requestMarshaller;
51 readonly Marshaller<TResponse> responseMarshaller;
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070052 CallOptions options;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080053
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070054 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070055 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070056 /// </summary>
57 /// <param name="channel">Channel to use for this call.</param>
58 /// <param name="method">Method to call.</param>
59 /// <param name="options">Call options.</param>
Jan Tattermusch5c371f82015-08-05 14:55:17 -070060 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, CallOptions options) :
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070061 this(channel, method, null, options)
62 {
63 }
64
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070065 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070066 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070067 /// </summary>
68 /// <param name="channel">Channel to use for this call.</param>
69 /// <param name="method">Method to call.</param>
70 /// <param name="host">Host that contains the method. if <c>null</c>, default host will be used.</param>
71 /// <param name="options">Call options.</param>
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070072 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, string host, CallOptions options) :
73 this(channel, method.FullName, host, method.RequestMarshaller, method.ResponseMarshaller, options)
Jan Tattermusch075dde42015-03-11 18:21:00 -070074 {
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070075 }
76
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070077 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -070078 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct.
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070079 /// </summary>
80 /// <param name="channel">Channel to use for this call.</param>
81 /// <param name="method">Qualified method name.</param>
82 /// <param name="host">Host that contains the method.</param>
83 /// <param name="requestMarshaller">Request marshaller.</param>
84 /// <param name="responseMarshaller">Response marshaller.</param>
85 /// <param name="options">Call options.</param>
Jan Tattermusch5c371f82015-08-05 14:55:17 -070086 public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options)
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070087 {
Jan Tattermusch7a3ee6a2016-02-18 10:36:02 -080088 this.channel = GrpcPreconditions.CheckNotNull(channel, "channel");
89 this.method = GrpcPreconditions.CheckNotNull(method, "method");
Jan Tattermuschcc97fed2015-08-05 00:44:29 -070090 this.host = host;
Jan Tattermusch7a3ee6a2016-02-18 10:36:02 -080091 this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller");
92 this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller");
Jan Tattermusch9698b5b2015-08-10 16:40:19 -070093 this.options = options;
Jan Tattermusch8ce5e8b2015-02-05 10:56:49 -080094 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -080095
Jan Tattermusch1b926ee2015-08-10 22:51:29 -070096 /// <summary>
97 /// Get channel associated with this call.
98 /// </summary>
Jan Tattermuscha7608b02015-02-03 17:54:38 -080099 public Channel Channel
100 {
101 get
102 {
103 return this.channel;
104 }
105 }
106
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700107 /// <summary>
108 /// Gets name of method to be called.
109 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -0700110 public string Method
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800111 {
112 get
113 {
Jan Tattermuschcc97fed2015-08-05 00:44:29 -0700114 return this.method;
115 }
116 }
117
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700118 /// <summary>
119 /// Get name of host.
120 /// </summary>
Jan Tattermuschcc97fed2015-08-05 00:44:29 -0700121 public string Host
122 {
123 get
124 {
125 return this.host;
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800126 }
127 }
128
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700129 /// <summary>
130 /// Gets marshaller used to serialize requests.
131 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -0700132 public Marshaller<TRequest> RequestMarshaller
133 {
134 get
135 {
136 return this.requestMarshaller;
137 }
138 }
139
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700140 /// <summary>
141 /// Gets marshaller used to deserialized responses.
142 /// </summary>
Jan Tattermusch5cb5ced2015-08-05 04:05:57 -0700143 public Marshaller<TResponse> ResponseMarshaller
144 {
145 get
146 {
147 return this.responseMarshaller;
148 }
149 }
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700150
Jan Tattermusch1b926ee2015-08-10 22:51:29 -0700151 /// <summary>
152 /// Gets the call options.
153 /// </summary>
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700154 public CallOptions Options
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800155 {
156 get
157 {
Jan Tattermusch5c371f82015-08-05 14:55:17 -0700158 return options;
Jan Tattermusch0846b682015-07-23 17:02:12 -0700159 }
160 }
Jan Tattermusch9698b5b2015-08-10 16:40:19 -0700161
162 /// <summary>
Jan Tattermusch12855fc2015-08-24 16:43:23 -0700163 /// Returns new instance of <see cref="CallInvocationDetails{TRequest, TResponse}"/> with
Jan Tattermusch9698b5b2015-08-10 16:40:19 -0700164 /// <c>Options</c> set to the value provided. Values of all other fields are preserved.
165 /// </summary>
166 public CallInvocationDetails<TRequest, TResponse> WithOptions(CallOptions options)
167 {
168 var newDetails = this;
169 newDetails.options = options;
170 return newDetails;
171 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800172 }
173}