This app provides monitoring and information features for the common freifunk user and the technical stuff of a freifunk community.
Code base is taken from a TUM Practical Course project and added here to see if Freifunk Altdorf can use it.
https://www.freifunk-altdorf.de
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.9 KiB
147 lines
3.9 KiB
/** |
|
* Copyright (c) 2015-present, Facebook, Inc. |
|
* |
|
* This source code is licensed under the MIT license found in the |
|
* LICENSE file in the root directory of this source tree. |
|
*/ |
|
|
|
#import "RCTDisplayLink.h" |
|
|
|
#import <Foundation/Foundation.h> |
|
#import <QuartzCore/CADisplayLink.h> |
|
|
|
#import "RCTAssert.h" |
|
#import "RCTBridgeModule.h" |
|
#import "RCTFrameUpdate.h" |
|
#import "RCTModuleData.h" |
|
#import "RCTProfile.h" |
|
|
|
#define RCTAssertRunLoop() \ |
|
RCTAssert(_runLoop == [NSRunLoop currentRunLoop], \ |
|
@"This method must be called on the CADisplayLink run loop") |
|
|
|
@implementation RCTDisplayLink |
|
{ |
|
CADisplayLink *_jsDisplayLink; |
|
NSMutableSet<RCTModuleData *> *_frameUpdateObservers; |
|
NSRunLoop *_runLoop; |
|
} |
|
|
|
- (instancetype)init |
|
{ |
|
if ((self = [super init])) { |
|
_frameUpdateObservers = [NSMutableSet new]; |
|
_jsDisplayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_jsThreadUpdate:)]; |
|
} |
|
|
|
return self; |
|
} |
|
|
|
- (void)registerModuleForFrameUpdates:(id<RCTBridgeModule>)module |
|
withModuleData:(RCTModuleData *)moduleData |
|
{ |
|
if (![moduleData.moduleClass conformsToProtocol:@protocol(RCTFrameUpdateObserver)] || |
|
[_frameUpdateObservers containsObject:moduleData]) { |
|
return; |
|
} |
|
|
|
[_frameUpdateObservers addObject:moduleData]; |
|
|
|
// Don't access the module instance via moduleData, as this will cause deadlock |
|
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)module; |
|
__weak typeof(self) weakSelf = self; |
|
observer.pauseCallback = ^{ |
|
typeof(self) strongSelf = weakSelf; |
|
if (!strongSelf) { |
|
return; |
|
} |
|
|
|
CFRunLoopRef cfRunLoop = [strongSelf->_runLoop getCFRunLoop]; |
|
if (!cfRunLoop) { |
|
return; |
|
} |
|
|
|
if ([NSRunLoop currentRunLoop] == strongSelf->_runLoop) { |
|
[weakSelf updateJSDisplayLinkState]; |
|
} else { |
|
CFRunLoopPerformBlock(cfRunLoop, kCFRunLoopDefaultMode, ^{ |
|
[weakSelf updateJSDisplayLinkState]; |
|
}); |
|
CFRunLoopWakeUp(cfRunLoop); |
|
} |
|
}; |
|
|
|
// Assuming we're paused right now, we only need to update the display link's state |
|
// when the new observer is not paused. If it not paused, the observer will immediately |
|
// start receiving updates anyway. |
|
if (![observer isPaused] && _runLoop) { |
|
CFRunLoopPerformBlock([_runLoop getCFRunLoop], kCFRunLoopDefaultMode, ^{ |
|
[self updateJSDisplayLinkState]; |
|
}); |
|
} |
|
} |
|
|
|
- (void)addToRunLoop:(NSRunLoop *)runLoop |
|
{ |
|
_runLoop = runLoop; |
|
[_jsDisplayLink addToRunLoop:runLoop forMode:NSRunLoopCommonModes]; |
|
} |
|
|
|
- (void)invalidate |
|
{ |
|
[_jsDisplayLink invalidate]; |
|
} |
|
|
|
- (void)dispatchBlock:(dispatch_block_t)block |
|
queue:(dispatch_queue_t)queue |
|
{ |
|
if (queue == RCTJSThread) { |
|
block(); |
|
} else if (queue) { |
|
dispatch_async(queue, block); |
|
} |
|
} |
|
|
|
- (void)_jsThreadUpdate:(CADisplayLink *)displayLink |
|
{ |
|
RCTAssertRunLoop(); |
|
|
|
RCT_PROFILE_BEGIN_EVENT(RCTProfileTagAlways, @"-[RCTDisplayLink _jsThreadUpdate:]", nil); |
|
|
|
RCTFrameUpdate *frameUpdate = [[RCTFrameUpdate alloc] initWithDisplayLink:displayLink]; |
|
for (RCTModuleData *moduleData in _frameUpdateObservers) { |
|
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance; |
|
if (!observer.paused) { |
|
RCTProfileBeginFlowEvent(); |
|
|
|
[self dispatchBlock:^{ |
|
RCTProfileEndFlowEvent(); |
|
[observer didUpdateFrame:frameUpdate]; |
|
} queue:moduleData.methodQueue]; |
|
} |
|
} |
|
|
|
[self updateJSDisplayLinkState]; |
|
|
|
RCTProfileImmediateEvent(RCTProfileTagAlways, @"JS Thread Tick", displayLink.timestamp, 'g'); |
|
|
|
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"objc_call"); |
|
} |
|
|
|
- (void)updateJSDisplayLinkState |
|
{ |
|
RCTAssertRunLoop(); |
|
|
|
BOOL pauseDisplayLink = YES; |
|
for (RCTModuleData *moduleData in _frameUpdateObservers) { |
|
id<RCTFrameUpdateObserver> observer = (id<RCTFrameUpdateObserver>)moduleData.instance; |
|
if (!observer.paused) { |
|
pauseDisplayLink = NO; |
|
break; |
|
} |
|
} |
|
|
|
_jsDisplayLink.paused = pauseDisplayLink; |
|
} |
|
|
|
@end
|
|
|