Skip to content
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

[im] Always use interaction model to send commands #5945

Merged
merged 18 commits into from
May 11, 2021
Merged
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
6,682 changes: 2,381 additions & 4,301 deletions examples/all-clusters-app/all-clusters-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

1,649 changes: 582 additions & 1,067 deletions examples/bridge-app/bridge-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions examples/chip-tool/commands/clusters/ModelCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ namespace {
constexpr uint16_t kWaitDurationInSeconds = 10;
} // namespace

void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
chip::TLV::TLVReader & aReader, Command * apCommandObj)
{
ChipLogDetail(Controller, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId,
aCommandId, aEndPointId);
ChipLogError(
Controller,
"Default DispatchSingleClusterCommand is called, this should be replaced by actual dispatched for cluster commands");
}

CHIP_ERROR ModelCommand::Run(PersistentStorage & storage, NodeId localId, NodeId remoteId)
{
CHIP_ERROR err = CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion examples/chip-tool/commands/clusters/ModelCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ModelCommand : public Command
virtual CHIP_ERROR SendCommand(ChipDevice * device, uint8_t endPointId) = 0;

private:
ChipDeviceCommissioner mCommissioner;
ChipDeviceController mCommissioner;
ChipDevice * mDevice;
chip::Controller::ExampleOperationalCredentialsIssuer mOpCredsIssuer;
uint8_t mEndPointId;
Expand Down
1 change: 1 addition & 0 deletions examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class Command
{
public:
using ChipDeviceCommissioner = ::chip::Controller::DeviceCommissioner;
using ChipDeviceController = ::chip::Controller::DeviceController;
using ChipSerializedDevice = ::chip::Controller::SerializedDevice;
using ChipDevice = ::chip::Controller::Device;
using PeerAddress = ::chip::Transport::PeerAddress;
Expand Down
177 changes: 112 additions & 65 deletions examples/chip-tool/gen/CHIPClientCallbacks.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions examples/chip-tool/gen/CHIPClientCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

#pragma once

#include <app/Command.h>
#include <app/util/af-enums.h>
#include <gen/af-structs.h>
#include <inttypes.h>
#include <lib/support/Span.h>

// Note: The IMDefaultResponseCallback is a bridge to the old CallbackMgr before IM is landed, so it still accepts EmberAfStatus
// instead of IM status code.
// #6308 should handle IM error code on the application side, either modify this function or remove this.
bool IMDefaultResponseCallback(const chip::app::Command * commandObj, EmberAfStatus status);

// Global Response Callbacks
typedef void (*DefaultSuccessCallback)(void * context);
typedef void (*DefaultFailureCallback)(void * context, uint8_t status);
Expand Down
1,379 changes: 360 additions & 1,019 deletions examples/chip-tool/gen/CHIPClusters.cpp

Large diffs are not rendered by default.

5,042 changes: 2,049 additions & 2,993 deletions examples/chip-tool/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

1,649 changes: 582 additions & 1,067 deletions examples/lighting-app/lighting-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/lighting-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ target_sources(app PRIVATE
${LIGHTING_COMMON}/gen/attribute-size.cpp
${LIGHTING_COMMON}/gen/call-command-handler.cpp
${LIGHTING_COMMON}/gen/callback-stub.cpp
${LIGHTING_COMMON}/gen/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${NRFCONNECT_COMMON}/app/Service.cpp
Expand All @@ -65,6 +66,7 @@ target_sources(app PRIVATE
${CHIP_ROOT}/src/app/util/binding-table.cpp
${CHIP_ROOT}/src/app/util/chip-message-send.cpp
${CHIP_ROOT}/src/app/util/client-api.cpp
${CHIP_ROOT}/src/app/util/ember-compatibility-functions.cpp
${CHIP_ROOT}/src/app/util/ember-print.cpp
${CHIP_ROOT}/src/app/util/message.cpp
${CHIP_ROOT}/src/app/util/process-cluster-message.cpp
Expand Down
1,068 changes: 395 additions & 673 deletions examples/lock-app/lock-common/gen/IMClusterCommandHandler.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions examples/lock-app/nrfconnect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ target_sources(app PRIVATE
${LOCK_COMMON}/gen/attribute-size.cpp
${LOCK_COMMON}/gen/call-command-handler.cpp
${LOCK_COMMON}/gen/callback-stub.cpp
${LOCK_COMMON}/gen/IMClusterCommandHandler.cpp
${NRFCONNECT_COMMON}/util/LEDWidget.cpp
${NRFCONNECT_COMMON}/util/ThreadUtil.cpp
${NRFCONNECT_COMMON}/app/Service.cpp
Expand All @@ -65,6 +66,7 @@ target_sources(app PRIVATE
${CHIP_ROOT}/src/app/util/binding-table.cpp
${CHIP_ROOT}/src/app/util/chip-message-send.cpp
${CHIP_ROOT}/src/app/util/client-api.cpp
${CHIP_ROOT}/src/app/util/ember-compatibility-functions.cpp
${CHIP_ROOT}/src/app/util/ember-print.cpp
${CHIP_ROOT}/src/app/util/message.cpp
${CHIP_ROOT}/src/app/util/process-cluster-message.cpp
Expand Down
47 changes: 47 additions & 0 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

#include "gen/CHIPClientCallbacks.h"

#include <cinttypes>

#include "gen/enums.h"
#include <app/Command.h>
#include <app/util/CHIPDeviceCallbacksMgr.h>
Expand Down Expand Up @@ -80,6 +82,28 @@ using namespace ::chip;
return true; \
}

#define GET_CLUSTER_RESPONSE_CALLBACKS(name) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be a macro?

Callback::Cancelable * onSuccessCallback = nullptr; \
Callback::Cancelable * onFailureCallback = nullptr; \
NodeId sourceIdentifier = reinterpret_cast<NodeId>(commandObj); \
/* #6559: Currently, we only have one commands for the IMInvokeCommands and to a device, so the seqNum is always set to 0. */ \
CHIP_ERROR err = gCallbacks.GetResponseCallback(sourceIdentifier, 0, &onSuccessCallback, &onFailureCallback); \
erjiaqing marked this conversation as resolved.
Show resolved Hide resolved
\
if (CHIP_NO_ERROR != err) \
{ \
if (onSuccessCallback == nullptr) \
{ \
ChipLogDetail(Zcl, "%s: Missing success callback", name); \
} \
\
if (onFailureCallback == nullptr) \
{ \
ChipLogDetail(Zcl, "%s: Missing failure callback", name); \
} \
\
return true; \
}

#define GET_REPORT_CALLBACK(name) \
Callback::Cancelable * onReportCallback = nullptr; \
CHIP_ERROR err = gCallbacks.GetReportCallback(sourceId, endpointId, clusterId, attributeId, &onReportCallback); \
Expand Down Expand Up @@ -248,6 +272,29 @@ bool emberAfDefaultResponseCallback(ClusterId clusterId, CommandId commandId, Em
return true;
}

bool IMDefaultResponseCallback(const chip::app::Command * commandObj, EmberAfStatus status)
{
ChipLogProgress(Zcl, "DefaultResponse:");
ChipLogProgress(Zcl, " Transaction: %p", commandObj);
LogStatus(status);

GET_CLUSTER_RESPONSE_CALLBACKS("emberAfDefaultResponseCallback");
if (status == EMBER_ZCL_STATUS_SUCCESS)
{
Callback::Callback<DefaultSuccessCallback> * cb =
Callback::Callback<DefaultSuccessCallback>::FromCancelable(onSuccessCallback);
cb->mCall(cb->mContext);
}
else
{
Callback::Callback<DefaultFailureCallback> * cb =
Callback::Callback<DefaultFailureCallback>::FromCancelable(onFailureCallback);
cb->mCall(cb->mContext, static_cast<uint8_t>(status));
}

return true;
}

bool emberAfReadAttributesResponseCallback(ClusterId clusterId, uint8_t * message, uint16_t messageLen)
{
ChipLogProgress(Zcl, "ReadAttributesResponse:");
Expand Down
7 changes: 7 additions & 0 deletions examples/pump-app/pump-common/gen/CHIPClientCallbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,17 @@

#pragma once

#include <app/Command.h>
#include <app/util/af-enums.h>
#include <gen/af-structs.h>
#include <inttypes.h>
#include <lib/support/Span.h>

// Note: The IMDefaultResponseCallback is a bridge to the old CallbackMgr before IM is landed, so it still accepts EmberAfStatus
// instead of IM status code.
// #6308 should handle IM error code on the application side, either modify this function or remove this.
bool IMDefaultResponseCallback(const chip::app::Command * commandObj, EmberAfStatus status);

// Global Response Callbacks
typedef void (*DefaultSuccessCallback)(void * context);
typedef void (*DefaultFailureCallback)(void * context, uint8_t status);
Expand Down
22 changes: 6 additions & 16 deletions examples/pump-app/pump-common/gen/CHIPClusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ namespace Controller {
CHIP_ERROR IdentifyCluster::Identify(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback,
uint16_t identifyTime)
{
#if CHIP_ENABLE_INTERACTION_MODEL
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
(void) onSuccessCallback;
(void) onFailureCallback;

app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kIdentifyCommandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
Expand All @@ -52,20 +49,15 @@ CHIP_ERROR IdentifyCluster::Identify(Callback::Cancelable * onSuccessCallback, C

ReturnErrorOnFailure(ZCLcommand->FinishCommand());

// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(onSuccessCallback, onFailureCallback);

return mDevice->SendCommands();
#else
uint8_t seqNum = mDevice->GetNextSequenceNumber();
System::PacketBufferHandle encodedCommand = encodeIdentifyClusterIdentifyCommand(seqNum, mEndpoint, identifyTime);
return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
#endif
}

CHIP_ERROR IdentifyCluster::IdentifyQuery(Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
{
#if CHIP_ENABLE_INTERACTION_MODEL
VerifyOrReturnError(mDevice != nullptr, CHIP_ERROR_INCORRECT_STATE);
(void) onSuccessCallback;
(void) onFailureCallback;

app::CommandPathParams cmdParams = { mEndpoint, /* group id */ 0, mClusterId, kIdentifyQueryCommandId,
(chip::app::CommandPathFlags::kEndpointIdValid) };
Expand All @@ -77,12 +69,10 @@ CHIP_ERROR IdentifyCluster::IdentifyQuery(Callback::Cancelable * onSuccessCallba

ReturnErrorOnFailure(ZCLcommand->FinishCommand());

// #6308: This is a temporary solution before we fully support IM on application side and should be replaced by IMDelegate.
mDevice->AddIMResponseHandler(onSuccessCallback, onFailureCallback);

return mDevice->SendCommands();
#else
uint8_t seqNum = mDevice->GetNextSequenceNumber();
System::PacketBufferHandle encodedCommand = encodeIdentifyClusterIdentifyQueryCommand(seqNum, mEndpoint);
return SendCommand(seqNum, std::move(encodedCommand), onSuccessCallback, onFailureCallback);
#endif
}

// Identify Cluster Attributes
Expand Down
Loading