Skip to content

Commit

Permalink
Remove the CHIPClusters ReadAttribute* APIs. (#12652)
Browse files Browse the repository at this point in the history
They were unused except by chip-tool.  chip-tool is switched to use
the type-safe read API.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 4, 2023
1 parent ae1dd58 commit 2960745
Show file tree
Hide file tree
Showing 24 changed files with 5,928 additions and 14,793 deletions.
145 changes: 20 additions & 125 deletions examples/chip-tool/templates/commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,15 @@ CHIP_ERROR LogValue(const char * label, size_t indent, chip::CharSpan value)

CHIP_ERROR LogValue(const char * label, size_t indent, chip::ByteSpan value)
{
ChipLogProgress(chipTool, "%s%s: %zu", IndentStr(indent).c_str(), label, value.size());
char buffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
if (CHIP_NO_ERROR == chip::Encoding::BytesToUppercaseHexString(value.data(), value.size(), &buffer[0], CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE))
{
ChipLogProgress(chipTool, "%s%s: %s", IndentStr(indent).c_str(), label, buffer);
}
else
{
ChipLogProgress(chipTool, "%s%s: %zu", IndentStr(indent).c_str(), label, value.size());
}
return CHIP_NO_ERROR;
}

Expand Down Expand Up @@ -197,144 +205,56 @@ static void OnBooleanAttributeReport(void * context, bool value)
ChipLogProgress(chipTool, "Boolean attribute Response: %d", value);
}

static void OnBooleanAttributeResponse(void * context, bool value)
{
OnBooleanAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt8uAttributeReport(void * context, uint8_t value)
{
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, value);
}

static void OnInt8uAttributeResponse(void * context, uint8_t value)
{
OnInt8uAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt16uAttributeReport(void * context, uint16_t value)
{
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, value);
}

