diff --git a/services/distributedfiledaemon/include/device/device_manager_agent.h b/services/distributedfiledaemon/include/device/device_manager_agent.h index 27617ac03f75f3a50d67f2f15eb89765aa12b1c1..50a82e8d7eaa5c2852a3fa8ae03d36d2c384a8d3 100644 --- a/services/distributedfiledaemon/include/device/device_manager_agent.h +++ b/services/distributedfiledaemon/include/device/device_manager_agent.h @@ -24,12 +24,12 @@ #include "device_auth.h" #include "device_info.h" #include "device_manager.h" +#include "dfsu_actor.h" +#include "dfsu_singleton.h" +#include "dfsu_startable.h" #include "mountpoint/mount_point.h" #include "network/network_agent_template.h" #include "nlohmann/json.hpp" -#include "utils_actor.h" -#include "utils_singleton.h" -#include "utils_startable.h" namespace OHOS { namespace Storage { @@ -51,9 +51,9 @@ void from_json(const nlohmann::json &jsonObject, GroupInfo &groupInfo); class DeviceManagerAgent final : public DistributedHardware::DmInitCallback, public DistributedHardware::DeviceStateCallback, public std::enable_shared_from_this, - public Startable, - public Actor, - public Utils::Singleton { + public DfsuStartable, + public DfsuActor, + public Utils::DfsuSingleton { DECLARE_SINGLETON(DeviceManagerAgent); public: diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index a1a3ecc87bd46d6782c8a00c964e9e98635ff188..1ed72b23cb1854ab4a861b6b6cc74ac6b1207524 100644 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ b/services/distributedfiledaemon/include/ipc/daemon.h @@ -21,6 +21,7 @@ #include "daemon_stub.h" #include "i_daemon.h" #include "iremote_stub.h" +#include "multiuser/os_account_observer.h" #include "system_ability.h" namespace OHOS { @@ -50,7 +51,7 @@ private: static sptr instance_; static std::mutex instanceLock_; bool registerToService_ { false }; - + std::shared_ptr subScriber_; void PublishSA(); void RegisterOsAccount(); }; diff --git a/services/distributedfiledaemon/include/mountpoint/mount_manager.h b/services/distributedfiledaemon/include/mountpoint/mount_manager.h index 7b04f10c3d17c515c6e97924f3bdcba23236209d..3012028efaa817ceddb9657a3d3ac5c0c93c23a3 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_manager.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_manager.h @@ -20,13 +20,13 @@ #include #include +#include "dfsu_singleton.h" #include "mount_point.h" -#include "utils_singleton.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class MountManager final : public Utils::Singleton { +class MountManager final : public Utils::DfsuSingleton { public: void Mount(std::unique_ptr mp); void Umount(std::weak_ptr wmp); diff --git a/services/distributedfiledaemon/include/mountpoint/mount_point.h b/services/distributedfiledaemon/include/mountpoint/mount_point.h index 9887e7331b0527fec91d0cfcf21fbe0416c9d758..c2a274b88af6e0bbe9bf936a01f5f890ac40406e 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_point.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_point.h @@ -19,8 +19,8 @@ #include #include +#include "dfsu_mount_argument_descriptors.h" #include "nocopyable.h" -#include "utils_mount_argument.h" namespace OHOS { namespace Storage { diff --git a/services/distributedfiledaemon/include/network/network_agent_template.h b/services/distributedfiledaemon/include/network/network_agent_template.h index a8c886f0386567e5f0426efe329abdd52a14e282..24a4fe5801ce10fd3af117f9e4b991ebac6c403d 100644 --- a/services/distributedfiledaemon/include/network/network_agent_template.h +++ b/services/distributedfiledaemon/include/network/network_agent_template.h @@ -22,20 +22,20 @@ #include #include "device/device_info.h" +#include "dfsu_actor.h" +#include "dfsu_startable.h" +#include "dfsu_thread.h" #include "mountpoint/mount_point.h" #include "network/kernel_talker.h" #include "network/session_pool.h" -#include "utils_actor.h" -#include "utils_dfs_thread.h" -#include "utils_startable.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class NetworkAgentTemplate : public Startable, public Actor { +class NetworkAgentTemplate : public DfsuStartable, public DfsuActor { public: explicit NetworkAgentTemplate(std::weak_ptr mountPoint) - : Actor(this), + : DfsuActor(this), mountPoint_(mountPoint), kernerlTalker_(std::make_shared( mountPoint, @@ -76,7 +76,7 @@ private: void GetSessionProcessInner(NotifyParam param); std::mutex taskMut_; - std::list tasks_; + std::list tasks_; std::shared_ptr kernerlTalker_; SessionPool sessionPool_; }; diff --git a/services/distributedfiledaemon/src/device/device_info.cpp b/services/distributedfiledaemon/src/device/device_info.cpp index bf15d03be8631631176225272d33f5955494b831..7f83943c415f3f28d1a50bc693929079e0f8a6fd 100644 --- a/services/distributedfiledaemon/src/device/device_info.cpp +++ b/services/distributedfiledaemon/src/device/device_info.cpp @@ -14,7 +14,7 @@ */ #include "device/device_info.h" -#include "utils_exception.h" +#include "dfsu_exception.h" #include "utils_log.h" namespace OHOS { diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index dba021dcf3417568a7b49a72617e5be3d16e68a2..cadd4313e03680d58f2e1d6697ac256f7cdf79c7 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -20,12 +20,12 @@ #include #include "device_auth.h" +#include "dfsu_exception.h" #include "ipc/i_daemon.h" #include "mountpoint/mount_manager.h" #include "network/devsl_dispatcher.h" #include "network/softbus/softbus_agent.h" #include "softbus_bus_center.h" -#include "utils_exception.h" #include "utils_log.h" #include "parameters.h" @@ -40,7 +40,7 @@ const std::string SAME_ACCOUNT_MARK = "const.distributed_file_only_for_same_acco } // namespace using namespace std; -DeviceManagerAgent::DeviceManagerAgent() : Actor(this, std::numeric_limits::max()) {} +DeviceManagerAgent::DeviceManagerAgent() : DfsuActor(this, std::numeric_limits::max()) {} DeviceManagerAgent::~DeviceManagerAgent() { @@ -119,7 +119,7 @@ void DeviceManagerAgent::OfflineAllDevice() { unique_lock lock(mpToNetworksMutex_); for (auto [ignore, net] : cidNetTypeRecord_) { - auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectAllDevices); + auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectAllDevices); net->Recv(move(cmd)); } } @@ -128,7 +128,7 @@ void DeviceManagerAgent::ReconnectOnlineDevices() { unique_lock lock(mpToNetworksMutex_); for (auto [ignore, net] : cidNetTypeRecord_) { - auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); + auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); cmd->UpdateOption({ .tryTimes_ = MAX_RETRY_COUNT, }); @@ -164,7 +164,7 @@ void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo return; } auto cmd = - make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); + make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption({.tryTimes_ = MAX_RETRY_COUNT}); networkAgent->Recv(move(cmd)); @@ -183,7 +183,8 @@ void DeviceManagerAgent::OnDeviceOffline(const DistributedHardware::DmDeviceInfo return; } - auto cmd = make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); + auto cmd = + make_unique>(&NetworkAgentTemplate::DisconnectDevice, info); networkAgent->Recv(move(cmd)); cidNetTypeRecord_.erase(info.cid_); LOGI("OnDeviceOffline end"); diff --git a/services/distributedfiledaemon/src/ipc/daemon.cpp b/services/distributedfiledaemon/src/ipc/daemon.cpp index f50c2d5701b7af4157adef38d079cbf2e3eeddf9..53c7ce5a24f2434ab42baf54f292f375a0fc8731 100644 --- a/services/distributedfiledaemon/src/ipc/daemon.cpp +++ b/services/distributedfiledaemon/src/ipc/daemon.cpp @@ -16,7 +16,6 @@ #include "ipc/daemon.h" #include "mountpoint/mount_manager.h" -#include "multiuser/os_account_observer.h" #include "os_account_manager.h" #include "system_ability_definition.h" #include "utils_log.h" @@ -47,10 +46,11 @@ void Daemon::RegisterOsAccount() osAccountSubscribeInfo.SetOsAccountSubscribeType(OHOS::AccountSA::OS_ACCOUNT_SUBSCRIBE_TYPE::ACTIVED); osAccountSubscribeInfo.SetName("distributed_file_service"); - auto subScriber = std::make_shared(osAccountSubscribeInfo); - int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber); + subScriber_ = std::make_shared(osAccountSubscribeInfo); + int ret = OHOS::AccountSA::OsAccountManager::SubscribeOsAccount(subScriber_); if (ret != 0) { LOGE("register os account fail ret %{public}d", ret); + return; } LOGI("register os account success, ret %{public}d", ret); } @@ -79,6 +79,11 @@ void Daemon::OnStop() LOGI("Begin to stop"); state_ = ServiceRunningState::STATE_NOT_START; registerToService_ = false; + int32_t ret = OHOS::AccountSA::OsAccountManager::UnsubscribeOsAccount(subScriber_); + if (ret != 0) { + LOGI("UnsubscribeOsAccount failed, ret %{public}d", ret); + } + subScriber_ = nullptr; LOGI("Stop finished successfully"); } diff --git a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp index 3f8696eaa0452c963071e4d8b6826cd305d0718d..52fca4351a952d9a0f7e1a9e885dafd2171990bb 100644 --- a/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp +++ b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp @@ -19,8 +19,8 @@ #include #include "device/device_manager_agent.h" +#include "dfsu_mount_argument_descriptors.h" #include "utils_log.h" -#include "utils_mount_argument.h" namespace OHOS { namespace Storage { diff --git a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp index 086f7a27e11bd487cad5ab0f9c7772fde2b6e4d4..accf450405916ba5ee8052b5e37555a3db837cdf 100644 --- a/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp +++ b/services/distributedfiledaemon/src/multiuser/os_account_observer.cpp @@ -16,8 +16,8 @@ #include "multiuser/os_account_observer.h" #include "device/device_manager_agent.h" +#include "dfsu_mount_argument_descriptors.h" #include "utils_log.h" -#include "utils_mount_argument.h" namespace OHOS { namespace Storage { @@ -46,9 +46,9 @@ OsAccountObserver::~OsAccountObserver() void OsAccountObserver::AddMPInfo(const int id, const std::string &relativePath) { - auto smp = make_shared(Utils::MountArgumentDescriptors::Alpha(id, relativePath)); + auto smp = make_shared(Utils::DfsuMountArgumentDescriptors::Alpha(id, relativePath)); auto dm = DeviceManagerAgent::GetInstance(); - dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); + dm->Recv(make_unique>>(&DeviceManagerAgent::JoinGroup, smp)); mountPoints_[id].emplace_back(smp); } @@ -77,8 +77,8 @@ void OsAccountObserver::RemoveMPInfo(const int id) } auto dm = DeviceManagerAgent::GetInstance(); - for (auto smp : iter->second) { - dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); + for (auto smp : iter->second) { + dm->Recv(make_unique>>(&DeviceManagerAgent::QuitGroup, smp)); } mountPoints_.erase(iter); diff --git a/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp b/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp index 2462f05a00ef82d74d7705119baee1401ea6007e..135bc5122dc91bc17b16ba8f7f3556442c2d4a31 100644 --- a/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp +++ b/services/distributedfiledaemon/src/network/devsl_dispatcher.cpp @@ -17,7 +17,6 @@ #include "ipc/i_daemon.h" #include "utils_log.h" - namespace OHOS { namespace Storage { namespace DistributedFile { diff --git a/services/distributedfiledaemon/src/network/kernel_talker.cpp b/services/distributedfiledaemon/src/network/kernel_talker.cpp index 7e64a30fb1cf116197789b34047184d743dd219f..03a72e1b9d9ce12f5bc328caaf2106c18981c898 100644 --- a/services/distributedfiledaemon/src/network/kernel_talker.cpp +++ b/services/distributedfiledaemon/src/network/kernel_talker.cpp @@ -83,7 +83,7 @@ void KernelTalker::SinkSessionTokernel(shared_ptr session) UpdateSocketParam cmd = { .cmd = CMD_UPDATE_SOCKET, .newfd = socketFd, - .devsl = 3, + .devsl = 0, .status = status, }; if (memcpy_s(cmd.masterKey, KEY_MAX_LEN, masterkey.data(), KEY_MAX_LEN) != EOK) { @@ -94,6 +94,8 @@ void KernelTalker::SinkSessionTokernel(shared_ptr session) return; } SetCmd(cmd); + + DevslDispatcher::DevslGetRegister(cid, shared_from_this()); } void KernelTalker::SinkDevslTokernel(const std::string &cid, uint32_t devsl) diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index e5d2d9e1e4633ffd6a550004ef392db573f448e0..06c181a4b6b7427c65794ff39f7dabbc2e3e3dfa 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -15,7 +15,7 @@ #include "network/network_agent_template.h" #include "device/device_manager_agent.h" -#include "utils_exception.h" +#include "dfsu_exception.h" #include "utils_log.h" namespace OHOS { @@ -54,8 +54,8 @@ void NetworkAgentTemplate::ConnectOnlineDevices() auto infos = dma->GetRemoteDevicesInfo(); LOGI("Have %{public}d devices Online", infos.size()); for (const auto &info : infos) { - auto cmd = - make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); + auto cmd = make_unique>( + &NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption({.tryTimes_ = MAX_RETRY_COUNT}); Recv(move(cmd)); } @@ -79,7 +79,7 @@ void NetworkAgentTemplate::CloseSessionForOneDevice(const string &cid) void NetworkAgentTemplate::AcceptSession(shared_ptr session) { - auto cmd = make_unique>>( + auto cmd = make_unique>>( &NetworkAgentTemplate::AcceptSessionInner, session); cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); @@ -94,8 +94,8 @@ void NetworkAgentTemplate::AcceptSessionInner(shared_ptr session) void NetworkAgentTemplate::GetSessionProcess(NotifyParam ¶m) { - auto cmd = - make_unique>(&NetworkAgentTemplate::GetSessionProcessInner, param); + auto cmd = make_unique>( + &NetworkAgentTemplate::GetSessionProcessInner, param); cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); } @@ -115,7 +115,7 @@ void NetworkAgentTemplate::GetSession(const string &cid) deviceInfo.SetCid(cid); try { OpenSession(deviceInfo); - } catch (const Exception &e) { + } catch (const DfsuException &e) { LOGE("reget session failed, code: %{public}d", e.code()); } } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index 8ff475ab4a2ccf8b563330049941b7605ae5b4a4..e69426223f7c1c0c593d99c23ac62512dfd2b3fa 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -16,12 +16,12 @@ #include +#include "dfsu_exception.h" #include "ipc/i_daemon.h" #include "network/softbus/softbus_session.h" #include "network/softbus/softbus_session_dispatcher.h" #include "network/softbus/softbus_session_name.h" #include "session.h" -#include "utils_exception.h" #include "utils_log.h" namespace OHOS { @@ -136,7 +136,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) (session->IsFromServer() == true) ? "Server" : "Client", result); if (!session->IsFromServer()) { // client retry if (IsContinueRetry(cid)) { - auto cmd = make_unique>( + auto cmd = make_unique>( &NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); diff --git a/services/distributedfileservice/include/device/device_manager_agent.h b/services/distributedfileservice/include/device/device_manager_agent.h index b2a11da1a6652661e0a32748688780d05e09348d..82f024813e8a6fdcc7d849ceefc12f447b07b640 100644 --- a/services/distributedfileservice/include/device/device_manager_agent.h +++ b/services/distributedfileservice/include/device/device_manager_agent.h @@ -24,7 +24,7 @@ #include #include "device_manager.h" -#include "utils_singleton.h" +#include "dfsu_singleton.h" namespace OHOS { namespace Storage { @@ -32,7 +32,7 @@ namespace DistributedFile { class DeviceManagerAgent : public DistributedHardware::DmInitCallback, public DistributedHardware::DeviceStateCallback, public std::enable_shared_from_this, - public Utils::Singleton { + public Utils::DfsuSingleton { DECLARE_SINGLETON(DeviceManagerAgent); public: diff --git a/services/distributedfileservice/include/network/softbus_agent.h b/services/distributedfileservice/include/network/softbus_agent.h index 556d2b23f69daa36e509671e0343dab6c78db9a4..bde01d7c7fac63ba7a87f9e3024866a4d1d03c3e 100644 --- a/services/distributedfileservice/include/network/softbus_agent.h +++ b/services/distributedfileservice/include/network/softbus_agent.h @@ -20,13 +20,13 @@ #include #include +#include "dfsu_singleton.h" #include "i_filetransfer_callback.h" -#include "utils_singleton.h" namespace OHOS { namespace Storage { namespace DistributedFile { -class SoftbusAgent : public std::enable_shared_from_this, public Utils::Singleton { +class SoftbusAgent : public std::enable_shared_from_this, public Utils::DfsuSingleton { DECLARE_SINGLETON(SoftbusAgent); public: diff --git a/services/distributedfileservice/src/device/device_manager_agent.cpp b/services/distributedfileservice/src/device/device_manager_agent.cpp index 2e494cc27c56c509e7ef7f84c57c16e71c265251..aa418b9ca9009ad4856f91d2fde4836f522303b3 100644 --- a/services/distributedfileservice/src/device/device_manager_agent.cpp +++ b/services/distributedfileservice/src/device/device_manager_agent.cpp @@ -14,9 +14,9 @@ */ #include "device_manager_agent.h" +#include "dfsu_exception.h" #include "distributedfile_service.h" #include "softbus_agent.h" -#include "utils_exception.h" #include "utils_log.h" namespace OHOS { diff --git a/services/distributedfileservice/src/network/softbus_agent.cpp b/services/distributedfileservice/src/network/softbus_agent.cpp index 3596162c8793a30cd502d114ee5a59e64a6aeba6..8fa2df2b58cff333005a786200b01f9f14cab9ee 100644 --- a/services/distributedfileservice/src/network/softbus_agent.cpp +++ b/services/distributedfileservice/src/network/softbus_agent.cpp @@ -20,13 +20,13 @@ #include #include "device_manager_agent.h" +#include "dfsu_exception.h" #include "distributedfile_service.h" #include "i_distributedfile_service.h" #include "iservice_registry.h" #include "session.h" #include "softbus_dispatcher.h" #include "system_ability_definition.h" -#include "utils_exception.h" #include "utils_directory.h" #include "utils_log.h" diff --git a/test/moduletest/src/distributedfiledaemon_service_test.cpp b/test/moduletest/src/distributedfiledaemon_service_test.cpp index 13d9b452132b200ca738e1713b79443a9dac40cb..52f5d55cdbf442e1b785cb1dfc0d53ea2c68fd23 100644 --- a/test/moduletest/src/distributedfiledaemon_service_test.cpp +++ b/test/moduletest/src/distributedfiledaemon_service_test.cpp @@ -97,7 +97,7 @@ void DistributedFileDaemonServiceTest::TearDown(void) HWTEST_F(DistributedFileDaemonServiceTest, mount_umount_test_001, TestSize.Level1) { auto mp = make_unique( - OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(100, SAME_ACCOUNT)); + Utils::DfsuMountArgumentDescriptors::Alpha(100, SAME_ACCOUNT)); shared_ptr smp = move(mp); @@ -122,7 +122,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 101; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -194,7 +194,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 const int len = sizeof(userId) / sizeof(userId[0]); for (int i = 0; i < len; i++) { - mountArgument[i] = Utils::MountArgumentDescriptors::Alpha(userId[i], SAME_ACCOUNT); + mountArgument[i] = Utils::DfsuMountArgumentDescriptors::Alpha(userId[i], SAME_ACCOUNT); auto mp = make_unique(mountArgument[i]); smpArr[i] = move(mp); } @@ -266,7 +266,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3337; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -331,7 +331,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3338; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -400,7 +400,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_00 { const int userId = 3339; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -502,7 +502,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4200; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -533,7 +533,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4201; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -576,8 +576,8 @@ HWTEST_F(DistributedFileDaemonServiceTest, { const int userId1 = 4202; const int userId2 = 4203; - auto mountArgument1 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId1, SAME_ACCOUNT); - auto mountArgument2 = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId2, SAME_ACCOUNT); + auto mountArgument1 = Utils::DfsuMountArgumentDescriptors::Alpha(userId1, SAME_ACCOUNT); + auto mountArgument2 = Utils::DfsuMountArgumentDescriptors::Alpha(userId2, SAME_ACCOUNT); auto mp1 = make_unique(mountArgument1); auto mp2 = make_unique(mountArgument2); shared_ptr smp1 = move(mp1); @@ -614,7 +614,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, TestSize.Level1) { const int userId = 4204; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -655,7 +655,7 @@ HWTEST_F(DistributedFileDaemonServiceTest, HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_015_kernel_notify_deal, TestSize.Level1) { const int userId = 4500; - auto mountArgument = OHOS::Storage::DistributedFile::Utils::MountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); + auto mountArgument = Utils::DfsuMountArgumentDescriptors::Alpha(userId, SAME_ACCOUNT); auto mp = make_unique(mountArgument); shared_ptr smp = move(mp); @@ -677,7 +677,6 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_01 } EXPECT_EQ(0, 0); } - } // namespace Test } // namespace DistributedFile } // namespace Storage diff --git a/utils/BUILD.gn b/utils/BUILD.gn old mode 100755 new mode 100644 index 8ce6bc6df43ecdb14c4caf33bd2ed8803e5a7086..3a0a3036369998c9c2e396db478f2b17b415c893 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -52,8 +52,8 @@ config("utils_public_config") { ohos_shared_library("libdistributedfileutils") { sources = [ "log/src/utils_log.cpp", + "system/src/dfsu_mount_argument_descriptors.cpp", "system/src/utils_directory.cpp", - "system/src/utils_mount_argument.cpp", ] configs = [ "//build/config/compiler:exceptions" ] diff --git a/utils/system/include/utils_actor.h b/utils/system/include/dfsu_actor.h similarity index 64% rename from utils/system/include/utils_actor.h rename to utils/system/include/dfsu_actor.h index 35a902a2a2f2214f73dd5344d895e63e7256f7b8..05ce9b5510b0d0fddc6c5a497dbe4f0056e1e3aa 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/dfsu_actor.h @@ -13,18 +13,16 @@ * limitations under the License. */ -#ifndef UTILS_ACTOR_H -#define UTILS_ACTOR_H +#ifndef DFSU_ACTOR_H +#define DFSU_ACTOR_H #include #include #include #include -#include -#include -#include "utils_cmd.h" -#include "utils_thread_safe_queue.h" +#include "dfsu_cmd.h" +#include "dfsu_thread_safe_queue.h" namespace OHOS { namespace Storage { @@ -36,16 +34,16 @@ constexpr int RETRY_SLEEP_TIME = 1500; * @tparam Ctx Context for Commands */ template -class Actor { +class DfsuActor { public: - explicit Actor(Ctx *ctx, int startCmdTryTimes = 1) : ctx_(ctx), retryTimes_(startCmdTryTimes) {} - virtual ~Actor() {} + explicit DfsuActor(Ctx *ctx, int startCmdTryTimes = 1) : ctx_(ctx), retryTimes_(startCmdTryTimes) {} + virtual ~DfsuActor() {} void StartActor() { // Always insert cmds b4 starting an actor StartCtx(); - loop_ = std::thread(&Actor::Main, this); + loop_ = std::thread(&DfsuActor::Main, this); } void StopActor() @@ -63,7 +61,7 @@ public: } protected: - ThreadSafeQueue> pendingCmds_; + DfsuThreadSafeQueue> pendingCmds_; Ctx *ctx_ {nullptr}; uint32_t retryTimes_ {1}; @@ -88,14 +86,14 @@ private: void StartCtx() { - auto startCmd = std::make_unique>(&Ctx::Start); + auto startCmd = std::make_unique>(&Ctx::Start); startCmd->UpdateOption({.importance_ = CmdImportance::SUBVITAL, .tryTimes_ = retryTimes_}); pendingCmds_.Push(std::move(startCmd)); } void StopCtx() { - auto cmd = std::make_unique>(&Ctx::Stop); + auto cmd = std::make_unique>(&Ctx::Stop); cmd->UpdateOption({.importance_ = CmdImportance::VITAL, .tryTimes_ = 1}); pendingCmds_.Push(std::move(cmd)); } @@ -111,6 +109,41 @@ private: return result; } + bool ExceptionHandler(const DfsuException &e, std::unique_ptr> ¤tCmd) + { + if (e.code() == ERR_UTILS_ACTOR_QUEUE_STOP) { + return false; + } + + const CmdOptions &op = currentCmd->option_; + + if (IsExistStopTask() && (op.tryTimes_ > 0)) { + return false; // exist stop Task, stop retry + } + + if (op.importance_ == CmdImportance::TRIVIAL) { + if (op.tryTimes_) { + retryTasks.emplace_back( + std::async(std::launch::async, &DfsuActor::DelayRetry, this, std::move(currentCmd))); + return true; + } + } else { + if (op.tryTimes_) { + Retry(std::move(currentCmd)); + return true; + } + if (op.importance_ == CmdImportance::VITAL) { + return false; + } + if (op.importance_ == CmdImportance::NORMAL) { + StopCtx(); + StartCtx(); + return true; + } + } + return true; + } + void Main() { while (true) { @@ -121,36 +154,11 @@ private: (*currentCmd)(ctx_); currentCmd.release(); } - } catch (const Exception &e) { - if (e.code() == ERR_UTILS_ACTOR_QUEUE_STOP) { - break; - } - - const CmdOptions &op = currentCmd->option_; - - if (IsExistStopTask() && (op.tryTimes_ > 0)) { - break; // exist stop Task, stop retry - } - - if (op.importance_ == CmdImportance::TRIVIAL) { - if (op.tryTimes_) { - retryTasks.emplace_back( - std::async(std::launch::async, &Actor::DelayRetry, this, std::move(currentCmd))); - continue; - } + } catch (const DfsuException &e) { + if (ExceptionHandler(e, currentCmd)) { + continue; } else { - if (op.tryTimes_) { - Retry(std::move(currentCmd)); - continue; - } - if (op.importance_ == CmdImportance::VITAL) { - break; - } - if (op.importance_ == CmdImportance::NORMAL) { - StopCtx(); - StartCtx(); - continue; - } + break; } } catch (const std::exception &e) { LOGE("Unexpected Low Level exception"); @@ -161,4 +169,4 @@ private: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_ACTOR_H +#endif // DFSU_ACTOR_H diff --git a/utils/system/include/utils_cmd.h b/utils/system/include/dfsu_cmd.h similarity index 85% rename from utils/system/include/utils_cmd.h rename to utils/system/include/dfsu_cmd.h index f45ddd7d109450defa57a639dd57a48a4e654b65..dd7b7c0f99ed19bf178feeac7bd5d3d89f342b36 100644 --- a/utils/system/include/utils_cmd.h +++ b/utils/system/include/dfsu_cmd.h @@ -13,13 +13,12 @@ * limitations under the License. */ -#ifndef UTILS_CMD_H -#define UTILS_CMD_H +#ifndef DFSU_CMD_H +#define DFSU_CMD_H #include -#include -#include "utils_exception.h" +#include "dfsu_exception.h" namespace OHOS { namespace Storage { @@ -42,11 +41,11 @@ struct CmdOptions { }; template -class Actor; +class DfsuActor; template class VirtualCmd { - friend class Actor; + friend class DfsuActor; public: VirtualCmd() = default; @@ -63,12 +62,12 @@ protected: }; template -class Cmd : public VirtualCmd { - friend class Actor; +class DfsuCmd : public VirtualCmd { + friend class DfsuActor; public: - Cmd(void (Ctx::*f)(Args...), Args... args) : f_(f), args_(args...) {} - ~Cmd() override = default; + DfsuCmd(void (Ctx::*f)(Args...), Args... args) : f_(f), args_(args...) {} + ~DfsuCmd() override = default; private: void (Ctx::*f_)(Args...); @@ -87,4 +86,4 @@ private: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_CMD_H \ No newline at end of file +#endif // DFSU_CMD_H \ No newline at end of file diff --git a/utils/system/include/utils_exception.h b/utils/system/include/dfsu_exception.h similarity index 69% rename from utils/system/include/utils_exception.h rename to utils/system/include/dfsu_exception.h index 46fb45290c01d9c22bdef493114928563a1a1ecf..2e523847cb83ea7c22dea4f0e1a5c2b4a419e7d3 100644 --- a/utils/system/include/utils_exception.h +++ b/utils/system/include/dfsu_exception.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UTILS_EXCEPTION_H -#define UTILS_EXCEPTION_H +#ifndef DFSU_EXCEPTION_H +#define DFSU_EXCEPTION_H #include #include @@ -34,9 +34,9 @@ enum { ERR_DEVICE_CID_UN_INIT, }; -class Exception : public std::exception { +class DfsuException : public std::exception { public: - Exception(int code, const std::string &msg) : code_(code), msg_(msg) {}; + DfsuException(int code, const std::string &msg) : code_(code), msg_(msg) {}; uint32_t code() const noexcept { @@ -53,15 +53,14 @@ private: std::string msg_; }; -#define ThrowException(code, msg) \ - do { \ - std::stringstream __ss; \ - __ss << '[' << code << ']' << msg << std::endl; \ - LOGE("%{public}s", __ss.str().c_str()); \ - throw Exception(code, __ss.str()); \ +#define ThrowException(code, msg) \ + do { \ + std::stringstream __ss; \ + __ss << '[' << (code) << ']' << (msg) << std::endl; \ + LOGE("%{public}s", __ss.str().c_str()); \ + throw DfsuException((code), __ss.str()); \ } while (0) - } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_EXCEPTION_H \ No newline at end of file +#endif // DFSU_EXCEPTION_H \ No newline at end of file diff --git a/utils/system/include/utils_mount_argument.h b/utils/system/include/dfsu_mount_argument_descriptors.h similarity index 89% rename from utils/system/include/utils_mount_argument.h rename to utils/system/include/dfsu_mount_argument_descriptors.h index e3cf81f150a36067c9ddf8f8e4f449e63000ecba..87fc9e7518e56d97d3199e98ab47c50450b0da20 100644 --- a/utils/system/include/utils_mount_argument.h +++ b/utils/system/include/dfsu_mount_argument_descriptors.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UTILS_MOUNT_ARGUMENT_H -#define UTILS_MOUNT_ARGUMENT_H +#ifndef DFSU_MOUNT_ARGUMENT_DESCRIPTORS_H +#define DFSU_MOUNT_ARGUMENT_DESCRIPTORS_H #include @@ -42,7 +42,7 @@ struct MountArgument final { unsigned long GetFlags() const; }; -class MountArgumentDescriptors final { +class DfsuMountArgumentDescriptors final { public: static MountArgument Alpha(int userId, std::string relativePath); }; @@ -50,4 +50,4 @@ public: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_MOUNT_ARGUMENT_H +#endif // DFSU_MOUNT_ARGUMENT_DESCRIPTORS_H diff --git a/utils/system/include/utils_singleton.h b/utils/system/include/dfsu_singleton.h similarity index 90% rename from utils/system/include/utils_singleton.h rename to utils/system/include/dfsu_singleton.h index 3cdff6b8b8d383d20502fcf7532de2b5f29f2b7e..eea5a43c26d3f839e06770f7f92d93fe31845ca0 100644 --- a/utils/system/include/utils_singleton.h +++ b/utils/system/include/dfsu_singleton.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UTILS_SINGLETON_H -#define UTILS_SINGLETON_H +#ifndef DFSU_SINGLETON_H +#define DFSU_SINGLETON_H #include #include @@ -32,11 +32,11 @@ public: \ MyClass& operator=(const MyClass&) = delete; \ \ private: \ - friend Singleton; \ + friend DfsuSingleton; \ MyClass(); template -class Singleton : public NoCopyable { +class DfsuSingleton : public NoCopyable { public: static std::shared_ptr GetInstance(); @@ -62,7 +62,7 @@ protected: * @note Memory leaking of T is exactly what we want. Now T will be available along the program's life-time */ template -std::shared_ptr Singleton::GetInstance() +std::shared_ptr DfsuSingleton::GetInstance() { static std::shared_ptr *dummy = nullptr; static std::once_flag once; @@ -76,4 +76,4 @@ std::shared_ptr Singleton::GetInstance() } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_SINGLETON_H \ No newline at end of file +#endif // DFSU_SINGLETON_H \ No newline at end of file diff --git a/utils/system/include/utils_startable.h b/utils/system/include/dfsu_startable.h similarity index 89% rename from utils/system/include/utils_startable.h rename to utils/system/include/dfsu_startable.h index e00127c2ae47306ba8f9b1a2b1865620ce3c7c9d..4a5d6f5c643c77ca2f98af13d5399f0bf49e674f 100644 --- a/utils/system/include/utils_startable.h +++ b/utils/system/include/dfsu_startable.h @@ -13,13 +13,13 @@ * limitations under the License. */ -#ifndef UTILS_STARTABLE_H -#define UTILS_STARTABLE_H +#ifndef DFSU_STARTABLE_H +#define DFSU_STARTABLE_H namespace OHOS { namespace Storage { namespace DistributedFile { -class Startable { +class DfsuStartable { public: virtual void Start() = 0; virtual void Stop() = 0; @@ -27,4 +27,4 @@ public: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_STARTABLE_H \ No newline at end of file +#endif // DFSU_STARTABLE_H \ No newline at end of file diff --git a/utils/system/include/utils_dfs_thread.h b/utils/system/include/dfsu_thread.h similarity index 94% rename from utils/system/include/utils_dfs_thread.h rename to utils/system/include/dfsu_thread.h index 4643fec67029223b437747f6e91e8a8ec0a57833..751eda2555e403c2a7b8f5e9f0bc80b630df65d5 100644 --- a/utils/system/include/utils_dfs_thread.h +++ b/utils/system/include/dfsu_thread.h @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef UTILS_DFS_THREAD_H -#define UTILS_DFS_THREAD_H +#ifndef DFSU_THREAD_H +#define DFSU_THREAD_H #include #include @@ -26,13 +26,13 @@ namespace OHOS { namespace Storage { namespace DistributedFile { namespace Utils { -class DfsThread { +class DfsuThread { public: - DfsThread() = default; - DfsThread(const DfsThread &) = delete; - DfsThread &operator=(const DfsThread &) = delete; + DfsuThread() = default; + DfsuThread(const DfsuThread &) = delete; + DfsuThread &operator=(const DfsuThread &) = delete; - ~DfsThread() + ~DfsuThread() { Stop(); } @@ -136,4 +136,4 @@ private: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_DFS_THREAD_H \ No newline at end of file +#endif // DFSU_THREAD_H \ No newline at end of file diff --git a/utils/system/include/utils_thread_safe_queue.h b/utils/system/include/dfsu_thread_safe_queue.h similarity index 91% rename from utils/system/include/utils_thread_safe_queue.h rename to utils/system/include/dfsu_thread_safe_queue.h index 11a06347d60ca616f19e023f6ae965b04478426f..e66ba45679ed945b2a9f33059ca602121e415764 100644 --- a/utils/system/include/utils_thread_safe_queue.h +++ b/utils/system/include/dfsu_thread_safe_queue.h @@ -13,16 +13,13 @@ * limitations under the License. */ -#ifndef UTILS_THREAD_SAFE_QUEUE_H -#define UTILS_THREAD_SAFE_QUEUE_H +#ifndef DFSU_THREAD_SAFE_QUEUE_H +#define DFSU_THREAD_SAFE_QUEUE_H #include -#include -#include #include -#include -#include "utils_exception.h" +#include "dfsu_exception.h" namespace OHOS { namespace Storage { @@ -40,7 +37,7 @@ namespace DistributedFile { * */ template -class ThreadSafeQueue { +class DfsuThreadSafeQueue { public: void Push(std::unique_ptr pt) { @@ -97,4 +94,4 @@ private: } // namespace DistributedFile } // namespace Storage } // namespace OHOS -#endif // UTILS_THREAD_SAFE_QUEUE_H \ No newline at end of file +#endif // DFSU_THREAD_SAFE_QUEUE_H \ No newline at end of file diff --git a/utils/system/src/utils_mount_argument.cpp b/utils/system/src/dfsu_mount_argument_descriptors.cpp similarity index 95% rename from utils/system/src/utils_mount_argument.cpp rename to utils/system/src/dfsu_mount_argument_descriptors.cpp index 17ac0d3c4b1e6289e5a9fc469ad6fe526ab62311..43906edfdf7736a1828c91f072c1104b9d6144f5 100644 --- a/utils/system/src/utils_mount_argument.cpp +++ b/utils/system/src/dfsu_mount_argument_descriptors.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "utils_mount_argument.h" +#include "dfsu_mount_argument_descriptors.h" #include #include @@ -101,7 +101,7 @@ unsigned long MountArgument::GetFlags() const return MS_NODEV; } -MountArgument MountArgumentDescriptors::Alpha(int userId, string relativePath) +MountArgument DfsuMountArgumentDescriptors::Alpha(int userId, string relativePath) { MountArgument mountArgument = { .userId_ = userId,