From a84e98b8bc6940257c5fb7d2da99391785c91738 Mon Sep 17 00:00:00 2001 From: haonan_7 Date: Tue, 22 Mar 2022 17:19:05 +0800 Subject: [PATCH 1/2] add mod_document Signed-off-by: haonan_7 --- interfaces/kits/js/@ohos.document.d.ts | 63 +++++++++++++++++++ .../src/mod_document/document_n_exporter.cpp | 43 +++++++++++++ .../js/src/mod_document/document_n_exporter.h | 30 +++++++++ .../js/src/mod_document/document_napi.cpp | 41 ++++++++++++ .../kits/js/src/mod_document/document_napi.h | 27 ++++++++ 5 files changed, 204 insertions(+) create mode 100644 interfaces/kits/js/@ohos.document.d.ts create mode 100644 interfaces/kits/js/src/mod_document/document_n_exporter.cpp create mode 100644 interfaces/kits/js/src/mod_document/document_n_exporter.h create mode 100644 interfaces/kits/js/src/mod_document/document_napi.cpp create mode 100644 interfaces/kits/js/src/mod_document/document_napi.h diff --git a/interfaces/kits/js/@ohos.document.d.ts b/interfaces/kits/js/@ohos.document.d.ts new file mode 100644 index 000000000..1333942fe --- /dev/null +++ b/interfaces/kits/js/@ohos.document.d.ts @@ -0,0 +1,63 @@ +/* + * 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/src/mod_document/document_n_exporter.cpp b/interfaces/kits/js/src/mod_document/document_n_exporter.cpp new file mode 100644 index 000000000..6901de715 --- /dev/null +++ b/interfaces/kits/js/src/mod_document/document_n_exporter.cpp @@ -0,0 +1,43 @@ +/* + * 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 new file mode 100644 index 000000000..6342d41e2 --- /dev/null +++ b/interfaces/kits/js/src/mod_document/document_n_exporter.h @@ -0,0 +1,30 @@ +/* + * 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 new file mode 100644 index 000000000..0d277c581 --- /dev/null +++ b/interfaces/kits/js/src/mod_document/document_napi.cpp @@ -0,0 +1,41 @@ +/* + * 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 new file mode 100644 index 000000000..80cdd7c8b --- /dev/null +++ b/interfaces/kits/js/src/mod_document/document_napi.h @@ -0,0 +1,27 @@ +/* + * 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 -- Gitee From 04d98c7f5509c88a172a2502d4eb9ba53fd49bfe Mon Sep 17 00:00:00 2001 From: haonan_7 Date: Tue, 22 Mar 2022 17:59:37 +0800 Subject: [PATCH 2/2] add mod_document Signed-off-by: haonan_7 --- interfaces/kits/js/src/mod_document/document_n_exporter.cpp | 4 ++-- interfaces/kits/js/src/mod_document/document_n_exporter.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_document/document_n_exporter.cpp b/interfaces/kits/js/src/mod_document/document_n_exporter.cpp index 6901de715..eacc54f8d 100644 --- a/interfaces/kits/js/src/mod_document/document_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_document/document_n_exporter.cpp @@ -31,12 +31,12 @@ namespace DistributedFS { namespace ModuleDocument { napi_value Choose(napi_env env, napi_callback_info info) { - UniError(EINVAL).ThrowErr(env, "error"); + UniError(EINVAL).ThrowErr(env, "error"); } napi_value Show(napi_env env, napi_callback_info info) { - UniError(EINVAL).ThrowErr(env, "error"); + UniError(EINVAL).ThrowErr(env, "error"); } } // namespace ModuleDocument } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_document/document_n_exporter.h b/interfaces/kits/js/src/mod_document/document_n_exporter.h index 6342d41e2..653e1e6c7 100644 --- a/interfaces/kits/js/src/mod_document/document_n_exporter.h +++ b/interfaces/kits/js/src/mod_document/document_n_exporter.h @@ -23,7 +23,6 @@ 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 -- Gitee