Skip to content

Commit

Permalink
Remove now-unused old-style subscribe/report functionality. (#13041)
Browse files Browse the repository at this point in the history
Specific things being removed:

1) The "reporting" commands in chip-tool.  Subscribing to an attribute
and receiving reports (which is what these commands used to do) can be
done via "chip-tool clusterName report attributeName" with the
appropriate arguments.  This method supports all types, unlike the
"reporting" commands.

2) The generated CHIPClusters code for setting up subscriptions and
getting reports.  This has no consumers (even the chip-tool code being
removed in item 1 does not use it).

3) The reporting bits in DeviceProxy and callbacks manager, which are
unused after items 1 and 2 are removed, along with the tests for that
functionality.

4) The ReadClient::Callback implementation in
DeviceControllerInteractionModelDelegate, which becomes unused, and
the CHIPConfig bits for it.

5) The im-client-callbacks bits that then become unused.

6) The Python bits that overrode the read stuff from
DeviceControllerInteractionModelDelegate.  Clearly unused, since it's
no longer a ReadClient::Callback and it all compiles, so nothing was
using that delegate to interact with ReadClients.

7) zzz_generated/controller-clusters/zap-generated/tests/CHIPClustersTest.cpp
which is only there because of a bad merge.  Not strictly related to
this PR, but I noticed it when looking through what else becomes
removable with the above removals.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Dec 17, 2021
1 parent 86ae652 commit 34a46d6
Show file tree
Hide file tree
Showing 41 changed files with 1,311 additions and 20,414 deletions.
1 change: 0 additions & 1 deletion examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ executable("chip-tool") {
"commands/pairing/PairingCommand.cpp",
"commands/payload/AdditionalDataParseCommand.cpp",
"commands/payload/SetupPayloadParseCommand.cpp",
"commands/reporting/ReportingCommand.cpp",
"commands/tests/TestCommand.cpp",
"config/PersistentStorage.cpp",
"main.cpp",
Expand Down
65 changes: 0 additions & 65 deletions examples/chip-tool/commands/reporting/ReportingCommand.cpp

This file was deleted.

50 changes: 0 additions & 50 deletions examples/chip-tool/commands/reporting/ReportingCommand.h

This file was deleted.

2 changes: 0 additions & 2 deletions examples/chip-tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "commands/payload/Commands.h"

#include <zap-generated/cluster/Commands.h>
#include <zap-generated/reporting/Commands.h>
#include <zap-generated/test/Commands.h>

// ================================================================================
Expand All @@ -35,7 +34,6 @@ int main(int argc, char * argv[])
registerCommandsDiscover(commands);
registerCommandsPayload(commands);
registerCommandsPairing(commands);
registerCommandsReporting(commands);
registerCommandsTests(commands);
registerClusters(commands);

Expand Down
71 changes: 0 additions & 71 deletions examples/chip-tool/templates/reporting-commands.zapt

This file was deleted.

5 changes: 0 additions & 5 deletions examples/chip-tool/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
"name": "Cluster Commands header",
"output": "cluster/Commands.h"
},
{
"path": "reporting-commands.zapt",
"name": "Reporting Commands header",
"output": "reporting/Commands.h"
},
{
"path": "tests-commands.zapt",
"name": "Tests Commands header",
Expand Down
84 changes: 2 additions & 82 deletions src/app/DeviceControllerInteractionModelDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ namespace Controller {
*
* TODO:(#8967) Implementation of CommandSender::Callback should be removed after switching to ClusterObjects.
*/
class DeviceControllerInteractionModelDelegate : public chip::app::ReadClient::Callback,
public chip::app::CommandSender::Callback,
class DeviceControllerInteractionModelDelegate : public chip::app::CommandSender::Callback,
public chip::app::WriteClient::Callback,
public chip::app::InteractionModelDelegate
{
public:
DeviceControllerInteractionModelDelegate() : mBufferedReadAdapter(*this) {}

app::BufferedReadCallback & GetBufferedCallback() { return mBufferedReadAdapter; }
DeviceControllerInteractionModelDelegate() {}

void OnResponse(app::CommandSender * apCommandSender, const app::ConcreteCommandPath & aPath,
const chip::app::StatusIB & aStatus, TLV::TLVReader * aData) override
Expand Down Expand Up @@ -72,83 +69,6 @@ class DeviceControllerInteractionModelDelegate : public chip::app::ReadClient::C
}

void OnDone(app::WriteClient * apWriteClient) override {}

void OnEventData(const app::ReadClient * apReadClient, const app::EventHeader & aEventHeader, TLV::TLVReader * apData,
const app::StatusIB * apStatus) override
{}

void OnAttributeData(const app::ReadClient * apReadClient, const app::ConcreteDataAttributePath & aPath,
TLV::TLVReader * apData, const app::StatusIB & aStatus) override
{
//
// We shouldn't be getting list item operations in the provided path since that should be handled by the buffered read
// callback. If we do, that's a bug.
//
VerifyOrDie(!aPath.IsListItemOperation());

IMReadReportAttributesResponseCallback(apReadClient, &aPath, apData, aStatus.mStatus);
}

void OnSubscriptionEstablished(const app::ReadClient * apReadClient) override
{
IMSubscribeResponseCallback(apReadClient, EMBER_ZCL_STATUS_SUCCESS);
}

void OnError(const app::ReadClient * apReadClient, CHIP_ERROR aError) override
{
app::ClusterInfo path;
path.mNodeId = apReadClient->GetPeerNodeId();
IMReadReportAttributesResponseCallback(apReadClient, nullptr, nullptr, Protocols::InteractionModel::Status::Failure);
}

void OnDone(app::ReadClient * apReadClient) override
{
if (apReadClient->IsSubscriptionType())
{
this->FreeAttributePathParam(reinterpret_cast<uint64_t>(apReadClient));
}
}

// TODO: FreeAttributePathParam and AllocateAttributePathParam are used by CHIPDevice.cpp for getting a long-live attribute path
// object.
void FreeAttributePathParam(uint64_t applicationId)
{
for (auto & item : mAttributePathTransactionMapPool)
{
if (item.ApplicationId == applicationId)
{
item.ApplicationId = UINT64_MAX;
}
}
}

// TODO: We only support allocating one path, should support multiple path later.
app::AttributePathParams * AllocateAttributePathParam(size_t n, uint64_t applicationId)
{
if (n > 1)
{
return nullptr;
}
for (auto & item : mAttributePathTransactionMapPool)
{
if (item.ApplicationId == UINT64_MAX)
{
item.ApplicationId = applicationId;
return &item.Params;
}
}
return nullptr;
}

private:
struct AttributePathTransactionMap
{
uint64_t ApplicationId = UINT64_MAX;
app::AttributePathParams Params;
};

app::BufferedReadCallback mBufferedReadAdapter;
AttributePathTransactionMap mAttributePathTransactionMapPool[CHIP_DEVICE_CONTROLLER_SUBSCRIPTION_ATTRIBUTE_PATH_POOL_SIZE];
};

} // namespace Controller
Expand Down
49 changes: 0 additions & 49 deletions src/app/DeviceProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,55 +68,6 @@ void DeviceProxy::CancelIMResponseHandler(void * commandObj)
mCallbacksMgr.CancelResponseCallback(transactionId, 0 /* seqNum, always 0 for IM before #6559 */);
}

