Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / include / platform / internal / GenericPlatformManagerImpl.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2018 Nest Labs, Inc.
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  *          Provides an generic implementation of PlatformManager features
22  *          for use on various platforms.
23  */
24
25 #pragma once
26
27 namespace chip {
28 namespace DeviceLayer {
29 namespace Internal {
30
31 /**
32  * Provides a generic implementation of PlatformManager features that works on multiple platforms.
33  *
34  * This template contains implementations of select features from the PlatformManager abstract
35  * interface that are suitable for use on all platforms.  It is intended to be inherited (directly
36  * or indirectly) by the PlatformManagerImpl class, which also appears as the template's ImplClass
37  * parameter.
38  */
39 template <class ImplClass>
40 class GenericPlatformManagerImpl
41 {
42 protected:
43     struct AppEventHandler
44     {
45         AppEventHandler * Next;
46         PlatformManager::EventHandlerFunct Handler;
47         intptr_t Arg;
48     };
49
50     AppEventHandler * mAppEventHandlerList;
51
52     // ===== Methods that implement the PlatformManager abstract interface.
53
54     CHIP_ERROR _InitChipStack();
55     CHIP_ERROR _Shutdown();
56     CHIP_ERROR _AddEventHandler(PlatformManager::EventHandlerFunct handler, intptr_t arg);
57     void _RemoveEventHandler(PlatformManager::EventHandlerFunct handler, intptr_t arg);
58     void _ScheduleWork(AsyncWorkFunct workFunct, intptr_t arg);
59     void _DispatchEvent(const ChipDeviceEvent * event);
60
61     // ===== Support methods that can be overridden by the implementation subclass.
62
63     void DispatchEventToSystemLayer(const ChipDeviceEvent * event);
64     void DispatchEventToDeviceLayer(const ChipDeviceEvent * event);
65     void DispatchEventToApplication(const ChipDeviceEvent * event);
66     static void HandleMessageLayerActivityChanged(bool messageLayerIsActive);
67
68 private:
69     bool mMsgLayerWasActive;
70
71     ImplClass * Impl() { return static_cast<ImplClass *>(this); }
72 };
73
74 // Instruct the compiler to instantiate the template only when explicitly told to do so.
75 extern template class GenericPlatformManagerImpl<PlatformManagerImpl>;
76
77 } // namespace Internal
78 } // namespace DeviceLayer
79 } // namespace chip