1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef TIMER_MANAGER_H 17#define TIMER_MANAGER_H 18 19#include <atomic> 20#include <functional> 21#include <memory> 22#include <mutex> 23 24#include <singleton.h> 25 26namespace OHOS { 27namespace MMI { 28class TimerManager final { 29public: 30 static std::shared_ptr<TimerManager> GetInstance(); 31 32 TimerManager() = default; 33 ~TimerManager() = default; 34 DISALLOW_COPY_AND_MOVE(TimerManager); 35 36 int32_t AddTimer(int32_t intervalMs, int32_t repeatCount, std::function<void()> callback); 37 int32_t RemoveTimer(int32_t timerId); 38 int32_t ResetTimer(int32_t timerId); 39 40private: 41 std::atomic_bool running_; 42 static std::mutex mutex_; 43 static std::shared_ptr<TimerManager> instance_; 44}; 45 46#define TimerMgr TimerManager::GetInstance() 47} // namespace MMI 48} // namespace OHOS 49#endif // TIMER_MANAGER_H