1 /*
2  * Copyright (c) 2021-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 #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_stat/stat_n_exporter.h"
24 #include "class_stream/stream_n_exporter.h"
25 #include "class_watcher/watcher_n_exporter.h"
26 #include "properties/prop_n_exporter.h"
27 
28 using namespace std;
29 
30 namespace OHOS {
31 namespace DistributedFS {
32 namespace ModuleFileIO {
Export(napi_env env,napi_value exports)33 static napi_value Export(napi_env env, napi_value exports)
34 {
35     std::vector<unique_ptr<NExporter>> products;
36     products.emplace_back(make_unique<PropNExporter>(env, exports));
37     products.emplace_back(make_unique<DirentNExporter>(env, exports));
38     products.emplace_back(make_unique<DirNExporter>(env, exports));
39     products.emplace_back(make_unique<StatNExporter>(env, exports));
40     products.emplace_back(make_unique<StreamNExporter>(env, exports));
41     products.emplace_back(make_unique<WatcherNExporter>(env, exports));
42     products.emplace_back(make_unique<Constants>(env, exports));
43 
44     for (auto &&product : products) {
45         if (!product->Export()) {
46             HILOGE("INNER BUG. Failed to export class %{public}s for module fileio", product->GetClassName().c_str());
47             return nullptr;
48         }
49     }
50     return exports;
51 }
52 
53 NAPI_MODULE(fileio, Export)
54 } // namespace ModuleFileIO
55 } // namespace DistributedFS
56 } // namespace OHOS
57