1/* 2 * Copyright (c) 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 "pm_smartptr_util.h" 17#include "purgeable_mem_builder.h" 18 19namespace OHOS { 20namespace PurgeableMem { 21#ifdef LOG_TAG 22#undef LOG_TAG 23#endif 24#define LOG_TAG "PurgeableMem: Builder" 25 26PurgeableMemBuilder::~PurgeableMemBuilder() 27{ 28 if (nextBuilder_) { 29 nextBuilder_.reset(); 30 } 31} 32 33void PurgeableMemBuilder::AppendBuilder(std::unique_ptr<PurgeableMemBuilder> builder) 34{ 35 IF_NULL_LOG_ACTION(builder, "input builder is nullptr", return); 36 if (nextBuilder_) { 37 nextBuilder_->AppendBuilder(std::move(builder)); 38 } else { 39 nextBuilder_ = std::move(builder); 40 } 41} 42 43bool PurgeableMemBuilder::BuildAll(void *data, size_t size) 44{ 45 if (!Build(data, size)) { 46 HILOG_ERROR(LOG_CORE, "%{public}s: build(0x%{public}llx, %{public}zu) fail", 47 __func__, (unsigned long long)data, size); 48 return false; 49 } 50 if (!nextBuilder_) { 51 return true; 52 } 53 return nextBuilder_->BuildAll(data, size); 54} 55} /* namespace PurgeableMem */ 56} /* namespace OHOS */ 57