From 3ac712779dc5d386a653c500dc0b785109a80aeb Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Mon, 28 Feb 2022 17:17:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=89=AB=E6=8F=8F=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=92=8C=E7=B1=BB=E5=90=8D=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hhchinasoft --- .../include/device/device_manager_agent.h | 12 ++++---- .../include/mountpoint/mount_manager.h | 4 +-- .../include/mountpoint/mount_point.h | 2 +- .../include/network/network_agent_template.h | 12 ++++---- .../src/device/device_info.cpp | 2 +- .../src/device/device_manager_agent.cpp | 13 +++++---- .../src/mountpoint/mount_manager.cpp | 2 +- .../src/multiuser/os_account_observer.cpp | 10 +++---- .../src/network/devsl_dispatcher.cpp | 1 - .../src/network/network_agent_template.cpp | 14 +++++----- .../src/network/softbus/softbus_agent.cpp | 4 +-- .../include/device/device_manager_agent.h | 4 +-- .../include/network/softbus_agent.h | 4 +-- .../src/device/device_manager_agent.cpp | 2 +- .../src/network/softbus_agent.cpp | 2 +- .../distributedfiledaemon_service_test.cpp | 1 - utils/BUILD.gn | 2 +- .../include/{utils_actor.h => dfsu_actor.h} | 28 +++++++++---------- .../include/{utils_cmd.h => dfsu_cmd.h} | 20 ++++++------- .../{utils_exception.h => dfsu_exception.h} | 13 ++++----- ...nt.h => dfsu_mount_argument_descriptors.h} | 8 +++--- .../{utils_singleton.h => dfsu_singleton.h} | 12 ++++---- .../{utils_startable.h => dfsu_startable.h} | 8 +++--- .../{utils_dfs_thread.h => dfsu_thread.h} | 16 +++++------ ..._safe_queue.h => dfsu_thread_safe_queue.h} | 10 +++---- ...pp => dfsu_mount_argument_descriptors.cpp} | 4 +-- 26 files changed, 104 insertions(+), 106 deletions(-) mode change 100755 => 100644 utils/BUILD.gn rename utils/system/include/{utils_actor.h => dfsu_actor.h} (85%) rename utils/system/include/{utils_cmd.h => dfsu_cmd.h} (85%) rename utils/system/include/{utils_exception.h => dfsu_exception.h} (85%) rename utils/system/include/{utils_mount_argument.h => dfsu_mount_argument_descriptors.h} (89%) rename utils/system/include/{utils_singleton.h => dfsu_singleton.h} (90%) rename utils/system/include/{utils_startable.h => dfsu_startable.h} (89%) rename utils/system/include/{utils_dfs_thread.h => dfsu_thread.h} (94%) rename utils/system/include/{utils_thread_safe_queue.h => dfsu_thread_safe_queue.h} (94%) rename utils/system/src/{utils_mount_argument.cpp => dfsu_mount_argument_descriptors.cpp} (95%) diff --git a/services/distributedfiledaemon/include/device/device_manager_agent.h b/services/distributedfiledaemon/include/device/device_manager_agent.h index 27617ac03..50a82e8d7 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/mountpoint/mount_manager.h b/services/distributedfiledaemon/include/mountpoint/mount_manager.h index 7b04f10c3..3012028ef 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 9887e7331..c2a274b88 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 a8c886f03..24a4fe580 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 bf15d03be..7f83943c4 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 dba021dcf..cadd4313e 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/mountpoint/mount_manager.cpp b/services/distributedfiledaemon/src/mountpoint/mount_manager.cpp index 3f8696eaa..52fca4351 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 086f7a27e..accf45040 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 2462f05a0..135bc5122 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/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index e5d2d9e1e..06c181a4b 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 8ff475ab4..e69426223 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 b2a11da1a..82f024813 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 556d2b23f..bde01d7c7 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 2e494cc27..aa418b9ca 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 3596162c8..8fa2df2b5 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 13d9b4521..57f07ff69 100644 --- a/test/moduletest/src/distributedfiledaemon_service_test.cpp +++ b/test/moduletest/src/distributedfiledaemon_service_test.cpp @@ -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 8ce6bc6df..3a0a30363 --- 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 85% rename from utils/system/include/utils_actor.h rename to utils/system/include/dfsu_actor.h index 35a902a2a..479189656 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/dfsu_actor.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UTILS_ACTOR_H -#define UTILS_ACTOR_H +#ifndef DFSU_ACTOR_H +#define DFSU_ACTOR_H #include #include @@ -23,8 +23,8 @@ #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 +36,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 +63,7 @@ public: } protected: - ThreadSafeQueue> pendingCmds_; + DfsuThreadSafeQueue> pendingCmds_; Ctx *ctx_ {nullptr}; uint32_t retryTimes_ {1}; @@ -88,14 +88,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)); } @@ -121,7 +121,7 @@ private: (*currentCmd)(ctx_); currentCmd.release(); } - } catch (const Exception &e) { + } catch (const DfsuException &e) { if (e.code() == ERR_UTILS_ACTOR_QUEUE_STOP) { break; } @@ -135,7 +135,7 @@ private: if (op.importance_ == CmdImportance::TRIVIAL) { if (op.tryTimes_) { retryTasks.emplace_back( - std::async(std::launch::async, &Actor::DelayRetry, this, std::move(currentCmd))); + std::async(std::launch::async, &DfsuActor::DelayRetry, this, std::move(currentCmd))); continue; } } else { @@ -161,4 +161,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 f45ddd7d1..ee15bb269 100644 --- a/utils/system/include/utils_cmd.h +++ b/utils/system/include/dfsu_cmd.h @@ -13,13 +13,13 @@ * 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 +42,11 @@ struct CmdOptions { }; template -class Actor; +class DfsuActor; template class VirtualCmd { - friend class Actor; + friend class DfsuActor; public: VirtualCmd() = default; @@ -63,12 +63,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 +87,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 85% rename from utils/system/include/utils_exception.h rename to utils/system/include/dfsu_exception.h index 46fb45290..42c361534 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 { @@ -58,10 +58,9 @@ private: std::stringstream __ss; \ __ss << '[' << code << ']' << msg << std::endl; \ LOGE("%{public}s", __ss.str().c_str()); \ - throw Exception(code, __ss.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 e3cf81f15..87fc9e751 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 3cdff6b8b..eea5a43c2 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 e00127c2a..4a5d6f5c6 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 4643fec67..751eda255 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 94% rename from utils/system/include/utils_thread_safe_queue.h rename to utils/system/include/dfsu_thread_safe_queue.h index 11a06347d..198715fa9 100644 --- a/utils/system/include/utils_thread_safe_queue.h +++ b/utils/system/include/dfsu_thread_safe_queue.h @@ -13,8 +13,8 @@ * 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 @@ -22,7 +22,7 @@ #include #include -#include "utils_exception.h" +#include "dfsu_exception.h" namespace OHOS { namespace Storage { @@ -40,7 +40,7 @@ namespace DistributedFile { * */ template -class ThreadSafeQueue { +class DfsuThreadSafeQueue { public: void Push(std::unique_ptr pt) { @@ -97,4 +97,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 17ac0d3c4..43906edfd 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, -- Gitee From f846294bf6dcdc0cbf3dcf2640e7dff49bcd9b3b Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Mon, 28 Feb 2022 18:02:58 +0800 Subject: [PATCH 2/3] code chek clean Signed-off-by: hhchinasoft --- .../distributedfiledaemon_service_test.cpp | 24 +++++++++---------- utils/system/include/dfsu_actor.h | 2 -- utils/system/include/dfsu_cmd.h | 1 - utils/system/include/dfsu_exception.h | 12 +++++----- utils/system/include/dfsu_thread_safe_queue.h | 3 --- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/test/moduletest/src/distributedfiledaemon_service_test.cpp b/test/moduletest/src/distributedfiledaemon_service_test.cpp index 57f07ff69..52f5d55cd 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); diff --git a/utils/system/include/dfsu_actor.h b/utils/system/include/dfsu_actor.h index 479189656..dde2edeef 100644 --- a/utils/system/include/dfsu_actor.h +++ b/utils/system/include/dfsu_actor.h @@ -20,8 +20,6 @@ #include #include #include -#include -#include #include "dfsu_cmd.h" #include "dfsu_thread_safe_queue.h" diff --git a/utils/system/include/dfsu_cmd.h b/utils/system/include/dfsu_cmd.h index ee15bb269..dd7b7c0f9 100644 --- a/utils/system/include/dfsu_cmd.h +++ b/utils/system/include/dfsu_cmd.h @@ -17,7 +17,6 @@ #define DFSU_CMD_H #include -#include #include "dfsu_exception.h" diff --git a/utils/system/include/dfsu_exception.h b/utils/system/include/dfsu_exception.h index 42c361534..2e523847c 100644 --- a/utils/system/include/dfsu_exception.h +++ b/utils/system/include/dfsu_exception.h @@ -53,12 +53,12 @@ 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 DfsuException(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 diff --git a/utils/system/include/dfsu_thread_safe_queue.h b/utils/system/include/dfsu_thread_safe_queue.h index 198715fa9..e66ba4567 100644 --- a/utils/system/include/dfsu_thread_safe_queue.h +++ b/utils/system/include/dfsu_thread_safe_queue.h @@ -17,10 +17,7 @@ #define DFSU_THREAD_SAFE_QUEUE_H #include -#include -#include #include -#include #include "dfsu_exception.h" -- Gitee From 6859ba564aa1c55a50c999c614ccd1be64c6aed4 Mon Sep 17 00:00:00 2001 From: hhchinasoft Date: Tue, 1 Mar 2022 15:29:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A5=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=89=AB=E6=8F=8F=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?= =?UTF-8?q?=E5=92=8C=E7=B1=BB=E5=90=8D=E4=B8=8D=E4=B8=80=E8=87=B4=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hhchinasoft --- utils/system/include/dfsu_actor.h | 66 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/utils/system/include/dfsu_actor.h b/utils/system/include/dfsu_actor.h index dde2edeef..05ce9b551 100644 --- a/utils/system/include/dfsu_actor.h +++ b/utils/system/include/dfsu_actor.h @@ -109,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) { @@ -120,35 +155,10 @@ private: currentCmd.release(); } } catch (const DfsuException &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, &DfsuActor::DelayRetry, this, std::move(currentCmd))); - continue; - } + 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"); -- Gitee