UIDConnectionListener
Summary: Add a connection listener similarly to the one used on Android. The usage at this point will come from framework events as a means to control when to capture the events or not. Reviewed By: ivanmisuno Differential Revision: D49092691 fbshipit-source-id: d004f7ff5d1a254ad5f9c7f207d485afcb7ac54a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
0900a2a41d
commit
2ad789d14e
@@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if FB_SONARKIT_ENABLED
|
||||||
|
|
||||||
|
@protocol UIDConnectionListener
|
||||||
|
|
||||||
|
- (void)onDidConnect;
|
||||||
|
- (void)onDidDisconnect;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#import <FlipperKit/FlipperConnection.h>
|
#import <FlipperKit/FlipperConnection.h>
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "UIDConnectionListener.h"
|
||||||
#import "UIDFrameworkEventManager.h"
|
#import "UIDFrameworkEventManager.h"
|
||||||
#import "UIDUpdateDigester.h"
|
#import "UIDUpdateDigester.h"
|
||||||
|
|
||||||
@@ -33,6 +34,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|||||||
descriptorRegister:(UIDDescriptorRegister*)descriptorRegister
|
descriptorRegister:(UIDDescriptorRegister*)descriptorRegister
|
||||||
observerFactory:(UIDTreeObserverFactory*)observerFactory;
|
observerFactory:(UIDTreeObserverFactory*)observerFactory;
|
||||||
|
|
||||||
|
- (NSSet<id<UIDConnectionListener>>*)connectionListeners;
|
||||||
|
- (void)addConnectionListener:(id<UIDConnectionListener>)listener;
|
||||||
|
- (void)removeConnectionListener:(id<UIDConnectionListener>)listener;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
NS_ASSUME_NONNULL_END
|
NS_ASSUME_NONNULL_END
|
||||||
|
|||||||
@@ -12,6 +12,13 @@
|
|||||||
#import "UIDSerialFrameworkEventManager.h"
|
#import "UIDSerialFrameworkEventManager.h"
|
||||||
#import "UIDTreeObserverFactory.h"
|
#import "UIDTreeObserverFactory.h"
|
||||||
|
|
||||||
|
@interface UIDContext () {
|
||||||
|
NSMutableSet<id<UIDConnectionListener>>* _connectionListeners;
|
||||||
|
dispatch_queue_t _accessQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation UIDContext
|
@implementation UIDContext
|
||||||
|
|
||||||
- (instancetype)initWithApplication:(UIApplication*)application
|
- (instancetype)initWithApplication:(UIApplication*)application
|
||||||
@@ -24,10 +31,34 @@
|
|||||||
_observerFactory = observerFactory;
|
_observerFactory = observerFactory;
|
||||||
_connection = nil;
|
_connection = nil;
|
||||||
_frameworkEventManager = [UIDSerialFrameworkEventManager new];
|
_frameworkEventManager = [UIDSerialFrameworkEventManager new];
|
||||||
|
_connectionListeners = [NSMutableSet new];
|
||||||
|
_accessQueue =
|
||||||
|
dispatch_queue_create("ui-debugger.context", DISPATCH_QUEUE_SERIAL);
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSSet<id<UIDConnectionListener>>*)connectionListeners {
|
||||||
|
__block NSSet* listeners = nil;
|
||||||
|
dispatch_sync(_accessQueue, ^{
|
||||||
|
listeners = [_connectionListeners copy];
|
||||||
|
});
|
||||||
|
|
||||||
|
return listeners;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)addConnectionListener:(id<UIDConnectionListener>)listener {
|
||||||
|
dispatch_sync(_accessQueue, ^{
|
||||||
|
[_connectionListeners addObject:listener];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeConnectionListener:(id<UIDConnectionListener>)listener {
|
||||||
|
dispatch_sync(_accessQueue, ^{
|
||||||
|
[_connectionListeners removeObject:listener];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -51,11 +51,23 @@
|
|||||||
_context.connection = connection;
|
_context.connection = connection;
|
||||||
|
|
||||||
[[UIDTreeObserverManager shared] startWithContext:_context];
|
[[UIDTreeObserverManager shared] startWithContext:_context];
|
||||||
|
|
||||||
|
NSSet<id<UIDConnectionListener>>* connectionListeners =
|
||||||
|
_context.connectionListeners;
|
||||||
|
for (id<UIDConnectionListener> listener in connectionListeners) {
|
||||||
|
[listener onDidConnect];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didDisconnect {
|
- (void)didDisconnect {
|
||||||
_context.connection = nil;
|
_context.connection = nil;
|
||||||
[[UIDTreeObserverManager shared] stop];
|
[[UIDTreeObserverManager shared] stop];
|
||||||
|
|
||||||
|
NSSet<id<UIDConnectionListener>>* connectionListeners =
|
||||||
|
_context.connectionListeners;
|
||||||
|
for (id<UIDConnectionListener> listener in connectionListeners) {
|
||||||
|
[listener onDidDisconnect];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user