1/* 2 * 3 * Copyright 2019 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 */ 18 19#import "InteropTestsBlockCallbacks.h" 20 21@implementation InteropTestsBlockCallbacks { 22 void (^_initialMetadataCallback)(NSDictionary *); 23 void (^_messageCallback)(id); 24 void (^_closeCallback)(NSDictionary *, NSError *); 25 void (^_writeMessageCallback)(void); 26 dispatch_queue_t _dispatchQueue; 27} 28 29- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback 30 messageCallback:(void (^)(id))messageCallback 31 closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback 32 writeMessageCallback:(void (^)(void))writeMessageCallback { 33 if ((self = [super init])) { 34 _initialMetadataCallback = initialMetadataCallback; 35 _messageCallback = messageCallback; 36 _closeCallback = closeCallback; 37 _writeMessageCallback = writeMessageCallback; 38 _dispatchQueue = dispatch_queue_create(nil, DISPATCH_QUEUE_SERIAL); 39 } 40 return self; 41} 42 43- (instancetype)initWithInitialMetadataCallback:(void (^)(NSDictionary *))initialMetadataCallback 44 messageCallback:(void (^)(id))messageCallback 45 closeCallback:(void (^)(NSDictionary *, NSError *))closeCallback { 46 return [self initWithInitialMetadataCallback:initialMetadataCallback 47 messageCallback:messageCallback 48 closeCallback:closeCallback 49 writeMessageCallback:nil]; 50} 51 52- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata { 53 if (_initialMetadataCallback) { 54 _initialMetadataCallback(initialMetadata); 55 } 56} 57 58- (void)didReceiveProtoMessage:(GPBMessage *)message { 59 if (_messageCallback) { 60 _messageCallback(message); 61 } 62} 63 64- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { 65 if (_closeCallback) { 66 _closeCallback(trailingMetadata, error); 67 } 68} 69 70- (void)didWriteMessage { 71 if (_writeMessageCallback) { 72 _writeMessageCallback(); 73 } 74} 75 76- (dispatch_queue_t)dispatchQueue { 77 return _dispatchQueue; 78} 79 80@end 81