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 namespace OHOS::Ace { 19 20 EnvironmentProxy* EnvironmentProxy::inst_ = nullptr; 21 22 std::mutex EnvironmentProxy::mutex_; 23 GetInstance()24EnvironmentProxy* EnvironmentProxy::GetInstance() 25 { 26 if (inst_ == nullptr) { 27 std::lock_guard<std::mutex> lock(mutex_); 28 if (inst_ == nullptr) { 29 inst_ = new EnvironmentProxy(); 30 } 31 } 32 return (inst_); 33 } 34 SetDelegate(std::unique_ptr<EnvironmentInterface> && delegate)35void EnvironmentProxy::SetDelegate(std::unique_ptr<EnvironmentInterface>&& delegate) 36 { 37 delegate_ = std::move(delegate); 38 } 39 GetEnvironment(const RefPtr<TaskExecutor> & taskExecutor) const40RefPtr<Environment> EnvironmentProxy::GetEnvironment(const RefPtr<TaskExecutor>& taskExecutor) const 41 { 42 CHECK_NULL_RETURN(delegate_, nullptr); 43 return delegate_->GetEnvironment(taskExecutor); 44 } 45 46 } // namespace OHOS::Ace 47