Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / all-clusters-app / esp32 / main / include / CHIPDeviceManager.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *
5  *    Licensed under the Apache License, Version 2.0 (the "License");
6  *    you may not use this file except in compliance with the License.
7  *    You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *    Unless required by applicable law or agreed to in writing, software
12  *    distributed under the License is distributed on an "AS IS" BASIS,
13  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *    See the License for the specific language governing permissions and
15  *    limitations under the License.
16  */
17
18 /**
19  *    @file
20  *      This file contains definitions for the CHIP DeviceManager Interface
21  *
22  *      This object will co-ordinate multiple activities such as
23  *      initialisation, rendezvous, session mgmt and other such
24  *      activities within the CHIP stack. This is a singleton object.
25  */
26
27 #pragma once
28
29 #include <core/CHIPCore.h>
30 #include <core/CHIPError.h>
31 #include <platform/CHIPDeviceLayer.h>
32
33 #include <support/DLLUtil.h>
34
35 #include <stdarg.h>
36 #include <stdlib.h>
37
38 #include "af-types.h"
39
40 namespace chip {
41 namespace DeviceManager {
42
43 /**
44  * @brief
45  *   This class provides a skeleton for all the callback functions. The functions will be
46  *   called by other objects within the CHIP stack for specific events.
47  *   Applications interested in receiving specific callbacks can specialize this class and handle
48  *   these events in their implementation of this class.
49  */
50 class DLL_EXPORT CHIPDeviceManagerCallbacks
51 {
52 public:
53     /**
54      * @brief
55      *   Called when CHIP Device events (PublicEventTypes) are triggered.
56      *
57      * @param event   ChipDeviceEvent that occurred
58      * @param arg     arguments specific to the event, if any
59      */
60     virtual void DeviceEventCallback(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
61
62     /**
63      * @brief
64      *   Called after an attribute has been changed
65      *
66      * @param endpoint           endpoint id
67      * @param clusterID          cluster id
68      * @param attributeId        attribute id that was changed
69      * @param mask               mask of the attribute
70      * @param manufacturerCode   manufacturer code
71      * @param type               attribute type
72      * @param size               size of the attribute
73      * @param value              pointer to the new value
74      */
75     virtual void PostAttributeChangeCallback(chip::EndpointId endpoint, chip::ClusterId clusterId, chip::AttributeId attributeId,
76                                              uint8_t mask, uint16_t manufacturerCode, uint8_t type, uint8_t size, uint8_t * value)
77     {}
78     virtual ~CHIPDeviceManagerCallbacks() {}
79 };
80
81 /**
82  * @brief
83  *   A common class that drives other components of the CHIP stack
84  */
85 class DLL_EXPORT CHIPDeviceManager
86 {
87 public:
88     CHIPDeviceManager(const CHIPDeviceManager &)  = delete;
89     CHIPDeviceManager(const CHIPDeviceManager &&) = delete;
90     CHIPDeviceManager & operator=(const CHIPDeviceManager &) = delete;
91
92     static CHIPDeviceManager & GetInstance()
93     {
94         static CHIPDeviceManager instance;
95         return instance;
96     }
97
98     /**
99      * @brief
100      *   Initialise CHIPDeviceManager
101      *
102      * @param cb Application's instance of the CHIPDeviceManagerCallbacks for consuming events
103      */
104     CHIP_ERROR Init(CHIPDeviceManagerCallbacks * cb);
105
106     /**
107      * @brief
108      *   Fetch a pointer to the registered CHIPDeviceManagerCallbacks object.
109      *
110      */
111     CHIPDeviceManagerCallbacks * GetCHIPDeviceManagerCallbacks() { return mCB; }
112
113     /**
114      * Use internally for registration of the ChipDeviceEvents
115      */
116     static void CommonDeviceEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);
117
118 private:
119     CHIPDeviceManagerCallbacks * mCB = nullptr;
120     CHIPDeviceManager() {}
121 };
122
123 } // namespace DeviceManager
124 } // namespace chip