| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 | /* * * Copyright 2019 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * *     http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */#import <UIKit/UIKit.h>#import <GRPCClient/GRPCCall.h>#import <GRPCClient/GRPCCallOptions.h>#import <RemoteTest/Messages.pbobjc.h>#import <RemoteTest/Test.pbrpc.h>NSString *const kRemoteHost = @"grpc-test.sandbox.googleapis.com";const int32_t kMessageSize = 100;@interface ViewController : UIViewController<GRPCProtoResponseHandler>@end@implementation ViewController {  RMTTestService *_service;  dispatch_queue_t _dispatchQueue;  GRPCStreamingProtoCall *_call;}- (void)viewDidLoad {  [super viewDidLoad];  _dispatchQueue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);}- (IBAction)tapUnaryCall:(id)sender {  if (_service == nil) {    _service = [RMTTestService serviceWithHost:kRemoteHost];  }  // Set up request proto message  RMTSimpleRequest *request = [RMTSimpleRequest message];  request.responseType = RMTPayloadType_Compressable;  request.responseSize = kMessageSize;  request.payload.body = [NSMutableData dataWithLength:kMessageSize];  GRPCUnaryProtoCall *call =      [_service unaryCallWithMessage:request responseHandler:self callOptions:nil];  [call start];}- (IBAction)tapStreamingCallStart:(id)sender {  if (_service == nil) {    _service = [RMTTestService serviceWithHost:kRemoteHost];  }  // Set up request proto message  RMTStreamingOutputCallRequest *request = RMTStreamingOutputCallRequest.message;  RMTResponseParameters *parameters = [RMTResponseParameters message];  parameters.size = kMessageSize;  [request.responseParametersArray addObject:parameters];  request.payload.body = [NSMutableData dataWithLength:kMessageSize];  GRPCStreamingProtoCall *call = [_service fullDuplexCallWithResponseHandler:self callOptions:nil];  [call start];  _call = call;  // display something to confirm the tester the call is started  NSLog(@"Started streaming call");}- (IBAction)tapStreamingCallSend:(id)sender {  if (_call == nil) return;  RMTStreamingOutputCallRequest *request = RMTStreamingOutputCallRequest.message;  RMTResponseParameters *parameters = [RMTResponseParameters message];  parameters.size = kMessageSize;  [request.responseParametersArray addObject:parameters];  request.payload.body = [NSMutableData dataWithLength:kMessageSize];  [_call writeMessage:request];}- (IBAction)tapStreamingCallStop:(id)sender {  if (_call == nil) return;  [_call finish];  _call = nil;}- (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata {  NSLog(@"Recv initial metadata: %@", initialMetadata);}- (void)didReceiveProtoMessage:(GPBMessage *)message {  NSLog(@"Recv message: %@", message);}- (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata                               error:(nullable NSError *)error {  NSLog(@"Recv trailing metadata: %@, error: %@", trailingMetadata, error);}- (dispatch_queue_t)dispatchQueue {  return _dispatchQueue;}@end
 |