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 the CallbacksMgr class. The object of this
22 * class will be used by Controller applications to interact with ZCL messages.
23 * This class provide mechanism to store callbacks for global message dispatching
24 * across the ZCL stack.
29 #include "basic-types.h"
30 #include <core/CHIPCallback.h>
31 #include <core/CHIPError.h>
32 #include <support/DLLUtil.h>
37 class DLL_EXPORT CHIPDeviceCallbacksMgr
40 CHIPDeviceCallbacksMgr(const CHIPDeviceCallbacksMgr &) = delete;
41 CHIPDeviceCallbacksMgr(const CHIPDeviceCallbacksMgr &&) = delete;
42 CHIPDeviceCallbacksMgr & operator=(const CHIPDeviceCallbacksMgr &) = delete;
44 static CHIPDeviceCallbacksMgr & GetInstance()
46 static CHIPDeviceCallbacksMgr instance;
50 CHIP_ERROR AddResponseCallback(NodeId nodeId, uint8_t sequenceNumber, Callback::Cancelable * onSuccessCallback,
51 Callback::Cancelable * onFailureCallback);
52 CHIP_ERROR GetResponseCallback(NodeId nodeId, uint8_t sequenceNumber, Callback::Cancelable ** onSuccessCallback,
53 Callback::Cancelable ** onFailureCallback);
55 CHIP_ERROR AddReportCallback(NodeId nodeId, EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
56 Callback::Cancelable * onReportCallback);
57 CHIP_ERROR GetReportCallback(NodeId nodeId, EndpointId endpointId, ClusterId clusterId, AttributeId attributeId,
58 Callback::Cancelable ** onReportCallback);
61 CHIPDeviceCallbacksMgr() {}
64 CHIP_ERROR CancelCallback(T & info, Callback::CallbackDeque & queue)
66 Callback::Cancelable * ca = nullptr;
67 CHIP_ERROR err = GetCallback(info, queue, &ca);
68 if (CHIP_NO_ERROR == err)
78 CHIP_ERROR GetCallback(T & info, Callback::CallbackDeque & queue, Callback::Cancelable ** callback)
80 Callback::Cancelable * ca = &queue;
81 while (ca != nullptr && ca->mNext != &queue)
83 if (*reinterpret_cast<T *>(&ca->mNext->mInfoPtr) == info)
85 *callback = ca->mNext;
92 return CHIP_ERROR_KEY_NOT_FOUND;
95 Callback::CallbackDeque mResponsesSuccess;
96 Callback::CallbackDeque mResponsesFailure;
97 Callback::CallbackDeque mReports;