diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2016-08-25 16:56:14 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2016-08-25 16:56:14 -0400 |
commit | 44d6fd093b5ffd3267e34ce48003ef15a930b195 (patch) | |
tree | 2729ba1f7c99c5ad59d7e9a8397e57d5cec9d39c /SmartDeviceLink | |
parent | ad762812898c1849be83eb4dbefcba475dfbafe1 (diff) | |
download | sdl_ios-44d6fd093b5ffd3267e34ce48003ef15a930b195.tar.gz |
Add typed SDL notifications with backward compatibility
Diffstat (limited to 'SmartDeviceLink')
-rw-r--r-- | SmartDeviceLink/SDLNotificationDispatcher.m | 157 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRPCNotificationNotification.h | 24 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRPCNotificationNotification.m | 26 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRPCResponseNotification.h | 24 | ||||
-rw-r--r-- | SmartDeviceLink/SDLRPCResponseNotification.m | 26 |
5 files changed, 190 insertions, 67 deletions
diff --git a/SmartDeviceLink/SDLNotificationDispatcher.m b/SmartDeviceLink/SDLNotificationDispatcher.m index c4a7ce4ac..1abf6249a 100644 --- a/SmartDeviceLink/SDLNotificationDispatcher.m +++ b/SmartDeviceLink/SDLNotificationDispatcher.m @@ -10,6 +10,9 @@ #import "SDLError.h" #import "SDLNotificationConstants.h" +#import "SDLRPCNotification.h" +#import "SDLRPCResponseNotification.h" +#import "SDLRPCNotificationNotification.h" NS_ASSUME_NONNULL_BEGIN @@ -21,12 +24,27 @@ NS_ASSUME_NONNULL_BEGIN if (infoObject != nil) { userInfo = @{SDLNotificationUserInfoObject : infoObject}; } - + dispatch_async(dispatch_get_main_queue(), ^{ [[NSNotificationCenter defaultCenter] postNotificationName:name object:self userInfo:userInfo]; }); } +- (void)postRPCResponseNotification:(NSString *)name response:(__kindof SDLRPCResponse *)response { + dispatch_async(dispatch_get_main_queue(), ^{ + SDLRPCResponseNotification *notification = [[SDLRPCResponseNotification alloc] initWithName:name object:self rpcResponse:response]; + [[NSNotificationCenter defaultCenter] postNotification:notification]; + }); +} + +- (void)postRPCNotificationNotification:(NSString *)name notification:(__kindof SDLRPCNotification *)rpcNotification { + dispatch_async(dispatch_get_main_queue(), ^{ + SDLRPCNotificationNotification *notification = [[SDLRPCNotificationNotification alloc] initWithName:name object:self rpcNotification:rpcNotification]; + [[NSNotificationCenter defaultCenter] postNotification:notification]; + }); +} + + #pragma mark - SDLProxyListener Delegate Methods - (void)onProxyOpened { @@ -37,12 +55,15 @@ NS_ASSUME_NONNULL_BEGIN [self postNotificationName:SDLTransportDidDisconnect infoObject:nil]; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wincompatible-pointer-types" + - (void)onOnHMIStatus:(SDLOnHMIStatus *)notification { - [self postNotificationName:SDLDidChangeHMIStatusNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidChangeHMIStatusNotification notification:notification]; } - (void)onOnDriverDistraction:(SDLOnDriverDistraction *)notification { - [self postNotificationName:SDLDidChangeDriverDistractionStateNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidChangeDriverDistractionStateNotification notification:notification]; } @@ -53,238 +74,240 @@ NS_ASSUME_NONNULL_BEGIN [self postNotificationName:SDLDidReceiveError infoObject:error]; } +- (void)onReceivedLockScreenIcon:(UIImage *)icon { + [self postNotificationName:SDLDidReceiveLockScreenIcon infoObject:icon]; +} + - (void)onAddCommandResponse:(SDLAddCommandResponse *)response { - [self postNotificationName:SDLDidReceiveAddCommandResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveAddCommandResponse response:response]; } - (void)onAddSubMenuResponse:(SDLAddSubMenuResponse *)response { - [self postNotificationName:SDLDidReceiveAddSubMenuResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveAddSubMenuResponse response:response]; } - (void)onAlertManeuverResponse:(SDLAlertManeuverResponse *)response { - [self postNotificationName:SDLDidReceiveAlertManeuverResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveAlertManeuverResponse response:response]; } - (void)onAlertResponse:(SDLAlertResponse *)response { - [self postNotificationName:SDLDidReceiveAlertResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveAlertResponse response:response]; } - (void)onChangeRegistrationResponse:(SDLChangeRegistrationResponse *)response { - [self postNotificationName:SDLDidReceiveChangeRegistrationResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveChangeRegistrationResponse response:response]; } - (void)onCreateInteractionChoiceSetResponse:(SDLCreateInteractionChoiceSetResponse *)response { - [self postNotificationName:SDLDidReceiveCreateInteractionChoiceSetResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveCreateInteractionChoiceSetResponse response:response]; } - (void)onDeleteCommandResponse:(SDLDeleteCommandResponse *)response { - [self postNotificationName:SDLDidReceiveDeleteCommandResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDeleteCommandResponse response:response]; } - (void)onDeleteFileResponse:(SDLDeleteFileResponse *)response { - [self postNotificationName:SDLDidReceiveDeleteFileResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDeleteFileResponse response:response]; } - (void)onDeleteInteractionChoiceSetResponse:(SDLDeleteInteractionChoiceSetResponse *)response { - [self postNotificationName:SDLDidReceiveDeleteInteractionChoiceSetResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDeleteInteractionChoiceSetResponse response:response]; } - (void)onDeleteSubMenuResponse:(SDLDeleteSubMenuResponse *)response { - [self postNotificationName:SDLDidReceiveDeleteSubmenuResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDeleteSubmenuResponse response:response]; } - (void)onDiagnosticMessageResponse:(SDLDiagnosticMessageResponse *)response { - [self postNotificationName:SDLDidReceiveDiagnosticMessageResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDiagnosticMessageResponse response:response]; } - (void)onDialNumberResponse:(SDLDialNumberResponse *)response { - [self postNotificationName:SDLDidReceiveDialNumberResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveDialNumberResponse response:response]; } - (void)onEncodedSyncPDataResponse:(SDLEncodedSyncPDataResponse *)response { - [self postNotificationName:SDLDidReceiveEncodedSyncPDataResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveEncodedSyncPDataResponse response:response]; } - (void)onEndAudioPassThruResponse:(SDLEndAudioPassThruResponse *)response { - [self postNotificationName:SDLDidReceiveEndAudioPassThruResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveEndAudioPassThruResponse response:response]; } - (void)onGenericResponse:(SDLGenericResponse *)response { - [self postNotificationName:SDLDidReceiveGenericResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveGenericResponse response:response]; } - (void)onGetDTCsResponse:(SDLGetDTCsResponse *)response { - [self postNotificationName:SDLDidReceiveGetDTCsResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveGetDTCsResponse response:response]; } - (void)onGetVehicleDataResponse:(SDLGetVehicleDataResponse *)response { - [self postNotificationName:SDLDidReceiveGetVehicleDataResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveGetVehicleDataResponse response:response]; } - (void)onListFilesResponse:(SDLListFilesResponse *)response { - [self postNotificationName:SDLDidReceiveListFilesResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveListFilesResponse response:response]; } - (void)onPerformAudioPassThruResponse:(SDLPerformAudioPassThruResponse *)response { - [self postNotificationName:SDLDidReceivePerformAudioPassThruResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceivePerformAudioPassThruResponse response:response]; } - (void)onPerformInteractionResponse:(SDLPerformInteractionResponse *)response { - [self postNotificationName:SDLDidReceivePerformInteractionResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceivePerformInteractionResponse response:response]; } - (void)onPutFileResponse:(SDLPutFileResponse *)response { - [self postNotificationName:SDLDidReceivePutFileResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceivePutFileResponse response:response]; } - (void)onReadDIDResponse:(SDLReadDIDResponse *)response { - [self postNotificationName:SDLDidReceiveReadDIDResponse infoObject:response]; -} - -- (void)onReceivedLockScreenIcon:(UIImage *)icon { - [self postNotificationName:SDLDidReceiveLockScreenIcon infoObject:icon]; + [self postRPCResponseNotification:SDLDidReceiveReadDIDResponse response:response]; } - (void)onRegisterAppInterfaceResponse:(SDLRegisterAppInterfaceResponse *)response { - [self postNotificationName:SDLDidReceiveRegisterAppInterfaceResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveRegisterAppInterfaceResponse response:response]; } - (void)onResetGlobalPropertiesResponse:(SDLResetGlobalPropertiesResponse *)response { - [self postNotificationName:SDLDidReceiveResetGlobalPropertiesResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveResetGlobalPropertiesResponse response:response]; } - (void)onScrollableMessageResponse:(SDLScrollableMessageResponse *)response { - [self postNotificationName:SDLDidReceiveScrollableMessageResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveScrollableMessageResponse response:response]; } - (void)onSendLocationResponse:(SDLSendLocationResponse *)response { - [self postNotificationName:SDLDidReceiveSendLocationResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSendLocationResponse response:response]; } - (void)onSetAppIconResponse:(SDLSetAppIconResponse *)response { - [self postNotificationName:SDLDidReceiveSetAppIconResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSetAppIconResponse response:response]; } - (void)onSetDisplayLayoutResponse:(SDLSetDisplayLayoutResponse *)response { - [self postNotificationName:SDLDidReceiveSetDisplayLayoutResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSetDisplayLayoutResponse response:response]; } - (void)onSetGlobalPropertiesResponse:(SDLSetGlobalPropertiesResponse *)response { - [self postNotificationName:SDLDidReceiveSetGlobalPropertiesResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSetGlobalPropertiesResponse response:response]; } - (void)onSetMediaClockTimerResponse:(SDLSetMediaClockTimerResponse *)response { - [self postNotificationName:SDLDidReceiveSetMediaClockTimerResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSetMediaClockTimerResponse response:response]; } - (void)onShowConstantTBTResponse:(SDLShowConstantTBTResponse *)response { - [self postNotificationName:SDLDidReceiveShowConstantTBTResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveShowConstantTBTResponse response:response]; } - (void)onShowResponse:(SDLShowResponse *)response { - [self postNotificationName:SDLDidReceiveShowResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveShowResponse response:response]; } - (void)onSliderResponse:(SDLSliderResponse *)response { - [self postNotificationName:SDLDidReceiveSliderResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSliderResponse response:response]; } - (void)onSpeakResponse:(SDLSpeakResponse *)response { - [self postNotificationName:SDLDidReceiveSpeakResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSpeakResponse response:response]; } - (void)onSubscribeButtonResponse:(SDLSubscribeButtonResponse *)response { - [self postNotificationName:SDLDidReceiveSubscribeButtonResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSubscribeButtonResponse response:response]; } - (void)onSubscribeVehicleDataResponse:(SDLSubscribeVehicleDataResponse *)response { - [self postNotificationName:SDLDidReceiveSubscribeVehicleDataResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSubscribeVehicleDataResponse response:response]; } - (void)onSyncPDataResponse:(SDLSyncPDataResponse *)response { - [self postNotificationName:SDLDidReceiveSyncPDataResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveSyncPDataResponse response:response]; } - (void)onUpdateTurnListResponse:(SDLUpdateTurnListResponse *)response { - [self postNotificationName:SDLDidReceiveUpdateTurnListResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveUpdateTurnListResponse response:response]; } - (void)onUnregisterAppInterfaceResponse:(SDLUnregisterAppInterfaceResponse *)response { - [self postNotificationName:SDLDidReceiveUnregisterAppInterfaceResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveUnregisterAppInterfaceResponse response:response]; } - (void)onUnsubscribeButtonResponse:(SDLUnsubscribeButtonResponse *)response { - [self postNotificationName:SDLDidReceiveUnsubscribeButtonResponse infoObject:response]; + [self postRPCResponseNotification:SDLDidReceiveUnsubscribeButtonResponse response:response]; } - (void)onUnsubscribeVehicleDataResponse:(SDLUnsubscribeVehicleDataResponse *)response { - [self postNotificationName:SDLDidReceiveUnsubscribeVehicleDataResponse infoObject:response]; -} - -- (void)onOnLockScreenNotification:(SDLOnLockScreenStatus *)notification { - [self postNotificationName:SDLDidChangeLockScreenStatusNotification infoObject:notification]; + [self postRPCResponseNotification:SDLDidReceiveUnsubscribeVehicleDataResponse response:response]; } - (void)onOnAppInterfaceUnregistered:(SDLOnAppInterfaceUnregistered *)notification { - [self postNotificationName:SDLDidReceiveUnregisterAppInterfaceResponse infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveUnregisterAppInterfaceResponse notification:notification]; } - (void)onOnAudioPassThru:(SDLOnAudioPassThru *)notification { - [self postNotificationName:SDLDidReceiveAudioPassThruNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveAudioPassThruNotification notification:notification]; } - (void)onOnButtonEvent:(SDLOnButtonEvent *)notification { - [self postNotificationName:SDLDidReceiveButtonEventNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveButtonEventNotification notification:notification]; } - (void)onOnButtonPress:(SDLOnButtonPress *)notification { - [self postNotificationName:SDLDidReceiveButtonPressNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveButtonPressNotification notification:notification]; } - (void)onOnCommand:(SDLOnCommand *)notification { - [self postNotificationName:SDLDidReceiveCommandNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveCommandNotification notification:notification]; } - (void)onOnEncodedSyncPData:(SDLOnEncodedSyncPData *)notification { - [self postNotificationName:SDLDidReceiveEncodedDataNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveEncodedDataNotification notification:notification]; } - (void)onOnHashChange:(SDLOnHashChange *)notification { - [self postNotificationName:SDLDidReceiveNewHashNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveNewHashNotification notification:notification]; } - (void)onOnKeyboardInput:(SDLOnKeyboardInput *)notification { - [self postNotificationName:SDLDidReceiveKeyboardInputNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveKeyboardInputNotification notification:notification]; } - (void)onOnLanguageChange:(SDLOnLanguageChange *)notification { - [self postNotificationName:SDLDidChangeLanguageNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidChangeLanguageNotification notification:notification]; +} + +- (void)onOnLockScreenNotification:(SDLOnLockScreenStatus *)notification { + [self postRPCNotificationNotification:SDLDidChangeLockScreenStatusNotification notification:notification]; } - (void)onOnPermissionsChange:(SDLOnPermissionsChange *)notification { - [self postNotificationName:SDLDidChangePermissionsNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidChangePermissionsNotification notification:notification]; } - (void)onOnSyncPData:(SDLOnSyncPData *)notification { - [self postNotificationName:SDLDidReceiveSystemRequestNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveSystemRequestNotification notification:notification]; } - (void)onOnSystemRequest:(SDLOnSystemRequest *)notification { - [self postNotificationName:SDLDidReceiveSystemRequestNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveSystemRequestNotification notification:notification]; } - (void)onOnTBTClientState:(SDLOnTBTClientState *)notification { - [self postNotificationName:SDLDidChangeTurnByTurnStateNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidChangeTurnByTurnStateNotification notification:notification]; } - (void)onOnTouchEvent:(SDLOnTouchEvent *)notification { - [self postNotificationName:SDLDidReceiveTouchEventNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveTouchEventNotification notification:notification]; } - (void)onOnVehicleData:(SDLOnVehicleData *)notification { - [self postNotificationName:SDLDidReceiveVehicleDataNotification infoObject:notification]; + [self postRPCNotificationNotification:SDLDidReceiveVehicleDataNotification notification:notification]; } +#pragma clang diagnostic pop + @end NS_ASSUME_NONNULL_END
\ No newline at end of file diff --git a/SmartDeviceLink/SDLRPCNotificationNotification.h b/SmartDeviceLink/SDLRPCNotificationNotification.h new file mode 100644 index 000000000..ba0b7a05f --- /dev/null +++ b/SmartDeviceLink/SDLRPCNotificationNotification.h @@ -0,0 +1,24 @@ +// +// SDLRPCNotificationNotification.h +// SmartDeviceLink-iOS +// +// Created by Joel Fischer on 8/25/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@class SDLRPCNotification; + + +NS_ASSUME_NONNULL_BEGIN + +@interface SDLRPCNotificationNotification : NSNotification + +@property (copy, nonatomic, readonly) SDLRPCNotification *notification; + +- (instancetype)initWithName:(NSString *)name object:(id)object rpcNotification:(__kindof SDLRPCNotification *)notification; + +@end + +NS_ASSUME_NONNULL_END
\ No newline at end of file diff --git a/SmartDeviceLink/SDLRPCNotificationNotification.m b/SmartDeviceLink/SDLRPCNotificationNotification.m new file mode 100644 index 000000000..e32c11714 --- /dev/null +++ b/SmartDeviceLink/SDLRPCNotificationNotification.m @@ -0,0 +1,26 @@ +// +// SDLRPCNotificationNotification.m +// SmartDeviceLink-iOS +// +// Created by Joel Fischer on 8/25/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import "SDLRPCNotificationNotification.h" + +#import "SDLNotificationConstants.h" +#import "SDLRPCNotification.h" + + +@implementation SDLRPCNotificationNotification + +- (instancetype)initWithName:(NSString *)name object:(id)object rpcNotification:(SDLRPCNotification *)notification { + self = [self initWithName:name object:object userInfo:@{SDLNotificationUserInfoObject : notification}]; + if (!self) { return nil; } + + _notification = notification; + + return self; +} + +@end diff --git a/SmartDeviceLink/SDLRPCResponseNotification.h b/SmartDeviceLink/SDLRPCResponseNotification.h new file mode 100644 index 000000000..5f0668e44 --- /dev/null +++ b/SmartDeviceLink/SDLRPCResponseNotification.h @@ -0,0 +1,24 @@ +// +// SDLRPCResponseNotification.h +// SmartDeviceLink-iOS +// +// Created by Joel Fischer on 8/25/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> + +@class SDLRPCResponse; + + +NS_ASSUME_NONNULL_BEGIN + +@interface SDLRPCResponseNotification : NSNotification + +@property (copy, nonatomic, readonly) SDLRPCResponse *response; + +- (instancetype)initWithName:(NSString *)name object:(id)object rpcResponse:(__kindof SDLRPCResponse *)response; + +@end + +NS_ASSUME_NONNULL_END
\ No newline at end of file diff --git a/SmartDeviceLink/SDLRPCResponseNotification.m b/SmartDeviceLink/SDLRPCResponseNotification.m new file mode 100644 index 000000000..35cf6e560 --- /dev/null +++ b/SmartDeviceLink/SDLRPCResponseNotification.m @@ -0,0 +1,26 @@ +// +// SDLRPCResponseNotification.m +// SmartDeviceLink-iOS +// +// Created by Joel Fischer on 8/25/16. +// Copyright © 2016 smartdevicelink. All rights reserved. +// + +#import "SDLRPCResponseNotification.h" + +#import "SDLNotificationConstants.h" +#import "SDLRPCResponse.h" + + +@implementation SDLRPCResponseNotification + +- (instancetype)initWithName:(NSString *)name object:(id)object rpcResponse:(SDLRPCResponse *)response { + self = [self initWithName:name object:object userInfo:@{SDLNotificationUserInfoObject : response}]; + if (!self) { return nil; } + + _response = response; + + return self; +} + +@end |