Rename handlers to didXxx

pull/16190/head
Muxi Yan 6 years ago
parent 76f1ec16e1
commit eeced98fc5
  1. 8
      src/objective-c/GRPCClient/GRPCCall.h
  2. 16
      src/objective-c/GRPCClient/GRPCCall.m
  3. 12
      src/objective-c/ProtoRPC/ProtoRPC.h
  4. 24
      src/objective-c/ProtoRPC/ProtoRPC.m
  5. 6
      src/objective-c/tests/APIv2Tests/APIv2Tests.m
  6. 6
      src/objective-c/tests/InteropTests.m

@ -158,13 +158,13 @@ extern NSString *const kGRPCTrailersKey;
/** /**
* Issued when initial metadata is received from the server. * Issued when initial metadata is received from the server.
*/ */
- (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata; - (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata;
/** /**
* Issued when a message is received from the server. The message is the raw data received from the * Issued when a message is received from the server. The message is the raw data received from the
* server, with decompression and without proto deserialization. * server, with decompression and without proto deserialization.
*/ */
- (void)receivedRawMessage:(nullable NSData *)message; - (void)didReceiveRawMessage:(nullable NSData *)message;
/** /**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a * Issued when a call finished. If the call finished successfully, \a error is nil and \a
@ -172,7 +172,7 @@ extern NSString *const kGRPCTrailersKey;
* is non-nil and contains the corresponding error information, including gRPC error codes and * is non-nil and contains the corresponding error information, including gRPC error codes and
* error descriptions. * error descriptions.
*/ */
- (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(nullable NSError *)error; error:(nullable NSError *)error;
@required @required
@ -247,7 +247,7 @@ extern NSString *const kGRPCTrailersKey;
/** /**
* Cancel the request of this call at best effort. It attempts to notify the server that the RPC * Cancel the request of this call at best effort. It attempts to notify the server that the RPC
* should be cancelled, and issue closedWithTrailingMetadata:error: callback with error code * should be cancelled, and issue didCloseWithTrailingMetadata:error: callback with error code
* CANCELED if no other error code has already been issued. * CANCELED if no other error code has already been issued.
*/ */
- (void)cancel; - (void)cancel;

@ -250,7 +250,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
_call = nil; _call = nil;
_pipe = nil; _pipe = nil;
if ([_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
// Copy to local so that block is freed after cancellation completes. // Copy to local so that block is freed after cancellation completes.
id<GRPCResponseHandler> copiedHandler = nil; id<GRPCResponseHandler> copiedHandler = nil;
@ -259,7 +259,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler closedWithTrailingMetadata:nil [copiedHandler didCloseWithTrailingMetadata:nil
error:[NSError errorWithDomain:kGRPCErrorDomain error:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
userInfo:@{ userInfo:@{
@ -321,13 +321,13 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)issueInitialMetadata:(NSDictionary *)initialMetadata { - (void)issueInitialMetadata:(NSDictionary *)initialMetadata {
@synchronized(self) { @synchronized(self) {
if (initialMetadata != nil && if (initialMetadata != nil &&
[_handler respondsToSelector:@selector(receivedInitialMetadata:)]) { [_handler respondsToSelector:@selector(didReceiveInitialMetadata:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCResponseHandler> copiedHandler = nil; id<GRPCResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
} }
[copiedHandler receivedInitialMetadata:initialMetadata]; [copiedHandler didReceiveInitialMetadata:initialMetadata];
}); });
} }
} }
@ -335,13 +335,13 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)issueMessage:(id)message { - (void)issueMessage:(id)message {
@synchronized(self) { @synchronized(self) {
if (message != nil && [_handler respondsToSelector:@selector(receivedRawMessage:)]) { if (message != nil && [_handler respondsToSelector:@selector(didReceiveRawMessage:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCResponseHandler> copiedHandler = nil; id<GRPCResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
} }
[copiedHandler receivedRawMessage:message]; [copiedHandler didReceiveRawMessage:message];
}); });
} }
} }
@ -349,7 +349,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - (void)issueClosedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
@synchronized(self) { @synchronized(self) {
if ([_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCResponseHandler> copiedHandler = nil; id<GRPCResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
@ -357,7 +357,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Clean up _handler so that no more responses are reported to the handler. // Clean up _handler so that no more responses are reported to the handler.
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler closedWithTrailingMetadata:trailingMetadata error:error]; [copiedHandler didCloseWithTrailingMetadata:trailingMetadata error:error];
}); });
} else { } else {
_handler = nil; _handler = nil;

@ -33,12 +33,12 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* Issued when initial metadata is received from the server. * Issued when initial metadata is received from the server.
*/ */
- (void)receivedInitialMetadata:(nullable NSDictionary *)initialMetadata; - (void)didReceiveInitialMetadata:(nullable NSDictionary *)initialMetadata;
/** /**
* Issued when a message is received from the server. The message is the deserialized proto object. * Issued when a message is received from the server. The message is the deserialized proto object.
*/ */
- (void)receivedProtoMessage:(nullable GPBMessage *)message; - (void)didReceiveProtoMessage:(nullable GPBMessage *)message;
/** /**
* Issued when a call finished. If the call finished successfully, \a error is nil and \a * Issued when a call finished. If the call finished successfully, \a error is nil and \a
@ -46,8 +46,8 @@ NS_ASSUME_NONNULL_BEGIN
* is non-nil and contains the corresponding error information, including gRPC error codes and * is non-nil and contains the corresponding error information, including gRPC error codes and
* error descriptions. * error descriptions.
*/ */
- (void)closedWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata - (void)didCloseWithTrailingMetadata:(nullable NSDictionary *)trailingMetadata
error:(nullable NSError *)error; error:(nullable NSError *)error;
@required @required
@ -83,7 +83,7 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* Cancel the request of this call at best effort. It attempts to notify the server that the RPC * Cancel the request of this call at best effort. It attempts to notify the server that the RPC
* should be cancelled, and issue closedWithTrailingMetadata:error: callback with error code * should be cancelled, and issue didCloseWithTrailingMetadata:error: callback with error code
* CANCELED if no other error code has already been issued. * CANCELED if no other error code has already been issued.
*/ */
- (void)cancel; - (void)cancel;
@ -113,7 +113,7 @@ NS_ASSUME_NONNULL_BEGIN
/** /**
* Cancel the request of this call at best effort. It attempts to notify the server that the RPC * Cancel the request of this call at best effort. It attempts to notify the server that the RPC
* should be cancelled, and issue closedWithTrailingMetadata:error: callback with error code * should be cancelled, and issue didCloseWithTrailingMetadata:error: callback with error code
* CANCELED if no other error code has already been issued. * CANCELED if no other error code has already been issued.
*/ */
- (void)cancel; - (void)cancel;

@ -144,14 +144,14 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
@synchronized(self) { @synchronized(self) {
copiedCall = _call; copiedCall = _call;
_call = nil; _call = nil;
if ([_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_handler.dispatchQueue, ^{ dispatch_async(_handler.dispatchQueue, ^{
id<GRPCProtoResponseHandler> copiedHandler = nil; id<GRPCProtoResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler closedWithTrailingMetadata:nil [copiedHandler didCloseWithTrailingMetadata:nil
error:[NSError errorWithDomain:kGRPCErrorDomain error:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
userInfo:@{ userInfo:@{
@ -187,7 +187,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
[call finish]; [call finish];
} }
- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { - (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata {
@synchronized(self) { @synchronized(self) {
if (initialMetadata != nil && [_handler respondsToSelector:@selector(initialMetadata:)]) { if (initialMetadata != nil && [_handler respondsToSelector:@selector(initialMetadata:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
@ -195,35 +195,35 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
} }
[copiedHandler receivedInitialMetadata:initialMetadata]; [copiedHandler didReceiveInitialMetadata:initialMetadata];
}); });
} }
} }
} }
- (void)receivedRawMessage:(NSData *)message { - (void)didReceiveRawMessage:(NSData *)message {
if (message == nil) return; if (message == nil) return;
NSError *error = nil; NSError *error = nil;
GPBMessage *parsed = [_responseClass parseFromData:message error:&error]; GPBMessage *parsed = [_responseClass parseFromData:message error:&error];
@synchronized(self) { @synchronized(self) {
if (parsed && [_handler respondsToSelector:@selector(receivedProtoMessage:)]) { if (parsed && [_handler respondsToSelector:@selector(didReceiveProtoMessage:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCProtoResponseHandler> copiedHandler = nil; id<GRPCProtoResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
} }
[copiedHandler receivedProtoMessage:parsed]; [copiedHandler didReceiveProtoMessage:parsed];
}); });
} else if (!parsed && } else if (!parsed &&
[_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { [_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCProtoResponseHandler> copiedHandler = nil; id<GRPCProtoResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler closedWithTrailingMetadata:nil [copiedHandler didCloseWithTrailingMetadata:nil
error:ErrorForBadProto(message, _responseClass, error)]; error:ErrorForBadProto(message, _responseClass, error)];
}); });
[_call cancel]; [_call cancel];
@ -232,16 +232,16 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
} }
} }
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
@synchronized(self) { @synchronized(self) {
if ([_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) { if ([_handler respondsToSelector:@selector(didCloseWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{ dispatch_async(_dispatchQueue, ^{
id<GRPCProtoResponseHandler> copiedHandler = nil; id<GRPCProtoResponseHandler> copiedHandler = nil;
@synchronized(self) { @synchronized(self) {
copiedHandler = self->_handler; copiedHandler = self->_handler;
self->_handler = nil; self->_handler = nil;
} }
[copiedHandler closedWithTrailingMetadata:trailingMetadata error:error]; [copiedHandler didCloseWithTrailingMetadata:trailingMetadata error:error];
}); });
} }
_call = nil; _call = nil;

@ -81,19 +81,19 @@ static const NSTimeInterval kTestTimeout = 16;
return self; return self;
} }
- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { - (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata {
if (self->_initialMetadataCallback) { if (self->_initialMetadataCallback) {
self->_initialMetadataCallback(initialMetadata); self->_initialMetadataCallback(initialMetadata);
} }
} }
- (void)receivedRawMessage:(GPBMessage *)message { - (void)didReceiveRawMessage:(GPBMessage *)message {
if (self->_messageCallback) { if (self->_messageCallback) {
self->_messageCallback(message); self->_messageCallback(message);
} }
} }
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
if (self->_closeCallback) { if (self->_closeCallback) {
self->_closeCallback(trailingMetadata, error); self->_closeCallback(trailingMetadata, error);
} }

@ -102,19 +102,19 @@ BOOL isRemoteInteropTest(NSString *host) {
return self; return self;
} }
- (void)receivedInitialMetadata:(NSDictionary *)initialMetadata { - (void)didReceiveInitialMetadata:(NSDictionary *)initialMetadata {
if (_initialMetadataCallback) { if (_initialMetadataCallback) {
_initialMetadataCallback(initialMetadata); _initialMetadataCallback(initialMetadata);
} }
} }
- (void)receivedProtoMessage:(GPBMessage *)message { - (void)didReceiveProtoMessage:(GPBMessage *)message {
if (_messageCallback) { if (_messageCallback) {
_messageCallback(message); _messageCallback(message);
} }
} }
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error { - (void)didCloseWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
if (_closeCallback) { if (_closeCallback) {
_closeCallback(trailingMetadata, error); _closeCallback(trailingMetadata, error);
} }

Loading…
Cancel
Save