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 Linux platforms.
27 #include <platform/internal/GenericPlatformManagerImpl.h>
31 #include <sys/select.h>
40 namespace DeviceLayer {
44 * Provides a generic implementation of PlatformManager features that works on any OSAL platform.
46 * This template contains implementations of select features from the PlatformManager abstract
47 * interface that are suitable for use on OSAL-based platforms. It is intended to be inherited
48 * (directly or indirectly) by the PlatformManagerImpl class, which also appears as the template's
49 * ImplClass parameter.
51 template <class ImplClass>
52 class GenericPlatformManagerImpl_POSIX : public GenericPlatformManagerImpl<ImplClass>
55 // Members for select loop
60 struct timeval mNextTimeout;
62 // OS-specific members (pthread)
63 pthread_mutex_t mChipStackLock;
64 std::queue<ChipDeviceEvent> mChipEventQueue;
67 pthread_attr_t mChipTaskAttr;
68 struct sched_param mChipTaskSchedParam;
70 // ===== Methods that implement the PlatformManager abstract interface.
74 void _LockChipStack();
75 bool _TryLockChipStack();
76 void _UnlockChipStack();
77 void _PostEvent(const ChipDeviceEvent * event);
79 CHIP_ERROR _StartEventLoopTask();
80 CHIP_ERROR _StartChipTimer(int64_t durationMS);
81 CHIP_ERROR _Shutdown();
83 // ===== Methods available to the implementation subclass.
86 // ===== Private members for use by this class only.
88 inline ImplClass * Impl() { return static_cast<ImplClass *>(this); }
92 static void SysOnEventSignal(void * arg);
94 void ProcessDeviceEvents();
96 std::atomic<bool> mShouldRunEventLoop;
97 static void * EventLoopTaskMain(void * arg);
100 // Instruct the compiler to instantiate the template only when explicitly told to do so.
101 extern template class GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>;
103 } // namespace Internal
104 } // namespace DeviceLayer