Skip to content

Testing signature change for response command encode. #39110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/platform/linux/testing/CustomCSRResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ namespace app {
namespace DataModel {

template <>
CHIP_ERROR Encode(TLV::TLVWriter & writer, TLV::Tag tag, const CSRResponse::Type & responseData)
CHIP_ERROR EncodeResponseCommandPayload(DataModel::TLVWriterWithAccessingFabricIndex & writerWithFabricIndex, TLV::Tag tag,
const CSRResponse::Type & responseData)
{
TLV::TLVWriter & writer = writerWithFabricIndex;

auto tag1 = TLV::ContextTag(CSRResponse::Fields::kNOCSRElements);
auto tag2 = TLV::ContextTag(CSRResponse::Fields::kAttestationSignature);
auto & options = LinuxDeviceOptions::GetInstance().mCSRResponseOptions;
Expand Down
11 changes: 2 additions & 9 deletions src/app/CommandHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,9 @@ class CommandHandler
public:
EncodableResponseCommandPayload(const CommandData & value) : mValue(value) {}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag, [[maybe_unused]] FabricIndex aAccessingFabricIndex) const final
CHIP_ERROR EncodeTo(DataModel::TLVWriterWithAccessingFabricIndex & writer, TLV::Tag tag) const final
{
if constexpr (DataModel::IsFabricScoped<CommandData>::value)
{
return mValue.Encode(writer, tag, aAccessingFabricIndex);
}
else
{
return mValue.Encode(writer, tag);
}
return DataModel::EncodeResponseCommandPayload(writer, tag, mValue);
}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const final
Expand Down
4 changes: 3 additions & 1 deletion src/app/CommandHandlerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ CHIP_ERROR CommandHandlerImpl::TryAddResponseData(const ConcreteCommandPath & aR
accessingFabricIndex = kUndefinedFabricIndex;
}

ReturnErrorOnFailure(aEncodable.EncodeTo(*writer, TLV::ContextTag(CommandDataIB::Tag::kFields), accessingFabricIndex));
DataModel::TLVWriterWithAccessingFabricIndex responseWriter(*writer, accessingFabricIndex);

ReturnErrorOnFailure(aEncodable.EncodeTo(responseWriter, TLV::ContextTag(CommandDataIB::Tag::kFields)));
return FinishCommand(/* aEndDataStruct = */ false);
}

Expand Down
10 changes: 0 additions & 10 deletions src/app/clusters/network-commissioning/network-commissioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,6 @@ class WifiScanResponseToTLV : public chip::app::DataModel::EncodableToTLV
mStatus(status), mDebugText(debugText), mNetworks(networks)
{}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex aAccessingFabricIndex) const override
{
return EncodeTo(writer, tag);
}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override;

private:
Expand Down Expand Up @@ -219,11 +214,6 @@ class ThreadScanResponseToTLV : public chip::app::DataModel::EncodableToTLV
mStatus(status), mDebugText(debugText), mNetworks(networks)
{}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex aAccessingFabricIndex) const override
{
return EncodeTo(writer, tag);
}

CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const override;

private:
Expand Down
4 changes: 2 additions & 2 deletions src/app/data-model/EncodableToTLV.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ class EncodableToTLV
public:
virtual ~EncodableToTLV() = default;

virtual CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex aAccessingFabricIndex) const
virtual CHIP_ERROR EncodeTo(TLVWriterWithAccessingFabricIndex & writer, TLV::Tag tag) const
{
// By default, just ignore the fabric index. Implementations that care
// about it should override as needed.
return EncodeTo(writer, tag);
return EncodeTo(writer.mTLVWriter, tag);
}
virtual CHIP_ERROR EncodeTo(TLV::TLVWriter & writer, TLV::Tag tag) const = 0;
};
Expand Down
25 changes: 25 additions & 0 deletions src/app/data-model/Encode.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,31 @@ CHIP_ERROR EncodeForRead(TLV::TLVWriter & writer, TLV::Tag tag, FabricIndex acce
#pragma GCC diagnostic pop
}

// TODO: Needs better name? And should it be declared in a separate header?
struct TLVWriterWithAccessingFabricIndex
{
TLVWriterWithAccessingFabricIndex(TLV::TLVWriter & writer, FabricIndex accessingFabricIndex) :
mTLVWriter(writer), mAccessingFabricIndex(accessingFabricIndex)
{}

operator TLV::TLVWriter &() { return mTLVWriter; }

TLV::TLVWriter & mTLVWriter;
const FabricIndex mAccessingFabricIndex;
};

/**
* @brief
*
* Encodes a response command payload. This is a templated function to allow
* specializations to be created as needed to customize the behavior.
*/
template <typename PayloadType>
CHIP_ERROR EncodeResponseCommandPayload(TLVWriterWithAccessingFabricIndex & writer, TLV::Tag tag, const PayloadType & payload)
{
return payload.Encode(writer, tag);
}

} // namespace DataModel
} // namespace app
} // namespace chip
11 changes: 4 additions & 7 deletions src/app/zap-templates/templates/app/clusters-Commands.h.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/Nullable.h>
#include <app/data-model/NullObject.h>
Expand Down Expand Up @@ -66,14 +67,10 @@ public:
{{/zcl_command_arguments}}


