3 * Copyright (c) 2020 Project CHIP Authors
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file contains definitions for a base Cluster class. This class will
22 * be derived by various ZCL clusters supported by CHIP. The objects of the
23 * ZCL cluster class will be used by Controller applications to interact with
27 #include <controller/CHIPCluster.h>
30 namespace Controller {
32 CHIP_ERROR ClusterBase::Associate(Device * device, EndpointId endpoint)
34 CHIP_ERROR err = CHIP_NO_ERROR;
35 // TODO: Check if the device supports mCluster at the requested endpoint
42 void ClusterBase::Dissociate()
47 CHIP_ERROR ClusterBase::SendCommand(uint8_t seqNum, chip::System::PacketBufferHandle payload,
48 Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
50 CHIP_ERROR err = CHIP_NO_ERROR;
52 VerifyOrExit(mDevice != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
53 VerifyOrExit(!payload.IsNull(), err = CHIP_ERROR_INTERNAL);
55 err = mDevice->SendMessage(std::move(payload));
58 if (onSuccessCallback != nullptr || onFailureCallback != nullptr)
60 mDevice->AddResponseHandler(seqNum, onSuccessCallback, onFailureCallback);
64 if (err != CHIP_NO_ERROR)
66 ChipLogError(Controller, "Failed in sending cluster command. Err %d", err);
72 CHIP_ERROR ClusterBase::RequestAttributeReporting(AttributeId attributeId, Callback::Cancelable * onReportCallback)
74 CHIP_ERROR err = CHIP_NO_ERROR;
76 VerifyOrExit(onReportCallback != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
77 mDevice->AddReportHandler(mEndpoint, mClusterId, attributeId, onReportCallback);
83 } // namespace Controller