From 8fadea3c7d5692a0208c77829c225e23d33de4f9 Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 23 Nov 2021 16:13:47 +0800 Subject: [PATCH 1/9] add fms code 1.fms_service 2.fms_proxy 3.fms_stub 3.fms_napi Signed-off-by: panqiangbiao --- LICENSE | 177 ++++++++++ README.md | 84 +++-- interfaces/kits/js/BUILD.gn | 67 ++++ .../src/common/napi/n_async/n_async_context.h | 69 ++++ .../napi/n_async/n_async_work_callback.cpp | 103 ++++++ .../napi/n_async/n_async_work_callback.h | 37 +++ .../napi/n_async/n_async_work_factory.h | 35 ++ .../napi/n_async/n_async_work_promise.cpp | 98 ++++++ .../napi/n_async/n_async_work_promise.h | 36 +++ .../kits/js/src/common/napi/n_async/n_ref.cpp | 53 +++ .../kits/js/src/common/napi/n_async/n_ref.h | 37 +++ .../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 | 306 ++++++++++++++++++ interfaces/kits/js/src/common/napi/n_val.h | 79 +++++ .../kits/js/src/common/napi/uni_header.h | 23 ++ interfaces/kits/js/src/common/uni_error.cpp | 122 +++++++ interfaces/kits/js/src/common/uni_error.h | 64 ++++ interfaces/kits/js/src/fms_napi.cpp | 207 ++++++++++++ interfaces/kits/js/src/fms_napi.h | 38 +++ interfaces/kits/js/src/module.cpp | 47 +++ ohos.build | 12 + sa_profile/4933.xml | 28 ++ sa_profile/BUILD.gn | 20 ++ services/BUILD.gn | 87 +++++ services/etc/fms_service.cfg | 14 + services/etc/fms_service.rc | 20 ++ services/include/fms_const.h | 36 +++ services/include/log.h | 78 +++++ services/src/client/fms_proxy.cpp | 139 ++++++++ services/src/client/fms_proxy.h | 38 +++ services/src/client/ifms_client.h | 32 ++ services/src/fileoper/fms_file_oper.h | 34 ++ services/src/fileoper/fms_fileinfo.h | 66 ++++ services/src/fileoper/fms_mediafile_oper.cpp | 196 +++++++++++ services/src/fileoper/fms_mediafile_oper.h | 31 ++ services/src/fileoper/fms_oper_factory.cpp | 34 ++ services/src/fileoper/fms_oper_factory.h | 29 ++ services/src/server/fms_service.cpp | 46 +++ services/src/server/fms_service.h | 41 +++ services/src/server/fms_service_stub.cpp | 110 +++++++ services/src/server/fms_service_stub.h | 46 +++ services/test/BUILD.gn | 52 +++ services/test/fms_test.cpp | 57 ++++ 47 files changed, 3303 insertions(+), 27 deletions(-) create mode 100644 LICENSE create mode 100644 interfaces/kits/js/BUILD.gn create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_context.h create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_ref.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_async/n_ref.h create mode 100644 interfaces/kits/js/src/common/napi/n_class.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_class.h create mode 100644 interfaces/kits/js/src/common/napi/n_exporter.h create mode 100644 interfaces/kits/js/src/common/napi/n_func_arg.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_func_arg.h create mode 100644 interfaces/kits/js/src/common/napi/n_val.cpp create mode 100644 interfaces/kits/js/src/common/napi/n_val.h create mode 100644 interfaces/kits/js/src/common/napi/uni_header.h create mode 100644 interfaces/kits/js/src/common/uni_error.cpp create mode 100644 interfaces/kits/js/src/common/uni_error.h create mode 100644 interfaces/kits/js/src/fms_napi.cpp create mode 100644 interfaces/kits/js/src/fms_napi.h create mode 100644 interfaces/kits/js/src/module.cpp create mode 100644 ohos.build create mode 100644 sa_profile/4933.xml create mode 100644 sa_profile/BUILD.gn create mode 100644 services/BUILD.gn create mode 100644 services/etc/fms_service.cfg create mode 100644 services/etc/fms_service.rc create mode 100644 services/include/fms_const.h create mode 100644 services/include/log.h create mode 100644 services/src/client/fms_proxy.cpp create mode 100644 services/src/client/fms_proxy.h create mode 100644 services/src/client/ifms_client.h create mode 100644 services/src/fileoper/fms_file_oper.h create mode 100644 services/src/fileoper/fms_fileinfo.h create mode 100644 services/src/fileoper/fms_mediafile_oper.cpp create mode 100644 services/src/fileoper/fms_mediafile_oper.h create mode 100644 services/src/fileoper/fms_oper_factory.cpp create mode 100644 services/src/fileoper/fms_oper_factory.h create mode 100644 services/src/server/fms_service.cpp create mode 100644 services/src/server/fms_service.h create mode 100644 services/src/server/fms_service_stub.cpp create mode 100644 services/src/server/fms_service_stub.h create mode 100644 services/test/BUILD.gn create mode 100644 services/test/fms_test.cpp diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..4947287f --- /dev/null +++ b/LICENSE @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/README.md b/README.md index 1b2468c0..12b248b0 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,69 @@ -# storage_user_file_manger +# File Mangaer Service公共文件管理服务 -#### 介绍 -{**以下是 Gitee 平台说明,您可以替换此简介** -Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN)。专为开发者提供稳定、高效、安全的云端软件开发协作平台 -无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)} +- [简介](#section1158716411637) +- [目录](#section161941989596) +- [使用说明](#usage-guidelines) + - [创建文件](#get-audioasset) +- [相关仓](#section1533973044317) -#### 软件架构 -软件架构说明 +## 简介 -#### 安装教程 +**File Mangaer Service**公共文件管理服务仓库提供了公共文件管理接口。File Mangaer Service接口暂不对外部应用开放, 仅内部使用。 -1. xxxx -2. xxxx -3. xxxx +支持能力列举如下: +- 公共文件路径下媒体文件查询,创建 +- 公共文件路径下文档文件查询、创建 -#### 使用说明 -1. xxxx -2. xxxx -3. xxxx +## 目录 -#### 参与贡献 +仓目录结构如下: +``` +/foundation/storage/user_file_manger # fms组件代码 +├── serivce # 框架代码 +│   ├── etc # 内部接口实现 +│   ├── src # 内部接口实现 +├── interfaces # 接口代码 +│   ├── innerkits # 内部 Native 接口 +│   └── kits # 外部 JS 接口 +├── LICENSE # 证书文件 +├── ohos.build # 编译文件 +├── sa_profile # 服务配置文件 +└── services # 服务实现 +``` -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +## 使用说明 +### 创建文件 +1. + ``` + 接口流程 + 应用通过接口让媒体库创建文件,返回文件uri, 应用自己通过openfile打开uri,获取fd进行文件操作。 + // 应用A + // 拉起filepicker 获取 uri + import media_library from '@ohos.media_library' + fd = media_library.openfile(uri) + fileio.write(fd, data) + fileio.close() -#### 特技 + // file picker 流程 + // media_path通过filepicker获取待保存目录uri + import filemanager from '@ohos.filemanager' + let media_path = "xxxx" + let name = "xxxx" + filemanager.createFile(name,media_path) + .then((uri) => { + // success + }) + .catch(function(err) { + //类型错误,重名... + // fail + }) -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) + // FMS + mediaLib.createAsset(name) + return fileuri + ``` + +## 相关仓 diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn new file mode 100644 index 00000000..607a7524 --- /dev/null +++ b/interfaces/kits/js/BUILD.gn @@ -0,0 +1,67 @@ +# 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("//build/ohos.gni") +FMS_BASE_DIR = "//foundation/storage/services" + +ohos_shared_library("filemanager") { + subsystem_name = "storage" + part_name = "filemanager" + + relative_install_dir = "module" + + include_dirs = [ + # "$BASE_DIR/napi", + "//third_party/node/src", + "//foundation/ace/napi/interfaces/kits", + "//utils/native/base/include", + "//third_party/libuv/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + ] + + sources = [ + "src/common/napi/n_async/n_async_work_callback.cpp", + "src/common/napi/n_async/n_async_work_promise.cpp", + "src/common/napi/n_async/n_ref.cpp", + "src/common/napi/n_class.cpp", + "src/common/napi/n_func_arg.cpp", + "src/common/napi/n_val.cpp", + "src/common/uni_error.cpp", + "src/module.cpp", + "src/fms_napi.cpp", + ] + + deps = [ + "//utils/native/base:utils", + "$FMS_BASE_DIR:fms_server", + "//foundation/ace/napi:ace_napi", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + + + + + 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 new file mode 100644 index 00000000..67dcdde7 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_context.h @@ -0,0 +1,69 @@ +/* + * 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 "../../uni_error.h" +#include "../n_val.h" +#include "../uni_header.h" +#include "n_ref.h" + +namespace OHOS { +namespace DistributedFS { +typedef std::function NContextCBExec; +typedef std::function NContextCBComplete; + +class NAsyncContext { +public: + UniError err_; + NVal res_; + NContextCBExec cbExec_; + NContextCBComplete cbComplete_; + napi_async_work awork_; + NRef thisPtr_; + + explicit NAsyncContext(NVal thisPtr) : thisPtr_(thisPtr) {} + ~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 \ 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 new file mode 100644 index 00000000..d9c05c02 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp @@ -0,0 +1,103 @@ +/* + * 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 +#include + +#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); +} +NAsyncWorkCallback::NAsyncWorkCallback(const NAsyncWorkCallback &in, napi_env env) : NAsyncWorkFactory(env) +{ + delete ctx_; + this->ctx_ = new NAsyncContextCallback(in.ctx_->thisPtr_.Deref(env), in.ctx_->cb_.Deref(env)); +} + +static void CallbackExecute(napi_env env, void *data) +{ + auto ctx = static_cast(data); + if (ctx->cbExec_) { + 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->cbComplete_) { + 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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..a700a4ef --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.h @@ -0,0 +1,37 @@ +/* + * 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 "n_async_work_factory.h" + +namespace OHOS { +namespace DistributedFS { +class NAsyncWorkCallback : public NAsyncWorkFactory { +public: + NAsyncWorkCallback(napi_env env, NVal thisPtr, NVal cb); + ~NAsyncWorkCallback() = default; + NAsyncWorkCallback(const NAsyncWorkCallback &in, napi_env env); + NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; + +private: + NAsyncContextCallback *ctx_ = nullptr; +}; +} // namespace DistributedFS +} // namespace OHOS \ 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 new file mode 100644 index 00000000..bd993e5d --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.h @@ -0,0 +1,35 @@ +/* + * 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 "n_async_context.h" + +namespace OHOS { +namespace DistributedFS { +class NAsyncWorkFactory { +public: + explicit NAsyncWorkFactory(napi_env env) : env_(env) {} + ~NAsyncWorkFactory() = default; + virtual NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) = 0; + + napi_env env_ = nullptr; +}; +} // namespace DistributedFS +} // namespace OHOS \ 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 new file mode 100644 index 00000000..727f8269 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.cpp @@ -0,0 +1,98 @@ +/* + * 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 +#include +#include + +#include "log.h" + +namespace OHOS { +namespace DistributedFS { +using namespace std; + +NAsyncWorkPromise::NAsyncWorkPromise(napi_env env, NVal thisPtr) : NAsyncWorkFactory(env) +{ + ctx_ = new NAsyncContextPromise(thisPtr); +} +NAsyncWorkPromise::NAsyncWorkPromise(const NAsyncWorkPromise &in, napi_env env) : NAsyncWorkFactory(env) +{ + delete ctx_; + ctx_ = new NAsyncContextPromise(in.ctx_->thisPtr_.Deref(env)); +} + +static void PromiseOnExec(napi_env env, void *data) +{ + auto ctx = static_cast(data); + if (ctx->cbExec_) { + ctx->err_ = ctx->cbExec_(env); + } +} +static void PromiseOnComplete(napi_env env, napi_status status, void *data) +{ + auto ctx = static_cast(data); + if (ctx->cbComplete_) { + 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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..9bef0eba --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h @@ -0,0 +1,36 @@ +/* + * 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 "n_async_work_factory.h" + +namespace OHOS { +namespace DistributedFS { +class NAsyncWorkPromise : public NAsyncWorkFactory { +public: + NAsyncWorkPromise(napi_env env, NVal thisPtr); + ~NAsyncWorkPromise() = default; + NAsyncWorkPromise(const NAsyncWorkPromise &in, napi_env env); + NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; + +private: + NAsyncContextPromise *ctx_; +}; +} // namespace DistributedFS +} // namespace OHOS \ 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 new file mode 100644 index 00000000..8b78ac9c --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_ref.cpp @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 00000000..12b216ab --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_async/n_ref.h @@ -0,0 +1,37 @@ +/* + * 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 "../n_val.h" +#include "../uni_header.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 diff --git a/interfaces/kits/js/src/common/napi/n_class.cpp b/interfaces/kits/js/src/common/napi/n_class.cpp new file mode 100644 index 00000000..c6c60ee9 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_class.cpp @@ -0,0 +1,99 @@ +/* + * 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) { + ERR_LOG("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 }); + INFO_LOG("Class %{public}s has been saved", className.c_str()); + } else { + ERR_LOG("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()) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..e048ae80 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_class.h @@ -0,0 +1,82 @@ +/* + * 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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..2ade0c07 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_exporter.h @@ -0,0 +1,39 @@ +/* + * 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 new file mode 100644 index 00000000..ed3a5ec7 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_func_arg.cpp @@ -0,0 +1,111 @@ +/* + * 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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..7ff5b294 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_func_arg.h @@ -0,0 +1,71 @@ +/* + * 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 new file mode 100644 index 00000000..79a35d63 --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_val.cpp @@ -0,0 +1,306 @@ +/* + * 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 + +#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)) { + ERR_LOG("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) { + ERR_LOG("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)) { + ERR_LOG("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) { + ERR_LOG("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::CreateInt32(napi_env env, int32_t val) +{ + napi_value res = nullptr; + napi_create_int32(env, val, &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::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::CreateUTF8String(napi_env env, const char* str, ssize_t len) +{ + napi_value res = nullptr; + napi_create_string_utf8(env, str, len, &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 }; +} +tuple NVal::CreateArrayBuffer(napi_env env, size_t len) +{ + napi_value val; + void *buf = nullptr; + napi_create_arraybuffer(env, len, &buf, &val); + return { { env, val }, { buf }}; +} + +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 new file mode 100644 index 00000000..0cb2f74a --- /dev/null +++ b/interfaces/kits/js/src/common/napi/n_val.h @@ -0,0 +1,79 @@ +/* + * 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 "sys/types.h" +#include "uni_header.h" +namespace OHOS { +namespace DistributedFS { +class NVal final { +public: + NVal() = default; + NVal(napi_env nEnv, napi_value nVal); + 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 CreateInt32(napi_env env, int32_t val); + static NVal CreateInt64(napi_env env, int64_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 CreateUTF8String(napi_env env, const char* str, ssize_t len); + static NVal CreateUint8Array(napi_env env, void *buf, size_t bufLen); + static std::tuple CreateArrayBuffer(napi_env env, size_t len); + /* 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 diff --git a/interfaces/kits/js/src/common/napi/uni_header.h b/interfaces/kits/js/src/common/napi/uni_header.h new file mode 100644 index 00000000..a79d4e1e --- /dev/null +++ b/interfaces/kits/js/src/common/napi/uni_header.h @@ -0,0 +1,23 @@ +/* + * 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 new file mode 100644 index 00000000..0f1e0882 --- /dev/null +++ b/interfaces/kits/js/src/common/uni_error.cpp @@ -0,0 +1,122 @@ +/* + * 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) +{ + if (!*this) { + return NVal::CreateUndefined(env).val_; + } + + 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) { + ERR_LOG("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) { + ERR_LOG("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) { + ERR_LOG("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 new file mode 100644 index 00000000..a4183986 --- /dev/null +++ b/interfaces/kits/js/src/common/uni_error.h @@ -0,0 +1,64 @@ +/* + * 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/fms_napi.cpp b/interfaces/kits/js/src/fms_napi.cpp new file mode 100644 index 00000000..77de6749 --- /dev/null +++ b/interfaces/kits/js/src/fms_napi.cpp @@ -0,0 +1,207 @@ +/* + * 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 "fms_napi.h" + +#include +#include +#include +#include +#include "common/napi/n_func_arg.h" +#include "common/uni_error.h" + +#include "common/napi/n_async/n_async_work_promise.h" +#include "common/napi/n_async/n_async_work_callback.h" +#include "sys/syscall.h" +#define gettid() syscall(__NR_gettid) + +#ifdef FILE_SUBSYSTEM_DEV_ON_PC +#define DEBUG_LOG(fmt, ...) +#endif +#ifndef FILE_SUBSYSTEM_DEV_ON_PC +#include "log.h" +#include "fms_proxy.h" +#include "ifms_client.h" +#endif +namespace OHOS { +namespace DistributedFS { +namespace FMS_NAPI { +using namespace std; +#ifndef FILE_SUBSYSTEM_DEV_ON_PC +using namespace FileManagerService; +#endif +struct AsyncFileInfoArg { + NRef _ref; +#ifndef FILE_SUBSYSTEM_DEV_ON_PC + vector fileRes; +#else + vector res; +#endif + explicit AsyncFileInfoArg(NVal ref) : _ref(ref) {}; + ~AsyncFileInfoArg() = default; +}; + +napi_value FMS_NAPI::CreateFile(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { + UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); + return nullptr; + } + bool succ = false; + unique_ptr name; + unique_ptr path; + tie(succ, name, ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Invalid name"); + return nullptr; + } + tie(succ, path, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String(); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Invalid path"); + return nullptr; + } + string uri = ""; +#ifndef FILE_SUBSYSTEM_DEV_ON_PC + FileManagerService::IFmsClient::GetFmsInstance()->CreateFile(name.get(), path.get(), uri); +#endif + return NVal::CreateUTF8String(env, uri).val_; +} + +napi_value FMS_NAPI::ListFile(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + + if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::THREE)) { + UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); + return nullptr; + } + + bool succ = false; + unique_ptr path; + tie(succ, path, ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Invalid path"); + return nullptr; + } + int64_t offset = 0; + int64_t count = 0; + bool hasOp = false; + // need to check SECOND valid ? + NVal op(env, NVal(env, funcArg[NARG_POS::SECOND]).val_); + if (op.HasProp("offset")) { + tie(succ, offset) = op.GetProp("offset").ToInt64(); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Invalid option"); + return nullptr; + } + hasOp = true; + } + + if (op.HasProp("count")) { + tie(succ, count) = op.GetProp("count").ToInt64(); + if (!succ) { + UniError(EINVAL).ThrowErr(env, "Invalid option"); + return nullptr; + } + hasOp = true; + } + napi_value fileArr; + napi_create_array(env, &fileArr); + auto arg = make_shared(NVal(env, fileArr)); + auto cbExec = [path = string(path.get()), offset, count, arg, fileArr] (napi_env env) -> UniError { +#ifndef FILE_SUBSYSTEM_DEV_ON_PC + int err = 0; + vector fileRes; + err = FileManagerService::IFmsClient::GetFmsInstance()->ListFile(path, offset, count, fileRes); + arg->fileRes = fileRes; + if (err) { + // need to add specific error + return UniError(EIO); + } +#else + vector resArr = {"name", "path", "type", "size", "added_time", "modified_time"}; + arg->res = resArr; +#endif + + return UniError(ERRNO_NOERR); + }; + + auto cbComplete = [arg](napi_env env, UniError err) -> NVal { +#ifndef FILE_SUBSYSTEM_DEV_ON_PC + for (unsigned int i = 0; i < arg->fileRes.size(); i++) { + NVal obj = NVal::CreateObject(env); + FileManagerService::FileInfo res = arg->fileRes[i]; + obj.AddProp("name", NVal::CreateUTF8String(env, res.GetName()).val_); + obj.AddProp("path", NVal::CreateUTF8String(env, res.GetPath()).val_); + obj.AddProp("type", NVal::CreateUTF8String(env, res.GetType()).val_); + obj.AddProp("size", NVal::CreateInt64(env, res.GetSize()).val_); + obj.AddProp("added_time", NVal::CreateInt64(env, res.GetAdded_Time()).val_); + obj.AddProp("modified_time", NVal::CreateInt64(env, res.GetModified_time()).val_); + napi_set_property(env, arg->_ref.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); + } +#else + vector resArr = {"name", "path", "type", "size", "added_time", "modified_time"}; + for (unsigned int i = 0; i < resArr.size(); i++) { + NVal obj = NVal::CreateObject(env); + for (auto s : arg->res) { + obj.AddProp(s, NVal::CreateUTF8String(env, s).val_); + } + napi_set_property(env, arg->_ref.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); + } +#endif + if (err) { + return { env, err.GetNapiErr(env) }; + } else { + return NVal(env, arg->_ref.Deref(env).val_); + } + }; + string procedureName = "ListFile"; + int argc = funcArg.GetArgc(); + NVal thisVar(env, funcArg.GetThisVar()); + if (argc == NARG_CNT::ONE || (argc == NARG_CNT::TWO && hasOp)) { + return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; + } else { + int cbIdx = ((hasOp == false) ? NARG_POS::SECOND : NARG_POS::THIRD); + NVal cb(env, funcArg[cbIdx]); + return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; + } +} + +napi_value FMS_NAPI::mkdir(napi_env env, napi_callback_info info) +{ + return NVal::CreateUndefined(env).val_; +} + +bool FMS_NAPI::Export() +{ + return exports_.AddProp({ + NVal::DeclareNapiFunction("listFile", ListFile), + NVal::DeclareNapiFunction("CreateFile", CreateFile), + NVal::DeclareNapiFunction("mkdir", mkdir), + }); +} + +string FMS_NAPI::GetClassName() +{ + return FMS_NAPI::className_; +} + +FMS_NAPI::FMS_NAPI(napi_env env, napi_value exports) : NExporter(env, exports) {} + +FMS_NAPI::~FMS_NAPI() {} +} // namespace FMS_NAPI +} // namespace DistributedFS +} // namespace OHOS diff --git a/interfaces/kits/js/src/fms_napi.h b/interfaces/kits/js/src/fms_napi.h new file mode 100644 index 00000000..2f5b8aec --- /dev/null +++ b/interfaces/kits/js/src/fms_napi.h @@ -0,0 +1,38 @@ +/* + * 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/n_exporter.h" + +namespace OHOS { +namespace DistributedFS { +namespace FMS_NAPI { +class FMS_NAPI final : public NExporter { +public: + inline static const std::string className_ = "__properities__"; + + static napi_value CreateFile(napi_env env, napi_callback_info info); + static napi_value ListFile(napi_env env, napi_callback_info info); + static napi_value mkdir(napi_env env, napi_callback_info info); + bool Export() override; + std::string GetClassName() override; + + FMS_NAPI(napi_env env, napi_value exports); + ~FMS_NAPI() override; +}; +} // namespace FMS_NAPI +} // namespace DistributedFS +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/module.cpp b/interfaces/kits/js/src/module.cpp new file mode 100644 index 00000000..f783e20a --- /dev/null +++ b/interfaces/kits/js/src/module.cpp @@ -0,0 +1,47 @@ +/* + * 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 +#include + +#include "fms_napi.h" +#include "log.h" + +using namespace std; + +namespace OHOS { +namespace DistributedFS { +namespace FMS_NAPI { + +static napi_value Export(napi_env env, napi_value exports) +{ + std::vector> products; + products.emplace_back(make_unique(env, exports)); + + for (auto &&product : products) { + if (!product->Export()) { + ERR_LOG("INNER BUG. Failed to export class %{public}s for module filemanager", product->GetClassName().c_str()); + return nullptr; + } else { + ERR_LOG("Class %{public}s for module filemanager has been exported", product->GetClassName().c_str()); + } + } + return exports; +} + +NAPI_MODULE(filemanager, Export) +} // namespace FMS_NAPI +} // namespace DistributedFS +} // namespace OHOS \ No newline at end of file diff --git a/ohos.build b/ohos.build new file mode 100644 index 00000000..ca16b782 --- /dev/null +++ b/ohos.build @@ -0,0 +1,12 @@ +{ + "subsystem": "storage", + "parts": { + "filemanager": { + "module_list": [ + "//foundation/storage/services:fms", + "//foundation/storage/sa_profile:filemanager_service_sa_profile", + "//foundation/storage/interfaces/kits/js:filemanager" + ] + } + } +} diff --git a/sa_profile/4933.xml b/sa_profile/4933.xml new file mode 100644 index 00000000..216eb6a8 --- /dev/null +++ b/sa_profile/4933.xml @@ -0,0 +1,28 @@ + + + + fms_service + + /system/lib/libfms_server.z.so + + + 4933 + /system/lib/libfms_server.z.so + true + false + 1 + + diff --git a/sa_profile/BUILD.gn b/sa_profile/BUILD.gn new file mode 100644 index 00000000..11b34990 --- /dev/null +++ b/sa_profile/BUILD.gn @@ -0,0 +1,20 @@ +# 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("//build/ohos/sa_profile/sa_profile.gni") + +ohos_sa_profile("filemanager_service_sa_profile") { + sources = [ "4933.xml" ] + + part_name = "filemanager" +} diff --git a/services/BUILD.gn b/services/BUILD.gn new file mode 100644 index 00000000..a7556ab9 --- /dev/null +++ b/services/BUILD.gn @@ -0,0 +1,87 @@ +# 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("//build/ohos.gni") +FMS_BASE_DIR = "//foundation/storage/services" + +group("fms") { + deps = [ + ":fms_service.rc", + ":fms_server", + ] +} + +ohos_prebuilt_etc("fms_service.rc") { + if (use_musl) { + source = "etc/fms_service.cfg" + } else { + source = "etc/fms_service.rc" + } + relative_install_dir = "init" + subsystem_name = "storage" + part_name = "filemanager" +} + + +ohos_shared_library("fms_server") { + subsystem_name = "storage" + part_name = "filemanager" + + include_dirs = [ + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + "$FMS_BASE_DIR/include/fileoper", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include/hilog", + ] + + sources = [ + "src/server/fms_service_stub.cpp", + "src/server/fms_service.cpp", + "src/fileoper/fms_mediafile_oper.cpp", + "src/fileoper/fms_oper_factory.cpp", + "src/client/fms_proxy.cpp", + ] + + deps = [ + "//utils/native/base:utils", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + "//foundation/multimedia/medialibrary_standard/frameworks/innerkitsimpl/medialibrary_data_ability:medialibrary_data_ability", + "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native", + "//foundation/aafwk/standard/interfaces/innerkits/base:base", + "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + "aafwk_standard:ability_manager", + "native_appdatamgr:native_appdatafwk", + "native_appdatamgr:native_dataability", + "native_appdatamgr:native_rdb", + ] +} + +# Unittest +group("test") { + testonly = true + + deps = [ "test:test" ] +} diff --git a/services/etc/fms_service.cfg b/services/etc/fms_service.cfg new file mode 100644 index 00000000..705fd897 --- /dev/null +++ b/services/etc/fms_service.cfg @@ -0,0 +1,14 @@ +{ + "jobs" : [{ + "name" : "boot", + "cmds" : [ + "start fms_service" + ] + } + ], + "services" : [{ + "name" : "fms_service", + "path" : ["/system/bin/sa_main", "/system/profile/fms_service.xml"] + } + ] +} diff --git a/services/etc/fms_service.rc b/services/etc/fms_service.rc new file mode 100644 index 00000000..41f1e4d1 --- /dev/null +++ b/services/etc/fms_service.rc @@ -0,0 +1,20 @@ +# 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. + +service fms_service /system/bin/sa_main /system/profile/fms_service.xml + class z_core + seclabel u:r:audiodistributedservice:s0 + +on boot + start fms_service + diff --git a/services/include/fms_const.h b/services/include/fms_const.h new file mode 100644 index 00000000..6c3afd21 --- /dev/null +++ b/services/include/fms_const.h @@ -0,0 +1,36 @@ +/* + * 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 +namespace OHOS { +namespace FileManagerService { +enum { + FMS_GET_ROOT, + FMS_MEDIA_START, + FMS_MEDIA_MKDIR, + FMS_MEDIA_LISTFILE, + FMS_MEDIA_CREATEFILE, + FMS_MEDIA_END, + FMS_EXTERNAL_START, + FMS_EXTERNAL_END, +}; +const int32_t SUCCESS = 0; +const int32_t FAIL = -1; +const int32_t E_NOEXIST = -2; +const int32_t E_EMPTYFOLDER = -3; + +} // namespace FileManagerService +} // namespace OHOS diff --git a/services/include/log.h b/services/include/log.h new file mode 100644 index 00000000..87bd8a21 --- /dev/null +++ b/services/include/log.h @@ -0,0 +1,78 @@ +/* + * 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 +#ifndef FILE_SUBSYSTEM_DEV_ON_PC +#include "hilog/log.h" +#endif + +#undef LOG_DOMAIN +#undef LOG_TAG +#define LOG_DOMAIN 0xD002B00 +#define LOG_TAG "Storage:FMS" + +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) + +#ifndef FILE_SUBSYSTEM_DEV_ON_PC +#ifndef OHOS_DEBUG +#define DECORATOR_HILOG(op, fmt, args...) \ + do { \ + op(LOG_CORE, fmt, ##args); \ + } while (0) +#else +#define DECORATOR_HILOG(op, fmt, args...) \ + do { \ + op(LOG_CORE, "{%s()-%s:%d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); \ + } while (0) +#endif + +#define DEBUG_LOG(fmt, args...) HILOG_DEBUG(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); +#define ERR_LOG(fmt, args...) HILOG_ERROR(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); +#define WARNING_LOG(fmt, args...) HILOG_WARN(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); +#define INFO_LOG(fmt, args...) HILOG_INFO(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##args); +#define FATAL_LOG(fmt, args...) HILOG_FATAL(LOG_CORE, "{%{public}s()-%{public}s:%{public}d} " fmt, __FUNCTION__, __FILENAME__, __LINE__, ##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 DEBUG_LOG(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) +#define INFO_LOG(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) +#define WARNING_LOG(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) +#define ERR_LOG(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) +#define FATAL_LOG(fmt, ...) PCLOG("%{public}s: " fmt, __func__, ##__VA_ARGS__) +#endif + +#define OK 0 +#define INVALID_PARAM (-1) +#define INIT_FAIL (-2) +#define ERR (-3) +#define PERMISSION_DENIED (-4) diff --git a/services/src/client/fms_proxy.cpp b/services/src/client/fms_proxy.cpp new file mode 100644 index 00000000..db9e1cb5 --- /dev/null +++ b/services/src/client/fms_proxy.cpp @@ -0,0 +1,139 @@ +/* + * 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 "fms_proxy.h" + +#include "fms_const.h" +#include "fms_fileinfo.h" +#include "fms_service_stub.h" +#include "log.h" + +using namespace std; + +namespace OHOS { +namespace FileManagerService { +FileManagerProxy::FileManagerProxy(const sptr &impl) + : IRemoteProxy(impl) { } + +IFmsClient *IFmsClient::GetFmsInstance() +{ + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + DEBUG_LOG("samgr object is NULL."); + return nullptr; + } + sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); + if (object == nullptr) { + DEBUG_LOG("FileManager Service object is NULL."); + return nullptr; + } + static FileManagerProxy msProxy(object); + + DEBUG_LOG("FileManagerProxy::GetFmsInstance"); + return &msProxy; +} + +int FileManagerProxy::CreateFile(string name, string path, string &uri) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + sptr remote = Remote(); + data.WriteString(name); + data.WriteString(path); + int err = remote->SendRequest(FMS_MEDIA_CREATEFILE, data, reply, option); + if (err != ERR_NONE) { + ERR_LOG("FileManagerProxy::CreateFile send request fail %{public}d", err); + return err; + } + reply.ReadString(uri); + DEBUG_LOG("FileManagerProxy::CreateFile reply uri %{public}s", uri.c_str()); + reply.ReadInt32(err); + DEBUG_LOG("FileManagerProxy::CreateFile reply %{public}d", err); + return err; +} + +int GetFileInfo(FileInfo &file, MessageParcel &reply) +{ + string path; + string name; + string type; + int64_t size = 0; + int64_t at = 0; + int64_t mt = 0; + + reply.ReadString(path); + reply.ReadString(type); + reply.ReadString(name); + reply.ReadInt64(size); + reply.ReadInt64(at); + reply.ReadInt64(mt); + file = FileInfo(name, path, type, size, at, mt); + return SUCCESS; +} + + +int FileManagerProxy::ListFile(string path, int off, int count, vector &fileRes) +{ + int err; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + sptr remote = Remote(); + data.WriteString(path); + data.WriteInt32(off); + data.WriteInt32(count); + err = remote->SendRequest(FMS_MEDIA_LISTFILE, data, reply, option); + if (err != ERR_NONE) { + ERR_LOG("FileManagerProxy::ListFile err %{public}d", err); + return err; + } + int fileInfoNum = 0; + reply.ReadInt32(fileInfoNum); + ERR_LOG("FileManagerProxy::ListFile num %{public}d", fileInfoNum); + while (fileInfoNum) { + FileInfo file; + GetFileInfo(file, reply); + fileRes.emplace_back(file); + fileInfoNum--; + } + reply.ReadInt32(err); + DEBUG_LOG("FileManagerProxy::ListFile reply %{public}d", err); + return err; +} + +int FileManagerProxy::mkdir(string name, string path) +{ + int err; + MessageParcel data; + MessageParcel reply; + MessageOption option; + + sptr remote = Remote(); + data.WriteString(name); + data.WriteString(path); + err = remote->SendRequest(FMS_MEDIA_MKDIR, data, reply, option); + if (err != ERR_NONE) { + ERR_LOG("FileManagerProxy::mkdir err %{public}d", err); + return err; + } + reply.ReadInt32(err); + DEBUG_LOG("FileManagerProxy::mkdir reply %{public}d", err); + return err; +} + +} // FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/client/fms_proxy.h b/services/src/client/fms_proxy.h new file mode 100644 index 00000000..2b3d6d1b --- /dev/null +++ b/services/src/client/fms_proxy.h @@ -0,0 +1,38 @@ +/* + * 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 "fms_service_stub.h" +#include "ifms_client.h" +#include "iremote_proxy.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace FileManagerService { +class FileManagerProxy : public IRemoteProxy, public IFmsClient { +public: + explicit FileManagerProxy(const sptr &impl); + virtual ~FileManagerProxy() = default; + static IFmsClient* GetFmsInstance(); + int mkdir(std::string name, std::string path); + int ListFile(std::string path, int off, int count, std::vector &fileRes); + int CreateFile(std::string name, std::string path, std::string &uri); + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h new file mode 100644 index 00000000..3b50f90f --- /dev/null +++ b/services/src/client/ifms_client.h @@ -0,0 +1,32 @@ +/* + * 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 "fms_fileinfo.h" + +namespace OHOS { +namespace FileManagerService { +class IFmsClient { +public: + virtual ~IFmsClient() {} + + static IFmsClient *GetFmsInstance(); + + virtual int mkdir(std::string name, std::string path) = 0; + virtual int ListFile(std::string path, int off, int count, std::vector &fileRes) = 0; + virtual int CreateFile(std::string name, std::string path, std::string &uri) = 0; +}; +} // namespace FileManagerService { +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/fms_file_oper.h b/services/src/fileoper/fms_file_oper.h new file mode 100644 index 00000000..efd32fe5 --- /dev/null +++ b/services/src/fileoper/fms_file_oper.h @@ -0,0 +1,34 @@ +/* + * 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 "ipc_types.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace FileManagerService { +class FileOper { +public: + virtual ~FileOper() = default; + virtual int mkdir(const std::string &name, const std::string &path) = 0; + virtual int ListFile(const std::string &path, int offset, int count, MessageParcel &data) = 0; + virtual int CreateFile(const std::string &name, const std::string &path, std::string &uri); +}; +} // OHOS +} // FileManager \ No newline at end of file diff --git a/services/src/fileoper/fms_fileinfo.h b/services/src/fileoper/fms_fileinfo.h new file mode 100644 index 00000000..d5cd9082 --- /dev/null +++ b/services/src/fileoper/fms_fileinfo.h @@ -0,0 +1,66 @@ +/* + * 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 "ipc_types.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" + +namespace OHOS { +namespace FileManagerService { +class FileInfo { +public: + FileInfo() {}; + FileInfo(const std::string &name, const std::string &path, const std::string &type, int64_t size, int64_t added_time, + int64_t modified_time) : path_(path), name_(name), type_(type), size_(size), + added_time_(added_time), modified_time_(modified_time) {} + std::string GetName() + { + return name_; + } + std::string GetPath() + { + return path_; + } + std::string GetType() + { + return type_; + } + int64_t GetSize() + { + return size_; + } + int64_t GetAdded_Time() + { + return added_time_; + } + int64_t GetModified_time() + { + return modified_time_; + } +private: + std::string path_; + std::string name_; + std::string type_; + int64_t size_; + int64_t added_time_; + int64_t modified_time_; +}; +} // OHOS +} // FileManager \ No newline at end of file diff --git a/services/src/fileoper/fms_mediafile_oper.cpp b/services/src/fileoper/fms_mediafile_oper.cpp new file mode 100644 index 00000000..5b10efda --- /dev/null +++ b/services/src/fileoper/fms_mediafile_oper.cpp @@ -0,0 +1,196 @@ +/* + * 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 "fms_mediafile_oper.h" + +#include + +#include "fms_const.h" +#include "fms_fileinfo.h" +#include "ipc_types.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" +#include "log.h" +#include "media_data_ability_const.h" +#include "medialibrary_data_ability.h" + +using namespace std; + +namespace OHOS { +namespace FileManagerService { +const std::vector mediaData = { Media::MEDIA_DATA_DB_ID, + Media::MEDIA_DATA_DB_URI, + Media::MEDIA_DATA_DB_NAME }; +const std::vector> mediaMetaMap = { {0, "string"}, // 0 id + {1, "string"}, // 1 fileuri + {4, "string"}, // 4 type + {6, "string"}, // 6 name + {7, "int"}, // 7 size + {8, "int"}, // 8 at + {9, "int"} }; // 9 mt +int Insert(const string &name, const string &path, const string &type) +{ + Media::ValuesBucket values; + Media::MediaLibraryDataAbility abi; + string abilityUri = Media::MEDIALIBRARY_DATA_URI; + string oper; + if (type == "album") { + oper = Media::MEDIA_ALBUMOPRN + "/" + Media::MEDIA_ALBUMOPRN_CREATEALBUM; + } else if(type == "file") { + oper = Media::MEDIA_FILEOPRN + "/" + Media::MEDIA_FILEOPRN_CREATEASSET; + } + Uri createUri(abilityUri + "/" + oper); + struct stat statInfo {}; + string str = createUri.ToString(); + DEBUG_LOG("MediaFileOper::Insert uri %{public}s", str.c_str()); + values.PutString(Media::MEDIA_DATA_DB_URI, name); + values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, path + "/" + name); + values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "dstPath2"); + values.PutString(Media::MEDIA_DATA_DB_NAME, "dispName2"); + values.PutLong(Media::MEDIA_DATA_DB_DATE_ADDED, statInfo.st_ctime); + values.PutLong(Media::MEDIA_DATA_DB_DATE_MODIFIED, statInfo.st_mtime); + abi.InitMediaLibraryRdbStore(); + return abi.Insert(createUri, values); +} + +int MediaFileOper::CreateFile(const std::string &name, const std::string &path, std::string &uri) +{ + string type = "file"; + + int index = Insert(name, path, type); + + // media type need to check the path + if (index < 0) { + ERR_LOG("MediaFileOper:: Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); + return index; + } + uri = Media::MEDIALIBRARY_FILE_URI; + uri += "/" + to_string(index); + return SUCCESS; +} + +bool pushFileInfo(shared_ptr result, MessageParcel &reply) +{ + string id; + string uri; + result->GetString(mediaMetaMap[0].first, id); + result->GetString(mediaMetaMap[1].first, uri); + reply.WriteString(uri + "/" + id); + for (int i = 2; i < mediaMetaMap.size(); i++) { + if(mediaMetaMap[i].second == "string") + { + string value; + result->GetString(mediaMetaMap[i].first, value); + reply.WriteString(value); + } else { + int64_t value; + result->GetLong(mediaMetaMap[i].first, value); + reply.WriteInt64(value); + } + } + return true; +} + +int GetFileInfoFromResult(shared_ptr result, MessageParcel &reply) +{ + int count = 0; + result->GetRowCount(count); + if (count == 0) { + ERR_LOG("GetFileInfoFromResult::AbsSharedResultSet null"); + return FAIL; + } + result->GoToFirstRow(); + reply.WriteInt32(count); + for (int i = 0; i < count; i++) { + pushFileInfo(result, reply); + result->GoToNextRow(); + } + return SUCCESS; +} + +bool GetRelativePath(const string &path, string &relativePath) +{ + NativeRdb::DataAbilityPredicates predicates; + string selection = Media::MEDIA_DATA_DB_ID + " LIKE ? "; + vector selectionArgs = { path }; + predicates.SetWhereClause(selection); + predicates.SetWhereArgs(selectionArgs); + Media::MediaLibraryDataAbility abi; + abi.InitMediaLibraryRdbStore(); + Uri uri(Media::MEDIALIBRARY_DATA_URI); + vector columns; + shared_ptr result = abi.Query(uri, columns, predicates); + if (result == nullptr) { + return false; + } + int count = 0; + result->GetRowCount(count); + + if (count != 1) { + ERR_LOG("GetRelativePath::AbsSharedResultSet more than one uri"); + } + int32_t columnIndex; + int ret = result->GetColumnIndex(Media::MEDIA_DATA_DB_FILE_PATH, columnIndex); + if(ret != NativeRdb::E_OK) { + return false; + } + result->GoToFirstRow(); + ret = result->GetString(columnIndex, relativePath); + if(ret != NativeRdb::E_OK) { + return false; + } + DEBUG_LOG("GetRelativePath %{public}s", relativePath.c_str()); + return true; +} + +int MediaFileOper::ListFile(const string &path, int offset, int count, MessageParcel &reply) +{ + //get the relative path from the path uri + string relativePath; + + DEBUG_LOG("ListFile %{public}s", path.c_str()); + if(!GetRelativePath(path, relativePath)) { + ERR_LOG("MediaFileOper::path not exsit"); + return E_NOEXIST; + } + NativeRdb::DataAbilityPredicates predicates; + string selection = Media::MEDIA_DATA_DB_RELATIVE_PATH + " LIKE ? "; + vector selectionArgs = { relativePath }; + predicates.SetWhereClause(selection); + predicates.SetWhereArgs(selectionArgs); + Media::MediaLibraryDataAbility abi; + abi.InitMediaLibraryRdbStore(); + Uri uri(Media::MEDIALIBRARY_DATA_URI); + vector columns; + shared_ptr result = abi.Query(uri, columns, predicates); + if (result == nullptr) { + ERR_LOG("MediaFileOper::ListFile folder is empty"); + return E_EMPTYFOLDER; + } + GetFileInfoFromResult(result, reply); + return SUCCESS; +} + +int MediaFileOper::mkdir(const string &name, const string &path) +{ + string type = "album"; + Insert(name, path, type); + DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); + return 1; +} + +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/fms_mediafile_oper.h b/services/src/fileoper/fms_mediafile_oper.h new file mode 100644 index 00000000..5b87b33d --- /dev/null +++ b/services/src/fileoper/fms_mediafile_oper.h @@ -0,0 +1,31 @@ +/* + * 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 "fms_file_oper.h" + +namespace OHOS { +namespace FileManagerService { +class MediaFileOper : public FileOper { +public: + virtual ~MediaFileOper() = default; + int mkdir(const std::string &name, const std::string &path) override; + int ListFile(const std::string &path, int offset, int count, MessageParcel &data) override; + int CreateFile(const std::string &name, const std::string &path, std::string &uri) override; +}; +} // OHOS +} // FileManager \ No newline at end of file diff --git a/services/src/fileoper/fms_oper_factory.cpp b/services/src/fileoper/fms_oper_factory.cpp new file mode 100644 index 00000000..1a3658ba --- /dev/null +++ b/services/src/fileoper/fms_oper_factory.cpp @@ -0,0 +1,34 @@ +/* + * 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 "fms_file_oper.h" +#include "fms_mediafile_oper.h" +#include "fms_oper_factory.h" +#include "log.h" + +using namespace std; + +namespace OHOS { +namespace FileManagerService { +FileOper* OperFactory::getFileOper(string oper) +{ + + DEBUG_LOG("OperFactory::getFileOper %{public}s.",oper.c_str()); + + return new MediaFileOper(); +} + +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/fms_oper_factory.h b/services/src/fileoper/fms_oper_factory.h new file mode 100644 index 00000000..4b4e7bef --- /dev/null +++ b/services/src/fileoper/fms_oper_factory.h @@ -0,0 +1,29 @@ +/* + * 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 "fms_file_oper.h" + +namespace OHOS { +namespace FileManagerService { +class OperFactory { +public: + FileOper* getFileOper(std::string oper); +}; +} // OHOS +} // FileManager \ No newline at end of file diff --git a/services/src/server/fms_service.cpp b/services/src/server/fms_service.cpp new file mode 100644 index 00000000..5e3d14ed --- /dev/null +++ b/services/src/server/fms_service.cpp @@ -0,0 +1,46 @@ +/* + * 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 "fms_service.h" + +#include "iservice_registry.h" +#include "log.h" +#include "system_ability_definition.h" + + +namespace OHOS { +namespace FileManagerService { +REGISTER_SYSTEM_ABILITY_BY_ID(FileManagerService, FILE_MANAGER_SERVICE_ID, true); + +FileManagerService::FileManagerService(int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate) { } +void FileManagerService::OnDump() { } + +void FileManagerService::OnStart() +{ + DEBUG_LOG("FileManagerService::OnStart called"); + bool res = Publish(this); + if (res) { + DEBUG_LOG("FileManagerService OnStart valid"); + } +} + +void FileManagerService::OnStop() +{ + DEBUG_LOG("FileManagerService OnStop"); +} + +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/server/fms_service.h b/services/src/server/fms_service.h new file mode 100644 index 00000000..6ae6679f --- /dev/null +++ b/services/src/server/fms_service.h @@ -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. + */ + +#pragma once + +#include "iremote_stub.h" +#include "system_ability.h" +#include "fms_service_stub.h" + +namespace OHOS { +namespace FileManagerService { + +class FileManagerService : public SystemAbility, public FileManagerServiceStub { + DECLARE_SYSTEM_ABILITY(FileManagerService); +public: + DISALLOW_COPY_AND_MOVE(FileManagerService); + explicit FileManagerService(int32_t systemAbilityId, bool runOnCreate = true); + virtual ~FileManagerService() = default; + + void OnDump() override; + + void OnStart() override; + + void OnStop() override; + +}; + +} // namespace FileManagerService +} // namespace OHOS diff --git a/services/src/server/fms_service_stub.cpp b/services/src/server/fms_service_stub.cpp new file mode 100644 index 00000000..a3c15044 --- /dev/null +++ b/services/src/server/fms_service_stub.cpp @@ -0,0 +1,110 @@ +/* + * 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 "fms_service_stub.h" + +#include "fms_const.h" +#include "fms_oper_factory.h" +#include "fms_service.h" +#include "log.h" + +using namespace std; + +namespace OHOS { +namespace FileManagerService { +int FileManagerServiceStub::OperMediaProcess(OperFactory &factory, uint32_t code, MessageParcel &data, + MessageParcel &reply) +{ + int errCode = SUCCESS; + if (code < FMS_MEDIA_START || code > FMS_MEDIA_END) { + return errCode; + } + auto *fp = factory.getFileOper("media"); + // media process + switch(code) { + case FMS_MEDIA_MKDIR: { + string name = data.ReadString(); + string path = data.ReadString(); + errCode = fp->mkdir(name, path); + break; + } + case FMS_MEDIA_LISTFILE: { + string path = data.ReadString(); + int off = data.ReadInt32(); + int count = data.ReadInt32(); + errCode = fp->ListFile(path, off, count, reply); + // need reply fileInfo + break; + } + case FMS_MEDIA_CREATEFILE: { + string name = data.ReadString(); + string path = data.ReadString(); + string uri; + errCode = fp->CreateFile(name, path, uri); + reply.WriteString(uri); + break; + } + default: + break; + } + delete fp; + return errCode; +} + +int FileManagerServiceStub::OperExtProcess(OperFactory &factory, uint32_t code, MessageParcel &data, + MessageParcel &reply) +{ + int errCode = SUCCESS; + if (code < FMS_EXTERNAL_START || code > FMS_EXTERNAL_END) { + return errCode; + } + // do Exteranl storage process; + return errCode; +} + +int FileManagerServiceStub::OperProcess(uint32_t code, MessageParcel &data, + MessageParcel &reply) +{ + int errCode = SUCCESS; + + switch (code) { + case FMS_GET_ROOT: { + // return root base on type + // return fileInfo + break; + } + default: { + OperFactory factory = OperFactory(); + // check uri -->Media or --> External + errCode = OperMediaProcess(factory, code, data, reply); + } + } + return errCode; +} + +int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) +{ + DEBUG_LOG("OnRemoteRequest %{public}d", code); + + // to do checkpermission() + // do file process + int32_t errCode = OperProcess(code, data, reply); + reply.WriteInt32(errCode); + return errCode; +} + +} // namespace FileManagerService +} // namespace OHOS \ No newline at end of file diff --git a/services/src/server/fms_service_stub.h b/services/src/server/fms_service_stub.h new file mode 100644 index 00000000..cdc025c6 --- /dev/null +++ b/services/src/server/fms_service_stub.h @@ -0,0 +1,46 @@ +/* + * 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 "ipc_types.h" +#include "iremote_broker.h" +#include "iremote_proxy.h" +#include "iremote_stub.h" +#include "../fileoper/fms_oper_factory.h" + + +namespace OHOS { +namespace FileManagerService { +class IFileManagerService : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"IFileManagerService"); +}; + +class FileManagerServiceStub : public IRemoteStub { +public: + + int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply); + int OperMediaProcess(OperFactory &factory, uint32_t code, MessageParcel &data, + MessageParcel &reply); + int OperExtProcess(OperFactory &factory, uint32_t code, MessageParcel &data, + MessageParcel &reply); + + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) override; +}; + +} // namespace FileManagerService +} // namespace OHOS diff --git a/services/test/BUILD.gn b/services/test/BUILD.gn new file mode 100644 index 00000000..ae241dfe --- /dev/null +++ b/services/test/BUILD.gn @@ -0,0 +1,52 @@ +# 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("//build/test.gni") +FMS_BASE_DIR = "//foundation/storage/services" +ohos_unittest("fms_test") { + module_out_path = "storage/fms" + + sources = [ "fms_test.cpp" ] + + include_dirs = [ + "//third_party/json/include", + "//base/security/huks/interfaces/innerkits/huks_standard/main/include", + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + ] + + configs = [ + "//build/config/compiler:exceptions", + ] + + deps = [ + "//foundation/storage/services:fms_server", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//utils/native/base:utils", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +group("test") { + testonly = true + + deps = [ ":fms_test" ] +} diff --git a/services/test/fms_test.cpp b/services/test/fms_test.cpp new file mode 100644 index 00000000..fb68aa70 --- /dev/null +++ b/services/test/fms_test.cpp @@ -0,0 +1,57 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "fms_proxy.h" + +namespace { +using namespace std; +using namespace OHOS; +class FMSTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + cout << "FMS code test" << endl; + } + static void TearDownTestCase() {} +}; + +/** + * @tc.number SUB_STORAGE_FMS_Function_Enable_0000 + * @tc.name FMS_Function_Enable_0000 + * @tc.desc Test function of Enable interface. + */ +HWTEST_F(FMSTest, FMS_Function_Enable_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Function_Enable_0000" << endl; + try { + int result = 0; + FileManagerService::FileManagerProxy proxy; + EXPECT_EQ(result, 0); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Function_Enable_0000" << endl; +} + +} // namespace -- Gitee From 045d70e93e042fb9124d4f688b92677e86fcec8b Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 14 Dec 2021 10:28:30 +0800 Subject: [PATCH 2/9] add TDD test Signed-off-by: panqiangbiao --- services/test/fms_test.cpp | 185 +++++++++++++++++++++++++++++++++++-- 1 file changed, 177 insertions(+), 8 deletions(-) diff --git a/services/test/fms_test.cpp b/services/test/fms_test.cpp index fb68aa70..a9bb17ec 100644 --- a/services/test/fms_test.cpp +++ b/services/test/fms_test.cpp @@ -37,21 +37,190 @@ public: }; /** - * @tc.number SUB_STORAGE_FMS_Function_Enable_0000 - * @tc.name FMS_Function_Enable_0000 - * @tc.desc Test function of Enable interface. + * @tc.number: SUB_STORAGE_FMS_Proxy_GetFmsInstance_0000 + * @tc.name: fms_Proxy_GetFmsInstance_0000 + * @tc.desc: Test function of GetFmsInstance interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: */ -HWTEST_F(FMSTest, FMS_Function_Enable_0000, testing::ext::TestSize.Level1) +HWTEST_F(FMSTest, FMS_Proxy_GetFmsInstance_0000, testing::ext::TestSize.Level1) { - cout << "FMSTest-begin FMS_Function_Enable_0000" << endl; + cout << "FMSTest-begin FMS_Proxy_GetFmsInstance_0000" << endl; try { - int result = 0; FileManagerService::FileManagerProxy proxy; + IFmsClient result = proxy.GetFmsInstance(); + EXPECT_NE(result, nullptr); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Proxy_GetFmsInstance_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Proxy_getFileInfo_0000 + * @tc.name: fms_Proxy_getFileInfo_0000 + * @tc.desc: Test function of getFileInfo interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Proxy_getFileInfo_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Proxy_getFileInfo_0000" << endl; + try { + FileManagerService::FileManagerProxy proxy; + FileInfo fileInfo; + MessageParcel messageParcel; + messageParcel.WriteString("FMS_Proxy_getFileInfo_0000"); + messageParcel.WriteString("./"); + messageParcel.WriteString("file"); + messageParcel.WriteString(0); + messageParcel.WriteString(0); + messageParcel.WriteString(0); + int result = proxy.getFileInfo(fileInfo, messageParcel); + EXPECT_EQ(result, 0); + EXPECT_NE(fileInfo, nullptr); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Proxy_getFileInfo_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Proxy_ListFile_0000 + * @tc.name: fms_Proxy_ListFile_0000 + * @tc.desc: Test function of ListFile interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Proxy_ListFile_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Proxy_ListFile_0000" << endl; + try { + FileManagerService::FileManagerProxy proxy; + vector fileList; + int result = proxy.ListFile("./", 0, 1, fileList); + EXPECT_EQ(result, 0); + EXPECT_NE(fileList, nullptr); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Proxy_ListFile_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Mediafile_Insert_0000 + * @tc.name: fms_Mediafile_Insert_0000 + * @tc.desc: Test function of Insert interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Mediafile_Insert_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Mediafile_Insert_0000" << endl; + try { + int result = MediaFileOper::Insert("FMS_Mediafile_Insert_0000", "./", "file"); + EXPECT_EQ(result, 0); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Mediafile_Insert_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Mediafile_CreateFile_0000 + * @tc.name: fms_Mediafile_CreateFile_0000 + * @tc.desc: Test function of CreateFile interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Mediafile_CreateFile_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Mediafile_CreateFile_0000" << endl; + try { + string path = "./"; + string url; + int result = MediaFileOper::CreateFile("FMS_Mediafile_CreateFile_0000", path, url); + EXPECT_EQ(result, 0); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Mediafile_CreateFile_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Mediafile_pushFileInfo_0000 + * @tc.name: fms_Mediafile_pushFileInfo_0000 + * @tc.desc: Test function of pushFileInfo interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Mediafile_pushFileInfo_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Mediafile_pushFileInfo_0000" << endl; + try { + FileInfo fileInfo = FileInfo("FMS_Mediafile_pushFileInfo_0000", "./", "file", 0, 0, 0); + MessageParcel messageParcel; + int result = MediaFileOper::pushFileInfo(fileInfo, messageParcel); EXPECT_EQ(result, 0); } catch (...) { cout << "FMSTest-an exception occurred." << endl; } - cout << "FMSTest-end FMS_Function_Enable_0000" << endl; + cout << "FMSTest-end FMS_Mediafile_pushFileInfo_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Mediafile_ListFile_0000 + * @tc.name: fms_Mediafile_ListFile_0000 + * @tc.desc: Test function of ListFile interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Mediafile_ListFile_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Mediafile_ListFile_0000" << endl; + try { + MessageParcel messageParcel; + int result = MediaFileOper::ListFile("./", 0, 0, messageParcel); + EXPECT_EQ(result, 0); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Mediafile_ListFile_0000" << endl; +} + +/** + * @tc.number: SUB_STORAGE_FMS_Mediafile_mkdir_0000 + * @tc.name: fms_Mediafile_mkdir_0000 + * @tc.desc: Test function of mkdir interface. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: + */ +HWTEST_F(FMSTest, FMS_Mediafile_mkdir_0000, testing::ext::TestSize.Level1) +{ + cout << "FMSTest-begin FMS_Mediafile_mkdir_0000" << endl; + try { + int result = MediaFileOper::mkdir("FMS_Mediafile_mkdir_0000", "./"); + EXPECT_EQ(result, 1); + } catch (...) { + cout << "FMSTest-an exception occurred." << endl; + } + cout << "FMSTest-end FMS_Mediafile_mkdir_0000" << endl; } -} // namespace +} // namespace \ No newline at end of file -- Gitee From c16d79d2b7face7e605e83d483cfcdf7f06983ab Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 14 Dec 2021 10:28:30 +0800 Subject: [PATCH 3/9] fix createfile issue Signed-off-by: panqiangbiao --- services/src/client/fms_proxy.cpp | 4 ++-- services/src/fileoper/fms_mediafile_oper.cpp | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/services/src/client/fms_proxy.cpp b/services/src/client/fms_proxy.cpp index db9e1cb5..fc34da90 100644 --- a/services/src/client/fms_proxy.cpp +++ b/services/src/client/fms_proxy.cpp @@ -71,8 +71,8 @@ int GetFileInfo(FileInfo &file, MessageParcel &reply) string name; string type; int64_t size = 0; - int64_t at = 0; - int64_t mt = 0; + int64_t at = 0; + int64_t mt = 0; reply.ReadString(path); reply.ReadString(type); diff --git a/services/src/fileoper/fms_mediafile_oper.cpp b/services/src/fileoper/fms_mediafile_oper.cpp index 5b10efda..b21b0400 100644 --- a/services/src/fileoper/fms_mediafile_oper.cpp +++ b/services/src/fileoper/fms_mediafile_oper.cpp @@ -54,12 +54,9 @@ int Insert(const string &name, const string &path, const string &type) } Uri createUri(abilityUri + "/" + oper); struct stat statInfo {}; - string str = createUri.ToString(); - DEBUG_LOG("MediaFileOper::Insert uri %{public}s", str.c_str()); - values.PutString(Media::MEDIA_DATA_DB_URI, name); - values.PutString(Media::MEDIA_DATA_DB_FILE_PATH, path + "/" + name); - values.PutString(Media::MEDIA_DATA_DB_RELATIVE_PATH, "dstPath2"); - values.PutString(Media::MEDIA_DATA_DB_NAME, "dispName2"); + // need getfileStat info + // need MEDIA_DATA_DB_RELATIVE_PATH + // need MEDIA_DATA_DB_NAME values.PutLong(Media::MEDIA_DATA_DB_DATE_ADDED, statInfo.st_ctime); values.PutLong(Media::MEDIA_DATA_DB_DATE_MODIFIED, statInfo.st_mtime); abi.InitMediaLibraryRdbStore(); -- Gitee From 059230b0fb21141719cd31983749d00192943bdb Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 14 Dec 2021 21:07:45 +0800 Subject: [PATCH 4/9] refactor file oper process Signed-off-by: panqiangbiao --- services/include/fms_const.h | 27 ++++--- services/src/client/fms_proxy.cpp | 75 +++++++++----------- services/src/fileoper/fms_file_oper.h | 3 +- services/src/fileoper/fms_mediafile_oper.cpp | 33 +++++++++ services/src/fileoper/fms_mediafile_oper.h | 1 + services/src/fileoper/fms_oper_factory.cpp | 27 +++++-- services/src/fileoper/fms_oper_factory.h | 2 +- services/src/server/fms_service_stub.cpp | 75 ++++---------------- services/src/server/fms_service_stub.h | 7 -- 9 files changed, 122 insertions(+), 128 deletions(-) diff --git a/services/include/fms_const.h b/services/include/fms_const.h index 6c3afd21..f6360a40 100644 --- a/services/include/fms_const.h +++ b/services/include/fms_const.h @@ -17,20 +17,25 @@ #include namespace OHOS { namespace FileManagerService { -enum { - FMS_GET_ROOT, - FMS_MEDIA_START, - FMS_MEDIA_MKDIR, - FMS_MEDIA_LISTFILE, - FMS_MEDIA_CREATEFILE, - FMS_MEDIA_END, - FMS_EXTERNAL_START, - FMS_EXTERNAL_END, +enum FILE_OPER { + GET_ROOT, + MKDIR, + LIST_FILE, + CREATE_FILE }; + +enum EQUIPMENT { + INTERNAL, + EXTERNAL +}; + +const int32_t CODE_MASK = 0xff; +const int32_t EQUIPMENT_SHIFT = 16; + const int32_t SUCCESS = 0; const int32_t FAIL = -1; -const int32_t E_NOEXIST = -2; -const int32_t E_EMPTYFOLDER = -3; +const int32_t E_NOEXIST = -2; // file not exist +const int32_t E_EMPTYFOLDER = -3; // folder empty } // namespace FileManagerService } // namespace OHOS diff --git a/services/src/client/fms_proxy.cpp b/services/src/client/fms_proxy.cpp index fc34da90..0eecdbc0 100644 --- a/services/src/client/fms_proxy.cpp +++ b/services/src/client/fms_proxy.cpp @@ -23,27 +23,28 @@ using namespace std; namespace OHOS { namespace FileManagerService { -FileManagerProxy::FileManagerProxy(const sptr &impl) - : IRemoteProxy(impl) { } - -IFmsClient *IFmsClient::GetFmsInstance() +int GetFileInfo(FileInfo &file, MessageParcel &reply) { - auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (samgr == nullptr) { - DEBUG_LOG("samgr object is NULL."); - return nullptr; - } - sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); - if (object == nullptr) { - DEBUG_LOG("FileManager Service object is NULL."); - return nullptr; - } - static FileManagerProxy msProxy(object); + string path; + string name; + string type; + int64_t size = 0; + int64_t at = 0; + int64_t mt = 0; - DEBUG_LOG("FileManagerProxy::GetFmsInstance"); - return &msProxy; + reply.ReadString(path); + reply.ReadString(type); + reply.ReadString(name); + reply.ReadInt64(size); + reply.ReadInt64(at); + reply.ReadInt64(mt); + file = FileInfo(name, path, type, size, at, mt); + return SUCCESS; } +FileManagerProxy::FileManagerProxy(const sptr &impl) + : IRemoteProxy(impl) { } + int FileManagerProxy::CreateFile(string name, string path, string &uri) { MessageParcel data; @@ -53,38 +54,34 @@ int FileManagerProxy::CreateFile(string name, string path, string &uri) sptr remote = Remote(); data.WriteString(name); data.WriteString(path); - int err = remote->SendRequest(FMS_MEDIA_CREATEFILE, data, reply, option); + int err = remote->SendRequest(FILE_OPER::CREATE_FILE, data, reply, option); if (err != ERR_NONE) { ERR_LOG("FileManagerProxy::CreateFile send request fail %{public}d", err); return err; } reply.ReadString(uri); - DEBUG_LOG("FileManagerProxy::CreateFile reply uri %{public}s", uri.c_str()); reply.ReadInt32(err); - DEBUG_LOG("FileManagerProxy::CreateFile reply %{public}d", err); return err; } -int GetFileInfo(FileInfo &file, MessageParcel &reply) +IFmsClient *IFmsClient::GetFmsInstance() { - string path; - string name; - string type; - int64_t size = 0; - int64_t at = 0; - int64_t mt = 0; + auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + DEBUG_LOG("samgr object is NULL."); + return nullptr; + } + sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); + if (object == nullptr) { + DEBUG_LOG("FileManager Service object is NULL."); + return nullptr; + } + static FileManagerProxy msProxy(object); - reply.ReadString(path); - reply.ReadString(type); - reply.ReadString(name); - reply.ReadInt64(size); - reply.ReadInt64(at); - reply.ReadInt64(mt); - file = FileInfo(name, path, type, size, at, mt); - return SUCCESS; + DEBUG_LOG("FileManagerProxy::GetFmsInstance"); + return &msProxy; } - int FileManagerProxy::ListFile(string path, int off, int count, vector &fileRes) { int err; @@ -96,14 +93,13 @@ int FileManagerProxy::ListFile(string path, int off, int count, vector data.WriteString(path); data.WriteInt32(off); data.WriteInt32(count); - err = remote->SendRequest(FMS_MEDIA_LISTFILE, data, reply, option); + err = remote->SendRequest(FILE_OPER::LIST_FILE, data, reply, option); if (err != ERR_NONE) { ERR_LOG("FileManagerProxy::ListFile err %{public}d", err); return err; } int fileInfoNum = 0; reply.ReadInt32(fileInfoNum); - ERR_LOG("FileManagerProxy::ListFile num %{public}d", fileInfoNum); while (fileInfoNum) { FileInfo file; GetFileInfo(file, reply); @@ -111,7 +107,6 @@ int FileManagerProxy::ListFile(string path, int off, int count, vector fileInfoNum--; } reply.ReadInt32(err); - DEBUG_LOG("FileManagerProxy::ListFile reply %{public}d", err); return err; } @@ -125,7 +120,7 @@ int FileManagerProxy::mkdir(string name, string path) sptr remote = Remote(); data.WriteString(name); data.WriteString(path); - err = remote->SendRequest(FMS_MEDIA_MKDIR, data, reply, option); + err = remote->SendRequest(FILE_OPER::MKDIR, data, reply, option); if (err != ERR_NONE) { ERR_LOG("FileManagerProxy::mkdir err %{public}d", err); return err; diff --git a/services/src/fileoper/fms_file_oper.h b/services/src/fileoper/fms_file_oper.h index efd32fe5..7db107a4 100644 --- a/services/src/fileoper/fms_file_oper.h +++ b/services/src/fileoper/fms_file_oper.h @@ -28,7 +28,8 @@ public: virtual ~FileOper() = default; virtual int mkdir(const std::string &name, const std::string &path) = 0; virtual int ListFile(const std::string &path, int offset, int count, MessageParcel &data) = 0; - virtual int CreateFile(const std::string &name, const std::string &path, std::string &uri); + virtual int CreateFile(const std::string &name, const std::string &path, std::string &uri) = 0; + virtual int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) = 0; }; } // OHOS } // FileManager \ No newline at end of file diff --git a/services/src/fileoper/fms_mediafile_oper.cpp b/services/src/fileoper/fms_mediafile_oper.cpp index b21b0400..6f0665c7 100644 --- a/services/src/fileoper/fms_mediafile_oper.cpp +++ b/services/src/fileoper/fms_mediafile_oper.cpp @@ -153,6 +153,39 @@ bool GetRelativePath(const string &path, string &relativePath) return true; } +int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) +{ + int errCode = SUCCESS; + // media process + switch(code) { + case FILE_OPER::MKDIR: { + string name = data.ReadString(); + string path = data.ReadString(); + errCode = mkdir(name, path); + break; + } + case FILE_OPER::LIST_FILE: { + string path = data.ReadString(); + int off = data.ReadInt32(); + int count = data.ReadInt32(); + errCode = ListFile(path, off, count, reply); + // need reply fileInfo + break; + } + case FILE_OPER::CREATE_FILE: { + string name = data.ReadString(); + string path = data.ReadString(); + string uri; + errCode = CreateFile(name, path, uri); + reply.WriteString(uri); + break; + } + default: + break; + } + return errCode; +} + int MediaFileOper::ListFile(const string &path, int offset, int count, MessageParcel &reply) { //get the relative path from the path uri diff --git a/services/src/fileoper/fms_mediafile_oper.h b/services/src/fileoper/fms_mediafile_oper.h index 5b87b33d..e0dac288 100644 --- a/services/src/fileoper/fms_mediafile_oper.h +++ b/services/src/fileoper/fms_mediafile_oper.h @@ -26,6 +26,7 @@ public: int mkdir(const std::string &name, const std::string &path) override; int ListFile(const std::string &path, int offset, int count, MessageParcel &data) override; int CreateFile(const std::string &name, const std::string &path, std::string &uri) override; + int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) override; }; } // OHOS } // FileManager \ No newline at end of file diff --git a/services/src/fileoper/fms_oper_factory.cpp b/services/src/fileoper/fms_oper_factory.cpp index 1a3658ba..69616770 100644 --- a/services/src/fileoper/fms_oper_factory.cpp +++ b/services/src/fileoper/fms_oper_factory.cpp @@ -13,21 +13,34 @@ * limitations under the License. */ +#include "fms_oper_factory.h" + +#include "fms_const.h" #include "fms_file_oper.h" #include "fms_mediafile_oper.h" -#include "fms_oper_factory.h" #include "log.h" using namespace std; - namespace OHOS { namespace FileManagerService { -FileOper* OperFactory::getFileOper(string oper) +FileOper* OperFactory::getFileOper(int equipmentId) { - - DEBUG_LOG("OperFactory::getFileOper %{public}s.",oper.c_str()); - - return new MediaFileOper(); + DEBUG_LOG("OperFactory::getFileOper %{public}d.", equipmentId); + switch (equipmentId) { + case EQUIPMENT::INTERNAL: { + return new MediaFileOper(); + break; + } + case EQUIPMENT::EXTERNAL: { + // do Exteranl storage process; + // return ExternalOper() + break; + } + default: { + break; + } + } + return nullptr; } } // namespace FileManagerService diff --git a/services/src/fileoper/fms_oper_factory.h b/services/src/fileoper/fms_oper_factory.h index 4b4e7bef..430b2a09 100644 --- a/services/src/fileoper/fms_oper_factory.h +++ b/services/src/fileoper/fms_oper_factory.h @@ -23,7 +23,7 @@ namespace OHOS { namespace FileManagerService { class OperFactory { public: - FileOper* getFileOper(std::string oper); + FileOper* getFileOper(int equipmentId); }; } // OHOS } // FileManager \ No newline at end of file diff --git a/services/src/server/fms_service_stub.cpp b/services/src/server/fms_service_stub.cpp index a3c15044..c414783d 100644 --- a/services/src/server/fms_service_stub.cpp +++ b/services/src/server/fms_service_stub.cpp @@ -24,81 +24,34 @@ using namespace std; namespace OHOS { namespace FileManagerService { -int FileManagerServiceStub::OperMediaProcess(OperFactory &factory, uint32_t code, MessageParcel &data, - MessageParcel &reply) +int getEquipmentCode(uint32_t code) { - int errCode = SUCCESS; - if (code < FMS_MEDIA_START || code > FMS_MEDIA_END) { - return errCode; - } - auto *fp = factory.getFileOper("media"); - // media process - switch(code) { - case FMS_MEDIA_MKDIR: { - string name = data.ReadString(); - string path = data.ReadString(); - errCode = fp->mkdir(name, path); - break; - } - case FMS_MEDIA_LISTFILE: { - string path = data.ReadString(); - int off = data.ReadInt32(); - int count = data.ReadInt32(); - errCode = fp->ListFile(path, off, count, reply); - // need reply fileInfo - break; - } - case FMS_MEDIA_CREATEFILE: { - string name = data.ReadString(); - string path = data.ReadString(); - string uri; - errCode = fp->CreateFile(name, path, uri); - reply.WriteString(uri); - break; - } - default: - break; - } - delete fp; - return errCode; + return (code >> EQUIPMENT_SHIFT) & CODE_MASK; } - -int FileManagerServiceStub::OperExtProcess(OperFactory &factory, uint32_t code, MessageParcel &data, - MessageParcel &reply) +int getOperCode(uint32_t code) { - int errCode = SUCCESS; - if (code < FMS_EXTERNAL_START || code > FMS_EXTERNAL_END) { - return errCode; - } - // do Exteranl storage process; - return errCode; + return code & CODE_MASK; } - int FileManagerServiceStub::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) { - int errCode = SUCCESS; - - switch (code) { - case FMS_GET_ROOT: { - // return root base on type - // return fileInfo - break; - } - default: { - OperFactory factory = OperFactory(); - // check uri -->Media or --> External - errCode = OperMediaProcess(factory, code, data, reply); - } + int equipmentId = getEquipmentCode(code); + int operCode = getOperCode(code); + OperFactory factory = OperFactory(); + auto *fp = factory.getFileOper(equipmentId); + if (fp == nullptr) { + ERR_LOG("OnRemoteRequest inner error %{public}d", code); + return FAIL; } + int errCode = fp->OperProcess(operCode, data, reply); + + delete fp; return errCode; } int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - DEBUG_LOG("OnRemoteRequest %{public}d", code); - // to do checkpermission() // do file process int32_t errCode = OperProcess(code, data, reply); diff --git a/services/src/server/fms_service_stub.h b/services/src/server/fms_service_stub.h index cdc025c6..fbf3b2ec 100644 --- a/services/src/server/fms_service_stub.h +++ b/services/src/server/fms_service_stub.h @@ -21,7 +21,6 @@ #include "iremote_stub.h" #include "../fileoper/fms_oper_factory.h" - namespace OHOS { namespace FileManagerService { class IFileManagerService : public IRemoteBroker { @@ -31,13 +30,7 @@ public: class FileManagerServiceStub : public IRemoteStub { public: - int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply); - int OperMediaProcess(OperFactory &factory, uint32_t code, MessageParcel &data, - MessageParcel &reply); - int OperExtProcess(OperFactory &factory, uint32_t code, MessageParcel &data, - MessageParcel &reply); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -- Gitee From d8eec8bc0984c5e991a299469feaf3cb314e52bb Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Tue, 14 Dec 2021 21:39:00 +0800 Subject: [PATCH 5/9] delete js code Signed-off-by: panqiangbiao --- interfaces/kits/js/BUILD.gn | 67 ---- .../src/common/napi/n_async/n_async_context.h | 69 ---- .../napi/n_async/n_async_work_callback.cpp | 103 ------ .../napi/n_async/n_async_work_callback.h | 37 --- .../napi/n_async/n_async_work_factory.h | 35 -- .../napi/n_async/n_async_work_promise.cpp | 98 ------ .../napi/n_async/n_async_work_promise.h | 36 --- .../kits/js/src/common/napi/n_async/n_ref.cpp | 53 --- .../kits/js/src/common/napi/n_async/n_ref.h | 37 --- .../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 | 306 ------------------ interfaces/kits/js/src/common/napi/n_val.h | 79 ----- .../kits/js/src/common/napi/uni_header.h | 23 -- interfaces/kits/js/src/common/uni_error.cpp | 122 ------- interfaces/kits/js/src/common/uni_error.h | 64 ---- interfaces/kits/js/src/fms_napi.cpp | 207 ------------ interfaces/kits/js/src/fms_napi.h | 38 --- interfaces/kits/js/src/module.cpp | 47 --- 22 files changed, 1823 deletions(-) delete mode 100644 interfaces/kits/js/BUILD.gn 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/fms_napi.cpp delete mode 100644 interfaces/kits/js/src/fms_napi.h delete mode 100644 interfaces/kits/js/src/module.cpp diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn deleted file mode 100644 index 607a7524..00000000 --- a/interfaces/kits/js/BUILD.gn +++ /dev/null @@ -1,67 +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("//build/ohos.gni") -FMS_BASE_DIR = "//foundation/storage/services" - -ohos_shared_library("filemanager") { - subsystem_name = "storage" - part_name = "filemanager" - - relative_install_dir = "module" - - include_dirs = [ - # "$BASE_DIR/napi", - "//third_party/node/src", - "//foundation/ace/napi/interfaces/kits", - "//utils/native/base/include", - "//third_party/libuv/include", - "$FMS_BASE_DIR/include", - "$FMS_BASE_DIR/src/client", - "$FMS_BASE_DIR/src/server", - "$FMS_BASE_DIR/src/fileoper", - ] - - sources = [ - "src/common/napi/n_async/n_async_work_callback.cpp", - "src/common/napi/n_async/n_async_work_promise.cpp", - "src/common/napi/n_async/n_ref.cpp", - "src/common/napi/n_class.cpp", - "src/common/napi/n_func_arg.cpp", - "src/common/napi/n_val.cpp", - "src/common/uni_error.cpp", - "src/module.cpp", - "src/fms_napi.cpp", - ] - - deps = [ - "//utils/native/base:utils", - "$FMS_BASE_DIR:fms_server", - "//foundation/ace/napi:ace_napi", - ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - - - - - 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 67dcdde7..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_context.h +++ /dev/null @@ -1,69 +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 "../../uni_error.h" -#include "../n_val.h" -#include "../uni_header.h" -#include "n_ref.h" - -namespace OHOS { -namespace DistributedFS { -typedef std::function NContextCBExec; -typedef std::function NContextCBComplete; - -class NAsyncContext { -public: - UniError err_; - NVal res_; - NContextCBExec cbExec_; - NContextCBComplete cbComplete_; - napi_async_work awork_; - NRef thisPtr_; - - explicit NAsyncContext(NVal thisPtr) : thisPtr_(thisPtr) {} - ~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 \ 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 d9c05c02..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.cpp +++ /dev/null @@ -1,103 +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 -#include - -#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); -} -NAsyncWorkCallback::NAsyncWorkCallback(const NAsyncWorkCallback &in, napi_env env) : NAsyncWorkFactory(env) -{ - delete ctx_; - this->ctx_ = new NAsyncContextCallback(in.ctx_->thisPtr_.Deref(env), in.ctx_->cb_.Deref(env)); -} - -static void CallbackExecute(napi_env env, void *data) -{ - auto ctx = static_cast(data); - if (ctx->cbExec_) { - 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->cbComplete_) { - 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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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 a700a4ef..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_callback.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. - */ - -#pragma once - -#include -#include -#include - -#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; - NAsyncWorkCallback(const NAsyncWorkCallback &in, napi_env env); - NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; - -private: - NAsyncContextCallback *ctx_ = nullptr; -}; -} // namespace DistributedFS -} // namespace OHOS \ 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 bd993e5d..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_factory.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. - */ - -#pragma once - -#include -#include -#include - -#include "n_async_context.h" - -namespace OHOS { -namespace DistributedFS { -class NAsyncWorkFactory { -public: - explicit NAsyncWorkFactory(napi_env env) : env_(env) {} - ~NAsyncWorkFactory() = default; - virtual NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) = 0; - - napi_env env_ = nullptr; -}; -} // namespace DistributedFS -} // namespace OHOS \ 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 727f8269..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.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_promise.h" - -#include -#include -#include - -#include "log.h" - -namespace OHOS { -namespace DistributedFS { -using namespace std; - -NAsyncWorkPromise::NAsyncWorkPromise(napi_env env, NVal thisPtr) : NAsyncWorkFactory(env) -{ - ctx_ = new NAsyncContextPromise(thisPtr); -} -NAsyncWorkPromise::NAsyncWorkPromise(const NAsyncWorkPromise &in, napi_env env) : NAsyncWorkFactory(env) -{ - delete ctx_; - ctx_ = new NAsyncContextPromise(in.ctx_->thisPtr_.Deref(env)); -} - -static void PromiseOnExec(napi_env env, void *data) -{ - auto ctx = static_cast(data); - if (ctx->cbExec_) { - ctx->err_ = ctx->cbExec_(env); - } -} -static void PromiseOnComplete(napi_env env, napi_status status, void *data) -{ - auto ctx = static_cast(data); - if (ctx->cbComplete_) { - 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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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 9bef0eba..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_async_work_promise.h +++ /dev/null @@ -1,36 +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 "n_async_work_factory.h" - -namespace OHOS { -namespace DistributedFS { -class NAsyncWorkPromise : public NAsyncWorkFactory { -public: - NAsyncWorkPromise(napi_env env, NVal thisPtr); - ~NAsyncWorkPromise() = default; - NAsyncWorkPromise(const NAsyncWorkPromise &in, napi_env env); - NVal Schedule(std::string procedureName, NContextCBExec cbExec, NContextCBComplete cbComplete) final; - -private: - NAsyncContextPromise *ctx_; -}; -} // namespace DistributedFS -} // namespace OHOS \ 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 8b78ac9c..00000000 --- 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 12b216ab..00000000 --- a/interfaces/kits/js/src/common/napi/n_async/n_ref.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. - */ - -#pragma once - -#include "../n_val.h" -#include "../uni_header.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 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 c6c60ee9..00000000 --- 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) { - ERR_LOG("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 }); - INFO_LOG("Class %{public}s has been saved", className.c_str()); - } else { - ERR_LOG("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()) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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 e048ae80..00000000 --- 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) { - ERR_LOG("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) { - ERR_LOG("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 2ade0c07..00000000 --- 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 ed3a5ec7..00000000 --- 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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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 7ff5b294..00000000 --- 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 79a35d63..00000000 --- a/interfaces/kits/js/src/common/napi/n_val.cpp +++ /dev/null @@ -1,306 +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 - -#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)) { - ERR_LOG("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) { - ERR_LOG("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)) { - ERR_LOG("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) { - ERR_LOG("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::CreateInt32(napi_env env, int32_t val) -{ - napi_value res = nullptr; - napi_create_int32(env, val, &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::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::CreateUTF8String(napi_env env, const char* str, ssize_t len) -{ - napi_value res = nullptr; - napi_create_string_utf8(env, str, len, &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 }; -} -tuple NVal::CreateArrayBuffer(napi_env env, size_t len) -{ - napi_value val; - void *buf = nullptr; - napi_create_arraybuffer(env, len, &buf, &val); - return { { env, val }, { buf }}; -} - -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 0cb2f74a..00000000 --- a/interfaces/kits/js/src/common/napi/n_val.h +++ /dev/null @@ -1,79 +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 "sys/types.h" -#include "uni_header.h" -namespace OHOS { -namespace DistributedFS { -class NVal final { -public: - NVal() = default; - NVal(napi_env nEnv, napi_value nVal); - 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 CreateInt32(napi_env env, int32_t val); - static NVal CreateInt64(napi_env env, int64_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 CreateUTF8String(napi_env env, const char* str, ssize_t len); - static NVal CreateUint8Array(napi_env env, void *buf, size_t bufLen); - static std::tuple CreateArrayBuffer(napi_env env, size_t len); - /* 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 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 a79d4e1e..00000000 --- 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 0f1e0882..00000000 --- a/interfaces/kits/js/src/common/uni_error.cpp +++ /dev/null @@ -1,122 +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) -{ - if (!*this) { - return NVal::CreateUndefined(env).val_; - } - - 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) { - ERR_LOG("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) { - ERR_LOG("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) { - ERR_LOG("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 a4183986..00000000 --- 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/fms_napi.cpp b/interfaces/kits/js/src/fms_napi.cpp deleted file mode 100644 index 77de6749..00000000 --- a/interfaces/kits/js/src/fms_napi.cpp +++ /dev/null @@ -1,207 +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 "fms_napi.h" - -#include -#include -#include -#include -#include "common/napi/n_func_arg.h" -#include "common/uni_error.h" - -#include "common/napi/n_async/n_async_work_promise.h" -#include "common/napi/n_async/n_async_work_callback.h" -#include "sys/syscall.h" -#define gettid() syscall(__NR_gettid) - -#ifdef FILE_SUBSYSTEM_DEV_ON_PC -#define DEBUG_LOG(fmt, ...) -#endif -#ifndef FILE_SUBSYSTEM_DEV_ON_PC -#include "log.h" -#include "fms_proxy.h" -#include "ifms_client.h" -#endif -namespace OHOS { -namespace DistributedFS { -namespace FMS_NAPI { -using namespace std; -#ifndef FILE_SUBSYSTEM_DEV_ON_PC -using namespace FileManagerService; -#endif -struct AsyncFileInfoArg { - NRef _ref; -#ifndef FILE_SUBSYSTEM_DEV_ON_PC - vector fileRes; -#else - vector res; -#endif - explicit AsyncFileInfoArg(NVal ref) : _ref(ref) {}; - ~AsyncFileInfoArg() = default; -}; - -napi_value FMS_NAPI::CreateFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - bool succ = false; - unique_ptr name; - unique_ptr path; - tie(succ, name, ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid name"); - return nullptr; - } - tie(succ, path, ignore) = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - string uri = ""; -#ifndef FILE_SUBSYSTEM_DEV_ON_PC - FileManagerService::IFmsClient::GetFmsInstance()->CreateFile(name.get(), path.get(), uri); -#endif - return NVal::CreateUTF8String(env, uri).val_; -} - -napi_value FMS_NAPI::ListFile(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - - if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of argments unmatched"); - return nullptr; - } - - bool succ = false; - unique_ptr path; - tie(succ, path, ignore) = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - int64_t offset = 0; - int64_t count = 0; - bool hasOp = false; - // need to check SECOND valid ? - NVal op(env, NVal(env, funcArg[NARG_POS::SECOND]).val_); - if (op.HasProp("offset")) { - tie(succ, offset) = op.GetProp("offset").ToInt64(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid option"); - return nullptr; - } - hasOp = true; - } - - if (op.HasProp("count")) { - tie(succ, count) = op.GetProp("count").ToInt64(); - if (!succ) { - UniError(EINVAL).ThrowErr(env, "Invalid option"); - return nullptr; - } - hasOp = true; - } - napi_value fileArr; - napi_create_array(env, &fileArr); - auto arg = make_shared(NVal(env, fileArr)); - auto cbExec = [path = string(path.get()), offset, count, arg, fileArr] (napi_env env) -> UniError { -#ifndef FILE_SUBSYSTEM_DEV_ON_PC - int err = 0; - vector fileRes; - err = FileManagerService::IFmsClient::GetFmsInstance()->ListFile(path, offset, count, fileRes); - arg->fileRes = fileRes; - if (err) { - // need to add specific error - return UniError(EIO); - } -#else - vector resArr = {"name", "path", "type", "size", "added_time", "modified_time"}; - arg->res = resArr; -#endif - - return UniError(ERRNO_NOERR); - }; - - auto cbComplete = [arg](napi_env env, UniError err) -> NVal { -#ifndef FILE_SUBSYSTEM_DEV_ON_PC - for (unsigned int i = 0; i < arg->fileRes.size(); i++) { - NVal obj = NVal::CreateObject(env); - FileManagerService::FileInfo res = arg->fileRes[i]; - obj.AddProp("name", NVal::CreateUTF8String(env, res.GetName()).val_); - obj.AddProp("path", NVal::CreateUTF8String(env, res.GetPath()).val_); - obj.AddProp("type", NVal::CreateUTF8String(env, res.GetType()).val_); - obj.AddProp("size", NVal::CreateInt64(env, res.GetSize()).val_); - obj.AddProp("added_time", NVal::CreateInt64(env, res.GetAdded_Time()).val_); - obj.AddProp("modified_time", NVal::CreateInt64(env, res.GetModified_time()).val_); - napi_set_property(env, arg->_ref.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); - } -#else - vector resArr = {"name", "path", "type", "size", "added_time", "modified_time"}; - for (unsigned int i = 0; i < resArr.size(); i++) { - NVal obj = NVal::CreateObject(env); - for (auto s : arg->res) { - obj.AddProp(s, NVal::CreateUTF8String(env, s).val_); - } - napi_set_property(env, arg->_ref.Deref(env).val_, NVal::CreateInt32(env, i).val_, obj.val_); - } -#endif - if (err) { - return { env, err.GetNapiErr(env) }; - } else { - return NVal(env, arg->_ref.Deref(env).val_); - } - }; - string procedureName = "ListFile"; - int argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - if (argc == NARG_CNT::ONE || (argc == NARG_CNT::TWO && hasOp)) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - int cbIdx = ((hasOp == false) ? NARG_POS::SECOND : NARG_POS::THIRD); - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } -} - -napi_value FMS_NAPI::mkdir(napi_env env, napi_callback_info info) -{ - return NVal::CreateUndefined(env).val_; -} - -bool FMS_NAPI::Export() -{ - return exports_.AddProp({ - NVal::DeclareNapiFunction("listFile", ListFile), - NVal::DeclareNapiFunction("CreateFile", CreateFile), - NVal::DeclareNapiFunction("mkdir", mkdir), - }); -} - -string FMS_NAPI::GetClassName() -{ - return FMS_NAPI::className_; -} - -FMS_NAPI::FMS_NAPI(napi_env env, napi_value exports) : NExporter(env, exports) {} - -FMS_NAPI::~FMS_NAPI() {} -} // namespace FMS_NAPI -} // namespace DistributedFS -} // namespace OHOS diff --git a/interfaces/kits/js/src/fms_napi.h b/interfaces/kits/js/src/fms_napi.h deleted file mode 100644 index 2f5b8aec..00000000 --- a/interfaces/kits/js/src/fms_napi.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. - */ - -#pragma once - -#include "common/napi/n_exporter.h" - -namespace OHOS { -namespace DistributedFS { -namespace FMS_NAPI { -class FMS_NAPI final : public NExporter { -public: - inline static const std::string className_ = "__properities__"; - - static napi_value CreateFile(napi_env env, napi_callback_info info); - static napi_value ListFile(napi_env env, napi_callback_info info); - static napi_value mkdir(napi_env env, napi_callback_info info); - bool Export() override; - std::string GetClassName() override; - - FMS_NAPI(napi_env env, napi_value exports); - ~FMS_NAPI() override; -}; -} // namespace FMS_NAPI -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/module.cpp b/interfaces/kits/js/src/module.cpp deleted file mode 100644 index f783e20a..00000000 --- a/interfaces/kits/js/src/module.cpp +++ /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. - */ - -#include -#include - -#include "fms_napi.h" -#include "log.h" - -using namespace std; - -namespace OHOS { -namespace DistributedFS { -namespace FMS_NAPI { - -static napi_value Export(napi_env env, napi_value exports) -{ - std::vector> products; - products.emplace_back(make_unique(env, exports)); - - for (auto &&product : products) { - if (!product->Export()) { - ERR_LOG("INNER BUG. Failed to export class %{public}s for module filemanager", product->GetClassName().c_str()); - return nullptr; - } else { - ERR_LOG("Class %{public}s for module filemanager has been exported", product->GetClassName().c_str()); - } - } - return exports; -} - -NAPI_MODULE(filemanager, Export) -} // namespace FMS_NAPI -} // namespace DistributedFS -} // namespace OHOS \ No newline at end of file -- Gitee From 83a0cd1db868b69771c5800543b04e24c4d0d42a Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Wed, 15 Dec 2021 10:44:01 +0800 Subject: [PATCH 6/9] change file name Signed-off-by: panqiangbiao --- services/BUILD.gn | 11 ++++--- ...s_const.h => file_manager_service_const.h} | 0 .../{fms_proxy.cpp => file_manager_proxy.cpp} | 10 +++--- .../{fms_proxy.h => file_manager_proxy.h} | 4 +-- services/src/client/ifms_client.h | 4 +-- .../fileoper/{fms_fileinfo.h => file_info.h} | 0 .../fileoper/{fms_file_oper.h => file_oper.h} | 2 +- ...mediafile_oper.cpp => media_file_oper.cpp} | 32 +++++++++---------- ...fms_mediafile_oper.h => media_file_oper.h} | 4 +-- ...{fms_oper_factory.cpp => oper_factory.cpp} | 13 ++++---- .../{fms_oper_factory.h => oper_factory.h} | 2 +- ...s_service.cpp => file_manager_service.cpp} | 2 +- .../{fms_service.h => file_manager_service.h} | 2 +- ...stub.cpp => file_manager_service_stub.cpp} | 8 ++--- ...ice_stub.h => file_manager_service_stub.h} | 2 +- services/test/fms_test.cpp | 2 +- 16 files changed, 50 insertions(+), 48 deletions(-) rename services/include/{fms_const.h => file_manager_service_const.h} (100%) rename services/src/client/{fms_proxy.cpp => file_manager_proxy.cpp} (95%) rename services/src/client/{fms_proxy.h => file_manager_proxy.h} (93%) rename services/src/fileoper/{fms_fileinfo.h => file_info.h} (100%) rename services/src/fileoper/{fms_file_oper.h => file_oper.h} (94%) rename services/src/fileoper/{fms_mediafile_oper.cpp => media_file_oper.cpp} (89%) rename services/src/fileoper/{fms_mediafile_oper.h => media_file_oper.h} (92%) rename services/src/fileoper/{fms_oper_factory.cpp => oper_factory.cpp} (85%) rename services/src/fileoper/{fms_oper_factory.h => oper_factory.h} (96%) rename services/src/server/{fms_service.cpp => file_manager_service.cpp} (97%) rename services/src/server/{fms_service.h => file_manager_service.h} (96%) rename services/src/server/{fms_service_stub.cpp => file_manager_service_stub.cpp} (92%) rename services/src/server/{fms_service_stub.h => file_manager_service_stub.h} (96%) diff --git a/services/BUILD.gn b/services/BUILD.gn index a7556ab9..8d1d0675 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -18,6 +18,7 @@ group("fms") { deps = [ ":fms_service.rc", ":fms_server", + ":fms_exe", ] } @@ -47,11 +48,11 @@ ohos_shared_library("fms_server") { ] sources = [ - "src/server/fms_service_stub.cpp", - "src/server/fms_service.cpp", - "src/fileoper/fms_mediafile_oper.cpp", - "src/fileoper/fms_oper_factory.cpp", - "src/client/fms_proxy.cpp", + "src/server/file_manager_service_stub.cpp", + "src/server/file_manager_service.cpp", + "src/fileoper/media_file_oper.cpp", + "src/fileoper/oper_factory.cpp", + "src/client/file_manager_proxy.cpp", ] deps = [ diff --git a/services/include/fms_const.h b/services/include/file_manager_service_const.h similarity index 100% rename from services/include/fms_const.h rename to services/include/file_manager_service_const.h diff --git a/services/src/client/fms_proxy.cpp b/services/src/client/file_manager_proxy.cpp similarity index 95% rename from services/src/client/fms_proxy.cpp rename to services/src/client/file_manager_proxy.cpp index 0eecdbc0..17a55308 100644 --- a/services/src/client/fms_proxy.cpp +++ b/services/src/client/file_manager_proxy.cpp @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "fms_proxy.h" +#include "file_manager_proxy.h" -#include "fms_const.h" -#include "fms_fileinfo.h" -#include "fms_service_stub.h" +#include "file_manager_service_const.h" +#include "file_info.h" +#include "file_manager_service_stub.h" #include "log.h" using namespace std; @@ -110,7 +110,7 @@ int FileManagerProxy::ListFile(string path, int off, int count, vector return err; } -int FileManagerProxy::mkdir(string name, string path) +int FileManagerProxy::Mkdir(string name, string path) { int err; MessageParcel data; diff --git a/services/src/client/fms_proxy.h b/services/src/client/file_manager_proxy.h similarity index 93% rename from services/src/client/fms_proxy.h rename to services/src/client/file_manager_proxy.h index 2b3d6d1b..b19d44b9 100644 --- a/services/src/client/fms_proxy.h +++ b/services/src/client/file_manager_proxy.h @@ -14,7 +14,7 @@ */ #pragma once -#include "fms_service_stub.h" +#include "file_manager_service_stub.h" #include "ifms_client.h" #include "iremote_proxy.h" #include "iservice_registry.h" @@ -27,7 +27,7 @@ public: explicit FileManagerProxy(const sptr &impl); virtual ~FileManagerProxy() = default; static IFmsClient* GetFmsInstance(); - int mkdir(std::string name, std::string path); + int Mkdir(std::string name, std::string path); int ListFile(std::string path, int off, int count, std::vector &fileRes); int CreateFile(std::string name, std::string path, std::string &uri); diff --git a/services/src/client/ifms_client.h b/services/src/client/ifms_client.h index 3b50f90f..105411fb 100644 --- a/services/src/client/ifms_client.h +++ b/services/src/client/ifms_client.h @@ -14,7 +14,7 @@ */ #pragma once -#include "fms_fileinfo.h" +#include "file_info.h" namespace OHOS { namespace FileManagerService { @@ -24,7 +24,7 @@ public: static IFmsClient *GetFmsInstance(); - virtual int mkdir(std::string name, std::string path) = 0; + virtual int Mkdir(std::string name, std::string path) = 0; virtual int ListFile(std::string path, int off, int count, std::vector &fileRes) = 0; virtual int CreateFile(std::string name, std::string path, std::string &uri) = 0; }; diff --git a/services/src/fileoper/fms_fileinfo.h b/services/src/fileoper/file_info.h similarity index 100% rename from services/src/fileoper/fms_fileinfo.h rename to services/src/fileoper/file_info.h diff --git a/services/src/fileoper/fms_file_oper.h b/services/src/fileoper/file_oper.h similarity index 94% rename from services/src/fileoper/fms_file_oper.h rename to services/src/fileoper/file_oper.h index 7db107a4..f8027a3e 100644 --- a/services/src/fileoper/fms_file_oper.h +++ b/services/src/fileoper/file_oper.h @@ -26,7 +26,7 @@ namespace FileManagerService { class FileOper { public: virtual ~FileOper() = default; - virtual int mkdir(const std::string &name, const std::string &path) = 0; + virtual int Mkdir(const std::string &name, const std::string &path) = 0; virtual int ListFile(const std::string &path, int offset, int count, MessageParcel &data) = 0; virtual int CreateFile(const std::string &name, const std::string &path, std::string &uri) = 0; virtual int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) = 0; diff --git a/services/src/fileoper/fms_mediafile_oper.cpp b/services/src/fileoper/media_file_oper.cpp similarity index 89% rename from services/src/fileoper/fms_mediafile_oper.cpp rename to services/src/fileoper/media_file_oper.cpp index 6f0665c7..0eb60c86 100644 --- a/services/src/fileoper/fms_mediafile_oper.cpp +++ b/services/src/fileoper/media_file_oper.cpp @@ -13,12 +13,12 @@ * limitations under the License. */ -#include "fms_mediafile_oper.h" +#include "media_file_oper.h" #include -#include "fms_const.h" -#include "fms_fileinfo.h" +#include "file_info.h" +#include "file_manager_service_const.h" #include "ipc_types.h" #include "iremote_broker.h" #include "iremote_proxy.h" @@ -44,7 +44,7 @@ const std::vector> mediaMetaMap = { {0, "string"}, / int Insert(const string &name, const string &path, const string &type) { Media::ValuesBucket values; - Media::MediaLibraryDataAbility abi; + Media::MediaLibraryDataAbility mediaLibDb; string abilityUri = Media::MEDIALIBRARY_DATA_URI; string oper; if (type == "album") { @@ -59,8 +59,8 @@ int Insert(const string &name, const string &path, const string &type) // need MEDIA_DATA_DB_NAME values.PutLong(Media::MEDIA_DATA_DB_DATE_ADDED, statInfo.st_ctime); values.PutLong(Media::MEDIA_DATA_DB_DATE_MODIFIED, statInfo.st_mtime); - abi.InitMediaLibraryRdbStore(); - return abi.Insert(createUri, values); + mediaLibDb.InitMediaLibraryRdbStore(); + return mediaLibDb.Insert(createUri, values); } int MediaFileOper::CreateFile(const std::string &name, const std::string &path, std::string &uri) @@ -79,7 +79,7 @@ int MediaFileOper::CreateFile(const std::string &name, const std::string &path, return SUCCESS; } -bool pushFileInfo(shared_ptr result, MessageParcel &reply) +bool PushFileInfo(shared_ptr result, MessageParcel &reply) { string id; string uri; @@ -112,7 +112,7 @@ int GetFileInfoFromResult(shared_ptr result, MessageP result->GoToFirstRow(); reply.WriteInt32(count); for (int i = 0; i < count; i++) { - pushFileInfo(result, reply); + PushFileInfo(result, reply); result->GoToNextRow(); } return SUCCESS; @@ -125,11 +125,11 @@ bool GetRelativePath(const string &path, string &relativePath) vector selectionArgs = { path }; predicates.SetWhereClause(selection); predicates.SetWhereArgs(selectionArgs); - Media::MediaLibraryDataAbility abi; - abi.InitMediaLibraryRdbStore(); + Media::MediaLibraryDataAbility mediaLibDb; + mediaLibDb.InitMediaLibraryRdbStore(); Uri uri(Media::MEDIALIBRARY_DATA_URI); vector columns; - shared_ptr result = abi.Query(uri, columns, predicates); + shared_ptr result = mediaLibDb.Query(uri, columns, predicates); if (result == nullptr) { return false; } @@ -161,7 +161,7 @@ int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel case FILE_OPER::MKDIR: { string name = data.ReadString(); string path = data.ReadString(); - errCode = mkdir(name, path); + errCode = Mkdir(name, path); break; } case FILE_OPER::LIST_FILE: { @@ -201,11 +201,11 @@ int MediaFileOper::ListFile(const string &path, int offset, int count, MessagePa vector selectionArgs = { relativePath }; predicates.SetWhereClause(selection); predicates.SetWhereArgs(selectionArgs); - Media::MediaLibraryDataAbility abi; - abi.InitMediaLibraryRdbStore(); + Media::MediaLibraryDataAbility mediaLibDb; + mediaLibDb.InitMediaLibraryRdbStore(); Uri uri(Media::MEDIALIBRARY_DATA_URI); vector columns; - shared_ptr result = abi.Query(uri, columns, predicates); + shared_ptr result = mediaLibDb.Query(uri, columns, predicates); if (result == nullptr) { ERR_LOG("MediaFileOper::ListFile folder is empty"); return E_EMPTYFOLDER; @@ -214,7 +214,7 @@ int MediaFileOper::ListFile(const string &path, int offset, int count, MessagePa return SUCCESS; } -int MediaFileOper::mkdir(const string &name, const string &path) +int MediaFileOper::Mkdir(const string &name, const string &path) { string type = "album"; Insert(name, path, type); diff --git a/services/src/fileoper/fms_mediafile_oper.h b/services/src/fileoper/media_file_oper.h similarity index 92% rename from services/src/fileoper/fms_mediafile_oper.h rename to services/src/fileoper/media_file_oper.h index e0dac288..76d84858 100644 --- a/services/src/fileoper/fms_mediafile_oper.h +++ b/services/src/fileoper/media_file_oper.h @@ -16,14 +16,14 @@ #pragma once #include -#include "fms_file_oper.h" +#include "file_oper.h" namespace OHOS { namespace FileManagerService { class MediaFileOper : public FileOper { public: virtual ~MediaFileOper() = default; - int mkdir(const std::string &name, const std::string &path) override; + int Mkdir(const std::string &name, const std::string &path) override; int ListFile(const std::string &path, int offset, int count, MessageParcel &data) override; int CreateFile(const std::string &name, const std::string &path, std::string &uri) override; int OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) override; diff --git a/services/src/fileoper/fms_oper_factory.cpp b/services/src/fileoper/oper_factory.cpp similarity index 85% rename from services/src/fileoper/fms_oper_factory.cpp rename to services/src/fileoper/oper_factory.cpp index 69616770..2255c87d 100644 --- a/services/src/fileoper/fms_oper_factory.cpp +++ b/services/src/fileoper/oper_factory.cpp @@ -13,22 +13,23 @@ * limitations under the License. */ -#include "fms_oper_factory.h" +#include "oper_factory.h" -#include "fms_const.h" -#include "fms_file_oper.h" -#include "fms_mediafile_oper.h" +#include "file_oper.h" +#include "file_manager_service_const.h" #include "log.h" +#include "media_file_oper.h" using namespace std; namespace OHOS { namespace FileManagerService { FileOper* OperFactory::getFileOper(int equipmentId) { + FileOper* fp = nullptr; DEBUG_LOG("OperFactory::getFileOper %{public}d.", equipmentId); switch (equipmentId) { case EQUIPMENT::INTERNAL: { - return new MediaFileOper(); + fp = new MediaFileOper(); break; } case EQUIPMENT::EXTERNAL: { @@ -40,7 +41,7 @@ FileOper* OperFactory::getFileOper(int equipmentId) break; } } - return nullptr; + return fp; } } // namespace FileManagerService diff --git a/services/src/fileoper/fms_oper_factory.h b/services/src/fileoper/oper_factory.h similarity index 96% rename from services/src/fileoper/fms_oper_factory.h rename to services/src/fileoper/oper_factory.h index 430b2a09..992e2ccb 100644 --- a/services/src/fileoper/fms_oper_factory.h +++ b/services/src/fileoper/oper_factory.h @@ -17,7 +17,7 @@ #include -#include "fms_file_oper.h" +#include "file_oper.h" namespace OHOS { namespace FileManagerService { diff --git a/services/src/server/fms_service.cpp b/services/src/server/file_manager_service.cpp similarity index 97% rename from services/src/server/fms_service.cpp rename to services/src/server/file_manager_service.cpp index 5e3d14ed..e0760d5e 100644 --- a/services/src/server/fms_service.cpp +++ b/services/src/server/file_manager_service.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "fms_service.h" +#include "file_manager_service.h" #include "iservice_registry.h" #include "log.h" diff --git a/services/src/server/fms_service.h b/services/src/server/file_manager_service.h similarity index 96% rename from services/src/server/fms_service.h rename to services/src/server/file_manager_service.h index 6ae6679f..48c14e27 100644 --- a/services/src/server/fms_service.h +++ b/services/src/server/file_manager_service.h @@ -15,9 +15,9 @@ #pragma once +#include "file_manager_service_stub.h" #include "iremote_stub.h" #include "system_ability.h" -#include "fms_service_stub.h" namespace OHOS { namespace FileManagerService { diff --git a/services/src/server/fms_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp similarity index 92% rename from services/src/server/fms_service_stub.cpp rename to services/src/server/file_manager_service_stub.cpp index c414783d..7de411f3 100644 --- a/services/src/server/fms_service_stub.cpp +++ b/services/src/server/file_manager_service_stub.cpp @@ -13,12 +13,12 @@ * limitations under the License. */ -#include "fms_service_stub.h" +#include "file_manager_service_stub.h" -#include "fms_const.h" -#include "fms_oper_factory.h" -#include "fms_service.h" +#include "file_manager_service_const.h" +#include "file_manager_service.h" #include "log.h" +#include "oper_factory.h" using namespace std; diff --git a/services/src/server/fms_service_stub.h b/services/src/server/file_manager_service_stub.h similarity index 96% rename from services/src/server/fms_service_stub.h rename to services/src/server/file_manager_service_stub.h index fbf3b2ec..0faf4094 100644 --- a/services/src/server/fms_service_stub.h +++ b/services/src/server/file_manager_service_stub.h @@ -19,7 +19,7 @@ #include "iremote_broker.h" #include "iremote_proxy.h" #include "iremote_stub.h" -#include "../fileoper/fms_oper_factory.h" +#include "oper_factory.h" namespace OHOS { namespace FileManagerService { diff --git a/services/test/fms_test.cpp b/services/test/fms_test.cpp index a9bb17ec..231d5c52 100644 --- a/services/test/fms_test.cpp +++ b/services/test/fms_test.cpp @@ -22,7 +22,7 @@ #include #include #include -#include "fms_proxy.h" +#include "file_manager_proxy.h" namespace { using namespace std; -- Gitee From 1343364017e44818d0d1c89fbee594305d35b8e5 Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Wed, 15 Dec 2021 11:15:53 +0800 Subject: [PATCH 7/9] fix code issue Signed-off-by: panqiangbiao --- services/BUILD.gn | 31 ++++++++++++ services/include/file_manager_service_const.h | 1 - services/src/client/file_manager_proxy.cpp | 1 - services/src/client/file_manager_proxy.h | 6 +-- services/src/fileoper/media_file_oper.cpp | 47 ++++++++++--------- services/src/fileoper/oper_factory.cpp | 1 - services/src/server/file_manager_service.h | 6 --- .../src/server/file_manager_service_stub.cpp | 1 - services/test/fms_test.cpp | 1 - 9 files changed, 58 insertions(+), 37 deletions(-) diff --git a/services/BUILD.gn b/services/BUILD.gn index 8d1d0675..b2858907 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -80,6 +80,37 @@ ohos_shared_library("fms_server") { ] } + +ohos_executable("fms_exe") { + install_enable = true + + sources = [ "exe/main.cpp" ] + + include_dirs = [ + "$FMS_BASE_DIR/include", + "$FMS_BASE_DIR/src/client", + "$FMS_BASE_DIR/src/server", + "$FMS_BASE_DIR/src/fileoper", + ] + + deps = [ + "//utils/native/base:utils", + "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog", + ":fms_server", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] + + subsystem_name = "storage" + part_name = "filemanager" +} + + # Unittest group("test") { testonly = true diff --git a/services/include/file_manager_service_const.h b/services/include/file_manager_service_const.h index f6360a40..ec4509f7 100644 --- a/services/include/file_manager_service_const.h +++ b/services/include/file_manager_service_const.h @@ -36,6 +36,5 @@ const int32_t SUCCESS = 0; const int32_t FAIL = -1; const int32_t E_NOEXIST = -2; // file not exist const int32_t E_EMPTYFOLDER = -3; // folder empty - } // namespace FileManagerService } // namespace OHOS diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp index 17a55308..709ba080 100644 --- a/services/src/client/file_manager_proxy.cpp +++ b/services/src/client/file_manager_proxy.cpp @@ -129,6 +129,5 @@ int FileManagerProxy::Mkdir(string name, string path) DEBUG_LOG("FileManagerProxy::mkdir reply %{public}d", err); return err; } - } // FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/client/file_manager_proxy.h b/services/src/client/file_manager_proxy.h index b19d44b9..4df64c1a 100644 --- a/services/src/client/file_manager_proxy.h +++ b/services/src/client/file_manager_proxy.h @@ -27,9 +27,9 @@ public: explicit FileManagerProxy(const sptr &impl); virtual ~FileManagerProxy() = default; static IFmsClient* GetFmsInstance(); - int Mkdir(std::string name, std::string path); - int ListFile(std::string path, int off, int count, std::vector &fileRes); - int CreateFile(std::string name, std::string path, std::string &uri); + int Mkdir(std::string name, std::string path) override; + int ListFile(std::string path, int off, int count, std::vector &fileRes) override; + int CreateFile(std::string name, std::string path, std::string &uri) override; private: static inline BrokerDelegator delegator_; diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp index 0eb60c86..937a0c51 100644 --- a/services/src/fileoper/media_file_oper.cpp +++ b/services/src/fileoper/media_file_oper.cpp @@ -31,16 +31,21 @@ using namespace std; namespace OHOS { namespace FileManagerService { -const std::vector mediaData = { Media::MEDIA_DATA_DB_ID, - Media::MEDIA_DATA_DB_URI, - Media::MEDIA_DATA_DB_NAME }; -const std::vector> mediaMetaMap = { {0, "string"}, // 0 id - {1, "string"}, // 1 fileuri - {4, "string"}, // 4 type - {6, "string"}, // 6 name - {7, "int"}, // 7 size - {8, "int"}, // 8 at - {9, "int"} }; // 9 mt +const std::vector mediaData = { + Media::MEDIA_DATA_DB_ID, + Media::MEDIA_DATA_DB_URI, + Media::MEDIA_DATA_DB_NAME + }; +const std::vector> mediaMetaMap = { + {0, "string"}, // 0 id + {1, "string"}, // 1 fileuri + {4, "string"}, // 4 type + {6, "string"}, // 6 name + {7, "int"}, // 7 size + {8, "int"}, // 8 at + // 9 mt + {9, "int"} + }; int Insert(const string &name, const string &path, const string &type) { Media::ValuesBucket values; @@ -49,7 +54,7 @@ int Insert(const string &name, const string &path, const string &type) string oper; if (type == "album") { oper = Media::MEDIA_ALBUMOPRN + "/" + Media::MEDIA_ALBUMOPRN_CREATEALBUM; - } else if(type == "file") { + } else if (type == "file") { oper = Media::MEDIA_FILEOPRN + "/" + Media::MEDIA_FILEOPRN_CREATEASSET; } Uri createUri(abilityUri + "/" + oper); @@ -66,13 +71,11 @@ int Insert(const string &name, const string &path, const string &type) int MediaFileOper::CreateFile(const std::string &name, const std::string &path, std::string &uri) { string type = "file"; - int index = Insert(name, path, type); - // media type need to check the path if (index < 0) { - ERR_LOG("MediaFileOper:: Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); - return index; + ERR_LOG("MediaFileOper:: Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); + return index; } uri = Media::MEDIALIBRARY_FILE_URI; uri += "/" + to_string(index); @@ -87,8 +90,7 @@ bool PushFileInfo(shared_ptr result, MessageParcel &r result->GetString(mediaMetaMap[1].first, uri); reply.WriteString(uri + "/" + id); for (int i = 2; i < mediaMetaMap.size(); i++) { - if(mediaMetaMap[i].second == "string") - { + if (mediaMetaMap[i].second == "string") { string value; result->GetString(mediaMetaMap[i].first, value); reply.WriteString(value); @@ -141,12 +143,12 @@ bool GetRelativePath(const string &path, string &relativePath) } int32_t columnIndex; int ret = result->GetColumnIndex(Media::MEDIA_DATA_DB_FILE_PATH, columnIndex); - if(ret != NativeRdb::E_OK) { + if (ret != NativeRdb::E_OK) { return false; } result->GoToFirstRow(); ret = result->GetString(columnIndex, relativePath); - if(ret != NativeRdb::E_OK) { + if (ret != NativeRdb::E_OK) { return false; } DEBUG_LOG("GetRelativePath %{public}s", relativePath.c_str()); @@ -157,7 +159,7 @@ int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel { int errCode = SUCCESS; // media process - switch(code) { + switch (code) { case FILE_OPER::MKDIR: { string name = data.ReadString(); string path = data.ReadString(); @@ -188,11 +190,11 @@ int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel int MediaFileOper::ListFile(const string &path, int offset, int count, MessageParcel &reply) { - //get the relative path from the path uri + // get the relative path from the path uri string relativePath; DEBUG_LOG("ListFile %{public}s", path.c_str()); - if(!GetRelativePath(path, relativePath)) { + if (!GetRelativePath(path, relativePath)) { ERR_LOG("MediaFileOper::path not exsit"); return E_NOEXIST; } @@ -221,6 +223,5 @@ int MediaFileOper::Mkdir(const string &name, const string &path) DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); return 1; } - } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/fileoper/oper_factory.cpp b/services/src/fileoper/oper_factory.cpp index 2255c87d..445fac50 100644 --- a/services/src/fileoper/oper_factory.cpp +++ b/services/src/fileoper/oper_factory.cpp @@ -43,6 +43,5 @@ FileOper* OperFactory::getFileOper(int equipmentId) } return fp; } - } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/server/file_manager_service.h b/services/src/server/file_manager_service.h index 48c14e27..181d29d4 100644 --- a/services/src/server/file_manager_service.h +++ b/services/src/server/file_manager_service.h @@ -21,21 +21,15 @@ namespace OHOS { namespace FileManagerService { - class FileManagerService : public SystemAbility, public FileManagerServiceStub { DECLARE_SYSTEM_ABILITY(FileManagerService); public: DISALLOW_COPY_AND_MOVE(FileManagerService); explicit FileManagerService(int32_t systemAbilityId, bool runOnCreate = true); virtual ~FileManagerService() = default; - void OnDump() override; - void OnStart() override; - void OnStop() override; - }; - } // namespace FileManagerService } // namespace OHOS diff --git a/services/src/server/file_manager_service_stub.cpp b/services/src/server/file_manager_service_stub.cpp index 7de411f3..d286a6f0 100644 --- a/services/src/server/file_manager_service_stub.cpp +++ b/services/src/server/file_manager_service_stub.cpp @@ -58,6 +58,5 @@ int FileManagerServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, reply.WriteInt32(errCode); return errCode; } - } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/test/fms_test.cpp b/services/test/fms_test.cpp index 231d5c52..a339a9c6 100644 --- a/services/test/fms_test.cpp +++ b/services/test/fms_test.cpp @@ -222,5 +222,4 @@ HWTEST_F(FMSTest, FMS_Mediafile_mkdir_0000, testing::ext::TestSize.Level1) } cout << "FMSTest-end FMS_Mediafile_mkdir_0000" << endl; } - } // namespace \ No newline at end of file -- Gitee From b90618918fb9f72a4098d58467bcac878a78cf81 Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Wed, 15 Dec 2021 15:19:24 +0800 Subject: [PATCH 8/9] fix code issue Signed-off-by: panqiangbiao --- README.md | 19 +++++++----------- figures/file manager service.png | Bin 0 -> 34766 bytes services/include/file_manager_service_const.h | 4 ++-- services/src/client/file_manager_proxy.cpp | 11 ++++------ services/src/fileoper/file_info.h | 12 +++++------ services/src/fileoper/media_file_oper.cpp | 3 --- services/src/fileoper/oper_factory.cpp | 4 ++-- services/src/server/file_manager_service.cpp | 6 ++---- .../src/server/file_manager_service_stub.h | 1 - 9 files changed, 23 insertions(+), 37 deletions(-) create mode 100644 figures/file manager service.png diff --git a/README.md b/README.md index 12b248b0..520b34b1 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,21 @@ 支持能力列举如下: - 公共文件路径下媒体文件查询,创建 + 媒体文件包括图片,音频,视频。媒体文件通过相册方式呈现 + - 公共文件路径下文档文件查询、创建 + 文档文件包括其他文件,外部存储卡内的文件,文件以目录树方式呈现 + +**图 1** 公共文件管理架构图 +![](figures/file manager service.png "公共文件管理架构图") ## 目录 仓目录结构如下: ``` /foundation/storage/user_file_manger # fms组件代码 +├── figures # 插图文件 ├── serivce # 框架代码 │   ├── etc # 内部接口实现 │   ├── src # 内部接口实现 @@ -36,17 +43,9 @@ ## 使用说明 ### 创建文件 1. - ``` 接口流程 应用通过接口让媒体库创建文件,返回文件uri, 应用自己通过openfile打开uri,获取fd进行文件操作。 - // 应用A - // 拉起filepicker 获取 uri - import media_library from '@ohos.media_library' - fd = media_library.openfile(uri) - fileio.write(fd, data) - fileio.close() - // file picker 流程 // media_path通过filepicker获取待保存目录uri import filemanager from '@ohos.filemanager' @@ -60,10 +59,6 @@ //类型错误,重名... // fail }) - - // FMS - mediaLib.createAsset(name) - return fileuri ``` ## 相关仓 diff --git a/figures/file manager service.png b/figures/file manager service.png new file mode 100644 index 0000000000000000000000000000000000000000..8aa79a296704af54e3f1242e897f06d8ed0b1a6f GIT binary patch literal 34766 zcmdqJWmH_v_C84RlHl$h+?~cHgvKom1a}f#gErD6xHlRc0*xhja1Yi%u;3(E8h3Y{ zCinjCx?}6V)_j_o4_Tb9Q>Us`()=SJ_v61OeJ&+$ zQBcCIl!3B3KBjwZ;YKtD-s^r3qJj05QY#xx7b8B2eO7BfRTdHrzf6I?Oo?$MB+I_| z_4~0jnAq?4O4KIaJZR*OSyPZN2XDD$FR$b5d2r@U}hcF+ri}kpLv=p9R)kT(){%UvfbW}ik9Gq zt8SuK$YJ8$j%3>XA|Cw4IwR@r?-45sw{xR3mr$9T$2nfXdpjN$g9EQm(dBU-e@i>E z*+1UUB7HrHoPfT7>vPFtyOP06klf>N-#+ArJ>Gct1o^-!_n)p)Zl0mqwCaH^3Y#Kl zT3;8gq4(u+Z_TDFQ~~}6q)91~(=+BF{^1?KSi)J6$9lR1C0sm-}tS>xTe^C!jItnT{;bIc{mLuO5)%4<;d}7Z=?Vsa;d`OgvJw z%I=Dk&;W4A+CO(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GtUKdE5S-r&xV zvB&Wd@(y7=+_ns*FTz@7##QJsT5KomPKP}W)RX;9q=P41f%CGinCX*=IeG%q`jlr; zIb1UI43QTki3jWxLc+&7{e{C9yWK-%Mhe|69sODcgUqe_>&J*1!`Xj>24_-%<{Q0s zjpm${-q!J85=c7(v@7KapseW4pIP;aF?M0>y{wak--$D9$oDT~%cb7;LLginhk zr)GZ@oM*n)y#ak1(*-2RX~H-bar4DLLBhM#t;bHNeG9qVbj%Yep81aVyXo_5y<+%; z72XLh@87qpmmU7a#HUyh_CErxj=dp%wGeoDZ;#eRjsDIh%p7#MKGHnCcZkVo>V$)G zxFogU>6I{%K= z-j@UQ573z_;(TN&{okVB|0`~c1&9_qC3tM%J+}1ruKNBHHJ0$uaEfw&0-5|zn-OV! z#ddoa+Hqhog#x71n0a75ybi(rFX++H1E)h^NFj6XFmhgwbYvw^6Zj~AktDDZ^hsI5 z`ac0&^4L&C*tosGe47yDzqv>@mj7?DNY9_&hwz7}3x_xGkUs(bR1`Gjt7YGX{x55y B34#Cs literal 0 HcmV?d00001 diff --git a/services/include/file_manager_service_const.h b/services/include/file_manager_service_const.h index ec4509f7..5eb1218d 100644 --- a/services/include/file_manager_service_const.h +++ b/services/include/file_manager_service_const.h @@ -25,8 +25,8 @@ enum FILE_OPER { }; enum EQUIPMENT { - INTERNAL, - EXTERNAL + INTERNAL_CARD, + EXTERNAL_CARD }; const int32_t CODE_MASK = 0xff; diff --git a/services/src/client/file_manager_proxy.cpp b/services/src/client/file_manager_proxy.cpp index 709ba080..80a65d19 100644 --- a/services/src/client/file_manager_proxy.cpp +++ b/services/src/client/file_manager_proxy.cpp @@ -68,18 +68,16 @@ IFmsClient *IFmsClient::GetFmsInstance() { auto samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (samgr == nullptr) { - DEBUG_LOG("samgr object is NULL."); + ERR_LOG("samgr object is NULL."); return nullptr; } sptr object = samgr->GetSystemAbility(FILE_MANAGER_SERVICE_ID); if (object == nullptr) { - DEBUG_LOG("FileManager Service object is NULL."); + ERR_LOG("FileManager Service object is NULL."); return nullptr; } - static FileManagerProxy msProxy(object); - - DEBUG_LOG("FileManagerProxy::GetFmsInstance"); - return &msProxy; + static FileManagerProxy proxy(object); + return &proxy; } int FileManagerProxy::ListFile(string path, int off, int count, vector &fileRes) @@ -126,7 +124,6 @@ int FileManagerProxy::Mkdir(string name, string path) return err; } reply.ReadInt32(err); - DEBUG_LOG("FileManagerProxy::mkdir reply %{public}d", err); return err; } } // FileManagerService diff --git a/services/src/fileoper/file_info.h b/services/src/fileoper/file_info.h index d5cd9082..9262ccc3 100644 --- a/services/src/fileoper/file_info.h +++ b/services/src/fileoper/file_info.h @@ -30,27 +30,27 @@ public: FileInfo(const std::string &name, const std::string &path, const std::string &type, int64_t size, int64_t added_time, int64_t modified_time) : path_(path), name_(name), type_(type), size_(size), added_time_(added_time), modified_time_(modified_time) {} - std::string GetName() + std::string GetName() const { return name_; } - std::string GetPath() + std::string GetPath() const { return path_; } - std::string GetType() + std::string GetType() const { return type_; } - int64_t GetSize() + int64_t GetSize() const { return size_; } - int64_t GetAdded_Time() + int64_t GetAdded_Time() const { return added_time_; } - int64_t GetModified_time() + int64_t GetModified_time() const { return modified_time_; } diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp index 937a0c51..ea9d2ba5 100644 --- a/services/src/fileoper/media_file_oper.cpp +++ b/services/src/fileoper/media_file_oper.cpp @@ -151,7 +151,6 @@ bool GetRelativePath(const string &path, string &relativePath) if (ret != NativeRdb::E_OK) { return false; } - DEBUG_LOG("GetRelativePath %{public}s", relativePath.c_str()); return true; } @@ -192,8 +191,6 @@ int MediaFileOper::ListFile(const string &path, int offset, int count, MessagePa { // get the relative path from the path uri string relativePath; - - DEBUG_LOG("ListFile %{public}s", path.c_str()); if (!GetRelativePath(path, relativePath)) { ERR_LOG("MediaFileOper::path not exsit"); return E_NOEXIST; diff --git a/services/src/fileoper/oper_factory.cpp b/services/src/fileoper/oper_factory.cpp index 445fac50..542d8858 100644 --- a/services/src/fileoper/oper_factory.cpp +++ b/services/src/fileoper/oper_factory.cpp @@ -28,11 +28,11 @@ FileOper* OperFactory::getFileOper(int equipmentId) FileOper* fp = nullptr; DEBUG_LOG("OperFactory::getFileOper %{public}d.", equipmentId); switch (equipmentId) { - case EQUIPMENT::INTERNAL: { + case EQUIPMENT::INTERNAL_CARD: { fp = new MediaFileOper(); break; } - case EQUIPMENT::EXTERNAL: { + case EQUIPMENT::EXTERNAL_CARD: { // do Exteranl storage process; // return ExternalOper() break; diff --git a/services/src/server/file_manager_service.cpp b/services/src/server/file_manager_service.cpp index e0760d5e..2a924a62 100644 --- a/services/src/server/file_manager_service.cpp +++ b/services/src/server/file_manager_service.cpp @@ -30,10 +30,9 @@ void FileManagerService::OnDump() { } void FileManagerService::OnStart() { - DEBUG_LOG("FileManagerService::OnStart called"); bool res = Publish(this); - if (res) { - DEBUG_LOG("FileManagerService OnStart valid"); + if (!res) { + ERR_LOG("FileManagerService OnStart invalid"); } } @@ -41,6 +40,5 @@ void FileManagerService::OnStop() { DEBUG_LOG("FileManagerService OnStop"); } - } // namespace FileManagerService } // namespace OHOS \ No newline at end of file diff --git a/services/src/server/file_manager_service_stub.h b/services/src/server/file_manager_service_stub.h index 0faf4094..d0fbc97e 100644 --- a/services/src/server/file_manager_service_stub.h +++ b/services/src/server/file_manager_service_stub.h @@ -34,6 +34,5 @@ public: virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; - } // namespace FileManagerService } // namespace OHOS -- Gitee From 8639a08bff23c69fce7f17d36d0e25393298639a Mon Sep 17 00:00:00 2001 From: panqiangbiao Date: Wed, 15 Dec 2021 15:31:41 +0800 Subject: [PATCH 9/9] fix code issue Signed-off-by: panqiangbiao --- services/src/fileoper/media_file_oper.cpp | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/services/src/fileoper/media_file_oper.cpp b/services/src/fileoper/media_file_oper.cpp index ea9d2ba5..2e9734bd 100644 --- a/services/src/fileoper/media_file_oper.cpp +++ b/services/src/fileoper/media_file_oper.cpp @@ -68,20 +68,6 @@ int Insert(const string &name, const string &path, const string &type) return mediaLibDb.Insert(createUri, values); } -int MediaFileOper::CreateFile(const std::string &name, const std::string &path, std::string &uri) -{ - string type = "file"; - int index = Insert(name, path, type); - // media type need to check the path - if (index < 0) { - ERR_LOG("MediaFileOper:: Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); - return index; - } - uri = Media::MEDIALIBRARY_FILE_URI; - uri += "/" + to_string(index); - return SUCCESS; -} - bool PushFileInfo(shared_ptr result, MessageParcel &reply) { string id; @@ -154,6 +140,20 @@ bool GetRelativePath(const string &path, string &relativePath) return true; } +int MediaFileOper::CreateFile(const std::string &name, const std::string &path, std::string &uri) +{ + string type = "file"; + int index = Insert(name, path, type); + // media type need to check the path + if (index < 0) { + ERR_LOG("MediaFileOper:: Fail to create fail %{public}s %{public}s", name.c_str(), path.c_str()); + return index; + } + uri = Media::MEDIALIBRARY_FILE_URI; + uri += "/" + to_string(index); + return SUCCESS; +} + int MediaFileOper::OperProcess(uint32_t code, MessageParcel &data, MessageParcel &reply) { int errCode = SUCCESS; @@ -218,7 +218,7 @@ int MediaFileOper::Mkdir(const string &name, const string &path) string type = "album"; Insert(name, path, type); DEBUG_LOG("MediaFileOper::mkdir path %{public}s.", path.c_str()); - return 1; + return SUCCESS; } } // namespace FileManagerService } // namespace OHOS \ No newline at end of file -- Gitee