Skip to content
Snippets Groups Projects
Commit 95d75ea4 authored by Muxi Yan's avatar Muxi Yan
Browse files

clean with clang-format

parent 48483697
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
*/ */
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ #define GRPC_XMACRO_ITEM(methodName, FlagName) \
@property(nonatomic, readonly) BOOL methodName; @property(nonatomic, readonly) BOOL methodName;
#include "GRPCReachabilityFlagNames.xmacro.h" #include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM #undef GRPC_XMACRO_ITEM
...@@ -53,7 +53,6 @@ ...@@ -53,7 +53,6 @@
@property(nonatomic, readonly) BOOL isHostReachable; @property(nonatomic, readonly) BOOL isHostReachable;
@end @end
@interface GRPCConnectivityMonitor : NSObject @interface GRPCConnectivityMonitor : NSObject
+ (nullable instancetype)monitorWithHost:(nonnull NSString *)hostName; + (nullable instancetype)monitorWithHost:(nonnull NSString *)hostName;
...@@ -61,17 +60,21 @@ ...@@ -61,17 +60,21 @@
- (nonnull instancetype)init NS_UNAVAILABLE; - (nonnull instancetype)init NS_UNAVAILABLE;
/** /**
* Queue on which callbacks will be dispatched. Default is the main queue. Set it before calling * Queue on which callbacks will be dispatched. Default is the main queue. Set
* it before calling
* handleLossWithHandler:. * handleLossWithHandler:.
*/ */
// TODO(jcanizales): Default to a serial background queue instead. // TODO(jcanizales): Default to a serial background queue instead.
@property(nonatomic, strong, null_resettable) dispatch_queue_t queue; @property(nonatomic, strong, null_resettable) dispatch_queue_t queue;
/** /**
* Calls handler every time the connectivity to this instance's host is lost. If this instance is * Calls handler every time the connectivity to this instance's host is lost. If
* this instance is
* released before that happens, the handler won't be called. * released before that happens, the handler won't be called.
* Only one handler is active at a time, so if this method is called again before the previous * Only one handler is active at a time, so if this method is called again
* handler has been called, it might never be called at all (or yes, if it has already been queued). * before the previous
* handler has been called, it might never be called at all (or yes, if it has
* already been queued).
*/ */
- (void)handleLossWithHandler:(nonnull void (^)())handler - (void)handleLossWithHandler:(nonnull void (^)())handler
wifiStatusChangeHandler:(nonnull void (^)())wifiStatusChangeHandler; wifiStatusChangeHandler:(nonnull void (^)())wifiStatusChangeHandler;
......
...@@ -58,45 +58,50 @@ ...@@ -58,45 +58,50 @@
} }
*/ */
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ #define GRPC_XMACRO_ITEM(methodName, FlagName) \
- (BOOL)methodName { \ -(BOOL)methodName { \
return !!(_flags & kSCNetworkReachabilityFlags ## FlagName); \ return !!(_flags & kSCNetworkReachabilityFlags##FlagName); \
} }
#include "GRPCReachabilityFlagNames.xmacro.h" #include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM #undef GRPC_XMACRO_ITEM
- (BOOL)isHostReachable { - (BOOL)isHostReachable {
// Note: connectionOnDemand means it'll be reachable only if using the CFSocketStream API or APIs // Note: connectionOnDemand means it'll be reachable only if using the
// CFSocketStream API or APIs
// on top of it. // on top of it.
// connectionRequired means we can't tell until a connection is attempted (e.g. for VPN on // connectionRequired means we can't tell until a connection is attempted
// (e.g. for VPN on
// demand). // demand).
return self.reachable && !self.interventionRequired && !self.connectionOnDemand; return self.reachable && !self.interventionRequired &&
!self.connectionOnDemand;
} }
- (NSString *)description { - (NSString *)description {
NSMutableArray *activeOptions = [NSMutableArray arrayWithCapacity:9]; NSMutableArray *activeOptions = [NSMutableArray arrayWithCapacity:9];
/* /*
* For each flag, add its name to the array if it's ON. Example: * For each flag, add its name to the array if it's ON. Example:
if (self.isCell) { if (self.isCell) {
[activeOptions addObject:@"isCell"]; [activeOptions addObject:@"isCell"];
} }
*/ */
#define GRPC_XMACRO_ITEM(methodName, FlagName) \ #define GRPC_XMACRO_ITEM(methodName, FlagName) \
if (self.methodName) { \ if (self.methodName) { \
[activeOptions addObject:@#methodName]; \ [activeOptions addObject:@ #methodName]; \
} }
#include "GRPCReachabilityFlagNames.xmacro.h" #include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM #undef GRPC_XMACRO_ITEM
return activeOptions.count == 0 ? @"(none)" : [activeOptions componentsJoinedByString:@", "]; return activeOptions.count == 0
? @"(none)"
: [activeOptions componentsJoinedByString:@", "];
} }
- (BOOL)isEqual:(id)object { - (BOOL)isEqual:(id)object {
return [object isKindOfClass:[GRPCReachabilityFlags class]] && return [object isKindOfClass:[GRPCReachabilityFlags class]] &&
_flags == ((GRPCReachabilityFlags *)object)->_flags; _flags == ((GRPCReachabilityFlags *)object)->_flags;
} }
- (NSUInteger)hash { - (NSUInteger)hash {
...@@ -106,15 +111,18 @@ ...@@ -106,15 +111,18 @@
#pragma mark Connectivity Monitor #pragma mark Connectivity Monitor
// Assumes the third argument is a block that accepts a GRPCReachabilityFlags object, and passes the // Assumes the third argument is a block that accepts a GRPCReachabilityFlags
// object, and passes the
// received ones to it. // received ones to it.
static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
SCNetworkReachabilityFlags flags, SCNetworkReachabilityFlags flags,
void *info) { void *info) {
#pragma unused (target) #pragma unused(target)
// This can be called many times with the same info. The info is retained by SCNetworkReachability // This can be called many times with the same info. The info is retained by
// SCNetworkReachability
// while this function is being executed. // while this function is being executed.
void (^handler)(GRPCReachabilityFlags *) = (__bridge void (^)(GRPCReachabilityFlags *))info; void (^handler)(GRPCReachabilityFlags *) =
(__bridge void (^)(GRPCReachabilityFlags *))info;
handler([[GRPCReachabilityFlags alloc] initWithFlags:flags]); handler([[GRPCReachabilityFlags alloc] initWithFlags:flags]);
} }
...@@ -123,7 +131,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, ...@@ -123,7 +131,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
GRPCReachabilityFlags *_previousReachabilityFlags; GRPCReachabilityFlags *_previousReachabilityFlags;
} }
- (nullable instancetype)initWithReachability:(nullable SCNetworkReachabilityRef)reachability { - (nullable instancetype)initWithReachability:
(nullable SCNetworkReachabilityRef)reachability {
if (!reachability) { if (!reachability) {
return nil; return nil;
} }
...@@ -144,7 +153,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, ...@@ -144,7 +153,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
SCNetworkReachabilityRef reachability = SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, hostName); SCNetworkReachabilityCreateWithName(NULL, hostName);
GRPCConnectivityMonitor *returnValue = [[self alloc] initWithReachability:reachability]; GRPCConnectivityMonitor *returnValue =
[[self alloc] initWithReachability:reachability];
if (reachability) { if (reachability) {
CFRelease(reachability); CFRelease(reachability);
} }
...@@ -160,7 +170,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, ...@@ -160,7 +170,8 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
if (!flags.reachable) { if (!flags.reachable) {
handler(); handler();
} else if (strongSelf->_previousReachabilityFlags && } else if (strongSelf->_previousReachabilityFlags &&
(flags.isWWAN ^ strongSelf->_previousReachabilityFlags.isWWAN)) { (flags.isWWAN ^
strongSelf->_previousReachabilityFlags.isWWAN)) {
wifiStatusChangeHandler(); wifiStatusChangeHandler();
} }
strongSelf->_previousReachabilityFlags = flags; strongSelf->_previousReachabilityFlags = flags;
...@@ -169,17 +180,20 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target, ...@@ -169,17 +180,20 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
} }
- (void)startListeningWithHandler:(void (^)(GRPCReachabilityFlags *))handler { - (void)startListeningWithHandler:(void (^)(GRPCReachabilityFlags *))handler {
// Copy to ensure the handler block is in the heap (and so can't be deallocated when this method // Copy to ensure the handler block is in the heap (and so can't be
// deallocated when this method
// returns). // returns).
void (^copiedHandler)(GRPCReachabilityFlags *) = [handler copy]; void (^copiedHandler)(GRPCReachabilityFlags *) = [handler copy];
SCNetworkReachabilityContext context = { SCNetworkReachabilityContext context = {
.version = 0, .version = 0,
.info = (__bridge void *)copiedHandler, .info = (__bridge void *)copiedHandler,
.retain = CFRetain, .retain = CFRetain,
.release = CFRelease, .release = CFRelease,
}; };
// The following will retain context.info, and release it when the callback is set to NULL. // The following will retain context.info, and release it when the callback is
SCNetworkReachabilitySetCallback(_reachabilityRef, PassFlagsToContextInfoBlock, &context); // set to NULL.
SCNetworkReachabilitySetCallback(_reachabilityRef,
PassFlagsToContextInfoBlock, &context);
SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _queue); SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _queue);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment