1 /* 2 * Copyright (c) 2023 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 "auto_layout.h" 17 #include "log/log.h" 18 namespace Updater { RegisterHelper(std::unique_ptr<LayoutInterface> ptr)19void AutoLayout::RegisterHelper(std::unique_ptr<LayoutInterface> ptr) 20 { 21 helper_ = std::move(ptr); 22 } 23 GetInstance()24AutoLayout &AutoLayout::GetInstance() 25 { 26 static AutoLayout layout; 27 return layout; 28 } 29 Init()30void AutoLayout::Init() 31 { 32 if (isInited_ || helper_ == nullptr) { 33 LOG(ERROR) << "helper_ null error or already has been inited"; 34 return; 35 } 36 helper_->Init(); 37 isInited_ = true; 38 } 39 SetJsonLocation(JsonNode & root)40void AutoLayout::SetJsonLocation(JsonNode &root) 41 { 42 if (helper_ == nullptr) { 43 LOG(ERROR) << "helper_ null error"; 44 return; 45 } 46 helper_->SetJsonLocation(root); 47 } 48 IsInited()49bool AutoLayout::IsInited() 50 { 51 return isInited_; 52 } 53 }