• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "class_stream/stream_n_exporter.h"
24 #include "filemgmt_libhilog.h"
25 #include "properties/prop_n_exporter.h"
26 
27 using namespace std;
28 
29 namespace OHOS {
30 namespace FileManagement {
31 namespace ModuleFileIO {
Export(napi_env env,napi_value exports)32 static napi_value Export(napi_env env, napi_value exports)
33 {
34     InitOpenMode(env, exports);
35     std::vector<unique_ptr<NExporter>> products;
36     products.emplace_back(make_unique<PropNExporter>(env, exports));
37     products.emplace_back(make_unique<FileNExporter>(env, exports));
38     products.emplace_back(make_unique<StatNExporter>(env, exports));
39     products.emplace_back(make_unique<StreamNExporter>(env, exports));
40 
41     for (auto &&product : products) {
42         if (!product->Export()) {
43             HILOGE("INNER BUG. Failed to export class %{public}s for module fileio", product->GetClassName().c_str());
44             return nullptr;
45         } else {
46             HILOGI("Class %{public}s for module fileio has been exported", product->GetClassName().c_str());
47         }
48     }
49     return exports;
50 }
51 
52 static napi_module _module = {
53     .nm_version = 1,
54     .nm_flags = 0,
55     .nm_filename = nullptr,
56     .nm_register_func = Export,
57     .nm_modname = "file.fs",
58     .nm_priv = ((void *)0),
59     .reserved = {0}
60 };
61 
RegisterModule(void)62 extern "C" __attribute__((constructor)) void RegisterModule(void)
63 {
64     napi_module_register(&_module);
65 }
66 } // namespace ModuleFileIO
67 } // namespace FileManagement
68 } // namespace OHOS