• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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/environment/environment_proxy.h"
17 
18 #include "base/memory/ace_type.h"
19 #include "base/utils/utils.h"
20 
21 namespace OHOS::Ace {
22 
23 EnvironmentProxy* EnvironmentProxy::inst_ = nullptr;
24 
25 std::mutex EnvironmentProxy::mutex_;
26 
GetInstance()27 EnvironmentProxy* EnvironmentProxy::GetInstance()
28 {
29     if (inst_ == nullptr) {
30         std::lock_guard<std::mutex> lock(mutex_);
31         if (inst_ == nullptr) {
32             inst_ = new EnvironmentProxy();
33         }
34     }
35     return (inst_);
36 }
37 
SetDelegate(std::unique_ptr<EnvironmentInterface> && delegate)38 void EnvironmentProxy::SetDelegate(std::unique_ptr<EnvironmentInterface>&& delegate)
39 {
40     delegate_ = std::move(delegate);
41 }
42 
GetEnvironment(const RefPtr<TaskExecutor> & taskExecutor) const43 RefPtr<Environment> EnvironmentProxy::GetEnvironment(const RefPtr<TaskExecutor>& taskExecutor) const
44 {
45     CHECK_NULL_RETURN_NOLOG(delegate_, nullptr);
46     return delegate_->GetEnvironment(taskExecutor);
47 }
48 
49 } // namespace OHOS::Ace
50