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
16 #include <memory>
17 #include <vector>
18
19 #include "../common/log.h"
20 #include "class_constants/constants.h"
21 #include "class_dir/dir_n_exporter.h"
22 #include "class_dirent/dirent_n_exporter.h"
23 #include "class_randomaccessfile/randomaccessfile_n_exporter.h"
24 #include "class_stat/stat_n_exporter.h"
25 #include "class_stream/stream_n_exporter.h"
26 #include "class_watcher/watcher_n_exporter.h"
27 #include "properties/prop_n_exporter.h"
28
29 using namespace std;
30
31 namespace OHOS {
32 namespace DistributedFS {
33 namespace ModuleFileIO {
Export(napi_env env,napi_value exports)34 static napi_value Export(napi_env env, napi_value exports)
35 {
36 std::vector<unique_ptr<NExporter>> products;
37 products.emplace_back(make_unique<PropNExporter>(env, exports));
38 products.emplace_back(make_unique<DirentNExporter>(env, exports));
39 products.emplace_back(make_unique<DirNExporter>(env, exports));
40 products.emplace_back(make_unique<RandomAccessFileNExporter>(env, exports));
41 products.emplace_back(make_unique<StatNExporter>(env, exports));
42 products.emplace_back(make_unique<StreamNExporter>(env, exports));
43 products.emplace_back(make_unique<WatcherNExporter>(env, exports));
44 products.emplace_back(make_unique<Constants>(env, exports));
45
46 for (auto &&product : products) {
47 if (!product->Export()) {
48 HILOGE("INNER BUG. Failed to export class %{public}s for module fileio", product->GetClassName().c_str());
49 return nullptr;
50 } else {
51 HILOGE("Class %{public}s for module fileio has been exported", product->GetClassName().c_str());
52 }
53 }
54 return exports;
55 }
56
57 NAPI_MODULE(fileio, Export)
58 } // namespace ModuleFileIO
59 } // namespace DistributedFS
60 } // namespace OHOS