From fb202680656b9f7822007850229e482a4c2f288b Mon Sep 17 00:00:00 2001 From: flemingYu Date: Sat, 19 Feb 2022 09:38:19 -0800 Subject: [PATCH 1/6] code check Signed-off-by: flemingYu --- .../include/device/device_info.h | 2 +- services/distributedfiledaemon/include/ipc/daemon.h | 6 +++--- .../distributedfiledaemon/include/ipc/i_daemon.h | 2 +- .../include/mountpoint/mount_point.h | 2 +- .../include/network/kernel_talker.h | 6 +++--- .../include/network/softbus/softbus_agent.h | 2 +- .../include/network/softbus/softbus_session.h | 2 +- .../src/device/device_manager_agent.cpp | 4 ++-- .../src/network/kernel_talker.cpp | 4 ++-- .../src/network/network_agent_template.cpp | 6 +++--- .../src/network/session_pool.cpp | 2 +- .../src/network/softbus/softbus_agent.cpp | 4 ++-- .../unittest/device/device_manager_agent_test.cpp | 2 +- .../src/distributedfiledaemon_service_test.cpp | 1 - utils/system/include/utils_actor.h | 8 ++++---- utils/system/include/utils_cmd.h | 4 ++-- utils/system/include/utils_dfs_thread.h | 12 ++++++------ utils/system/include/utils_exception.h | 4 ++-- utils/system/include/utils_singleton.h | 2 +- utils/system/include/utils_thread_safe_queue.h | 4 +--- 20 files changed, 38 insertions(+), 41 deletions(-) diff --git a/services/distributedfiledaemon/include/device/device_info.h b/services/distributedfiledaemon/include/device/device_info.h index 0864dc2cc..532455cdd 100644 --- a/services/distributedfiledaemon/include/device/device_info.h +++ b/services/distributedfiledaemon/include/device/device_info.h @@ -39,7 +39,7 @@ public: private: friend class DeviceManagerAgent; - std::atomic initCidFlag_{false}; + std::atomic initCidFlag_ { false }; std::string cid_; std::string udid_; }; diff --git a/services/distributedfiledaemon/include/ipc/daemon.h b/services/distributedfiledaemon/include/ipc/daemon.h index d5326ac4e..a1a3ecc87 100644 --- a/services/distributedfiledaemon/include/ipc/daemon.h +++ b/services/distributedfiledaemon/include/ipc/daemon.h @@ -32,7 +32,7 @@ class Daemon final : public SystemAbility, public DaemonStub, protected NoCopyab DECLARE_SYSTEM_ABILITY(Daemon); public: - explicit Daemon(int32_t saID, bool runOnCreate = true) : SystemAbility(saID, runOnCreate){}; + explicit Daemon(int32_t saID, bool runOnCreate = true) : SystemAbility(saID, runOnCreate) {}; virtual ~Daemon() = default; void OnStart() override; @@ -46,10 +46,10 @@ public: private: Daemon(); - ServiceRunningState state_{ServiceRunningState::STATE_NOT_START}; + ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START }; static sptr instance_; static std::mutex instanceLock_; - bool registerToService_{false}; + bool registerToService_ { false }; void PublishSA(); void RegisterOsAccount(); diff --git a/services/distributedfiledaemon/include/ipc/i_daemon.h b/services/distributedfiledaemon/include/ipc/i_daemon.h index fce520673..d67264daa 100644 --- a/services/distributedfiledaemon/include/ipc/i_daemon.h +++ b/services/distributedfiledaemon/include/ipc/i_daemon.h @@ -28,7 +28,7 @@ public: }; virtual int32_t EchoServerDemo(const std::string &echoStr) = 0; - static inline const std::string SERVICE_NAME{"ohos.storage.distributedfile.daemon"}; + static inline const std::string SERVICE_NAME { "ohos.storage.distributedfile.daemon" }; DECLARE_INTERFACE_DESCRIPTOR(u"ohos.storage.distributedfile.daemon") }; } // namespace DistributedFile diff --git a/services/distributedfiledaemon/include/mountpoint/mount_point.h b/services/distributedfiledaemon/include/mountpoint/mount_point.h index 4c047f41c..b7e464ed3 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_point.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_point.h @@ -50,7 +50,7 @@ private: void Mount() const; void Umount() const; static std::atomic idGen_; - uint32_t id_{0}; + uint32_t id_ { 0 }; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/network/kernel_talker.h b/services/distributedfiledaemon/include/network/kernel_talker.h index d54960554..f98fac656 100644 --- a/services/distributedfiledaemon/include/network/kernel_talker.h +++ b/services/distributedfiledaemon/include/network/kernel_talker.h @@ -93,9 +93,9 @@ private: std::weak_ptr mountPoint_; std::mutex cmdMutex_; std::atomic isRunning_{true}; - std::unique_ptr pollThread_{nullptr}; - std::function GetSessionCallback_{nullptr}; - std::function CloseSessionCallback_{nullptr}; + std::unique_ptr pollThread_ {nullptr}; + std::function GetSessionCallback_ {nullptr}; + std::function CloseSessionCallback_ {nullptr}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h index 28d88c4b7..03c7f14ff 100644 --- a/services/distributedfiledaemon/include/network/softbus/softbus_agent.h +++ b/services/distributedfiledaemon/include/network/softbus/softbus_agent.h @@ -16,8 +16,8 @@ #ifndef SOFTBUS_AGENT_H #define SOFTBUS_AGENT_H -#include "network/network_agent_template.h" #include +#include "network/network_agent_template.h" namespace OHOS { namespace Storage { diff --git a/services/distributedfiledaemon/include/network/softbus/softbus_session.h b/services/distributedfiledaemon/include/network/softbus/softbus_session.h index 4816c3ead..9d41f89ea 100644 --- a/services/distributedfiledaemon/include/network/softbus/softbus_session.h +++ b/services/distributedfiledaemon/include/network/softbus/softbus_session.h @@ -36,7 +36,7 @@ public: private: int sessionId_; std::string cid_; - int32_t socketFd_{INVALID_SOCKET_FD}; + int32_t socketFd_ { INVALID_SOCKET_FD }; std::array key_; bool IsServerSide_; }; diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index bde0253ac..96fa5b656 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -129,7 +129,7 @@ void DeviceManagerAgent::ReconnectOnlineDevices() unique_lock lock(mpToNetworksMutex_); for (auto [ignore, net] : cidNetTypeRecord_) { auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, }); net->Recv(move(cmd)); @@ -165,7 +165,7 @@ void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo } auto cmd = make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, }); networkAgent->Recv(move(cmd)); diff --git a/services/distributedfiledaemon/src/network/kernel_talker.cpp b/services/distributedfiledaemon/src/network/kernel_talker.cpp index 87b7f877f..7e64a30fb 100644 --- a/services/distributedfiledaemon/src/network/kernel_talker.cpp +++ b/services/distributedfiledaemon/src/network/kernel_talker.cpp @@ -50,7 +50,7 @@ struct OfflineParam { uint8_t remoteCid[CID_MAX_LEN]; } __attribute__((packed)); -enum { +enum CmdCode { CMD_UPDATE_SOCKET = 0, CMD_UPDATE_DEVSL, CMD_OFF_LINE, @@ -58,7 +58,7 @@ enum { CMD_CNT, }; -enum { +enum SocketStat { SOCKET_STAT_ACCEPT = 0, SOCKET_STAT_OPEN, }; diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index fabad4140..79268606a 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -56,7 +56,7 @@ void NetworkAgentTemplate::ConnectOnlineDevices() for (const auto &info : infos) { auto cmd = make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, }); Recv(move(cmd)); @@ -83,7 +83,7 @@ void NetworkAgentTemplate::AcceptSession(shared_ptr session) { auto cmd = make_unique>>( &NetworkAgentTemplate::AcceptSessionInner, session); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = 1, }); Recv(move(cmd)); @@ -100,7 +100,7 @@ void NetworkAgentTemplate::GetSessionProcess(NotifyParam ¶m) { auto cmd = make_unique>(&NetworkAgentTemplate::GetSessionProcessInner, param); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = 1, }); Recv(move(cmd)); diff --git a/services/distributedfiledaemon/src/network/session_pool.cpp b/services/distributedfiledaemon/src/network/session_pool.cpp index 0bf259db4..0303a552f 100644 --- a/services/distributedfiledaemon/src/network/session_pool.cpp +++ b/services/distributedfiledaemon/src/network/session_pool.cpp @@ -59,7 +59,7 @@ void SessionPool::ReleaseAllSession() lock_guard lock(sessionPoolLock_); for (auto iter = usrSpaceSessionPool_.begin(); iter != usrSpaceSessionPool_.end();) { talker_->SinkOfflineCmdToKernel((*iter)->GetCid()); - /* device offline, session release by softbus*/ + /* device offline, session release by softbus */ iter = usrSpaceSessionPool_.erase(iter); } } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index ccb14e7c3..8ce2d4bab 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -118,7 +118,7 @@ bool SoftbusAgent::IsContinueRetry(const string &cid) return false; } } else { - OpenSessionRetriedTimesMap_.insert({cid, 0}); + OpenSessionRetriedTimesMap_.insert( { cid, 0 } ); } OpenSessionRetriedTimesMap_[cid]++; return true; @@ -138,7 +138,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) if (IsContinueRetry(cid)) { auto cmd = make_unique>( &NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption({ + cmd->UpdateOption( { .tryTimes_ = 1, }); Recv(move(cmd)); diff --git a/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp b/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp index c029960eb..8fda2f32e 100644 --- a/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp +++ b/services/distributedfiledaemon/test/unittest/device/device_manager_agent_test.cpp @@ -13,8 +13,8 @@ * limitations under the License. */ -#include "device/device_manager_agent.h" #include +#include "device/device_manager_agent.h" namespace OHOS { namespace Storage { diff --git a/test/moduletest/src/distributedfiledaemon_service_test.cpp b/test/moduletest/src/distributedfiledaemon_service_test.cpp index 38199d5d3..13d9b4521 100644 --- a/test/moduletest/src/distributedfiledaemon_service_test.cpp +++ b/test/moduletest/src/distributedfiledaemon_service_test.cpp @@ -675,7 +675,6 @@ HWTEST_F(DistributedFileDaemonServiceTest, distributedFileDaemon_service_test_01 strcpy_s(param.remoteCid, CID_MAX_LEN, str.data()); kt.NotifyHandler(param); } - EXPECT_EQ(0, 0); } diff --git a/utils/system/include/utils_actor.h b/utils/system/include/utils_actor.h index 18b27291d..6a93a6ec0 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/utils_actor.h @@ -65,8 +65,8 @@ public: protected: ThreadSafeQueue> pendingCmds_; - Ctx *ctx_{nullptr}; - uint32_t retryTimes_{1}; + Ctx *ctx_ { nullptr }; + uint32_t retryTimes_ { 1 }; std::thread loop_; std::list> retryTasks; @@ -89,7 +89,7 @@ private: void StartCtx() { auto startCmd = std::make_unique>(&Ctx::Start); - startCmd->UpdateOption({ + startCmd->UpdateOption( { .importance_ = CmdImportance::SUBVITAL, .tryTimes_ = retryTimes_, }); @@ -99,7 +99,7 @@ private: void StopCtx() { auto cmd = std::make_unique>(&Ctx::Stop); - cmd->UpdateOption({ + cmd->UpdateOption( { .importance_ = CmdImportance::VITAL, .tryTimes_ = 1, }); diff --git a/utils/system/include/utils_cmd.h b/utils/system/include/utils_cmd.h index fc41bfc7e..f47a93566 100644 --- a/utils/system/include/utils_cmd.h +++ b/utils/system/include/utils_cmd.h @@ -37,8 +37,8 @@ enum class CmdImportance { }; struct CmdOptions { - CmdImportance importance_{CmdImportance::TRIVIAL}; - uint32_t tryTimes_{1}; + CmdImportance importance_ { CmdImportance::TRIVIAL }; + uint32_t tryTimes_ { 1 }; }; template diff --git a/utils/system/include/utils_dfs_thread.h b/utils/system/include/utils_dfs_thread.h index 593ec79fd..bd82a549c 100644 --- a/utils/system/include/utils_dfs_thread.h +++ b/utils/system/include/utils_dfs_thread.h @@ -15,12 +15,12 @@ #ifndef UTILS_DFS_THREAD_H #define UTILS_DFS_THREAD_H -#include "utils_log.h" #include #include #include #include #include +#include "utils_log.h" namespace OHOS { namespace Storage { @@ -126,11 +126,11 @@ public: } private: - std::atomic_bool running_{false}; - std::mutex threadMutex_{}; - std::unique_ptr thread_{nullptr}; - std::mutex sleepMutex_{}; - std::condition_variable sleepCv_{}; + std::atomic_bool running_ { false }; + std::mutex threadMutex_ {}; + std::unique_ptr thread_ { nullptr }; + std::mutex sleepMutex_ {}; + std::condition_variable sleepCv_ {}; }; } // namespace Utils } // namespace DistributedFile diff --git a/utils/system/include/utils_exception.h b/utils/system/include/utils_exception.h index 6afd215aa..97dd6b27f 100644 --- a/utils/system/include/utils_exception.h +++ b/utils/system/include/utils_exception.h @@ -36,7 +36,7 @@ enum { class Exception : public std::exception { public: - Exception(int code, const std::string &msg) : code_(code), msg_(msg){}; + Exception(int code, const std::string &msg) : code_(code), msg_(msg) {}; uint32_t code() const noexcept { @@ -49,7 +49,7 @@ public: } private: - int code_{ERR_DEFAULT}; + int code_ { ERR_DEFAULT }; std::string msg_; }; diff --git a/utils/system/include/utils_singleton.h b/utils/system/include/utils_singleton.h index ffa1b58b5..3cdff6b8b 100644 --- a/utils/system/include/utils_singleton.h +++ b/utils/system/include/utils_singleton.h @@ -16,10 +16,10 @@ #ifndef UTILS_SINGLETON_H #define UTILS_SINGLETON_H -#include "nocopyable.h" #include #include #include +#include "nocopyable.h" namespace OHOS { namespace Storage { diff --git a/utils/system/include/utils_thread_safe_queue.h b/utils/system/include/utils_thread_safe_queue.h index fb6139dcc..0c42f99cc 100644 --- a/utils/system/include/utils_thread_safe_queue.h +++ b/utils/system/include/utils_thread_safe_queue.h @@ -27,7 +27,6 @@ namespace OHOS { namespace Storage { namespace DistributedFile { - /** * @brief A Thread-safe Queue. * @@ -40,7 +39,6 @@ namespace DistributedFile { * @tparam T Any type. Aggregate data type is prefered * */ - template class ThreadSafeQueue { public: @@ -94,7 +92,7 @@ private: std::mutex mutex_; std::condition_variable cv_; - bool halted{false}; + bool halted { false }; }; } // namespace DistributedFile } // namespace Storage -- Gitee From 63bc2336719a9fa19f5aa639e498208d90393caa Mon Sep 17 00:00:00 2001 From: flemingYu Date: Mon, 21 Feb 2022 10:28:26 +0800 Subject: [PATCH 2/6] code chek Signed-off-by: flemingYu --- .../src/device/device_manager_agent.cpp | 2 +- .../src/network/network_agent_template.cpp | 6 +++--- .../src/network/softbus/softbus_agent.cpp | 4 ++-- utils/system/include/utils_actor.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index 96fa5b656..ff1978f02 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -131,7 +131,7 @@ void DeviceManagerAgent::ReconnectOnlineDevices() auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, - }); + } ); net->Recv(move(cmd)); } } diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 79268606a..24a387a3d 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -58,7 +58,7 @@ void NetworkAgentTemplate::ConnectOnlineDevices() make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, - }); + } ); Recv(move(cmd)); } } @@ -85,7 +85,7 @@ void NetworkAgentTemplate::AcceptSession(shared_ptr session) &NetworkAgentTemplate::AcceptSessionInner, session); cmd->UpdateOption( { .tryTimes_ = 1, - }); + } ); Recv(move(cmd)); } @@ -102,7 +102,7 @@ void NetworkAgentTemplate::GetSessionProcess(NotifyParam ¶m) make_unique>(&NetworkAgentTemplate::GetSessionProcessInner, param); cmd->UpdateOption( { .tryTimes_ = 1, - }); + } ); Recv(move(cmd)); } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index 8ce2d4bab..95ac950f6 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -118,7 +118,7 @@ bool SoftbusAgent::IsContinueRetry(const string &cid) return false; } } else { - OpenSessionRetriedTimesMap_.insert( { cid, 0 } ); + OpenSessionRetriedTimesMap_.insert( {cid, 0} ); } OpenSessionRetriedTimesMap_[cid]++; return true; @@ -140,7 +140,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) &NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption( { .tryTimes_ = 1, - }); + } ); Recv(move(cmd)); } else { LOGE("Exceeded the maximum number of retries, not retry"); diff --git a/utils/system/include/utils_actor.h b/utils/system/include/utils_actor.h index 6a93a6ec0..a4e713c81 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/utils_actor.h @@ -92,7 +92,7 @@ private: startCmd->UpdateOption( { .importance_ = CmdImportance::SUBVITAL, .tryTimes_ = retryTimes_, - }); + } ); pendingCmds_.Push(std::move(startCmd)); } @@ -102,7 +102,7 @@ private: cmd->UpdateOption( { .importance_ = CmdImportance::VITAL, .tryTimes_ = 1, - }); + } ); pendingCmds_.Push(std::move(cmd)); } @@ -113,7 +113,7 @@ private: if (item->option_.importance_ == CmdImportance::VITAL) { result = true; } - }); + } ); return result; } -- Gitee From b54925c673464cbcb272865a99cafdf816727f81 Mon Sep 17 00:00:00 2001 From: flemingYu Date: Mon, 21 Feb 2022 15:28:12 +0800 Subject: [PATCH 3/6] code-check Signed-off-by: flemingYu --- .../src/device/device_manager_agent.cpp | 4 ++-- .../src/network/kernel_talker.cpp | 24 +++++++++---------- .../src/network/network_agent_template.cpp | 8 +++---- .../src/network/softbus/softbus_agent.cpp | 4 ++-- utils/system/include/utils_actor.h | 8 +++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index ff1978f02..a9aefa9f7 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -129,9 +129,9 @@ void DeviceManagerAgent::ReconnectOnlineDevices() unique_lock lock(mpToNetworksMutex_); for (auto [ignore, net] : cidNetTypeRecord_) { auto cmd = make_unique>(&NetworkAgentTemplate::ConnectOnlineDevices); - cmd->UpdateOption( { + cmd->UpdateOption({ .tryTimes_ = MAX_RETRY_COUNT, - } ); + }); net->Recv(move(cmd)); } } diff --git a/services/distributedfiledaemon/src/network/kernel_talker.cpp b/services/distributedfiledaemon/src/network/kernel_talker.cpp index 7e64a30fb..1c6bab090 100644 --- a/services/distributedfiledaemon/src/network/kernel_talker.cpp +++ b/services/distributedfiledaemon/src/network/kernel_talker.cpp @@ -50,7 +50,7 @@ struct OfflineParam { uint8_t remoteCid[CID_MAX_LEN]; } __attribute__((packed)); -enum CmdCode { +enum class CmdCode : int32_t { CMD_UPDATE_SOCKET = 0, CMD_UPDATE_DEVSL, CMD_OFF_LINE, @@ -58,12 +58,12 @@ enum CmdCode { CMD_CNT, }; -enum SocketStat { +enum class SocketStat : uint8_t { SOCKET_STAT_ACCEPT = 0, SOCKET_STAT_OPEN, }; -enum Notify { +enum class Notify : int32_t { NOTIFY_GET_SESSION = 0, NOTIFY_OFFLINE, NOTIFY_NONE, @@ -78,13 +78,13 @@ void KernelTalker::SinkSessionTokernel(shared_ptr session) LOGD("sink session to kernel success, cid:%{public}s, socketFd:%{public}d, key[0]:%{public}x", cid.c_str(), socketFd, *(uint32_t *)masterkey.data()); - uint8_t status = (session->IsFromServer() ? SOCKET_STAT_ACCEPT : SOCKET_STAT_OPEN); + SocketStat status = (session->IsFromServer() ? SocketStat::SOCKET_STAT_ACCEPT : SocketStat::SOCKET_STAT_OPEN); UpdateSocketParam cmd = { - .cmd = CMD_UPDATE_SOCKET, + .cmd = static_cast(CmdCode::CMD_UPDATE_SOCKET), .newfd = socketFd, .devsl = 3, - .status = status, + .status = static_cast(status), }; if (memcpy_s(cmd.masterKey, KEY_MAX_LEN, masterkey.data(), KEY_MAX_LEN) != EOK) { return; @@ -100,7 +100,7 @@ void KernelTalker::SinkDevslTokernel(const std::string &cid, uint32_t devsl) { LOGD("sink dsl to kernel success, cid:%{public}s, devsl:%{public}d", cid.c_str(), devsl); UpdateDevslParam cmd = { - .cmd = CMD_UPDATE_DEVSL, + .cmd = static_cast(CmdCode::CMD_UPDATE_DEVSL), .devsl = devsl, }; @@ -113,7 +113,7 @@ void KernelTalker::SinkDevslTokernel(const std::string &cid, uint32_t devsl) void KernelTalker::SinkOfflineCmdToKernel(string cid) { OfflineParam cmd = { - .cmd = CMD_OFF_LINE, + .cmd = static_cast(CmdCode::CMD_OFF_LINE), }; if (cid.length() < CID_MAX_LEN) { @@ -204,9 +204,9 @@ void KernelTalker::HandleAllNotify(int fd) while (isRunning_) { lseek(fd, 0, SEEK_SET); - param.notify = NOTIFY_NONE; + param.notify = static_cast(Notify::NOTIFY_NONE); int readSize = read(fd, ¶m, sizeof(NotifyParam)); - if ((readSize < (int)sizeof(NotifyParam)) || (param.notify == NOTIFY_NONE)) { + if ((readSize < (int)sizeof(NotifyParam)) || (param.notify == static_cast(Notify::NOTIFY_NONE))) { return; } NotifyHandler(param); @@ -218,10 +218,10 @@ void KernelTalker::NotifyHandler(NotifyParam ¶m) int cmd = param.notify; string cidStr(param.remoteCid, CID_MAX_LEN); switch (cmd) { - case NOTIFY_GET_SESSION: + case static_cast(Notify::NOTIFY_GET_SESSION): GetSessionCallback_(param); break; - case NOTIFY_OFFLINE: + case static_cast(Notify::NOTIFY_OFFLINE): LOGI("NOTIFY_OFFLINE, remote cid %{public}s", cidStr.c_str()); CloseSessionCallback_(cidStr); break; diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 24a387a3d..0bd403136 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -58,7 +58,7 @@ void NetworkAgentTemplate::ConnectOnlineDevices() make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption( { .tryTimes_ = MAX_RETRY_COUNT, - } ); + }); Recv(move(cmd)); } } @@ -83,9 +83,9 @@ void NetworkAgentTemplate::AcceptSession(shared_ptr session) { auto cmd = make_unique>>( &NetworkAgentTemplate::AcceptSessionInner, session); - cmd->UpdateOption( { + cmd->UpdateOption({ .tryTimes_ = 1, - } ); + }); Recv(move(cmd)); } @@ -102,7 +102,7 @@ void NetworkAgentTemplate::GetSessionProcess(NotifyParam ¶m) make_unique>(&NetworkAgentTemplate::GetSessionProcessInner, param); cmd->UpdateOption( { .tryTimes_ = 1, - } ); + }); Recv(move(cmd)); } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index 95ac950f6..a913a51c2 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -118,7 +118,7 @@ bool SoftbusAgent::IsContinueRetry(const string &cid) return false; } } else { - OpenSessionRetriedTimesMap_.insert( {cid, 0} ); + OpenSessionRetriedTimesMap_.insert({cid, 0}); } OpenSessionRetriedTimesMap_[cid]++; return true; @@ -140,7 +140,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) &NetworkAgentTemplate::ConnectDeviceAsync, info); cmd->UpdateOption( { .tryTimes_ = 1, - } ); + }); Recv(move(cmd)); } else { LOGE("Exceeded the maximum number of retries, not retry"); diff --git a/utils/system/include/utils_actor.h b/utils/system/include/utils_actor.h index a4e713c81..84f7118be 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/utils_actor.h @@ -92,17 +92,17 @@ private: startCmd->UpdateOption( { .importance_ = CmdImportance::SUBVITAL, .tryTimes_ = retryTimes_, - } ); + }); pendingCmds_.Push(std::move(startCmd)); } void StopCtx() { auto cmd = std::make_unique>(&Ctx::Stop); - cmd->UpdateOption( { + cmd->UpdateOption({ .importance_ = CmdImportance::VITAL, .tryTimes_ = 1, - } ); + }); pendingCmds_.Push(std::move(cmd)); } @@ -113,7 +113,7 @@ private: if (item->option_.importance_ == CmdImportance::VITAL) { result = true; } - } ); + }); return result; } -- Gitee From cd20b7b39cb63e02e424983a68a9307011bc3c6f Mon Sep 17 00:00:00 2001 From: flemingYu Date: Mon, 21 Feb 2022 16:13:27 +0800 Subject: [PATCH 4/6] code chk Signed-off-by: flemingYu --- .../src/device/device_manager_agent.cpp | 4 +--- .../src/network/network_agent_template.cpp | 4 +--- .../src/network/softbus/softbus_agent.cpp | 4 +--- utils/system/include/utils_actor.h | 10 ++-------- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/services/distributedfiledaemon/src/device/device_manager_agent.cpp b/services/distributedfiledaemon/src/device/device_manager_agent.cpp index a9aefa9f7..dba021dcf 100644 --- a/services/distributedfiledaemon/src/device/device_manager_agent.cpp +++ b/services/distributedfiledaemon/src/device/device_manager_agent.cpp @@ -165,9 +165,7 @@ void DeviceManagerAgent::OnDeviceOnline(const DistributedHardware::DmDeviceInfo } auto cmd = make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption( { - .tryTimes_ = MAX_RETRY_COUNT, - }); + cmd->UpdateOption({.tryTimes_ = MAX_RETRY_COUNT}); networkAgent->Recv(move(cmd)); LOGI("OnDeviceOnline end"); diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 0bd403136..5d10bec66 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -100,9 +100,7 @@ void NetworkAgentTemplate::GetSessionProcess(NotifyParam ¶m) { auto cmd = make_unique>(&NetworkAgentTemplate::GetSessionProcessInner, param); - cmd->UpdateOption( { - .tryTimes_ = 1, - }); + cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index a913a51c2..4042df123 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -138,9 +138,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) if (IsContinueRetry(cid)) { auto cmd = make_unique>( &NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption( { - .tryTimes_ = 1, - }); + cmd->UpdateOption({ .tryTimes_ = 1 }); Recv(move(cmd)); } else { LOGE("Exceeded the maximum number of retries, not retry"); diff --git a/utils/system/include/utils_actor.h b/utils/system/include/utils_actor.h index 84f7118be..20741d264 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/utils_actor.h @@ -89,20 +89,14 @@ private: void StartCtx() { auto startCmd = std::make_unique>(&Ctx::Start); - startCmd->UpdateOption( { - .importance_ = CmdImportance::SUBVITAL, - .tryTimes_ = retryTimes_, - }); + startCmd->UpdateOption({.importance_ = CmdImportance::SUBVITAL, .tryTimes_ = retryTimes_}); pendingCmds_.Push(std::move(startCmd)); } void StopCtx() { auto cmd = std::make_unique>(&Ctx::Stop); - cmd->UpdateOption({ - .importance_ = CmdImportance::VITAL, - .tryTimes_ = 1, - }); + cmd->UpdateOption({.importance_ = CmdImportance::VITAL, .tryTimes_ = 1}); pendingCmds_.Push(std::move(cmd)); } -- Gitee From 0163442787fdb261018ad009935aadfc60ea4d0d Mon Sep 17 00:00:00 2001 From: flemingYu Date: Mon, 21 Feb 2022 21:23:03 +0800 Subject: [PATCH 5/6] code check: unify space Signed-off-by: flemingYu --- .../include/mountpoint/mount_point.h | 2 +- .../distributedfiledaemon/include/network/kernel_talker.h | 2 +- .../include/network/softbus/softbus_session.h | 2 +- .../src/network/network_agent_template.cpp | 8 ++------ .../src/network/softbus/softbus_agent.cpp | 2 +- utils/system/include/utils_actor.h | 4 ++-- utils/system/include/utils_cmd.h | 2 +- utils/system/include/utils_dfs_thread.h | 4 ++-- utils/system/include/utils_exception.h | 2 +- utils/system/include/utils_thread_safe_queue.h | 2 +- 10 files changed, 13 insertions(+), 17 deletions(-) diff --git a/services/distributedfiledaemon/include/mountpoint/mount_point.h b/services/distributedfiledaemon/include/mountpoint/mount_point.h index b7e464ed3..9887e7331 100644 --- a/services/distributedfiledaemon/include/mountpoint/mount_point.h +++ b/services/distributedfiledaemon/include/mountpoint/mount_point.h @@ -50,7 +50,7 @@ private: void Mount() const; void Umount() const; static std::atomic idGen_; - uint32_t id_ { 0 }; + uint32_t id_ {0}; }; } // namespace DistributedFile } // namespace Storage diff --git a/services/distributedfiledaemon/include/network/kernel_talker.h b/services/distributedfiledaemon/include/network/kernel_talker.h index f98fac656..036ba4ce9 100644 --- a/services/distributedfiledaemon/include/network/kernel_talker.h +++ b/services/distributedfiledaemon/include/network/kernel_talker.h @@ -92,7 +92,7 @@ private: std::weak_ptr mountPoint_; std::mutex cmdMutex_; - std::atomic isRunning_{true}; + std::atomic isRunning_ {true}; std::unique_ptr pollThread_ {nullptr}; std::function GetSessionCallback_ {nullptr}; std::function CloseSessionCallback_ {nullptr}; diff --git a/services/distributedfiledaemon/include/network/softbus/softbus_session.h b/services/distributedfiledaemon/include/network/softbus/softbus_session.h index 9d41f89ea..4aed8576a 100644 --- a/services/distributedfiledaemon/include/network/softbus/softbus_session.h +++ b/services/distributedfiledaemon/include/network/softbus/softbus_session.h @@ -36,7 +36,7 @@ public: private: int sessionId_; std::string cid_; - int32_t socketFd_ { INVALID_SOCKET_FD }; + int32_t socketFd_ {INVALID_SOCKET_FD}; std::array key_; bool IsServerSide_; }; diff --git a/services/distributedfiledaemon/src/network/network_agent_template.cpp b/services/distributedfiledaemon/src/network/network_agent_template.cpp index 5d10bec66..e5d2d9e1e 100644 --- a/services/distributedfiledaemon/src/network/network_agent_template.cpp +++ b/services/distributedfiledaemon/src/network/network_agent_template.cpp @@ -56,9 +56,7 @@ void NetworkAgentTemplate::ConnectOnlineDevices() for (const auto &info : infos) { auto cmd = make_unique>(&NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption( { - .tryTimes_ = MAX_RETRY_COUNT, - }); + cmd->UpdateOption({.tryTimes_ = MAX_RETRY_COUNT}); Recv(move(cmd)); } } @@ -83,9 +81,7 @@ void NetworkAgentTemplate::AcceptSession(shared_ptr session) { auto cmd = make_unique>>( &NetworkAgentTemplate::AcceptSessionInner, session); - cmd->UpdateOption({ - .tryTimes_ = 1, - }); + cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); } diff --git a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp index 4042df123..8ff475ab4 100644 --- a/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp +++ b/services/distributedfiledaemon/src/network/softbus/softbus_agent.cpp @@ -138,7 +138,7 @@ int SoftbusAgent::OnSessionOpened(const int sessionId, const int result) if (IsContinueRetry(cid)) { auto cmd = make_unique>( &NetworkAgentTemplate::ConnectDeviceAsync, info); - cmd->UpdateOption({ .tryTimes_ = 1 }); + cmd->UpdateOption({.tryTimes_ = 1}); Recv(move(cmd)); } else { LOGE("Exceeded the maximum number of retries, not retry"); diff --git a/utils/system/include/utils_actor.h b/utils/system/include/utils_actor.h index 20741d264..35a902a2a 100644 --- a/utils/system/include/utils_actor.h +++ b/utils/system/include/utils_actor.h @@ -65,8 +65,8 @@ public: protected: ThreadSafeQueue> pendingCmds_; - Ctx *ctx_ { nullptr }; - uint32_t retryTimes_ { 1 }; + Ctx *ctx_ {nullptr}; + uint32_t retryTimes_ {1}; std::thread loop_; std::list> retryTasks; diff --git a/utils/system/include/utils_cmd.h b/utils/system/include/utils_cmd.h index f47a93566..f45ddd7d1 100644 --- a/utils/system/include/utils_cmd.h +++ b/utils/system/include/utils_cmd.h @@ -38,7 +38,7 @@ enum class CmdImportance { struct CmdOptions { CmdImportance importance_ { CmdImportance::TRIVIAL }; - uint32_t tryTimes_ { 1 }; + uint32_t tryTimes_ {1}; }; template diff --git a/utils/system/include/utils_dfs_thread.h b/utils/system/include/utils_dfs_thread.h index bd82a549c..4643fec67 100644 --- a/utils/system/include/utils_dfs_thread.h +++ b/utils/system/include/utils_dfs_thread.h @@ -126,9 +126,9 @@ public: } private: - std::atomic_bool running_ { false }; + std::atomic_bool running_ {false}; std::mutex threadMutex_ {}; - std::unique_ptr thread_ { nullptr }; + std::unique_ptr thread_ {nullptr}; std::mutex sleepMutex_ {}; std::condition_variable sleepCv_ {}; }; diff --git a/utils/system/include/utils_exception.h b/utils/system/include/utils_exception.h index 97dd6b27f..46fb45290 100644 --- a/utils/system/include/utils_exception.h +++ b/utils/system/include/utils_exception.h @@ -49,7 +49,7 @@ public: } private: - int code_ { ERR_DEFAULT }; + int code_ {ERR_DEFAULT}; std::string msg_; }; diff --git a/utils/system/include/utils_thread_safe_queue.h b/utils/system/include/utils_thread_safe_queue.h index 0c42f99cc..11a06347d 100644 --- a/utils/system/include/utils_thread_safe_queue.h +++ b/utils/system/include/utils_thread_safe_queue.h @@ -92,7 +92,7 @@ private: std::mutex mutex_; std::condition_variable cv_; - bool halted { false }; + bool halted {false}; }; } // namespace DistributedFile } // namespace Storage -- Gitee From 4ed012c265281a5c248b78d366526e1feba7d87b Mon Sep 17 00:00:00 2001 From: flemingYu Date: Tue, 22 Feb 2022 10:11:56 +0800 Subject: [PATCH 6/6] code check Signed-off-by: flemingYu --- .../src/network/kernel_talker.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/services/distributedfiledaemon/src/network/kernel_talker.cpp b/services/distributedfiledaemon/src/network/kernel_talker.cpp index 1c6bab090..7e64a30fb 100644 --- a/services/distributedfiledaemon/src/network/kernel_talker.cpp +++ b/services/distributedfiledaemon/src/network/kernel_talker.cpp @@ -50,7 +50,7 @@ struct OfflineParam { uint8_t remoteCid[CID_MAX_LEN]; } __attribute__((packed)); -enum class CmdCode : int32_t { +enum CmdCode { CMD_UPDATE_SOCKET = 0, CMD_UPDATE_DEVSL, CMD_OFF_LINE, @@ -58,12 +58,12 @@ enum class CmdCode : int32_t { CMD_CNT, }; -enum class SocketStat : uint8_t { +enum SocketStat { SOCKET_STAT_ACCEPT = 0, SOCKET_STAT_OPEN, }; -enum class Notify : int32_t { +enum Notify { NOTIFY_GET_SESSION = 0, NOTIFY_OFFLINE, NOTIFY_NONE, @@ -78,13 +78,13 @@ void KernelTalker::SinkSessionTokernel(shared_ptr session) LOGD("sink session to kernel success, cid:%{public}s, socketFd:%{public}d, key[0]:%{public}x", cid.c_str(), socketFd, *(uint32_t *)masterkey.data()); - SocketStat status = (session->IsFromServer() ? SocketStat::SOCKET_STAT_ACCEPT : SocketStat::SOCKET_STAT_OPEN); + uint8_t status = (session->IsFromServer() ? SOCKET_STAT_ACCEPT : SOCKET_STAT_OPEN); UpdateSocketParam cmd = { - .cmd = static_cast(CmdCode::CMD_UPDATE_SOCKET), + .cmd = CMD_UPDATE_SOCKET, .newfd = socketFd, .devsl = 3, - .status = static_cast(status), + .status = status, }; if (memcpy_s(cmd.masterKey, KEY_MAX_LEN, masterkey.data(), KEY_MAX_LEN) != EOK) { return; @@ -100,7 +100,7 @@ void KernelTalker::SinkDevslTokernel(const std::string &cid, uint32_t devsl) { LOGD("sink dsl to kernel success, cid:%{public}s, devsl:%{public}d", cid.c_str(), devsl); UpdateDevslParam cmd = { - .cmd = static_cast(CmdCode::CMD_UPDATE_DEVSL), + .cmd = CMD_UPDATE_DEVSL, .devsl = devsl, }; @@ -113,7 +113,7 @@ void KernelTalker::SinkDevslTokernel(const std::string &cid, uint32_t devsl) void KernelTalker::SinkOfflineCmdToKernel(string cid) { OfflineParam cmd = { - .cmd = static_cast(CmdCode::CMD_OFF_LINE), + .cmd = CMD_OFF_LINE, }; if (cid.length() < CID_MAX_LEN) { @@ -204,9 +204,9 @@ void KernelTalker::HandleAllNotify(int fd) while (isRunning_) { lseek(fd, 0, SEEK_SET); - param.notify = static_cast(Notify::NOTIFY_NONE); + param.notify = NOTIFY_NONE; int readSize = read(fd, ¶m, sizeof(NotifyParam)); - if ((readSize < (int)sizeof(NotifyParam)) || (param.notify == static_cast(Notify::NOTIFY_NONE))) { + if ((readSize < (int)sizeof(NotifyParam)) || (param.notify == NOTIFY_NONE)) { return; } NotifyHandler(param); @@ -218,10 +218,10 @@ void KernelTalker::NotifyHandler(NotifyParam ¶m) int cmd = param.notify; string cidStr(param.remoteCid, CID_MAX_LEN); switch (cmd) { - case static_cast(Notify::NOTIFY_GET_SESSION): + case NOTIFY_GET_SESSION: GetSessionCallback_(param); break; - case static_cast(Notify::NOTIFY_OFFLINE): + case NOTIFY_OFFLINE: LOGI("NOTIFY_OFFLINE, remote cid %{public}s", cidStr.c_str()); CloseSessionCallback_(cidStr); break; -- Gitee