From ef43819d73629a2e02bfe2d62c96366888cad5c4 Mon Sep 17 00:00:00 2001 From: buzhenwang Date: Sat, 4 May 2024 11:02:51 +0800 Subject: [PATCH] clean code Signed-off-by: buzhenwang --- frameworks/libhilog/base/hilog_base.c | 2 +- frameworks/libhilog/include/hilog_base.h | 2 +- frameworks/libhilog/include/hilog_cmd.h | 2 +- frameworks/libhilog/include/hilog_common.h | 4 ++-- frameworks/libhilog/param/properties.cpp | 21 +++++++++---------- .../socket/hilog_input_socket_client.cpp | 2 +- frameworks/libhilog/utils/log_utils.cpp | 4 ++-- .../js/kits/napi/src/common/napi/util.h | 3 ++- services/hilogd/include/log_data.h | 8 +++---- services/hilogd/include/log_msg_wrapper.h | 2 +- services/hilogd/kmsg_parser.cpp | 2 +- services/hilogd/log_buffer.cpp | 12 +++++------ services/hilogd/log_collector.cpp | 4 ++-- services/hilogd/service_controller.cpp | 12 +++++------ 14 files changed, 40 insertions(+), 40 deletions(-) diff --git a/frameworks/libhilog/base/hilog_base.c b/frameworks/libhilog/base/hilog_base.c index 7e344f6..b6f8f52 100644 --- a/frameworks/libhilog/base/hilog_base.c +++ b/frameworks/libhilog/base/hilog_base.c @@ -61,7 +61,7 @@ static int SendMessage(HilogMsg *header, const char *tag, uint16_t tagLen, const header->tv_nsec = (uint32_t)(ts.tv_nsec); header->mono_sec = (uint32_t)(ts_mono.tv_sec); header->len = sizeof(HilogMsg) + tagLen + fmtLen; - header->tag_len = tagLen; + header->tagLen = tagLen; struct iovec vec[LOG_LEN] = {0}; vec[0].iov_base = header; // 0 : index of hos log header diff --git a/frameworks/libhilog/include/hilog_base.h b/frameworks/libhilog/include/hilog_base.h index c3ac339..58757fd 100644 --- a/frameworks/libhilog/include/hilog_base.h +++ b/frameworks/libhilog/include/hilog_base.h @@ -33,7 +33,7 @@ typedef struct __attribute__((__packed__)) { uint16_t version : 3; uint16_t type : 4; /* APP,CORE,INIT,SEC etc */ uint16_t level : 3; - uint16_t tag_len : 6; /* include '\0' */ + uint16_t tagLen : 6; /* include '\0' */ uint32_t tv_sec; uint32_t tv_nsec; uint32_t mono_sec; diff --git a/frameworks/libhilog/include/hilog_cmd.h b/frameworks/libhilog/include/hilog_cmd.h index 0529251..b1cd3d4 100644 --- a/frameworks/libhilog/include/hilog_cmd.h +++ b/frameworks/libhilog/include/hilog_cmd.h @@ -90,7 +90,7 @@ struct OutputRqst { } __attribute__((__packed__)); struct OutputRsp { - uint16_t len; /* data len, equals tag_len plus content length, include '\0' */ + uint16_t len; /* data len, equals tagLen plus content length, include '\0' */ uint8_t level; uint8_t type; uint32_t pid; diff --git a/frameworks/libhilog/include/hilog_common.h b/frameworks/libhilog/include/hilog_common.h index 4de499b..7993dc6 100644 --- a/frameworks/libhilog/include/hilog_common.h +++ b/frameworks/libhilog/include/hilog_common.h @@ -53,8 +53,8 @@ using OptRef = std::optional>; template using OptCRef = std::optional>; -#define CONTENT_LEN(pMsg) ((pMsg)->len - sizeof(HilogMsg) - (pMsg)->tag_len) /* include '\0' */ -#define CONTENT_PTR(pMsg) ((pMsg)->tag + (pMsg)->tag_len) +#define CONTENT_LEN(pMsg) ((pMsg)->len - sizeof(HilogMsg) - (pMsg)->tagLen) /* include '\0' */ +#define CONTENT_PTR(pMsg) ((pMsg)->tag + (pMsg)->tagLen) #define likely(x) __builtin_expect(!!(x), 1) #define unlikely(x) __builtin_expect(!!(x), 0) diff --git a/frameworks/libhilog/param/properties.cpp b/frameworks/libhilog/param/properties.cpp index ac4713e..725924c 100644 --- a/frameworks/libhilog/param/properties.cpp +++ b/frameworks/libhilog/param/properties.cpp @@ -65,7 +65,8 @@ enum class PropType { using ReadLock = shared_lock; using InsertLock = unique_lock; -static const int HILOG_PROP_VALUE_MAX = 92; +static constexpr int HILOG_PROP_VALUE_MAX = 92; +static constexpr int DEFAULT_QUOTA = 51200; static int LockByProp(PropType propType); static void UnlockByProp(PropType propType); @@ -83,7 +84,7 @@ using PropRes = struct { string name; pthread_mutex_t* lock; }; -static PropRes g_PropResources[static_cast(PropType::PROP_MAX)] = { +static PropRes g_propResources[static_cast(PropType::PROP_MAX)] = { // Cached: {"hilog.private.on", &g_privateLock}, // PROP_PRIVATE {"hilog.debug.on", &g_onceDebugLock}, // PROP_ONCE_DEBUG @@ -105,23 +106,23 @@ static PropRes g_PropResources[static_cast(PropType::PROP_MAX)] = { static string GetPropertyName(PropType propType) { - return g_PropResources[static_cast(propType)].name; + return g_propResources[static_cast(propType)].name; } static int LockByProp(PropType propType) { - if (g_PropResources[static_cast(propType)].lock == nullptr) { + if (g_propResources[static_cast(propType)].lock == nullptr) { return -1; } - return pthread_mutex_trylock(g_PropResources[static_cast(propType)].lock); + return pthread_mutex_trylock(g_propResources[static_cast(propType)].lock); } static void UnlockByProp(PropType propType) { - if (g_PropResources[static_cast(propType)].lock == nullptr) { + if (g_propResources[static_cast(propType)].lock == nullptr) { return; } - pthread_mutex_unlock(g_PropResources[static_cast(propType)].lock); + pthread_mutex_unlock(g_propResources[static_cast(propType)].lock); return; } @@ -469,26 +470,24 @@ bool IsTagStatsEnable() int GetProcessQuota(const string& proc) { - static constexpr int default_quota = 51200; char value[HILOG_PROP_VALUE_MAX] = {0}; string prop = GetPropertyName(PropType::PROP_PROC_QUOTA) + proc; int ret = PropertyGet(prop, value, HILOG_PROP_VALUE_MAX); if (ret == RET_FAIL || value[0] == 0) { - return default_quota; + return DEFAULT_QUOTA; } return std::stoi(value); } int GetDomainQuota(uint32_t domain) { - static constexpr int default_quota = 51200; char value[HILOG_PROP_VALUE_MAX] = {0}; string prop = GetPropertyName(PropType::PROP_DOMAIN_QUOTA) + Uint2HexStr(domain); int ret = PropertyGet(prop, value, HILOG_PROP_VALUE_MAX); if (ret == RET_FAIL || value[0] == 0) { - return default_quota; + return DEFAULT_QUOTA; } return std::stoi(value); } diff --git a/frameworks/libhilog/socket/hilog_input_socket_client.cpp b/frameworks/libhilog/socket/hilog_input_socket_client.cpp index e901023..e0e700b 100644 --- a/frameworks/libhilog/socket/hilog_input_socket_client.cpp +++ b/frameworks/libhilog/socket/hilog_input_socket_client.cpp @@ -37,7 +37,7 @@ int HilogInputSocketClient::WriteLogMessage(HilogMsg *header, const char *tag, u } header->len = sizeof(HilogMsg) + tagLen + fmtLen; - header->tag_len = tagLen; + header->tagLen = tagLen; iovec vec[3]; vec[0].iov_base = header; // 0 : index of hos log header diff --git a/frameworks/libhilog/utils/log_utils.cpp b/frameworks/libhilog/utils/log_utils.cpp index 7cef847..0b5b3c1 100644 --- a/frameworks/libhilog/utils/log_utils.cpp +++ b/frameworks/libhilog/utils/log_utils.cpp @@ -477,8 +477,8 @@ uint32_t GetPPidByPid(uint32_t pid) uint64_t GenerateHash(const char *p, size_t size) { - static const uint64_t PRIME = 0x100000001B3ull; - static const uint64_t BASIS = 0xCBF29CE484222325ull; + static const uint64_t PRIME = 0x100000001B3ULL; + static const uint64_t BASIS = 0xCBF29CE484222325ULL; uint64_t ret {BASIS}; unsigned long i = 0; while (i < size) { diff --git a/interfaces/js/kits/napi/src/common/napi/util.h b/interfaces/js/kits/napi/src/common/napi/util.h index f103410..c2a2010 100644 --- a/interfaces/js/kits/napi/src/common/napi/util.h +++ b/interfaces/js/kits/napi/src/common/napi/util.h @@ -110,7 +110,8 @@ template , typename ReturnT = typename Traits::result_type> -ReturnT do_call(FuncType& func, VecType& args, indices) { +ReturnT do_call(FuncType& func, VecType& args, indices) +{ return func(args[I]...); } } // namespace details diff --git a/services/hilogd/include/log_data.h b/services/hilogd/include/log_data.h index c3fa3f3..88ebbf0 100644 --- a/services/hilogd/include/log_data.h +++ b/services/hilogd/include/log_data.h @@ -30,7 +30,7 @@ struct HilogData { uint16_t version : 3; uint16_t type : 3; /* APP,CORE,INIT,SEC etc */ uint16_t level : 4; - uint16_t tag_len : 6; /* include '\0' */ + uint16_t tagLen : 6; /* include '\0' */ uint32_t tv_sec; uint32_t tv_nsec; uint32_t mono_sec; @@ -67,11 +67,11 @@ struct HilogData { } HilogData() : len(0), tag(nullptr), content(nullptr) {} explicit HilogData(const HilogMsg& msg) - : len(0), version(msg.version), type(msg.type), level(msg.level), tag_len(msg.tag_len), + : len(0), version(msg.version), type(msg.type), level(msg.level), tagLen(msg.tagLen), tv_sec(msg.tv_sec), tv_nsec(msg.tv_nsec), mono_sec(msg.mono_sec), pid(msg.pid), tid(msg.tid), domain(msg.domain), tag(nullptr), content(nullptr) { - init(msg.tag, msg.tag_len, CONTENT_PTR((&msg)), CONTENT_LEN((&msg))); + init(msg.tag, msg.tagLen, CONTENT_PTR((&msg)), CONTENT_LEN((&msg))); } HilogData(const HilogData& copy) { @@ -85,7 +85,7 @@ struct HilogData { if (unlikely(memcpy_s(tag, len, copy.tag, len) != 0)) { return; } - content = tag + tag_len; + content = tag + tagLen; } HilogData& operator=(const HilogData&) = delete; HilogData(HilogData&&) = delete; diff --git a/services/hilogd/include/log_msg_wrapper.h b/services/hilogd/include/log_msg_wrapper.h index de4a7b0..14220fa 100644 --- a/services/hilogd/include/log_msg_wrapper.h +++ b/services/hilogd/include/log_msg_wrapper.h @@ -38,7 +38,7 @@ public: return *reinterpret_cast(msgBuffer.data()); } - const std::vector & GetRawData() const + const std::vector& GetRawData() const { return msgBuffer; } diff --git a/services/hilogd/kmsg_parser.cpp b/services/hilogd/kmsg_parser.cpp index f219b7d..8417b00 100644 --- a/services/hilogd/kmsg_parser.cpp +++ b/services/hilogd/kmsg_parser.cpp @@ -90,7 +90,7 @@ std::optional KmsgParser::ParseKmsg(const std::vector& km HilogMsgWrapper msgWrap((std::vector(msgLen, '\0'))); HilogMsg& msg = msgWrap.GetHilogMsg(); msg.len = msgLen; - msg.tag_len = tagLen + 1; + msg.tagLen = tagLen + 1; msg.type = LOG_KMSG; msg.level = KmsgLevelMap(LOG_INFO); struct timespec ts = {0}; diff --git a/services/hilogd/log_buffer.cpp b/services/hilogd/log_buffer.cpp index 788949d..4cf50dd 100644 --- a/services/hilogd/log_buffer.cpp +++ b/services/hilogd/log_buffer.cpp @@ -82,7 +82,7 @@ HilogBuffer::~HilogBuffer() {} size_t HilogBuffer::Insert(const HilogMsg& msg, bool& isFull) { size_t elemSize = CONTENT_LEN((&msg)); /* include '\0' */ - if (unlikely(msg.tag_len > MAX_TAG_LEN || msg.tag_len == 0 || elemSize > MAX_LOG_LEN || + if (unlikely(msg.tagLen > MAX_TAG_LEN || msg.tagLen == 0 || elemSize > MAX_LOG_LEN || elemSize == 0 || msg.type >= LOG_TYPE_MAX)) { return 0; } @@ -108,7 +108,7 @@ size_t HilogBuffer::Insert(const HilogMsg& msg, bool& isFull) } OnDeleteItem(it, DeleteReason::BUFF_OVERFLOW); - size_t cLen = it->len - it->tag_len; + size_t cLen = it->len - it->tagLen; sizeByType[(*it).type] -= cLen; it = hilogDataList.erase(it); } @@ -282,7 +282,7 @@ int32_t HilogBuffer::Delete(uint16_t logType) // Delete corresponding logs OnDeleteItem(it, DeleteReason::CMD_CLEAR); - size_t cLen = it->len - it->tag_len; + size_t cLen = it->len - it->tagLen; sum += cLen; sizeByType[(*it).type] -= cLen; it = hilogDataList.erase(it); @@ -426,11 +426,11 @@ static int GenerateHilogMsgInside(HilogMsg& hilogMsg, const string& msg, uint16_ hilogMsg.pid = 0; hilogMsg.tid = 0; hilogMsg.domain = 0; - hilogMsg.tag_len = tag.length() + 1; - if (memcpy_s(hilogMsg.tag, contentLen, tag.c_str(), hilogMsg.tag_len) != 0) { + hilogMsg.tagLen = tag.length() + 1; + if (memcpy_s(hilogMsg.tag, contentLen, tag.c_str(), hilogMsg.tagLen) != 0) { return RET_FAIL; } - if (memcpy_s(hilogMsg.tag + hilogMsg.tag_len, contentLen - hilogMsg.tag_len, msg.c_str(), msg.length() + 1) != 0) { + if (memcpy_s(hilogMsg.tag + hilogMsg.tagLen, contentLen - hilogMsg.tagLen, msg.c_str(), msg.length() + 1) != 0) { return RET_FAIL; } diff --git a/services/hilogd/log_collector.cpp b/services/hilogd/log_collector.cpp index 26969c6..09f48a8 100644 --- a/services/hilogd/log_collector.cpp +++ b/services/hilogd/log_collector.cpp @@ -41,7 +41,7 @@ void LogCollector::InsertDropInfo(const HilogMsg &msg, int droppedCount) dropMsg->version = msg.version; dropMsg->type = msg.type; dropMsg->level = msg.level; - dropMsg->tag_len = tag.size(); + dropMsg->tagLen = tag.size(); dropMsg->tv_sec = msg.tv_sec; dropMsg->tv_nsec = msg.tv_nsec; dropMsg->mono_sec = msg.mono_sec; @@ -106,7 +106,7 @@ void LogCollector::onDataRecv(const ucred& cred, std::vector& data, int da // Log statistics if (countEnable) { - if (*(msg.tag + msg.tag_len - 1) != '\0') { + if (*(msg.tag + msg.tagLen - 1) != '\0') { return; } StatsInfo info = { diff --git a/services/hilogd/service_controller.cpp b/services/hilogd/service_controller.cpp index e79401f..8c853b9 100644 --- a/services/hilogd/service_controller.cpp +++ b/services/hilogd/service_controller.cpp @@ -67,10 +67,10 @@ inline bool IsKmsg(uint16_t types) ServiceController::ServiceController(std::unique_ptr communicationSocket, LogCollector& collector, HilogBuffer& hilogBuffer, HilogBuffer& kmsgBuffer) - : m_communicationSocket(std::move(communicationSocket)) - , m_logCollector(collector) - , m_hilogBuffer(hilogBuffer) - , m_kmsgBuffer(kmsgBuffer) + : m_communicationSocket(std::move(communicationSocket)), + m_logCollector(collector), + m_hilogBuffer(hilogBuffer), + m_kmsgBuffer(kmsgBuffer) { m_hilogBufferReader = m_hilogBuffer.CreateBufReader([this]() { NotifyForNewData(); }); m_kmsgBufferReader = m_kmsgBuffer.CreateBufReader([this]() { NotifyForNewData(); }); @@ -141,10 +141,10 @@ int ServiceController::WriteQueryResponse(OptCRef pData) return m_communicationSocket->Write(reinterpret_cast(&rsp), sizeof(rsp)); } const HilogData& data = pData->get(); - rsp.len = data.len; /* data len, equals tag_len plus content length, include '\0' */ + rsp.len = data.len; /* data len, equals tagLen plus content length, include '\0' */ rsp.level = data.level; rsp.type = data.type; - rsp.tagLen = data.tag_len; /* include '\0' */ + rsp.tagLen = data.tagLen; /* include '\0' */ rsp.pid = data.pid; rsp.tid = data.tid; rsp.domain = data.domain; -- Gitee