1 /* 2 * Copyright (c) 2025 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 "metadata_impl.h" 17 18 #include "image_log.h" 19 20 namespace OHOS { 21 namespace Media { MetadataImpl(std::shared_ptr<ImageMetadata> metadata)22MetadataImpl::MetadataImpl(std::shared_ptr<ImageMetadata> metadata) 23 { 24 static std::atomic<uint32_t> currentId = 0; 25 uniqueId_ = currentId.fetch_add(1, std::memory_order_relaxed); 26 nativeMetadata_ = metadata; 27 } 28 ~MetadataImpl()29MetadataImpl::~MetadataImpl() 30 { 31 release(); 32 } 33 release()34void MetadataImpl::release() 35 { 36 if (!isRelease) { 37 nativeMetadata_ = nullptr; 38 isRelease = true; 39 } 40 } 41 GetAllProperties(uint32_t * errCode)42std::vector<std::pair<std::string, std::string>> MetadataImpl::GetAllProperties(uint32_t* errCode) 43 { 44 std::vector<std::pair<std::string, std::string>> propertiesArray; 45 if (nativeMetadata_ == nullptr) { 46 IMAGE_LOGE("Empty native rMetadata"); 47 return propertiesArray; 48 } 49 ImageMetadata::PropertyMapPtr allKey = nativeMetadata_->GetAllProperties(); 50 for (const auto& entry : *allKey) { 51 propertiesArray.emplace_back(std::make_pair(entry.first, entry.second)); 52 } 53 return propertiesArray; 54 } 55 } // namespace Media 56 } // namespace OHOS