1 /* 2 * Copyright (C) 2024 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 #ifndef INTERFACES_KITS_JS_COMMON_INCLUDE_METADATA_NAPI_H 17 #define INTERFACES_KITS_JS_COMMON_INCLUDE_METADATA_NAPI_H 18 19 #include <vector> 20 #include <memory> 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 #include "metadata.h" 24 25 namespace OHOS { 26 namespace Media { 27 28 class MetadataNapi { 29 public: 30 MetadataNapi(); 31 ~MetadataNapi(); 32 33 static napi_value Init(napi_env env, napi_value exports); 34 static napi_value CreateMetadata(napi_env env, std::shared_ptr<ImageMetadata> metadata); GetNativeMetadata()35 std::shared_ptr<ImageMetadata> GetNativeMetadata() 36 { 37 return nativeMetadata_; 38 } 39 40 private: 41 static napi_value Constructor(napi_env env, napi_callback_info info); 42 static void Destructor(napi_env env, void *nativeObject, void *finalize); 43 44 static napi_value GetProperties(napi_env env, napi_callback_info info); 45 static napi_value SetProperties(napi_env env, napi_callback_info info); 46 static napi_value GetAllProperties(napi_env env, napi_callback_info info); 47 static napi_value Clone(napi_env env, napi_callback_info info); 48 49 void release(); 50 static thread_local napi_ref sConstructor_; 51 static thread_local std::shared_ptr<ImageMetadata> sMetadata_; 52 std::shared_ptr<ImageMetadata> nativeMetadata_; 53 napi_env env_ = nullptr; 54 bool isRelease = false; 55 uint32_t uniqueId_ = 0; 56 }; 57 } // namespace Media 58 } // namespace OHOS 59 #endif // INTERFACES_KITS_JS_COMMON_INCLUDE_METADATA_NAPI_H