1 /* 2 * Copyright (c) 2022-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 #include "delegator_thread.h" 17 #include "hilog_tag_wrapper.h" 18 19 namespace OHOS { 20 namespace AppExecFwk { DelegatorThread(bool isMain)21DelegatorThread::DelegatorThread(bool isMain) 22 { 23 if (isMain) { 24 runner_ = EventRunner::GetMainEventRunner(); 25 } else { 26 runner_ = EventRunner::Create(); 27 } 28 29 handler_ = std::make_shared<EventHandler>(runner_); 30 } 31 Run(const DTask & task)32bool DelegatorThread::Run(const DTask &task) 33 { 34 if (!task) { 35 TAG_LOGW(AAFwkTag::DELEGATOR, "invalid input params"); 36 return false; 37 } 38 39 if (!handler_) { 40 TAG_LOGW(AAFwkTag::DELEGATOR, "invalid EventHandler"); 41 return false; 42 } 43 44 return handler_->PostTask(task, "DelegatorThread::Run"); 45 } 46 GetThreadName() const47std::string DelegatorThread::GetThreadName() const 48 { 49 return threadName_; 50 } 51 } // namespace AppExecFwk 52 } // namespace OHOS 53