summaryrefslogtreecommitdiff
path: root/SmartDeviceLink
diff options
context:
space:
mode:
authorMuller, Alexander (A.) <amulle19@ford.com>2016-09-22 12:34:26 -0700
committerMuller, Alexander (A.) <amulle19@ford.com>2016-09-22 12:34:26 -0700
commit8676a8a3b66c0ce4a1f48e1fdb1854a155d6f5c2 (patch)
treebf05c08cd20af985c5f996c9d4a2be8f12cd44cf /SmartDeviceLink
parent90c51bf63042326daae4e01dd569a460b8a73f24 (diff)
downloadsdl_ios-8676a8a3b66c0ce4a1f48e1fdb1854a155d6f5c2.tar.gz
Updated SDLFunctionID to be a singleton.
Diffstat (limited to 'SmartDeviceLink')
-rw-r--r--SmartDeviceLink/SDLFunctionID.h6
-rw-r--r--SmartDeviceLink/SDLFunctionID.m147
-rw-r--r--SmartDeviceLink/SDLProtocol.m2
-rw-r--r--SmartDeviceLink/SDLProtocolMessage.m2
-rw-r--r--SmartDeviceLink/SDLProxy.m2
-rw-r--r--SmartDeviceLink/SDLRPCMessage.h2
-rw-r--r--SmartDeviceLink/SDLRPCMessage.m2
-rw-r--r--SmartDeviceLink/SDLV2ProtocolMessage.m2
8 files changed, 86 insertions, 79 deletions
diff --git a/SmartDeviceLink/SDLFunctionID.h b/SmartDeviceLink/SDLFunctionID.h
index 8d594b61e..c9cd4afb7 100644
--- a/SmartDeviceLink/SDLFunctionID.h
+++ b/SmartDeviceLink/SDLFunctionID.h
@@ -8,7 +8,9 @@
@interface SDLFunctionID : NSObject
-- (SDLName)getFunctionName:(int)functionID;
-- (NSNumber *)getFunctionID:(SDLName)functionName;
++ (instancetype)sharedInstance;
+
+- (SDLName)functionNameForId:(int)functionID;
+- (NSNumber *)functionIdForName:(SDLName)functionName;
@end
diff --git a/SmartDeviceLink/SDLFunctionID.m b/SmartDeviceLink/SDLFunctionID.m
index 7bb4f13d7..f03826df4 100644
--- a/SmartDeviceLink/SDLFunctionID.m
+++ b/SmartDeviceLink/SDLFunctionID.m
@@ -6,91 +6,96 @@
@interface SDLFunctionID ()
-@property (nonatomic, strong, nonnull) NSDictionary* functionIDs;
+@property (nonatomic, strong, nonnull) NSDictionary* functionIds;
@end
@implementation SDLFunctionID
++ (instancetype)sharedInstance {
+ static SDLFunctionID* functionId = nil;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ functionId = [[SDLFunctionID alloc] init];
+ });
+ return functionId;
+}
+
- (instancetype)init {
if (self = [super init]) {
- static NSDictionary* functionIDs = nil;
- if (functionIDs == nil) {
- functionIDs = @{
- @0: SDLNameReserved,
- @1: SDLNameRegisterAppInterface,
- @2: SDLNameUnregisterAppInterface,
- @3: SDLNameSetGlobalProperties,
- @4: SDLNameResetGlobalProperties,
- @5: SDLNameAddCommand,
- @6: SDLNameDeleteCommand,
- @7: SDLNameAddSubMenu,
- @8: SDLNameDeleteSubMenu,
- @9: SDLNameCreateInteractionChoiceSet,
- @10: SDLNamePerformInteraction,
- @11: SDLNameDeleteInteractionChoiceSet,
- @12: SDLNameAlert,
- @13: SDLNameShow,
- @14: SDLNameSpeak,
- @15: SDLNameSetMediaClockTimer,
- @16: SDLNamePerformAudioPassThru,
- @17: SDLNameEndAudioPassThru,
- @18: SDLNameSubscribeButton,
- @19: SDLNameUnsubscribeButton,
- @20: SDLNameSubscribeVehicleData,
- @21: SDLNameUnsubscribeVehicleData,
- @22: SDLNameGetVehicleData,
- @23: SDLNameReadDID,
- @24: SDLNameGetDTCs,
- @25: SDLNameScrollableMessage,
- @26: SDLNameSlider,
- @27: SDLNameShowConstantTBT,
- @28: SDLNameAlertManeuver,
- @29: SDLNameUpdateTurnList,
- @30: SDLNameChangeRegistration,
- @31: SDLNameGenericResponse,
- @32: SDLNamePutFile,
- @33: SDLNameDeleteFile,
- @34: SDLNameListFiles,
- @35: SDLNameSetAppIcon,
- @36: SDLNameSetDisplayLayout,
- @37: SDLNameDiagnosticMessage,
- @38: SDLNameSystemRequest,
- @39: SDLNameSendLocation,
- @40: SDLNameDialNumber,
- @32768: SDLNameOnHMIStatus,
- @32769: SDLNameOnAppInterfaceUnregistered,
- @32770: SDLNameOnButtonEvent,
- @32771: SDLNameOnButtonPress,
- @32772: SDLNameOnVehicleData,
- @32773: SDLNameOnCommand,
- @32774: SDLNameOnTBTClientState,
- @32775: SDLNameOnDriverDistraction,
- @32776: SDLNameOnPermissionsChange,
- @32777: SDLNameOnAudioPassThru,
- @32778: SDLNameOnLanguageChange,
- @32779: SDLNameOnKeyboardInput,
- @32780: SDLNameOnTouchEvent,
- @32781: SDLNameOnSystemRequest,
- @32782: SDLNameOnHashChange,
- @65536: SDLNameEncodedSyncPData,
- @65537: SDLNameSyncPData,
- @98304: SDLNameOnEncodedSyncPData,
- @98305: SDLNameOnSyncPData
- };
- }
- self.functionIDs = functionIDs;
+ self.functionIds = @{
+ @0: SDLNameReserved,
+ @1: SDLNameRegisterAppInterface,
+ @2: SDLNameUnregisterAppInterface,
+ @3: SDLNameSetGlobalProperties,
+ @4: SDLNameResetGlobalProperties,
+ @5: SDLNameAddCommand,
+ @6: SDLNameDeleteCommand,
+ @7: SDLNameAddSubMenu,
+ @8: SDLNameDeleteSubMenu,
+ @9: SDLNameCreateInteractionChoiceSet,
+ @10: SDLNamePerformInteraction,
+ @11: SDLNameDeleteInteractionChoiceSet,
+ @12: SDLNameAlert,
+ @13: SDLNameShow,
+ @14: SDLNameSpeak,
+ @15: SDLNameSetMediaClockTimer,
+ @16: SDLNamePerformAudioPassThru,
+ @17: SDLNameEndAudioPassThru,
+ @18: SDLNameSubscribeButton,
+ @19: SDLNameUnsubscribeButton,
+ @20: SDLNameSubscribeVehicleData,
+ @21: SDLNameUnsubscribeVehicleData,
+ @22: SDLNameGetVehicleData,
+ @23: SDLNameReadDID,
+ @24: SDLNameGetDTCs,
+ @25: SDLNameScrollableMessage,
+ @26: SDLNameSlider,
+ @27: SDLNameShowConstantTBT,
+ @28: SDLNameAlertManeuver,
+ @29: SDLNameUpdateTurnList,
+ @30: SDLNameChangeRegistration,
+ @31: SDLNameGenericResponse,
+ @32: SDLNamePutFile,
+ @33: SDLNameDeleteFile,
+ @34: SDLNameListFiles,
+ @35: SDLNameSetAppIcon,
+ @36: SDLNameSetDisplayLayout,
+ @37: SDLNameDiagnosticMessage,
+ @38: SDLNameSystemRequest,
+ @39: SDLNameSendLocation,
+ @40: SDLNameDialNumber,
+ @32768: SDLNameOnHMIStatus,
+ @32769: SDLNameOnAppInterfaceUnregistered,
+ @32770: SDLNameOnButtonEvent,
+ @32771: SDLNameOnButtonPress,
+ @32772: SDLNameOnVehicleData,
+ @32773: SDLNameOnCommand,
+ @32774: SDLNameOnTBTClientState,
+ @32775: SDLNameOnDriverDistraction,
+ @32776: SDLNameOnPermissionsChange,
+ @32777: SDLNameOnAudioPassThru,
+ @32778: SDLNameOnLanguageChange,
+ @32779: SDLNameOnKeyboardInput,
+ @32780: SDLNameOnTouchEvent,
+ @32781: SDLNameOnSystemRequest,
+ @32782: SDLNameOnHashChange,
+ @65536: SDLNameEncodedSyncPData,
+ @65537: SDLNameSyncPData,
+ @98304: SDLNameOnEncodedSyncPData,
+ @98305: SDLNameOnSyncPData
+ };
}
return self;
}
-- (SDLName)getFunctionName:(int)functionID {
- return [self.functionIDs objectForKey:@(functionID)];
+- (SDLName)functionNameForId:(int)functionID {
+ return self.functionIds[@(functionID)];
}
-- (NSNumber *)getFunctionID:(SDLName)functionName {
- return [[self.functionIDs allKeysForObject:functionName] firstObject];
+- (NSNumber *)functionIdForName:(SDLName)functionName {
+ return [[self.functionIds allKeysForObject:functionName] firstObject];
}
diff --git a/SmartDeviceLink/SDLProtocol.m b/SmartDeviceLink/SDLProtocol.m
index 6261e02ee..e53829faa 100644
--- a/SmartDeviceLink/SDLProtocol.m
+++ b/SmartDeviceLink/SDLProtocol.m
@@ -203,7 +203,7 @@ typedef NSNumber SDLServiceTypeBox;
// Build a binary header
// Serialize the RPC data into an NSData
SDLRPCPayload *rpcPayload = [[SDLRPCPayload alloc] init];
- rpcPayload.functionID = [[[[SDLFunctionID alloc] init] getFunctionID:[message getFunctionName]] intValue];
+ rpcPayload.functionID = [[[SDLFunctionID sharedInstance] functionIdForName:[message functionNameForId]] intValue];
rpcPayload.jsonData = jsonData;
rpcPayload.binaryData = message.bulkData;
diff --git a/SmartDeviceLink/SDLProtocolMessage.m b/SmartDeviceLink/SDLProtocolMessage.m
index 151f820e0..2d1007dbf 100644
--- a/SmartDeviceLink/SDLProtocolMessage.m
+++ b/SmartDeviceLink/SDLProtocolMessage.m
@@ -61,7 +61,7 @@
if (self.header.version >= 2) {
SDLRPCPayload *rpcPayload = [SDLRPCPayload rpcPayloadWithData:self.payload];
if (rpcPayload) {
- SDLName functionName = [[[SDLFunctionID alloc] init] getFunctionName:rpcPayload.functionID];
+ SDLName functionName = [[SDLFunctionID sharedInstance] functionNameForId:rpcPayload.functionID];
UInt8 rpcType = rpcPayload.rpcType;
NSArray *rpcTypeNames = @[@"Request", @"Response", @"Notification"];
diff --git a/SmartDeviceLink/SDLProxy.m b/SmartDeviceLink/SDLProxy.m
index 11dbf3597..5c32a3f80 100644
--- a/SmartDeviceLink/SDLProxy.m
+++ b/SmartDeviceLink/SDLProxy.m
@@ -304,7 +304,7 @@ const int POLICIES_CORRELATION_ID = 65535;
- (void)handleRPCDictionary:(NSDictionary *)dict {
SDLRPCMessage *message = [[SDLRPCMessage alloc] initWithDictionary:[dict mutableCopy]];
- NSString *functionName = [message getFunctionName];
+ NSString *functionName = [message functionNameForId];
NSString *messageType = [message messageType];
// If it's a response, append response
diff --git a/SmartDeviceLink/SDLRPCMessage.h b/SmartDeviceLink/SDLRPCMessage.h
index fc5f577ef..bc31361d5 100644
--- a/SmartDeviceLink/SDLRPCMessage.h
+++ b/SmartDeviceLink/SDLRPCMessage.h
@@ -13,7 +13,7 @@
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithDictionary:(NSMutableDictionary *)dict;
-- (NSString *)getFunctionName;
+- (NSString *)functionNameForId;
- (void)setFunctionName:(NSString *)functionName;
- (NSObject *)getParameters:(NSString *)functionName;
- (void)setParameters:(NSString *)functionName value:(NSObject *)value;
diff --git a/SmartDeviceLink/SDLRPCMessage.m b/SmartDeviceLink/SDLRPCMessage.m
index d93780111..ce9ea9f05 100644
--- a/SmartDeviceLink/SDLRPCMessage.m
+++ b/SmartDeviceLink/SDLRPCMessage.m
@@ -38,7 +38,7 @@
return self;
}
-- (NSString *)getFunctionName {
+- (NSString *)functionNameForId {
return [function objectForKey:SDLNameOperationName];
}
diff --git a/SmartDeviceLink/SDLV2ProtocolMessage.m b/SmartDeviceLink/SDLV2ProtocolMessage.m
index 5f1aa5492..e8e89e259 100644
--- a/SmartDeviceLink/SDLV2ProtocolMessage.m
+++ b/SmartDeviceLink/SDLV2ProtocolMessage.m
@@ -33,7 +33,7 @@
// Create the inner dictionary with the RPC properties
NSMutableDictionary *innerDictionary = [[NSMutableDictionary alloc] init];
- NSString *functionName = [[[SDLFunctionID alloc] init] getFunctionName:rpcPayload.functionID];
+ NSString *functionName = [[SDLFunctionID sharedInstance] functionNameForId:rpcPayload.functionID];
[innerDictionary setObject:functionName forKey:SDLNameOperationName];
[innerDictionary setObject:[NSNumber numberWithInt:rpcPayload.correlationID] forKey:SDLNameCorrelationId];