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 #ifndef RESOURCE_MANAGER_ADDON_H 17 #define RESOURCE_MANAGER_ADDON_H 18 19 #include <memory> 20 #include <string> 21 22 #include "napi/native_api.h" 23 #include "rawfile/raw_file_manager.h" 24 25 namespace OHOS { 26 namespace Global { 27 namespace Resource { 28 class NdkAddon { 29 public: 30 static napi_value Init(napi_env env, napi_value exports); 31 32 private: 33 static napi_value GetResourceManager(napi_env env, napi_callback_info info); 34 static napi_async_execute_callback TestRawFileExecute(); 35 }; 36 37 struct NdkAsyncContext { 38 napi_async_work work_; 39 40 std::string path_; 41 42 typedef napi_value (*CreateNapiValue)(napi_env env, NdkAsyncContext &context); 43 CreateNapiValue createValueFunc_; 44 std::string value_; 45 46 std::unique_ptr<char[]> mediaData; 47 long len_; 48 49 napi_deferred deferred_; 50 napi_ref callbackRef_; 51 52 std::string errMsg_; 53 int success_; 54 55 NativeResourceManager* ndk_; 56 NdkAsyncContextNdkAsyncContext57 NdkAsyncContext() : work_(nullptr), createValueFunc_(nullptr), deferred_(nullptr), 58 callbackRef_(nullptr), success_(true), ndk_(nullptr) {} 59 60 void SetErrorMsg(const std::string &msg); 61 }; 62 } // namespace Resource 63 } // namespace Global 64 } // namespace OHOS 65 #endif