Skip to content

Commit

Permalink
Convert CreateBindingWithCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
vivien-apple committed Jan 28, 2022
1 parent 3ef70a0 commit 8447bc5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
18 changes: 6 additions & 12 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ CHIP_ERROR ShutdownCommissioner()
class PairingCommand : public Controller::DevicePairingDelegate, public Controller::DeviceAddressUpdateDelegate
{
public:
PairingCommand() : mSuccessCallback(OnSuccessResponse, this), mFailureCallback(OnFailureResponse, this){};
PairingCommand(){};

/////////// DevicePairingDelegate Interface /////////
void OnStatusUpdate(Controller::DevicePairingDelegate::Status status) override;
Expand All @@ -337,12 +337,9 @@ class PairingCommand : public Controller::DevicePairingDelegate, public Controll
CHIP_ERROR UpdateNetworkAddress();

/* Callback when command results in success */
static void OnSuccessResponse(void * context);
static void OnSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &);
/* Callback when command results in failure */
static void OnFailureResponse(void * context, uint8_t status);

Callback::Callback<DefaultSuccessCallback> mSuccessCallback;
Callback::Callback<DefaultFailureCallback> mFailureCallback;
static void OnFailureResponse(void * context, CHIP_ERROR error);
};

PairingCommand gPairingCommand;
Expand Down Expand Up @@ -401,12 +398,12 @@ void PairingCommand::OnPairingDeleted(CHIP_ERROR err)
}
}

void PairingCommand::OnSuccessResponse(void * context)
void PairingCommand::OnSuccessResponse(void * context, const chip::app::DataModel::NullObjectType &)
{
ChipLogProgress(Controller, "OnSuccessResponse");
}

void PairingCommand::OnFailureResponse(void * context, uint8_t status)
void PairingCommand::OnFailureResponse(void * context, CHIP_ERROR error)
{
ChipLogProgress(Controller, "OnFailureResponse");
}
Expand All @@ -423,15 +420,12 @@ void PairingCommand::OnCommissioningComplete(NodeId nodeId, CHIP_ERROR err)
// - the cluster(s) chosen should come from the App Platform
constexpr EndpointId kBindingClusterEndpoint = 0;

Callback::Cancelable * successCallback = mSuccessCallback.Cancel();
Callback::Cancelable * failureCallback = mFailureCallback.Cancel();

GroupId groupId = kUndefinedGroupId;
EndpointId endpointId = 1;
ClusterId clusterId = kInvalidClusterId;

gCommissioner.CreateBindingWithCallback(nodeId, kBindingClusterEndpoint, gLocalId, groupId, endpointId, clusterId,
successCallback, failureCallback);
OnSuccessResponse, OnFailureResponse);
}
else
{
Expand Down
12 changes: 8 additions & 4 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ CHIP_ERROR DeviceController::OpenCommissioningWindowInternal()
CHIP_ERROR DeviceController::CreateBindingWithCallback(chip::NodeId deviceId, chip::EndpointId deviceEndpointId,
chip::NodeId bindingNodeId, chip::GroupId bindingGroupId,
chip::EndpointId bindingEndpointId, chip::ClusterId bindingClusterId,
Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback)
CommandResponseSuccessCallback<app::DataModel::NullObjectType> successCb,
CommandResponseFailureCallback failureCb)
{
PeerId peerId;
peerId.SetNodeId(deviceId);
Expand All @@ -578,8 +578,12 @@ CHIP_ERROR DeviceController::CreateBindingWithCallback(chip::NodeId deviceId, ch
chip::Controller::BindingCluster cluster;
cluster.Associate(device, deviceEndpointId);

ReturnErrorOnFailure(
cluster.Bind(onSuccessCallback, onFailureCallback, bindingNodeId, bindingGroupId, bindingEndpointId, bindingClusterId));
Binding::Commands::Bind::Type request;
request.nodeId = bindingNodeId;
request.groupId = bindingGroupId;
request.endpointId = bindingEndpointId;
request.clusterId = bindingClusterId;
ReturnErrorOnFailure(cluster.InvokeCommand(request, this, successCb, failureCb));

ChipLogDetail(Controller, "Sent Bind command request, waiting for response");
return CHIP_NO_ERROR;
Expand Down
10 changes: 5 additions & 5 deletions src/controller/CHIPDeviceController.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <app/InteractionModelDelegate.h>
#include <app/OperationalDeviceProxy.h>
#include <app/OperationalDeviceProxyPool.h>
#include <controller-clusters/zap-generated/CHIPClientCallbacks.h>
#include <controller/AbstractDnssdDiscoveryController.h>
#include <controller/AutoCommissioner.h>
#include <controller/CHIPCluster.h>
Expand Down Expand Up @@ -321,10 +320,11 @@ class DLL_EXPORT DeviceController : public SessionRecoveryDelegate,
*
* @return CHIP_ERROR CHIP_NO_ERROR on success, or corresponding error
*/
CHIP_ERROR CreateBindingWithCallback(chip::NodeId deviceId, chip::EndpointId deviceEndpointId, chip::NodeId bindingNodeId,
chip::GroupId bindingGroupId, chip::EndpointId bindingEndpointId,
chip::ClusterId bindingClusterId, Callback::Cancelable * onSuccessCallback,
Callback::Cancelable * onFailureCallback);
CHIP_ERROR
CreateBindingWithCallback(chip::NodeId deviceId, chip::EndpointId deviceEndpointId, chip::NodeId bindingNodeId,
chip::GroupId bindingGroupId, chip::EndpointId bindingEndpointId, chip::ClusterId bindingClusterId,
CommandResponseSuccessCallback<app::DataModel::NullObjectType> successCb,
CommandResponseFailureCallback failureCb);

#if CHIP_DEVICE_CONFIG_ENABLE_DNSSD
void RegisterDeviceAddressUpdateDelegate(DeviceAddressUpdateDelegate * delegate) { mDeviceAddressUpdateDelegate = delegate; }
Expand Down

0 comments on commit 8447bc5

Please sign in to comment.