From ef5f7f1692cf3faa8119445cd261333abd70f892 Mon Sep 17 00:00:00 2001 From: maokelong95 Date: Fri, 15 Jul 2022 18:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: maokelong95 --- interfaces/innerkits/include/security_label.h | 37 -- interfaces/kits/js/@ohos.document.d.ts | 63 --- interfaces/kits/js/@ohos.statfs.d.ts | 42 -- .../kits/js/src/common/ability_helper.cpp | 54 -- .../kits/js/src/common/ability_helper.h | 27 - interfaces/kits/js/src/common/fd_guard.cpp | 46 -- interfaces/kits/js/src/common/fd_guard.h | 34 -- interfaces/kits/js/src/common/log.h | 90 --- .../src/common/napi/n_async/n_async_context.h | 70 --- .../napi/n_async/n_async_work_callback.cpp | 98 ---- .../napi/n_async/n_async_work_callback.h | 35 -- .../napi/n_async/n_async_work_factory.h | 33 -- .../napi/n_async/n_async_work_promise.cpp | 91 --- .../napi/n_async/n_async_work_promise.h | 35 -- .../kits/js/src/common/napi/n_async/n_ref.cpp | 53 -- .../kits/js/src/common/napi/n_async/n_ref.h | 38 -- .../kits/js/src/common/napi/n_class.cpp | 99 ---- interfaces/kits/js/src/common/napi/n_class.h | 82 --- .../kits/js/src/common/napi/n_exporter.h | 39 -- .../kits/js/src/common/napi/n_func_arg.cpp | 111 ---- .../kits/js/src/common/napi/n_func_arg.h | 71 --- interfaces/kits/js/src/common/napi/n_val.cpp | 290 ---------- interfaces/kits/js/src/common/napi/n_val.h | 77 --- .../kits/js/src/common/napi/uni_header.h | 23 - interfaces/kits/js/src/common/uni_error.cpp | 118 ---- interfaces/kits/js/src/common/uni_error.h | 64 --- .../src/mod_document/document_n_exporter.cpp | 43 -- .../js/src/mod_document/document_n_exporter.h | 29 - .../js/src/mod_document/document_napi.cpp | 41 -- .../kits/js/src/mod_document/document_napi.h | 27 - .../js/src/mod_statfs/statfs_n_exporter.cpp | 532 ------------------ .../js/src/mod_statfs/statfs_n_exporter.h | 47 -- .../kits/js/src/mod_statfs/statfs_napi.cpp | 41 -- .../kits/js/src/mod_statfs/statfs_napi.h | 27 - 34 files changed, 2607 deletions(-) delete mode 100644 interfaces/innerkits/include/security_label.h delete mode 100644 interfaces/kits/js/@ohos.document.d.ts delete mode 100644 interfaces/kits/js/@ohos.statfs.d.ts delete mode 100644 interfaces/kits/js/src/common/ability_helper.cpp delete mode 100644 interfaces/kits/js/src/common/ability_helper.h delete mode 100644 interfaces/kits/js/src/common/fd_guard.cpp delete mode 100644 interfaces/kits/js/src/common/fd_guard.h delete mode 100644 interfaces/kits/js/src/common/log.h delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_context.h delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_ref.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_async/n_ref.h delete mode 100644 interfaces/kits/js/src/common/napi/n_class.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_class.h delete mode 100644 interfaces/kits/js/src/common/napi/n_exporter.h delete mode 100644 interfaces/kits/js/src/common/napi/n_func_arg.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_func_arg.h delete mode 100644 interfaces/kits/js/src/common/napi/n_val.cpp delete mode 100644 interfaces/kits/js/src/common/napi/n_val.h delete mode 100644 interfaces/kits/js/src/common/napi/uni_header.h delete mode 100644 interfaces/kits/js/src/common/uni_error.cpp delete mode 100644 interfaces/kits/js/src/common/uni_error.h delete mode 100644 interfaces/kits/js/src/mod_document/document_n_exporter.cpp delete mode 100644 interfaces/kits/js/src/mod_document/document_n_exporter.h delete mode 100644 interfaces/kits/js/src/mod_document/document_napi.cpp delete mode 100644 interfaces/kits/js/src/mod_document/document_napi.h delete mode 100644 interfaces/kits/js/src/mod_statfs/statfs_n_exporter.cpp delete mode 100644 interfaces/kits/js/src/mod_statfs/statfs_n_exporter.h delete mode 100644 interfaces/kits/js/src/mod_statfs/statfs_napi.cpp delete mode 100644 interfaces/kits/js/src/mod_statfs/statfs_napi.h diff --git a/interfaces/innerkits/include/security_label.h b/interfaces/innerkits/include/security_label.h deleted file mode 100644 index 3727c9a61..000000000 --- a/interfaces/innerkits/include/security_label.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FOUNDATION_FILEMANAGEMENT_FILEAPI_INTERFACES_INNERKITS_SECURITY_LABEL_H -#define FOUNDATION_FILEMANAGEMENT_FILEAPI_INTERFACES_INNERKITS_SECURITY_LABEL_H - -#include - -namespace OHOS { -namespace FileIO { -class SecurityLabel { -public: - static bool SetSecurityLabel(std::string path, std::string dataLevel) - { - return true; - } - static std::string GetSecurityLabel(std::string path) - { - return "data.security.level"; - }; -}; -} // namespace FileIO -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.document.d.ts b/interfaces/kits/js/@ohos.document.d.ts deleted file mode 100644 index 1333942fe..000000000 --- a/interfaces/kits/js/@ohos.document.d.ts +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import { AsyncCallback } from './basic' - -export default document; - -/** - * document - * @syscap SystemCapability.FileManagement.UserFileService - * @since 6 - * @import import document from '@ohos.document'; - * @permission N/A - */ -declare namespace document { - export { choose }; - export { show }; -} - -/** - * choose. - * - * @note N/A - * @syscap SystemCapability.FileManagement.UserFileService - * @since 6 - * @permission N/A - * @function choose - * @param {string} type - type. - * @param {AsyncCallback} [callback] - callback. - * @returns {void | Promise} no callback return Promise otherwise return void - * @throws {TypedError} Parameter check failed - */ -declare function choose(types?: string[]): Promise; -declare function choose(callback: AsyncCallback): void; -declare function choose(types: string[], callback: AsyncCallback): void; - -/** - * show. - * - * @note N/A - * @syscap SystemCapability.FileManagement.UserFileService - * @since 6 - * @permission N/A - * @function show - * @param {string} uri - uri. - * @param {string} type - type. - * @param {AsyncCallback} [callback] - callback. - * @returns {void | Promise} no callback return Promise otherwise return void - * @throws {TypedError} Parameter check failed - */ -declare function show(uri: string, type: string): Promise; -declare function show(uri: string, type: string, callback: AsyncCallback): void; \ No newline at end of file diff --git a/interfaces/kits/js/@ohos.statfs.d.ts b/interfaces/kits/js/@ohos.statfs.d.ts deleted file mode 100644 index 53a32c9ea..000000000 --- a/interfaces/kits/js/@ohos.statfs.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* -* Copyright (C) 2021 Huawei Device Co., Ltd. -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import {AsyncCallback, Callback} from "./basic"; - -/** - * Provides filesystem statistics APIs - * - * @since 8 - * @sysCap N/A - * @devices phone, tablet - */ -declare namespace Statfs { - /** - * Get the number of free bytes on the specified path. - * - * @since 8 - */ - function getFreeBytes(path: string, callback: AsyncCallback): void; - function getFreeBytes(path: string): Promise; - /** - * Get the total number of bytes of the specified path. - * - * @since 8 - */ - function getTotalBytes(path: string, callback: AsyncCallback): void; - function getTotalBytes(path: string): Promise; -} - -export default Statfs; diff --git a/interfaces/kits/js/src/common/ability_helper.cpp b/interfaces/kits/js/src/common/ability_helper.cpp deleted file mode 100644 index c5aae1548..000000000 --- a/interfaces/kits/js/src/common/ability_helper.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ability_helper.h" - -#include "log.h" -#include "napi/n_func_arg.h" -#include "napi/uni_header.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; -using OHOS::AppExecFwk::Ability; -using OHOS::AppExecFwk::AbilityContext; - -Ability* AbilityHelper::GetJsAbility(napi_env env) -{ - napi_value global = nullptr; - napi_value abilityContext = nullptr; - - napi_status status = napi_get_global(env, &global); - if (status != napi_ok || global == nullptr) { - HILOGE("Cannot get global instance for %{public}d", status); - return nullptr; - } - - status = napi_get_named_property(env, global, "ability", &abilityContext); - if (status != napi_ok || abilityContext == nullptr) { - HILOGE("Cannot get ability context for %{public}d", status); - return nullptr; - } - - Ability *ability = nullptr; - status = napi_get_value_external(env, abilityContext, (void **)&ability); - if (status != napi_ok || ability == nullptr) { - HILOGE("Get ability form property failed for %{public}d", status); - } - - return ability; -} -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/ability_helper.h b/interfaces/kits/js/src/common/ability_helper.h deleted file mode 100644 index e998027c0..000000000 --- a/interfaces/kits/js/src/common/ability_helper.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "../common/napi/uni_header.h" -#include "ability.h" - -namespace OHOS { -namespace DistributedFS { -struct AbilityHelper { - static AppExecFwk::Ability *GetJsAbility(napi_env env); -}; -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/fd_guard.cpp b/interfaces/kits/js/src/common/fd_guard.cpp deleted file mode 100644 index fa4594573..000000000 --- a/interfaces/kits/js/src/common/fd_guard.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fd_guard.h" - -#include - -namespace OHOS { -namespace DistributedFS { -FDGuard::FDGuard(int fd) : fd_(fd) {} - -FDGuard::~FDGuard() -{ - if (fd_ > 0) { - close(fd_); - } -} - -int FDGuard::GetFD() const -{ - return fd_; -} - -void FDGuard::SetFD(int fd) -{ - fd_ = fd; -} - -void FDGuard::ClearFD() -{ - fd_ = -1; -} -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/fd_guard.h b/interfaces/kits/js/src/common/fd_guard.h deleted file mode 100644 index 2db743831..000000000 --- a/interfaces/kits/js/src/common/fd_guard.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -namespace OHOS { -namespace DistributedFS { -class FDGuard { -public: - FDGuard() = default; - explicit FDGuard(int fd); - ~FDGuard(); - - int GetFD() const; - void SetFD(int fd); - void ClearFD(); - -private: - int fd_ = -1; -}; -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/common/log.h b/interfaces/kits/js/src/common/log.h deleted file mode 100644 index 32a09a751..000000000 --- a/interfaces/kits/js/src/common/log.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include - -#ifndef FILE_SUBSYSTEM_DEV_ON_PC -#include "hilog/log.h" -#endif - -namespace OHOS { -namespace DistributedFS { -#ifndef FILE_SUBSYSTEM_DEV_ON_PC -static constexpr int FILEIO_DOMAIN_ID = 0; -static constexpr OHOS::HiviewDFX::HiLogLabel FILEIO_LABEL = { LOG_CORE, FILEIO_DOMAIN_ID, "distributedfilejs" }; - -#ifdef HILOGD -#undef HILOGD -#endif - -#ifdef HILOGF -#undef HILOGF -#endif - -#ifdef HILOGE -#undef HILOGE -#endif - -#ifdef HILOGW -#undef HILOGW -#endif - -#ifdef HILOGI -#undef HILOGI -#endif - -#define HILOGD(fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Debug(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGI(fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Info(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGW(fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGE(fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Error(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGF(fmt, ...) \ - (void)OHOS::HiviewDFX::HiLog::Fatal(OHOS::DistributedFS::FILEIO_LABEL, "%{public}s: " fmt, __func__, ##__VA_ARGS__) - -#else - -#define PCLOG(fmt, ...) \ - do { \ - const std::vector filter = { \ - "{public}", \ - "{private}", \ - }; \ - std::string str____(fmt); \ - for (auto &&pattern : filter) { \ - size_t pos = 0; \ - while (std::string::npos != (pos = str____.find(pattern))) { \ - str____.erase(pos, pattern.length()); \ - } \ - } \ - str____ += "\n"; \ - printf(str____.c_str(), ##__VA_ARGS__); \ - } while (0); - -#define HILOGD(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGI(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGW(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGE(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define HILOGF(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) - -#endif -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h deleted file mode 100644 index 7c45ce20a..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_ASYNC_CONTEXT_H -#define N_ASYNC_CONTEXT_H - -#include - -#include "../../uni_error.h" -#include "../n_val.h" -#include "n_ref.h" - -namespace OHOS { -namespace DistributedFS { -using NContextCBExec = std::function; -using NContextCBComplete = std::function; - -class NAsyncContext { -public: - UniError err_; - NVal res_; - NContextCBExec cbExec_; - NContextCBComplete cbComplete_; - napi_async_work awork_; - NRef thisPtr_; - - explicit NAsyncContext(NVal thisPtr) : err_(0), res_(NVal()), cbExec_(nullptr), - cbComplete_(nullptr), awork_(nullptr), thisPtr_(thisPtr) {} - virtual ~NAsyncContext() = default; -}; - -class NAsyncContextPromise : public NAsyncContext { -public: - napi_deferred deferred_; - explicit NAsyncContextPromise(NVal thisPtr) : NAsyncContext(thisPtr) {} - ~NAsyncContextPromise() = default; -}; - -class NAsyncContextCallback : public NAsyncContext { -public: - NRef cb_; - NAsyncContextCallback(NVal thisPtr, NVal cb) : NAsyncContext(thisPtr), cb_(cb) {} - ~NAsyncContextCallback() = default; -}; - -class NAsyncContextLegacy : public NAsyncContext { -public: - NRef cbSucc_; - NRef cbFail_; - NRef cbFinal_; - NAsyncContextLegacy(NVal thisPtr, NVal cbSucc, NVal cbFail, NVal cbFinal) - : NAsyncContext(thisPtr), cbSucc_(cbSucc), cbFail_(cbFail), cbFinal_(cbFinal) - {} - ~NAsyncContextLegacy() = default; -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_ASYNC_CONTEXT_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp deleted file mode 100644 index 6b6d0b70a..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_async_work_callback.h" -#include "../../log.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -NAsyncWorkCallback::NAsyncWorkCallback(napi_env env, NVal thisPtr, NVal cb) : NAsyncWorkFactory(env) -{ - ctx_ = new NAsyncContextCallback(thisPtr, cb); -} - -static void CallbackExecute(napi_env env, void *data) -{ - auto ctx = static_cast(data); - if (ctx != nullptr && ctx->cbExec_ != nullptr) { - ctx->err_ = ctx->cbExec_(env); - } -} - -static void CallbackComplete(napi_env env, napi_status status, void *data) -{ - napi_handle_scope scope = nullptr; - napi_open_handle_scope(env, &scope); - auto ctx = static_cast(data); - if (ctx == nullptr) { - return; - } - if (ctx->cbComplete_ != nullptr) { - ctx->res_ = ctx->cbComplete_(env, ctx->err_); - ctx->cbComplete_ = nullptr; - } - - vector argv; - if (!ctx->res_.TypeIsError(true)) { - argv = { UniError(ERRNO_NOERR).GetNapiErr(env), ctx->res_.val_ }; - } else { - argv = { ctx->res_.val_ }; - } - - napi_value global = nullptr; - napi_value callback = ctx->cb_.Deref(env).val_; - napi_value tmp = nullptr; - napi_get_global(env, &global); - napi_status stat = napi_call_function(env, global, callback, argv.size(), argv.data(), &tmp); - if (stat != napi_ok) { - HILOGE("Failed to call function for %{public}d", stat); - } - napi_close_handle_scope(env, scope); - napi_delete_async_work(env, ctx->awork_); - delete ctx; -} - -NVal NAsyncWorkCallback::Schedule(string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) -{ - if (!ctx_->cb_ || !ctx_->cb_.Deref(env_).TypeIs(napi_function)) { - UniError(EINVAL).ThrowErr(env_, "The callback shall be a funciton"); - return NVal(); - } - - ctx_->cbExec_ = move(cbExec); - ctx_->cbComplete_ = move(cbComplete); - - napi_value resource = NVal::CreateUTF8String(env_, procedureName).val_; - - napi_status status = - napi_create_async_work(env_, nullptr, resource, CallbackExecute, CallbackComplete, ctx_, &ctx_->awork_); - if (status != napi_ok) { - HILOGE("INNER BUG. Failed to create async work for %{public}d", status); - return NVal(); - } - - status = napi_queue_async_work(env_, ctx_->awork_); - if (status != napi_ok) { - HILOGE("INNER BUG. Failed to queue async work for %{public}d", status); - return NVal(); - } - - ctx_ = nullptr; // The ownership of ctx_ has been transfered - return NVal::CreateUndefined(env_); -} -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h deleted file mode 100644 index 7b7f190c8..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_ASYNC_WORK_CALLBACK_H -#define N_ASYNC_WORK_CALLBACK_H - -#include "n_async_work_factory.h" - -namespace OHOS { -namespace DistributedFS { -class NAsyncWorkCallback : public NAsyncWorkFactory { -public: - NAsyncWorkCallback(napi_env env, NVal thisPtr, NVal cb); - ~NAsyncWorkCallback() = default; - - NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; - NAsyncWorkCallback(const NAsyncWorkCallback&) = delete; -private: - NAsyncContextCallback *ctx_ = nullptr; -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_ASYNC_WORK_CALLBACK_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h deleted file mode 100644 index 7b1154698..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_ASYNC_WORK_FACTORY_H -#define N_ASYNC_WORK_FACTORY_H - -#include "n_async_context.h" - -namespace OHOS { -namespace DistributedFS { -class NAsyncWorkFactory { -public: - explicit NAsyncWorkFactory(napi_env env) : env_(env) {} - virtual ~NAsyncWorkFactory() = default; - virtual NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) = 0; - - napi_env env_ = nullptr; -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_ASYNC_WORK_FACTORY_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp deleted file mode 100644 index 3809c1a4b..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_async_work_promise.h" -#include "../../log.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -NAsyncWorkPromise::NAsyncWorkPromise(napi_env env, NVal thisPtr) : NAsyncWorkFactory(env) -{ - ctx_ = new NAsyncContextPromise(thisPtr); -} - -static void PromiseOnExec(napi_env env, void *data) -{ - auto ctx = static_cast(data); - if (ctx != nullptr && ctx->cbExec_ != nullptr) { - ctx->err_ = ctx->cbExec_(env); - } -} - -static void PromiseOnComplete(napi_env env, napi_status status, void *data) -{ - auto ctx = static_cast(data); - if (ctx == nullptr) { - return; - } - if (ctx->cbComplete_ != nullptr) { - ctx->res_ = ctx->cbComplete_(env, ctx->err_); - } - if (!ctx->res_.TypeIsError(true)) { - napi_status status = napi_resolve_deferred(env, ctx->deferred_, ctx->res_.val_); - if (status != napi_ok) { - HILOGE("Internal BUG, cannot resolve promise for %{public}d", status); - } - } else { - napi_status status = napi_reject_deferred(env, ctx->deferred_, ctx->res_.val_); - if (status != napi_ok) { - HILOGE("Internal BUG, cannot reject promise for %{public}d", status); - } - } - ctx->deferred_ = nullptr; - napi_delete_async_work(env, ctx->awork_); - delete ctx; -} - -NVal NAsyncWorkPromise::Schedule(string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) -{ - ctx_->cbExec_ = move(cbExec); - ctx_->cbComplete_ = move(cbComplete); - - napi_status status; - napi_value result = nullptr; - status = napi_create_promise(env_, &ctx_->deferred_, &result); - if (status != napi_ok) { - HILOGE("INNER BUG. Cannot create promise for %{public}d", status); - return NVal(); - } - - napi_value resource = NVal::CreateUTF8String(env_, procedureName).val_; - status = napi_create_async_work(env_, nullptr, resource, PromiseOnExec, PromiseOnComplete, ctx_, &ctx_->awork_); - if (status != napi_ok) { - HILOGE("INNER BUG. Failed to create async work for %{public}d", status); - return NVal(); - } - - status = napi_queue_async_work(env_, ctx_->awork_); - if (status != napi_ok) { - HILOGE("INNER BUG. Failed to queue async work for %{public}d", status); - return NVal(); - } - - ctx_ = nullptr; // The ownership of ctx_ has been transfered - return { env_, result }; -} -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h deleted file mode 100644 index f2406913f..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_ASYNC_WORK_PROMISE_H -#define N_ASYNC_WORK_PROMISE_H - -#include "n_async_work_factory.h" - -namespace OHOS { -namespace DistributedFS { -class NAsyncWorkPromise : public NAsyncWorkFactory { -public: - NAsyncWorkPromise(napi_env env, NVal thisPtr); - ~NAsyncWorkPromise() = default; - - NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; - NAsyncWorkPromise(const NAsyncWorkPromise&) = delete; -private: - NAsyncContextPromise *ctx_; -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_ASYNC_WORK_PROMISE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_async/n_ref.cpp b/interfaces/kits/js/src/common/napi/n_async/n_ref.cpp deleted file mode 100644 index 8b78ac9c8..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_ref.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_ref.h" - -namespace OHOS { -namespace DistributedFS { -NRef::NRef() {} - -NRef::NRef(NVal val) -{ - if (val) { - env_ = val.env_; - napi_create_reference(val.env_, val.val_, 1, &ref_); - } -} - -NRef::~NRef() -{ - if (ref_) { - napi_delete_reference(env_, ref_); - } -} - -NRef::operator bool() const -{ - return ref_ != nullptr; -} - -NVal NRef::Deref(napi_env env) -{ - if (!ref_) { - return NVal(); - } - - napi_value val = nullptr; - napi_get_reference_value(env, ref_, &val); - return { env, val }; -} -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/common/napi/n_async/n_ref.h b/interfaces/kits/js/src/common/napi/n_async/n_ref.h deleted file mode 100644 index a9f166cfc..000000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_ref.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_REF_H -#define N_REF_H - -#include "../n_val.h" - -namespace OHOS { -namespace DistributedFS { -class NRef { -public: - NRef(); - explicit NRef(NVal val); - ~NRef(); - - explicit operator bool() const; - NVal Deref(napi_env env); - -private: - napi_env env_ = nullptr; - napi_ref ref_ = nullptr; -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_REF_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_class.cpp b/interfaces/kits/js/src/common/napi/n_class.cpp deleted file mode 100644 index 0e9028b02..000000000 --- a/interfaces/kits/js/src/common/napi/n_class.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_class.h" - -#include -#include - -#include "../log.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; -NClass &NClass::GetInstance() -{ - static NClass nClass; - return nClass; -} - -tuple NClass::DefineClass(napi_env env, - string className, - napi_callback constructor, - vector &&properties) -{ - napi_value classVal = nullptr; - napi_status stat = napi_define_class(env, - className.c_str(), - className.length(), - constructor, - nullptr, - properties.size(), - properties.data(), - &classVal); - if (stat != napi_ok) { - HILOGE("INNER BUG. Cannot define class %{public}s because of %{public}d", className.c_str(), stat); - } - return { stat == napi_ok, classVal }; -} - -bool NClass::SaveClass(napi_env env, string className, napi_value exClass) -{ - NClass &nClass = NClass::GetInstance(); - lock_guard(nClass.exClassMapLock); - - if (nClass.exClassMap.find(className) != nClass.exClassMap.end()) { - return true; - } - - napi_ref constructor; - napi_status res = napi_create_reference(env, exClass, 1, &constructor); - if (res == napi_ok) { - nClass.exClassMap.insert({ className, constructor }); - HILOGI("Class %{public}s has been saved", className.c_str()); - } else { - HILOGE("INNER BUG. Cannot ref class constructor %{public}s because of %{public}d", className.c_str(), res); - } - return res == napi_ok; -} - -napi_value NClass::InstantiateClass(napi_env env, string className, vector args) -{ - NClass &nClass = NClass::GetInstance(); - lock_guard(nClass.exClassMapLock); - - auto it = nClass.exClassMap.find(className); - if (it == nClass.exClassMap.end()) { - HILOGE("Class %{public}s hasn't been saved yet", className.c_str()); - return nullptr; - } - - napi_value cons = nullptr; - napi_status status = napi_get_reference_value(env, it->second, &cons); - if (status != napi_ok) { - HILOGE("INNER BUG. Cannot deref class %{public}s because of %{public}d", className.c_str(), status); - return nullptr; - } - - napi_value instance = nullptr; - status = napi_new_instance(env, cons, args.size(), args.data(), &instance); - if (status != napi_ok) { - HILOGE("INNER BUG. Cannot instantiate the class %{public}s because of %{public}d", className.c_str(), status); - return nullptr; - } - return instance; -} -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_class.h b/interfaces/kits/js/src/common/napi/n_class.h deleted file mode 100644 index db9a90ca0..000000000 --- a/interfaces/kits/js/src/common/napi/n_class.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "uni_header.h" - -#include -#include -#include -#include -#include -#include - -#include "../log.h" - -namespace OHOS { -namespace DistributedFS { -class NClass final { -public: - NClass(const NClass &) = delete; - NClass &operator = (const NClass &) = delete; - static NClass &GetInstance(); - - static std::tuple DefineClass(napi_env env, - std::string className, - napi_callback constructor, - std::vector &&properties); - static bool SaveClass(napi_env env, std::string className, napi_value exClass); - static napi_value InstantiateClass(napi_env env, std::string className, std::vector args); - - template static T *GetEntityOf(napi_env env, napi_value objStat) - { - if (!env || !objStat) { - HILOGE("Empty input: env %d, obj %d", env == nullptr, objStat == nullptr); - return nullptr; - } - T *t = nullptr; - napi_status status = napi_unwrap(env, objStat, (void **)&t); - if (status != napi_ok) { - HILOGE("Cannot umwarp for pointer: %d", status); - return nullptr; - } - return t; - } - - template static bool SetEntityFor(napi_env env, napi_value obj, std::unique_ptr entity) - { - napi_status status = napi_wrap( - env, - obj, - entity.get(), - [](napi_env env, void *data, void *hint) { - auto entity = static_cast(data); - delete entity; - }, - nullptr, - nullptr); - entity.release(); - return status == napi_ok; - } - -private: - NClass() = default; - ~NClass() = default; - std::map exClassMap; - std::mutex exClassMapLock; -}; -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_exporter.h b/interfaces/kits/js/src/common/napi/n_exporter.h deleted file mode 100644 index 2ade0c076..000000000 --- a/interfaces/kits/js/src/common/napi/n_exporter.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "uni_header.h" - -#include -#include - -#include "n_val.h" - -namespace OHOS { -namespace DistributedFS { -class NExporter { -public: - NExporter(napi_env env, napi_value exports) : exports_(env, exports) {}; - virtual ~NExporter() = default; - - virtual bool Export() = 0; - virtual std::string GetClassName() = 0; - -protected: - NVal exports_; -}; -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.cpp b/interfaces/kits/js/src/common/napi/n_func_arg.cpp deleted file mode 100644 index 123ef8d0a..000000000 --- a/interfaces/kits/js/src/common/napi/n_func_arg.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_func_arg.h" - -#include -#include - -#include "../log.h" -#include "../uni_error.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -NFuncArg::NFuncArg(napi_env env, napi_callback_info info) : env_(env), info_(info) {} - -NFuncArg::~NFuncArg() {} - -void NFuncArg::SetArgc(size_t argc) -{ - argc_ = argc; -} -void NFuncArg::SetThisVar(napi_value thisVar) -{ - thisVar_ = thisVar; -} - -size_t NFuncArg::GetArgc(void) const -{ - return argc_; -} - -napi_value NFuncArg::GetThisVar(void) const -{ - return thisVar_; -} - -napi_value NFuncArg::GetArg(size_t argPos) const -{ - return (argPos < GetArgc()) ? argv_[argPos] : nullptr; -} - -napi_value NFuncArg::operator[](size_t argPos) const -{ - return GetArg(argPos); -} - -bool NFuncArg::InitArgs(std::function argcChecker) -{ - SetArgc(0); - argv_.reset(); - - size_t argc; - napi_value thisVar; - napi_status status = napi_get_cb_info(env_, info_, &argc, nullptr, &thisVar, nullptr); - if (status != napi_ok) { - HILOGE("Cannot get num of func args for %{public}d", status); - return false; - } - if (argc) { - argv_ = make_unique(argc); - status = napi_get_cb_info(env_, info_, &argc, argv_.get(), &thisVar, nullptr); - if (status != napi_ok) { - HILOGE("Cannot get func args for %{public}d", status); - return false; - } - } - SetArgc(argc); - SetThisVar(thisVar); - - return argcChecker(); -} - -bool NFuncArg::InitArgs(size_t argc) -{ - return InitArgs([argc, this]() { - size_t realArgc = GetArgc(); - if (argc != realArgc) { - HILOGE("Num of args recved eq %zu while expecting %{public}zu", realArgc, argc); - return false; - } - return true; - }); -} - -bool NFuncArg::InitArgs(size_t minArgc, size_t maxArgc) -{ - return InitArgs([minArgc, maxArgc, this]() { - size_t realArgc = GetArgc(); - if (minArgc > realArgc || maxArgc < realArgc) { - HILOGE("Num of args recved eq %zu while expecting %{public}zu ~ %{public}zu", realArgc, minArgc, maxArgc); - return false; - } - return true; - }); -} -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/common/napi/n_func_arg.h b/interfaces/kits/js/src/common/napi/n_func_arg.h deleted file mode 100644 index 7ff5b2942..000000000 --- a/interfaces/kits/js/src/common/napi/n_func_arg.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include - -#include "n_val.h" -#include "uni_header.h" - -namespace OHOS { -namespace DistributedFS { -enum NARG_CNT { - ZERO = 0, - ONE = 1, - TWO = 2, - THREE = 3, - FOUR = 4, -}; - -enum NARG_POS { - FIRST = 0, - SECOND = 1, - THIRD = 2, - FOURTH = 3, -}; - -class NFuncArg final { -public: - NFuncArg(napi_env env, napi_callback_info info); - virtual ~NFuncArg(); - - bool InitArgs(size_t argc); - bool InitArgs(size_t minArgc, size_t maxArgc); - - size_t GetArgc() const; - napi_value GetThisVar() const; - - napi_value operator[](size_t idx) const; - napi_value GetArg(size_t argPos) const; - -private: - napi_env env_ = nullptr; - napi_callback_info info_ = nullptr; - - size_t argc_ = 0; - std::unique_ptr argv_ = { nullptr }; - napi_value thisVar_ = nullptr; - - bool InitArgs(std::function argcChecker); - - void SetArgc(size_t argc); - void SetThisVar(napi_value thisVar); -}; -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_val.cpp b/interfaces/kits/js/src/common/napi/n_val.cpp deleted file mode 100644 index 6a234449d..000000000 --- a/interfaces/kits/js/src/common/napi/n_val.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "n_val.h" - -#include - -#include "../log.h" -#include "../uni_error.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -NVal::NVal(napi_env nEnv, napi_value nVal = nullptr) : env_(nEnv), val_(nVal) {} - -NVal::operator bool() const -{ - return env_ && val_; -} - -bool NVal::TypeIs(napi_valuetype expType) const -{ - if (!*this) { - return false; - } - napi_valuetype valueType; - napi_typeof(env_, val_, &valueType); - - if (expType != valueType) { - return false; - } - return true; -} - -bool NVal::TypeIsError(bool checkErrno) const -{ - if (!*this) { - return false; - } - - bool res = false; - napi_is_error(env_, val_, &res); - - return res; -} - -tuple, size_t> NVal::ToUTF8String() const -{ - size_t strLen = 0; - napi_status status = napi_get_value_string_utf8(env_, val_, nullptr, -1, &strLen); - if (status != napi_ok) { - return { false, nullptr, 0 }; - } - - size_t bufLen = strLen + 1; - unique_ptr str = make_unique(bufLen); - status = napi_get_value_string_utf8(env_, val_, str.get(), bufLen, &strLen); - return make_tuple(status == napi_ok, move(str), strLen); -} - -tuple, size_t> NVal::ToUTF16String() const -{ -#ifdef FILE_SUBSYSTEM_DEV_ON_PC - size_t strLen = 0; - napi_status status = napi_get_value_string_utf16(env_, val_, nullptr, -1, &strLen); - if (status != napi_ok) { - return { false, nullptr, 0 }; - } - - auto str = make_unique(++strLen); - status = napi_get_value_string_utf16(env_, val_, str.get(), strLen, nullptr); - if (status != napi_ok) { - return { false, nullptr, 0 }; - } - - strLen = reinterpret_cast(str.get() + strLen) - reinterpret_cast(str.get()); - auto strRet = unique_ptr(reinterpret_cast(str.release())); - return { true, move(strRet), strLen }; -#else - // Note that quickjs doesn't support utf16 - return ToUTF8String(); -#endif -} - -tuple NVal::ToPointer() const -{ - void *res = nullptr; - napi_status status = napi_get_value_external(env_, val_, &res); - return make_tuple(status == napi_ok, res); -} - -tuple NVal::ToBool() const -{ - bool flag = false; - napi_status status = napi_get_value_bool(env_, val_, &flag); - return make_tuple(status == napi_ok, flag); -} - -tuple NVal::ToInt32() const -{ - int32_t res = 0; - napi_status status = napi_get_value_int32(env_, val_, &res); - return make_tuple(status == napi_ok, res); -} - -tuple NVal::ToInt64() const -{ - int64_t res = 0; - napi_status status = napi_get_value_int64(env_, val_, &res); - return make_tuple(status == napi_ok, res); -} - -tuple NVal::ToArraybuffer() const -{ - void *buf = nullptr; - size_t bufLen = 0; - bool status = napi_get_arraybuffer_info(env_, val_, &buf, &bufLen); - return make_tuple(status == napi_ok, buf, bufLen); -} - -tuple NVal::ToTypedArray() const -{ - napi_typedarray_type type; - napi_value in_array_buffer = nullptr; - size_t byte_offset; - size_t length; - void *data = nullptr; - napi_status status = - napi_get_typedarray_info(env_, val_, &type, &length, (void **)&data, &in_array_buffer, &byte_offset); - return make_tuple(status == napi_ok, data, length); -} - -bool NVal::HasProp(string propName) const -{ - bool res = false; - - if (!env_ || !val_ || !TypeIs(napi_object)) - return false; - napi_status status = napi_has_named_property(env_, val_, propName.c_str(), &res); - return (status == napi_ok) && res; -} - -NVal NVal::GetProp(string propName) const -{ - if (!HasProp(propName)) { - return { env_, nullptr }; - } - napi_value prop = nullptr; - napi_status status = napi_get_named_property(env_, val_, propName.c_str(), &prop); - if (status != napi_ok) { - return { env_, nullptr }; - } - return NVal(env_, prop); -} - -bool NVal::AddProp(vector &&propVec) const -{ - if (!TypeIs(napi_valuetype::napi_object)) { - HILOGE("INNER BUG. Prop should only be added to objects"); - return false; - } - napi_status status = napi_define_properties(env_, val_, propVec.size(), propVec.data()); - if (status != napi_ok) { - HILOGE("INNER BUG. Cannot define properties because of %{public}d", status); - return false; - } - return true; -} - -bool NVal::AddProp(string propName, napi_value val) const -{ - if (!TypeIs(napi_valuetype::napi_object) || HasProp(propName)) { - HILOGE("INNER BUG. Prop should only be added to objects"); - return false; - } - - napi_status status = napi_set_named_property(env_, val_, propName.c_str(), val); - if (status != napi_ok) { - HILOGE("INNER BUG. Cannot set named property because of %{public}d", status); - return false; - } - return true; -} - -NVal NVal::CreateUndefined(napi_env env) -{ - napi_value res = nullptr; - napi_get_undefined(env, &res); - return { env, res }; -} - -NVal NVal::CreateInt64(napi_env env, int64_t val) -{ - napi_value res = nullptr; - napi_create_int64(env, val, &res); - return { env, res }; -} - -NVal NVal::CreateInt32(napi_env env, int32_t val) -{ - napi_value res = nullptr; - napi_create_int32(env, val, &res); - return { env, res }; -} - -NVal NVal::CreateObject(napi_env env) -{ - napi_value res = nullptr; - napi_create_object(env, &res); - return { env, res }; -} - -NVal NVal::CreateBool(napi_env env, bool val) -{ - napi_value res = nullptr; - napi_get_boolean(env, val, &res); - return { env, res }; -} - -NVal NVal::CreateUTF8String(napi_env env, std::string str) -{ - napi_value res = nullptr; - napi_create_string_utf8(env, str.c_str(), str.length(), &res); - return { env, res }; -} - -NVal NVal::CreateUint8Array(napi_env env, void *buf, size_t bufLen) -{ - napi_value output_buffer = nullptr; - napi_create_external_arraybuffer( - env, - buf, - bufLen, - [](napi_env env, void *finalize_data, void *finalize_hint) { free(finalize_data); }, - NULL, - &output_buffer); - napi_value output_array = nullptr; - napi_create_typedarray(env, napi_uint8_array, bufLen, output_buffer, 0, &output_array); - return { env, output_array }; -} - -napi_property_descriptor NVal::DeclareNapiProperty(const char *name, napi_value val) -{ - return { (name), nullptr, nullptr, nullptr, nullptr, val, napi_default, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiStaticProperty(const char *name, napi_value val) -{ - return { (name), nullptr, nullptr, nullptr, nullptr, val, napi_static, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiFunction(const char *name, napi_callback func) -{ - return { (name), nullptr, (func), nullptr, nullptr, nullptr, napi_default, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiStaticFunction(const char *name, napi_callback func) -{ - return { (name), nullptr, (func), nullptr, nullptr, nullptr, napi_static, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiGetter(const char *name, napi_callback getter) -{ - return { (name), nullptr, nullptr, (getter), nullptr, nullptr, napi_default, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiSetter(const char *name, napi_callback setter) -{ - return { (name), nullptr, nullptr, nullptr, (setter), nullptr, napi_default, nullptr }; -} - -napi_property_descriptor NVal::DeclareNapiGetterSetter(const char *name, napi_callback getter, napi_callback setter) -{ - return { (name), nullptr, nullptr, (getter), (setter), nullptr, napi_default, nullptr }; -} -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/n_val.h b/interfaces/kits/js/src/common/napi/n_val.h deleted file mode 100644 index c772b9c5e..000000000 --- a/interfaces/kits/js/src/common/napi/n_val.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef N_VAL_H -#define N_VAL_H - -#include "uni_header.h" - -namespace OHOS { -namespace DistributedFS { -class NVal final { -public: - NVal() = default; - NVal(napi_env nEnv, napi_value nVal); - NVal(const NVal &) = default; - NVal &operator = (const NVal &) = default; - virtual ~NVal() = default; - - // NOTE! env_ and val_ is LIKELY to be null - napi_env env_ = nullptr; - napi_value val_ = nullptr; - - explicit operator bool() const; - bool TypeIs(napi_valuetype expType) const; - bool TypeIsError(bool checkErrno = false) const; - - /* SHOULD ONLY BE USED FOR EXPECTED TYPE */ - std::tuple, size_t> ToUTF8String() const; - std::tuple, size_t> ToUTF16String() const; - std::tuple ToPointer() const; - std::tuple ToBool() const; - std::tuple ToInt32() const; - std::tuple ToInt64() const; - std::tuple ToArraybuffer() const; - std::tuple ToTypedArray() const; - - /* Static helpers to create js objects */ - static NVal CreateUndefined(napi_env env); - static NVal CreateInt64(napi_env env, int64_t val); - static NVal CreateInt32(napi_env env, int32_t val); - static NVal CreateObject(napi_env env); - static NVal CreateBool(napi_env env, bool val); - static NVal CreateUTF8String(napi_env env, std::string str); - static NVal CreateUint8Array(napi_env env, void *buf, size_t bufLen); - - /* SHOULD ONLY BE USED FOR OBJECT */ - bool HasProp(std::string propName) const; - NVal GetProp(std::string propName) const; - bool AddProp(std::vector &&propVec) const; - bool AddProp(std::string propName, napi_value nVal) const; - - /* Static helpers to create prop of js objects */ - static napi_property_descriptor DeclareNapiProperty(const char *name, napi_value val); - static napi_property_descriptor DeclareNapiStaticProperty(const char *name, napi_value val); - static napi_property_descriptor DeclareNapiFunction(const char *name, napi_callback func); - static napi_property_descriptor DeclareNapiStaticFunction(const char *name, napi_callback func); - static napi_property_descriptor DeclareNapiGetter(const char *name, napi_callback getter); - static napi_property_descriptor DeclareNapiSetter(const char *name, napi_callback setter); - static inline napi_property_descriptor DeclareNapiGetterSetter(const char *name, - napi_callback getter, - napi_callback setter); -}; -} // namespace DistributedFS -} // namespace OHOS -#endif // N_VAL_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/napi/uni_header.h b/interfaces/kits/js/src/common/napi/uni_header.h deleted file mode 100644 index a79d4e1ed..000000000 --- a/interfaces/kits/js/src/common/napi/uni_header.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#ifdef FILE_SUBSYSTEM_DEV_ON_PC -#include -#else -#include "napi/native_api.h" -#include "napi/native_node_api.h" -#endif diff --git a/interfaces/kits/js/src/common/uni_error.cpp b/interfaces/kits/js/src/common/uni_error.cpp deleted file mode 100644 index 010aa3dad..000000000 --- a/interfaces/kits/js/src/common/uni_error.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "uni_error.h" - -#include -#include - -#include "log.h" -#include "napi/n_val.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -UniError::UniError() {} - -UniError::UniError(ELegacy eLegacy) : errno_(eLegacy), codingSystem_(ERR_CODE_SYSTEM_LEGACY) {} - -UniError::UniError(int ePosix) : errno_(ePosix), codingSystem_(ERR_CODE_SYSTEM_POSIX) {} - -UniError::operator bool() const -{ - return errno_ != ERRNO_NOERR; -} - -int UniError::GetErrno(ErrCodeSystem cs) -{ - if (errno_ == ERRNO_NOERR) { - return ERRNO_NOERR; - } - if (cs == codingSystem_) { - return errno_; - } - - if (cs == ERR_CODE_SYSTEM_POSIX) { - // Note that we should support more codes here - return EINVAL; - } - - // Note that this shall be done properly - return ELEGACY_INVAL; -} - -void UniError::SetErrno(ELegacy eLegacy) -{ - errno_ = eLegacy; - codingSystem_ = ERR_CODE_SYSTEM_LEGACY; -} - -void UniError::SetErrno(int ePosix) -{ - errno_ = ePosix; - codingSystem_ = ERR_CODE_SYSTEM_POSIX; -} - -std::string UniError::GetDefaultErrstr() -{ - if (codingSystem_ != ERR_CODE_SYSTEM_POSIX && codingSystem_ != ERR_CODE_SYSTEM_LEGACY) { - return "BUG: Curious coding system"; - } - return strerror(GetErrno(ERR_CODE_SYSTEM_POSIX)); -} - -napi_value UniError::GetNapiErr(napi_env env) -{ - return GetNapiErr(env, GetDefaultErrstr()); -} - -napi_value UniError::GetNapiErr(napi_env env, string errMsg) -{ - napi_value code = NVal::CreateUTF8String(env, to_string(GetErrno(codingSystem_))).val_; - napi_value msg = NVal::CreateUTF8String(env, errMsg).val_; - - napi_value res = nullptr; - napi_status createRes = napi_create_error(env, code, msg, &res); - if (createRes) { - HILOGE("Failed to create an exception, msg = %{public}s", errMsg.c_str()); - } - return res; -} - -void UniError::ThrowErr(napi_env env) -{ - string msg = GetDefaultErrstr(); - napi_value tmp = nullptr; - napi_get_and_clear_last_exception(env, &tmp); - // Note that ace engine cannot thow errors created by napi_create_error so far - napi_status throwStatus = napi_throw_error(env, nullptr, msg.c_str()); - if (throwStatus != napi_ok) { - HILOGE("Failed to throw an exception, %{public}d, code = %{public}s", throwStatus, msg.c_str()); - } -} - -void UniError::ThrowErr(napi_env env, string errMsg) -{ - napi_value tmp = nullptr; - napi_get_and_clear_last_exception(env, &tmp); - // Note that ace engine cannot thow errors created by napi_create_error so far - napi_status throwStatus = napi_throw_error(env, nullptr, errMsg.c_str()); - if (throwStatus != napi_ok) { - HILOGE("Failed to throw an exception, %{public}d, code = %{public}s", throwStatus, errMsg.c_str()); - } -} -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/common/uni_error.h b/interfaces/kits/js/src/common/uni_error.h deleted file mode 100644 index a4183986d..000000000 --- a/interfaces/kits/js/src/common/uni_error.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "napi/uni_header.h" - -namespace OHOS { -namespace DistributedFS { -constexpr int ERRNO_NOERR = 0; - -enum ELegacy { - ELEGACY_INVAL = 202, - ELEGACY_IO = 300, - ELEGACY_NOENT = 301, -}; - -enum ErrCodeSystem { - ERR_CODE_SYSTEM_LEGACY, - ERR_CODE_SYSTEM_POSIX, -}; - -class UniError { -public: - UniError(); - explicit UniError(ELegacy eLegacy); - explicit UniError(int ePosix); - ~UniError() = default; - - UniError &operator = (const UniError &) = default; - - explicit operator bool() const; - - void SetErrno(ELegacy eLegacy); - void SetErrno(int ePosix); - int GetErrno(ErrCodeSystem cs); - - std::string GetDefaultErrstr(); - napi_value GetNapiErr(napi_env env); - napi_value GetNapiErr(napi_env env, std::string errMsg); - void ThrowErr(napi_env env); - void ThrowErr(napi_env env, std::string errMsg); - -private: - int errno_ = ERRNO_NOERR; - ErrCodeSystem codingSystem_ = ERR_CODE_SYSTEM_POSIX; -}; -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_document/document_n_exporter.cpp b/interfaces/kits/js/src/mod_document/document_n_exporter.cpp deleted file mode 100644 index eacc54f8d..000000000 --- a/interfaces/kits/js/src/mod_document/document_n_exporter.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "document_n_exporter.h" - -#include -#include - -#include "../common/napi/n_class.h" -#include "../common/napi/n_func_arg.h" -#include "../common/napi/n_val.h" -#include "../common/uni_error.h" - -#include "../common/napi/n_async/n_async_work_callback.h" -#include "../common/napi/n_async/n_async_work_promise.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleDocument { -napi_value Choose(napi_env env, napi_callback_info info) -{ - UniError(EINVAL).ThrowErr(env, "error"); -} - -napi_value Show(napi_env env, napi_callback_info info) -{ - UniError(EINVAL).ThrowErr(env, "error"); -} -} // namespace ModuleDocument -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_document/document_n_exporter.h b/interfaces/kits/js/src/mod_document/document_n_exporter.h deleted file mode 100644 index 653e1e6c7..000000000 --- a/interfaces/kits/js/src/mod_document/document_n_exporter.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DOCUMENT_N_EXPORTER_H -#define DOCUMENT_N_EXPORTER_H - -#include "../common/napi/n_exporter.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleDocument { -napi_value Choose(napi_env env, napi_callback_info info); -napi_value Show(napi_env env, napi_callback_info info); -} // namespace ModuleDocument -} // namespace DistributedFS -} // namespace OHOS -#endif // DOCUMENT_N_EXPORTER_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_document/document_napi.cpp b/interfaces/kits/js/src/mod_document/document_napi.cpp deleted file mode 100644 index 0d277c581..000000000 --- a/interfaces/kits/js/src/mod_document/document_napi.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "napi/native_api.h" -#include "napi/native_node_api.h" - -#include "document_n_exporter.h" -#include "document_napi.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleDocument { -/*********************************************** - * Module export and register - ***********************************************/ -napi_value DocumentExport(napi_env env, napi_value exports) -{ - static napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("choose", Choose), - DECLARE_NAPI_FUNCTION("show", Show), - }; - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - return exports; -} - -NAPI_MODULE(document, DocumentExport) -} // namespace ModuleDocument -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_document/document_napi.h b/interfaces/kits/js/src/mod_document/document_napi.h deleted file mode 100644 index 80cdd7c8b..000000000 --- a/interfaces/kits/js/src/mod_document/document_napi.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DOCUMENT_NAPI_H -#define DOCUMENT_NAPI_H - -#include "napi/native_api.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleDocument { -} // namespace ModuleDocument -} // namespace DistributedFS -} // namespace OHOS -#endif // DOCUMENT_NAPI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.cpp b/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.cpp deleted file mode 100644 index ff857cb08..000000000 --- a/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.cpp +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "statfs_n_exporter.h" - -#include -#include - -#include "../common/napi/n_class.h" -#include "../common/napi/n_func_arg.h" -#include "../common/napi/n_val.h" -#include "../common/uni_error.h" - -#include "../common/napi/n_async/n_async_work_callback.h" -#include "../common/napi/n_async/n_async_work_promise.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleStatfs { -napi_value GetFrSizeSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env, "Failed get info"); - return nullptr; - } - unsigned long long freeSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_bavail); - return NVal::CreateInt64(env, freeSize).val_; -} - -napi_value GetFrSize(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_bavail); - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetFrSize"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetBSizeSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateInt64(env, diskInfo.f_bsize).val_; -} - -napi_value GetBSize(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = diskInfo.f_bsize; - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetBSize"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetBAvailSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateInt64(env, diskInfo.f_bavail).val_; -} - -napi_value GetBAvail(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = diskInfo.f_bavail; - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetBAvail"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetBlocksSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateInt64(env, diskInfo.f_blocks).val_; -} - -napi_value GetBlocks(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = diskInfo.f_blocks; - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetBlocks"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetBFreeSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateInt64(env, diskInfo.f_bfree).val_; -} - -napi_value GetBFree(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = diskInfo.f_bfree; - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetBFree"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetFreeBytesSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - unsigned long long freeSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_bfree); - return NVal::CreateInt64(env, freeSize).val_; -} - -napi_value GetFreeBytes(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_bfree); - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return NVal::CreateInt64(env, *resultSize); - }; - - std::string procedureName = "GetFreeBytes"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} - -napi_value GetTotalBytesSync(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - struct statvfs diskInfo; - int ret = statvfs(path.get(), &diskInfo); - if (ret != 0) { - UniError(errno).ThrowErr(env); - return nullptr; - } - unsigned long long totalSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_blocks); - return NVal::CreateInt64(env, totalSize).val_; -} - -napi_value GetTotalBytes(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - bool succ = false; - std::unique_ptr path; - tie(succ, path, std::ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto resultSize = std::make_shared(); - std::string pathString(path.get()); - auto cbExec = [pathString, resultSize](napi_env env) -> UniError { - struct statvfs diskInfo; - int ret = statvfs(pathString.c_str(), &diskInfo); - if (ret != 0) { - return UniError(errno); - } - *resultSize = - static_cast(diskInfo.f_bsize) * static_cast(diskInfo.f_blocks); - return UniError(ERRNO_NOERR); - }; - auto cbComplete = [resultSize](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateInt64(env, *resultSize) }; - }; - - std::string procedureName = "GetTotalBytes"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::ONE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::SECOND]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } - return NVal::CreateUndefined(env).val_; -} -} // namespace ModuleStatfs -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.h b/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.h deleted file mode 100644 index ddee8c664..000000000 --- a/interfaces/kits/js/src/mod_statfs/statfs_n_exporter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef STATFS_N_EXPORTER_H -#define STATFS_N_EXPORTER_H - -#include "../common/napi/n_exporter.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleStatfs { -napi_value GetFrSizeSync(napi_env env, napi_callback_info info); -napi_value GetFrSize(napi_env env, napi_callback_info info); - -napi_value GetBSizeSync(napi_env env, napi_callback_info info); -napi_value GetBSize(napi_env env, napi_callback_info info); - -napi_value GetBAvailSync(napi_env env, napi_callback_info info); -napi_value GetBAvail(napi_env env, napi_callback_info info); - -napi_value GetBlocksSync(napi_env env, napi_callback_info info); -napi_value GetBlocks(napi_env env, napi_callback_info info); - -napi_value GetBFreeSync(napi_env env, napi_callback_info info); -napi_value GetBFree(napi_env env, napi_callback_info info); - -napi_value GetFreeBytesSync(napi_env env, napi_callback_info info); -napi_value GetFreeBytes(napi_env env, napi_callback_info info); - -napi_value GetTotalBytesSync(napi_env env, napi_callback_info info); -napi_value GetTotalBytes(napi_env env, napi_callback_info info); -} // namespace ModuleStatfs -} // namespace DistributedFS -} // namespace OHOS -#endif // STATFS_N_EXPORTER_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_statfs/statfs_napi.cpp b/interfaces/kits/js/src/mod_statfs/statfs_napi.cpp deleted file mode 100644 index e25fddf19..000000000 --- a/interfaces/kits/js/src/mod_statfs/statfs_napi.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "statfs_napi.h" -#include "statfs_n_exporter.h" - -#include "napi/native_api.h" -#include "napi/native_node_api.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleStatfs { -/*********************************************** - * Module export and register - ***********************************************/ -napi_value StatfsExport(napi_env env, napi_value exports) -{ - static napi_property_descriptor desc[] = { - DECLARE_NAPI_FUNCTION("getFreeBytes", GetFreeBytes), - DECLARE_NAPI_FUNCTION("getTotalBytes", GetTotalBytes), - }; - NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc)); - return exports; -} - -NAPI_MODULE(statfs, StatfsExport) -} // namespace ModuleStatfs -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_statfs/statfs_napi.h b/interfaces/kits/js/src/mod_statfs/statfs_napi.h deleted file mode 100644 index a08b1f281..000000000 --- a/interfaces/kits/js/src/mod_statfs/statfs_napi.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef STATFS_NAPI_H -#define STATFS_NAPI_H - -#include "napi/native_api.h" - -namespace OHOS { -namespace DistributedFS { -namespace ModuleStatfs { -} // namespace ModuleStatfs -} // namespace DistributedFS -} // namespace OHOS -#endif // STATFS_NAPI_H \ No newline at end of file -- Gitee