Skip to content

Commit

Permalink
Github Optional Shadow Topic Subscription aws-amplify#2039 fix. enabl…
Browse files Browse the repository at this point in the history
…eIgnoreDeletes and enableIgnoreRejecteds flags added for decreasing subscribed topic count.
  • Loading branch information
emrekarasahin committed Nov 11, 2021
1 parent 6245d6b commit 48c0e00
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions AWSIoT/AWSIoTDataManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ enableVersioning: BOOL, set to NO to disable versioning (default YES)
enableForeignStateUpdateNotifications: BOOL, set to YES to enable foreign state updates (default NO)
enableStaleDiscards: BOOL, set to NO to disable discarding stale updates (default YES)
enableIgnoreDeltas: BOOL, set to YES to disable delta updates (default NO)
enableIgnoreDeletes: BOOL, set to YES to disable delete updates (default NO)
enableIgnoreRejecteds: BOOL, set to YES to disable all/rejected updates (default NO)
QoS: AWSIoTMQTTQoS (default AWSIoTMQTTQoSMessageDeliveryAttemptedAtMostOnce)
shadowOperationTimeoutSeconds: double, device shadow operation timeout (default 10.0)
Expand Down
29 changes: 25 additions & 4 deletions AWSIoT/AWSIoTDataManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ @interface AWSIoTDataShadow:NSObject
@property(atomic, assign) BOOL enableStaleDiscards;
@property(atomic, assign) BOOL enableIgnoreDeltas;
@property(atomic, assign) BOOL enableIgnoreDocuments;
@property(atomic, assign) BOOL enableIgnoreDeletes;
@property(atomic, assign) BOOL enableIgnoreRejecteds;
@property(atomic, assign) UInt32 version;
@property(nonatomic, strong) NSString *clientToken;
@property(atomic, assign) AWSIoTMQTTQoS qos;
Expand All @@ -73,6 +75,8 @@ - (instancetype)initWithName:(NSString *)name
discardStaleUpdates:(BOOL)enableStaleDiscards
discardDeltas:(BOOL)enableIgnoreDeltas
discardDocuments:(BOOL)enableIgnoreDocuments
discardDeletes:(BOOL)enableIgnoreDeletes
discardRejecteds:(BOOL)enableIgnoreRejecteds
updateOnForeignChanges:(BOOL)enableForeignStateUpdateNotifications
operationTimeout:(NSTimeInterval)operationTimeoutSeconds
QoS:(AWSIoTMQTTQoS)qos
Expand All @@ -85,6 +89,8 @@ - (instancetype)initWithName:(NSString *)name
_enableStaleDiscards = enableStaleDiscards;
_enableIgnoreDeltas = enableIgnoreDeltas;
_enableIgnoreDocuments = enableIgnoreDocuments;
_enableIgnoreDeletes = enableIgnoreDeletes;
_enableIgnoreRejecteds = enableIgnoreRejecteds;
_enableForeignStateUpdateNotifications = enableForeignStateUpdateNotifications;
_callback = callback;
_operationTimeout = operationTimeoutSeconds;
Expand Down Expand Up @@ -1218,6 +1224,8 @@ - (BOOL) registerWithShadow:(NSString *)name
discardStaleUpdates:YES
discardDeltas:NO
discardDocuments:NO
discardDeletes:NO
discardRejecteds:NO
updateOnForeignChanges:NO
operationTimeout:10.0
QoS:AWSIoTMQTTQoSMessageDeliveryAttemptedAtMostOnce
Expand Down Expand Up @@ -1257,6 +1265,14 @@ - (BOOL) registerWithShadow:(NSString *)name
if (numberOptionValue != nil) {
shadow.enableIgnoreDocuments = [numberOptionValue integerValue];
}
numberOptionValue = [options valueForKey:@"enableIgnoreDeletes"];
if (numberOptionValue != nil) {
shadow.enableIgnoreDeletes = [numberOptionValue integerValue];
}
numberOptionValue = [options valueForKey:@"enableIgnoreRejecteds"];
if (numberOptionValue != nil) {
shadow.enableIgnoreRejecteds = [numberOptionValue integerValue];
}
numberOptionValue = [options valueForKey:@"QoS"];
if (numberOptionValue != nil) {
shadow.qos = [numberOptionValue integerValue];
Expand All @@ -1276,12 +1292,17 @@ - (BOOL) registerWithShadow:(NSString *)name
operations:@[[NSNumber numberWithInteger:AWSIoTShadowOperationTypeUpdate]]
statii:@[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeDocuments]] ];
}
if (shadow.enableIgnoreDeletes == NO) {
NSArray * statii = shadow.enableIgnoreRejecteds ? @[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeAccepted]] : @[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeAccepted], [NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeRejected]];
[self createSubscriptionsForShadow:shadow
operations:@[[NSNumber numberWithInteger:AWSIoTShadowOperationTypeDelete]]
statii:statii];
}
NSArray * statii = shadow.enableIgnoreRejecteds ? @[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeAccepted]] : @[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeAccepted], [NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeRejected]];
[self createSubscriptionsForShadow:shadow
operations:@[[NSNumber numberWithInteger:AWSIoTShadowOperationTypeUpdate],
[NSNumber numberWithInteger:AWSIoTShadowOperationTypeGet],
[NSNumber numberWithInteger:AWSIoTShadowOperationTypeDelete]]
statii:@[[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeAccepted],
[NSNumber numberWithInteger:AWSIoTShadowOperationStatusTypeRejected]]];
[NSNumber numberWithInteger:AWSIoTShadowOperationTypeGet]]
statii:statii];
//
// Persistently subscribe to the special topics for this shadow.
//
Expand Down

0 comments on commit 48c0e00

Please sign in to comment.