void DeviceProxy::AddReportHandler(EndpointId endpoint, ClusterId cluster, AttributeId attribute,
Callback::Cancelable * onReportCallback, app::TLVDataFilter tlvDataFilter)
{
mCallbacksMgr.AddReportCallback(GetDeviceId(), endpoint, cluster, attribute, onReportCallback, tlvDataFilter);
}

CHIP_ERROR DeviceProxy::SendSubscribeAttributeRequest(app::AttributePathParams aPath, uint16_t mMinIntervalFloorSeconds,
uint16_t mMaxIntervalCeilingSeconds, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
VerifyOrReturnLogError(IsSecureConnected(), CHIP_ERROR_INCORRECT_STATE);

uint8_t seqNum = GetNextSequenceNumber();

app::AttributePathParams * path = GetInteractionModelDelegate()->AllocateAttributePathParam(1, seqNum);

VerifyOrReturnError(path != nullptr, CHIP_ERROR_NO_MEMORY);

*path = aPath;

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

// The application context is used to identify different requests from client application the type of it is intptr_t, here we
// use the seqNum.
VerifyOrReturnError(GetSecureSession().HasValue(), CHIP_ERROR_INCORRECT_STATE);
app::ReadPrepareParams params(GetSecureSession().Value());
params.mpAttributePathParamsList = path;
params.mAttributePathParamsListSize = 1;
params.mMinIntervalFloorSeconds = mMinIntervalFloorSeconds;
params.mMaxIntervalCeilingSeconds = mMaxIntervalCeilingSeconds;
params.mKeepSubscriptions = false;

CHIP_ERROR err = readClient->SendRequest(params);
if (err != CHIP_NO_ERROR)
{
GetInteractionModelDelegate()->FreeAttributePathParam(reinterpret_cast<uint64_t>(readClient));
readClient->Shutdown();
return err;
}

if (onSuccessCallback != nullptr || onFailureCallback != nullptr)
{
AddIMResponseHandler(readClient, onSuccessCallback, onFailureCallback);
}
return CHIP_NO_ERROR;
}

CHIP_ERROR DeviceProxy::SendWriteAttributeRequest(app::WriteClientHandle aHandle, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
{
Expand Down
Loading

0 comments on commit 34a46d6

Please sign in to comment.