Skip to content

Commit

Permalink
[DarwinFrameworkTool] Add autoResubscribe optional parameters to comm…
Browse files Browse the repository at this point in the history
…ands making subscriptions (#22339)
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 24, 2022
1 parent 1f23583 commit b468d7d
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,31 @@ class SubscribeAttribute : public ModelCommand {
{
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterId);
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ModelCommand::AddArguments();
AddCommonArguments();
}

SubscribeAttribute(chip::ClusterId clusterId)
: ModelCommand("subscribe-by-id")
, mClusterId(clusterId)
{
AddArgument("attribute-id", 0, UINT32_MAX, &mAttributeId);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
ModelCommand::AddArguments();
AddCommonArguments();
}

SubscribeAttribute(const char * _Nonnull attributeName)
: ModelCommand("subscribe")
{
AddArgument("attr-name", attributeName);
AddCommonArguments();
}

void AddCommonArguments()
{
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddArgument("autoResubscribe", 0, 1, &mAutoResubscribe);
ModelCommand::AddArguments();
}

Expand All @@ -125,9 +123,12 @@ class SubscribeAttribute : public ModelCommand {
CHIP_ERROR SendCommand(MTRBaseDevice * _Nonnull device, chip::EndpointId endpointId) override
{
dispatch_queue_t callbackQueue = dispatch_queue_create("com.chip.command", DISPATCH_QUEUE_SERIAL);

MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeAttributeWithEndpointId:[NSNumber numberWithUnsignedShort:endpointId]
clusterId:[NSNumber numberWithUnsignedInteger:mClusterId]
attributeId:[NSNumber numberWithUnsignedInteger:mAttributeId]
Expand All @@ -154,6 +155,7 @@ class SubscribeAttribute : public ModelCommand {

protected:
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mAutoResubscribe;
chip::Optional<bool> mFabricFiltered;
bool mSubscriptionEstablished = NO;
uint16_t mMinInterval;
Expand All @@ -180,6 +182,7 @@ class SubscribeEvent : public ModelCommand {
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddArgument("autoResubscribe", 0, 1, &mAutoResubscribe);
ModelCommand::AddArguments();
}

Expand All @@ -192,6 +195,8 @@ class SubscribeEvent : public ModelCommand {
MTRSubscribeParams * params = [[MTRSubscribeParams alloc] init];
params.keepPreviousSubscriptions
= mKeepSubscriptions.HasValue() ? [NSNumber numberWithBool:mKeepSubscriptions.Value()] : nil;
params.autoResubscribe = mAutoResubscribe.HasValue() ? [NSNumber numberWithBool:mAutoResubscribe.Value()] : nil;

[device subscribeWithQueue:callbackQueue
minInterval:mMinInterval
maxInterval:mMaxInterval
Expand Down Expand Up @@ -220,6 +225,7 @@ class SubscribeEvent : public ModelCommand {

protected:
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<bool> mAutoResubscribe;
chip::Optional<chip::EventNumber> mEventNumber;
bool mSubscriptionEstablished = NO;
uint16_t mMinInterval;
Expand Down

0 comments on commit b468d7d

Please sign in to comment.