summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2020-07-14 12:04:25 -0400
committerNicoleYarroch <nicole@livio.io>2020-07-14 12:04:25 -0400
commit633251ac1786426bfe4ea30d7bd28e7e1009054e (patch)
tree98ab21e2a9946c95b8800bbed00bb75685efce00
parent90f3e1db4a5062669c9d811df9d6e406051caf2d (diff)
downloadsdl_ios-bugfix/issue_1709_make_system_cap_manager_thread_safe.tar.gz
Only dispatch once when removing observersbugfix/issue_1709_make_system_cap_manager_thread_safe
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink/SDLSystemCapabilityManager.m19
1 files changed, 9 insertions, 10 deletions
diff --git a/SmartDeviceLink/SDLSystemCapabilityManager.m b/SmartDeviceLink/SDLSystemCapabilityManager.m
index 3f7c4f8a8..e5817b9d7 100644
--- a/SmartDeviceLink/SDLSystemCapabilityManager.m
+++ b/SmartDeviceLink/SDLSystemCapabilityManager.m
@@ -558,6 +558,7 @@ typedef NSString * SDLServiceID;
/// Helper method for subscribing to a system capability type
/// @param type The SystemCapabilityType that will be subscribed
/// @param observerObject An object that can be used to unsubscribe the block. If nil, the subscription was not succesful.
+/// @return The observer if the subscription was succesful; nil if not.
- (nullable id<NSObject>)sdl_subscribeToCapabilityType:(SDLSystemCapabilityType)type observerObject:(SDLSystemCapabilityObserver *)observerObject {
if ([self.currentHMILevel isEqualToEnum:SDLHMILevelNone] && ![type isEqualToEnum:SDLSystemCapabilityTypeDisplays]) {
SDLLogE(@"Attempted to subscribe to type: %@ in HMI level NONE, which is not allowed. Please wait until you are in HMI BACKGROUND, LIMITED, or FULL before attempting to subscribe to any SystemCapabilityType other than DISPLAYS.", type);
@@ -612,19 +613,17 @@ typedef NSString * SDLServiceID;
// Loop through our observers
for (SDLSystemCapabilityType key in self.capabilityObservers.allKeys) {
for (SDLSystemCapabilityObserver *observer in self.capabilityObservers[key]) {
- // If an observer object is nil, remove it
- if (observer.observer == nil) {
- [self sdl_runSyncOnQueue:^{
+ [self sdl_runSyncOnQueue:^{
+ // If an observer object is nil, remove it
+ if (observer.observer == nil) {
[self.capabilityObservers[key] removeObject:observer];
- }];
- }
+ }
- // If we no longer have any observers for that type, remove the array
- if (self.capabilityObservers[key].count == 0) {
- [self sdl_runSyncOnQueue:^{
+ // If we no longer have any observers for that type, remove the array
+ if (self.capabilityObservers[key].count == 0) {
[self.capabilityObservers removeObjectForKey:key];
- }];
- }
+ }
+ }];
}
}