3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2018 Nest Labs, Inc.
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 * Provides an generic implementation of PlatformManager features
22 * for use on various platforms.
28 namespace DeviceLayer {
32 * Provides a generic implementation of PlatformManager features that works on multiple platforms.
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
39 template <class ImplClass>
40 class GenericPlatformManagerImpl
43 struct AppEventHandler
45 AppEventHandler * Next;
46 PlatformManager::EventHandlerFunct Handler;
50 AppEventHandler * mAppEventHandlerList;
52 // ===== Methods that implement the PlatformManager abstract interface.
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);
61 // ===== Support methods that can be overridden by the implementation subclass.
63 void DispatchEventToSystemLayer(const ChipDeviceEvent * event);
64 void DispatchEventToDeviceLayer(const ChipDeviceEvent * event);
65 void DispatchEventToApplication(const ChipDeviceEvent * event);
66 static void HandleMessageLayerActivityChanged(bool messageLayerIsActive);
69 bool mMsgLayerWasActive;
71 ImplClass * Impl() { return static_cast<ImplClass *>(this); }
74 // Instruct the compiler to instantiate the template only when explicitly told to do so.
75 extern template class GenericPlatformManagerImpl<PlatformManagerImpl>;
77 } // namespace Internal
78 } // namespace DeviceLayer