• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/system_properties.h"
19 #include "base/utils/utils.h"
20 #include "core/common/ace_engine.h"
21 #include "core/common/container_scope.h"
22 
23 namespace OHOS::Ace {
24 
CurrentId()25 int32_t Container::CurrentId()
26 {
27     return ContainerScope::CurrentId();
28 }
29 
Current()30 RefPtr<Container> Container::Current()
31 {
32     return AceEngine::Get().GetContainer(ContainerScope::CurrentId());
33 }
34 
GetActive()35 RefPtr<Container> Container::GetActive()
36 {
37     RefPtr<Container> activeContainer;
38     AceEngine::Get().NotifyContainers([&activeContainer](const RefPtr<Container>& container) {
39         auto front = container->GetFrontend();
40         if (front && front->IsForeground()) {
41             activeContainer = container;
42         }
43     });
44     return activeContainer;
45 }
46 
CurrentTaskExecutor()47 RefPtr<TaskExecutor> Container::CurrentTaskExecutor()
48 {
49     auto curContainer = Current();
50     CHECK_NULL_RETURN_NOLOG(curContainer, nullptr);
51     return curContainer->GetTaskExecutor();
52 }
53 
UpdateCurrent(int32_t id)54 void Container::UpdateCurrent(int32_t id)
55 {
56     ContainerScope::UpdateCurrent(id);
57 }
58 
UpdateState(const Frontend::State & state)59 bool Container::UpdateState(const Frontend::State& state)
60 {
61     std::lock_guard<std::mutex> lock(stateMutex_);
62     if (state_ == state) {
63         return false;
64     }
65     state_ = state;
66     return true;
67 }
68 
69 } // namespace OHOS::Ace