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 System.Runtime.InteropServices; 21 using Grpc.Core.Utils; 22 23 namespace Grpc.Core.Internal 24 { 25 /// <summary> 26 /// grpc_call_error from grpc/grpc.h 27 /// </summary> 28 internal enum CallError 29 { 30 /* everything went ok */ 31 OK = 0, 32 /* something failed, we don't know what */ 33 Error, 34 /* this method is not available on the server */ 35 NotOnServer, 36 /* this method is not available on the client */ 37 NotOnClient, 38 /* this method must be called before server_accept */ 39 AlreadyAccepted, 40 /* this method must be called before invoke */ 41 AlreadyInvoked, 42 /* this method must be called after invoke */ 43 NotInvoked, 44 /* this call is already finished 45 (writes_done or write_status has already been called) */ 46 AlreadyFinished, 47 /* there is already an outstanding read/write operation on the call */ 48 TooManyOperations, 49 /* the flags value was illegal for this call */ 50 InvalidFlags, 51 /* invalid metadata was passed to this call */ 52 InvalidMetadata, 53 /* invalid message was passed to this call */ 54 InvalidMessage, 55 /* completion queue for notification has not been registered 56 with the server */ 57 NotServerCompletionQueue, 58 /* this batch of operations leads to more operations than allowed */ 59 BatchTooBig, 60 /* payload type requested is not the type registered */ 61 PayloadTypeMismatch, 62 /* completion queue has been shutdown */ 63 CompletionQueueShutdown 64 } 65 66 internal static class CallErrorExtensions 67 { 68 /// <summary> 69 /// Checks the call API invocation's result is OK. 70 /// </summary> CheckOk(this CallError callError)71 public static void CheckOk(this CallError callError) 72 { 73 if (callError != CallError.OK) 74 { 75 throw new InvalidOperationException("Call error: " + callError); 76 } 77 } 78 } 79 } 80