Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / controller / CHIPCluster.cpp
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    All rights reserved.
5  *
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
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 /**
20  *  @file
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
24  *    the CHIP device.
25  */
26
27 #include <controller/CHIPCluster.h>
28
29 namespace chip {
30 namespace Controller {
31
32 CHIP_ERROR ClusterBase::Associate(Device * device, EndpointId endpoint)
33 {
34     CHIP_ERROR err = CHIP_NO_ERROR;
35     // TODO: Check if the device supports mCluster at the requested endpoint
36
37     mDevice   = device;
38     mEndpoint = endpoint;
39     return err;
40 }
41
42 void ClusterBase::Dissociate()
43 {
44     mDevice = nullptr;
45 }
46
47 CHIP_ERROR ClusterBase::SendCommand(uint8_t seqNum, chip::System::PacketBufferHandle payload,
48                                     Callback::Cancelable * onSuccessCallback, Callback::Cancelable * onFailureCallback)
49 {
50     CHIP_ERROR err = CHIP_NO_ERROR;
51
52     VerifyOrExit(mDevice != nullptr, err = CHIP_ERROR_INCORRECT_STATE);
53     VerifyOrExit(!payload.IsNull(), err = CHIP_ERROR_INTERNAL);
54
55     err = mDevice->SendMessage(std::move(payload));
56     SuccessOrExit(err);
57
58     if (onSuccessCallback != nullptr || onFailureCallback != nullptr)
59     {
60         mDevice->AddResponseHandler(seqNum, onSuccessCallback, onFailureCallback);
61     }
62
63 exit:
64     if (err != CHIP_NO_ERROR)
65     {
66         ChipLogError(Controller, "Failed in sending cluster command. Err %d", err);
67     }
68
69     return err;
70 }
71
72 CHIP_ERROR ClusterBase::RequestAttributeReporting(AttributeId attributeId, Callback::Cancelable * onReportCallback)
73 {
74     CHIP_ERROR err = CHIP_NO_ERROR;
75
76     VerifyOrExit(onReportCallback != nullptr, err = CHIP_ERROR_INVALID_ARGUMENT);
77     mDevice->AddReportHandler(mEndpoint, mClusterId, attributeId, onReportCallback);
78
79 exit:
80     return err;
81 }
82
83 } // namespace Controller
84 } // namespace chip