Skip to content

Commit

Permalink
[Group] Remove AssociateWithGroup (#16583)
Browse files Browse the repository at this point in the history
* Remove AssociateWithGroup

* Fix comments
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Jan 10, 2024
1 parent 68843a4 commit 1433778
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 30 deletions.
15 changes: 10 additions & 5 deletions examples/chip-tool/templates/tests/partials/test_cluster.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand All @@ -289,11 +287,18 @@ class {{filename}}Suite: public TestCommand
{{/chip_tests_item_parameters}}

{{#if isWriteAttribute}}
{{#if isGroupCommand}}
ReturnErrorOnFailure(cluster.WriteAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>(groupId, {{>device}}->GetSecureSession().Value()->GetFabricIndex(), {{>device}}->GetDeviceId(),{{#chip_tests_item_parameters}}{{asLowerCamelCase name}}Argument, {{/chip_tests_item_parameters}}this, {{>staticSuccessResponse}}, {{>staticFailureResponse}}
{{~> maybeTimedInteractionTimeout ~}}
, {{>staticDoneResponse}}
));
{{> maybeWait }}
{{else}}
ReturnErrorOnFailure(cluster.WriteAttribute<chip::app::Clusters::{{asUpperCamelCase cluster}}::Attributes::{{asUpperCamelCase attribute}}::TypeInfo>({{#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}}
Expand Down
9 changes: 0 additions & 9 deletions src/controller/CHIPCluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
57 changes: 45 additions & 12 deletions src/controller/CHIPCluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<AttrType>(SessionHandle(groupSession), mEndpoint, clusterId, attributeId,
requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs, onDoneCb,
aDataVersion);
}

return chip::Controller::WriteAttribute<AttrType>(mDevice->GetSecureSession().Value(), mEndpoint, clusterId, attributeId,
requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs, onDoneCb,
aDataVersion);
}

template <typename AttrType>
CHIP_ERROR WriteAttribute(GroupId groupId, FabricIndex fabricIndex, NodeId sourceNodeId, const AttrType & requestData,
void * context, ClusterId clusterId, AttributeId attributeId, WriteResponseSuccessCallback successCb,
WriteResponseFailureCallback failureCb, const Optional<uint16_t> & aTimedWriteTimeoutMs,
WriteResponseDoneCallback doneCb = nullptr, const Optional<DataVersion> & 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<AttrType>(SessionHandle(groupSession), 0 /*Unused for Group*/, clusterId,
attributeId, requestData, onSuccessCb, onFailureCb, aTimedWriteTimeoutMs,
onDoneCb, aDataVersion);
}

template <typename AttributeInfo>
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<DataVersion> & aDataVersion = NullOptional,
const Optional<uint16_t> & aTimedWriteTimeoutMs = NullOptional)
{
return WriteAttribute(groupId, fabricIndex, sourceNodeId, requestData, context, AttributeInfo::GetClusterId(),
AttributeInfo::GetAttributeId(), successCb, failureCb, aTimedWriteTimeoutMs, doneCb, aDataVersion);
}

template <typename AttributeInfo>
CHIP_ERROR WriteAttribute(const typename AttributeInfo::Type & requestData, void * context,
WriteResponseSuccessCallback successCb, WriteResponseFailureCallback failureCb,
Expand Down Expand Up @@ -345,7 +379,6 @@ class DLL_EXPORT ClusterBase
const ClusterId mClusterId;
DeviceProxy * mDevice;
EndpointId mEndpoint;
Optional<GroupId> mGroupId;
Optional<System::Clock::Timeout> mTimeout;
};

Expand Down
10 changes: 6 additions & 4 deletions zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1433778

Please sign in to comment.