1/* 2 * Copyright (c) 2022 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#include "avsession_event_handler.h" 17#include "avsession_log.h" 18 19namespace OHOS::AVSession { 20AVSessionEventHandler &AVSessionEventHandler::GetInstance() 21{ 22 static AVSessionEventHandler avSessionEventHandler; 23 return avSessionEventHandler; 24} 25 26AVSessionEventHandler::AVSessionEventHandler() 27{ 28 SLOGI("construct"); 29} 30 31AVSessionEventHandler::~AVSessionEventHandler() 32{ 33 SLOGI("destroy"); 34} 35 36bool AVSessionEventHandler::AVSessionPostTask(const Callback &callback, const std::string &name, int64_t delayTime) 37{ 38 SLOGI("AVSessionEventHandler ProxyPostTask: %{public}s", name.c_str()); 39 std::lock_guard<std::mutex> lockGuard(handlerLock_); 40 if (!handler_) { 41 SLOGI("AVSessionEventHandler create new: %{public}s", name.c_str()); 42 auto runner = AppExecFwk::EventRunner::Create("OS_AVSessionHdl"); 43 handler_ = std::make_shared<AppExecFwk::EventHandler>(runner); 44 } 45 return handler_->PostTask(callback, name, delayTime); 46} 47 48void AVSessionEventHandler::AVSessionRemoveTask(const std::string &name) 49{ 50 SLOGI("AVSessionEventHandler ProxyRemoveTask"); 51 std::lock_guard<std::mutex> lockGuard(handlerLock_); 52 if (handler_) { 53 handler_->RemoveTask(name); 54 } 55} 56}