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
@@ -14,5 +14,6 @@ that forwards messages to the underlying C++ connection. This class allows
|
|||||||
pure Objective-C plugins to send messages to the underlying connection.
|
pure Objective-C plugins to send messages to the underlying connection.
|
||||||
*/
|
*/
|
||||||
@interface FlipperCppBridgingConnection : NSObject<FlipperConnection>
|
@interface FlipperCppBridgingConnection : NSObject<FlipperConnection>
|
||||||
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::flipper::FlipperConnection>)conn;
|
- (instancetype)initWithCppConnection:
|
||||||
|
(std::shared_ptr<facebook::flipper::FlipperConnection>)conn;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -14,5 +14,6 @@ that forwards messages to the underlying C++ responder. This class allows
|
|||||||
pure Objective-C plugins to send messages to the underlying responder.
|
pure Objective-C plugins to send messages to the underlying responder.
|
||||||
*/
|
*/
|
||||||
@interface FlipperCppBridgingResponder : NSObject<FlipperResponder>
|
@interface FlipperCppBridgingResponder : NSObject<FlipperResponder>
|
||||||
- (instancetype)initWithCppResponder:(std::shared_ptr<facebook::flipper::FlipperResponder>)responder;
|
- (instancetype)initWithCppResponder:
|
||||||
|
(std::shared_ptr<facebook::flipper::FlipperResponder>)responder;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
std::shared_ptr<facebook::flipper::FlipperResponder> responder_;
|
std::shared_ptr<facebook::flipper::FlipperResponder> responder_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithCppResponder:(std::shared_ptr<facebook::flipper::FlipperResponder>)responder
|
- (instancetype)initWithCppResponder:
|
||||||
{
|
(std::shared_ptr<facebook::flipper::FlipperResponder>)responder {
|
||||||
if (!responder) {
|
if (!responder) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,14 @@
|
|||||||
|
|
||||||
#pragma mark - FlipperResponder
|
#pragma mark - FlipperResponder
|
||||||
|
|
||||||
- (void)success:(NSDictionary *)response { responder_->success(facebook::cxxutils::convertIdToFollyDynamic(response, true)); }
|
- (void)success:(NSDictionary*)response {
|
||||||
|
responder_->success(
|
||||||
|
facebook::cxxutils::convertIdToFollyDynamic(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
- (void)error:(NSDictionary *)response { responder_->error(facebook::cxxutils::convertIdToFollyDynamic(response, true)); }
|
- (void)error:(NSDictionary*)response {
|
||||||
|
responder_->error(
|
||||||
|
facebook::cxxutils::convertIdToFollyDynamic(response, true));
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -28,15 +28,20 @@ public:
|
|||||||
// Under ARC copying objCPlugin *does* increment its retain count
|
// Under ARC copying objCPlugin *does* increment its retain count
|
||||||
FlipperCppWrapperPlugin(ObjCPlugin objCPlugin) : _objCPlugin(objCPlugin) {}
|
FlipperCppWrapperPlugin(ObjCPlugin objCPlugin) : _objCPlugin(objCPlugin) {}
|
||||||
|
|
||||||
std::string identifier() const override { return [[_objCPlugin identifier] UTF8String]; }
|
std::string identifier() const override {
|
||||||
|
return [[_objCPlugin identifier] UTF8String];
|
||||||
|
}
|
||||||
|
|
||||||
void didConnect(std::shared_ptr<facebook::flipper::FlipperConnection> conn) override
|
void didConnect(
|
||||||
{
|
std::shared_ptr<facebook::flipper::FlipperConnection> conn) override {
|
||||||
FlipperCppBridgingConnection *const bridgingConn = [[FlipperCppBridgingConnection alloc] initWithCppConnection:conn];
|
FlipperCppBridgingConnection* const bridgingConn =
|
||||||
|
[[FlipperCppBridgingConnection alloc] initWithCppConnection:conn];
|
||||||
[_objCPlugin didConnect:bridgingConn];
|
[_objCPlugin didConnect:bridgingConn];
|
||||||
}
|
}
|
||||||
|
|
||||||
void didDisconnect() override { [_objCPlugin didDisconnect]; }
|
void didDisconnect() override {
|
||||||
|
[_objCPlugin didDisconnect];
|
||||||
|
}
|
||||||
|
|
||||||
bool runInBackground() override {
|
bool runInBackground() override {
|
||||||
if ([_objCPlugin respondsToSelector:@selector(runInBackground)]) {
|
if ([_objCPlugin respondsToSelector:@selector(runInBackground)]) {
|
||||||
@@ -45,7 +50,9 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjCPlugin getObjCPlugin() { return _objCPlugin; }
|
ObjCPlugin getObjCPlugin() {
|
||||||
|
return _objCPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ObjCPlugin _objCPlugin;
|
ObjCPlugin _objCPlugin;
|
||||||
|
|||||||
@@ -17,4 +17,5 @@ namespace cxxutils {
|
|||||||
folly::dynamic convertIdToFollyDynamic(id json, bool nullifyNanAndInf = false);
|
folly::dynamic convertIdToFollyDynamic(id json, bool nullifyNanAndInf = false);
|
||||||
id convertFollyDynamicToId(const folly::dynamic& dyn);
|
id convertFollyDynamicToId(const folly::dynamic& dyn);
|
||||||
|
|
||||||
} }
|
} // namespace cxxutils
|
||||||
|
} // namespace facebook
|
||||||
|
|||||||
@@ -16,8 +16,7 @@ namespace cxxutils {
|
|||||||
* The implementation is taken from RCTFollyConvert(https://fburl.com/vzw8ql2q)
|
* The implementation is taken from RCTFollyConvert(https://fburl.com/vzw8ql2q)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
id convertFollyDynamicToId(const folly::dynamic &dyn)
|
id convertFollyDynamicToId(const folly::dynamic& dyn) {
|
||||||
{
|
|
||||||
// I could imagine an implementation which avoids copies by wrapping the
|
// I could imagine an implementation which avoids copies by wrapping the
|
||||||
// dynamic in a derived class of NSDictionary. We can do that if profiling
|
// dynamic in a derived class of NSDictionary. We can do that if profiling
|
||||||
// implies it will help.
|
// implies it will help.
|
||||||
@@ -32,9 +31,12 @@ id convertFollyDynamicToId(const folly::dynamic &dyn)
|
|||||||
case folly::dynamic::DOUBLE:
|
case folly::dynamic::DOUBLE:
|
||||||
return @(dyn.getDouble());
|
return @(dyn.getDouble());
|
||||||
case folly::dynamic::STRING:
|
case folly::dynamic::STRING:
|
||||||
return [[NSString alloc] initWithBytes:dyn.c_str() length:dyn.size() encoding:NSUTF8StringEncoding];
|
return [[NSString alloc] initWithBytes:dyn.c_str()
|
||||||
|
length:dyn.size()
|
||||||
|
encoding:NSUTF8StringEncoding];
|
||||||
case folly::dynamic::ARRAY: {
|
case folly::dynamic::ARRAY: {
|
||||||
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:dyn.size()];
|
NSMutableArray* array =
|
||||||
|
[[NSMutableArray alloc] initWithCapacity:dyn.size()];
|
||||||
for (auto& elem : dyn) {
|
for (auto& elem : dyn) {
|
||||||
id obj = convertFollyDynamicToId(elem);
|
id obj = convertFollyDynamicToId(elem);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
@@ -44,7 +46,8 @@ id convertFollyDynamicToId(const folly::dynamic &dyn)
|
|||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
case folly::dynamic::OBJECT: {
|
case folly::dynamic::OBJECT: {
|
||||||
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:dyn.size()];
|
NSMutableDictionary* dict =
|
||||||
|
[[NSMutableDictionary alloc] initWithCapacity:dyn.size()];
|
||||||
for (auto& elem : dyn.items()) {
|
for (auto& elem : dyn.items()) {
|
||||||
id obj = convertFollyDynamicToId(elem.second);
|
id obj = convertFollyDynamicToId(elem.second);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
@@ -56,8 +59,7 @@ id convertFollyDynamicToId(const folly::dynamic &dyn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
folly::dynamic convertIdToFollyDynamic(id json, bool nullifyNanAndInf)
|
folly::dynamic convertIdToFollyDynamic(id json, bool nullifyNanAndInf) {
|
||||||
{
|
|
||||||
if (json == nil || json == (id)kCFNull) {
|
if (json == nil || json == (id)kCFNull) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
} else if ([json isKindOfClass:[NSNumber class]]) {
|
} else if ([json isKindOfClass:[NSNumber class]]) {
|
||||||
@@ -120,8 +122,11 @@ folly::dynamic convertIdToFollyDynamic(id json, bool nullifyNanAndInf)
|
|||||||
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
} else if ([json isKindOfClass:[NSDictionary class]]) {
|
||||||
__block folly::dynamic object = folly::dynamic::object();
|
__block folly::dynamic object = folly::dynamic::object();
|
||||||
|
|
||||||
[json enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, __unused BOOL *stop) {
|
[json enumerateKeysAndObjectsUsingBlock:^(
|
||||||
object.insert(convertIdToFollyDynamic(key, nullifyNanAndInf), convertIdToFollyDynamic(value, nullifyNanAndInf));
|
NSString* key, NSString* value, __unused BOOL* stop) {
|
||||||
|
object.insert(
|
||||||
|
convertIdToFollyDynamic(key, nullifyNanAndInf),
|
||||||
|
convertIdToFollyDynamic(value, nullifyNanAndInf));
|
||||||
}];
|
}];
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
|||||||
@@ -15,8 +15,9 @@
|
|||||||
|
|
||||||
static const NSTimeInterval ReconnectDelay = 1.0;
|
static const NSTimeInterval ReconnectDelay = 1.0;
|
||||||
|
|
||||||
@interface FKPortForwardingClient () <GCDAsyncSocketDelegate, PTChannelDelegate>
|
@interface FKPortForwardingClient ()<
|
||||||
{
|
GCDAsyncSocketDelegate,
|
||||||
|
PTChannelDelegate> {
|
||||||
NSUInteger _destPort;
|
NSUInteger _destPort;
|
||||||
NSUInteger _channelPort;
|
NSUInteger _channelPort;
|
||||||
NSNumber* _connectingToDeviceID;
|
NSNumber* _connectingToDeviceID;
|
||||||
@@ -38,30 +39,28 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
|
|
||||||
@synthesize connectedDeviceID = _connectedDeviceID;
|
@synthesize connectedDeviceID = _connectedDeviceID;
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_notConnectedQueue = dispatch_queue_create("FKPortForwarding.notConnectedQueue", DISPATCH_QUEUE_SERIAL);
|
_notConnectedQueue = dispatch_queue_create(
|
||||||
_clientSocketsQueue = dispatch_queue_create("FKPortForwarding.clients", DISPATCH_QUEUE_SERIAL);
|
"FKPortForwarding.notConnectedQueue", DISPATCH_QUEUE_SERIAL);
|
||||||
|
_clientSocketsQueue = dispatch_queue_create(
|
||||||
|
"FKPortForwarding.clients", DISPATCH_QUEUE_SERIAL);
|
||||||
_clientSockets = [NSMutableDictionary dictionary];
|
_clientSockets = [NSMutableDictionary dictionary];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forwardConnectionsToPort:(NSUInteger)port
|
- (void)forwardConnectionsToPort:(NSUInteger)port {
|
||||||
{
|
|
||||||
_destPort = port;
|
_destPort = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)connectToMultiplexingChannelOnPort:(NSUInteger)port
|
- (void)connectToMultiplexingChannelOnPort:(NSUInteger)port {
|
||||||
{
|
|
||||||
_channelPort = port;
|
_channelPort = port;
|
||||||
[self startListeningForDevices];
|
[self startListeningForDevices];
|
||||||
[self enqueueConnectToLocalIPv4Port];
|
[self enqueueConnectToLocalIPv4Port];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close {
|
||||||
{
|
|
||||||
[self.connectedChannel close];
|
[self.connectedChannel close];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,20 +93,29 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - PTChannelDelegate
|
#pragma mark - PTChannelDelegate
|
||||||
|
|
||||||
- (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
|
- (void)ioFrameChannel:(PTChannel*)channel
|
||||||
|
didReceiveFrameOfType:(uint32_t)type
|
||||||
|
tag:(uint32_t)tag
|
||||||
|
payload:(PTData*)payload {
|
||||||
// NSLog(@"received %@, %u, %u, %@", channel, type, tag, payload);
|
// NSLog(@"received %@, %u, %u, %@", channel, type, tag, payload);
|
||||||
|
|
||||||
if (type == FKPortForwardingFrameTypeOpenPipe) {
|
if (type == FKPortForwardingFrameTypeOpenPipe) {
|
||||||
GCDAsyncSocket *sock = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_clientSocketsQueue];
|
GCDAsyncSocket* sock =
|
||||||
|
[[GCDAsyncSocket alloc] initWithDelegate:self
|
||||||
|
delegateQueue:_clientSocketsQueue];
|
||||||
sock.userData = @(tag);
|
sock.userData = @(tag);
|
||||||
_clientSockets[@(tag)] = sock;
|
_clientSockets[@(tag)] = sock;
|
||||||
|
|
||||||
NSError* connectError;
|
NSError* connectError;
|
||||||
if (![sock connectToHost:@"localhost" onPort:_destPort error:&connectError]) {
|
if (![sock connectToHost:@"localhost"
|
||||||
FBPFLog(@"Failed to connect to local %lu - %@", (unsigned long)_destPort, connectError);
|
onPort:_destPort
|
||||||
|
error:&connectError]) {
|
||||||
|
FBPFLog(
|
||||||
|
@"Failed to connect to local %lu - %@",
|
||||||
|
(unsigned long)_destPort,
|
||||||
|
connectError);
|
||||||
}
|
}
|
||||||
|
|
||||||
FBPFTrace(@"open socket (%d)", tag);
|
FBPFTrace(@"open socket (%d)", tag);
|
||||||
@@ -115,7 +123,9 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
|
|
||||||
if (type == FKPortForwardingFrameTypeWriteToPipe) {
|
if (type == FKPortForwardingFrameTypeWriteToPipe) {
|
||||||
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
||||||
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
|
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length]
|
||||||
|
withTimeout:-1
|
||||||
|
tag:0];
|
||||||
FBPFTrace(@"channel -> socket (%d) %zu bytes", tag, payload.length);
|
FBPFTrace(@"channel -> socket (%d) %zu bytes", tag, payload.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,7 +137,8 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)ioFrameChannel:(PTChannel*)channel didEndWithError:(NSError*)error {
|
- (void)ioFrameChannel:(PTChannel*)channel didEndWithError:(NSError*)error {
|
||||||
if (_connectedDeviceID && [_connectedDeviceID isEqualToNumber:channel.userInfo]) {
|
if (_connectedDeviceID &&
|
||||||
|
[_connectedDeviceID isEqualToNumber:channel.userInfo]) {
|
||||||
[self didDisconnectFromDevice:_connectedDeviceID];
|
[self didDisconnectFromDevice:_connectedDeviceID];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,45 +148,57 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - GCDAsyncSocketDelegate
|
#pragma mark - GCDAsyncSocketDelegate
|
||||||
|
|
||||||
|
- (void)socket:(GCDAsyncSocket*)sock
|
||||||
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
|
didConnectToHost:(NSString*)host
|
||||||
{
|
port:(uint16_t)port {
|
||||||
FBPFTrace(@"socket (%ld) connected to %@", (long)[sock.userData integerValue], host);
|
FBPFTrace(
|
||||||
|
@"socket (%ld) connected to %@",
|
||||||
|
(long)[sock.userData integerValue],
|
||||||
|
host);
|
||||||
[sock readDataWithTimeout:-1 tag:0];
|
[sock readDataWithTimeout:-1 tag:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
|
- (void)socketDidDisconnect:(GCDAsyncSocket*)sock withError:(NSError*)err {
|
||||||
{
|
|
||||||
UInt32 tag = [sock.userData unsignedIntValue];
|
UInt32 tag = [sock.userData unsignedIntValue];
|
||||||
[_clientSockets removeObjectForKey:@(tag)];
|
[_clientSockets removeObjectForKey:@(tag)];
|
||||||
FBPFTrace(@"socket (%d) disconnected", (unsigned int)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];
|
UInt32 tag = [sock.userData unsignedIntValue];
|
||||||
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
|
[_connectedChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe
|
||||||
FBPFTrace(@"channel -> socket (%d), %lu bytes", (unsigned int)tag, (unsigned long)data.length);
|
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];
|
[sock readDataWithTimeout:-1 tag:0];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Wired device connections
|
#pragma mark - Wired device connections
|
||||||
|
|
||||||
|
|
||||||
- (void)startListeningForDevices {
|
- (void)startListeningForDevices {
|
||||||
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
|
||||||
|
|
||||||
__weak typeof(self) weakSelf = self;
|
__weak typeof(self) weakSelf = self;
|
||||||
|
|
||||||
[nc addObserverForName:PTUSBDeviceDidAttachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) {
|
[nc addObserverForName:PTUSBDeviceDidAttachNotification
|
||||||
|
object:PTUSBHub.sharedHub
|
||||||
|
queue:nil
|
||||||
|
usingBlock:^(NSNotification* note) {
|
||||||
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||||
//NSLog(@"PTUSBDeviceDidAttachNotification: %@", note.userInfo);
|
// NSLog(@"PTUSBDeviceDidAttachNotification: %@",
|
||||||
|
// note.userInfo);
|
||||||
FBPFTrace(@"PTUSBDeviceDidAttachNotification: %@", deviceID);
|
FBPFTrace(@"PTUSBDeviceDidAttachNotification: %@", deviceID);
|
||||||
|
|
||||||
typeof(self) strongSelf = weakSelf;
|
typeof(self) strongSelf = weakSelf;
|
||||||
@@ -188,18 +211,22 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
|
|
||||||
[nc addObserverForName:PTUSBDeviceDidDetachNotification object:PTUSBHub.sharedHub queue:nil usingBlock:^(NSNotification *note) {
|
[nc addObserverForName:PTUSBDeviceDidDetachNotification
|
||||||
|
object:PTUSBHub.sharedHub
|
||||||
|
queue:nil
|
||||||
|
usingBlock:^(NSNotification* note) {
|
||||||
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
NSNumber* deviceID = [note.userInfo objectForKey:@"DeviceID"];
|
||||||
//NSLog(@"PTUSBDeviceDidDetachNotification: %@", note.userInfo);
|
// NSLog(@"PTUSBDeviceDidDetachNotification: %@",
|
||||||
|
// note.userInfo);
|
||||||
FBPFTrace(@"PTUSBDeviceDidDetachNotification: %@", deviceID);
|
FBPFTrace(@"PTUSBDeviceDidDetachNotification: %@", deviceID);
|
||||||
|
|
||||||
[weakSelf didDetachFromDevice:deviceID];
|
[weakSelf didDetachFromDevice:deviceID];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didAttachToDevice:(NSNumber *)deviceID note:(NSNotification *)note
|
- (void)didAttachToDevice:(NSNumber*)deviceID note:(NSNotification*)note {
|
||||||
{
|
if (!_connectingToDeviceID ||
|
||||||
if (!_connectingToDeviceID || ![deviceID isEqualToNumber:_connectingToDeviceID]) {
|
![deviceID isEqualToNumber:_connectingToDeviceID]) {
|
||||||
[self disconnectFromCurrentChannel];
|
[self disconnectFromCurrentChannel];
|
||||||
_connectingToDeviceID = deviceID;
|
_connectingToDeviceID = deviceID;
|
||||||
_connectedDeviceProperties = [note.userInfo objectForKey:@"Properties"];
|
_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]) {
|
if ([_connectingToDeviceID isEqualToNumber:deviceID]) {
|
||||||
_connectedDeviceProperties = nil;
|
_connectedDeviceProperties = nil;
|
||||||
_connectingToDeviceID = nil;
|
_connectingToDeviceID = nil;
|
||||||
@@ -218,7 +244,6 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)didDisconnectFromDevice:(NSNumber*)deviceID {
|
- (void)didDisconnectFromDevice:(NSNumber*)deviceID {
|
||||||
FBPFLog(@"Disconnected from device #%@", deviceID);
|
FBPFLog(@"Disconnected from device #%@", deviceID);
|
||||||
if ([_connectedDeviceID isEqualToNumber:deviceID]) {
|
if ([_connectedDeviceID isEqualToNumber:deviceID]) {
|
||||||
@@ -228,7 +253,6 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)disconnectFromCurrentChannel {
|
- (void)disconnectFromCurrentChannel {
|
||||||
if (_connectedDeviceID && _connectedChannel) {
|
if (_connectedDeviceID && _connectedChannel) {
|
||||||
[_connectedChannel close];
|
[_connectedChannel close];
|
||||||
@@ -244,16 +268,23 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)connectToLocalIPv4Port {
|
- (void)connectToLocalIPv4Port {
|
||||||
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
||||||
channel.userInfo = [NSString stringWithFormat:@"127.0.0.1:%lu", (unsigned long)_channelPort];
|
channel.userInfo =
|
||||||
[channel connectToPort:_channelPort IPv4Address:INADDR_LOOPBACK callback:^(NSError *error, PTAddress *address) {
|
[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) {
|
||||||
if (error.domain == NSPOSIXErrorDomain && (error.code == ECONNREFUSED || error.code == ETIMEDOUT)) {
|
if (error.domain == NSPOSIXErrorDomain &&
|
||||||
|
(error.code == ECONNREFUSED || error.code == ETIMEDOUT)) {
|
||||||
// this is an expected state
|
// this is an expected state
|
||||||
} else {
|
} else {
|
||||||
FBPFTrace(@"Failed to connect to 127.0.0.1:%lu: %@", (unsigned long)_channelPort, error);
|
FBPFTrace(
|
||||||
|
@"Failed to connect to 127.0.0.1:%lu: %@",
|
||||||
|
(unsigned long)_channelPort,
|
||||||
|
error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
[self disconnectFromCurrentChannel];
|
[self disconnectFromCurrentChannel];
|
||||||
@@ -261,7 +292,9 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
channel.userInfo = address;
|
channel.userInfo = address;
|
||||||
FBPFLog(@"Connected to %@", address);
|
FBPFLog(@"Connected to %@", address);
|
||||||
}
|
}
|
||||||
[self performSelector:@selector(enqueueConnectToLocalIPv4Port) withObject:nil afterDelay:ReconnectDelay];
|
[self performSelector:@selector(enqueueConnectToLocalIPv4Port)
|
||||||
|
withObject:nil
|
||||||
|
afterDelay:ReconnectDelay];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,30 +306,35 @@ static const NSTimeInterval ReconnectDelay = 1.0;
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (void)connectToUSBDevice {
|
- (void)connectToUSBDevice {
|
||||||
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
PTChannel* channel = [PTChannel channelWithDelegate:self];
|
||||||
channel.userInfo = _connectingToDeviceID;
|
channel.userInfo = _connectingToDeviceID;
|
||||||
channel.delegate = self;
|
channel.delegate = self;
|
||||||
|
|
||||||
[channel connectToPort:(int)_channelPort overUSBHub:PTUSBHub.sharedHub deviceID:_connectingToDeviceID callback:^(NSError *error) {
|
[channel connectToPort:(int)_channelPort
|
||||||
|
overUSBHub:PTUSBHub.sharedHub
|
||||||
|
deviceID:_connectingToDeviceID
|
||||||
|
callback:^(NSError* error) {
|
||||||
[self didConnectToChannel:channel withError:error];
|
[self didConnectToChannel:channel withError:error];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didConnectToChannel:(PTChannel *)channel withError:(NSError *)error
|
- (void)didConnectToChannel:(PTChannel*)channel withError:(NSError*)error {
|
||||||
{
|
|
||||||
if (error) {
|
if (error) {
|
||||||
FBPFTrace(@"Failed to connect to device #%@: %@", channel.userInfo, error);
|
FBPFTrace(@"Failed to connect to device #%@: %@", channel.userInfo, error);
|
||||||
if (channel.userInfo == _connectingToDeviceID) {
|
if (channel.userInfo == _connectingToDeviceID) {
|
||||||
[self performSelector:@selector(enqueueConnectToUSBDevice) withObject:nil afterDelay:ReconnectDelay];
|
[self performSelector:@selector(enqueueConnectToUSBDevice)
|
||||||
|
withObject:nil
|
||||||
|
afterDelay:ReconnectDelay];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_connectedDeviceID = _connectingToDeviceID;
|
_connectedDeviceID = _connectingToDeviceID;
|
||||||
self.connectedChannel = channel;
|
self.connectedChannel = channel;
|
||||||
FBPFLog(@"Connected to device #%@\n%@", _connectingToDeviceID, _connectedDeviceProperties);
|
FBPFLog(
|
||||||
|
@"Connected to device #%@\n%@",
|
||||||
|
_connectingToDeviceID,
|
||||||
|
_connectedDeviceProperties);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
|
|
||||||
#import "FKPortForwardingCommon.h"
|
#import "FKPortForwardingCommon.h"
|
||||||
|
|
||||||
@interface FKPortForwardingServer () <PTChannelDelegate, GCDAsyncSocketDelegate>
|
@interface FKPortForwardingServer ()<
|
||||||
{
|
PTChannelDelegate,
|
||||||
|
GCDAsyncSocketDelegate> {
|
||||||
__weak PTChannel* _serverChannel;
|
__weak PTChannel* _serverChannel;
|
||||||
__weak PTChannel* _peerChannel;
|
__weak PTChannel* _peerChannel;
|
||||||
|
|
||||||
@@ -30,10 +31,10 @@
|
|||||||
|
|
||||||
@implementation FKPortForwardingServer
|
@implementation FKPortForwardingServer
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_socketQueue = dispatch_queue_create("FKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
|
_socketQueue =
|
||||||
|
dispatch_queue_create("FKPortForwardingServer", DISPATCH_QUEUE_SERIAL);
|
||||||
_lastClientSocketTag = 0;
|
_lastClientSocketTag = 0;
|
||||||
_clientSockets = [NSMutableDictionary dictionary];
|
_clientSockets = [NSMutableDictionary dictionary];
|
||||||
_protocol = [[PTProtocol alloc] initWithDispatchQueue:_socketQueue];
|
_protocol = [[PTProtocol alloc] initWithDispatchQueue:_socketQueue];
|
||||||
@@ -41,23 +42,26 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc {
|
||||||
{
|
|
||||||
[self close];
|
[self close];
|
||||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forwardConnectionsFromPort:(NSUInteger)port
|
- (void)forwardConnectionsFromPort:(NSUInteger)port {
|
||||||
{
|
|
||||||
[self _forwardConnectionsFromPort:port reportError:YES];
|
[self _forwardConnectionsFromPort:port reportError:YES];
|
||||||
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserverForName:UIApplicationDidBecomeActiveNotification
|
||||||
|
object:nil
|
||||||
|
queue:nil
|
||||||
|
usingBlock:^(NSNotification* note) {
|
||||||
[self _forwardConnectionsFromPort:port reportError:NO];
|
[self _forwardConnectionsFromPort:port reportError:NO];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_forwardConnectionsFromPort:(NSUInteger)port reportError:(BOOL)shouldReportError
|
- (void)_forwardConnectionsFromPort:(NSUInteger)port
|
||||||
{
|
reportError:(BOOL)shouldReportError {
|
||||||
GCDAsyncSocket *serverSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
|
GCDAsyncSocket* serverSocket =
|
||||||
|
[[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:_socketQueue];
|
||||||
NSError* listenError;
|
NSError* listenError;
|
||||||
if ([serverSocket acceptOnPort:port error:&listenError]) {
|
if ([serverSocket acceptOnPort:port error:&listenError]) {
|
||||||
_serverSocket = serverSocket;
|
_serverSocket = serverSocket;
|
||||||
@@ -68,21 +72,31 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port
|
- (void)listenForMultiplexingChannelOnPort:(NSUInteger)port {
|
||||||
{
|
|
||||||
[self _listenForMultiplexingChannelOnPort:port reportError:YES];
|
[self _listenForMultiplexingChannelOnPort:port reportError:YES];
|
||||||
[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification object:nil queue:nil usingBlock:^(NSNotification *note) {
|
[[NSNotificationCenter defaultCenter]
|
||||||
|
addObserverForName:UIApplicationDidBecomeActiveNotification
|
||||||
|
object:nil
|
||||||
|
queue:nil
|
||||||
|
usingBlock:^(NSNotification* note) {
|
||||||
[self _listenForMultiplexingChannelOnPort:port reportError:NO];
|
[self _listenForMultiplexingChannelOnPort:port reportError:NO];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port reportError:(BOOL)shouldReportError
|
- (void)_listenForMultiplexingChannelOnPort:(NSUInteger)port
|
||||||
{
|
reportError:(BOOL)shouldReportError {
|
||||||
PTChannel *channel = [[PTChannel alloc] initWithProtocol:_protocol delegate:self];
|
PTChannel* channel = [[PTChannel alloc] initWithProtocol:_protocol
|
||||||
[channel listenOnPort:port IPv4Address:INADDR_LOOPBACK callback:^(NSError *error) {
|
delegate:self];
|
||||||
|
[channel
|
||||||
|
listenOnPort:port
|
||||||
|
IPv4Address:INADDR_LOOPBACK
|
||||||
|
callback:^(NSError* error) {
|
||||||
if (error) {
|
if (error) {
|
||||||
if (shouldReportError) {
|
if (shouldReportError) {
|
||||||
FBPFLog(@"Failed to listen on 127.0.0.1:%lu: %@", (unsigned long)port, error);
|
FBPFLog(
|
||||||
|
@"Failed to listen on 127.0.0.1:%lu: %@",
|
||||||
|
(unsigned long)port,
|
||||||
|
error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
FBPFTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
|
FBPFTrace(@"Listening on 127.0.0.1:%lu", (unsigned long)port);
|
||||||
@@ -91,8 +105,7 @@
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)close
|
- (void)close {
|
||||||
{
|
|
||||||
if (_serverChannel) {
|
if (_serverChannel) {
|
||||||
[_serverChannel close];
|
[_serverChannel close];
|
||||||
_serverChannel = nil;
|
_serverChannel = nil;
|
||||||
@@ -102,7 +115,9 @@
|
|||||||
|
|
||||||
#pragma mark - PTChannelDelegate
|
#pragma mark - PTChannelDelegate
|
||||||
|
|
||||||
- (void)ioFrameChannel:(PTChannel *)channel didAcceptConnection:(PTChannel *)otherChannel fromAddress:(PTAddress *)address {
|
- (void)ioFrameChannel:(PTChannel*)channel
|
||||||
|
didAcceptConnection:(PTChannel*)otherChannel
|
||||||
|
fromAddress:(PTAddress*)address {
|
||||||
// Cancel any other connection. We are FIFO, so the last connection
|
// Cancel any other connection. We are FIFO, so the last connection
|
||||||
// established will cancel any previous connection and "take its place".
|
// established will cancel any previous connection and "take its place".
|
||||||
if (_peerChannel) {
|
if (_peerChannel) {
|
||||||
@@ -116,11 +131,16 @@
|
|||||||
FBPFTrace(@"Connected to %@", address);
|
FBPFTrace(@"Connected to %@", address);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)ioFrameChannel:(PTChannel *)channel didReceiveFrameOfType:(uint32_t)type tag:(uint32_t)tag payload:(PTData *)payload {
|
- (void)ioFrameChannel:(PTChannel*)channel
|
||||||
|
didReceiveFrameOfType:(uint32_t)type
|
||||||
|
tag:(uint32_t)tag
|
||||||
|
payload:(PTData*)payload {
|
||||||
// NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
|
// NSLog(@"didReceiveFrameOfType: %u, %u, %@", type, tag, payload);
|
||||||
if (type == FKPortForwardingFrameTypeWriteToPipe) {
|
if (type == FKPortForwardingFrameTypeWriteToPipe) {
|
||||||
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
GCDAsyncSocket* sock = _clientSockets[@(tag)];
|
||||||
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length] withTimeout:-1 tag:0];
|
[sock writeData:[NSData dataWithBytes:payload.data length:payload.length]
|
||||||
|
withTimeout:-1
|
||||||
|
tag:0];
|
||||||
FBPFTrace(@"channel -> socket (%d), %zu bytes", tag, payload.length);
|
FBPFTrace(@"channel -> socket (%d), %zu bytes", tag, payload.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,11 +159,10 @@
|
|||||||
FBPFTrace(@"Disconnected from %@, error = %@", channel.userInfo, error);
|
FBPFTrace(@"Disconnected from %@, error = %@", channel.userInfo, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - GCDAsyncSocketDelegate
|
#pragma mark - GCDAsyncSocketDelegate
|
||||||
|
|
||||||
- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket
|
- (void)socket:(GCDAsyncSocket*)sock
|
||||||
{
|
didAcceptNewSocket:(GCDAsyncSocket*)newSocket {
|
||||||
dispatch_block_t block = ^() {
|
dispatch_block_t block = ^() {
|
||||||
if (!self->_peerChannel) {
|
if (!self->_peerChannel) {
|
||||||
[newSocket setDelegate:nil];
|
[newSocket setDelegate:nil];
|
||||||
@@ -154,8 +173,13 @@
|
|||||||
newSocket.userData = @(tag);
|
newSocket.userData = @(tag);
|
||||||
newSocket.delegate = self;
|
newSocket.delegate = self;
|
||||||
self->_clientSockets[@(tag)] = newSocket;
|
self->_clientSockets[@(tag)] = newSocket;
|
||||||
[self->_peerChannel sendFrameOfType:FKPortForwardingFrameTypeOpenPipe tag:self->_lastClientSocketTag withPayload:nil callback:^(NSError *error) {
|
[self->_peerChannel
|
||||||
FBPFTrace(@"open socket (%d), error = %@", (unsigned int)tag, error);
|
sendFrameOfType:FKPortForwardingFrameTypeOpenPipe
|
||||||
|
tag:self->_lastClientSocketTag
|
||||||
|
withPayload:nil
|
||||||
|
callback:^(NSError* error) {
|
||||||
|
FBPFTrace(
|
||||||
|
@"open socket (%d), error = %@", (unsigned int)tag, error);
|
||||||
[newSocket readDataWithTimeout:-1 tag:0];
|
[newSocket readDataWithTimeout:-1 tag:0];
|
||||||
}];
|
}];
|
||||||
};
|
};
|
||||||
@@ -163,28 +187,46 @@
|
|||||||
if (_peerChannel) {
|
if (_peerChannel) {
|
||||||
block();
|
block();
|
||||||
} else {
|
} else {
|
||||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), _socketQueue, block);
|
dispatch_after(
|
||||||
|
dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
|
||||||
|
_socketQueue,
|
||||||
|
block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)_
|
- (void)socket:(GCDAsyncSocket*)sock didReadData:(NSData*)data withTag:(long)_ {
|
||||||
{
|
|
||||||
UInt32 tag = [[sock userData] unsignedIntValue];
|
UInt32 tag = [[sock userData] unsignedIntValue];
|
||||||
FBPFTrace(@"Incoming data on socket (%d) - %lu bytes", (unsigned int)tag, (unsigned long)data.length);
|
FBPFTrace(
|
||||||
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe tag:tag withPayload:NSDataToGCDData(data) callback:^(NSError *error) {
|
@"Incoming data on socket (%d) - %lu bytes",
|
||||||
FBPFTrace(@"socket (%d) -> channel %lu bytes, error = %@", (unsigned int)tag, (unsigned long)data.length, error);
|
(unsigned int)tag,
|
||||||
|
(unsigned long)data.length);
|
||||||
|
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeWriteToPipe
|
||||||
|
tag:tag
|
||||||
|
withPayload:NSDataToGCDData(data)
|
||||||
|
callback:^(NSError* error) {
|
||||||
|
FBPFTrace(
|
||||||
|
@"socket (%d) -> channel %lu bytes, error = %@",
|
||||||
|
(unsigned int)tag,
|
||||||
|
(unsigned long)data.length,
|
||||||
|
error);
|
||||||
[sock readDataWithTimeout:-1 tag:_];
|
[sock readDataWithTimeout:-1 tag:_];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
|
- (void)socketDidDisconnect:(GCDAsyncSocket*)sock withError:(NSError*)err {
|
||||||
{
|
|
||||||
UInt32 tag = [sock.userData unsignedIntValue];
|
UInt32 tag = [sock.userData unsignedIntValue];
|
||||||
[_clientSockets removeObjectForKey:@(tag)];
|
[_clientSockets removeObjectForKey:@(tag)];
|
||||||
[_peerChannel sendFrameOfType:FKPortForwardingFrameTypeClosePipe tag:tag withPayload:nil callback:^(NSError *error) {
|
[_peerChannel
|
||||||
FBPFTrace(@"socket (%d) disconnected, err = %@, peer error = %@", (unsigned int)tag, err, error);
|
sendFrameOfType:FKPortForwardingFrameTypeClosePipe
|
||||||
|
tag:tag
|
||||||
|
withPayload:nil
|
||||||
|
callback:^(NSError* error) {
|
||||||
|
FBPFTrace(
|
||||||
|
@"socket (%d) disconnected, err = %@, peer error = %@",
|
||||||
|
(unsigned int)tag,
|
||||||
|
err,
|
||||||
|
error);
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -12,13 +12,14 @@
|
|||||||
#import "FlipperStateUpdateListener.h"
|
#import "FlipperStateUpdateListener.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Represents a connection between the Sonar desktop och client side. Manages the lifecycle of attached
|
Represents a connection between the Sonar desktop och client side. Manages the
|
||||||
plugin instances.
|
lifecycle of attached plugin instances.
|
||||||
*/
|
*/
|
||||||
@interface FlipperClient : NSObject
|
@interface FlipperClient : NSObject
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The shared singleton FlipperClient instance. It is an error to call this on non-debug builds to avoid leaking data.
|
The shared singleton FlipperClient instance. It is an error to call this on
|
||||||
|
non-debug builds to avoid leaking data.
|
||||||
*/
|
*/
|
||||||
+ (instancetype)sharedClient;
|
+ (instancetype)sharedClient;
|
||||||
|
|
||||||
@@ -33,7 +34,8 @@ Unregister a plugin with the client.
|
|||||||
- (void)removePlugin:(NSObject<FlipperPlugin>*)plugin;
|
- (void)removePlugin:(NSObject<FlipperPlugin>*)plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Retrieve the plugin with a given identifier which was previously registered with this client.
|
Retrieve the plugin with a given identifier which was previously registered with
|
||||||
|
this client.
|
||||||
*/
|
*/
|
||||||
- (NSObject<FlipperPlugin>*)pluginWithIdentifier:(NSString*)identifier;
|
- (NSObject<FlipperPlugin>*)pluginWithIdentifier:(NSString*)identifier;
|
||||||
|
|
||||||
@@ -62,7 +64,8 @@ Subscribe a ViewController to state update change notifications
|
|||||||
*/
|
*/
|
||||||
- (void)subscribeForUpdates:(id<FlipperStateUpdateListener>)controller;
|
- (void)subscribeForUpdates:(id<FlipperStateUpdateListener>)controller;
|
||||||
|
|
||||||
// initializers are disabled. You must use `+[FlipperClient sharedClient]` instance.
|
// initializers are disabled. You must use `+[FlipperClient sharedClient]`
|
||||||
|
// instance.
|
||||||
- (instancetype)init NS_UNAVAILABLE;
|
- (instancetype)init NS_UNAVAILABLE;
|
||||||
+ (instancetype)new NS_UNAVAILABLE;
|
+ (instancetype)new NS_UNAVAILABLE;
|
||||||
|
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
#if FB_SONARKIT_ENABLED
|
#if FB_SONARKIT_ENABLED
|
||||||
|
|
||||||
#import "FlipperClient.h"
|
#import "FlipperClient.h"
|
||||||
#import "FlipperCppWrapperPlugin.h"
|
|
||||||
#import <Flipper/FlipperClient.h>
|
#import <Flipper/FlipperClient.h>
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
#include <folly/io/async/EventBase.h>
|
#include <folly/io/async/EventBase.h>
|
||||||
#include <folly/io/async/ScopedEventBaseThread.h>
|
#include <folly/io/async/ScopedEventBaseThread.h>
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#include "SKStateUpdateCPPWrapper.h"
|
|
||||||
#import "FlipperClient+Testing.h"
|
#import "FlipperClient+Testing.h"
|
||||||
|
#import "FlipperCppWrapperPlugin.h"
|
||||||
#import "SKEnvironmentVariables.h"
|
#import "SKEnvironmentVariables.h"
|
||||||
|
#include "SKStateUpdateCPPWrapper.h"
|
||||||
|
|
||||||
#if !TARGET_OS_SIMULATOR
|
#if !TARGET_OS_SIMULATOR
|
||||||
#import <FKPortForwarding/FKPortForwardingServer.h>
|
#import <FKPortForwarding/FKPortForwardingServer.h>
|
||||||
@@ -33,8 +33,7 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (instancetype)sharedClient
|
+ (instancetype)sharedClient {
|
||||||
{
|
|
||||||
static FlipperClient* sharedClient = nil;
|
static FlipperClient* sharedClient = nil;
|
||||||
static dispatch_once_t onceToken;
|
static dispatch_once_t onceToken;
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
@@ -48,31 +47,37 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
return sharedClient;
|
return sharedClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)init
|
- (instancetype)init {
|
||||||
{
|
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
UIDevice* device = [UIDevice currentDevice];
|
UIDevice* device = [UIDevice currentDevice];
|
||||||
NSString* deviceName = [device name];
|
NSString* deviceName = [device name];
|
||||||
NSBundle* bundle = [NSBundle mainBundle];
|
NSBundle* bundle = [NSBundle mainBundle];
|
||||||
NSString *appName = [bundle objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey];
|
NSString* appName =
|
||||||
|
[bundle objectForInfoDictionaryKey:(NSString*)kCFBundleNameKey];
|
||||||
NSString* appId = [bundle bundleIdentifier];
|
NSString* appId = [bundle bundleIdentifier];
|
||||||
NSString *privateAppDirectory = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES)[0];
|
NSString* privateAppDirectory = NSSearchPathForDirectoriesInDomains(
|
||||||
|
NSApplicationSupportDirectory, NSUserDomainMask, YES)[0];
|
||||||
|
|
||||||
NSFileManager* manager = [NSFileManager defaultManager];
|
NSFileManager* manager = [NSFileManager defaultManager];
|
||||||
|
|
||||||
if ([manager fileExistsAtPath:privateAppDirectory isDirectory:NULL] == NO &&
|
if ([manager fileExistsAtPath:privateAppDirectory isDirectory:NULL] == NO &&
|
||||||
![manager createDirectoryAtPath:privateAppDirectory withIntermediateDirectories:YES attributes:nil error:nil]) {
|
![manager createDirectoryAtPath:privateAppDirectory
|
||||||
|
withIntermediateDirectories:YES
|
||||||
|
attributes:nil
|
||||||
|
error:nil]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TARGET_OS_SIMULATOR
|
#if TARGET_OS_SIMULATOR
|
||||||
deviceName = [NSString stringWithFormat:@"%@ %@", [[UIDevice currentDevice] model], @"Simulator"];
|
deviceName = [NSString stringWithFormat:@"%@ %@",
|
||||||
|
[[UIDevice currentDevice] model],
|
||||||
|
@"Simulator"];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const std::string UNKNOWN = std::string("unknown");
|
static const std::string UNKNOWN = std::string("unknown");
|
||||||
try {
|
try {
|
||||||
facebook::flipper::FlipperClient::init({
|
facebook::flipper::FlipperClient::init(
|
||||||
{
|
{{
|
||||||
"localhost",
|
"localhost",
|
||||||
"iOS",
|
"iOS",
|
||||||
[deviceName UTF8String],
|
[deviceName UTF8String],
|
||||||
@@ -84,8 +89,7 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
sonarThread.getEventBase(),
|
sonarThread.getEventBase(),
|
||||||
connectionThread.getEventBase(),
|
connectionThread.getEventBase(),
|
||||||
[SKEnvironmentVariables getInsecurePort],
|
[SKEnvironmentVariables getInsecurePort],
|
||||||
[SKEnvironmentVariables getSecurePort]
|
[SKEnvironmentVariables getSecurePort]});
|
||||||
});
|
|
||||||
_cppClient = facebook::flipper::FlipperClient::instance();
|
_cppClient = facebook::flipper::FlipperClient::instance();
|
||||||
} catch (const std::system_error& e) {
|
} catch (const std::system_error& e) {
|
||||||
// Probably ran out of disk space.
|
// Probably ran out of disk space.
|
||||||
@@ -95,23 +99,19 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)refreshPlugins
|
- (void)refreshPlugins {
|
||||||
{
|
|
||||||
_cppClient->refreshPlugins();
|
_cppClient->refreshPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)addPlugin:(NSObject<FlipperPlugin> *)plugin
|
- (void)addPlugin:(NSObject<FlipperPlugin>*)plugin {
|
||||||
{
|
|
||||||
_cppClient->addPlugin(std::make_shared<WrapperPlugin>(plugin));
|
_cppClient->addPlugin(std::make_shared<WrapperPlugin>(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removePlugin:(NSObject<FlipperPlugin> *)plugin
|
- (void)removePlugin:(NSObject<FlipperPlugin>*)plugin {
|
||||||
{
|
|
||||||
_cppClient->removePlugin(std::make_shared<WrapperPlugin>(plugin));
|
_cppClient->removePlugin(std::make_shared<WrapperPlugin>(plugin));
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSObject<FlipperPlugin> *)pluginWithIdentifier:(NSString *)identifier
|
- (NSObject<FlipperPlugin>*)pluginWithIdentifier:(NSString*)identifier {
|
||||||
{
|
|
||||||
auto cppPlugin = _cppClient->getPlugin([identifier UTF8String]);
|
auto cppPlugin = _cppClient->getPlugin([identifier UTF8String]);
|
||||||
if (auto wrapper = dynamic_cast<WrapperPlugin*>(cppPlugin.get())) {
|
if (auto wrapper = dynamic_cast<WrapperPlugin*>(cppPlugin.get())) {
|
||||||
return wrapper->getObjCPlugin();
|
return wrapper->getObjCPlugin();
|
||||||
@@ -119,8 +119,7 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)start
|
- (void)start {
|
||||||
{
|
|
||||||
#if !TARGET_OS_SIMULATOR
|
#if !TARGET_OS_SIMULATOR
|
||||||
_secureServer = [FKPortForwardingServer new];
|
_secureServer = [FKPortForwardingServer new];
|
||||||
[_secureServer forwardConnectionsFromPort:8088];
|
[_secureServer forwardConnectionsFromPort:8088];
|
||||||
@@ -132,9 +131,7 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
_cppClient->start();
|
_cppClient->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)stop {
|
||||||
- (void)stop
|
|
||||||
{
|
|
||||||
_cppClient->stop();
|
_cppClient->stop();
|
||||||
#if !TARGET_OS_SIMULATOR
|
#if !TARGET_OS_SIMULATOR
|
||||||
[_secureServer close];
|
[_secureServer close];
|
||||||
@@ -149,9 +146,11 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSArray*)getStateElements {
|
- (NSArray*)getStateElements {
|
||||||
NSMutableArray<NSDictionary<NSString *, NSString *>*> *const array = [NSMutableArray array];
|
NSMutableArray<NSDictionary<NSString*, NSString*>*>* const array =
|
||||||
|
[NSMutableArray array];
|
||||||
|
|
||||||
for (facebook::flipper::StateElement element: _cppClient->getStateElements()) {
|
for (facebook::flipper::StateElement element :
|
||||||
|
_cppClient->getStateElements()) {
|
||||||
facebook::flipper::State state = element.state_;
|
facebook::flipper::State state = element.state_;
|
||||||
NSString* stateString;
|
NSString* stateString;
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
|||||||
@@ -7,14 +7,15 @@
|
|||||||
|
|
||||||
#ifdef FB_SONARKIT_ENABLED
|
#ifdef FB_SONARKIT_ENABLED
|
||||||
|
|
||||||
#include "FlipperStateUpdateListener.h"
|
|
||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
|
#include "FlipperStateUpdateListener.h"
|
||||||
|
|
||||||
@interface StateTableDataSource : NSObject<UITableViewDataSource>
|
@interface StateTableDataSource : NSObject<UITableViewDataSource>
|
||||||
@property(strong, nonatomic) NSArray<NSDictionary*>* elements;
|
@property(strong, nonatomic) NSArray<NSDictionary*>* elements;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface FlipperDiagnosticsViewController : UIViewController<FlipperStateUpdateListener>
|
@interface FlipperDiagnosticsViewController
|
||||||
|
: UIViewController<FlipperStateUpdateListener>
|
||||||
@property(strong, nonatomic) StateTableDataSource* tableDataSource;
|
@property(strong, nonatomic) StateTableDataSource* tableDataSource;
|
||||||
@property(strong, nonatomic) UILabel* stateLabel;
|
@property(strong, nonatomic) UILabel* stateLabel;
|
||||||
@property(strong, nonatomic) UITableView* stateTable;
|
@property(strong, nonatomic) UITableView* stateTable;
|
||||||
|
|||||||
@@ -12,7 +12,8 @@
|
|||||||
|
|
||||||
#define STATE_VIEW_HEIGHT 300
|
#define STATE_VIEW_HEIGHT 300
|
||||||
|
|
||||||
static NSString *const kSKCellIdentifier = @"FlipperDiagnosticStateTableStableCellIdentifier";
|
static NSString* const kSKCellIdentifier =
|
||||||
|
@"FlipperDiagnosticStateTableStableCellIdentifier";
|
||||||
|
|
||||||
@implementation StateTableDataSource
|
@implementation StateTableDataSource
|
||||||
- (instancetype)initWithElements:(NSArray<NSDictionary*>*)elements {
|
- (instancetype)initWithElements:(NSArray<NSDictionary*>*)elements {
|
||||||
@@ -23,16 +24,21 @@ static NSString *const kSKCellIdentifier = @"FlipperDiagnosticStateTableStableCe
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
|
- (nonnull UITableViewCell*)tableView:(nonnull UITableView*)tableView
|
||||||
|
cellForRowAtIndexPath:(nonnull NSIndexPath*)indexPath {
|
||||||
NSInteger row = indexPath.row;
|
NSInteger row = indexPath.row;
|
||||||
|
|
||||||
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kSKCellIdentifier forIndexPath:indexPath];
|
UITableViewCell* cell =
|
||||||
|
[tableView dequeueReusableCellWithIdentifier:kSKCellIdentifier
|
||||||
|
forIndexPath:indexPath];
|
||||||
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10];
|
cell.textLabel.font = [UIFont fontWithName:@"Arial" size:10];
|
||||||
cell.textLabel.text = [self.elements[row][@"state"] stringByAppendingString:self.elements[row][@"name"]];
|
cell.textLabel.text = [self.elements[row][@"state"]
|
||||||
|
stringByAppendingString:self.elements[row][@"name"]];
|
||||||
return cell;
|
return cell;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
- (NSInteger)tableView:(nonnull UITableView*)tableView
|
||||||
|
numberOfRowsInSection:(NSInteger)section {
|
||||||
return [self.elements count];
|
return [self.elements count];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,16 +49,30 @@ static NSString *const kSKCellIdentifier = @"FlipperDiagnosticStateTableStableCe
|
|||||||
- (void)viewDidLoad {
|
- (void)viewDidLoad {
|
||||||
[super viewDidLoad];
|
[super viewDidLoad];
|
||||||
|
|
||||||
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, STATE_VIEW_HEIGHT, self.view.frame.size.width, self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)];
|
self.scrollView = [[UIScrollView alloc]
|
||||||
self.logLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.scrollView.frame.size.height)];
|
initWithFrame:CGRectMake(
|
||||||
|
0,
|
||||||
|
STATE_VIEW_HEIGHT,
|
||||||
|
self.view.frame.size.width,
|
||||||
|
self.view.frame.size.height - 100 - STATE_VIEW_HEIGHT)];
|
||||||
|
self.logLabel =
|
||||||
|
[[UILabel alloc] initWithFrame:CGRectMake(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
self.view.frame.size.width,
|
||||||
|
self.scrollView.frame.size.height)];
|
||||||
self.logLabel.numberOfLines = 0;
|
self.logLabel.numberOfLines = 0;
|
||||||
self.logLabel.font = [UIFont fontWithName:@"Arial" size:10];
|
self.logLabel.font = [UIFont fontWithName:@"Arial" size:10];
|
||||||
[self.scrollView addSubview:self.logLabel];
|
[self.scrollView addSubview:self.logLabel];
|
||||||
|
|
||||||
self.stateTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)];
|
self.stateTable = [[UITableView alloc]
|
||||||
[self.stateTable registerClass:[UITableViewCell class] forCellReuseIdentifier:kSKCellIdentifier];
|
initWithFrame:CGRectMake(
|
||||||
|
0, 0, self.view.bounds.size.width, STATE_VIEW_HEIGHT)];
|
||||||
|
[self.stateTable registerClass:[UITableViewCell class]
|
||||||
|
forCellReuseIdentifier:kSKCellIdentifier];
|
||||||
self.stateTable.rowHeight = 14;
|
self.stateTable.rowHeight = 14;
|
||||||
self.tableDataSource = [[StateTableDataSource alloc] initWithElements:[[FlipperClient sharedClient] getStateElements]];
|
self.tableDataSource = [[StateTableDataSource alloc]
|
||||||
|
initWithElements:[[FlipperClient sharedClient] getStateElements]];
|
||||||
self.stateTable.dataSource = self.tableDataSource;
|
self.stateTable.dataSource = self.tableDataSource;
|
||||||
|
|
||||||
[self updateLogView];
|
[self updateLogView];
|
||||||
@@ -71,7 +91,8 @@ static NSString *const kSKCellIdentifier = @"FlipperDiagnosticStateTableStableCe
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateStateTable {
|
- (void)updateStateTable {
|
||||||
self.tableDataSource.elements = [[FlipperClient sharedClient] getStateElements];
|
self.tableDataSource.elements =
|
||||||
|
[[FlipperClient sharedClient] getStateElements];
|
||||||
[self.stateTable reloadData];
|
[self.stateTable reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +103,9 @@ static NSString *const kSKCellIdentifier = @"FlipperDiagnosticStateTableStableCe
|
|||||||
self.scrollView.contentSize = self.logLabel.frame.size;
|
self.scrollView.contentSize = self.logLabel.frame.size;
|
||||||
|
|
||||||
// Scroll to bottom
|
// Scroll to bottom
|
||||||
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
|
CGPoint bottomOffset = CGPointMake(
|
||||||
|
0,
|
||||||
|
self.scrollView.contentSize.height - self.scrollView.bounds.size.height);
|
||||||
[self.scrollView setContentOffset:bottomOffset animated:YES];
|
[self.scrollView setContentOffset:bottomOffset animated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
#import "SKMacros.h"
|
|
||||||
#import "FlipperResponder.h"
|
#import "FlipperResponder.h"
|
||||||
|
#import "SKMacros.h"
|
||||||
|
|
||||||
SK_EXTERN_C_BEGIN
|
SK_EXTERN_C_BEGIN
|
||||||
void FlipperPerformBlockOnMainThread(void(^block)(), id<FlipperResponder> responder);
|
void FlipperPerformBlockOnMainThread(
|
||||||
|
void (^block)(),
|
||||||
|
id<FlipperResponder> responder);
|
||||||
SK_EXTERN_C_END
|
SK_EXTERN_C_END
|
||||||
|
|
||||||
@protocol FlipperConnection;
|
@protocol FlipperConnection;
|
||||||
@@ -19,26 +20,28 @@ SK_EXTERN_C_END
|
|||||||
@protocol FlipperPlugin
|
@protocol FlipperPlugin
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The plugin's identifier. This should map to a javascript plugin with the same identifier to ensure
|
The plugin's identifier. This should map to a javascript plugin with the same
|
||||||
messages are sent correctly.
|
identifier to ensure messages are sent correctly.
|
||||||
*/
|
*/
|
||||||
- (NSString*)identifier;
|
- (NSString*)identifier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called when a connection has been established between this plugin and the corresponding plugin on
|
Called when a connection has been established between this plugin and the
|
||||||
the Sonar desktop app. The provided connection can be used to register method receivers as well
|
corresponding plugin on the Sonar desktop app. The provided connection can be
|
||||||
as send messages back to the desktop app.
|
used to register method receivers as well as send messages back to the desktop
|
||||||
|
app.
|
||||||
*/
|
*/
|
||||||
- (void)didConnect:(id<FlipperConnection>)connection;
|
- (void)didConnect:(id<FlipperConnection>)connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called when a plugin has been disconnected and the SonarConnection provided in didConnect is no
|
Called when a plugin has been disconnected and the SonarConnection provided in
|
||||||
longer valid to use.
|
didConnect is no longer valid to use.
|
||||||
*/
|
*/
|
||||||
- (void)didDisconnect;
|
- (void)didDisconnect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns true if the plugin is meant to be run in background too, otherwise it returns false.
|
Returns true if the plugin is meant to be run in background too, otherwise it
|
||||||
|
returns false.
|
||||||
*/
|
*/
|
||||||
@optional
|
@optional
|
||||||
- (BOOL)runInBackground;
|
- (BOOL)runInBackground;
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Acts as a hook for providing return values to remote called from Sonar desktop plugins.
|
Acts as a hook for providing return values to remote called from Sonar desktop
|
||||||
|
plugins.
|
||||||
*/
|
*/
|
||||||
@protocol FlipperResponder
|
@protocol FlipperResponder
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,20 @@
|
|||||||
#import "FlipperPlugin.h"
|
#import "FlipperPlugin.h"
|
||||||
#import "FlipperResponder.h"
|
#import "FlipperResponder.h"
|
||||||
|
|
||||||
void FlipperPerformBlockOnMainThread(void(^block)(), id<FlipperResponder> responder)
|
void FlipperPerformBlockOnMainThread(
|
||||||
{
|
void (^block)(),
|
||||||
|
id<FlipperResponder> responder) {
|
||||||
if ([NSThread isMainThread]) {
|
if ([NSThread isMainThread]) {
|
||||||
@try {
|
@try {
|
||||||
block();
|
block();
|
||||||
} @catch (NSException* e) {
|
} @catch (NSException* e) {
|
||||||
[responder error:@{@"name" : e.name, @"message" : e.reason}];
|
[responder error:@{@"name" : e.name, @"message" : e.reason}];
|
||||||
} @catch (...) {
|
} @catch (...) {
|
||||||
[responder error:@{@"name": @"Unknown", @"message": @"Unknown error caught when processing operation on main thread"}];
|
[responder error:@{
|
||||||
|
@"name" : @"Unknown",
|
||||||
|
@"message" :
|
||||||
|
@"Unknown error caught when processing operation on main thread"
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
@@ -26,7 +31,11 @@ void FlipperPerformBlockOnMainThread(void(^block)(), id<FlipperResponder> respon
|
|||||||
} @catch (NSException* e) {
|
} @catch (NSException* e) {
|
||||||
[responder error:@{@"name" : e.name, @"message" : e.reason}];
|
[responder error:@{@"name" : e.name, @"message" : e.reason}];
|
||||||
} @catch (...) {
|
} @catch (...) {
|
||||||
[responder error:@{@"name": @"Unknown", @"message": @"Unknown error caught when processing operation on main thread"}];
|
[responder error:@{
|
||||||
|
@"name" : @"Unknown",
|
||||||
|
@"message" :
|
||||||
|
@"Unknown error caught when processing operation on main thread"
|
||||||
|
}];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
#ifdef FB_SONARKIT_ENABLED
|
#ifdef FB_SONARKIT_ENABLED
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This class exists to retreive configuration values stored in environment variables.
|
* This class exists to retreive configuration values stored in environment
|
||||||
|
* variables.
|
||||||
*/
|
*/
|
||||||
@interface SKEnvironmentVariables : NSObject
|
@interface SKEnvironmentVariables : NSObject
|
||||||
+ (int)getInsecurePort;
|
+ (int)getInsecurePort;
|
||||||
|
|||||||
@@ -16,13 +16,19 @@ static int const DEFAULT_SECURE_PORT = 8088;
|
|||||||
|
|
||||||
+ (int)getInsecurePort {
|
+ (int)getInsecurePort {
|
||||||
NSString* envVar = [self getFlipperPortsVariable];
|
NSString* envVar = [self getFlipperPortsVariable];
|
||||||
return [self extractIntFromPropValue:envVar atIndex:0 withDefault:DEFAULT_INSECURE_PORT];
|
return [self extractIntFromPropValue:envVar
|
||||||
|
atIndex:0
|
||||||
|
withDefault:DEFAULT_INSECURE_PORT];
|
||||||
}
|
}
|
||||||
+ (int)getSecurePort {
|
+ (int)getSecurePort {
|
||||||
NSString* envVar = [self getFlipperPortsVariable];
|
NSString* envVar = [self getFlipperPortsVariable];
|
||||||
return [self extractIntFromPropValue:envVar atIndex:1 withDefault:DEFAULT_SECURE_PORT];
|
return [self extractIntFromPropValue:envVar
|
||||||
|
atIndex:1
|
||||||
|
withDefault:DEFAULT_SECURE_PORT];
|
||||||
}
|
}
|
||||||
+ (int)extractIntFromPropValue:(NSString *)propValue atIndex:(int)index withDefault:(int)fallback {
|
+ (int)extractIntFromPropValue:(NSString*)propValue
|
||||||
|
atIndex:(int)index
|
||||||
|
withDefault:(int)fallback {
|
||||||
NSArray<NSString*>* components = [propValue componentsSeparatedByString:@","];
|
NSArray<NSString*>* components = [propValue componentsSeparatedByString:@","];
|
||||||
NSString* component = [components objectAtIndex:index];
|
NSString* component = [components objectAtIndex:index];
|
||||||
int envInt = [component intValue];
|
int envInt = [component intValue];
|
||||||
|
|||||||
@@ -13,12 +13,14 @@
|
|||||||
/*
|
/*
|
||||||
* This class exists to bridge the gap between Objective C and C++.
|
* This class exists to bridge the gap between Objective C and C++.
|
||||||
* A SKStateUpdateCPPWrapper instance allows for wrapping an Objective-C object
|
* A SKStateUpdateCPPWrapper instance allows for wrapping an Objective-C object
|
||||||
* and passing it to the pure C++ SonarClient, so it can be triggered when updates occur.
|
* and passing it to the pure C++ SonarClient, so it can be triggered when
|
||||||
|
* updates occur.
|
||||||
*/
|
*/
|
||||||
class SKStateUpdateCPPWrapper : public FlipperStateUpdateListener {
|
class SKStateUpdateCPPWrapper : public FlipperStateUpdateListener {
|
||||||
public:
|
public:
|
||||||
SKStateUpdateCPPWrapper(id<FlipperStateUpdateListener> delegate_);
|
SKStateUpdateCPPWrapper(id<FlipperStateUpdateListener> delegate_);
|
||||||
void onUpdate();
|
void onUpdate();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
__weak id<FlipperStateUpdateListener> delegate_;
|
__weak id<FlipperStateUpdateListener> delegate_;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
#include "SKStateUpdateCPPWrapper.h"
|
#include "SKStateUpdateCPPWrapper.h"
|
||||||
|
|
||||||
SKStateUpdateCPPWrapper::SKStateUpdateCPPWrapper(id<FlipperStateUpdateListener> controller) {
|
SKStateUpdateCPPWrapper::SKStateUpdateCPPWrapper(
|
||||||
|
id<FlipperStateUpdateListener> controller) {
|
||||||
delegate_ = controller;
|
delegate_ = controller;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user