blob: 170a5b68c3e4abcb4268d4365ac46df36bd7deb9 [file] [log] [blame]
Jan Tattermuscha7fff862015-02-13 11:08:08 -08001#region Copyright notice and license
Jan Tattermusch7897ae92017-06-07 22:57:36 +02002// Copyright 2015 gRPC authors.
Craig Tiller190d3602015-02-18 09:23:38 -08003//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02004// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
Craig Tiller190d3602015-02-18 09:23:38 -08007//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02008// http://www.apache.org/licenses/LICENSE-2.0
Craig Tiller190d3602015-02-18 09:23:38 -08009//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020010// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
Jan Tattermuscha7fff862015-02-13 11:08:08 -080015#endregion
16
Jan Tattermusch66eb18d2015-08-09 20:03:24 -070017using Grpc.Core.Utils;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080018
Jan Tattermusch30868622015-02-19 09:22:33 -080019namespace Grpc.Core
Jan Tattermuscha7608b02015-02-03 17:54:38 -080020{
Jan Tattermusch13cd1252015-03-06 10:11:50 -080021 /// <summary>
Jan Tattermusch66eb18d2015-08-09 20:03:24 -070022 /// Represents RPC result, which consists of <see cref="StatusCode"/> and an optional detail string.
Jan Tattermusch13cd1252015-03-06 10:11:50 -080023 /// </summary>
24 public struct Status
25 {
Jan Tattermuscha5272b62015-04-30 11:56:46 -070026 /// <summary>
27 /// Default result of a successful RPC. StatusCode=OK, empty details message.
28 /// </summary>
29 public static readonly Status DefaultSuccess = new Status(StatusCode.OK, "");
30
Jan Tattermusch8c2dd9d2015-05-04 09:20:43 -070031 /// <summary>
32 /// Default result of a cancelled RPC. StatusCode=Cancelled, empty details message.
33 /// </summary>
34 public static readonly Status DefaultCancelled = new Status(StatusCode.Cancelled, "");
35
Jan Tattermusch13cd1252015-03-06 10:11:50 -080036 readonly StatusCode statusCode;
37 readonly string detail;
Jan Tattermuscha7608b02015-02-03 17:54:38 -080038
Jan Tattermusch66eb18d2015-08-09 20:03:24 -070039 /// <summary>
40 /// Creates a new instance of <c>Status</c>.
41 /// </summary>
42 /// <param name="statusCode">Status code.</param>
43 /// <param name="detail">Detail.</param>
Jan Tattermusch13cd1252015-03-06 10:11:50 -080044 public Status(StatusCode statusCode, string detail)
45 {
46 this.statusCode = statusCode;
47 this.detail = detail;
48 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -080049
Jan Tattermuscha29d0f32015-03-04 17:54:56 -080050 /// <summary>
51 /// Gets the gRPC status code. OK indicates success, all other values indicate an error.
52 /// </summary>
Jan Tattermusch13cd1252015-03-06 10:11:50 -080053 public StatusCode StatusCode
54 {
55 get
56 {
57 return statusCode;
58 }
59 }
Jan Tattermuscha7608b02015-02-03 17:54:38 -080060
Jan Tattermuscha29d0f32015-03-04 17:54:56 -080061 /// <summary>
62 /// Gets the detail.
63 /// </summary>
Jan Tattermusch13cd1252015-03-06 10:11:50 -080064 public string Detail
65 {
66 get
67 {
68 return detail;
69 }
70 }
Jan Tattermusch1f18e802015-04-27 15:29:24 -070071
Jan Tattermusch66eb18d2015-08-09 20:03:24 -070072 /// <summary>
73 /// Returns a <see cref="System.String"/> that represents the current <see cref="Grpc.Core.Status"/>.
74 /// </summary>
Jan Tattermusch1f18e802015-04-27 15:29:24 -070075 public override string ToString()
76 {
77 return string.Format("Status(StatusCode={0}, Detail=\"{1}\")", statusCode, detail);
78 }
Jan Tattermusch13cd1252015-03-06 10:11:50 -080079 }
Craig Tiller190d3602015-02-18 09:23:38 -080080}