3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 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 * This file defines the chip::System::Timer class and its
22 * related types used for representing an in-progress one-shot
28 // Include configuration headers
29 #include <system/SystemConfig.h>
31 // Include dependent headers
32 #include <support/DLLUtil.h>
34 #include <system/SystemClock.h>
35 #include <system/SystemError.h>
36 #include <system/SystemObject.h>
37 #include <system/SystemStats.h>
48 * This is an internal class to CHIP System Layer, used to represent an in-progress one-shot timer. There is no real public
49 * interface available for the application layer. The static public methods used to acquire current system time are intended for
53 class DLL_EXPORT Timer : public Object
59 * Represents an epoch in the local system timescale, usually the POSIX timescale.
61 * The units are dependent on the context. If used with values returned by GetCurrentEpoch, the units are milliseconds.
63 typedef uint64_t Epoch;
65 static Epoch GetCurrentEpoch();
66 static bool IsEarlierEpoch(const Epoch & first, const Epoch & second);
68 typedef void (*OnCompleteFunct)(Layer * aLayer, void * aAppState, Error aError);
69 OnCompleteFunct OnComplete;
71 Error Start(uint32_t aDelayMilliseconds, OnCompleteFunct aOnComplete, void * aAppState);
74 static void GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark);
77 static ObjectPool<Timer, CHIP_SYSTEM_CONFIG_NUM_TIMERS> sPool;
81 void HandleComplete();
83 Error ScheduleWork(OnCompleteFunct aOnComplete, void * aAppState);
85 #if CHIP_SYSTEM_CONFIG_USE_LWIP
88 static Error HandleExpiredTimers(Layer & aLayer);
89 #endif // CHIP_SYSTEM_CONFIG_USE_LWIP
92 Timer(const Timer &) = delete;
93 Timer & operator=(const Timer &) = delete;
96 inline void Timer::GetStatistics(chip::System::Stats::count_t & aNumInUse, chip::System::Stats::count_t & aHighWatermark)
98 sPool.GetStatistics(aNumInUse, aHighWatermark);
101 } // namespace System