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 Copy(const Uri &sourceUri, const Uri &destUri, std::vector<Result> &copyResult,
43         bool force = false) override;
44     int CopyFile(const Uri &sourceUri, const Uri &destUri, const std::string &fileName,
45         Uri &newFileUri) override;
46     int Rename(const Uri &sourceFile, const std::string &displayName, Uri &newFile) override;
47     int ListFile(const FileInfo &fileInfo, const int64_t offset, const FileFilter &filter,
48         SharedMemoryInfo &memInfo) override;
49     int ScanFile(const FileInfo &fileInfo, const int64_t offset, const int64_t maxCount,
50         const FileFilter &filter, std::vector<FileInfo> &fileInfoVec) override;
51     int Query(const Uri &uri, std::vector<std::string> &columns, std::vector<std::string> &results) override;
52     int GetFileInfoFromUri(const Uri &selectFile, FileInfo &fileInfo) override;
53     int GetFileInfoFromRelativePath(const std::string &selectFile, FileInfo &fileInfo) override;
54     int GetRoots(std::vector<RootInfo> &rootInfoVec) override;
55     int Access(const Uri &uri, bool &isExist) override;
56     int StartWatcher(const Uri &uri) override;
57     int StopWatcher(const Uri &uri) override;
58     int MoveItem(const Uri &sourceFile, const Uri &targetParent, std::vector<Result> &moveResult,
59                  bool force = false) override;
60     int MoveFile(const Uri &sourceFile, const Uri &targetParent, std::string &fileName, Uri &newFile) override;
61 private:
62     std::shared_ptr<FileAccessExtAbility> GetOwner();
63     std::shared_ptr<FileAccessExtAbility> extension_;
64 };
65 } // namespace FileAccessFwk
66 } // namespace OHOS
67 #endif // FILE_ACCESS_EXT_STUB_IMPL_H