murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 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 | */ |
| 33 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 34 | #import "GRPCWrappedCall.h" |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 35 | |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 36 | #import <Foundation/Foundation.h> |
| 37 | #include <grpc/grpc.h> |
| 38 | #include <grpc/byte_buffer.h> |
| 39 | #include <grpc/support/alloc.h> |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 40 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 41 | #import "GRPCCompletionQueue.h" |
| 42 | #import "GRPCHost.h" |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 43 | #import "NSDictionary+GRPC.h" |
| 44 | #import "NSData+GRPC.h" |
| 45 | #import "NSError+GRPC.h" |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 46 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 47 | @implementation GRPCOperation { |
| 48 | @protected |
Jorge Canizales | 8848704 | 2015-06-21 21:59:37 -0700 | [diff] [blame] | 49 | // Most operation subclasses don't set any flags in the grpc_op, and rely on the flag member being |
| 50 | // initialized to zero. |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 51 | grpc_op _op; |
| 52 | void(^_handler)(); |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 55 | - (void)finish { |
| 56 | if (_handler) { |
Nicolas "Pixel" Noble | 7022436 | 2016-03-21 22:19:43 +0100 | [diff] [blame] | 57 | void(^handler)() = _handler; |
| 58 | _handler = nil; |
| 59 | handler(); |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | @end |
| 63 | |
| 64 | @implementation GRPCOpSendMetadata |
| 65 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 66 | - (instancetype)init { |
| 67 | return [self initWithMetadata:nil handler:nil]; |
| 68 | } |
| 69 | |
Jorge Canizales | f4f150f | 2015-11-01 22:31:12 -0800 | [diff] [blame] | 70 | - (instancetype)initWithMetadata:(NSDictionary *)metadata handler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 71 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 72 | _op.op = GRPC_OP_SEND_INITIAL_METADATA; |
| 73 | _op.data.send_initial_metadata.count = metadata.count; |
| 74 | _op.data.send_initial_metadata.metadata = metadata.grpc_metadataArray; |
David Garcia Quintas | e825df7 | 2016-05-17 22:11:18 -0700 | [diff] [blame] | 75 | _op.data.send_initial_metadata.maybe_compression_level.is_set = false; |
David Garcia Quintas | 8ba42be | 2016-06-07 17:30:20 -0700 | [diff] [blame] | 76 | _op.data.send_initial_metadata.maybe_compression_level.level = 0; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 77 | _handler = handler; |
| 78 | } |
| 79 | return self; |
| 80 | } |
| 81 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 82 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 83 | gpr_free(_op.data.send_initial_metadata.metadata); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 84 | } |
| 85 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 86 | @end |
| 87 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 88 | @implementation GRPCOpSendMessage |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 89 | |
| 90 | - (instancetype)init { |
| 91 | return [self initWithMessage:nil handler:nil]; |
| 92 | } |
| 93 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 94 | - (instancetype)initWithMessage:(NSData *)message handler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 95 | if (!message) { |
murgatroid99 | 2101a48 | 2015-04-29 11:42:26 -0700 | [diff] [blame] | 96 | [NSException raise:NSInvalidArgumentException format:@"message cannot be nil"]; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 97 | } |
| 98 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 99 | _op.op = GRPC_OP_SEND_MESSAGE; |
| 100 | _op.data.send_message = message.grpc_byteBuffer; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 101 | _handler = handler; |
| 102 | } |
| 103 | return self; |
| 104 | } |
| 105 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 106 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 107 | gpr_free(_op.data.send_message); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 108 | } |
| 109 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 110 | @end |
| 111 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 112 | @implementation GRPCOpSendClose |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 113 | |
| 114 | - (instancetype)init { |
| 115 | return [self initWithHandler:nil]; |
| 116 | } |
| 117 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 118 | - (instancetype)initWithHandler:(void (^)())handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 119 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 120 | _op.op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 121 | _handler = handler; |
| 122 | } |
| 123 | return self; |
| 124 | } |
| 125 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 126 | @end |
| 127 | |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 128 | @implementation GRPCOpRecvMetadata { |
| 129 | grpc_metadata_array _headers; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | - (instancetype) init { |
| 133 | return [self initWithHandler:nil]; |
| 134 | } |
| 135 | |
| 136 | - (instancetype) initWithHandler:(void (^)(NSDictionary *))handler { |
| 137 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 138 | _op.op = GRPC_OP_RECV_INITIAL_METADATA; |
| 139 | grpc_metadata_array_init(&_headers); |
| 140 | _op.data.recv_initial_metadata = &_headers; |
| 141 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 142 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 143 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 144 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 145 | __strong typeof(self) strongSelf = weakSelf; |
| 146 | NSDictionary *metadata = [NSDictionary |
| 147 | grpc_dictionaryFromMetadataArray:strongSelf->_headers]; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 148 | handler(metadata); |
| 149 | }; |
| 150 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 151 | } |
| 152 | return self; |
| 153 | } |
| 154 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 155 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 156 | grpc_metadata_array_destroy(&_headers); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 157 | } |
| 158 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 159 | @end |
| 160 | |
| 161 | @implementation GRPCOpRecvMessage{ |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 162 | grpc_byte_buffer *_receivedMessage; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | - (instancetype)init { |
| 166 | return [self initWithHandler:nil]; |
| 167 | } |
| 168 | |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 169 | - (instancetype)initWithHandler:(void (^)(grpc_byte_buffer *))handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 170 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 171 | _op.op = GRPC_OP_RECV_MESSAGE; |
| 172 | _op.data.recv_message = &_receivedMessage; |
| 173 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 174 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 175 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 176 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 177 | __strong typeof(self) strongSelf = weakSelf; |
| 178 | handler(strongSelf->_receivedMessage); |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 179 | }; |
| 180 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 181 | } |
| 182 | return self; |
| 183 | } |
| 184 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 185 | @end |
| 186 | |
| 187 | @implementation GRPCOpRecvStatus{ |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 188 | grpc_status_code _statusCode; |
| 189 | char *_details; |
murgatroid99 | ca38ddb | 2015-04-29 13:16:42 -0700 | [diff] [blame] | 190 | size_t _detailsCapacity; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 191 | grpc_metadata_array _trailers; |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | - (instancetype) init { |
| 195 | return [self initWithHandler:nil]; |
| 196 | } |
| 197 | |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 198 | - (instancetype) initWithHandler:(void (^)(NSError *, NSDictionary *))handler { |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 199 | if (self = [super init]) { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 200 | _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; |
| 201 | _op.data.recv_status_on_client.status = &_statusCode; |
| 202 | _op.data.recv_status_on_client.status_details = &_details; |
| 203 | _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity; |
| 204 | grpc_metadata_array_init(&_trailers); |
| 205 | _op.data.recv_status_on_client.trailing_metadata = &_trailers; |
| 206 | if (handler) { |
murgatroid99 | 231103b | 2015-06-25 10:14:09 -0700 | [diff] [blame] | 207 | // Prevent reference cycle with _handler |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 208 | __weak typeof(self) weakSelf = self; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 209 | _handler = ^{ |
murgatroid99 | dbda969 | 2015-06-24 16:55:55 -0700 | [diff] [blame] | 210 | __strong typeof(self) strongSelf = weakSelf; |
| 211 | NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode |
| 212 | details:strongSelf->_details]; |
| 213 | NSDictionary *trailers = [NSDictionary |
| 214 | grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 215 | handler(error, trailers); |
| 216 | }; |
| 217 | } |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 218 | } |
| 219 | return self; |
| 220 | } |
| 221 | |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 222 | - (void)dealloc { |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 223 | grpc_metadata_array_destroy(&_trailers); |
Jorge Canizales | f3a4f2c | 2015-06-12 22:12:50 -0700 | [diff] [blame] | 224 | gpr_free(_details); |
murgatroid99 | 33655f9 | 2015-04-29 11:15:35 -0700 | [diff] [blame] | 225 | } |
| 226 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 227 | @end |
| 228 | |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 229 | #pragma mark GRPCWrappedCall |
| 230 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 231 | @implementation GRPCWrappedCall { |
| 232 | GRPCCompletionQueue *_queue; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 233 | grpc_call *_call; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | - (instancetype)init { |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 237 | return [self initWithHost:nil path:nil]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 240 | - (instancetype)initWithHost:(NSString *)host |
| 241 | path:(NSString *)path { |
| 242 | if (!path || !host) { |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 243 | [NSException raise:NSInvalidArgumentException |
Jorge Canizales | 3a5253e | 2015-07-31 23:48:56 -0700 | [diff] [blame] | 244 | format:@"path and host cannot be nil."]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 245 | } |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 246 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 247 | if (self = [super init]) { |
| 248 | static dispatch_once_t initialization; |
| 249 | dispatch_once(&initialization, ^{ |
| 250 | grpc_init(); |
| 251 | }); |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 252 | |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 253 | // Each completion queue consumes one thread. There's a trade to be made between creating and |
| 254 | // consuming too many threads and having contention of multiple calls in a single completion |
Jorge Canizales | 5e824fa | 2016-06-24 11:32:51 -0700 | [diff] [blame] | 255 | // queue. Currently we use a singleton queue. |
Jorge Canizales | e8543b0 | 2015-08-01 17:37:40 -0700 | [diff] [blame] | 256 | _queue = [GRPCCompletionQueue completionQueue]; |
| 257 | |
| 258 | _call = [[GRPCHost hostWithAddress:host] unmanagedCallWithPath:path completionQueue:_queue]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 259 | if (_call == NULL) { |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 260 | return nil; |
| 261 | } |
| 262 | } |
| 263 | return self; |
| 264 | } |
| 265 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 266 | - (void)startBatchWithOperations:(NSArray *)operations { |
| 267 | [self startBatchWithOperations:operations errorHandler:nil]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 268 | } |
| 269 | |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 270 | - (void)startBatchWithOperations:(NSArray *)operations errorHandler:(void (^)())errorHandler { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 271 | size_t nops = operations.count; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 272 | grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op)); |
murgatroid99 | 54e93d4 | 2015-04-27 09:29:49 -0700 | [diff] [blame] | 273 | size_t i = 0; |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 274 | for (GRPCOperation *operation in operations) { |
| 275 | ops_array[i++] = operation.op; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 276 | } |
murgatroid99 | 6cc4680 | 2015-04-28 09:35:48 -0700 | [diff] [blame] | 277 | grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops, |
murgatroid99 | 6b54244 | 2015-05-08 10:40:01 -0700 | [diff] [blame] | 278 | (__bridge_retained void *)(^(bool success){ |
| 279 | if (!success) { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 280 | if (errorHandler) { |
| 281 | errorHandler(); |
| 282 | } else { |
murgatroid99 | def47aa | 2015-04-29 10:28:26 -0700 | [diff] [blame] | 283 | return; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 284 | } |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 285 | } |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 286 | for (GRPCOperation *operation in operations) { |
murgatroid99 | 2101a48 | 2015-04-29 11:42:26 -0700 | [diff] [blame] | 287 | [operation finish]; |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 288 | } |
Jorge Canizales | b3584aa | 2015-08-08 15:01:24 -0700 | [diff] [blame] | 289 | }), NULL); |
Jorge Canizales | 8d99775 | 2015-06-21 21:43:26 -0700 | [diff] [blame] | 290 | gpr_free(ops_array); |
| 291 | |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 292 | if (error != GRPC_CALL_OK) { |
murgatroid99 | 6a084f4 | 2015-04-29 10:18:05 -0700 | [diff] [blame] | 293 | [NSException raise:NSInternalInconsistencyException |
Jorge Canizales | bae38d9 | 2015-06-20 20:21:25 -0700 | [diff] [blame] | 294 | format:@"A precondition for calling grpc_call_start_batch wasn't met. Error %i", |
| 295 | error]; |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
| 299 | - (void)cancel { |
Jorge Canizales | b3584aa | 2015-08-08 15:01:24 -0700 | [diff] [blame] | 300 | grpc_call_cancel(_call, NULL); |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | - (void)dealloc { |
murgatroid99 | 69927d6 | 2015-04-24 13:32:48 -0700 | [diff] [blame] | 304 | grpc_call_destroy(_call); |
murgatroid99 | 30b7d4e | 2015-04-24 10:36:43 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jorge Canizales | bd993df | 2015-08-01 02:51:22 -0700 | [diff] [blame] | 307 | @end |