180922886Sopenharmony_ci/* 280922886Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 380922886Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 480922886Sopenharmony_ci * you may not use this file except in compliance with the License. 580922886Sopenharmony_ci * You may obtain a copy of the License at 680922886Sopenharmony_ci * 780922886Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 880922886Sopenharmony_ci * 980922886Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1080922886Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1180922886Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1280922886Sopenharmony_ci * See the License for the specific language governing permissions and 1380922886Sopenharmony_ci * limitations under the License. 1480922886Sopenharmony_ci */ 1580922886Sopenharmony_ci 1680922886Sopenharmony_ci#ifndef OHOS_COMMAND_SEND_LIMIT_H 1780922886Sopenharmony_ci#define OHOS_COMMAND_SEND_LIMIT_H 1880922886Sopenharmony_ci 1980922886Sopenharmony_ci#include <string> 2080922886Sopenharmony_ci#include <memory> 2180922886Sopenharmony_ci#include <mutex> 2280922886Sopenharmony_ci#include <functional> 2380922886Sopenharmony_ci#include "timer.h" 2480922886Sopenharmony_ci 2580922886Sopenharmony_cinamespace OHOS::AVSession { 2680922886Sopenharmony_ciclass CommandSendLimit : public std::enable_shared_from_this<CommandSendLimit> { 2780922886Sopenharmony_cipublic: 2880922886Sopenharmony_ci static CommandSendLimit& GetInstance(); 2980922886Sopenharmony_ci 3080922886Sopenharmony_ci CommandSendLimit(); 3180922886Sopenharmony_ci ~CommandSendLimit(); 3280922886Sopenharmony_ci 3380922886Sopenharmony_ci bool IsCommandSendEnable(pid_t pid); 3480922886Sopenharmony_ci void StartTimer(); 3580922886Sopenharmony_ci void StopTimer(); 3680922886Sopenharmony_ciprivate: 3780922886Sopenharmony_ci std::recursive_mutex commandLimitLock_; 3880922886Sopenharmony_ci void ClearCommandLimits(); 3980922886Sopenharmony_ci static std::shared_ptr<CommandSendLimit> instance_; 4080922886Sopenharmony_ci static std::once_flag onceFlag_; 4180922886Sopenharmony_ci std::map<pid_t, int32_t> commandLimits_; 4280922886Sopenharmony_ci std::unique_ptr<Utils::Timer> timer_; 4380922886Sopenharmony_ci uint32_t timerId_ = 0; 4480922886Sopenharmony_ci static constexpr int32_t COMMAND_SEND_NUM_MAX = 10; 4580922886Sopenharmony_ci static constexpr int32_t COMMAND_SEND_TIME = 1000; 4680922886Sopenharmony_ci}; 4780922886Sopenharmony_ci} // namespace OHOS::AVSession 4880922886Sopenharmony_ci#endif // OHOS_COMMAND_SEND_LIMIT_H