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.

146 lines
5.5 KiB

  1. // Generated by the announcer.rb DO NOT EDIT!!
  2. #import "SCManagedDeviceCapacityAnalyzerListenerAnnouncer.h"
  3. #include <mutex>
  4. using std::lock_guard;
  5. using std::mutex;
  6. #include <vector>
  7. using std::find;
  8. using std::make_shared;
  9. using std::shared_ptr;
  10. using std::vector;
  11. @implementation SCManagedDeviceCapacityAnalyzerListenerAnnouncer {
  12. mutex _mutex;
  13. shared_ptr<vector<__weak id<SCManagedDeviceCapacityAnalyzerListener>>> _listeners;
  14. }
  15. - (NSString *)description
  16. {
  17. auto listeners = atomic_load(&self->_listeners);
  18. NSMutableString *desc = [NSMutableString string];
  19. [desc appendFormat:@"<SCManagedDeviceCapacityAnalyzerListenerAnnouncer %p>: [", self];
  20. for (int i = 0; i < listeners->size(); ++i) {
  21. [desc appendFormat:@"%@", (*listeners)[i]];
  22. if (i != listeners->size() - 1) {
  23. [desc appendString:@", "];
  24. }
  25. }
  26. [desc appendString:@"]"];
  27. return desc;
  28. }
  29. - (void)addListener:(id<SCManagedDeviceCapacityAnalyzerListener>)listener
  30. {
  31. lock_guard<mutex> lock(_mutex);
  32. auto listeners = make_shared<vector<__weak id<SCManagedDeviceCapacityAnalyzerListener>>>();
  33. if (_listeners != nil) {
  34. // The listener we want to add already exists
  35. if (find(_listeners->begin(), _listeners->end(), listener) != _listeners->end()) {
  36. return;
  37. }
  38. for (auto &one : *_listeners) {
  39. if (one != nil) {
  40. listeners->push_back(one);
  41. }
  42. }
  43. listeners->push_back(listener);
  44. atomic_store(&self->_listeners, listeners);
  45. } else {
  46. listeners->push_back(listener);
  47. atomic_store(&self->_listeners, listeners);
  48. }
  49. }
  50. - (void)removeListener:(id<SCManagedDeviceCapacityAnalyzerListener>)listener
  51. {
  52. lock_guard<mutex> lock(_mutex);
  53. if (_listeners == nil) {
  54. return;
  55. }
  56. // If the only item in the listener list is the one we want to remove, store it back to nil again
  57. if (_listeners->size() == 1 && (*_listeners)[0] == listener) {
  58. atomic_store(&self->_listeners, shared_ptr<vector<__weak id<SCManagedDeviceCapacityAnalyzerListener>>>());
  59. return;
  60. }
  61. auto listeners = make_shared<vector<__weak id<SCManagedDeviceCapacityAnalyzerListener>>>();
  62. for (auto &one : *_listeners) {
  63. if (one != nil && one != listener) {
  64. listeners->push_back(one);
  65. }
  66. }
  67. atomic_store(&self->_listeners, listeners);
  68. }
  69. - (void)managedDeviceCapacityAnalyzer:(SCManagedDeviceCapacityAnalyzer *)managedDeviceCapacityAnalyzer
  70. didChangeLowLightCondition:(BOOL)lowLightCondition
  71. {
  72. auto listeners = atomic_load(&self->_listeners);
  73. if (listeners) {
  74. for (id<SCManagedDeviceCapacityAnalyzerListener> listener : *listeners) {
  75. if ([listener respondsToSelector:@selector(managedDeviceCapacityAnalyzer:didChangeLowLightCondition:)]) {
  76. [listener managedDeviceCapacityAnalyzer:managedDeviceCapacityAnalyzer
  77. didChangeLowLightCondition:lowLightCondition];
  78. }
  79. }
  80. }
  81. }
  82. - (void)managedDeviceCapacityAnalyzer:(SCManagedDeviceCapacityAnalyzer *)managedDeviceCapacityAnalyzer
  83. didChangeAdjustingExposure:(BOOL)adjustingExposure
  84. {
  85. auto listeners = atomic_load(&self->_listeners);
  86. if (listeners) {
  87. for (id<SCManagedDeviceCapacityAnalyzerListener> listener : *listeners) {
  88. if ([listener respondsToSelector:@selector(managedDeviceCapacityAnalyzer:didChangeAdjustingExposure:)]) {
  89. [listener managedDeviceCapacityAnalyzer:managedDeviceCapacityAnalyzer
  90. didChangeAdjustingExposure:adjustingExposure];
  91. }
  92. }
  93. }
  94. }
  95. - (void)managedDeviceCapacityAnalyzer:(SCManagedDeviceCapacityAnalyzer *)managedDeviceCapacityAnalyzer
  96. didChangeAdjustingFocus:(BOOL)adjustingFocus
  97. {
  98. auto listeners = atomic_load(&self->_listeners);
  99. if (listeners) {
  100. for (id<SCManagedDeviceCapacityAnalyzerListener> listener : *listeners) {
  101. if ([listener respondsToSelector:@selector(managedDeviceCapacityAnalyzer:didChangeAdjustingFocus:)]) {
  102. [listener managedDeviceCapacityAnalyzer:managedDeviceCapacityAnalyzer
  103. didChangeAdjustingFocus:adjustingFocus];
  104. }
  105. }
  106. }
  107. }
  108. - (void)managedDeviceCapacityAnalyzer:(SCManagedDeviceCapacityAnalyzer *)managedDeviceCapacityAnalyzer
  109. didChangeBrightness:(float)adjustingBrightness
  110. {
  111. auto listeners = atomic_load(&self->_listeners);
  112. if (listeners) {
  113. for (id<SCManagedDeviceCapacityAnalyzerListener> listener : *listeners) {
  114. if ([listener respondsToSelector:@selector(managedDeviceCapacityAnalyzer:didChangeBrightness:)]) {
  115. [listener managedDeviceCapacityAnalyzer:managedDeviceCapacityAnalyzer
  116. didChangeBrightness:adjustingBrightness];
  117. }
  118. }
  119. }
  120. }
  121. - (void)managedDeviceCapacityAnalyzer:(SCManagedDeviceCapacityAnalyzer *)managedDeviceCapacityAnalyzer
  122. didChangeLightingCondition:(SCCapturerLightingConditionType)lightingCondition
  123. {
  124. auto listeners = atomic_load(&self->_listeners);
  125. if (listeners) {
  126. for (id<SCManagedDeviceCapacityAnalyzerListener> listener : *listeners) {
  127. if ([listener respondsToSelector:@selector(managedDeviceCapacityAnalyzer:didChangeLightingCondition:)]) {
  128. [listener managedDeviceCapacityAnalyzer:managedDeviceCapacityAnalyzer
  129. didChangeLightingCondition:lightingCondition];
  130. }
  131. }
  132. }
  133. }
  134. @end