diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 540b850ab07c45fe75c3662a9e9bd08f25432bbb..f98ab96396b03094261a549a6b763023eb4b2284 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -232,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", @@ -707,10 +708,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 +737,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 07c00bea7952ef21ca5ba37367078daa2b3482db..294b230fb1c1c9730dc4bcc938ceee27116dd20f 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,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 { "connectDfs", nullptr, reinterpret_cast(ConnectDfsAni::ConnectDfsSync) }, + ani_native_function { "disConnectDfs", nullptr, reinterpret_cast(DisConnectDfsAni::DisConnectDfsSync) } }; return BindClass(env, className, methods); } @@ -229,12 +233,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 f685239f5513020d50a10b4597a64cf88e57a942..31b51cc71d58bbf1960f402e0f0948332d626dd0 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.connectDfs(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.disConnectDfs(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 connectDfs(networkId: string, listeners: DfsListeners): void; + static native copyFileSync(src: string | number, dest: string | number, mode?: number): void; + static native disConnectDfs(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 0000000000000000000000000000000000000000..da3f63b52fc23add8144ca97b4d47a55d0efa873 --- /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; + } +} +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..b215b37aa4599c76507767ddb954a2d6e87825d6 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/connectdfs_ani.h @@ -0,0 +1,54 @@ +/* + * 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 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 +#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); +}; + +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..7beafaeaaf27a429c70c695899865b3da4fc0f7d --- /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; + } +} +} // 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 new file mode 100644 index 0000000000000000000000000000000000000000..a42dab9cc026ee54cb102e614cd6c86863423794 --- /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 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" +#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); +}; + +} // 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.cpp b/interfaces/kits/js/src/mod_fs/properties/connectdfs_core.cpp new file mode 100644 index 0000000000000000000000000000000000000000..999a460b83a848d81acdff48abae8b3c9b7d8a0c --- /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 0000000000000000000000000000000000000000..9e6d713bcb5181edafdb7cdec1b10f5a86e7b4fe --- /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 INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CONNECTDFS_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_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); +}; + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CONNECTDFS_CORE_H + 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 0000000000000000000000000000000000000000..a77a6ff2608a06fc87fa16bcdfefedc29b0a0ded --- /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 0000000000000000000000000000000000000000..bafb64cad07fb244e8cf1660e40ccd7a98c0dc67 --- /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 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 0000000000000000000000000000000000000000..92020ae3773f11e620f7b593b916931100a87aa5 --- /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 0000000000000000000000000000000000000000..0cc11a1b903c78a145c3500566a561dcee98d70c --- /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 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" +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { + +class DisConnectDfsCore final { +public: + static FsResult DisConnectDfsExec(const std::string &networkId); +}; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DISCONNECTDFS_CORE_H \ No newline at end of file