From d175fe4a943c4c5116a39d353c3b61e792d4be24 Mon Sep 17 00:00:00 2001 From: jepenven-silabs Date: Wed, 23 Mar 2022 15:27:42 -0400 Subject: [PATCH 1/2] Remove AssociateWithGroup --- .../tests/partials/test_cluster.zapt | 14 +++-- src/controller/CHIPCluster.cpp | 9 --- src/controller/CHIPCluster.h | 57 +++++++++++++++---- .../chip-tool/zap-generated/test/Commands.h | 10 ++-- 4 files changed, 61 insertions(+), 29 deletions(-) diff --git a/examples/chip-tool/templates/tests/partials/test_cluster.zapt b/examples/chip-tool/templates/tests/partials/test_cluster.zapt index aa11b89cc0f81b..3ee6664f689166 100644 --- a/examples/chip-tool/templates/tests/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/tests/partials/test_cluster.zapt @@ -276,11 +276,9 @@ class {{filename}}Suite: public TestCommand {{> maybeWait }} {{else}} chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster; - {{#if isGroupCommand}} - cluster.AssociateWithGroup({{>device}}, groupId); - {{else}} + {{#unless isGroupCommand}} cluster.Associate({{>device}}, endpoint); - {{/if}} + {{/unless}} {{#if (chip_tests_item_has_list)}} ListFreer listFreer;{{/if}} {{#chip_tests_item_parameters}} @@ -289,11 +287,19 @@ class {{filename}}Suite: public TestCommand {{/chip_tests_item_parameters}} {{#if isWriteAttribute}} + {{#if isGroupCommand}} + ReturnErrorOnFailure(cluster.WriteAttribute(groupId, {{>device}}->GetSecureSession().Value()->GetFabricIndex(), {{>device}}->GetDeviceId(),{{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}} + {{~> maybeTimedInteractionTimeout ~}} + {{~#if isGroupCommand}}, {{>staticDoneResponse}}{{/if~}} + )); + {{> maybeWait }} + {{else}} ReturnErrorOnFailure(cluster.WriteAttribute({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}} {{~> maybeTimedInteractionTimeout ~}} {{~#if isGroupCommand}}, {{>staticDoneResponse}}{{/if~}} )); {{> maybeWait }} + {{/if}} {{else if isReadEvent}} ReturnErrorOnFailure(cluster.ReadEvent<{{zapTypeToDecodableClusterObjectType event ns=cluster isArgument=true}}>(this, {{>staticSuccessResponse}}, {{>staticFailureResponse}})); {{else if isSubscribeEvent}} diff --git a/src/controller/CHIPCluster.cpp b/src/controller/CHIPCluster.cpp index d011ea5832a9b9..b829d575cee52f 100644 --- a/src/controller/CHIPCluster.cpp +++ b/src/controller/CHIPCluster.cpp @@ -42,15 +42,6 @@ CHIP_ERROR ClusterBase::Associate(DeviceProxy * device, EndpointId endpoint) return err; } -CHIP_ERROR ClusterBase::AssociateWithGroup(DeviceProxy * device, GroupId groupId) -{ - // TODO Update this function to work in all possible conditions Issue #11850 - mDevice = device; - mEndpoint = 0; // Set to 0 for now. - mGroupId.SetValue(groupId); - return CHIP_NO_ERROR; -} - void ClusterBase::Dissociate() { mDevice = nullptr; diff --git a/src/controller/CHIPCluster.h b/src/controller/CHIPCluster.h index 5dbbb8aaa91204..859316f4699cb0 100644 --- a/src/controller/CHIPCluster.h +++ b/src/controller/CHIPCluster.h @@ -56,7 +56,6 @@ class DLL_EXPORT ClusterBase virtual ~ClusterBase() {} CHIP_ERROR Associate(DeviceProxy * device, EndpointId endpoint); - CHIP_ERROR AssociateWithGroup(DeviceProxy * device, GroupId groupId); void Dissociate(); // Temporary function to set command timeout before we move over to InvokeCommand @@ -141,21 +140,56 @@ class DLL_EXPORT ClusterBase } }; - if (mGroupId.HasValue()) - { - VerifyOrReturnError(mDevice->GetSecureSession().HasValue(), CHIP_ERROR_INCORRECT_STATE); - Transport::OutgoingGroupSession groupSession(mGroupId.Value(), mDevice->GetSecureSession().Value()->GetFabricIndex(), - mDevice->GetDeviceId()); - return chip::Controller::WriteAttribute(SessionHandle(groupSession), mEndpoint, clusterId, attributeId, - requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs, onDoneCb, - aDataVersion); - } - return chip::Controller::WriteAttribute(mDevice->GetSecureSession().Value(), mEndpoint, clusterId, attributeId, requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs, onDoneCb, aDataVersion); } + template + CHIP_ERROR WriteAttribute(GroupId groupId, FabricIndex fabricIndex, NodeId sourceNodeId, const AttrType & requestData, + void * context, ClusterId clusterId, AttributeId attributeId, WriteResponseSuccessCallback successCb, + WriteResponseFailureCallback failureCb, const Optional & aTimedWriteTimeoutMs, + WriteResponseDoneCallback doneCb = nullptr, const Optional & aDataVersion = NullOptional) + { + + auto onSuccessCb = [context, successCb](const app::ConcreteAttributePath & aPath) { + if (successCb != nullptr) + { + successCb(context); + } + }; + + auto onFailureCb = [context, failureCb](const app::ConcreteAttributePath * aPath, CHIP_ERROR aError) { + if (failureCb != nullptr) + { + failureCb(context, aError); + } + }; + + auto onDoneCb = [context, doneCb](app::WriteClient * pWriteClient) { + if (doneCb != nullptr) + { + doneCb(context); + } + }; + + Transport::OutgoingGroupSession groupSession(groupId, fabricIndex, sourceNodeId); + return chip::Controller::WriteAttribute(SessionHandle(groupSession), 0 /*Unused for Group*/, clusterId, + attributeId, requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs, + onDoneCb, aDataVersion); + } + + template + CHIP_ERROR WriteAttribute(GroupId groupId, FabricIndex fabricIndex, NodeId sourceNodeId, + const typename AttributeInfo::Type & requestData, void * context, + WriteResponseSuccessCallback successCb, WriteResponseFailureCallback failureCb, + WriteResponseDoneCallback doneCb = nullptr, const Optional & aDataVersion = NullOptional, + const Optional & aTimedWriteTimeoutMs = NullOptional) + { + return WriteAttribute(groupId, fabricIndex, sourceNodeId, requestData, context, AttributeInfo::GetClusterId(), + AttributeInfo::GetAttributeId(), successCb, failureCb, aTimedWriteTimeoutMs, doneCb, aDataVersion); + } + template CHIP_ERROR WriteAttribute(const typename AttributeInfo::Type & requestData, void * context, WriteResponseSuccessCallback successCb, WriteResponseFailureCallback failureCb, @@ -345,7 +379,6 @@ class DLL_EXPORT ClusterBase const ClusterId mClusterId; DeviceProxy * mDevice; EndpointId mEndpoint; - Optional mGroupId; Optional mTimeout; }; diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 22f68a840de67a..a26056976c19c7 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -101806,13 +101806,14 @@ class TestGroupMessagingSuite : public TestCommand { const chip::GroupId groupId = 258; chip::Controller::BasicClusterTest cluster; - cluster.AssociateWithGroup(mDevices[kIdentityAlpha], groupId); chip::CharSpan locationArgument; locationArgument = chip::Span("USgarbage: not in length on purpose", 2); ReturnErrorOnFailure(cluster.WriteAttribute( - locationArgument, this, OnSuccessCallback_7, OnFailureCallback_7, OnDoneCallback_7)); + groupId, mDevices[kIdentityAlpha]->GetSecureSession().Value()->GetFabricIndex(), + mDevices[kIdentityAlpha]->GetDeviceId(), locationArgument, this, OnSuccessCallback_7, OnFailureCallback_7, + OnDoneCallback_7)); return CHIP_NO_ERROR; } @@ -101854,13 +101855,14 @@ class TestGroupMessagingSuite : public TestCommand { const chip::GroupId groupId = 258; chip::Controller::BasicClusterTest cluster; - cluster.AssociateWithGroup(mDevices[kIdentityAlpha], groupId); chip::CharSpan locationArgument; locationArgument = chip::Span("XXgarbage: not in length on purpose", 2); ReturnErrorOnFailure(cluster.WriteAttribute( - locationArgument, this, OnSuccessCallback_9, OnFailureCallback_9, OnDoneCallback_9)); + groupId, mDevices[kIdentityAlpha]->GetSecureSession().Value()->GetFabricIndex(), + mDevices[kIdentityAlpha]->GetDeviceId(), locationArgument, this, OnSuccessCallback_9, OnFailureCallback_9, + OnDoneCallback_9)); return CHIP_NO_ERROR; } From a01e0ce9a26106559a1d16fa299a02b2dcee5e6a Mon Sep 17 00:00:00 2001 From: jepenven-silabs Date: Thu, 24 Mar 2022 11:52:32 -0400 Subject: [PATCH 2/2] Fix comments --- examples/chip-tool/templates/tests/partials/test_cluster.zapt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/chip-tool/templates/tests/partials/test_cluster.zapt b/examples/chip-tool/templates/tests/partials/test_cluster.zapt index 3ee6664f689166..8ae827ad9258ce 100644 --- a/examples/chip-tool/templates/tests/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/tests/partials/test_cluster.zapt @@ -290,13 +290,12 @@ class {{filename}}Suite: public TestCommand {{#if isGroupCommand}} ReturnErrorOnFailure(cluster.WriteAttribute(groupId, {{>device}}->GetSecureSession().Value()->GetFabricIndex(), {{>device}}->GetDeviceId(),{{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}} {{~> maybeTimedInteractionTimeout ~}} - {{~#if isGroupCommand}}, {{>staticDoneResponse}}{{/if~}} + , {{>staticDoneResponse}} )); {{> maybeWait }} {{else}} ReturnErrorOnFailure(cluster.WriteAttribute({{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}} {{~> maybeTimedInteractionTimeout ~}} - {{~#if isGroupCommand}}, {{>staticDoneResponse}}{{/if~}} )); {{> maybeWait }} {{/if}}