1 /* 2 * Copyright (c) 2021 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 STORAGE_DISKMGR_INTERFACE_KITS_NAPI_DSM_FILE_PICKER_EXPORTER_H 16 #define STORAGE_DISKMGR_INTERFACE_KITS_NAPI_DSM_FILE_PICKER_EXPORTER_H 17 18 #pragma once 19 20 #include "ability.h" 21 22 #include "../common/napi/n_exporter.h" 23 #include "file_info.h" 24 #include "root_info.h" 25 #include "storage_ability.h" 26 27 namespace OHOS { 28 namespace DistributedFS { 29 namespace ModuleFPExpoter { 30 struct MkdirAsyncInfo { 31 napi_async_work asyncWork = nullptr; 32 napi_deferred defer = nullptr; 33 napi_ref callback[3] = { nullptr }; 34 std::string path = ""; 35 int err = 0; 36 }; 37 38 struct SaveFileAsyncInfo { 39 napi_async_work asyncWork = nullptr; 40 napi_deferred defer = nullptr; 41 napi_ref callback[3] = { nullptr }; 42 std::string dstPath = ""; 43 size_t srcLen = 0; 44 int err = 0; 45 std::vector<std::string> srcPath; 46 std::vector<FileManager::SaveFileInfo> saveFileList; 47 }; 48 49 struct SearchFileAsyncInfo { 50 napi_async_work asyncWork = nullptr; 51 napi_deferred defer = nullptr; 52 napi_ref callback[3] = { nullptr }; 53 std::string path = ""; 54 std::string name = ""; 55 int err = 0; 56 std::vector<FileManager::FileInfo> fileInfoList; 57 }; 58 59 struct ListAsyncInfo { 60 napi_async_work asyncWork = nullptr; 61 napi_deferred defer = nullptr; 62 napi_ref callback[3] = { nullptr }; 63 std::string path = ""; 64 int err = 0; 65 std::vector<FileManager::FileInfo> fileInfoList; 66 }; 67 68 struct GetDeviceAsyncInfo { 69 napi_async_work asyncWork = nullptr; 70 napi_deferred defer = nullptr; 71 napi_ref callback[3] = { nullptr }; 72 int err = 0; 73 std::vector<FileManager::RootInfo> deviceInfoList; 74 }; 75 76 class FilePickerExporter final : public NExporter { 77 public: 78 inline static const std::string className_ = "FilePicker"; 79 static napi_value Mkdir(napi_env env, napi_callback_info info); 80 static napi_value SaveFile(napi_env env, napi_callback_info info); 81 static napi_value SearchFile(napi_env env, napi_callback_info info); 82 static napi_value List(napi_env env, napi_callback_info info); 83 static napi_value GetDeviceInfo(napi_env env, napi_callback_info info); 84 85 bool Export() override; 86 87 std::string GetClassName() override; 88 89 FilePickerExporter(napi_env env, napi_value exports); 90 ~FilePickerExporter() override; 91 }; 92 } // namespace ModuleFMSExpoter 93 } // namespace DistributedFS 94 } // namespace OHOS 95 96 #endif // STORAGE_DISKMGR_INTERFACE_KITS_NAPI_DSM_FILE_PICKER_EXPORTER_H