diff options
author | Muxi Yan <muxi@users.noreply.github.com> | 2018-02-23 10:04:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-23 10:04:40 -0800 |
commit | 5699cfcd4537df3a4358034fcfefed1ccc5a66a2 (patch) | |
tree | 664b02390b39a5e28b28bbc16a128e9ef06b2cc1 /src/objective-c/GRPCClient/private | |
parent | a90d718cb89414bfe5f6cfaa69a1b3716ed55d5f (diff) | |
parent | 1a6d3a529be65d3f75e02f522ee0c77025191fb2 (diff) |
Merge pull request #14318 from muxi/add-logging-interface
Add mobile log interface to ObjC
Diffstat (limited to 'src/objective-c/GRPCClient/private')
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCChannel.m | 22 | ||||
-rw-r--r-- | src/objective-c/GRPCClient/private/GRPCHost.m | 6 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index 87646f7895..b53d84159d 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -32,6 +32,24 @@ #endif #import "GRPCCompletionQueue.h" +static void* copy_pointer_arg(void *p) { + // Add ref count to the object when making copy + id obj = (__bridge id)p; + return (__bridge_retained void *)obj; +} + +static void destroy_pointer_arg(void *p) { + // Decrease ref count to the object when destroying + CFRelease((CFTreeRef)p); +} + +static int cmp_pointer_arg(void *p, void *q) { + return p == q; +} + +static const grpc_arg_pointer_vtable objc_arg_vtable = { + copy_pointer_arg, destroy_pointer_arg, cmp_pointer_arg}; + static void FreeChannelArgs(grpc_channel_args *channel_args) { for (size_t i = 0; i < channel_args->num_args; ++i) { grpc_arg *arg = &channel_args->args[i]; @@ -75,6 +93,10 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { } else if ([value respondsToSelector:@selector(intValue)]) { arg->type = GRPC_ARG_INTEGER; arg->value.integer = [value intValue]; + } else if (value != nil) { + arg->type = GRPC_ARG_POINTER; + arg->value.pointer.p = (__bridge_retained void *)value; + arg->value.pointer.vtable = &objc_arg_vtable; } else { [NSException raise:NSInvalidArgumentException format:@"Invalid value type: %@", [value class]]; diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m index ceae9607d7..71b57cf1f6 100644 --- a/src/objective-c/GRPCClient/private/GRPCHost.m +++ b/src/objective-c/GRPCClient/private/GRPCHost.m @@ -21,6 +21,7 @@ #include <grpc/grpc.h> #include <grpc/grpc_security.h> #import <GRPCClient/GRPCCall.h> +#import <GRPCClient/GRPCCall+MobileLog.h> #ifdef GRPC_COMPILE_WITH_CRONET #import <GRPCClient/GRPCCall+ChannelArg.h> #import <GRPCClient/GRPCCall+Cronet.h> @@ -231,6 +232,11 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil; [NSNumber numberWithInt:_compressAlgorithm]; } + id logConfig = [GRPCCall logConfig]; + if (logConfig != nil) { + args[@GRPC_ARG_MOBILE_LOG_CONFIG] = logConfig; + } + return args; } |