1 /* 2 * Copyright (c) 2021-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 "core/common/container.h" 17 18 #include "base/utils/utils.h" 19 #include "core/common/ace_engine.h" 20 #include "core/common/container_scope.h" 21 22 namespace OHOS::Ace { 23 CurrentId()24int32_t Container::CurrentId() 25 { 26 return ContainerScope::CurrentId(); 27 } 28 Current()29RefPtr<Container> Container::Current() 30 { 31 return AceEngine::Get().GetContainer(ContainerScope::CurrentId()); 32 } 33 GetActive()34RefPtr<Container> Container::GetActive() 35 { 36 RefPtr<Container> activeContainer; 37 AceEngine::Get().NotifyContainers([&activeContainer](const RefPtr<Container>& container) { 38 auto front = container->GetFrontend(); 39 if (front && front->IsForeground()) { 40 activeContainer = container; 41 } 42 }); 43 return activeContainer; 44 } 45 CurrentTaskExecutor()46RefPtr<TaskExecutor> Container::CurrentTaskExecutor() 47 { 48 auto curContainer = Current(); 49 CHECK_NULL_RETURN_NOLOG(curContainer, nullptr); 50 return curContainer->GetTaskExecutor(); 51 } 52 UpdateCurrent(int32_t id)53void Container::UpdateCurrent(int32_t id) 54 { 55 ContainerScope::UpdateCurrent(id); 56 } 57 UpdateState(const Frontend::State & state)58bool Container::UpdateState(const Frontend::State& state) 59 { 60 std::lock_guard<std::mutex> lock(stateMutex_); 61 if (state_ == state) { 62 return false; 63 } 64 state_ = state; 65 return true; 66 } 67 Dump(const std::vector<std::string> & params,std::vector<std::string> & info)68bool Container::Dump(const std::vector<std::string>& params, std::vector<std::string>& info) 69 { 70 std::string tip("container not support, type:"); 71 tip.append(AceType::TypeName(this)); 72 info.emplace_back(tip); 73 return true; 74 } 75 76 } // namespace OHOS::Ace