1/* 2 * Copyright (c) 2023-2024 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 "filemgmt_libhilog.h" 20#include "filemgmt_libn.h" 21#include "prop_n_exporter.h" 22#include "session_backup_n_exporter.h" 23#include "session_incremental_backup_n_exporter.h" 24#include "session_restore_n_exporter.h" 25 26namespace OHOS::FileManagement::Backup { 27using namespace std; 28using namespace LibN; 29 30static napi_value Export(napi_env env, napi_value exports) 31{ 32 std::vector<unique_ptr<NExporter>> products; 33 products.emplace_back(make_unique<PropNExporter>(env, exports)); 34 products.emplace_back(make_unique<SessionBackupNExporter>(env, exports)); 35 products.emplace_back(make_unique<SessionRestoreNExporter>(env, exports)); 36 products.emplace_back(make_unique<SessionIncrementalBackupNExporter>(env, exports)); 37 for (auto &&product : products) { 38 if (!product->Export()) { 39 HILOGE("INNER BUG. Failed to export class %{public}s for module file.backup", 40 product->GetClassName().c_str()); 41 return nullptr; 42 } else { 43 HILOGI("Class %{public}s for module file.backup has been exported", product->GetClassName().c_str()); 44 } 45 } 46 return exports; 47} 48 49static napi_module _module = { 50 .nm_version = 1, 51 .nm_flags = 0, 52 .nm_filename = nullptr, 53 .nm_register_func = Export, 54 .nm_modname = "file.backup", 55 .nm_priv = ((void *)0), 56 .reserved = {0} 57}; 58 59extern "C" __attribute__((constructor)) void RegisterModule(void) 60{ 61 napi_module_register(&_module); 62} 63} // namespace OHOS::FileManagement::Backup