Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | // Copyright 2015, Google Inc. |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 4 | // All rights reserved. |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 5 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 6 | // Redistribution and use in source and binary forms, with or without |
| 7 | // modification, are permitted provided that the following conditions are |
| 8 | // met: |
Craig Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 9 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 10 | // * 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 Tiller | 190d360 | 2015-02-18 09:23:38 -0800 | [diff] [blame] | 19 | // |
Jan Tattermusch | a7fff86 | 2015-02-13 11:08:08 -0800 | [diff] [blame] | 20 | // 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 Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 34 | using System; |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 35 | using Grpc.Core.Internal; |
Jan Tattermusch | c0b3721 | 2015-03-13 08:35:41 -0700 | [diff] [blame] | 36 | using Grpc.Core.Utils; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 37 | |
Jan Tattermusch | 3086862 | 2015-02-19 09:22:33 -0800 | [diff] [blame] | 38 | namespace Grpc.Core |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 39 | { |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 40 | /// <summary> |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 41 | /// Details about a client-side call to be invoked. |
Jan Tattermusch | a5272b6 | 2015-04-30 11:56:46 -0700 | [diff] [blame] | 42 | /// </summary> |
Jan Tattermusch | 12855fc | 2015-08-24 16:43:23 -0700 | [diff] [blame] | 43 | /// <typeparam name="TRequest">Request message type for the call.</typeparam> |
| 44 | /// <typeparam name="TResponse">Response message type for the call.</typeparam> |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 45 | public struct CallInvocationDetails<TRequest, TResponse> |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 46 | { |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 47 | readonly Channel channel; |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 48 | readonly string method; |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 49 | readonly string host; |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 50 | readonly Marshaller<TRequest> requestMarshaller; |
| 51 | readonly Marshaller<TResponse> responseMarshaller; |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 52 | CallOptions options; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 53 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 54 | /// <summary> |
Jan Tattermusch | 12855fc | 2015-08-24 16:43:23 -0700 | [diff] [blame] | 55 | /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 56 | /// </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 Tattermusch | 5c371f8 | 2015-08-05 14:55:17 -0700 | [diff] [blame] | 60 | public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, CallOptions options) : |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 61 | this(channel, method, null, options) |
| 62 | { |
| 63 | } |
| 64 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 65 | /// <summary> |
Jan Tattermusch | 12855fc | 2015-08-24 16:43:23 -0700 | [diff] [blame] | 66 | /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 67 | /// </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 Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 72 | public CallInvocationDetails(Channel channel, Method<TRequest, TResponse> method, string host, CallOptions options) : |
| 73 | this(channel, method.FullName, host, method.RequestMarshaller, method.ResponseMarshaller, options) |
Jan Tattermusch | 075dde4 | 2015-03-11 18:21:00 -0700 | [diff] [blame] | 74 | { |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 77 | /// <summary> |
Jan Tattermusch | 12855fc | 2015-08-24 16:43:23 -0700 | [diff] [blame] | 78 | /// Initializes a new instance of the <see cref="Grpc.Core.CallInvocationDetails{TRequest,TResponse}"/> struct. |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 79 | /// </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 Tattermusch | 5c371f8 | 2015-08-05 14:55:17 -0700 | [diff] [blame] | 86 | public CallInvocationDetails(Channel channel, string method, string host, Marshaller<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller, CallOptions options) |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 87 | { |
Jan Tattermusch | 7a3ee6a | 2016-02-18 10:36:02 -0800 | [diff] [blame] | 88 | this.channel = GrpcPreconditions.CheckNotNull(channel, "channel"); |
| 89 | this.method = GrpcPreconditions.CheckNotNull(method, "method"); |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 90 | this.host = host; |
Jan Tattermusch | 7a3ee6a | 2016-02-18 10:36:02 -0800 | [diff] [blame] | 91 | this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarshaller, "requestMarshaller"); |
| 92 | this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMarshaller, "responseMarshaller"); |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 93 | this.options = options; |
Jan Tattermusch | 8ce5e8b | 2015-02-05 10:56:49 -0800 | [diff] [blame] | 94 | } |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 95 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 96 | /// <summary> |
| 97 | /// Get channel associated with this call. |
| 98 | /// </summary> |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 99 | public Channel Channel |
| 100 | { |
| 101 | get |
| 102 | { |
| 103 | return this.channel; |
| 104 | } |
| 105 | } |
| 106 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 107 | /// <summary> |
| 108 | /// Gets name of method to be called. |
| 109 | /// </summary> |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 110 | public string Method |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 111 | { |
| 112 | get |
| 113 | { |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 114 | return this.method; |
| 115 | } |
| 116 | } |
| 117 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 118 | /// <summary> |
| 119 | /// Get name of host. |
| 120 | /// </summary> |
Jan Tattermusch | cc97fed | 2015-08-05 00:44:29 -0700 | [diff] [blame] | 121 | public string Host |
| 122 | { |
| 123 | get |
| 124 | { |
| 125 | return this.host; |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 129 | /// <summary> |
| 130 | /// Gets marshaller used to serialize requests. |
| 131 | /// </summary> |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 132 | public Marshaller<TRequest> RequestMarshaller |
| 133 | { |
| 134 | get |
| 135 | { |
| 136 | return this.requestMarshaller; |
| 137 | } |
| 138 | } |
| 139 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 140 | /// <summary> |
| 141 | /// Gets marshaller used to deserialized responses. |
| 142 | /// </summary> |
Jan Tattermusch | 5cb5ced | 2015-08-05 04:05:57 -0700 | [diff] [blame] | 143 | public Marshaller<TResponse> ResponseMarshaller |
| 144 | { |
| 145 | get |
| 146 | { |
| 147 | return this.responseMarshaller; |
| 148 | } |
| 149 | } |
Jan Tattermusch | 5c371f8 | 2015-08-05 14:55:17 -0700 | [diff] [blame] | 150 | |
Jan Tattermusch | 1b926ee | 2015-08-10 22:51:29 -0700 | [diff] [blame] | 151 | /// <summary> |
| 152 | /// Gets the call options. |
| 153 | /// </summary> |
Jan Tattermusch | 5c371f8 | 2015-08-05 14:55:17 -0700 | [diff] [blame] | 154 | public CallOptions Options |
Jan Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 155 | { |
| 156 | get |
| 157 | { |
Jan Tattermusch | 5c371f8 | 2015-08-05 14:55:17 -0700 | [diff] [blame] | 158 | return options; |
Jan Tattermusch | 0846b68 | 2015-07-23 17:02:12 -0700 | [diff] [blame] | 159 | } |
| 160 | } |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 161 | |
| 162 | /// <summary> |
Jan Tattermusch | 12855fc | 2015-08-24 16:43:23 -0700 | [diff] [blame] | 163 | /// Returns new instance of <see cref="CallInvocationDetails{TRequest, TResponse}"/> with |
Jan Tattermusch | 9698b5b | 2015-08-10 16:40:19 -0700 | [diff] [blame] | 164 | /// <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 Tattermusch | a7608b0 | 2015-02-03 17:54:38 -0800 | [diff] [blame] | 172 | } |
| 173 | } |