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 FILE_ACCESS_EXT_STUB_IMPL_H 17 #define FILE_ACCESS_EXT_STUB_IMPL_H 18 19 #include <memory> 20 #include <vector> 21 22 #include "file_access_ext_ability.h" 23 #include "file_access_ext_stub.h" 24 #include "file_access_extension_info.h" 25 #include "js_native_api_types.h" 26 #include "uri.h" 27 28 namespace OHOS { 29 namespace FileAccessFwk { 30 class FileAccessExtStubImpl : public FileAccessExtStub { 31 public: FileAccessExtStubImpl(const std::shared_ptr<FileAccessExtAbility> & extension,napi_env env)32 explicit FileAccessExtStubImpl(const std::shared_ptr<FileAccessExtAbility>& extension, napi_env env) 33 : extension_(extension) {} 34 ~FileAccessExtStubImpl()35 virtual ~FileAccessExtStubImpl() {} 36 37 int OpenFile(const Uri &uri, const int flags, int &fd) override; 38 int CreateFile(const Uri &parent, const std::string &displayName, Uri &newFile) override; 39 int Mkdir(const Uri &parent, const std::string &displayName, Uri &newFile) override; 40 int Delete(const Uri &sourceFile) override; 41 int Move(const Uri &sourceFile, const Uri &targetParent, Uri &newFile) override; 42 int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override; 43 int ListFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, 44 const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; 45 int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount, 46 const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override; 47 int UriToFileInfo(const Uri &selectFile, FileInfo &fileInfo) override; 48 int GetRoots(std::vector<RootInfo> &rootInfoVec) override; 49 int Access(const Uri &uri, bool &isExist) override; 50 int RegisterNotify(sptr<IFileAccessNotify> ¬ify) override; 51 int UnregisterNotify(sptr<IFileAccessNotify> ¬ify) override; 52 53 private: 54 std::shared_ptr<FileAccessExtAbility> GetOwner(); 55 std::shared_ptr<FileAccessExtAbility> extension_; 56 }; 57 } // namespace FileAccessFwk 58 } // namespace OHOS 59 #endif // FILE_ACCESS_EXT_STUB_IMPL_H