179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#ifndef DM_TIMER_H 1779a732c7Sopenharmony_ci#define DM_TIMER_H 1879a732c7Sopenharmony_ci 1979a732c7Sopenharmony_ci#include <atomic> 2079a732c7Sopenharmony_ci#include <chrono> 2179a732c7Sopenharmony_ci#include <condition_variable> 2279a732c7Sopenharmony_ci#include <functional> 2379a732c7Sopenharmony_ci#include <map> 2479a732c7Sopenharmony_ci#include <mutex> 2579a732c7Sopenharmony_ci#include <unordered_map> 2679a732c7Sopenharmony_ci 2779a732c7Sopenharmony_ci#include "ffrt.h" 2879a732c7Sopenharmony_ci 2979a732c7Sopenharmony_cinamespace OHOS { 3079a732c7Sopenharmony_cinamespace DistributedHardware { 3179a732c7Sopenharmony_ciconstexpr const char* AUTHENTICATE_TIMEOUT_TASK = "deviceManagerTimer:authenticate"; 3279a732c7Sopenharmony_ciconstexpr const char* NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:negotiate"; 3379a732c7Sopenharmony_ciconstexpr const char* CONFIRM_TIMEOUT_TASK = "deviceManagerTimer:confirm"; 3479a732c7Sopenharmony_ciconstexpr const char* INPUT_TIMEOUT_TASK = "deviceManagerTimer:input"; 3579a732c7Sopenharmony_ciconstexpr const char* ADD_TIMEOUT_TASK = "deviceManagerTimer:add"; 3679a732c7Sopenharmony_ciconstexpr const char* WAIT_NEGOTIATE_TIMEOUT_TASK = "deviceManagerTimer:waitNegotiate"; 3779a732c7Sopenharmony_ciconstexpr const char* WAIT_REQUEST_TIMEOUT_TASK = "deviceManagerTimer:waitRequest"; 3879a732c7Sopenharmony_ciconstexpr const char* STATE_TIMER_PREFIX = "deviceManagerTimer:stateTimer_"; 3979a732c7Sopenharmony_ciconstexpr const char* AUTH_DEVICE_TIMEOUT_TASK = "deviceManagerTimer:authDevice_"; 4079a732c7Sopenharmony_ciconstexpr const char* SESSION_HEARTBEAT_TIMEOUT_TASK = "deviceManagerTimer:sessionHeartbeat"; 4179a732c7Sopenharmony_ci 4279a732c7Sopenharmony_ciusing TimerCallback = std::function<void (std::string name)>; 4379a732c7Sopenharmony_ci 4479a732c7Sopenharmony_ciclass DmTimer { 4579a732c7Sopenharmony_cipublic: 4679a732c7Sopenharmony_ci DmTimer(); 4779a732c7Sopenharmony_ci ~DmTimer(); 4879a732c7Sopenharmony_ci 4979a732c7Sopenharmony_ci /** 5079a732c7Sopenharmony_ci * @tc.name: DmTimer::StartTimer 5179a732c7Sopenharmony_ci * @tc.desc: start timer running 5279a732c7Sopenharmony_ci * @tc.type: FUNC 5379a732c7Sopenharmony_ci */ 5479a732c7Sopenharmony_ci int32_t StartTimer(std::string name, int32_t timeOut, TimerCallback callback); 5579a732c7Sopenharmony_ci 5679a732c7Sopenharmony_ci /** 5779a732c7Sopenharmony_ci * @tc.name: DmTimer::DeleteTimer 5879a732c7Sopenharmony_ci * @tc.desc: delete timer 5979a732c7Sopenharmony_ci * @tc.type: FUNC 6079a732c7Sopenharmony_ci */ 6179a732c7Sopenharmony_ci int32_t DeleteTimer(std::string timerName); 6279a732c7Sopenharmony_ci 6379a732c7Sopenharmony_ci /** 6479a732c7Sopenharmony_ci * @tc.name: DmTimer::DeleteAll 6579a732c7Sopenharmony_ci * @tc.desc: delete all timer 6679a732c7Sopenharmony_ci * @tc.type: FUNC 6779a732c7Sopenharmony_ci */ 6879a732c7Sopenharmony_ci int32_t DeleteAll(); 6979a732c7Sopenharmony_ci 7079a732c7Sopenharmony_ciprivate: 7179a732c7Sopenharmony_ci mutable std::mutex timerMutex_; 7279a732c7Sopenharmony_ci std::unordered_map<std::string, ffrt::task_handle> timerVec_ = {}; 7379a732c7Sopenharmony_ci std::shared_ptr<ffrt::queue> queue_; 7479a732c7Sopenharmony_ci}; 7579a732c7Sopenharmony_ci} 7679a732c7Sopenharmony_ci} 7779a732c7Sopenharmony_ci#endif