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 #ifndef INTERFACES_KITS_NATIVE_PICKER_N_EXPOTER_H 16 #define INTERFACES_KITS_NATIVE_PICKER_N_EXPOTER_H 17 18 #include <dirent.h> 19 #include <thread> 20 #include "data_ability_helper.h" 21 #include "data_ability_observer_stub.h" 22 #include "data_ability_predicates.h" 23 #include "filemgmt_libn.h" 24 #include "picker_napi_utils.h" 25 #include "napi_base_context.h" 26 #include "napi_common_want.h" 27 #include "ui_extension_context.h" 28 29 30 namespace OHOS { 31 namespace Picker { 32 using namespace FileManagement::LibN; 33 using namespace std; 34 35 struct NameListArg { 36 struct dirent** namelist = { nullptr }; 37 int direntNum = 0; 38 }; 39 40 struct PickerCallBack { 41 bool ready = false; 42 int32_t resultCode; 43 OHOS::AAFwk::Want want; 44 }; 45 46 struct PickerAsyncContext { 47 napi_async_work work; 48 napi_deferred deferred; 49 napi_ref callbackRef; 50 size_t argc; 51 napi_value argv[NAPI_ARGC_MAX]; 52 std::shared_ptr<PickerCallBack> pickerCallBack; 53 }; 54 55 static sptr<Rosen::Window> window_; 56 57 class PickerNExporter final : public FileManagement::LibN::NExporter { 58 public: 59 inline static const std::string className_ = "Picker"; 60 static napi_value StartModalPicker(napi_env env, napi_callback_info info); 61 static napi_value MakeResultWithPickerCallBack(napi_env env, std::shared_ptr<PickerCallBack> pickerCallBack); 62 bool Export() override; 63 std::string GetClassName() override; 64 PickerNExporter(napi_env env, napi_value exports); 65 ~PickerNExporter() override; 66 }; 67 } // namespace FileAccessFwk 68 } // namespace OHOS 69 #endif // INTERFACES_KITS_NATIVE_PICKER_N_EXPOTER_H 70