From 9baf940625a1318c0cbce7ec3c11c4903cfba6ed Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 10:15:13 +0800 Subject: [PATCH 1/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/BUILD.gn | 5 + .../js/src/mod_fs/ani/bind_function_class.cpp | 9 +- .../js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 31 ++++++ .../mod_fs/properties/ani/connectdfs_ani.cpp | 95 +++++++++++++++++++ .../mod_fs/properties/ani/connectdfs_ani.h | 57 +++++++++++ .../properties/ani/disconnectdfs_ani.cpp | 46 +++++++++ .../mod_fs/properties/ani/disconnectdfs_ani.h | 38 ++++++++ .../src/mod_fs/properties/connectdfs_core.cpp | 50 ++++++++++ .../src/mod_fs/properties/connectdfs_core.h | 41 ++++++++ .../mod_fs/properties/disconnectdfs_core.cpp | 50 ++++++++++ .../mod_fs/properties/disconnectdfs_core.h | 33 +++++++ 11 files changed, 453 insertions(+), 2 deletions(-) create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/connectdfs_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 540b850ab..7ef938dfb 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -707,10 +707,12 @@ ohos_shared_library("ani_fs_class") { "src/mod_fs/properties/access_core.cpp", "src/mod_fs/properties/ani/access_ani.cpp", "src/mod_fs/properties/ani/close_ani.cpp", + "src/mod_fs/properties/ani/connectdfs_ani.cpp", "src/mod_fs/properties/ani/copy_ani.cpp", "src/mod_fs/properties/ani/copy_file_ani.cpp", "src/mod_fs/properties/ani/create_randomaccessfile_ani.cpp", "src/mod_fs/properties/ani/create_stream_ani.cpp", + "src/mod_fs/properties/ani/disconnectdfs_ani.cpp", "src/mod_fs/properties/ani/dup_ani.cpp", "src/mod_fs/properties/ani/fdatasync_ani.cpp", "src/mod_fs/properties/ani/fdopen_stream_ani.cpp", @@ -734,11 +736,14 @@ ohos_shared_library("ani_fs_class") { "src/mod_fs/properties/ani/write_ani.cpp", "src/mod_fs/properties/ani/xattr_ani.cpp", "src/mod_fs/properties/close_core.cpp", + "src/mod_fs/properties/connectdfs_core.cpp", "src/mod_fs/properties/copy_core.cpp", "src/mod_fs/properties/copy_file_core.cpp", "src/mod_fs/properties/copy_listener/trans_listener_core.cpp", "src/mod_fs/properties/create_randomaccessfile_core.cpp", "src/mod_fs/properties/create_stream_core.cpp", + "src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp", + "src/mod_fs/properties/disconnectdfs_core.cpp", "src/mod_fs/properties/dup_core.cpp", "src/mod_fs/properties/fdatasync_core.cpp", "src/mod_fs/properties/fdopen_stream_core.cpp", diff --git a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp index 07c00bea7..0d08fc919 100644 --- a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp +++ b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp @@ -21,8 +21,10 @@ #include "bind_function.h" #include "close_ani.h" #include "copy_ani.h" +#include "connectdfs_ani.h" #include "copy_file_ani.h" #include "create_randomaccessfile_ani.h" +#include "disconnectdfs_ani.h" #include "fdatasync_ani.h" #include "create_stream_ani.h" #include "fdopen_stream_ani.h" @@ -182,6 +184,9 @@ static ani_status BindStaticMethods(ani_env *env) ani_native_function { "unlinkSync", nullptr, reinterpret_cast(UnlinkAni::UnlinkSync) }, ani_native_function { "writeSync", nullptr, reinterpret_cast(WriteAni::WriteSync) }, ani_native_function { "utimes", nullptr, reinterpret_cast(UtimesAni::Utimes) }, + ani_native_function { "doConnectDfs", nullptr, reinterpret_cast(ConnectDfsAni::ConnectDfsSync) }, + ani_native_function { + "doDisConnectDfs", nullptr, reinterpret_cast(DisConnectDfsAni::DisConnectDfsSync) } }; return BindClass(env, className, methods); } @@ -229,12 +234,12 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) HILOGE("Cannot bind native methods for RafFile Class"); return status; }; - + if ((status = BindStreamMethods(env)) != ANI_OK) { HILOGE("Cannot bind native methods for Stream Class!"); return status; }; - + if ((status = BindTaskSignalClassMethods(env)) != ANI_OK) { HILOGE("Cannot bind native methods for TaskSignal Class!"); return status; diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index f685239f5..2bfe813a4 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -101,6 +101,29 @@ function closeSync(file: number | File): void { return FileIoImpl.closeSync(file) } +function connectDfs(networkId: string, listeners: DfsListeners): Promise { + return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { + let promise = taskpool.execute((networkId: string, listeners: DfsListeners): void => + FileIoImpl.doConnectDfs(networkId, listeners), networkId, listeners); + promise.then((): void => { + resolve(undefined); + }).catch((e: BusinessError): void => { + reject(e); + }); + }); +} + +function disconnectDfs(networkId: string): Promise { + return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { + let promise = taskpool.execute((networkId: string): void => FileIoImpl.doDisConnectDfs(networkId), networkId); + promise.then((): void => { + resolve(undefined); + }).catch((e: BusinessError): void => { + reject(e); + }); + }); +} + function getxattrSync(path: string, key: string): string { return FileIoImpl.getxattrSync(path, key) } @@ -1188,6 +1211,10 @@ export interface Progress { totalSize: number; } +export interface DfsListeners { + onStatus(networkId: string, status: number): void; +} + class ProgressInner implements Progress { processedSize: number; totalSize: number; @@ -1930,8 +1957,12 @@ class FileIoImpl { static native copySync(srcUri: string, destUri: string, options?: CopyOptions): void; + static native doConnectDfs(networkId: string, listeners: DfsListeners): void; + static native copyFileSync(src: string | number, dest: string | number, mode?: number): void; + static native doDisConnectDfs(networkId: string): void; + static native fdatasyncSync(fd: number): void; static native getxattrSync(path: string, key: string): string; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp new file mode 100644 index 000000000..407344539 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2025 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 "connectdfs_ani.h" +#include "connectdfs_core.h" +#include "filemgmt_libhilog.h" +#include "error_handler.h" +#include "type_converter.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +using namespace std; +void ConnectDfsAni::ConnectDfsSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string networkId, + ani_object listener) +{ + //注册 + auto [succNetworkId, networkIdStr] = TypeConverter::ToUTF8String(env, networkId); + if (!succNetworkId) { + HILOGE("Invalid NetworkId"); + ErrorHandler::Throw(env, E_PARAMS); + return; + } + sptr anidfslistener_(new(std::nothrow) ANIDfsListener()); + anidfslistener_->SetConnectDfsEnv(env); + ani_ref promiseDeferred = nullptr; + + if (listener != nullptr) { + anidfslistener_->SetConnectDfsCBRef(listener); + HILOGE("Connectdfs set callback success"); + } else { + anidfslistener_->SetConnectDfsPromiseRef(promiseDeferred); + HILOGE("Connectdfs set Promise success"); + } + + auto ret = ConnectDfsCore::ConnectDfsExec(networkIdStr, anidfslistener_); + if (!ret.IsSuccess()) { + HILOGE("ConnectDfsExec failed"); + ErrorHandler::Throw(env, E_PARAMS); + return; + } +} + +void ANIDfsListener::SetConnectDfsEnv(ani_env *env) +{ + env_ = env; +} + +void ANIDfsListener::SetConnectDfsCBRef(ani_ref ref) +{ + onStatusRef_ = ref; +} + +void ANIDfsListener::SetConnectDfsPromiseRef(ani_ref promiseDeferred) +{ + promiseDeferred_ = promiseDeferred; +} + +void ANIDfsListener::OnStatus(const std::string &networkId, int32_t status) +{ + //回调 + ani_string networkId_; + ani_status res = env_->String_NewUTF8(networkId.c_str(), networkId.size(), &networkId_); + if (res != ANI_OK) { + HILOGE("std string to ani string failed. ret = %{public}d", static_cast(res)); + ErrorHandler::Throw(env_, E_PARAMS); + return; + } + ani_double status_ = static_cast(status); + ani_status ret = env_->Object_CallMethodByName_Void(static_cast(objectlistener), "onStatus", nullptr, + networkId_, status_); + if (ret != ANI_OK) { + HILOGE("Object_CallMethodByName_Void failed. ret = %{public}d", static_cast(ret)); + ErrorHandler::Throw(env_, E_PARAMS); + return; + } +} +} +} +} +} \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h new file mode 100644 index 000000000..63dfe41d1 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h @@ -0,0 +1,57 @@ + + + +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H +#define FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H + +#include +#include +#include "dfs_listener/file_dfs_listener_stub.h" +#include "distributed_file_daemon_manager.h" +#include "filemgmt_libfs.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { +using namespace std; + +class ANIDfsListener : public FileDfsListenerStub { +public: + void OnStatus(const std::string &networkId, int32_t status); + void SetConnectDfsEnv(ani_env *env); + void SetConnectDfsCBRef(ani_ref ref); + void SetConnectDfsPromiseRef(ani_ref promiseDeferred); + +private: + ani_env *env_ = nullptr; + ani_ref onStatusRef_ = nullptr; + ani_ref promiseDeferred_ = nullptr; + ani_ref objectlistener = nullptr; +}; +class ConnectDfsAni final { +public: + static void ConnectDfsSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string networkId, + ani_object listener); +}; + +} +} +} +} +#endif //FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp new file mode 100644 index 000000000..aa68941ca --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 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 "disconnectdfs_ani.h" +#include "disconnectdfs_core.h" +#include "filemgmt_libhilog.h" +#include "error_handler.h" +#include "type_converter.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +using namespace std; +void DisConnectDfsAni::DisConnectDfsSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string networkId) +{ + auto [succNetworkId, networkIdStr] = TypeConverter::ToUTF8String(env, networkId); + if (!succNetworkId) { + HILOGE("Invalid NetworkId"); + ErrorHandler::Throw(env, E_PARAMS); + return; + } + auto ret = DisConnectDfsCore::DisConnectDfsExec(networkIdStr); + if (!ret.IsSuccess()) { + HILOGE("DisConnectDfsExec failed"); + ErrorHandler::Throw(env, E_PARAMS); + return; + } +} +} +} +} +} \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h new file mode 100644 index 000000000..eb06fcafa --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H +#define FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H + +#include +#include "dfs_listener/file_dfs_listener_stub.h" +#include "distributed_file_daemon_manager.h" +#include "filemgmt_libfs.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +class DisConnectDfsAni final { +public: + static void DisConnectDfsSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string networkId); +}; + +} +} +} +} +#endif //FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H diff --git a/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.cpp b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.cpp new file mode 100644 index 000000000..999a460b8 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "filemgmt_libhilog.h" +#include "distributed_file_daemon_manager.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace fs = std::filesystem; + +FsResult ConnectDfsCore::ConnectDfsExec(const std::string &networkId, sptr listener) +{ + if (networkId == "" || listener == nullptr) { + return FsResult::Error(E_PARAMS); + } + + int result = Storage::DistributedFile::DistributedFileDaemonManager::GetInstance(). + OpenP2PConnectionEx(networkId, listener); + if (result != ERRNO_NOERR) { + HILOGE("Fail to openp2pconnection"); + return FsResult::Error(result); + } + return FsResult::Success(); +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h new file mode 100644 index 000000000..d7a6b066f --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H +#define FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H +#include +#include +#include +#include +#include "bundle_mgr_client_impl.h" +#include "dfs_listener/file_dfs_listener_stub.h" +#include "distributed_file_daemon_manager.h" +#include "filemgmt_libfs.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +class ConnectDfsCore final { +public: + static FsResult ConnectDfsExec(const std::string &networkId, sptr listener); +}; + +} +} +} + +#endif //FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H + diff --git a/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.cpp b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.cpp new file mode 100644 index 000000000..92020ae37 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 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 "filemgmt_libhilog.h" +#include "distributed_file_daemon_manager.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace fs = std::filesystem; + +FsResult DisConnectDfsCore::DisConnectDfsExec(const std::string &networkId) +{ + if (networkId == "") { + return FsResult::Error(E_PARAMS); + } + + int result = Storage::DistributedFile::DistributedFileDaemonManager::GetInstance(). + CloseP2PConnectionEx(networkId); + if (result != ERRNO_NOERR) { + HILOGE("Fail to Closep2pconnection"); + return FsResult::Error(result); + } + return FsResult::Success(); +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h new file mode 100644 index 000000000..95704bd52 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H +#define FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H + +#include "filemgmt_libfs.h" +#include "fs_utils.h" +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { + +class DisConnectDfsCore final { +public: + static FsResult DisConnectDfsExec(const std::string &networkId); +}; +} +} +} + +#endif //FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H \ No newline at end of file -- Gitee From 698213695118539625b47d35d654ef3cedcb869c Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 10:24:00 +0800 Subject: [PATCH 2/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h index 63dfe41d1..4e4fc0db4 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h @@ -1,6 +1,3 @@ - - - /* * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); -- Gitee From 44d1436695616f5560880bc5cf49b4ee41ead783 Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 11:04:09 +0800 Subject: [PATCH 3/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/BUILD.gn | 1 + .../dfs_listener/file_dfs_listener_stub.cpp | 74 +++++++++++++++++++ .../dfs_listener/file_dfs_listener_stub.h | 46 ++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 7ef938dfb..fb6f7112f 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -155,6 +155,7 @@ ohos_shared_library("fs") { "src/mod_fs/common_func.cpp", "src/mod_fs/module.cpp", "src/mod_fs/properties/close.cpp", + "src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp", "src/mod_fs/properties/fdatasync.cpp", "src/mod_fs/properties/fsync.cpp", "src/mod_fs/properties/lstat.cpp", diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp new file mode 100644 index 000000000..a77a6ff26 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 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 "file_dfs_listener_stub.h" +#include "file_dfs_listener_interface_code.h" +#include "filemgmt_libhilog.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace FileManagement; +namespace { + constexpr int NO_ERROR = 0; + constexpr int E_INVAL_ARG = 1; +} + +FileDfsListenerStub::FileDfsListenerStub() +{ + opToInterfaceMap_[static_cast + (Storage::DistributedFile::FileDfsListenerInterfaceCode::FILE_DFS_LISTENER_ON_STATUS)] = + &FileDfsListenerStub::HandleOnStatus; +} + +int32_t FileDfsListenerStub::OnRemoteRequest(uint32_t code, + MessageParcel &data, + MessageParcel &reply, + MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + return FILE_DFS_LISTENER_DESCRIPTOR_IS_EMPTY; + } + switch (code) { + case static_cast(Storage::DistributedFile::FileDfsListenerInterfaceCode::FILE_DFS_LISTENER_ON_STATUS): + return HandleOnStatus(data, reply); + default: + HILOGE("Cannot response request %{public}d: unknown tranction", code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} + +int32_t FileDfsListenerStub::HandleOnStatus(MessageParcel &data, MessageParcel &reply) +{ + std::string networkId; + if (!data.ReadString(networkId)) { + HILOGE("read networkId failed"); + return E_INVAL_ARG; + } + int32_t status; + if (!data.ReadInt32(status)) { + HILOGE("read status failed"); + return E_INVAL_ARG; + } + if (networkId.empty() || status < 0) { + HILOGE("Invalid arguments"); + return E_INVAL_ARG; + } + OnStatus(networkId, status); + return NO_ERROR; +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h new file mode 100644 index 000000000..bafb64cad --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H +#define FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H + +#include +#include "i_file_dfs_listener.h" +#include "iremote_stub.h" +#include "message_option.h" +#include "message_parcel.h" +#include "refbase.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +class FileDfsListenerStub : public IRemoteStub { +public: + FileDfsListenerStub(); + virtual ~FileDfsListenerStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + using FileDfsListenerInterface = int32_t (FileDfsListenerStub::*)(MessageParcel &data, MessageParcel &reply); + std::map opToInterfaceMap_; + + int32_t HandleOnStatus(MessageParcel &data, MessageParcel &reply); +}; + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H \ No newline at end of file -- Gitee From a30b689121f005618ad1de5546c048d4026b909c Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 12:03:30 +0800 Subject: [PATCH 4/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index fb6f7112f..f98ab9639 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -155,7 +155,6 @@ ohos_shared_library("fs") { "src/mod_fs/common_func.cpp", "src/mod_fs/module.cpp", "src/mod_fs/properties/close.cpp", - "src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp", "src/mod_fs/properties/fdatasync.cpp", "src/mod_fs/properties/fsync.cpp", "src/mod_fs/properties/lstat.cpp", @@ -233,6 +232,7 @@ ohos_shared_library("fs") { "src/mod_fs/properties/create_randomaccessfile.cpp", "src/mod_fs/properties/create_stream.cpp", "src/mod_fs/properties/create_streamrw.cpp", + "src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp", "src/mod_fs/properties/disconnectdfs.cpp", "src/mod_fs/properties/dup.cpp", "src/mod_fs/properties/fdopen_stream.cpp", -- Gitee From 766c222c5ffe1156f1c0fe3958e83b93ceb2fc4b Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 14:42:17 +0800 Subject: [PATCH 5/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- .../src/mod_fs/properties/ani/connectdfs_ani.cpp | 10 +++++----- .../js/src/mod_fs/properties/ani/connectdfs_ani.h | 14 +++++++------- .../mod_fs/properties/ani/disconnectdfs_ani.cpp | 10 +++++----- .../src/mod_fs/properties/ani/disconnectdfs_ani.h | 14 +++++++------- .../js/src/mod_fs/properties/connectdfs_core.h | 12 ++++++------ .../js/src/mod_fs/properties/disconnectdfs_core.h | 12 ++++++------ 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp index 407344539..da3f63b52 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.cpp @@ -19,7 +19,7 @@ #include "error_handler.h" #include "type_converter.h" -namespace OHOS { +namespace OHOS { namespace FileManagement { namespace ModuleFileIO { namespace ANI { @@ -89,7 +89,7 @@ void ANIDfsListener::OnStatus(const std::string &networkId, int32_t status) return; } } -} -} -} -} \ No newline at end of file +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h index 4e4fc0db4..b215b37aa 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H -#define FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_CONNECTDFS_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_CONNECTDFS_ANI_H #include #include @@ -47,8 +47,8 @@ public: ani_object listener); }; -} -} -} -} -#endif //FILEMANAGEMENT_FILE_API_CONNECTDFS_ANI_H \ No newline at end of file +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_CONNECTDFS_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp index aa68941ca..7beafaeaa 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.cpp @@ -19,7 +19,7 @@ #include "error_handler.h" #include "type_converter.h" -namespace OHOS { +namespace OHOS { namespace FileManagement { namespace ModuleFileIO { namespace ANI { @@ -40,7 +40,7 @@ void DisConnectDfsAni::DisConnectDfsSync(ani_env *env, [[maybe_unused]] ani_clas return; } } -} -} -} -} \ No newline at end of file +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h index eb06fcafa..a42dab9cc 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/disconnectdfs_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H -#define FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_DISCONNECTDFS_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_DISCONNECTDFS_ANI_H #include #include "dfs_listener/file_dfs_listener_stub.h" @@ -31,8 +31,8 @@ public: static void DisConnectDfsSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string networkId); }; -} -} -} -} -#endif //FILEMANAGEMENT_FILE_API_DISCONNECTDFS_ANI_H +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_DISCONNECTDFS_ANI_H diff --git a/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h index d7a6b066f..9e6d713bc 100644 --- a/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H -#define FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CONNECTDFS_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CONNECTDFS_CORE_H #include #include #include @@ -33,9 +33,9 @@ public: static FsResult ConnectDfsExec(const std::string &networkId, sptr listener); }; -} -} -} +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS -#endif //FILEMANAGEMENT_FILE_API_CONNECTDFS_CORE_H +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CONNECTDFS_CORE_H diff --git a/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h index 95704bd52..0cc11a1b9 100644 --- a/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/disconnectdfs_core.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H -#define FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DISCONNECTDFS_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DISCONNECTDFS_CORE_H #include "filemgmt_libfs.h" #include "fs_utils.h" @@ -26,8 +26,8 @@ class DisConnectDfsCore final { public: static FsResult DisConnectDfsExec(const std::string &networkId); }; -} -} -} +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS -#endif //FILEMANAGEMENT_FILE_API_DISCONNECTDFS_CORE_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DISCONNECTDFS_CORE_H \ No newline at end of file -- Gitee From b224a860f9ea1a8495f9a65e81f0f4d4a745079c Mon Sep 17 00:00:00 2001 From: lixiang Date: Tue, 8 Apr 2025 16:54:48 +0800 Subject: [PATCH 6/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets index 2bfe813a4..31b51cc71 100644 --- a/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets +++ b/interfaces/kits/js/src/mod_fs/ani/ets/@ohos.file.fs.ets @@ -104,7 +104,7 @@ function closeSync(file: number | File): void { function connectDfs(networkId: string, listeners: DfsListeners): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { let promise = taskpool.execute((networkId: string, listeners: DfsListeners): void => - FileIoImpl.doConnectDfs(networkId, listeners), networkId, listeners); + FileIoImpl.connectDfs(networkId, listeners), networkId, listeners); promise.then((): void => { resolve(undefined); }).catch((e: BusinessError): void => { @@ -115,7 +115,7 @@ function connectDfs(networkId: string, listeners: DfsListeners): Promise { function disconnectDfs(networkId: string): Promise { return new Promise((resolve: (result: undefined) => void, reject: (e: BusinessError) => void): void => { - let promise = taskpool.execute((networkId: string): void => FileIoImpl.doDisConnectDfs(networkId), networkId); + let promise = taskpool.execute((networkId: string): void => FileIoImpl.disConnectDfs(networkId), networkId); promise.then((): void => { resolve(undefined); }).catch((e: BusinessError): void => { @@ -1957,11 +1957,11 @@ class FileIoImpl { static native copySync(srcUri: string, destUri: string, options?: CopyOptions): void; - static native doConnectDfs(networkId: string, listeners: DfsListeners): void; + static native connectDfs(networkId: string, listeners: DfsListeners): void; static native copyFileSync(src: string | number, dest: string | number, mode?: number): void; - static native doDisConnectDfs(networkId: string): void; + static native disConnectDfs(networkId: string): void; static native fdatasyncSync(fd: number): void; -- Gitee From 2eafc920718446b00e88f12c3965eed30e366de8 Mon Sep 17 00:00:00 2001 From: lixiang Date: Wed, 9 Apr 2025 08:44:54 +0800 Subject: [PATCH 7/7] =?UTF-8?q?connectdfs=20Ani=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiang --- interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp index 0d08fc919..294b230fb 100644 --- a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp +++ b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp @@ -184,9 +184,8 @@ static ani_status BindStaticMethods(ani_env *env) ani_native_function { "unlinkSync", nullptr, reinterpret_cast(UnlinkAni::UnlinkSync) }, ani_native_function { "writeSync", nullptr, reinterpret_cast(WriteAni::WriteSync) }, ani_native_function { "utimes", nullptr, reinterpret_cast(UtimesAni::Utimes) }, - ani_native_function { "doConnectDfs", nullptr, reinterpret_cast(ConnectDfsAni::ConnectDfsSync) }, - ani_native_function { - "doDisConnectDfs", nullptr, reinterpret_cast(DisConnectDfsAni::DisConnectDfsSync) } + ani_native_function { "connectDfs", nullptr, reinterpret_cast(ConnectDfsAni::ConnectDfsSync) }, + ani_native_function { "disConnectDfs", nullptr, reinterpret_cast(DisConnectDfsAni::DisConnectDfsSync) } }; return BindClass(env, className, methods); } -- Gitee