Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: third_party/grpc/src/csharp/Grpc.Core/Method.cs

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 #region Copyright notice and license
2
3 // Copyright 2015-2016, Google Inc.
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are
8 // met:
9 //
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.
19 //
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
34 using System;
35 using Grpc.Core.Utils;
36
37 namespace Grpc.Core
38 {
39 /// <summary>
40 /// Method types supported by gRPC.
41 /// </summary>
42 public enum MethodType
43 {
44 /// <summary>Single request sent from client, single response received f rom server.</summary>
45 Unary,
46
47 /// <summary>Stream of request sent from client, single response receive d from server.</summary>
48 ClientStreaming,
49
50 /// <summary>Single request sent from client, stream of responses receiv ed from server.</summary>
51 ServerStreaming,
52
53 /// <summary>Both server and client can stream arbitrary number of reque sts and responses simultaneously.</summary>
54 DuplexStreaming
55 }
56
57 /// <summary>
58 /// A non-generic representation of a remote method.
59 /// </summary>
60 public interface IMethod
61 {
62 /// <summary>
63 /// Gets the type of the method.
64 /// </summary>
65 MethodType Type { get; }
66
67 /// <summary>
68 /// Gets the name of the service to which this method belongs.
69 /// </summary>
70 string ServiceName { get; }
71
72 /// <summary>
73 /// Gets the unqualified name of the method.
74 /// </summary>
75 string Name { get; }
76
77 /// <summary>
78 /// Gets the fully qualified name of the method. On the server side, met hods are dispatched
79 /// based on this name.
80 /// </summary>
81 string FullName { get; }
82 }
83
84 /// <summary>
85 /// A description of a remote method.
86 /// </summary>
87 /// <typeparam name="TRequest">Request message type for this method.</typepa ram>
88 /// <typeparam name="TResponse">Response message type for this method.</type param>
89 public class Method<TRequest, TResponse> : IMethod
90 {
91 readonly MethodType type;
92 readonly string serviceName;
93 readonly string name;
94 readonly Marshaller<TRequest> requestMarshaller;
95 readonly Marshaller<TResponse> responseMarshaller;
96 readonly string fullName;
97
98 /// <summary>
99 /// Initializes a new instance of the <c>Method</c> class.
100 /// </summary>
101 /// <param name="type">Type of method.</param>
102 /// <param name="serviceName">Name of service this method belongs to.</p aram>
103 /// <param name="name">Unqualified name of the method.</param>
104 /// <param name="requestMarshaller">Marshaller used for request messages .</param>
105 /// <param name="responseMarshaller">Marshaller used for response messag es.</param>
106 public Method(MethodType type, string serviceName, string name, Marshall er<TRequest> requestMarshaller, Marshaller<TResponse> responseMarshaller)
107 {
108 this.type = type;
109 this.serviceName = GrpcPreconditions.CheckNotNull(serviceName, "serv iceName");
110 this.name = GrpcPreconditions.CheckNotNull(name, "name");
111 this.requestMarshaller = GrpcPreconditions.CheckNotNull(requestMarsh aller, "requestMarshaller");
112 this.responseMarshaller = GrpcPreconditions.CheckNotNull(responseMar shaller, "responseMarshaller");
113 this.fullName = GetFullName(serviceName, name);
114 }
115
116 /// <summary>
117 /// Gets the type of the method.
118 /// </summary>
119 public MethodType Type
120 {
121 get
122 {
123 return this.type;
124 }
125 }
126
127 /// <summary>
128 /// Gets the name of the service to which this method belongs.
129 /// </summary>
130 public string ServiceName
131 {
132 get
133 {
134 return this.serviceName;
135 }
136 }
137
138 /// <summary>
139 /// Gets the unqualified name of the method.
140 /// </summary>
141 public string Name
142 {
143 get
144 {
145 return this.name;
146 }
147 }
148
149 /// <summary>
150 /// Gets the marshaller used for request messages.
151 /// </summary>
152 public Marshaller<TRequest> RequestMarshaller
153 {
154 get
155 {
156 return this.requestMarshaller;
157 }
158 }
159
160 /// <summary>
161 /// Gets the marshaller used for response messages.
162 /// </summary>
163 public Marshaller<TResponse> ResponseMarshaller
164 {
165 get
166 {
167 return this.responseMarshaller;
168 }
169 }
170
171 /// <summary>
172 /// Gets the fully qualified name of the method. On the server side, met hods are dispatched
173 /// based on this name.
174 /// </summary>
175 public string FullName
176 {
177 get
178 {
179 return this.fullName;
180 }
181 }
182
183 /// <summary>
184 /// Gets full name of the method including the service name.
185 /// </summary>
186 internal static string GetFullName(string serviceName, string methodName )
187 {
188 return "/" + serviceName + "/" + methodName;
189 }
190 }
191 }
OLDNEW
« no previous file with comments | « third_party/grpc/src/csharp/Grpc.Core/Metadata.cs ('k') | third_party/grpc/src/csharp/Grpc.Core/Profiling/IProfiler.cs » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698