// // SCCaptureConfigurationAnnouncer.m // Snapchat // // Created by Lin Jia on 10/2/17. // // #import "SCCaptureConfigurationAnnouncer.h" #import "SCCaptureConfigurationAnnouncer_Private.h" #import "SCCaptureConfigurator.h" #import #import @interface SCCaptureConfigurationAnnouncer () { NSHashTable> *_listeners; SCQueuePerformer *_performer; __weak SCCaptureConfigurator *_configurator; } @end @implementation SCCaptureConfigurationAnnouncer - (instancetype)initWithPerformer:(SCQueuePerformer *)performer configurator:(SCCaptureConfigurator *)configurator { self = [super init]; if (self) { _listeners = [NSHashTable> hashTableWithOptions:NSHashTableWeakMemory]; SCAssert(performer, @"performer should not be nil"); _performer = performer; _configurator = configurator; } return self; } - (void)addListener:(id)listener { [_performer perform:^{ SCAssert(listener, @"listener should not be nil"); [_listeners addObject:listener]; [listener captureConfigurationDidChangeTo:_configurator.currentConfiguration]; }]; } - (void)removeListener:(id)listener { [_performer perform:^{ SCAssert(listener, @"listener should not be nil"); [_listeners removeObject:listener]; }]; } - (void)deliverConfigurationChange:(id)configuration { SCAssertPerformer(_performer); for (id listener in _listeners) { [listener captureConfigurationDidChangeTo:configuration]; } } - (void)dealloc { [_listeners removeAllObjects]; } @end