Run CLANGFORMAT on FlipperKit folder
Summary: This diff runs CLANGFORMAT lint on FlipperKit. I have added CLANGFORMAT as the lint engined for objc files in xplat/sonar. Right now the iOS folder is not formatted according to CLANGFORMAT. Ran `arc lint -a --paths-cmd "find ./iOS/FlipperKit -type f" --verbose` Reviewed By: passy Differential Revision: D19942170 fbshipit-source-id: af677323af4edb761f61f8f7e289cab743aa31f2
This commit is contained in:
committed by
Facebook Github Bot
parent
127eec5fa1
commit
ca513cf370
@@ -15,22 +15,23 @@
|
||||
|
||||
static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
|
||||
@interface FKPortForwardingClient () <GCDAsyncSocketDelegate, PTChannelDelegate>
|
||||
{
|
||||
@interface FKPortForwardingClient ()<
|
||||
GCDAsyncSocketDelegate,
|
||||
PTChannelDelegate> {
|
||||
NSUInteger _destPort;
|
||||
NSUInteger _channelPort;
|
||||
NSNumber *_connectingToDeviceID;
|
||||
NSNumber *_connectedDeviceID;
|
||||
NSDictionary *_connectedDeviceProperties;
|
||||
NSNumber* _connectingToDeviceID;
|
||||
NSNumber* _connectedDeviceID;
|
||||
NSDictionary* _connectedDeviceProperties;
|
||||
BOOL _notConnectedQueueSuspended;
|
||||
PTChannel *_connectedChannel;
|
||||
PTChannel* _connectedChannel;
|
||||
dispatch_queue_t _notConnectedQueue;
|
||||
dispatch_queue_t _clientSocketsQueue;
|
||||
NSMutableDictionary *_clientSockets;
|
||||
NSMutableDictionary* _clientSockets;
|
||||
}
|
||||
|
||||
@property (atomic, readonly) NSNumber *connectedDeviceID;
|
||||
@property (atomic, assign) PTChannel *connectedChannel;
|
||||
@property(atomic, readonly) NSNumber* connectedDeviceID;
|
||||
@property(atomic, assign) PTChannel* connectedChannel;
|
||||
|
||||
@end
|
||||
|
||||
@@ -38,42 +39,40 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
|
||||
@synthesize connectedDeviceID = _connectedDeviceID;
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_notConnectedQueue = dispatch_queue_create("FKPortForwarding.notConnectedQueue", DISPATCH_QUEUE_SERIAL);
|
||||
_clientSocketsQueue = dispatch_queue_create("FKPortForwarding.clients", DISPATCH_QUEUE_SERIAL);
|
||||
_notConnectedQueue = dispatch_queue_create(
|
||||
"FKPortForwarding.notConnectedQueue", DISPATCH_QUEUE_SERIAL);
|
||||
_clientSocketsQueue = dispatch_queue_create(
|
||||
"FKPortForwarding.clients", DISPATCH_QUEUE_SERIAL);
|
||||
_clientSockets = [NSMutableDictionary dictionary];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)forwardConnectionsToPort:(NSUInteger)port
|
||||
{
|
||||
- (void)forwardConnectionsToPort:(NSUInteger)port {
|
||||
_destPort = port;
|
||||
}
|
||||
|
||||
- (void)connectToMultiplexingChannelOnPort:(NSUInteger)port
|
||||
{
|
||||
- (void)connectToMultiplexingChannelOnPort:(NSUInteger)port {
|
||||
_channelPort = port;
|
||||
[self startListeningForDevices];
|
||||
[self enqueueConnectToLocalIPv4Port];
|
||||
}
|
||||
|
||||
- (void)close
|
||||
{
|
||||
- (void)close {
|
||||
[self.connectedChannel close];
|
||||
}
|
||||
|
||||
- (PTChannel *)connectedChannel {
|
||||
- (PTChannel*)connectedChannel {
|
||||
return _connectedChannel;
|
||||
}
|
||||
|
||||
- (void)setConnectedChannel:(PTChannel *)connectedChannel {
|
||||
- (void)setConnectedChannel:(PTChannel*)connectedChannel {
|
||||
_connectedChannel = connectedChannel;
|
||||
|
||||
if (!_connectedChannel) {
|
||||
for (GCDAsyncSocket *sock in [_clientSockets objectEnumerator]) {
|
||||
for (GCDAsyncSocket* sock in [_clientSockets objectEnumerator]) {
|
||||
[sock setDelegate:nil];
|
||||
[sock disconnect];
|
||||
}
|
||||
@@ -94,40 +93,52 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - PTChannelDelegate
|
||||
|
||||
- (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
|
||||
//NSLog(@"received %@, %u, %u, %@", channel, type, tag, payload);
|
||||
- (void)ioFrameChannel:(PTChannel*)channel
|
||||
didReceiveFrameOfType:(uint32_t)type
|
||||
tag:(uint32_t)tag
|
||||
payload:(PTData*)payload {
|
||||
// NSLog(@"received %@, %u, %u, %@", channel, type, tag, payload);
|
||||
|
||||
if (type == FKPortForwardingFrameTypeOpenPipe) {
|
||||
GCDAsyncSocket *sock = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_clientSocketsQueue];
|
||||
GCDAsyncSocket* sock =
|
||||
[[GCDAsyncSocket alloc] initWithDelegate:self
|
||||
delegateQueue:_clientSocketsQueue];
|
||||
sock.userData = @(tag);
|
||||
_clientSockets[@(tag)] = sock;
|
||||
|
||||
NSError *connectError;
|
||||
if (![sock connectToHost:@"localhost" onPort:_destPort error:&connectError]) {
|
||||
FBPFLog(@"Failed to connect to local %lu - %@", (unsigned long)_destPort, connectError);
|
||||
NSError* connectError;
|
||||
if (![sock connectToHost:@"localhost"
|
||||
onPort:_destPort
|
||||
error:&connectError]) {
|
||||
FBPFLog(
|
||||
@"Failed to connect to local %lu - %@",
|
||||
(unsigned long)_destPort,
|
||||
connectError);
|
||||
}
|
||||
|
||||
FBPFTrace(@"open socket (%d)", tag);
|
||||
}
|
||||
|
||||
if (type == FKPortForwardingFrameTypeWriteToPipe) {
|
||||
GCDAsyncSocket *sock = _clientSockets[@(tag)];
|
||||
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
|
||||
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
||||
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length]
|
||||
withTimeout:-1
|
||||
tag:0];
|
||||
FBPFTrace(@"channel -> socket (%d) %zu bytes", tag, payload.length);
|
||||
}
|
||||
|
||||
if (type == FKPortForwardingFrameTypeClosePipe) {
|
||||
GCDAsyncSocket *sock = _clientSockets[@(tag)];
|
||||
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
||||
[sock disconnectAfterWriting];
|
||||
FBPFTrace(@"close socket (%d)", tag);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)ioFrameChannel:(PTChannel *)channel didEndWithError:(NSError *)error {
|
||||
if (_connectedDeviceID && [_connectedDeviceID isEqualToNumber:channel.userInfo]) {
|
||||
- (void)ioFrameChannel:(PTChannel*)channel didEndWithError:(NSError*)error {
|
||||
if (_connectedDeviceID &&
|
||||
[_connectedDeviceID isEqualToNumber:channel.userInfo]) {
|
||||
[self didDisconnectFromDevice:_connectedDeviceID];
|
||||
}
|
||||
|
||||
@@ -137,69 +148,85 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - GCDAsyncSocketDelegate
|
||||
|
||||
|
||||
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
||||
{
|
||||
FBPFTrace(@"socket (%ld) connected to %@", (long)[sock.userData integerValue], host);
|
||||
- (void)socket:(GCDAsyncSocket*)sock
|
||||
didConnectToHost:(NSString*)host
|
||||
port:(uint16_t)port {
|
||||
FBPFTrace(
|
||||
@"socket (%ld) connected to %@",
|
||||
(long)[sock.userData integerValue],
|
||||
host);
|
||||
[sock readDataWithTimeout:-1 tag:0];
|
||||
}
|
||||
|
||||
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
|
||||
{
|
||||
- (void)socketDidDisconnect:(GCDAsyncSocket*)sock withError:(NSError*)err {
|
||||
UInt32 tag = [sock.userData unsignedIntValue];
|
||||
[_clientSockets removeObjectForKey:@(tag)];
|
||||
FBPFTrace(@"socket (%d) disconnected", (unsigned int)tag);
|
||||
|
||||
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeClosePipe tag:tag withPayload:nil callback:nil];
|
||||
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeClosePipe
|
||||
tag:tag
|
||||
withPayload:nil
|
||||
callback:nil];
|
||||
}
|
||||
|
||||
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)_
|
||||
{
|
||||
- (void)socket:(GCDAsyncSocket*)sock didReadData:(NSData*)data withTag:(long)_ {
|
||||
UInt32 tag = [sock.userData unsignedIntValue];
|
||||
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
|
||||
FBPFTrace(@"channel -> socket (%d), %lu bytes", (unsigned int)tag, (unsigned long)data.length);
|
||||
[sock readDataWithTimeout:-1 tag:0];
|
||||
}];
|
||||
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe
|
||||
tag:tag
|
||||
withPayload:NSDataToGCDData(data)
|
||||
callback:^(NSError* error) {
|
||||
FBPFTrace(
|
||||
@"channel -> socket (%d), %lu bytes",
|
||||
(unsigned int)tag,
|
||||
(unsigned long)data.length);
|
||||
[sock readDataWithTimeout:-1 tag:0];
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Wired device connections
|
||||
|
||||
|
||||
- (void)startListeningForDevices {
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
|
||||
[nc addObserverForName:PTUSBDeviceDidAttachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) {
|
||||
NSNumber *deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||
//NSLog(@"PTUSBDeviceDidAttachNotification: %@", note.userInfo);
|
||||
FBPFTrace(@"PTUSBDeviceDidAttachNotification: %@", deviceID);
|
||||
[nc addObserverForName:PTUSBDeviceDidAttachNotification
|
||||
object:PTUSBHub.sharedHub
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification* note) {
|
||||
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||
// NSLog(@"PTUSBDeviceDidAttachNotification: %@",
|
||||
// note.userInfo);
|
||||
FBPFTrace(@"PTUSBDeviceDidAttachNotification: %@", deviceID);
|
||||
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
typeof(self) strongSelf = weakSelf;
|
||||
if (!strongSelf) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch_async(strongSelf->_notConnectedQueue, ^{
|
||||
[strongSelf didAttachToDevice:deviceID note:note];
|
||||
});
|
||||
}];
|
||||
dispatch_async(strongSelf->_notConnectedQueue, ^{
|
||||
[strongSelf didAttachToDevice:deviceID note:note];
|
||||
});
|
||||
}];
|
||||
|
||||
[nc addObserverForName:PTUSBDeviceDidDetachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) {
|
||||
NSNumber *deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||
//NSLog(@"PTUSBDeviceDidDetachNotification: %@", note.userInfo);
|
||||
FBPFTrace(@"PTUSBDeviceDidDetachNotification: %@", deviceID);
|
||||
[nc addObserverForName:PTUSBDeviceDidDetachNotification
|
||||
object:PTUSBHub.sharedHub
|
||||
queue:nil
|
||||
usingBlock:^(NSNotification* note) {
|
||||
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||
// NSLog(@"PTUSBDeviceDidDetachNotification: %@",
|
||||
// note.userInfo);
|
||||
FBPFTrace(@"PTUSBDeviceDidDetachNotification: %@", deviceID);
|
||||
|
||||
[weakSelf didDetachFromDevice:deviceID];
|
||||
}];
|
||||
[weakSelf didDetachFromDevice:deviceID];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)didAttachToDevice:(NSNumber *)deviceID note:(NSNotification *)note
|
||||
{
|
||||
if (!_connectingToDeviceID || ![deviceID isEqualToNumber:_connectingToDeviceID]) {
|
||||
- (void)didAttachToDevice:(NSNumber*)deviceID note:(NSNotification*)note {
|
||||
if (!_connectingToDeviceID ||
|
||||
![deviceID isEqualToNumber:_connectingToDeviceID]) {
|
||||
[self disconnectFromCurrentChannel];
|
||||
_connectingToDeviceID = deviceID;
|
||||
_connectedDeviceProperties = [note.userInfo objectForKey:@"Properties"];
|
||||
@@ -207,8 +234,7 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didDetachFromDevice:(NSNumber *)deviceID
|
||||
{
|
||||
- (void)didDetachFromDevice:(NSNumber*)deviceID {
|
||||
if ([_connectingToDeviceID isEqualToNumber:deviceID]) {
|
||||
_connectedDeviceProperties = nil;
|
||||
_connectingToDeviceID = nil;
|
||||
@@ -218,8 +244,7 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)didDisconnectFromDevice:(NSNumber *)deviceID {
|
||||
- (void)didDisconnectFromDevice:(NSNumber*)deviceID {
|
||||
FBPFLog(@"Disconnected from device #%@", deviceID);
|
||||
if ([_connectedDeviceID isEqualToNumber:deviceID]) {
|
||||
[self willChangeValueForKey:@"connectedDeviceID"];
|
||||
@@ -228,7 +253,6 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void)disconnectFromCurrentChannel {
|
||||
if (_connectedDeviceID && _connectedChannel) {
|
||||
[_connectedChannel close];
|
||||
@@ -244,25 +268,34 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
- (void)connectToLocalIPv4Port {
|
||||
PTChannel *channel = [PTChannel channelWithDelegate:self];
|
||||
channel.userInfo = [NSString stringWithFormat:@"127.0.0.1:%lu", (unsigned long)_channelPort];
|
||||
[channel connectToPort:_channelPort IPv4Address:INADDR_LOOPBACK callback:^(NSError *error, PTAddress *address) {
|
||||
if (error) {
|
||||
if (error.domain == NSPOSIXErrorDomain && (error.code == ECONNREFUSED || error.code == ETIMEDOUT)) {
|
||||
// this is an expected state
|
||||
} else {
|
||||
FBPFTrace(@"Failed to connect to 127.0.0.1:%lu: %@", (unsigned long)_channelPort, error);
|
||||
}
|
||||
} else {
|
||||
[self disconnectFromCurrentChannel];
|
||||
self.connectedChannel = channel;
|
||||
channel.userInfo = address;
|
||||
FBPFLog(@"Connected to %@", address);
|
||||
}
|
||||
[self performSelector:@selector(enqueueConnectToLocalIPv4Port) withObject:nil afterDelay:ReconnectDelay];
|
||||
}];
|
||||
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
||||
channel.userInfo =
|
||||
[NSString stringWithFormat:@"127.0.0.1:%lu", (unsigned long)_channelPort];
|
||||
[channel
|
||||
connectToPort:_channelPort
|
||||
IPv4Address:INADDR_LOOPBACK
|
||||
callback:^(NSError* error, PTAddress* address) {
|
||||
if (error) {
|
||||
if (error.domain == NSPOSIXErrorDomain &&
|
||||
(error.code == ECONNREFUSED || error.code == ETIMEDOUT)) {
|
||||
// this is an expected state
|
||||
} else {
|
||||
FBPFTrace(
|
||||
@"Failed to connect to 127.0.0.1:%lu: %@",
|
||||
(unsigned long)_channelPort,
|
||||
error);
|
||||
}
|
||||
} else {
|
||||
[self disconnectFromCurrentChannel];
|
||||
self.connectedChannel = channel;
|
||||
channel.userInfo = address;
|
||||
FBPFLog(@"Connected to %@", address);
|
||||
}
|
||||
[self performSelector:@selector(enqueueConnectToLocalIPv4Port)
|
||||
withObject:nil
|
||||
afterDelay:ReconnectDelay];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)enqueueConnectToUSBDevice {
|
||||
@@ -273,30 +306,35 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
- (void)connectToUSBDevice {
|
||||
PTChannel *channel = [PTChannel channelWithDelegate:self];
|
||||
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
||||
channel.userInfo = _connectingToDeviceID;
|
||||
channel.delegate = self;
|
||||
|
||||
[channel connectToPort:(int)_channelPort overUSBHub:PTUSBHub.sharedHub deviceID:_connectingToDeviceID callback:^(NSError *error) {
|
||||
[self didConnectToChannel:channel withError:error];
|
||||
}];
|
||||
[channel connectToPort:(int)_channelPort
|
||||
overUSBHub:PTUSBHub.sharedHub
|
||||
deviceID:_connectingToDeviceID
|
||||
callback:^(NSError* error) {
|
||||
[self didConnectToChannel:channel withError:error];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)didConnectToChannel:(PTChannel *)channel withError:(NSError *)error
|
||||
{
|
||||
- (void)didConnectToChannel:(PTChannel*)channel withError:(NSError*)error {
|
||||
if (error) {
|
||||
FBPFTrace(@"Failed to connect to device #%@: %@", channel.userInfo, error);
|
||||
if (channel.userInfo == _connectingToDeviceID) {
|
||||
[self performSelector:@selector(enqueueConnectToUSBDevice) withObject:nil afterDelay:ReconnectDelay];
|
||||
[self performSelector:@selector(enqueueConnectToUSBDevice)
|
||||
withObject:nil
|
||||
afterDelay:ReconnectDelay];
|
||||
}
|
||||
} else {
|
||||
_connectedDeviceID = _connectingToDeviceID;
|
||||
self.connectedChannel = channel;
|
||||
FBPFLog(@"Connected to device #%@\n%@", _connectingToDeviceID, _connectedDeviceProperties);
|
||||
FBPFLog(
|
||||
@"Connected to device #%@\n%@",
|
||||
_connectingToDeviceID,
|
||||
_connectedDeviceProperties);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user