diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2019-04-04 16:09:20 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2019-04-04 16:09:20 -0400 |
commit | 183b18b55c8868949d620bbde0a13febe5415add (patch) | |
tree | 3bf92c467c54987d78e57ef2f1f5bf1b0d60db9e | |
parent | 1dbde874a8876909b9117bfd7eab2795528862df (diff) | |
download | sdl_ios-183b18b55c8868949d620bbde0a13febe5415add.tar.gz |
Store app services capabilities in a dict
* Better handling of merging service capabilities
-rw-r--r-- | SmartDeviceLink/SDLSystemCapabilityManager.m | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/SmartDeviceLink/SDLSystemCapabilityManager.m b/SmartDeviceLink/SDLSystemCapabilityManager.m index 088d56105..50fc3e669 100644 --- a/SmartDeviceLink/SDLSystemCapabilityManager.m +++ b/SmartDeviceLink/SDLSystemCapabilityManager.m @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN @interface SDLSystemCapabilityManager () +typedef NSString * SDLServiceID; + @property (weak, nonatomic) id<SDLConnectionManagerType> connectionManager; @property (nullable, strong, nonatomic, readwrite) SDLDisplayCapabilities *displayCapabilities; @@ -46,12 +48,13 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign, readwrite) BOOL vrCapability; @property (nullable, copy, nonatomic, readwrite) NSArray<SDLAudioPassThruCapabilities *> *audioPassThruCapabilities; @property (nullable, strong, nonatomic, readwrite) SDLAudioPassThruCapabilities *pcmStreamCapability; -@property (nullable, strong, nonatomic, readwrite) SDLAppServicesCapabilities *appServicesCapabilities; @property (nullable, strong, nonatomic, readwrite) SDLNavigationCapability *navigationCapability; @property (nullable, strong, nonatomic, readwrite) SDLPhoneCapability *phoneCapability; @property (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability; @property (nullable, strong, nonatomic, readwrite) SDLRemoteControlCapabilities *remoteControlCapability; +@property (nullable, strong, nonatomic) NSMutableDictionary<SDLServiceID, SDLAppServiceCapability *> *appServicesCapabilitiesDictionary; + @property (assign, nonatomic) BOOL isFirstHMILevelFull; @end @@ -68,6 +71,7 @@ NS_ASSUME_NONNULL_BEGIN _connectionManager = manager; _isFirstHMILevelFull = NO; + _appServicesCapabilitiesDictionary = [NSMutableDictionary dictionary]; [self sdl_registerForNotifications]; @@ -94,11 +98,17 @@ NS_ASSUME_NONNULL_BEGIN _phoneCapability = nil; _videoStreamingCapability = nil; _remoteControlCapability = nil; - _appServicesCapabilities = nil; + _appServicesCapabilitiesDictionary = [NSMutableDictionary dictionary]; _isFirstHMILevelFull = NO; } +#pragma mark - Getters + +- (nullable SDLAppServicesCapabilities *)appServicesCapabilities { + return [[SDLAppServicesCapabilities alloc] initWithAppServices:self.appServicesCapabilitiesDictionary.allValues]; +} + #pragma mark - Notifications /** @@ -255,21 +265,16 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sdl_saveAppServicesCapabilitiesUpdate:(SDLAppServicesCapabilities *)newCapabilities { - if (!self.appServicesCapabilities) { - self.appServicesCapabilities = newCapabilities; - } else { - NSMutableDictionary *cachedAppServicesCapabilities = [NSMutableDictionary dictionary]; - for (NSUInteger i = 0; i < self.appServicesCapabilities.appServices.count; i += 1) { - SDLAppServiceRecord *record = self.appServicesCapabilities.appServices[i].updatedAppServiceRecord; - cachedAppServicesCapabilities[record.serviceID] = record; - } - - for (NSUInteger i = 0; i < newCapabilities.appServices.count; i += 1) { - SDLAppServiceRecord *updatedRecord = newCapabilities.appServices[i].updatedAppServiceRecord; - cachedAppServicesCapabilities[updatedRecord.serviceID] = updatedRecord; + for (SDLAppServiceCapability *capability in newCapabilities.appServices) { + if (capability.updateReason == nil) { + // First update, new capability + self.appServicesCapabilitiesDictionary[capability.updatedAppServiceRecord.serviceID] = capability; + } else if ([capability.updateReason isEqualToEnum:SDLServiceUpdateRemoved]) { + self.appServicesCapabilitiesDictionary[capability.updatedAppServiceRecord.serviceID] = nil; + } else { + // Everything else involves adding or updating the existing service record + self.appServicesCapabilitiesDictionary[capability.updatedAppServiceRecord.serviceID] = capability; } - - self.appServicesCapabilities.appServices = [cachedAppServicesCapabilities allValues]; } } |