2014 snapchat source code
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.

67 lines
1.8 KiB

  1. //
  2. // SCCaptureConfigurationAnnouncer.m
  3. // Snapchat
  4. //
  5. // Created by Lin Jia on 10/2/17.
  6. //
  7. //
  8. #import "SCCaptureConfigurationAnnouncer.h"
  9. #import "SCCaptureConfigurationAnnouncer_Private.h"
  10. #import "SCCaptureConfigurator.h"
  11. #import <SCFoundation/SCAssertWrapper.h>
  12. #import <SCFoundation/SCPerforming.h>
  13. @interface SCCaptureConfigurationAnnouncer () {
  14. NSHashTable<id<SCCaptureConfigurationListener>> *_listeners;
  15. SCQueuePerformer *_performer;
  16. __weak SCCaptureConfigurator *_configurator;
  17. }
  18. @end
  19. @implementation SCCaptureConfigurationAnnouncer
  20. - (instancetype)initWithPerformer:(SCQueuePerformer *)performer configurator:(SCCaptureConfigurator *)configurator
  21. {
  22. self = [super init];
  23. if (self) {
  24. _listeners = [NSHashTable<id<SCCaptureConfigurationListener>> hashTableWithOptions:NSHashTableWeakMemory];
  25. SCAssert(performer, @"performer should not be nil");
  26. _performer = performer;
  27. _configurator = configurator;
  28. }
  29. return self;
  30. }
  31. - (void)addListener:(id<SCCaptureConfigurationListener>)listener
  32. {
  33. [_performer perform:^{
  34. SCAssert(listener, @"listener should not be nil");
  35. [_listeners addObject:listener];
  36. [listener captureConfigurationDidChangeTo:_configurator.currentConfiguration];
  37. }];
  38. }
  39. - (void)removeListener:(id<SCCaptureConfigurationListener>)listener
  40. {
  41. [_performer perform:^{
  42. SCAssert(listener, @"listener should not be nil");
  43. [_listeners removeObject:listener];
  44. }];
  45. }
  46. - (void)deliverConfigurationChange:(id<SCManagedCapturerState>)configuration
  47. {
  48. SCAssertPerformer(_performer);
  49. for (id<SCCaptureConfigurationListener> listener in _listeners) {
  50. [listener captureConfigurationDidChangeTo:configuration];
  51. }
  52. }
  53. - (void)dealloc
  54. {
  55. [_listeners removeAllObjects];
  56. }
  57. @end