blob: 37b452f020d390acd31a0deacc468be13688a562 [file] [log] [blame]
Jan Tattermuscha7fff862015-02-13 11:08:08 -08001#region Copyright notice and license
2
Jan Tattermuschaf77b3d2015-02-13 11:22:21 -08003// 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>
41 /// Abstraction of a call to be invoked on a client.
42 /// </summary>
Jan Tattermuscha7608b02015-02-03 17:54:38 -080043 public class Call<TRequest, TResponse>
44 {
Jan Tattermuschc0b37212015-03-13 08:35:41 -070045 readonly string name;
46 readonly Marshaller<TRequest> requestMarshaller;
47 readonly Marshaller<TResponse> responseMarshaller;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080048 readonly Channel channel;
Jan Tattermuschc0b37212015-03-13 08:35:41 -070049 readonly Metadata headers;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080050
Jan Tattermuschc0b37212015-03-13 08:35:41 -070051 public Call(string serviceName, Method<TRequest, TResponse> method, Channel channel, Metadata headers)
Jan Tattermusch075dde42015-03-11 18:21:00 -070052 {
Jan Tattermuschbee93252015-05-12 14:16:33 -070053 this.name = method.GetFullName(serviceName);
Jan Tattermuschc0b37212015-03-13 08:35:41 -070054 this.requestMarshaller = method.RequestMarshaller;
55 this.responseMarshaller = method.ResponseMarshaller;
56 this.channel = Preconditions.CheckNotNull(channel);
57 this.headers = Preconditions.CheckNotNull(headers);
Jan Tattermusch8ce5e8b2015-02-05 10:56:49 -080058 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -080059
60 public Channel Channel
61 {
62 get
63 {
64 return this.channel;
65 }
66 }
67
Jan Tattermuschc0b37212015-03-13 08:35:41 -070068 /// <summary>
69 /// Full methods name including the service name.
70 /// </summary>
71 public string Name
Jan Tattermuscha7608b02015-02-03 17:54:38 -080072 {
73 get
74 {
Jan Tattermuschc0b37212015-03-13 08:35:41 -070075 return name;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080076 }
77 }
78
Jan Tattermuschc0b37212015-03-13 08:35:41 -070079 /// <summary>
80 /// Headers to send at the beginning of the call.
81 /// </summary>
82 public Metadata Headers
Jan Tattermuscha7608b02015-02-03 17:54:38 -080083 {
84 get
85 {
Jan Tattermuschc0b37212015-03-13 08:35:41 -070086 return headers;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080087 }
88 }
89
Jan Tattermuschc0b37212015-03-13 08:35:41 -070090 public Marshaller<TRequest> RequestMarshaller
Jan Tattermuscha7608b02015-02-03 17:54:38 -080091 {
92 get
93 {
Jan Tattermuschc0b37212015-03-13 08:35:41 -070094 return requestMarshaller;
95 }
96 }
97
98 public Marshaller<TResponse> ResponseMarshaller
99 {
100 get
101 {
102 return responseMarshaller;
Jan Tattermuscha7608b02015-02-03 17:54:38 -0800103 }
104 }
105 }
106}