1 #region Copyright notice and license 2 3 // Copyright 2015 gRPC authors. 4 // 5 // 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 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // 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. 16 17 #endregion 18 19 using System; 20 using Grpc.Core.Internal; 21 using Grpc.Core.Utils; 22 23 namespace Grpc.Core 24 { 25 /// <summary> 26 /// Details about a client-side call to be invoked. 27 /// </summary> 28 /// <typeparam name="TRequest">Request message type for the call.</typeparam> 29 /// <typeparam name="TResponse">Response message type for the call.</typeparam> 30 public struct CallInvocationDetails<TRequest, TResponse> 31 { 32 readonly Channel channel; 33 readonly string method; 34 readonly string host; 35 readonly Marshaller<TRequest> requestMarshaller; 36 readonly Marshaller<TResponse> responseMarshaller; 37 CallOptions options; 38 39 /// <summary> 40 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. 41 /// </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> CallInvocationDetailsGrpc.Core.CallInvocationDetails45 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, CallOptions options) : 46 this(channel, method, null, options) 47 { 48 } 49 50 /// <summary> 51 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. 52 /// </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> CallInvocationDetailsGrpc.Core.CallInvocationDetails57 public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, string host, CallOptions options) : 58 this(channel, method.FullName, host, method.RequestMarshaller, method.ResponseMarshaller, options) 59 { 60 } 61 62 /// <summary> 63 /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. 64 /// </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> CallInvocationDetailsGrpc.Core.CallInvocationDetails71 public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options) 72 { 73 this.channel = GrpcPreconditions.CheckNotNull(channel, "channel"); 74 this.method = GrpcPreconditions.CheckNotNull(method, "method"); 75 this.host = host; 76 this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); 77 this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); 78 this.options = options; 79 } 80 81 /// <summary> 82 /// Get channel associated with this call. 83 /// </summary> 84 public Channel Channel 85 { 86 get 87 { 88 return this.channel; 89 } 90 } 91 92 /// <summary> 93 /// Gets name of method to be called. 94 /// </summary> 95 public string Method 96 { 97 get 98 { 99 return this.method; 100 } 101 } 102 103 /// <summary> 104 /// Get name of host. 105 /// </summary> 106 public string Host 107 { 108 get 109 { 110 return this.host; 111 } 112 } 113 114 /// <summary> 115 /// Gets marshaller used to serialize requests. 116 /// </summary> 117 public Marshaller<TRequest> RequestMarshaller 118 { 119 get 120 { 121 return this.requestMarshaller; 122 } 123 } 124 125 /// <summary> 126 /// Gets marshaller used to deserialized responses. 127 /// </summary> 128 public Marshaller<TResponse> ResponseMarshaller 129 { 130 get 131 { 132 return this.responseMarshaller; 133 } 134 } 135 136 /// <summary> 137 /// Gets the call options. 138 /// </summary> 139 public CallOptions Options 140 { 141 get 142 { 143 return options; 144 } 145 } 146 147 /// <summary> 148 /// Returns new instance of <see cref="CallInvocationDetails{TRequest, TResponse}"/> with 149 /// <c>Options</c> set to the value provided. Values of all other fields are preserved. 150 /// </summary> WithOptionsGrpc.Core.CallInvocationDetails151 public CallInvocationDetails<TRequest, TResponse> WithOptions(CallOptions options) 152 { 153 var newDetails = this; 154 newDetails.options = options; 155 return newDetails; 156 } 157 } 158 } 159