summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2018-09-12 15:54:42 -0400
committerJoel Fischer <joeljfischer@gmail.com>2018-09-12 15:54:42 -0400
commit59e120e432224cad7f77245e4636e41c66f41acd (patch)
treee6f05bc18d805340d3a290f3d1b28e0eb9a36efc
parent025d4f267462da43d84ed67296039e2926c050a8 (diff)
downloadsdl_ios-59e120e432224cad7f77245e4636e41c66f41acd.tar.gz
Allow the mitigation of PlayPause to work with the ResponseDispatcher
-rw-r--r--SmartDeviceLink-iOS.xcodeproj/project.pbxproj8
-rw-r--r--SmartDeviceLink/NSMutableArray+Safe.h15
-rw-r--r--SmartDeviceLink/NSMutableArray+Safe.m19
-rw-r--r--SmartDeviceLink/NSMutableDictionary+SafeRemove.h14
-rw-r--r--SmartDeviceLink/SDLResponseDispatcher.m38
5 files changed, 81 insertions, 13 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
index d12dce5a7..a6123ae42 100644
--- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
+++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj
@@ -391,6 +391,8 @@
5D00AC781F15283E004000D9 /* SDLNavigationCapability.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D00AC761F15283E004000D9 /* SDLNavigationCapability.m */; };
5D00AC7B1F15287E004000D9 /* SDLPhoneCapability.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D00AC791F15287E004000D9 /* SDLPhoneCapability.h */; settings = {ATTRIBUTES = (Public, ); }; };
5D00AC7C1F15287E004000D9 /* SDLPhoneCapability.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D00AC7A1F15287E004000D9 /* SDLPhoneCapability.m */; };
+ 5D019276214994AC003500F6 /* NSMutableArray+Safe.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D019274214994AC003500F6 /* NSMutableArray+Safe.h */; };
+ 5D019277214994AC003500F6 /* NSMutableArray+Safe.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D019275214994AC003500F6 /* NSMutableArray+Safe.m */; };
5D07C02D2044AC9100D1ECDC /* SDLSequentialRPCRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D07C02B2044AC9000D1ECDC /* SDLSequentialRPCRequestOperation.h */; };
5D07C02E2044AC9100D1ECDC /* SDLSequentialRPCRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D07C02C2044AC9100D1ECDC /* SDLSequentialRPCRequestOperation.m */; };
5D07C0312044AD0C00D1ECDC /* SDLAsynchronousRPCRequestOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D07C02F2044AD0C00D1ECDC /* SDLAsynchronousRPCRequestOperation.h */; };
@@ -1837,6 +1839,8 @@
5D00AC761F15283E004000D9 /* SDLNavigationCapability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLNavigationCapability.m; sourceTree = "<group>"; };
5D00AC791F15287E004000D9 /* SDLPhoneCapability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLPhoneCapability.h; sourceTree = "<group>"; };
5D00AC7A1F15287E004000D9 /* SDLPhoneCapability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLPhoneCapability.m; sourceTree = "<group>"; };
+ 5D019274214994AC003500F6 /* NSMutableArray+Safe.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSMutableArray+Safe.h"; sourceTree = "<group>"; };
+ 5D019275214994AC003500F6 /* NSMutableArray+Safe.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSMutableArray+Safe.m"; sourceTree = "<group>"; };
5D07C02B2044AC9000D1ECDC /* SDLSequentialRPCRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLSequentialRPCRequestOperation.h; sourceTree = "<group>"; };
5D07C02C2044AC9100D1ECDC /* SDLSequentialRPCRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLSequentialRPCRequestOperation.m; sourceTree = "<group>"; };
5D07C02F2044AD0C00D1ECDC /* SDLAsynchronousRPCRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLAsynchronousRPCRequestOperation.h; sourceTree = "<group>"; };
@@ -4880,6 +4884,8 @@
5DA102A31D4122C700C15826 /* NSMutableDictionary+SafeRemove.m */,
5D3E48C91D7722FE0000BFEF /* NSBundle+SDLBundle.h */,
5D3E48CA1D7722FE0000BFEF /* NSBundle+SDLBundle.m */,
+ 5D019274214994AC003500F6 /* NSMutableArray+Safe.h */,
+ 5D019275214994AC003500F6 /* NSMutableArray+Safe.m */,
);
name = Categories;
sourceTree = "<group>";
@@ -5794,6 +5800,7 @@
5DCF76F51ACDBAD300BB647B /* SDLSendLocation.h in Headers */,
5D61FC9E1A84238C00846EE7 /* SDLEncodedSyncPData.h in Headers */,
1FF7DABA1F75B2A800B46C30 /* SDLFocusableItemLocator.h in Headers */,
+ 5D019276214994AC003500F6 /* NSMutableArray+Safe.h in Headers */,
5D61FDE11A84238C00846EE7 /* SDLTurn.h in Headers */,
5D9FC29B1FD8812F00ACA5C2 /* SDLAudioStreamManagerDelegate.h in Headers */,
5D61FC801A84238C00846EE7 /* SDLDeleteSubMenuResponse.h in Headers */,
@@ -6371,6 +6378,7 @@
5D3E420B20EAAD6500D8C622 /* SDLTPMS.m in Sources */,
5DD67CB11E65DDB7009CD394 /* SDLLogTargetAppleSystemLog.m in Sources */,
5D92935420B2F76500FCC775 /* SDLTemplateColorScheme.m in Sources */,
+ 5D019277214994AC003500F6 /* NSMutableArray+Safe.m in Sources */,
5D61FD1C1A84238C00846EE7 /* SDLOnSystemRequest.m in Sources */,
5D61FC911A84238C00846EE7 /* SDLDisplayCapabilities.m in Sources */,
1EB59CC4202DB40400343A61 /* SDLSeatControlCapabilities.m in Sources */,
diff --git a/SmartDeviceLink/NSMutableArray+Safe.h b/SmartDeviceLink/NSMutableArray+Safe.h
new file mode 100644
index 000000000..795b186df
--- /dev/null
+++ b/SmartDeviceLink/NSMutableArray+Safe.h
@@ -0,0 +1,15 @@
+//
+// NSMutableArray+NSMutableArray_Safe.h
+// SmartDeviceLink
+//
+// Created by Joel Fischer on 9/12/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSMutableArray<ObjectType> (Safe)
+
+- (void)sdl_safeAddObject:(ObjectType)object;
+
+@end
diff --git a/SmartDeviceLink/NSMutableArray+Safe.m b/SmartDeviceLink/NSMutableArray+Safe.m
new file mode 100644
index 000000000..63d9827ca
--- /dev/null
+++ b/SmartDeviceLink/NSMutableArray+Safe.m
@@ -0,0 +1,19 @@
+//
+// NSMutableArray+NSMutableArray_Safe.m
+// SmartDeviceLink
+//
+// Created by Joel Fischer on 9/12/18.
+// Copyright © 2018 smartdevicelink. All rights reserved.
+//
+
+#import "NSMutableArray+NSMutableArray_Safe.h"
+
+@implementation NSMutableArray (Safe)
+
+- (void)sdl_safeAddObject:(id)object {
+ if (object == nil) { return; }
+
+ [self addObject:object];
+}
+
+@end
diff --git a/SmartDeviceLink/NSMutableDictionary+SafeRemove.h b/SmartDeviceLink/NSMutableDictionary+SafeRemove.h
index c72371395..4c238cde4 100644
--- a/SmartDeviceLink/NSMutableDictionary+SafeRemove.h
+++ b/SmartDeviceLink/NSMutableDictionary+SafeRemove.h
@@ -8,30 +8,28 @@
#import <Foundation/Foundation.h>
-@interface NSMutableDictionary <KeyType, ObjectType>
-(SafeRemove)
+@interface NSMutableDictionary <KeyType, ObjectType> (SafeRemove)
- /**
+/**
* Safely attempt to remove a key/object pair by no-oping if they don't exist in the Mutable Dictionary instead of throwing an exception
*
* @param aKey The key to attempt removal of
*
* @return Whether or not the key/object pair existed to remove.
*/
- - (BOOL)safeRemoveObjectForKey : (KeyType)aKey;
+- (BOOL)safeRemoveObjectForKey : (KeyType)aKey;
@end
-@interface NSMapTable <KeyType, ObjectType>
-(SafeRemove)
+@interface NSMapTable <KeyType, ObjectType> (SafeRemove)
- /**
+/**
* Safely attempt to remove a key/object pair by no-oping if they don't exist in the MapTable instead of throwing an exception
*
* @param aKey The key to attempt removal of
*
* @return Whether or not the key/object pair existed to remove.
*/
- - (BOOL)safeRemoveObjectForKey : (KeyType)aKey;
+- (BOOL)safeRemoveObjectForKey : (KeyType)aKey;
@end
diff --git a/SmartDeviceLink/SDLResponseDispatcher.m b/SmartDeviceLink/SDLResponseDispatcher.m
index e95c3be6c..11cc66972 100644
--- a/SmartDeviceLink/SDLResponseDispatcher.m
+++ b/SmartDeviceLink/SDLResponseDispatcher.m
@@ -8,6 +8,7 @@
#import "SDLResponseDispatcher.h"
+#import "NSMutableArray+Safe.h"
#import "NSMutableDictionary+SafeRemove.h"
#import "SDLAddCommand.h"
#import "SDLAlert.h"
@@ -15,6 +16,7 @@
#import "SDLDeleteCommand.h"
#import "SDLDeleteCommandResponse.h"
#import "SDLError.h"
+#import "SDLGlobals.h"
#import "SDLLogMacros.h"
#import "SDLOnAudioPassThru.h"
#import "SDLOnButtonEvent.h"
@@ -215,8 +217,6 @@ NS_ASSUME_NONNULL_BEGIN
- (void)sdl_runHandlerForButton:(SDLRPCNotificationNotification *)notification {
__kindof SDLRPCNotification *rpcNotification = notification.notification;
-
- SDLRPCButtonNotificationHandler handler = nil;
SDLButtonName name = nil;
NSNumber *customID = nil;
@@ -228,13 +228,16 @@ NS_ASSUME_NONNULL_BEGIN
customID = ((SDLOnButtonPress *)rpcNotification).customButtonID;
}
+ NSArray<SDLRPCButtonNotificationHandler> *handlers = nil;
if ([name isEqualToEnum:SDLButtonNameCustomButton]) {
- handler = self.customButtonHandlerMap[customID];
+ // Custom buttons
+ handlers = @[self.customButtonHandlerMap[customID]];
} else {
- handler = self.buttonHandlerMap[name];
+ // Static buttons
+ handlers = [self sdl_handlersForButtonName:name];
}
- if (handler) {
+ for (SDLRPCButtonNotificationHandler handler in handlers) {
if ([rpcNotification isMemberOfClass:[SDLOnButtonEvent class]]) {
handler(nil, rpcNotification);
} else if ([rpcNotification isMemberOfClass:[SDLOnButtonPress class]]) {
@@ -242,6 +245,31 @@ NS_ASSUME_NONNULL_BEGIN
}
}
}
+
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+- (NSArray<SDLRPCButtonNotificationHandler> *)sdl_handlersForButtonName:(SDLButtonName)name {
+ NSMutableArray<SDLRPCButtonNotificationHandler> *handlers = [NSMutableArray array];
+
+ if ([SDLGlobals sharedGlobals].rpcVersion.majorVersion.intValue >= 5) {
+ if ([name isEqualToEnum:SDLButtonNameOk]) {
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNameOkay]];
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNameOk]];
+ } else if ([name isEqualToEnum:SDLButtonNamePlayPause]) {
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNamePlayPause]];
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNameOk]];
+ }
+ } else {
+ if ([name isEqualToEnum:SDLButtonNameOk]) {
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNameOkay]];
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNameOk]];
+ [handlers sdl_safeAddObject:self.buttonHandlerMap[SDLButtonNamePlayPause]];
+ }
+ }
+
+ return [handlers copy];
+}
+#pragma clang diagnostic pop
#pragma mark Audio Pass Thru