• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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 #include "common_func.h"
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "class_file/file_n_exporter.h"
22 #include "class_stat/stat_n_exporter.h"
23 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
24 #include "class_atomicfile/atomicfile_n_exporter.h"
25 #include "class_randomaccessfile/randomaccessfile_n_exporter.h"
26 #include "class_readeriterator/readeriterator_n_exporter.h"
27 #include "class_stream/stream_n_exporter.h"
28 #include "class_tasksignal/task_signal_n_exporter.h"
29 #include "class_watcher/watcher_n_exporter.h"
30 #endif
31 #include "filemgmt_libhilog.h"
32 #include "properties/prop_n_exporter.h"
33 
34 using namespace std;
35 
36 namespace OHOS {
37 namespace FileManagement {
38 namespace ModuleFileIO {
Export(napi_env env,napi_value exports)39 static napi_value Export(napi_env env, napi_value exports)
40 {
41     InitAccessModeType(env, exports);
42     InitOpenMode(env, exports);
43     InitWhenceType(env, exports);
44     std::vector<unique_ptr<NExporter>> products;
45     products.emplace_back(make_unique<PropNExporter>(env, exports));
46     products.emplace_back(make_unique<FileNExporter>(env, exports));
47     products.emplace_back(make_unique<StatNExporter>(env, exports));
48 #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM)
49     products.emplace_back(make_unique<AtomicFileNExporter>(env, exports));
50     products.emplace_back(make_unique<RandomAccessFileNExporter>(env, exports));
51     products.emplace_back(make_unique<ReaderIteratorNExporter>(env, exports));
52     products.emplace_back(make_unique<StreamNExporter>(env, exports));
53     products.emplace_back(make_unique<WatcherNExporter>(env, exports));
54     products.emplace_back(make_unique<TaskSignalNExporter>(env, exports));
55 #endif
56     for (auto &&product : products) {
57 #ifdef WIN_PLATFORM
58         string nExporterName = product->GetNExporterName();
59 #else
60         string nExporterName = product->GetClassName();
61 #endif
62         if (!product->Export()) {
63             HILOGE("INNER BUG. Failed to export class %{public}s for module fileio", nExporterName.c_str());
64             return nullptr;
65         }
66     }
67     return exports;
68 }
69 
70 static napi_module _module = {
71     .nm_version = 1,
72     .nm_flags = 0,
73     .nm_filename = nullptr,
74     .nm_register_func = Export,
75     .nm_modname = "file.fs",
76     .nm_priv = ((void *)0),
77     .reserved = {0}
78 };
79 
RegisterModule(void)80 extern "C" __attribute__((constructor)) void RegisterModule(void)
81 {
82     napi_module_register(&_module);
83 }
84 } // namespace ModuleFileIO
85 } // namespace FileManagement
86 } // namespace OHOS
87