{{#if isFabricScoped~}}
{{#if (isServer source)}}
CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const;
{{else}}
{{#if (isClient source)}}
CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;
{{/if}}
{{else}}
CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;
CHIP_ERROR Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const;
{{/if}}

using ResponseType =
Expand All @@ -96,8 +93,8 @@ public:
{{zapTypeToDecodableClusterObjectType type cluster=../../name}} {{asLowerCamelCase label}}{{> cluster_objects_field_init cluster=../../name}};
{{/zcl_command_arguments}}

{{#if isFabricScoped~}}
{{#if (isClient source)}}
{{#if isFabricScoped~}}
CHIP_ERROR Decode(TLV::TLVReader &reader, FabricIndex aAccessingFabricIndex);
{{else}}
CHIP_ERROR Decode(TLV::TLVReader &reader);
Expand Down
12 changes: 4 additions & 8 deletions src/app/zap-templates/templates/app/clusters-Commands.ipp.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@ namespace Commands {
{{#zcl_commands}}
namespace {{asUpperCamelCase name}} {

{{#if isFabricScoped~}}
{{#if (isServer source)}}
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const {
{{else}}
{{#if (isClient source)}}
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const {
{{/if}}
{{else}}
CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const {
CHIP_ERROR Type::Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const {
{{/if}}
DataModel::WrappedStructEncoder encoder{aWriter, aTag};
{{#zcl_command_arguments~}}
Expand All @@ -31,7 +27,7 @@ CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const {
{{#if (isClient parent.source)}}
encoder.EncodeRequestCommandFabricScopedStructField(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}});
{{else}}
encoder.EncodeResponseCommandFabricScopedStructField(to_underlying(Fields::k{{asUpperCamelCase label}}), aAccessingFabricIndex, {{asLowerCamelCase label}});
encoder.EncodeResponseCommandFabricScopedStructField(to_underlying(Fields::k{{asUpperCamelCase label}}), aWriter.mAccessingFabricIndex, {{asLowerCamelCase label}});
{{/if}}
{{else}}
encoder.Encode(to_underlying(Fields::k{{asUpperCamelCase label}}), {{asLowerCamelCase label}});
Expand All @@ -41,8 +37,8 @@ CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const {
return encoder.Finalize();
}

{{#if isFabricScoped~}}
{{#if (isClient source)}}
{{#if isFabricScoped~}}
CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader, FabricIndex aAccessingFabricIndex) {
{{else}}
CHIP_ERROR DecodableType::Decode(TLV::TLVReader &reader) {
Expand Down
3 changes: 2 additions & 1 deletion zzz_generated/app-common/clusters/AccessControl/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down Expand Up @@ -110,7 +111,7 @@ struct Type

uint64_t token = static_cast<uint64_t>(0);

CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;
CHIP_ERROR Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const;

using ResponseType = DataModel::NullObjectType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader, FabricIndex aAccessing
} // namespace ReviewFabricRestrictions.
namespace ReviewFabricRestrictionsResponse {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
CHIP_ERROR Type::Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const
{
DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
encoder.Encode(to_underlying(Fields::kToken), token);
Expand Down
3 changes: 2 additions & 1 deletion zzz_generated/app-common/clusters/AccountLogin/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down Expand Up @@ -120,7 +121,7 @@ struct Type

chip::CharSpan setupPIN;

CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const;
CHIP_ERROR Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const;

using ResponseType = DataModel::NullObjectType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader, FabricIndex aAccessing
} // namespace GetSetupPIN.
namespace GetSetupPINResponse {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag, FabricIndex aAccessingFabricIndex) const
CHIP_ERROR Type::Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const
{
DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
encoder.Encode(to_underlying(Fields::kSetupPIN), setupPIN);
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/app-common/clusters/Actions/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/app-common/clusters/AirQuality/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down Expand Up @@ -195,7 +196,7 @@ struct Type
StatusEnum status = static_cast<StatusEnum>(0);
Optional<chip::ByteSpan> data;

CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;
CHIP_ERROR Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const;

using ResponseType = DataModel::NullObjectType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ CHIP_ERROR DecodableType::Decode(TLV::TLVReader & reader)
} // namespace HideApp.
namespace LauncherResponse {

CHIP_ERROR Type::Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const
CHIP_ERROR Type::Encode(DataModel::TLVWriterWithAccessingFabricIndex & aWriter, TLV::Tag aTag) const
{
DataModel::WrappedStructEncoder encoder{ aWriter, aTag };
encoder.Encode(to_underlying(Fields::kStatus), status);
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/app-common/clusters/AudioOutput/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/app-common/clusters/Binding/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
1 change: 1 addition & 0 deletions zzz_generated/app-common/clusters/BooleanState/Commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#pragma once

#include <app/data-model/DecodableList.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h>
#include <app/data-model/NullObject.h>
#include <app/data-model/Nullable.h>
Expand Down
Loading
Loading