Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2025 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 : #pragma once
19 :
20 : #include <lib/core/CHIPError.h>
21 : #include <lib/core/CriticalFailure.h>
22 : #include <system/SystemClock.h>
23 :
24 : namespace chip {
25 :
26 : class TimerContext
27 : {
28 : public:
29 404 : virtual ~TimerContext() {}
30 : virtual void TimerFired() = 0;
31 : };
32 :
33 : /// @brief This class acts as an interface between the report scheduler and the system timer to reduce dependencies on the
34 : /// system layer.
35 : class TimerDelegate
36 : {
37 : public:
38 78 : virtual ~TimerDelegate() {}
39 : /// @brief Start a timer for a given context. The report scheduler must always cancel an existing timer for a context (using
40 : /// CancelTimer) before starting a new one for that context.
41 : /// @param context context to pass to the timer callback.
42 : /// @param aTimeout time in milliseconds before the timer expires
43 : virtual CriticalFailure StartTimer(TimerContext * context, System::Clock::Timeout aTimeout) = 0;
44 : /// @brief Cancel a timer for a given context
45 : /// @param context used to identify the timer to cancel
46 : virtual void CancelTimer(TimerContext * context) = 0;
47 : virtual bool IsTimerActive(TimerContext * context) = 0;
48 : virtual System::Clock::Timestamp GetCurrentMonotonicTimestamp() = 0;
49 : };
50 :
51 : } // namespace chip
|