static void OnInt16uAttributeResponse(void * context, uint16_t value)
{
OnInt16uAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt32uAttributeReport(void * context, uint32_t value)
{
ChipLogProgress(chipTool, "Int32u attribute Response: %" PRIu32, value);
}

static void OnInt32uAttributeResponse(void * context, uint32_t value)
{
OnInt32uAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt64uAttributeReport(void * context, uint64_t value)
{
ChipLogProgress(chipTool, "Int64u attribute Response: %" PRIu64, value);
}

static void OnInt64uAttributeResponse(void * context, uint64_t value)
{
OnInt64uAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt8sAttributeReport(void * context, int8_t value)
{
ChipLogProgress(chipTool, "Int8s attribute Response: %" PRId8, value);
}

static void OnInt8sAttributeResponse(void * context, int8_t value)
{
OnInt8sAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt16sAttributeReport(void * context, int16_t value)
{
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, value);
}

static void OnInt16sAttributeResponse(void * context, int16_t value)
{
OnInt16sAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt32sAttributeReport(void * context, int32_t value)
{
ChipLogProgress(chipTool, "Int32s attribute Response: %" PRId32, value);
}

static void OnInt32sAttributeResponse(void * context, int32_t value)
{
OnInt32sAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnInt64sAttributeReport(void * context, int64_t value)
{
ChipLogProgress(chipTool, "Int64s attribute Response: %" PRId64, value);
}

static void OnInt64sAttributeResponse(void * context, int64_t value)
{
OnInt64sAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnFloatAttributeReport(void * context, float value)
{
ChipLogProgress(chipTool, "Float attribute Response: %f", value);
}

static void OnFloatAttributeResponse(void * context, float value)
{
OnFloatAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnDoubleAttributeReport(void * context, double value)
{
ChipLogProgress(chipTool, "Double attribute Response: %f", value);
}

static void OnDoubleAttributeResponse(void * context, double value)
{
OnDoubleAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnOctetStringAttributeReport(void * context, const chip::ByteSpan value)
{
char buffer[CHIP_CONFIG_LOG_MESSAGE_MAX_SIZE];
Expand All @@ -345,42 +265,20 @@ static void OnOctetStringAttributeReport(void * context, const chip::ByteSpan va
}
}

static void OnOctetStringAttributeResponse(void * context, const chip::ByteSpan value)
{
OnOctetStringAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

static void OnCharStringAttributeReport(void * context, const chip::CharSpan value)
{
ChipLogProgress(chipTool, "CharString attribute Response: %.*s", static_cast<int>(value.size()), value.data());
}

static void OnCharStringAttributeResponse(void * context, const chip::CharSpan value)
{
OnCharStringAttributeReport(context, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(CHIP_NO_ERROR);
}

{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#if isList}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} list)
template <typename T>
static void OnGeneralAttributeResponse(void * context, const char * label, T value)
{
CHIP_ERROR err = LogValue("On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse", 0, list);
CHIP_ERROR err = LogValue(label, 0, value);

ModelCommand * command = static_cast<ModelCommand *>(context);
auto * command = static_cast<ModelCommand *>(context);
command->SetCommandExitStatus(err);
}

{{/if}}
{{/chip_server_cluster_attributes}}
{{/chip_client_clusters}}

{{#chip_client_clusters}}
{{#chip_cluster_responses}}
static void On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}Success(void * context, const chip::app::Clusters::{{asUpperCamelCase parent.name}}::Commands::{{asUpperCamelCase name}}::DecodableType & data)
Expand Down Expand Up @@ -471,8 +369,6 @@ public:

~Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}()
{
delete onSuccessCallback;
delete onFailureCallback;
}

CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endpointId) override
Expand All @@ -481,16 +377,15 @@ public:

chip::Controller::{{asUpperCamelCase parent.name}}Cluster cluster;
cluster.Associate(device, endpointId);
return cluster.ReadAttribute{{asUpperCamelCase name}}(onSuccessCallback->Cancel(), onFailureCallback->Cancel());
return cluster.ReadAttribute<chip::app::Clusters::{{asUpperCamelCase parent.name}}::Attributes::{{asUpperCamelCase name}}::TypeInfo>(this,
OnAttributeResponse,
OnDefaultFailure);
}

private:
{{#if isList}}
chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeCallback>(On{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}ListAttributeResponse, this);
{{else}}
chip::Callback::Callback<{{chipCallback.name}}AttributeCallback> * onSuccessCallback = new chip::Callback::Callback<{{chipCallback.name}}AttributeCallback>(On{{chipCallback.name}}AttributeResponse, this);
{{/if}}
chip::Callback::Callback<DefaultFailureCallback> * onFailureCallback = new chip::Callback::Callback<DefaultFailureCallback>(OnDefaultFailureResponse, this);
static void OnAttributeResponse(void * context, {{zapTypeToDecodableClusterObjectType type ns=parent.name isArgument=true}} value)
{
OnGeneralAttributeResponse(context, "{{asUpperCamelCase parent.name}}.{{asUpperCamelCase name}} response", value);
}
};

{{#if isWritableAttribute}}
Expand Down
41 changes: 3 additions & 38 deletions examples/chip-tool/templates/reporting-commands.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma once

#include <commands/reporting/ReportingCommand.h>

#include "../cluster/Commands.h" // For the LogValue bits and read callbacks

typedef void (*UnsupportedAttributeCallback)(void * context);

Expand Down Expand Up @@ -45,49 +45,14 @@ public:
{{/chip_client_clusters}}
}

static void OnDefaultSuccessResponse(void * context)
{
ChipLogProgress(chipTool, "Default Success Response");
}

static void OnDefaultFailureResponse(void * context, uint8_t status)
{
ChipLogProgress(chipTool, "Default Failure Response: 0x%02x", status);
}

static void OnUnsupportedAttributeResponse(void * context)
{
ChipLogError(chipTool, "Unsupported attribute Response. This should never happen !");
}

static void OnBooleanAttributeResponse(void * context, bool value)
{
ChipLogProgress(chipTool, "Boolean attribute Response: %d", value);
}

static void OnInt8uAttributeResponse(void * context, uint8_t value)
{
ChipLogProgress(chipTool, "Int8u attribute Response: %" PRIu8, value);
}

static void OnInt16uAttributeResponse(void * context, uint16_t value)
{
ChipLogProgress(chipTool, "Int16u attribute Response: %" PRIu16, value);
}

static void OnInt16sAttributeResponse(void * context, int16_t value)
{
ChipLogProgress(chipTool, "Int16s attribute Response: %" PRId16, value);
}

private:
{{#chip_client_clusters}}
{{#chip_server_cluster_attributes}}
{{#if isReportableAttribute}}
{{#unless isList}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
chip::Callback::Callback<{{chipCallback.name}}AttributeCallback> * onReport{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}Callback = new chip::Callback::Callback<{{chipCallback.name}}AttributeCallback>(On{{chipCallback.name}}AttributeResponse, this);
{{/unless}}
chip::Callback::Callback<decltype(&Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}::OnAttributeResponse)> * onReport{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}Callback = new chip::Callback::Callback<decltype(&Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}::OnAttributeResponse)>(Read{{asUpperCamelCase parent.name}}{{asUpperCamelCase name}}::OnAttributeResponse, this);
{{/unless}}
{{/unless}}
{{/if}}
{{/chip_server_cluster_attributes}}
Expand Down
28 changes: 0 additions & 28 deletions src/app/DeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,34 +74,6 @@ void DeviceProxy::AddReportHandler(EndpointId endpoint, ClusterId cluster, Attri
mCallbacksMgr.AddReportCallback(GetDeviceId(), endpoint, cluster, attribute, onReportCallback, tlvDataFilter);
}

CHIP_ERROR DeviceProxy::SendReadAttributeRequest(app::AttributePathParams aPath, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, app::TLVDataFilter aTlvDataFilter)
{
VerifyOrReturnLogError(IsSecureConnected(), CHIP_ERROR_INCORRECT_STATE);

app::ReadClient * readClient = nullptr;
ReturnErrorOnFailure(chip::app::InteractionModelEngine::GetInstance()->NewReadClient(
&readClient, app::ReadClient::InteractionType::Read, &GetInteractionModelDelegate()->GetBufferedCallback()));

if (onSuccessCallback != nullptr || onFailureCallback != nullptr)
{
AddIMResponseHandler(readClient, onSuccessCallback, onFailureCallback, aTlvDataFilter);
}
// The application context is used to identify different requests from client application the type of it is intptr_t, here we
// use the seqNum.
chip::app::ReadPrepareParams readPrepareParams(GetSecureSession().Value());
readPrepareParams.mpAttributePathParamsList = &aPath;
readPrepareParams.mAttributePathParamsListSize = 1;

CHIP_ERROR err = readClient->SendReadRequest(readPrepareParams);

if (err != CHIP_NO_ERROR)
{
CancelIMResponseHandler(readClient);
}
return err;
}

CHIP_ERROR DeviceProxy::SendSubscribeAttributeRequest(app::AttributePathParams aPath, uint16_t mMinIntervalFloorSeconds,
uint16_t mMaxIntervalCeilingSeconds, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
Expand Down
3 changes: 0 additions & 3 deletions src/app/DeviceProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ class DLL_EXPORT DeviceProxy

virtual bool GetAddress(Inet::IPAddress & addr, uint16_t & port) const { return false; }

virtual CHIP_ERROR SendReadAttributeRequest(app::AttributePathParams aPath, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback, app::TLVDataFilter aTlvDataFilter);

virtual CHIP_ERROR SendSubscribeAttributeRequest(app::AttributePathParams aPath, uint16_t mMinIntervalFloorSeconds,
uint16_t mMaxIntervalCeilingSeconds, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback);
Expand Down
9 changes: 0 additions & 9 deletions src/app/zap-templates/templates/app/CHIPClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,6 @@ exit:
// {{asUpperCamelCase name}} Cluster Attributes
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
CHIP_ERROR {{asUpperCamelCase parent.name}}Cluster::ReadAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
app::AttributePathParams attributePath;
attributePath.mEndpointId = mEndpoint;
attributePath.mClusterId = mClusterId;
attributePath.mAttributeId = {{asHex code 8}};
return mDevice->SendReadAttributeRequest(attributePath, onSuccessCallback, onFailureCallback,{{#if isList}}{{asUpperCamelCase parent.name}}Cluster{{asUpperCamelCase name}}ListAttributeFilter{{else}}BasicAttributeFilter<{{chipCallback.name}}AttributeCallback>{{/if}});
}

{{#if isReportableAttribute}}
{{#unless isList}}
CHIP_ERROR {{asUpperCamelCase parent.name}}Cluster::SubscribeAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, uint16_t minInterval, uint16_t maxInterval)
Expand Down
1 change: 0 additions & 1 deletion src/app/zap-templates/templates/app/CHIPClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public:
// Cluster Attributes
{{#chip_server_cluster_attributes}}
{{#unless (isStrEqual chipCallback.name "Unsupported")}}
CHIP_ERROR ReadAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback);
{{#if isReportableAttribute}}
{{#unless isList}}
CHIP_ERROR SubscribeAttribute{{asUpperCamelCase name}}(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback, uint16_t minInterval, uint16_t maxInterval);
Expand Down
11 changes: 0 additions & 11 deletions zzz_generated/all-clusters-app/zap-generated/CHIPClusters.cpp

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

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

Loading

0 comments on commit 2960745

Please sign in to comment.