已合并
style: 修复adcore pre-commit告警 #4034
style: 修复adcore pre-commit告警 #4034
已合并
fujun19创建于 8月4日
56 个文件变更+813-873
@@ -41,7 +41,7 @@ repos:
41 )41 )
42 | scripts42 | scripts
43 | src/(43 | src/(
44- dfx/adump44+ dfx/adump(?!(?:/adcore)(?:/|$))
45 | dfx/log45 | dfx/log
46 | dfx/msprof46 | dfx/msprof
47 | dfx/trace47 | dfx/trace
@@ -26,8 +26,8 @@ constexpr int32_t TIME_ONE_THOUSAND = 1000;
26 * @param [in] : timeout 0 : wait_always, > 0 wait_timeout, < 0 wait_default; unit: ms26 * @param [in] : timeout 0 : wait_always, > 0 wait_timeout, < 0 wait_default; unit: ms
27 * @return : IDE_DAEMON_OK succeed; others failed27 * @return : IDE_DAEMON_OK succeed; others failed
28 */28 */
29-static int32_t ReadSettingResult(const HDC_SESSION session, const AdxStringBuffer resultBuf, uint32_t resultLen,29+static int32_t ReadSettingResult(
30- int32_t timeout)30+ const HDC_SESSION session, const AdxStringBuffer resultBuf, uint32_t resultLen, int32_t timeout)
31{31{
32 int32_t err = IDE_DAEMON_ERROR;32 int32_t err = IDE_DAEMON_ERROR;
33 if ((session == nullptr) || (resultBuf == nullptr)) {33 if ((session == nullptr) || (resultBuf == nullptr)) {
@@ -60,11 +60,11 @@ static int32_t ReadSettingResult(const HDC_SESSION session, const AdxStringBuffe
60 return err;60 return err;
61}61}
62 62 
63-static int32_t AdxSendMsgToServerByType(AdxHdcServiceType type, IdeTlvConReq req, const AdxStringBuffer result,63+static int32_t AdxSendMsgToServerByType(
64- uint32_t resultLen, int32_t timeout = -1)64+ AdxHdcServiceType type, IdeTlvConReq req, const AdxStringBuffer result, uint32_t resultLen, int32_t timeout = -1)
65{65{
66 int32_t err = IDE_DAEMON_ERROR;66 int32_t err = IDE_DAEMON_ERROR;
67- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(OptType::COMM_HDC));67+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(OptType::COMM_HDC));
68 IDE_CTRL_VALUE_FAILED(opt != nullptr, return err, "create hdc commopt exception");68 IDE_CTRL_VALUE_FAILED(opt != nullptr, return err, "create hdc commopt exception");
69 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);69 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);
70 IDE_CTRL_VALUE_FAILED(ret, return err, "register hdc failed");70 IDE_CTRL_VALUE_FAILED(ret, return err, "register hdc failed");
@@ -84,8 +84,8 @@ static int32_t AdxSendMsgToServerByType(AdxHdcServiceType type, IdeTlvConReq req
84 }84 }
85 85 
86 CommHandle handle{COMM_HDC, reinterpret_cast<OptHandle>(session), NR_COMPONENTS, -1, nullptr};86 CommHandle handle{COMM_HDC, reinterpret_cast<OptHandle>(session), NR_COMPONENTS, -1, nullptr};
87- err = Adx::AdxMsgProto::SendMsgData(handle, req->type, MsgStatus::MSG_STATUS_NONE_ERROR,87+ err = Adx::AdxMsgProto::SendMsgData(
88- static_cast<IdeSendBuffT>(req->value), req->len);88+ handle, req->type, MsgStatus::MSG_STATUS_NONE_ERROR, static_cast<IdeSendBuffT>(req->value), req->len);
89 if (err != EN_OK) {89 if (err != EN_OK) {
90 IDE_LOGE("Write level info to device failed by hdc, result=%d.", err);90 IDE_LOGE("Write level info to device failed by hdc, result=%d.", err);
91 } else if (result != nullptr) {91 } else if (result != nullptr) {
@@ -97,8 +97,8 @@ static int32_t AdxSendMsgToServerByType(AdxHdcServiceType type, IdeTlvConReq req
97 return err;97 return err;
98}98}
99 99 
100-int32_t AdxSendMsgAndGetResultByType(AdxHdcServiceType type, IdeTlvConReq req, const AdxStringBuffer result,100+int32_t AdxSendMsgAndGetResultByType(
101- uint32_t resultLen)101+ AdxHdcServiceType type, IdeTlvConReq req, const AdxStringBuffer result, uint32_t resultLen)
102{102{
103 if ((req == nullptr) || (result == nullptr)) {103 if ((req == nullptr) || (result == nullptr)) {
104 return IDE_DAEMON_ERROR;104 return IDE_DAEMON_ERROR;
@@ -120,17 +120,20 @@ int32_t AdxSendMsgByHandle(AdxCommConHandle handle, CmdClassT type, AdxString da
120 return IDE_DAEMON_ERROR;120 return IDE_DAEMON_ERROR;
121 }121 }
122 122 
123- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(handle->type));123+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(handle->type));
124 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");124 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");
125 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);125 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);
126 IDE_CTRL_VALUE_FAILED(ret, return IDE_DAEMON_ERROR, "register hdc failed");126 IDE_CTRL_VALUE_FAILED(ret, return IDE_DAEMON_ERROR, "register hdc failed");
127 127 
128- return (Adx::AdxMsgProto::SendMsgData(*handle, type, MsgStatus::MSG_STATUS_NONE_ERROR,128+ return (Adx::AdxMsgProto::SendMsgData(
129- static_cast<IdeSendBuffT>(data), len) == IDE_DAEMON_NONE_ERROR) ? IDE_DAEMON_OK : IDE_DAEMON_ERROR;129+ *handle, type, MsgStatus::MSG_STATUS_NONE_ERROR, static_cast<IdeSendBuffT>(data), len) ==
130+ IDE_DAEMON_NONE_ERROR) ?
131+ IDE_DAEMON_OK :
132+ IDE_DAEMON_ERROR;
130}133}
131 134 
132-int32_t AdxSendFileByHandle(AdxCommConHandle handle, CmdClassT type, AdxString srcPath, AdxString desPath,135+int32_t AdxSendFileByHandle(
133- SendFileType flag)136+ AdxCommConHandle handle, CmdClassT type, AdxString srcPath, AdxString desPath, SendFileType flag)
134{137{
135 if ((handle == nullptr) || (srcPath == nullptr) || (desPath == nullptr)) {138 if ((handle == nullptr) || (srcPath == nullptr) || (desPath == nullptr)) {
136 return IDE_DAEMON_ERROR;139 return IDE_DAEMON_ERROR;
@@ -140,7 +143,7 @@ int32_t AdxSendFileByHandle(AdxCommConHandle handle, CmdClassT type, AdxString s
140 return IDE_DAEMON_ERROR;143 return IDE_DAEMON_ERROR;
141 }144 }
142 145 
143- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(handle->type));146+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(handle->type));
144 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");147 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");
145 bool err = AdxCommOptManager::Instance().CommOptsRegister(opt);148 bool err = AdxCommOptManager::Instance().CommOptsRegister(opt);
146 IDE_CTRL_VALUE_FAILED(err, return IDE_DAEMON_ERROR, "register hdc failed");149 IDE_CTRL_VALUE_FAILED(err, return IDE_DAEMON_ERROR, "register hdc failed");
@@ -148,14 +151,15 @@ int32_t AdxSendFileByHandle(AdxCommConHandle handle, CmdClassT type, AdxString s
148 int32_t fd = mmOpen2(srcPath, M_RDONLY | M_BINARY, S_IREAD);151 int32_t fd = mmOpen2(srcPath, M_RDONLY | M_BINARY, S_IREAD);
149 if (fd < 0) {152 if (fd < 0) {
150 char errBuf[MAX_ERRSTR_LEN + 1] = {0};153 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
151- IDE_LOGE("open send file failed, info : %s, open file is %s",154+ IDE_LOGE(
155+ "open send file failed, info : %s, open file is %s",
152 mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN), srcPath);156 mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN), srcPath);
153 return IDE_DAEMON_ERROR;157 return IDE_DAEMON_ERROR;
154 }158 }
155 159 
156 // send file name160 // send file name
157- int32_t ret = Adx::AdxMsgProto::SendMsgData(*handle, type, MsgStatus::MSG_STATUS_NONE_ERROR,161+ int32_t ret = Adx::AdxMsgProto::SendMsgData(
158- static_cast<IdeSendBuffT>(desPath), strlen(desPath) + 1U);162+ *handle, type, MsgStatus::MSG_STATUS_NONE_ERROR, static_cast<IdeSendBuffT>(desPath), strlen(desPath) + 1U);
159 if (ret != IDE_DAEMON_NONE_ERROR) {163 if (ret != IDE_DAEMON_NONE_ERROR) {
160 if (fd >= 0) {164 if (fd >= 0) {
161 mmClose(fd);165 mmClose(fd);
@@ -207,7 +211,7 @@ static CmdClassT GetReqTypeByComponentType(ComponentType cmptType)
207 * @param [out] : value attribute value211 * @param [out] : value attribute value
208 * @return : IDE_DAEMON_OK succeed; IDE_DAEMON_ERROR failed212 * @return : IDE_DAEMON_OK succeed; IDE_DAEMON_ERROR failed
209 */213 */
210-int32_t AdxGetAttrByCommHandle(AdxCommConHandle handle, int32_t attr, int32_t *value)214+int32_t AdxGetAttrByCommHandle(AdxCommConHandle handle, int32_t attr, int32_t* value)
211{215{
212 if (handle == nullptr || value == nullptr) {216 if (handle == nullptr || value == nullptr) {
213 IDE_LOGE("get attribute failed, invalid input");217 IDE_LOGE("get attribute failed, invalid input");
@@ -225,7 +229,7 @@ int32_t AdxGetAttrByCommHandle(AdxCommConHandle handle, int32_t attr, int32_t *v
225 */229 */
226AdxCommHandle AdxCreateCommHandle(AdxHdcServiceType type, int32_t devId, ComponentType compType)230AdxCommHandle AdxCreateCommHandle(AdxHdcServiceType type, int32_t devId, ComponentType compType)
227{231{
228- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(OptType::COMM_HDC));232+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(OptType::COMM_HDC));
229 IDE_CTRL_VALUE_FAILED(opt != nullptr, return nullptr, "create hdc commopt exception");233 IDE_CTRL_VALUE_FAILED(opt != nullptr, return nullptr, "create hdc commopt exception");
230 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);234 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);
231 IDE_CTRL_VALUE_FAILED(ret, return nullptr, "register hdc failed");235 IDE_CTRL_VALUE_FAILED(ret, return nullptr, "register hdc failed");
@@ -250,7 +254,8 @@ AdxCommHandle AdxCreateCommHandle(AdxHdcServiceType type, int32_t devId, Compone
250 handle->timeout = 0;254 handle->timeout = 0;
251 255 
252 const std::string defaultMessage = "LONG_LINK_DEFAULT";256 const std::string defaultMessage = "LONG_LINK_DEFAULT";
253- err = Adx::AdxMsgProto::SendMsgData(*handle, GetReqTypeByComponentType(compType), MsgStatus::MSG_STATUS_LONG_LINK,257+ err = Adx::AdxMsgProto::SendMsgData(
258+ *handle, GetReqTypeByComponentType(compType), MsgStatus::MSG_STATUS_LONG_LINK,
254 static_cast<IdeSendBuffT>(defaultMessage.c_str()), defaultMessage.size());259 static_cast<IdeSendBuffT>(defaultMessage.c_str()), defaultMessage.size());
255 if (err != IDE_DAEMON_OK) {260 if (err != IDE_DAEMON_OK) {
256 IDE_LOGE("Write default info to device failed by hdc, result=%d.", err);261 IDE_LOGE("Write default info to device failed by hdc, result=%d.", err);
@@ -307,14 +312,16 @@ int32_t AdxSendMsg(AdxCommConHandle handle, AdxString data, uint32_t len)
307 return IDE_DAEMON_ERROR;312 return IDE_DAEMON_ERROR;
308 }313 }
309 314 
310- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(handle->type));315+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(handle->type));
311 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");316 IDE_CTRL_VALUE_FAILED(opt != nullptr, return IDE_DAEMON_ERROR, "create hdc commopt exception");
312 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);317 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);
313 IDE_CTRL_VALUE_FAILED(ret, return IDE_DAEMON_ERROR, "register hdc failed");318 IDE_CTRL_VALUE_FAILED(ret, return IDE_DAEMON_ERROR, "register hdc failed");
314 319 
315- return (Adx::AdxMsgProto::SendMsgData(*handle, GetReqTypeByComponentType(handle->comp),320+ return (Adx::AdxMsgProto::SendMsgData(
316- MsgStatus::MSG_STATUS_NONE_ERROR, static_cast<IdeSendBuffT>(data), len) ==321+ *handle, GetReqTypeByComponentType(handle->comp), MsgStatus::MSG_STATUS_NONE_ERROR,
317- IDE_DAEMON_NONE_ERROR) ? IDE_DAEMON_OK : IDE_DAEMON_ERROR;322+ static_cast<IdeSendBuffT>(data), len) == IDE_DAEMON_NONE_ERROR) ?
323+ IDE_DAEMON_OK :
324+ IDE_DAEMON_ERROR;
318}325}
319 326 
320/**327/**
@@ -325,7 +332,7 @@ int32_t AdxSendMsg(AdxCommConHandle handle, AdxString data, uint32_t len)
325 * @param [in] : timeout max wait time; unit: ms332 * @param [in] : timeout max wait time; unit: ms
326 * @return : IDE_DAEMON_OK succeed; others failed333 * @return : IDE_DAEMON_OK succeed; others failed
327 */334 */
328-int32_t AdxRecvMsg(AdxCommHandle handle, IdeStrBufAddrT data, uint32_t *len, uint32_t timeout)335+int32_t AdxRecvMsg(AdxCommHandle handle, IdeStrBufAddrT data, uint32_t* len, uint32_t timeout)
329{336{
330 int32_t err = IDE_DAEMON_ERROR;337 int32_t err = IDE_DAEMON_ERROR;
331 if (len == nullptr) {338 if (len == nullptr) {
@@ -364,8 +371,8 @@ int32_t AdxRecvMsg(AdxCommHandle handle, IdeStrBufAddrT data, uint32_t *len, uin
364 return err;371 return err;
365}372}
366 373 
367-static int32_t AdxServerCommProcess(AdxHdcServiceType type, AdxTlvConReq req, AdxStringBuffer result, uint32_t length,374+static int32_t AdxServerCommProcess(
368- uint32_t timeout)375+ AdxHdcServiceType type, AdxTlvConReq req, AdxStringBuffer result, uint32_t length, uint32_t timeout)
369{376{
370 if (req == nullptr) {377 if (req == nullptr) {
371 IDE_LOGE("invalid input, tlv struct is null");378 IDE_LOGE("invalid input, tlv struct is null");
@@ -395,11 +402,13 @@ static int32_t AdxServerCommProcess(AdxHdcServiceType type, AdxTlvConReq req, Ad
395 return IDE_DAEMON_ERROR;402 return IDE_DAEMON_ERROR;
396 }403 }
397 if (result == nullptr) {404 if (result == nullptr) {
398- IDE_LOGI("AdxDevCommShortLink, no results needed, cmpt=%d, cmd=%d, devId=%d",405+ IDE_LOGI(
399- static_cast<int32_t>(req->type), static_cast<int32_t>(ide->type), ide->dev_id);406+ "AdxDevCommShortLink, no results needed, cmpt=%d, cmd=%d, devId=%d", static_cast<int32_t>(req->type),
407+ static_cast<int32_t>(ide->type), ide->dev_id);
400 ret = AdxSendMsgAndNoResultByType(type, ide);408 ret = AdxSendMsgAndNoResultByType(type, ide);
401 } else {409 } else {
402- IDE_LOGI("AdxDevCommShortLink, result wait timeout:%u, cmpt=%d, cmd=%d, devId=%d", timeout,410+ IDE_LOGI(
411+ "AdxDevCommShortLink, result wait timeout:%u, cmpt=%d, cmd=%d, devId=%d", timeout,
403 static_cast<int32_t>(req->type), static_cast<int32_t>(ide->type), ide->dev_id);412 static_cast<int32_t>(req->type), static_cast<int32_t>(ide->type), ide->dev_id);
404 (void)memset_s(result, length, 0, length);413 (void)memset_s(result, length, 0, length);
405 ret = AdxSendMsgToServerByType(type, ide, result, length, static_cast<int32_t>(timeout));414 ret = AdxSendMsgToServerByType(type, ide, result, length, static_cast<int32_t>(timeout));
@@ -417,8 +426,9 @@ static int32_t AdxServerCommProcess(AdxHdcServiceType type, AdxTlvConReq req, Ad
417 * @param [in] : timeout 0 : wait_always, > 0 wait_timeout; unit: ms426 * @param [in] : timeout 0 : wait_always, > 0 wait_timeout; unit: ms
418 * @return : IDE_DAEMON_OK succeed; others failed427 * @return : IDE_DAEMON_OK succeed; others failed
419 */428 */
420-int32_t AdxDevCommShortLink(AdxHdcServiceType type, AdxTlvConReq req, AdxStringBuffer result, uint32_t length,429+int32_t AdxDevCommShortLink(
421- uint32_t timeout) {430+ AdxHdcServiceType type, AdxTlvConReq req, AdxStringBuffer result, uint32_t length, uint32_t timeout)
431+{
422 int32_t ret = AdxServerCommProcess(type, req, result, length, timeout);432 int32_t ret = AdxServerCommProcess(type, req, result, length, timeout);
423 if ((ret != IDE_DAEMON_OK) && (result != nullptr) && (strlen(result) == 0)) {433 if ((ret != IDE_DAEMON_OK) && (result != nullptr) && (strlen(result) == 0)) {
424 const std::string value = "get result data from server failed";434 const std::string value = "get result data from server failed";
@@ -428,4 +438,4 @@ int32_t AdxDevCommShortLink(AdxHdcServiceType type, AdxTlvConReq req, AdxStringB
428 }438 }
429 }439 }
430 return ret;440 return ret;
431-}441+}
@@ -32,21 +32,19 @@ static constexpr uint32_t DEFAULT_TIMEOUT = 10000; // 10000ms
32 * @param [in] devId : send file device id32 * @param [in] devId : send file device id
33 * @return CommHandle : client handle33 * @return CommHandle : client handle
34 */34 */
35-static CommHandle AdxHdcConnect(CommHandle &client, uint16_t devId,35+static CommHandle AdxHdcConnect(
36- AdxHdcServiceType hdcType = HDC_SERVICE_TYPE_IDE_FILE_TRANS)36+ CommHandle& client, uint16_t devId, AdxHdcServiceType hdcType = HDC_SERVICE_TYPE_IDE_FILE_TRANS)
37{37{
38 std::map<std::string, std::string> info;38 std::map<std::string, std::string> info;
39 info[OPT_DEVICE_KEY] = std::to_string(devId);39 info[OPT_DEVICE_KEY] = std::to_string(devId);
40 info[OPT_SERVICE_KEY] = std::to_string(hdcType);40 info[OPT_SERVICE_KEY] = std::to_string(hdcType);
41 CommHandle session = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};41 CommHandle session = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};
42- std::unique_ptr<AdxCommOpt> opt (CreateAdxCommOpt(OptType::COMM_HDC));42+ std::unique_ptr<AdxCommOpt> opt(CreateAdxCommOpt(OptType::COMM_HDC));
43- IDE_CTRL_VALUE_FAILED(opt != nullptr, return session,43+ IDE_CTRL_VALUE_FAILED(opt != nullptr, return session, "create hdc commopt exception");
44- "create hdc commopt exception");
45 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);44 bool ret = AdxCommOptManager::Instance().CommOptsRegister(opt);
46 IDE_CTRL_VALUE_FAILED(ret, return client, "register hdc failed");45 IDE_CTRL_VALUE_FAILED(ret, return client, "register hdc failed");
47 client = AdxCommOptManager::Instance().OpenClient(OptType::COMM_HDC, info);46 client = AdxCommOptManager::Instance().OpenClient(OptType::COMM_HDC, info);
48- IDE_CTRL_VALUE_FAILED(client.session != ADX_OPT_INVALID_HANDLE, return client,47+ IDE_CTRL_VALUE_FAILED(client.session != ADX_OPT_INVALID_HANDLE, return client, "open client failed");
49- "open client failed");
50 session = AdxCommOptManager::Instance().Connect(client, info);48 session = AdxCommOptManager::Instance().Connect(client, info);
51 if (session.session == ADX_OPT_INVALID_HANDLE) {49 if (session.session == ADX_OPT_INVALID_HANDLE) {
52 (void)AdxCommOptManager::Instance().CloseClient(client);50 (void)AdxCommOptManager::Instance().CloseClient(client);
@@ -60,11 +58,12 @@ static CommHandle AdxHdcConnect(CommHandle &client, uint16_t devId,
60 * @param [in] srcFile : send file source file with path58 * @param [in] srcFile : send file source file with path
61 * @return IDE_DAEMON_OK(0) : send file success, IDE_DAEMON_ERROR(-1) : send file failed59 * @return IDE_DAEMON_OK(0) : send file success, IDE_DAEMON_ERROR(-1) : send file failed
62 */60 */
63-static int32_t AdxCommonGetFile(const CommHandle &handle, const std::string &srcFile)61+static int32_t AdxCommonGetFile(const CommHandle& handle, const std::string& srcFile)
64{62{
65 IDE_CTRL_VALUE_FAILED(!srcFile.empty(), return IDE_DAEMON_ERROR, "source file input invalid");63 IDE_CTRL_VALUE_FAILED(!srcFile.empty(), return IDE_DAEMON_ERROR, "source file input invalid");
66- IDE_CTRL_VALUE_FAILED(FileUtils::CheckNonCrossPath(srcFile), return IDE_DAEMON_ERROR, 64+ IDE_CTRL_VALUE_FAILED(
67- "Cross-path access may exist on the path: %s", srcFile.c_str());65+ FileUtils::CheckNonCrossPath(srcFile), return IDE_DAEMON_ERROR, "Cross-path access may exist on the path: %s",
66+ srcFile.c_str());
68 // create dir if not exist67 // create dir if not exist
69 std::string saveDirName = FileUtils::GetFileDir(srcFile);68 std::string saveDirName = FileUtils::GetFileDir(srcFile);
70 if (!FileUtils::IsFileExist(saveDirName)) {69 if (!FileUtils::IsFileExist(saveDirName)) {
@@ -76,8 +75,9 @@ static int32_t AdxCommonGetFile(const CommHandle &handle, const std::string &src
76 // get file75 // get file
77 int32_t fd = mmOpen2(srcFile.c_str(), M_RDWR | M_CREAT | M_BINARY | M_TRUNC, M_IRUSR | M_IWRITE);76 int32_t fd = mmOpen2(srcFile.c_str(), M_RDWR | M_CREAT | M_BINARY | M_TRUNC, M_IRUSR | M_IWRITE);
78 char errBuf[MAX_ERRSTR_LEN + 1] = {0};77 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
79- IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_ERROR, "open file exception, info : %s",78+ IDE_CTRL_VALUE_FAILED(
80- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));79+ fd >= 0, return IDE_DAEMON_ERROR, "open file exception, info : %s",
80+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
81 81 
82 int32_t err = AdxMsgProto::RecvFile(handle, fd);82 int32_t err = AdxMsgProto::RecvFile(handle, fd);
83 if (err != IDE_DAEMON_NONE_ERROR && err != IDE_DAEMON_CHANNEL_ERROR) {83 if (err != IDE_DAEMON_NONE_ERROR && err != IDE_DAEMON_CHANNEL_ERROR) {
@@ -92,9 +92,9 @@ static int32_t AdxCommonGetFile(const CommHandle &handle, const std::string &src
92 fd = -1;92 fd = -1;
93 93 
94 if (err == IDE_DAEMON_CHANNEL_ERROR) {94 if (err == IDE_DAEMON_CHANNEL_ERROR) {
95- IDE_LOGE("send file receive response failed, " \95+ IDE_LOGE("send file receive response failed, "
96- "maybe multiple msnpureports executed at the same time, which is not supported, " \96+ "maybe multiple msnpureports executed at the same time, which is not supported, "
97- "please execute msnpureport only once per time later if needed");97+ "please execute msnpureport only once per time later if needed");
98 }98 }
99 return IDE_DAEMON_OK;99 return IDE_DAEMON_OK;
100}100}
@@ -110,27 +110,27 @@ static int32_t AdxCommonGetFile(const CommHandle &handle, const std::string &src
110int32_t AdxGetDeviceFileTimeout(uint16_t devId, IdeString desPath, IdeString logType, uint32_t timeout)110int32_t AdxGetDeviceFileTimeout(uint16_t devId, IdeString desPath, IdeString logType, uint32_t timeout)
111{111{
112 int32_t err = IDE_DAEMON_ERROR;112 int32_t err = IDE_DAEMON_ERROR;
113- IDE_CTRL_VALUE_FAILED(desPath != nullptr && logType != nullptr, return err,113+ IDE_CTRL_VALUE_FAILED(desPath != nullptr && logType != nullptr, return err, "send file input parameter invalid");
114- "send file input parameter invalid");
115 IDE_RUN_LOGI("get device file to %s", desPath);114 IDE_RUN_LOGI("get device file to %s", desPath);
116 CommHandle client = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};115 CommHandle client = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};
117 uint32_t logId = 0;116 uint32_t logId = 0;
118 err = AdxGetLogIdByPhyId(devId, &logId);117 err = AdxGetLogIdByPhyId(devId, &logId);
119 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "get device logic id failed");118 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "get device logic id failed");
120 CommHandle handle = AdxHdcConnect(client, logId);119 CommHandle handle = AdxHdcConnect(client, logId);
121- IDE_CTRL_VALUE_FAILED(handle.session != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,120+ IDE_CTRL_VALUE_FAILED(
122- "send file hdc client connect failed");121+ handle.session != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "send file hdc client connect failed");
123 handle.timeout = timeout;122 handle.timeout = timeout;
124 std::string basePath = desPath;123 std::string basePath = desPath;
125 std::string value;124 std::string value;
126 int32_t result = IDE_DAEMON_OK;125 int32_t result = IDE_DAEMON_OK;
127- MsgCode code = AdxMsgProto::SendMsgData(handle, IDE_FILE_GETD_REQ, MsgStatus::MSG_STATUS_NONE_ERROR,126+ MsgCode code = AdxMsgProto::SendMsgData(
128- logType, strlen(logType) + 1);127+ handle, IDE_FILE_GETD_REQ, MsgStatus::MSG_STATUS_NONE_ERROR, logType, strlen(logType) + 1);
129 IDE_CTRL_VALUE_FAILED(code == IDE_DAEMON_NONE_ERROR, goto GET_ERROR, "send file hand shake failed");128 IDE_CTRL_VALUE_FAILED(code == IDE_DAEMON_NONE_ERROR, goto GET_ERROR, "send file hand shake failed");
130 do {129 do {
131 // recv file name130 // recv file name
132 code = AdxMsgProto::GetStringMsgData(handle, value);131 code = AdxMsgProto::GetStringMsgData(handle, value);
133- IDE_CTRL_VALUE_FAILED(code == IDE_DAEMON_NONE_ERROR, goto GET_ERROR, "get file shake response failed, ret=%d",132+ IDE_CTRL_VALUE_FAILED(
133+ code == IDE_DAEMON_NONE_ERROR, goto GET_ERROR, "get file shake response failed, ret=%d",
134 static_cast<int32_t>(code));134 static_cast<int32_t>(code));
135 size_t msgSize = IdeDaemon::Common::Config::CONTAINER_NO_SUPPORT_MESSAGE.length();135 size_t msgSize = IdeDaemon::Common::Config::CONTAINER_NO_SUPPORT_MESSAGE.length();
136 if (value.compare(0, msgSize, IdeDaemon::Common::Config::CONTAINER_NO_SUPPORT_MESSAGE) == 0) {136 if (value.compare(0, msgSize, IdeDaemon::Common::Config::CONTAINER_NO_SUPPORT_MESSAGE) == 0) {
@@ -167,16 +167,16 @@ GET_ERROR:
167 * @param [in] fd : file descriptor167 * @param [in] fd : file descriptor
168 * @return IDE_DAEMON_OK(0) : recv file success, IDE_DAEMON_ERROR(-1) : recv file failed168 * @return IDE_DAEMON_OK(0) : recv file success, IDE_DAEMON_ERROR(-1) : recv file failed
169 */169 */
170-static int32_t AdxRecvFile(const CommHandle &handle, int32_t fd)170+static int32_t AdxRecvFile(const CommHandle& handle, int32_t fd)
171{171{
172 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_ERROR, "file fd input failed");172 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_ERROR, "file fd input failed");
173- MsgProto *msg = nullptr;173+ MsgProto* msg = nullptr;
174 int32_t length = 0;174 int32_t length = 0;
175 while (true) {175 while (true) {
176- int32_t ret = AdxCommOptManager::Instance().Read(handle, reinterpret_cast<IdeRecvBuffT>(&msg),176+ int32_t ret =
177- length, DEFAULT_TIMEOUT);177+ AdxCommOptManager::Instance().Read(handle, reinterpret_cast<IdeRecvBuffT>(&msg), length, DEFAULT_TIMEOUT);
178- IDE_CTRL_VALUE_FAILED((ret == IDE_DAEMON_OK) && (msg != nullptr), return IDE_DAEMON_ERROR,178+ IDE_CTRL_VALUE_FAILED(
179- "receive file failed, ret: %d", ret);179+ (ret == IDE_DAEMON_OK) && (msg != nullptr), return IDE_DAEMON_ERROR, "receive file failed, ret: %d", ret);
180 if (msg->msgType == MsgType::MSG_CTRL) { // check the message is ctrl or not180 if (msg->msgType == MsgType::MSG_CTRL) { // check the message is ctrl or not
181 IDE_LOGW("receive control message from device, stop receiving");181 IDE_LOGW("receive control message from device, stop receiving");
182 IDE_XFREE_AND_SET_NULL(msg);182 IDE_XFREE_AND_SET_NULL(msg);
@@ -186,8 +186,9 @@ static int32_t AdxRecvFile(const CommHandle &handle, int32_t fd)
186 mmSsize_t len = mmWrite(fd, msg->data, msg->sliceLen);186 mmSsize_t len = mmWrite(fd, msg->data, msg->sliceLen);
187 if (len < 0) {187 if (len < 0) {
188 char errBuf[MAX_ERRSTR_LEN + 1] = {0};188 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
189- IDE_LOGE("write file failed, error info: [%s]",189+ IDE_LOGE(
190- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));190+ "write file failed, error info: [%s]",
191+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
191 IDE_XFREE_AND_SET_NULL(msg);192 IDE_XFREE_AND_SET_NULL(msg);
192 return IDE_DAEMON_ERROR;193 return IDE_DAEMON_ERROR;
193 }194 }
@@ -225,10 +226,11 @@ int32_t AdxGetDeviceFile(uint16_t devId, IdeString desPath, IdeString logType)
225 * @param [in] file : the file name226 * @param [in] file : the file name
226 * @return IDE_DAEMON_OK(0) : recv file success, IDE_DAEMON_ERROR(-1) : recv file failed227 * @return IDE_DAEMON_OK(0) : recv file success, IDE_DAEMON_ERROR(-1) : recv file failed
227 */228 */
228-static int32_t AdxCreateFileAndRecvValue(const CommHandle &handle, std::string &file)229+static int32_t AdxCreateFileAndRecvValue(const CommHandle& handle, std::string& file)
229{230{
230- IDE_CTRL_VALUE_FAILED(FileUtils::CheckNonCrossPath(file), return IDE_DAEMON_ERROR, 231+ IDE_CTRL_VALUE_FAILED(
231- "Cross-path access may exist on the path: %s", file.c_str());232+ FileUtils::CheckNonCrossPath(file), return IDE_DAEMON_ERROR, "Cross-path access may exist on the path: %s",
233+ file.c_str());
232 // create dir if not exist234 // create dir if not exist
233 std::string saveDirName = FileUtils::GetFileDir(file);235 std::string saveDirName = FileUtils::GetFileDir(file);
234 if (!FileUtils::IsFileExist(saveDirName)) {236 if (!FileUtils::IsFileExist(saveDirName)) {
@@ -240,8 +242,9 @@ static int32_t AdxCreateFileAndRecvValue(const CommHandle &handle, std::string &
240 // get file242 // get file
241 int32_t fd = mmOpen2(file.c_str(), M_RDWR | M_CREAT | M_BINARY | M_TRUNC, M_IRUSR | M_IWRITE);243 int32_t fd = mmOpen2(file.c_str(), M_RDWR | M_CREAT | M_BINARY | M_TRUNC, M_IRUSR | M_IWRITE);
242 char errBuf[MAX_ERRSTR_LEN + 1] = {0};244 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
243- IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_ERROR, "open file exception, info : %s",245+ IDE_CTRL_VALUE_FAILED(
244- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));246+ fd >= 0, return IDE_DAEMON_ERROR, "open file exception, info : %s",
247+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
245 248 
246 int32_t err = AdxRecvFile(handle, fd);249 int32_t err = AdxRecvFile(handle, fd);
247 if (err == IDE_DAEMON_ERROR) {250 if (err == IDE_DAEMON_ERROR) {
@@ -269,16 +272,16 @@ static int32_t AdxCreateFileAndRecvValue(const CommHandle &handle, std::string &
269int32_t AdxGetSpecifiedFile(uint16_t devId, IdeString desPath, IdeString logType, int32_t hdcType, int32_t compType)272int32_t AdxGetSpecifiedFile(uint16_t devId, IdeString desPath, IdeString logType, int32_t hdcType, int32_t compType)
270{273{
271 int32_t err = IDE_DAEMON_ERROR;274 int32_t err = IDE_DAEMON_ERROR;
272- IDE_CTRL_VALUE_FAILED((desPath != nullptr) && (logType != nullptr), return err,275+ IDE_CTRL_VALUE_FAILED(
273- "send file input parameter invalid");276+ (desPath != nullptr) && (logType != nullptr), return err, "send file input parameter invalid");
274 IDE_RUN_LOGI("get device file to %s", desPath);277 IDE_RUN_LOGI("get device file to %s", desPath);
275 CommHandle client = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};278 CommHandle client = {OptType::COMM_HDC, ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr};
276 uint32_t logId = 0;279 uint32_t logId = 0;
277 err = AdxGetLogIdByPhyId(devId, &logId);280 err = AdxGetLogIdByPhyId(devId, &logId);
278 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "get device logic id failed");281 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "get device logic id failed");
279 CommHandle handle = AdxHdcConnect(client, logId, static_cast<AdxHdcServiceType>(hdcType));282 CommHandle handle = AdxHdcConnect(client, logId, static_cast<AdxHdcServiceType>(hdcType));
280- IDE_CTRL_VALUE_FAILED(handle.session != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,283+ IDE_CTRL_VALUE_FAILED(
281- "send file hdc client connect failed");284+ handle.session != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "send file hdc client connect failed");
282 handle.comp = static_cast<ComponentType>(compType);285 handle.comp = static_cast<ComponentType>(compType);
283 err = AdxSendMsg(static_cast<AdxCommConHandle>(&handle), logType, strlen(logType));286 err = AdxSendMsg(static_cast<AdxCommConHandle>(&handle), logType, strlen(logType));
284 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "send data message failed");287 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return err, "send data message failed");
@@ -321,8 +324,8 @@ int32_t AdxGetSpecifiedFile(uint16_t devId, IdeString desPath, IdeString logType
321 return err;324 return err;
322}325}
323 326 
324-int32_t AdxRecvDevFileTimeout(AdxCommHandle handle, AdxString desPath, uint32_t timeout, AdxStringBuffer fileName,327+int32_t AdxRecvDevFileTimeout(
325- uint32_t fileNameLen)328+ AdxCommHandle handle, AdxString desPath, uint32_t timeout, AdxStringBuffer fileName, uint32_t fileNameLen)
326{329{
327 IDE_CTRL_VALUE_FAILED(handle != nullptr, return IDE_DAEMON_ERROR, "handle is NULL.");330 IDE_CTRL_VALUE_FAILED(handle != nullptr, return IDE_DAEMON_ERROR, "handle is NULL.");
328 IDE_CTRL_VALUE_FAILED(desPath != nullptr, return IDE_DAEMON_ERROR, "desPath is NULL.");331 IDE_CTRL_VALUE_FAILED(desPath != nullptr, return IDE_DAEMON_ERROR, "desPath is NULL.");
@@ -342,4 +345,4 @@ int32_t AdxRecvDevFileTimeout(AdxCommHandle handle, AdxString desPath, uint32_t
342 return IDE_DAEMON_ERROR;345 return IDE_DAEMON_ERROR;
343 }346 }
344 return IDE_DAEMON_OK;347 return IDE_DAEMON_OK;
345-}348+}
@@ -14,13 +14,12 @@
14#include <queue>14#include <queue>
15#include <mutex>15#include <mutex>
16namespace Adx {16namespace Adx {
17-template<typename T>17+template <typename T>
18class BoundQueue {18class BoundQueue {
19public:19public:
20- explicit BoundQueue (uint32_t capacity)20+ explicit BoundQueue(uint32_t capacity) : quit_(false), capacity_(capacity) {}
21- : quit_(false), capacity_(capacity) {}
22 virtual ~BoundQueue() {}21 virtual ~BoundQueue() {}
23- bool TryPush(T &value)22+ bool TryPush(T& value)
24 {23 {
25 std::lock_guard<std::mutex> lk(mtx_);24 std::lock_guard<std::mutex> lk(mtx_);
26 if (this->IsFull()) {25 if (this->IsFull()) {
@@ -32,16 +31,16 @@ public:
32 return true;31 return true;
33 }32 }
34 33 
35- bool Push(T &value)34+ bool Push(T& value)
36 {35 {
37 std::unique_lock<std::mutex> lk(mtx_);36 std::unique_lock<std::mutex> lk(mtx_);
38- cvPop_.wait(lk, [=] { return !this->IsFull() || quit_;});37+ cvPop_.wait(lk, [=] { return !this->IsFull() || quit_; });
39 dataQueue_.push(value);38 dataQueue_.push(value);
40 cvPush_.notify_all();39 cvPush_.notify_all();
41 return true;40 return true;
42 }41 }
43 42 
44- bool TryPop(T &value)43+ bool TryPop(T& value)
45 {44 {
46 std::lock_guard<std::mutex> lk(mtx_);45 std::lock_guard<std::mutex> lk(mtx_);
47 if (dataQueue_.empty()) {46 if (dataQueue_.empty()) {
@@ -54,7 +53,7 @@ public:
54 return true;53 return true;
55 }54 }
56 55 
57- bool Pop(T &value)56+ bool Pop(T& value)
58 {57 {
59 std::unique_lock<std::mutex> lk(mtx_);58 std::unique_lock<std::mutex> lk(mtx_);
60 cvPush_.wait(lk, [=] { return !this->IsEmpty() || quit_; });59 cvPush_.wait(lk, [=] { return !this->IsEmpty() || quit_; });
@@ -68,15 +67,9 @@ public:
68 return false;67 return false;
69 }68 }
70 69 
71- bool IsEmpty() const70+ bool IsEmpty() const { return dataQueue_.empty(); }
72- {
73- return dataQueue_.empty();
74- }
75 71 
76- bool IsFull() const72+ bool IsFull() const { return dataQueue_.size() == capacity_; }
77- {
78- return dataQueue_.size() == capacity_;
79- }
80 73 
81 void Quit()74 void Quit()
82 {75 {
@@ -88,10 +81,8 @@ public:
88 }81 }
89 }82 }
90 83 
91- uint32_t Size()84+ uint32_t Size() { return dataQueue_.size(); }
92- {85+ 
93- return dataQueue_.size();
94- }
95private:86private:
96 mutable bool quit_;87 mutable bool quit_;
97 mutable std::mutex mtx_;88 mutable std::mutex mtx_;
@@ -100,5 +91,5 @@ private:
100 std::condition_variable cvPush_;91 std::condition_variable cvPush_;
101 uint32_t capacity_;92 uint32_t capacity_;
102};93};
103-}94+} // namespace Adx
104#endif95#endif
@@ -24,21 +24,23 @@ constexpr const char* MEM_USAGE_V2 = "/sys/fs/cgroup/memory.current";
24constexpr const char* MEM_LIMIT_V1 = "/sys/fs/cgroup/memory/memory.limit_in_bytes";24constexpr const char* MEM_LIMIT_V1 = "/sys/fs/cgroup/memory/memory.limit_in_bytes";
25constexpr const char* MEM_LIMIT_V2 = "/sys/fs/cgroup/memory.max";25constexpr const char* MEM_LIMIT_V2 = "/sys/fs/cgroup/memory.max";
26 26 
27-template<typename T>27+template <typename T>
28class BoundQueueMemory {28class BoundQueueMemory {
29public:29public:
30- explicit BoundQueueMemory () : quit_(false), memLimit_(InitMemLimit()) {30+ explicit BoundQueueMemory() : quit_(false), memLimit_(InitMemLimit())
31+ {
31 memUsageV1_.open(MEM_USAGE_V1);32 memUsageV1_.open(MEM_USAGE_V1);
32 memUsageV2_.open(MEM_USAGE_V2);33 memUsageV2_.open(MEM_USAGE_V2);
33 }34 }
34- virtual ~BoundQueueMemory() {35+ virtual ~BoundQueueMemory()
36+ {
35 memUsageV1_.close();37 memUsageV1_.close();
36 memUsageV2_.close();38 memUsageV2_.close();
37 }39 }
38- bool Push(T &value)40+ bool Push(T& value)
39 {41 {
40 std::unique_lock<std::mutex> lk(mtx_);42 std::unique_lock<std::mutex> lk(mtx_);
41- cvPop_.wait(lk, [this] { return !this->IsFullUnlocked() || this->quit_;});43+ cvPop_.wait(lk, [this] { return !this->IsFullUnlocked() || this->quit_; });
42 if (this->quit_) {44 if (this->quit_) {
43 return false;45 return false;
44 }46 }
@@ -47,7 +49,7 @@ public:
47 return true;49 return true;
48 }50 }
49 51 
50- bool Pop(T &value)52+ bool Pop(T& value)
51 {53 {
52 std::unique_lock<std::mutex> lk(mtx_);54 std::unique_lock<std::mutex> lk(mtx_);
53 cvPush_.wait(lk, [this] { return !this->IsEmptyUnlocked() || this->quit_; });55 cvPush_.wait(lk, [this] { return !this->IsEmptyUnlocked() || this->quit_; });
@@ -94,16 +96,10 @@ public:
94 return dataQueue_.size();96 return dataQueue_.size();
95 }97 }
96 98 
97- void SetPath(std::string path)99+ void SetPath(std::string path) { path_ = path; }
98- {
99- path_ = path;
100- }
101 100 
102private:101private:
103- bool IsEmptyUnlocked() const102+ bool IsEmptyUnlocked() const { return dataQueue_.empty(); }
104- {
105- return dataQueue_.empty();
106- }
107 103 
108 bool IsFullUnlocked() const104 bool IsFullUnlocked() const
109 {105 {
@@ -126,7 +122,8 @@ private:
126 return (info.freeram < (info.totalram * (1 - ADX_QUEUE_FULL_SIZE))) && dataQueue_.size() > queueSize;122 return (info.freeram < (info.totalram * (1 - ADX_QUEUE_FULL_SIZE))) && dataQueue_.size() > queueSize;
127 }123 }
128 124 
129- uint64_t InitMemLimit() const {125+ uint64_t InitMemLimit() const
126+ {
130 std::ifstream memLimitV1(MEM_LIMIT_V1);127 std::ifstream memLimitV1(MEM_LIMIT_V1);
131 std::ifstream memLimitV2(MEM_LIMIT_V2);128 std::ifstream memLimitV2(MEM_LIMIT_V2);
132 uint64_t ret = ReadMemory(memLimitV1, memLimitV2);129 uint64_t ret = ReadMemory(memLimitV1, memLimitV2);
@@ -134,7 +131,8 @@ private:
134 memLimitV2.close();131 memLimitV2.close();
135 return ret;132 return ret;
136 }133 }
137- uint64_t ReadLongLong(std::ifstream &f) const {134+ uint64_t ReadLongLong(std::ifstream& f) const
135+ {
138 if (!f.is_open()) {136 if (!f.is_open()) {
139 return 0;137 return 0;
140 }138 }
@@ -147,7 +145,8 @@ private:
147 return 0;145 return 0;
148 }146 }
149 147 
150- uint64_t ReadMemory(std::ifstream &f1, std::ifstream &f2) const {148+ uint64_t ReadMemory(std::ifstream& f1, std::ifstream& f2) const
149+ {
151 uint64_t value = ReadLongLong(f2);150 uint64_t value = ReadLongLong(f2);
152 if (value == 0) {151 if (value == 0) {
153 value = ReadLongLong(f1);152 value = ReadLongLong(f1);
@@ -164,5 +163,5 @@ private:
164 mutable std::ifstream memUsageV2_;163 mutable std::ifstream memUsageV2_;
165 uint64_t memLimit_;164 uint64_t memLimit_;
166};165};
167-}166+} // namespace Adx
168#endif167#endif
@@ -20,14 +20,15 @@ constexpr uint64_t DUMP_STATS_NEG_INF = 1U << 4;
20constexpr uint64_t DUMP_STATS_POS_INF = 1U << 5;20constexpr uint64_t DUMP_STATS_POS_INF = 1U << 5;
21constexpr uint64_t DUMP_STATS_L2NORM = 1U << 6;21constexpr uint64_t DUMP_STATS_L2NORM = 1U << 6;
22 22 
23-#define IDE_RETURN_IF_CHECK_ASSIGN_32U_ADD(A, B, result, action) do { \23+#define IDE_RETURN_IF_CHECK_ASSIGN_32U_ADD(A, B, result, action) \
24- if (UINT32_MAX - (A) <= (B)) { \24+ do { \
25- action; \25+ if (UINT32_MAX - (A) <= (B)) { \
26- } \26+ action; \
27- (result) = (A) + (B); \27+ } \
28-} while (0)28+ (result) = (A) + (B); \
29+ } while (0)
29 30 
30template <typename T>31template <typename T>
zhangjie
zhangjiezhangjie8月4日

级别:提示 问题:文件末尾缺少换行符(\ No newline at end of file)。 影响:不符合POSIX规范,部分工具(如cat拼接、diff)可能产生异常输出。此问题同样存在于 file_utils.h、file_utils.cpp、memory_utils.h、create_func.h、sock_api.h、sock_comm_opt.cpp、thread.cpp、thread_without_attr.cpp、adx_common_component.cpp、adx_common_component.h、adx_component.h、adx_comm_opt_manager.h 等多个文件。 修复建议:在上述文件末尾补一个空行。

likedislike
fujun19
8月5日 评论:
31using SharedPtr = std::shared_ptr<T>;32using SharedPtr = std::shared_ptr<T>;
32-}33+} // namespace Adx
33-#endif34+#endif
@@ -15,35 +15,34 @@ namespace IdeDaemon {
15namespace Common {15namespace Common {
16namespace Config {16namespace Config {
17/* directory umask */17/* directory umask */
18-constexpr int32_t DEFAULT_UMASK = (0027);18+constexpr int32_t DEFAULT_UMASK = (0027);
19-constexpr int32_t SPECIAL_UMASK = (0022);19+constexpr int32_t SPECIAL_UMASK = (0022);
20-constexpr int32_t IDE_CREATE_SERVER_TIME = 5000; // 5 * 1000ms20+constexpr int32_t IDE_CREATE_SERVER_TIME = 5000; // 5 * 1000ms
21-constexpr int32_t MAX_LISTEN_NUM = 100;21+constexpr int32_t MAX_LISTEN_NUM = 100;
22-constexpr int32_t PATH_LEN = 200;22+constexpr int32_t PATH_LEN = 200;
23-constexpr int32_t IDE_DAEMON_BLOCK = 0;23+constexpr int32_t IDE_DAEMON_BLOCK = 0;
24-constexpr int32_t IDE_DAEMON_NOBLOCK = 1;24+constexpr int32_t IDE_DAEMON_NOBLOCK = 1;
25-constexpr int32_t IDE_DAEMON_TIMEOUT = 2;25+constexpr int32_t IDE_DAEMON_TIMEOUT = 2;
26-constexpr uint32_t IDE_MAX_HDC_SEGMENT = 524288; // (512 * 1024) max size of hdc segment26+constexpr uint32_t IDE_MAX_HDC_SEGMENT = 524288; // (512 * 1024) max size of hdc segment
27-constexpr uint32_t IDE_MIN_HDC_SEGMENT = 1024; // min size of hdc segment27+constexpr uint32_t IDE_MIN_HDC_SEGMENT = 1024; // min size of hdc segment
28-constexpr uint32_t DISK_RESERVED_SPACE = 1048576; // disk reserved space 1Mb28+constexpr uint32_t DISK_RESERVED_SPACE = 1048576; // disk reserved space 1Mb
29-constexpr int32_t NON_DOCKER = 1;29+constexpr int32_t NON_DOCKER = 1;
30-constexpr int32_t IS_DOCKER = 2;30+constexpr int32_t IS_DOCKER = 2;
31-constexpr int32_t VM_NON_DOCKER = 3;31+constexpr int32_t VM_NON_DOCKER = 3;
32-constexpr const char *IDE_HDC_SERVER_THREAD_NAME = "ide_hdc_server";32+constexpr const char* IDE_HDC_SERVER_THREAD_NAME = "ide_hdc_server";
33-constexpr const char *IDE_HDC_PROCESS_THREAD_NAME = "ide_hdc_process";33+constexpr const char* IDE_HDC_PROCESS_THREAD_NAME = "ide_hdc_process";
34-constexpr const char *IDE_DEVICE_MONITOR_THREAD_NAME = "ide_dev_monitor";34+constexpr const char* IDE_DEVICE_MONITOR_THREAD_NAME = "ide_dev_monitor";
35-constexpr const char *IDE_UNDERLINE = "_";35+constexpr const char* IDE_UNDERLINE = "_";
36-constexpr const char *IDE_HOME_WAVE_DIR = "~/";36+constexpr const char* IDE_HOME_WAVE_DIR = "~/";
37-constexpr const char *IDE_SPLIT_CHAR = ";";37+constexpr const char* IDE_SPLIT_CHAR = ";";
38-constexpr const char *ADX_PF_LOCAL_CHAN = "adserver";38+constexpr const char* ADX_PF_LOCAL_CHAN = "adserver";
39-constexpr const char *OS_SPLIT_STR = "/";39+constexpr const char* OS_SPLIT_STR = "/";
40-const std::string CONTAINER_NO_SUPPORT_MESSAGE = "MESSAGE_CONTAINER_NO_SUPPORT";40+const std::string CONTAINER_NO_SUPPORT_MESSAGE = "MESSAGE_CONTAINER_NO_SUPPORT";
41-constexpr char OS_SPLIT = '/';41+constexpr char OS_SPLIT = '/';
42-const std::string SEND_END_MSG = "game_over";42+const std::string SEND_END_MSG = "game_over";
43-const std::string HELPER_HOSTPID = "ASCEND_HOSTPID";43+const std::string HELPER_HOSTPID = "ASCEND_HOSTPID";
44-} // end config44+} // namespace Config
45-}45+} // namespace Common
46-}46+} // namespace IdeDaemon
47 47 
48#endif48#endif
49- 
@@ -15,7 +15,7 @@ namespace Adx {
15std::unique_ptr<AdxEpoll> CreateAdxEpoll(EpollType epollType)15std::unique_ptr<AdxEpoll> CreateAdxEpoll(EpollType epollType)
16{16{
17 if (epollType == EpollType::EPOLL_HDC) {17 if (epollType == EpollType::EPOLL_HDC) {
18- return std::unique_ptr<AdxEpoll>(new(std::nothrow)AdxHdcEpoll);18+ return std::unique_ptr<AdxEpoll>(new (std::nothrow) AdxHdcEpoll);
19 }19 }
20 return nullptr;20 return nullptr;
21}21}
@@ -23,8 +23,8 @@ std::unique_ptr<AdxEpoll> CreateAdxEpoll(EpollType epollType)
23std::unique_ptr<AdxCommOpt> CreateAdxCommOpt(OptType optType)23std::unique_ptr<AdxCommOpt> CreateAdxCommOpt(OptType optType)
24{24{
25 if (optType == OptType::COMM_HDC) {25 if (optType == OptType::COMM_HDC) {
26- return std::unique_ptr<AdxCommOpt>(new(std::nothrow)HdcCommOpt);26+ return std::unique_ptr<AdxCommOpt>(new (std::nothrow) HdcCommOpt);
27 }27 }
28 return nullptr;28 return nullptr;
29}29}
30-}30+} // namespace Adx
@@ -17,5 +17,5 @@
17namespace Adx {17namespace Adx {
18std::unique_ptr<AdxEpoll> CreateAdxEpoll(EpollType epollType);18std::unique_ptr<AdxEpoll> CreateAdxEpoll(EpollType epollType);
19std::unique_ptr<AdxCommOpt> CreateAdxCommOpt(OptType optType);19std::unique_ptr<AdxCommOpt> CreateAdxCommOpt(OptType optType);
20-}20+} // namespace Adx
21-#endif21+#endif
@@ -13,7 +13,7 @@
13#include "log/adx_log.h"13#include "log/adx_log.h"
14#include "ide_os_type.h"14#include "ide_os_type.h"
15namespace Adx {15namespace Adx {
16-static const std::string MAPPING_FILE_NAME = "mapping.csv";16+static const std::string MAPPING_FILE_NAME = "mapping.csv";
17 17 
18/**18/**
19 * @brief Write data to file19 * @brief Write data to file
@@ -25,7 +25,7 @@ static const std::string MAPPING_FILE_NAME = "mapping.csv";
25 * IDE_DAEMON_NONE_ERROR: Write data to file success25 * IDE_DAEMON_NONE_ERROR: Write data to file success
26 * Other: failed, check for IdeErrorCode26 * Other: failed, check for IdeErrorCode
27 */27 */
28-IdeErrorT FileUtils::WriteFile(const std::string &fileName, IdeSendBuffT data, uint32_t len, int64_t offset)28+IdeErrorT FileUtils::WriteFile(const std::string& fileName, IdeSendBuffT data, uint32_t len, int64_t offset)
29{29{
30 IDE_CTRL_VALUE_FAILED(!fileName.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "fileName is nullptr");30 IDE_CTRL_VALUE_FAILED(!fileName.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "fileName is nullptr");
31 IDE_CTRL_VALUE_FAILED(data != nullptr, return IDE_DAEMON_INVALID_PARAM_ERROR, "data is nullptr");31 IDE_CTRL_VALUE_FAILED(data != nullptr, return IDE_DAEMON_INVALID_PARAM_ERROR, "data is nullptr");
@@ -33,8 +33,9 @@ IdeErrorT FileUtils::WriteFile(const std::string &fileName, IdeSendBuffT data, u
33 int32_t fd = mmOpen2(wrFile.c_str(), O_APPEND | M_RDWR | M_CREAT, M_IREAD | M_IWRITE);33 int32_t fd = mmOpen2(wrFile.c_str(), O_APPEND | M_RDWR | M_CREAT, M_IREAD | M_IWRITE);
34 if (fd < 0 && mmGetErrorCode() != ENAMETOOLONG) {34 if (fd < 0 && mmGetErrorCode() != ENAMETOOLONG) {
35 char errBuf[MAX_ERRSTR_LEN + 1] = {0};35 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
36- IDE_LOGE("Open file %s failed , exception %s", fileName.c_str(),36+ IDE_LOGE(
37- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));37+ "Open file %s failed , exception %s", fileName.c_str(),
38+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
38 return IDE_DAEMON_INVALID_PATH_ERROR;39 return IDE_DAEMON_INVALID_PATH_ERROR;
39 } else if (fd < 0) {40 } else if (fd < 0) {
40 std::string wrPath = GetFileDir(wrFile);41 std::string wrPath = GetFileDir(wrFile);
@@ -45,8 +46,9 @@ IdeErrorT FileUtils::WriteFile(const std::string &fileName, IdeSendBuffT data, u
45 IDE_LOGE("add mapping item [ %s ] failed", hashValue.c_str());46 IDE_LOGE("add mapping item [ %s ] failed", hashValue.c_str());
46 }47 }
47 wrFile = wrPath + OS_SPLIT_STR + hashValue;48 wrFile = wrPath + OS_SPLIT_STR + hashValue;
48- IDE_LOGW("file name [ %s ] too long rename as [ %s ] and the mapping record in mapping.csv",49+ IDE_LOGW(
49- fileName.c_str(), wrFile.c_str());50+ "file name [ %s ] too long rename as [ %s ] and the mapping record in mapping.csv", fileName.c_str(),
51+ wrFile.c_str());
50 fd = mmOpen2(wrFile.c_str(), O_APPEND | M_RDWR | M_CREAT, M_IREAD | M_IWRITE);52 fd = mmOpen2(wrFile.c_str(), O_APPEND | M_RDWR | M_CREAT, M_IREAD | M_IWRITE);
51 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PATH_ERROR, "file path error");53 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PATH_ERROR, "file path error");
52 }54 }
@@ -66,8 +68,9 @@ IdeErrorT FileUtils::WriteFile(const std::string &fileName, IdeSendBuffT data, u
66 mmSsize_t writeLen = mmWrite(fd, wrData + (len - reserve), reserve);68 mmSsize_t writeLen = mmWrite(fd, wrData + (len - reserve), reserve);
67 if (writeLen < 0) {69 if (writeLen < 0) {
68 char errBuf[MAX_ERRSTR_LEN + 1] = {0};70 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
69- IDE_LOGE("Write failed, info: %s, write ratio: %u/%u",71+ IDE_LOGE(
70- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN), len - reserve, len);72+ "Write failed, info: %s, write ratio: %u/%u",
73+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN), len - reserve, len);
71 FILE_MMCLOSE_AND_SET_INVALID(fd);74 FILE_MMCLOSE_AND_SET_INVALID(fd);
72 return IDE_DAEMON_NO_SPACE_ERROR;75 return IDE_DAEMON_NO_SPACE_ERROR;
73 }76 }
@@ -86,7 +89,7 @@ IdeErrorT FileUtils::WriteFile(const std::string &fileName, IdeSendBuffT data, u
86 * IDE_DAEMON_NONE_ERROR: add mapping item success89 * IDE_DAEMON_NONE_ERROR: add mapping item success
87 * Other: failed, check for IdeErrorCode90 * Other: failed, check for IdeErrorCode
88 */91 */
89-IdeErrorT FileUtils::AddMappingFileItem(const std::string &filePath, const std::string &hashValue)92+IdeErrorT FileUtils::AddMappingFileItem(const std::string& filePath, const std::string& hashValue)
90{93{
91 IDE_CTRL_VALUE_FAILED(!filePath.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "filePath is nullptr");94 IDE_CTRL_VALUE_FAILED(!filePath.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "filePath is nullptr");
92 IDE_CTRL_VALUE_FAILED(!hashValue.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "hashValue is null");95 IDE_CTRL_VALUE_FAILED(!hashValue.empty(), return IDE_DAEMON_INVALID_PARAM_ERROR, "hashValue is null");
@@ -115,13 +118,14 @@ IdeErrorT FileUtils::AddMappingFileItem(const std::string &filePath, const std::
115 uint32_t mapItemDataLen = mapItem.length();118 uint32_t mapItemDataLen = mapItem.length();
116 uint32_t residLen = mapItemDataLen;119 uint32_t residLen = mapItemDataLen;
117 do {120 do {
118- mmSsize_t writeLen = mmWrite(fd, const_cast<IdeStringBuffer>(mapItem.c_str()) +121+ mmSsize_t writeLen =
119- (mapItemDataLen - residLen), residLen);122+ mmWrite(fd, const_cast<IdeStringBuffer>(mapItem.c_str()) + (mapItemDataLen - residLen), residLen);
120 if (writeLen < 0) {123 if (writeLen < 0) {
121 char errBuf[MAX_ERRSTR_LEN + 1] = {0};124 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
122- IDE_LOGE("Write failed, info: %s, write ratio: %u/%u",125+ IDE_LOGE(
123- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN),126+ "Write failed, info: %s, write ratio: %u/%u",
124- mapItemDataLen - residLen, mapItemDataLen);127+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN), mapItemDataLen - residLen,
128+ mapItemDataLen);
125 FILE_MMCLOSE_AND_SET_INVALID(fd);129 FILE_MMCLOSE_AND_SET_INVALID(fd);
126 return IDE_DAEMON_NO_SPACE_ERROR;130 return IDE_DAEMON_NO_SPACE_ERROR;
127 }131 }
@@ -129,8 +133,9 @@ IdeErrorT FileUtils::AddMappingFileItem(const std::string &filePath, const std::
129 residLen -= writeLen;133 residLen -= writeLen;
130 } else {134 } else {
131 char errBuf[MAX_ERRSTR_LEN + 1] = {0};135 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
132- IDE_LOGE("Write failed, info : %s, writeLen larger than residLen",136+ IDE_LOGE(
133- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));137+ "Write failed, info : %s, writeLen larger than residLen",
138+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
134 FILE_MMCLOSE_AND_SET_INVALID(fd);139 FILE_MMCLOSE_AND_SET_INVALID(fd);
135 return IDE_DAEMON_UNKNOW_ERROR;140 return IDE_DAEMON_UNKNOW_ERROR;
136 }141 }
@@ -147,7 +152,7 @@ IdeErrorT FileUtils::AddMappingFileItem(const std::string &filePath, const std::
147 * true: file exists152 * true: file exists
148 * false: file not exist153 * false: file not exist
149 */154 */
150-bool FileUtils::IsFileExist(const std::string &path)155+bool FileUtils::IsFileExist(const std::string& path)
151{156{
152 if (path.empty()) {157 if (path.empty()) {
153 return false;158 return false;
@@ -168,7 +173,7 @@ bool FileUtils::IsFileExist(const std::string &path)
168 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path173 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path
169 * IDE_DAEMON_MKDIR_ERROR: Mkdir failed174 * IDE_DAEMON_MKDIR_ERROR: Mkdir failed
170 */175 */
171-IdeErrorT FileUtils::CreateDir(const std::string &path)176+IdeErrorT FileUtils::CreateDir(const std::string& path)
172{177{
173 std::string curr = path;178 std::string curr = path;
174 IdeErrorT ret = IDE_DAEMON_UNKNOW_ERROR;179 IdeErrorT ret = IDE_DAEMON_UNKNOW_ERROR;
@@ -191,8 +196,9 @@ IdeErrorT FileUtils::CreateDir(const std::string &path)
191 if (!IsFileExist(path)) {196 if (!IsFileExist(path)) {
192 if (mmMkdir(path.c_str(), (mmMode_t)DEFAULT_PATH_MODE) != EN_OK && errno != EEXIST) {197 if (mmMkdir(path.c_str(), (mmMode_t)DEFAULT_PATH_MODE) != EN_OK && errno != EEXIST) {
193 char errBuf[MAX_ERRSTR_LEN + 1] = {0};198 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
194- IDE_LOGE("mkdir %s failed, errorstr: %s", path.c_str(),199+ IDE_LOGE(
195- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));200+ "mkdir %s failed, errorstr: %s", path.c_str(),
201+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
196 return IDE_DAEMON_MKDIR_ERROR;202 return IDE_DAEMON_MKDIR_ERROR;
197 }203 }
198 }204 }
@@ -208,7 +214,7 @@ IdeErrorT FileUtils::CreateDir(const std::string &path)
208 * IDE_DAEMON_NONE_ERROR: Dump start Success214 * IDE_DAEMON_NONE_ERROR: Dump start Success
209 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path215 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path
210 */216 */
211-std::string FileUtils::GetFileDir(const std::string &path)217+std::string FileUtils::GetFileDir(const std::string& path)
212{218{
213 std::string dir;219 std::string dir;
214 size_t pos = path.find_last_of(OS_SPLIT_CHAR);220 size_t pos = path.find_last_of(OS_SPLIT_CHAR);
@@ -231,7 +237,7 @@ std::string FileUtils::GetFileDir(const std::string &path)
231 * true: the path has sufficient disk space237 * true: the path has sufficient disk space
232 * false: invalid path or the path does not have sufficient disk space238 * false: invalid path or the path does not have sufficient disk space
233 */239 */
234-bool FileUtils::IsDiskFull(const std::string &path, uint64_t size)240+bool FileUtils::IsDiskFull(const std::string& path, uint64_t size)
235{241{
236 IDE_CTRL_VALUE_FAILED(!path.empty(), return false, "path is empty");242 IDE_CTRL_VALUE_FAILED(!path.empty(), return false, "path is empty");
237 243 
@@ -239,8 +245,9 @@ bool FileUtils::IsDiskFull(const std::string &path, uint64_t size)
239 (void)memset_s(&diskSize, sizeof(diskSize), 0, sizeof(diskSize));245 (void)memset_s(&diskSize, sizeof(diskSize), 0, sizeof(diskSize));
240 int32_t ret = mmGetDiskFreeSpace(path.c_str(), &diskSize);246 int32_t ret = mmGetDiskFreeSpace(path.c_str(), &diskSize);
241 IDE_CTRL_VALUE_FAILED(ret == EN_OK, return true, "get disk free space fail");247 IDE_CTRL_VALUE_FAILED(ret == EN_OK, return true, "get disk free space fail");
242- IDE_CTRL_VALUE_FAILED(diskSize.freeSize > DISK_RESERVED_SPACE, return true,248+ IDE_CTRL_VALUE_FAILED(
243- "the %s more than disk reserved space(1Mb)", path.c_str());249+ diskSize.freeSize > DISK_RESERVED_SPACE, return true, "the %s more than disk reserved space(1Mb)",
250+ path.c_str());
244 IDE_CTRL_VALUE_FAILED(size < diskSize.freeSize, return true, "the %s is full", path.c_str());251 IDE_CTRL_VALUE_FAILED(size < diskSize.freeSize, return true, "the %s is full", path.c_str());
245 return false;252 return false;
246}253}
@@ -253,7 +260,7 @@ bool FileUtils::IsDiskFull(const std::string &path, uint64_t size)
253 * IDE_DAEMON_NONE_ERROR: Dump start Success260 * IDE_DAEMON_NONE_ERROR: Dump start Success
254 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path261 * IDE_DAEMON_INVALID_PATH_ERROR: Invalid path
255 */262 */
256-IdeErrorT FileUtils::GetFileName(const std::string &path, std::string &name)263+IdeErrorT FileUtils::GetFileName(const std::string& path, std::string& name)
257{264{
258 size_t pos = path.find_last_of(OS_SPLIT_CHAR);265 size_t pos = path.find_last_of(OS_SPLIT_CHAR);
259 if (pos != std::string::npos) {266 if (pos != std::string::npos) {
@@ -274,7 +281,7 @@ IdeErrorT FileUtils::GetFileName(const std::string &path, std::string &name)
274 * true : file not exists cross path281 * true : file not exists cross path
275 * false : file exists cross path282 * false : file exists cross path
276 */283 */
277-bool FileUtils::CheckNonCrossPath(const std::string &path)284+bool FileUtils::CheckNonCrossPath(const std::string& path)
278{285{
279 if (path.empty() || path.length() > MMPA_MAX_PATH) {286 if (path.empty() || path.length() > MMPA_MAX_PATH) {
280 return false;287 return false;
@@ -285,8 +292,7 @@ bool FileUtils::CheckNonCrossPath(const std::string &path)
285 return false;292 return false;
286 }293 }
287 294 
288- if (path.find("/..") != std::string::npos ||295+ if (path.find("/..") != std::string::npos || path.find("/\\.\\.") != std::string::npos) {
289- path.find("/\\.\\.") != std::string::npos) {
290 return false;296 return false;
291 }297 }
292 298 
@@ -302,7 +308,7 @@ bool FileUtils::CheckNonCrossPath(const std::string &path)
302 * IDE_DAEMON_OK: succ308 * IDE_DAEMON_OK: succ
303 * IDE_DAEMON_ERROR: failed309 * IDE_DAEMON_ERROR: failed
304 */310 */
305-int32_t FileUtils::FilePathIsReal(const std::string &filePath, std::string &resultPath)311+int32_t FileUtils::FilePathIsReal(const std::string& filePath, std::string& resultPath)
306{312{
307 if (filePath.empty()) {313 if (filePath.empty()) {
308 return IDE_DAEMON_ERROR;314 return IDE_DAEMON_ERROR;
@@ -328,7 +334,7 @@ int32_t FileUtils::FilePathIsReal(const std::string &filePath, std::string &resu
328 * IDE_DAEMON_OK: succ334 * IDE_DAEMON_OK: succ
329 * IDE_DAEMON_ERROR: failed335 * IDE_DAEMON_ERROR: failed
330 */336 */
331-int32_t FileUtils::FileNameIsReal(const std::string &file, std::string &resultPath)337+int32_t FileUtils::FileNameIsReal(const std::string& file, std::string& resultPath)
332{338{
333 int32_t ret = 0;339 int32_t ret = 0;
334 if (file.empty()) {340 if (file.empty()) {
@@ -355,7 +361,7 @@ int32_t FileUtils::FileNameIsReal(const std::string &file, std::string &resultPa
355 * true: characters of the dir are all valid361 * true: characters of the dir are all valid
356 * false: characters of the dir are not all valid362 * false: characters of the dir are not all valid
357 */363 */
358-bool FileUtils::IsValidDirChar(const std::string &path)364+bool FileUtils::IsValidDirChar(const std::string& path)
359{365{
360 if (path.empty()) {366 if (path.empty()) {
361 IDE_LOGE("invalid parameter");367 IDE_LOGE("invalid parameter");
@@ -375,7 +381,7 @@ bool FileUtils::IsValidDirChar(const std::string &path)
375 return true;381 return true;
376}382}
377 383 
378-std::string FileUtils::ReplaceAll(std::string &base, const std::string &src, const std::string &dst)384+std::string FileUtils::ReplaceAll(std::string& base, const std::string& src, const std::string& dst)
379{385{
380 size_t pos = 0;386 size_t pos = 0;
381 std::string targetStr = dst;387 std::string targetStr = dst;
@@ -386,7 +392,7 @@ std::string FileUtils::ReplaceAll(std::string &base, const std::string &src, con
386 return base;392 return base;
387}393}
388 394 
389-bool FileUtils::IsAbsolutePath(const std::string &path)395+bool FileUtils::IsAbsolutePath(const std::string& path)
390{396{
391#if (OS_TYPE == LINUX)397#if (OS_TYPE == LINUX)
392 return path.front() == OS_SPLIT_CHAR;398 return path.front() == OS_SPLIT_CHAR;
@@ -394,13 +400,12 @@ bool FileUtils::IsAbsolutePath(const std::string &path)
394 if (path.length() < WIN_PATH_MIN_LENGTH) {400 if (path.length() < WIN_PATH_MIN_LENGTH) {
395 return false;401 return false;
396 }402 }
397- return (path[1] == COLON) &&403+ return (path[1] == COLON) && ((path[0] >= 'a' && path[0] <= 'z') || (path[0] >= 'A' && path[0] <= 'Z'));
398- ((path[0] >= 'a' && path[0] <= 'z') ||
399- (path[0] >= 'A' && path[0] <= 'Z'));
400#endif404#endif
401}405}
402 406 
403-bool FileUtils::IsPathHasPermission(const std::string &path, std::string &errorMsg) {407+bool FileUtils::IsPathHasPermission(const std::string& path, std::string& errorMsg)
408+{
404 std::string trustedPath;409 std::string trustedPath;
405 int32_t ret = FilePathIsReal(path, trustedPath);410 int32_t ret = FilePathIsReal(path, trustedPath);
406 if (ret != IDE_DAEMON_OK) {411 if (ret != IDE_DAEMON_OK) {
@@ -408,13 +413,13 @@ bool FileUtils::IsPathHasPermission(const std::string &path, std::string &errorM
408 IDE_LOGE("%s", errorMsg.c_str());413 IDE_LOGE("%s", errorMsg.c_str());
409 return false;414 return false;
410 }415 }
411- constexpr uint32_t accessMode = static_cast<uint32_t>(M_R_OK) | static_cast<uint32_t>(M_W_OK);416+ constexpr uint32_t accessMode = static_cast<uint32_t>(M_R_OK) | static_cast<uint32_t>(M_W_OK);
412- if (mmAccess2(trustedPath.c_str(), static_cast<INT32>(accessMode)) != EN_OK) {417+ if (mmAccess2(trustedPath.c_str(), static_cast<INT32>(accessMode)) != EN_OK) {
413 errorMsg = "The path " + trustedPath + " does not have read and write permission";418 errorMsg = "The path " + trustedPath + " does not have read and write permission";
414 IDE_LOGE("%s", errorMsg.c_str());419 IDE_LOGE("%s", errorMsg.c_str());
415- return false;420+ return false;
416- }421+ }
417 errorMsg.clear();422 errorMsg.clear();
418- return true;423+ return true;
419}424}
420-}425+} // namespace Adx
@@ -16,43 +16,44 @@
16#include "extra_config.h"16#include "extra_config.h"
17#include "adump_device_pub.h"17#include "adump_device_pub.h"
18#include "ide_os_type.h"18#include "ide_os_type.h"
19-#define FILE_MMCLOSE_AND_SET_INVALID(fd) do { \19+#define FILE_MMCLOSE_AND_SET_INVALID(fd) \
20- if ((fd) >= 0) { \20+ do { \
21- (void)mmClose(fd); \21+ if ((fd) >= 0) { \
22- fd = -1; \22+ (void)mmClose(fd); \
23- } \23+ fd = -1; \
24-} while (0)24+ } \
25+ } while (0)
25 26 
26namespace Adx {27namespace Adx {
27#if (OS_TYPE == LINUX)28#if (OS_TYPE == LINUX)
28-constexpr char OS_SPLIT_CHAR = '/';29+constexpr char OS_SPLIT_CHAR = '/';
29-const std::string OS_SPLIT_STR = "/";30+const std::string OS_SPLIT_STR = "/";
30#else31#else
31-constexpr char OS_SPLIT_CHAR = '\\';32+constexpr char OS_SPLIT_CHAR = '\\';
32-const std::string OS_SPLIT_STR = "\\";33+const std::string OS_SPLIT_STR = "\\";
33-static const uint32_t WIN_PATH_MIN_LENGTH = 2;34+static const uint32_t WIN_PATH_MIN_LENGTH = 2;
34-constexpr char COLON = ':';35+constexpr char COLON = ':';
35#endif36#endif
36-constexpr uint32_t DEFAULT_PATH_MODE = 0700;37+constexpr uint32_t DEFAULT_PATH_MODE = 0700;
37-constexpr uint32_t DISK_RESERVED_SPACE = 1048576; // disk reserved space 1Mb38+constexpr uint32_t DISK_RESERVED_SPACE = 1048576; // disk reserved space 1Mb
38class FileUtils {39class FileUtils {
39public:40public:
40- static bool IsFileExist(const std::string &path);41+ static bool IsFileExist(const std::string& path);
41- static IdeErrorT WriteFile(const std::string &fileName, IdeSendBuffT data, uint32_t len, int64_t offset);42+ static IdeErrorT WriteFile(const std::string& fileName, IdeSendBuffT data, uint32_t len, int64_t offset);
42- static IdeErrorT CreateDir(const std::string &path);43+ static IdeErrorT CreateDir(const std::string& path);
43- static std::string GetFileDir(const std::string &path);44+ static std::string GetFileDir(const std::string& path);
44- static bool IsDiskFull(const std::string &path, uint64_t size);45+ static bool IsDiskFull(const std::string& path, uint64_t size);
45- static IdeErrorT GetFileName(const std::string &path, std::string &name);46+ static IdeErrorT GetFileName(const std::string& path, std::string& name);
46- static bool CheckNonCrossPath(const std::string &path);47+ static bool CheckNonCrossPath(const std::string& path);
47- static int32_t FilePathIsReal(const std::string &filePath, std::string &resultPath);48+ static int32_t FilePathIsReal(const std::string& filePath, std::string& resultPath);
48- static int32_t FileNameIsReal(const std::string &file, std::string &resultPath);49+ static int32_t FileNameIsReal(const std::string& file, std::string& resultPath);
49- static bool IsValidDirChar(const std::string &path);50+ static bool IsValidDirChar(const std::string& path);
50- static bool StartsWith(const std::string &s, const std::string &sub);51+ static bool StartsWith(const std::string& s, const std::string& sub);
51- static bool EndsWith(const std::string &s, const std::string &sub);52+ static bool EndsWith(const std::string& s, const std::string& sub);
52- static std::string ReplaceAll(std::string &base, const std::string &src, const std::string &dst);53+ static std::string ReplaceAll(std::string& base, const std::string& src, const std::string& dst);
53- static bool IsAbsolutePath(const std::string &path);54+ static bool IsAbsolutePath(const std::string& path);
54- static IdeErrorT AddMappingFileItem(const std::string &fileName, const std::string &hashValue);55+ static IdeErrorT AddMappingFileItem(const std::string& fileName, const std::string& hashValue);
55- static bool IsPathHasPermission(const std::string &path, std::string &errorMsg);56+ static bool IsPathHasPermission(const std::string& path, std::string& errorMsg);
56};57};
57-}58+} // namespace Adx
58-#endif59+#endif
@@ -91,4 +91,4 @@ void IdeXfree(const IdeMemHandle ptr)
91 free(ptr);91 free(ptr);
92 }92 }
93}93}
94-}94+} // namespace Adx
@@ -12,14 +12,15 @@
12#define ADX_COMMON_MEMORY_UTILS_H12#define ADX_COMMON_MEMORY_UTILS_H
13#include "extra_config.h"13#include "extra_config.h"
14 14 
15-#define IDE_XFREE_AND_SET_NULL(ptr) do { \15+#define IDE_XFREE_AND_SET_NULL(ptr) \
16- IdeXfree(ptr); \16+ do { \
17- ptr = nullptr; \17+ IdeXfree(ptr); \
18-} while (0)18+ ptr = nullptr; \
19+ } while (0)
19 20 
20namespace Adx {21namespace Adx {
21IdeMemHandle IdeXmalloc(size_t size);22IdeMemHandle IdeXmalloc(size_t size);
22IdeMemHandle IdeXrmalloc(const IdeMemHandle ptr, size_t ptrsize, size_t size);23IdeMemHandle IdeXrmalloc(const IdeMemHandle ptr, size_t ptrsize, size_t size);
23void IdeXfree(const IdeMemHandle ptr);24void IdeXfree(const IdeMemHandle ptr);
24-}25+} // namespace Adx
25-#endif // ADX_COMMON_MEMORY_UTILS_H26+#endif // ADX_COMMON_MEMORY_UTILS_H
@@ -14,7 +14,7 @@
14namespace Adx {14namespace Adx {
15namespace Common {15namespace Common {
16namespace Singleton {16namespace Singleton {
17-template<class T>17+template <class T>
18class Singleton {18class Singleton {
19public:19public:
20 static T& Instance()20 static T& Instance()
@@ -22,14 +22,14 @@ public:
22 static T instance;22 static T instance;
23 return instance;23 return instance;
24 }24 }
25- virtual ~Singleton() {} // dtor hidden25+ virtual ~Singleton() {} // dtor hidden
26- Singleton(Singleton const &) = delete; // copy ctor hidden26+ Singleton(Singleton const&) = delete; // copy ctor hidden
27- Singleton &operator=(Singleton const &) = delete; // assign op. hidden27+ Singleton& operator=(Singleton const&) = delete; // assign op. hidden
28protected:28protected:
29- Singleton() {} // ctor hidden29+ Singleton() {} // ctor hidden
30};30};
31-} // namespace singleton31+} // namespace Singleton
32-} // namespace common32+} // namespace Common
33-} // namespace analysis33+} // namespace Adx
34 34 
35#endif35#endif
@@ -18,7 +18,7 @@ namespace Adx {
18 * true: string all digital18 * true: string all digital
19 * false: string have other char19 * false: string have other char
20 */20 */
21-bool StringUtils::IsIntDigital(const std::string &digital)21+bool StringUtils::IsIntDigital(const std::string& digital)
22{22{
23 if (digital.empty()) {23 if (digital.empty()) {
24 return false;24 return false;
@@ -33,7 +33,7 @@ bool StringUtils::IsIntDigital(const std::string &digital)
33 return true;33 return true;
34}34}
35 35 
36-bool StringUtils::IpValid(const std::string &ipStr)36+bool StringUtils::IpValid(const std::string& ipStr)
37{37{
38 if (ipStr.empty()) {38 if (ipStr.empty()) {
39 return false;39 return false;
@@ -75,7 +75,7 @@ bool StringUtils::IpValid(const std::string &ipStr)
75 return true;75 return true;
76}76}
77 77 
78-bool StringUtils::ParseConnectInfo(const std::string &connectInfo, std::string &hostId, std::string &hostPid)78+bool StringUtils::ParseConnectInfo(const std::string& connectInfo, std::string& hostId, std::string& hostPid)
79{79{
80 std::string connectInfoStr;80 std::string connectInfoStr;
81 std::string::size_type idx;81 std::string::size_type idx;
@@ -84,7 +84,8 @@ bool StringUtils::ParseConnectInfo(const std::string &connectInfo, std::string &
84 84 
85 idx = connectInfoStr.find(";");85 idx = connectInfoStr.find(";");
86 if (idx == std::string::npos) {86 if (idx == std::string::npos) {
87- IDE_LOGE("invalid private info %s format, valid format like \"host:port;host_id;host_pid\"", connectInfo.c_str());87+ IDE_LOGE(
88+ "invalid private info %s format, valid format like \"host:port;host_id;host_pid\"", connectInfo.c_str());
88 return false;89 return false;
89 }90 }
90 IDE_LOGD("info str check host:port;host_id success");91 IDE_LOGD("info str check host:port;host_id success");
@@ -92,7 +93,8 @@ bool StringUtils::ParseConnectInfo(const std::string &connectInfo, std::string &
92 std::string hostIdHostPidStr = connectInfoStr.substr(idx + 1);93 std::string hostIdHostPidStr = connectInfoStr.substr(idx + 1);
93 idx = hostIdHostPidStr.find(";");94 idx = hostIdHostPidStr.find(";");
94 if (idx == std::string::npos) {95 if (idx == std::string::npos) {
95- IDE_LOGE("invalid private info %s format, valid format like \"host:port;host_id;host_pid\"", connectInfo.c_str());96+ IDE_LOGE(
97+ "invalid private info %s format, valid format like \"host:port;host_id;host_pid\"", connectInfo.c_str());
96 return false;98 return false;
97 }99 }
98 IDE_LOGD("info str check host_id;host_pid success");100 IDE_LOGD("info str check host_id;host_pid success");
@@ -114,4 +116,4 @@ bool StringUtils::ParseConnectInfo(const std::string &connectInfo, std::string &
114 IDE_LOGD("info str check host_id and host_pid number format success");116 IDE_LOGD("info str check host_id and host_pid number format success");
115 return true;117 return true;
116}118}
117-}119+} // namespace Adx
@@ -12,16 +12,14 @@
12#define ADX_STRING_UTILS_H12#define ADX_STRING_UTILS_H
13#include <string>13#include <string>
14namespace Adx {14namespace Adx {
15-constexpr uint32_t IP_VALID_PART_NUM = 3;15+constexpr uint32_t IP_VALID_PART_NUM = 3;
16-constexpr uint32_t IP_MAX_NUM = 255;16+constexpr uint32_t IP_MAX_NUM = 255;
17-constexpr uint32_t IP_MIN_NUM = 0;17+constexpr uint32_t IP_MIN_NUM = 0;
18class StringUtils {18class StringUtils {
19public:19public:
20- static bool IsIntDigital(const std::string &digital);20+ static bool IsIntDigital(const std::string& digital);
21- static bool IpValid(const std::string &ipStr);21+ static bool IpValid(const std::string& ipStr);
22- static bool ParseConnectInfo(const std::string &connectInfo,22+ static bool ParseConnectInfo(const std::string& connectInfo, std::string& hostId, std::string& hostPid);
23- std::string &hostId,
24- std::string &hostPid);
25};23};
26-}24+} // namespace Adx
27#endif25#endif
@@ -9,7 +9,7 @@
9 */9 */
10#include "thread.h"10#include "thread.h"
11namespace Adx {11namespace Adx {
12-static const int32_t WAIT_TID_TIME = 500;12+static const int32_t WAIT_TID_TIME = 500;
13/**13/**
14 * @brief create thread with default attributes14 * @brief create thread with default attributes
15 * @param [out]tid : thread id15 * @param [out]tid : thread id
@@ -19,7 +19,7 @@ static const int32_t WAIT_TID_TIME = 500;
19 * EN_OK: succ19 * EN_OK: succ
20 * other: failed20 * other: failed
21 */21 */
22-int32_t Thread::CreateTaskWithDefaultAttr(mmThread &tid, mmUserBlock_t &funcBlock)22+int32_t Thread::CreateTaskWithDefaultAttr(mmThread& tid, mmUserBlock_t& funcBlock)
23{23{
24 mmThreadAttr threadAttr = IDE_DAEMON_DEFAULT_THREAD_ATTR;24 mmThreadAttr threadAttr = IDE_DAEMON_DEFAULT_THREAD_ATTR;
25 return mmCreateTaskWithThreadAttr(&tid, &funcBlock, &threadAttr);25 return mmCreateTaskWithThreadAttr(&tid, &funcBlock, &threadAttr);
@@ -34,21 +34,15 @@ int32_t Thread::CreateTaskWithDefaultAttr(mmThread &tid, mmUserBlock_t &funcBloc
34 * EN_OK: succ34 * EN_OK: succ
35 * other: failed35 * other: failed
36 */36 */
37-int32_t Thread::CreateDetachTaskWithDefaultAttr(mmThread &tid, mmUserBlock_t &funcBlock)37+int32_t Thread::CreateDetachTaskWithDefaultAttr(mmThread& tid, mmUserBlock_t& funcBlock)
38{38{
39 mmThreadAttr threadAttr = IDE_DAEMON_DEFAULT_DETACH_THREAD_ATTR;39 mmThreadAttr threadAttr = IDE_DAEMON_DEFAULT_DETACH_THREAD_ATTR;
40 return mmCreateTaskWithThreadAttr(&tid, &funcBlock, &threadAttr);40 return mmCreateTaskWithThreadAttr(&tid, &funcBlock, &threadAttr);
41}41}
42 42 
43-Runnable::Runnable()43+Runnable::Runnable() : tid_(0), quit_(false), isStarted_(false), threadName_("adx") {}
44- : tid_(0), quit_(false), isStarted_(false), threadName_("adx")
45-{
46-}
47 44 
48-Runnable::~Runnable()45+Runnable::~Runnable() { Stop(); }
49-{
50- Stop();
51-}
52 46 
53int32_t Runnable::Start()47int32_t Runnable::Start()
54{48{
@@ -104,29 +98,20 @@ int32_t Runnable::Join()
104 return IDE_DAEMON_OK;98 return IDE_DAEMON_OK;
105}99}
106 100 
107-bool Runnable::IsQuit() const101+bool Runnable::IsQuit() const { return quit_; }
108-{
109- return quit_;
110-}
111 102 
112-void Runnable::SetThreadName(const std::string &name)103+void Runnable::SetThreadName(const std::string& name) { threadName_ = name; }
113-{
114- threadName_ = name;
115-}
116 104 
117-const std::string &Runnable::GetThreadName() const105+const std::string& Runnable::GetThreadName() const { return threadName_; }
118-{
119- return threadName_;
120-}
121 106 
122IdeThreadArg Runnable::Process(IdeThreadArg arg)107IdeThreadArg Runnable::Process(IdeThreadArg arg)
123{108{
124 if (arg == nullptr) {109 if (arg == nullptr) {
125 return nullptr;110 return nullptr;
126 }111 }
127- auto runnable = reinterpret_cast<Runnable *>(arg);112+ auto runnable = reinterpret_cast<Runnable*>(arg);
128 (void)mmSetCurrentThreadName(runnable->threadName_.c_str());113 (void)mmSetCurrentThreadName(runnable->threadName_.c_str());
129 runnable->Run();114 runnable->Run();
130 return nullptr;115 return nullptr;
131}116}
132-}117+} // namespace Adx
@@ -16,15 +16,15 @@
16#include "extra_config.h"16#include "extra_config.h"
17 17 
18namespace Adx {18namespace Adx {
19-const mmThreadAttr IDE_DAEMON_DEFAULT_THREAD_ATTR = {0, 0, 0, 0, 0, 1, 128 * 1024};19+const mmThreadAttr IDE_DAEMON_DEFAULT_THREAD_ATTR = {0, 0, 0, 0, 0, 1, 128 * 1024};
20const mmThreadAttr IDE_DAEMON_DEFAULT_DETACH_THREAD_ATTR = {1, 0, 0, 0, 0, 1, 128 * 1024};20const mmThreadAttr IDE_DAEMON_DEFAULT_DETACH_THREAD_ATTR = {1, 0, 0, 0, 0, 1, 128 * 1024};
21 21 
22class Thread {22class Thread {
23public:23public:
24- static int32_t CreateTask(mmThread &tid, mmUserBlock_t &funcBlock);24+ static int32_t CreateTask(mmThread& tid, mmUserBlock_t& funcBlock);
25- static int32_t CreateDetachTask(mmThread &tid, mmUserBlock_t &funcBlock);25+ static int32_t CreateDetachTask(mmThread& tid, mmUserBlock_t& funcBlock);
26- static int32_t CreateTaskWithDefaultAttr(mmThread &tid, mmUserBlock_t &funcBlock);26+ static int32_t CreateTaskWithDefaultAttr(mmThread& tid, mmUserBlock_t& funcBlock);
27- static int32_t CreateDetachTaskWithDefaultAttr(mmThread &tid, mmUserBlock_t &funcBlock);27+ static int32_t CreateDetachTaskWithDefaultAttr(mmThread& tid, mmUserBlock_t& funcBlock);
28};28};
29 29 
30class Runnable {30class Runnable {
@@ -36,19 +36,20 @@ public:
36 int32_t Stop();36 int32_t Stop();
37 int32_t Join();37 int32_t Join();
38 bool IsQuit() const;38 bool IsQuit() const;
39- void SetThreadName(const std::string &name);39+ void SetThreadName(const std::string& name);
40- const std::string &GetThreadName() const;40+ const std::string& GetThreadName() const;
41 41 
42protected:42protected:
43 virtual void Run() = 0;43 virtual void Run() = 0;
44 44 
45private:45private:
46 static IdeThreadArg Process(IdeThreadArg arg);46 static IdeThreadArg Process(IdeThreadArg arg);
47+ 
47private:48private:
48 mmThread tid_;49 mmThread tid_;
49 mutable bool quit_;50 mutable bool quit_;
50 mutable bool isStarted_;51 mutable bool isStarted_;
51 std::string threadName_;52 std::string threadName_;
52};53};
53-}54+} // namespace Adx
54#endif55#endif
@@ -18,7 +18,7 @@ namespace Adx {
18 * EN_OK: succ18 * EN_OK: succ
19 * other: failed19 * other: failed
20 */20 */
21-int32_t Thread::CreateTask(mmThread &tid, mmUserBlock_t &funcBlock)21+int32_t Thread::CreateTask(mmThread& tid, mmUserBlock_t& funcBlock)
22{22{
23 return CreateTaskWithDefaultAttr(tid, funcBlock);23 return CreateTaskWithDefaultAttr(tid, funcBlock);
24}24}
@@ -32,8 +32,8 @@ int32_t Thread::CreateTask(mmThread &tid, mmUserBlock_t &funcBlock)
32 * EN_OK: succ32 * EN_OK: succ
33 * other: failed33 * other: failed
34 */34 */
35-int32_t Thread::CreateDetachTask(mmThread &tid, mmUserBlock_t &funcBlock)35+int32_t Thread::CreateDetachTask(mmThread& tid, mmUserBlock_t& funcBlock)
36{36{
37 return CreateDetachTaskWithDefaultAttr(tid, funcBlock);37 return CreateDetachTaskWithDefaultAttr(tid, funcBlock);
38}38}
39-}39+} // namespace Adx
@@ -18,10 +18,7 @@ namespace Adx {
18 * EN_OK: succ18 * EN_OK: succ
19 * other: failed19 * other: failed
20 */20 */
21-int32_t Thread::CreateTask(mmThread &tid, mmUserBlock_t &funcBlock)21+int32_t Thread::CreateTask(mmThread& tid, mmUserBlock_t& funcBlock) { return mmCreateTask(&tid, &funcBlock); }
22-{
23- return mmCreateTask(&tid, &funcBlock);
24-}
25 22 
26/**23/**
27 * @brief create thread with detach24 * @brief create thread with detach
@@ -32,8 +29,8 @@ int32_t Thread::CreateTask(mmThread &tid, mmUserBlock_t &funcBlock)
32 * EN_OK: succ29 * EN_OK: succ
33 * other: failed30 * other: failed
34 */31 */
35-int32_t Thread::CreateDetachTask(mmThread &tid, mmUserBlock_t &funcBlock)32+int32_t Thread::CreateDetachTask(mmThread& tid, mmUserBlock_t& funcBlock)
36{33{
37 return mmCreateTaskWithDetach(&tid, &funcBlock);34 return mmCreateTaskWithDetach(&tid, &funcBlock);
38}35}
39-}36+} // namespace Adx
@@ -21,9 +21,9 @@ constexpr int32_t COMM_OPT_BLOCK = 0;
21constexpr int32_t COMM_OPT_NOBLOCK = 1;21constexpr int32_t COMM_OPT_NOBLOCK = 1;
22constexpr int32_t COMM_OPT_TIMEOUT = 2;22constexpr int32_t COMM_OPT_TIMEOUT = 2;
23constexpr OptHandle ADX_OPT_INVALID_HANDLE = -1;23constexpr OptHandle ADX_OPT_INVALID_HANDLE = -1;
24-const std::string OPT_DEVICE_KEY = "DeviceId";24+const std::string OPT_DEVICE_KEY = "DeviceId";
25-const std::string OPT_SERVICE_KEY = "ServiceType";25+const std::string OPT_SERVICE_KEY = "ServiceType";
26-const std::string OPT_PID_KEY = "Pid";26+const std::string OPT_PID_KEY = "Pid";
27 27 
28class AdxCommOpt {28class AdxCommOpt {
29public:29public:
@@ -31,19 +31,20 @@ public:
31 virtual ~AdxCommOpt() {}31 virtual ~AdxCommOpt() {}
32 virtual std::string CommOptName() = 0;32 virtual std::string CommOptName() = 0;
33 virtual OptType GetOptType() = 0;33 virtual OptType GetOptType() = 0;
34- virtual OptHandle OpenServer(const std::map<std::string, std::string> &info) = 0;34+ virtual OptHandle OpenServer(const std::map<std::string, std::string>& info) = 0;
35- virtual int32_t CloseServer(const OptHandle &handle) const = 0;35+ virtual int32_t CloseServer(const OptHandle& handle) const = 0;
36- virtual OptHandle OpenClient(const std::map<std::string, std::string> &info) = 0;36+ virtual OptHandle OpenClient(const std::map<std::string, std::string>& info) = 0;
37- virtual int32_t CloseClient(OptHandle &handle) const = 0;37+ virtual int32_t CloseClient(OptHandle& handle) const = 0;
38 virtual OptHandle Accept(const OptHandle handle) const = 0;38 virtual OptHandle Accept(const OptHandle handle) const = 0;
39- virtual OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string> &info) = 0;39+ virtual OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string>& info) = 0;
40- virtual int32_t Close(OptHandle &handle) const = 0;40+ virtual int32_t Close(OptHandle& handle) const = 0;
41 virtual int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) = 0;41 virtual int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) = 0;
42- virtual int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag) = 0;42+ virtual int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag) = 0;
43 virtual SharedPtr<AdxDevice> GetDevice() = 0;43 virtual SharedPtr<AdxDevice> GetDevice() = 0;
44 virtual void Timer(void) const = 0;44 virtual void Timer(void) const = 0;
45+ 
45protected:46protected:
46 SharedPtr<AdxDevice> device_ = nullptr;47 SharedPtr<AdxDevice> device_ = nullptr;
47};48};
48-}49+} // namespace Adx
49#endif50#endif
@@ -12,29 +12,28 @@
12namespace Adx {12namespace Adx {
13AdxCommOptManager::~AdxCommOptManager()13AdxCommOptManager::~AdxCommOptManager()
14{14{
15- std::unique_lock<std::mutex> lock {commOptMapMtx_};15+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
16 commOptMap_.clear();16 commOptMap_.clear();
17}17}
18 18 
19- 19+bool AdxCommOptManager::CommOptsRegister(std::unique_ptr<AdxCommOpt>& opt)
20-bool AdxCommOptManager::CommOptsRegister(std::unique_ptr<AdxCommOpt> &opt)
21{20{
22 if (opt == nullptr) {21 if (opt == nullptr) {
23 return false;22 return false;
24 }23 }
25 24 
26- std::unique_lock<std::mutex> lock {commOptMapMtx_};25+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
27 if (commOptMap_.find(opt->GetOptType()) == commOptMap_.end()) {26 if (commOptMap_.find(opt->GetOptType()) == commOptMap_.end()) {
28 commOptMap_[opt->GetOptType()] = std::move(opt);27 commOptMap_[opt->GetOptType()] = std::move(opt);
29 }28 }
30 return true;29 return true;
31}30}
32 31 
33-CommHandle AdxCommOptManager::OpenServer(OptType type, const std::map<std::string, std::string> &info)32+CommHandle AdxCommOptManager::OpenServer(OptType type, const std::map<std::string, std::string>& info)
34{33{
35 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);34 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
36 {35 {
37- std::unique_lock<std::mutex> lock {commOptMapMtx_};36+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
38 auto it = commOptMap_.find(type);37 auto it = commOptMap_.find(type);
39 if (it != commOptMap_.end()) {38 if (it != commOptMap_.end()) {
40 currCommOpt = it->second;39 currCommOpt = it->second;
@@ -49,11 +48,11 @@ CommHandle AdxCommOptManager::OpenServer(OptType type, const std::map<std::strin
49 return ADX_COMMOPT_INVALID_HANDLE(type);48 return ADX_COMMOPT_INVALID_HANDLE(type);
50}49}
51 50 
52-int32_t AdxCommOptManager::CloseServer(const CommHandle &handle) const51+int32_t AdxCommOptManager::CloseServer(const CommHandle& handle) const
53{52{
54 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);53 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
55 {54 {
56- std::unique_lock<std::mutex> lock {commOptMapMtx_};55+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
57 auto it = commOptMap_.find(handle.type);56 auto it = commOptMap_.find(handle.type);
58 if (it != commOptMap_.end()) {57 if (it != commOptMap_.end()) {
59 currCommOpt = it->second;58 currCommOpt = it->second;
@@ -65,11 +64,11 @@ int32_t AdxCommOptManager::CloseServer(const CommHandle &handle) const
65 return IDE_DAEMON_OK;64 return IDE_DAEMON_OK;
66}65}
67 66 
68-CommHandle AdxCommOptManager::OpenClient(OptType type, const std::map<std::string, std::string> &info)67+CommHandle AdxCommOptManager::OpenClient(OptType type, const std::map<std::string, std::string>& info)
69{68{
70 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);69 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
71 {70 {
72- std::unique_lock<std::mutex> lock {commOptMapMtx_};71+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
73 auto it = commOptMap_.find(type);72 auto it = commOptMap_.find(type);
74 if (it != commOptMap_.end()) {73 if (it != commOptMap_.end()) {
75 currCommOpt = it->second;74 currCommOpt = it->second;
@@ -83,11 +82,11 @@ CommHandle AdxCommOptManager::OpenClient(OptType type, const std::map<std::strin
83 return ADX_COMMOPT_INVALID_HANDLE(type);82 return ADX_COMMOPT_INVALID_HANDLE(type);
84}83}
85 84 
86-int32_t AdxCommOptManager::CloseClient(CommHandle &handle) const85+int32_t AdxCommOptManager::CloseClient(CommHandle& handle) const
87{86{
88 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);87 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
89 {88 {
90- std::unique_lock<std::mutex> lock {commOptMapMtx_};89+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
91 auto it = commOptMap_.find(handle.type);90 auto it = commOptMap_.find(handle.type);
92 if (it != commOptMap_.end()) {91 if (it != commOptMap_.end()) {
93 currCommOpt = it->second;92 currCommOpt = it->second;
@@ -99,11 +98,11 @@ int32_t AdxCommOptManager::CloseClient(CommHandle &handle) const
99 return IDE_DAEMON_OK;98 return IDE_DAEMON_OK;
100}99}
101 100 
102-CommHandle AdxCommOptManager::Accept(const CommHandle &handle) const101+CommHandle AdxCommOptManager::Accept(const CommHandle& handle) const
103{102{
104 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);103 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
105 {104 {
106- std::unique_lock<std::mutex> lock {commOptMapMtx_};105+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
107 auto it = commOptMap_.find(handle.type);106 auto it = commOptMap_.find(handle.type);
108 if (it != commOptMap_.end()) {107 if (it != commOptMap_.end()) {
109 currCommOpt = it->second;108 currCommOpt = it->second;
@@ -117,11 +116,11 @@ CommHandle AdxCommOptManager::Accept(const CommHandle &handle) const
117 return ADX_COMMOPT_INVALID_HANDLE(handle.type);116 return ADX_COMMOPT_INVALID_HANDLE(handle.type);
118}117}
119 118 
120-CommHandle AdxCommOptManager::Connect(const CommHandle &handle, const std::map<std::string, std::string> &info)119+CommHandle AdxCommOptManager::Connect(const CommHandle& handle, const std::map<std::string, std::string>& info)
121{120{
122 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);121 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
123 {122 {
124- std::unique_lock<std::mutex> lock {commOptMapMtx_};123+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
125 auto it = commOptMap_.find(handle.type);124 auto it = commOptMap_.find(handle.type);
126 if (it != commOptMap_.end()) {125 if (it != commOptMap_.end()) {
127 currCommOpt = it->second;126 currCommOpt = it->second;
@@ -135,11 +134,11 @@ CommHandle AdxCommOptManager::Connect(const CommHandle &handle, const std::map<s
135 return ADX_COMMOPT_INVALID_HANDLE(handle.type);134 return ADX_COMMOPT_INVALID_HANDLE(handle.type);
136}135}
137 136 
138-int32_t AdxCommOptManager::Close(CommHandle &handle) const137+int32_t AdxCommOptManager::Close(CommHandle& handle) const
139{138{
140 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);139 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
141 {140 {
142- std::unique_lock<std::mutex> lock {commOptMapMtx_};141+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
143 auto it = commOptMap_.find(handle.type);142 auto it = commOptMap_.find(handle.type);
144 if (it != commOptMap_.end()) {143 if (it != commOptMap_.end()) {
145 currCommOpt = it->second;144 currCommOpt = it->second;
@@ -151,11 +150,11 @@ int32_t AdxCommOptManager::Close(CommHandle &handle) const
151 return IDE_DAEMON_OK;150 return IDE_DAEMON_OK;
152}151}
153 152 
154-int32_t AdxCommOptManager::Write(const CommHandle &handle, IdeSendBuffT buffer, int32_t length, int32_t flag)153+int32_t AdxCommOptManager::Write(const CommHandle& handle, IdeSendBuffT buffer, int32_t length, int32_t flag)
155{154{
156 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);155 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
157 {156 {
158- std::unique_lock<std::mutex> lock {commOptMapMtx_};157+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
159 auto it = commOptMap_.find(handle.type);158 auto it = commOptMap_.find(handle.type);
160 if (it != commOptMap_.end()) {159 if (it != commOptMap_.end()) {
161 currCommOpt = it->second;160 currCommOpt = it->second;
@@ -168,11 +167,11 @@ int32_t AdxCommOptManager::Write(const CommHandle &handle, IdeSendBuffT buffer,
168 return -1;167 return -1;
169}168}
170 169 
171-int32_t AdxCommOptManager::Read(const CommHandle &handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag)170+int32_t AdxCommOptManager::Read(const CommHandle& handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag)
172{171{
173 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);172 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
174 {173 {
175- std::unique_lock<std::mutex> lock {commOptMapMtx_};174+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
176 auto it = commOptMap_.find(handle.type);175 auto it = commOptMap_.find(handle.type);
177 if (it != commOptMap_.end()) {176 if (it != commOptMap_.end()) {
178 currCommOpt = it->second;177 currCommOpt = it->second;
@@ -189,7 +188,7 @@ SharedPtr<AdxDevice> AdxCommOptManager::GetDevice(OptType type)
189{188{
190 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);189 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
191 {190 {
192- std::unique_lock<std::mutex> lock {commOptMapMtx_};191+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
193 auto it = commOptMap_.find(type);192 auto it = commOptMap_.find(type);
194 if (it != commOptMap_.end()) {193 if (it != commOptMap_.end()) {
195 currCommOpt = it->second;194 currCommOpt = it->second;
@@ -206,7 +205,7 @@ void AdxCommOptManager::Timer(OptType type) const
206{205{
207 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);206 std::shared_ptr<AdxCommOpt> currCommOpt(nullptr);
208 {207 {
209- std::unique_lock<std::mutex> lock {commOptMapMtx_};208+ std::unique_lock<std::mutex> lock{commOptMapMtx_};
210 auto it = commOptMap_.find(type);209 auto it = commOptMap_.find(type);
211 if (it != commOptMap_.end()) {210 if (it != commOptMap_.end()) {
212 currCommOpt = it->second;211 currCommOpt = it->second;
@@ -216,4 +215,4 @@ void AdxCommOptManager::Timer(OptType type) const
216 currCommOpt->Timer();215 currCommOpt->Timer();
217 }216 }
218}217}
219-}218+} // namespace Adx
@@ -19,26 +19,30 @@
19#include "device/adx_device.h"19#include "device/adx_device.h"
20#include "extra_config.h"20#include "extra_config.h"
21namespace Adx {21namespace Adx {
22-#define ADX_COMMOPT_INVALID_HANDLE(type) {(type), ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr}22+#define ADX_COMMOPT_INVALID_HANDLE(type) \
23+ { \
24+ (type), ADX_OPT_INVALID_HANDLE, NR_COMPONENTS, -1, nullptr \
25+ }
23 26 
24class AdxCommOptManager : public Adx::Common::Singleton::Singleton<AdxCommOptManager> {27class AdxCommOptManager : public Adx::Common::Singleton::Singleton<AdxCommOptManager> {
25public:28public:
26 ~AdxCommOptManager();29 ~AdxCommOptManager();
27- bool CommOptsRegister(std::unique_ptr<AdxCommOpt> &opt);30+ bool CommOptsRegister(std::unique_ptr<AdxCommOpt>& opt);
28- CommHandle OpenServer(OptType type, const std::map<std::string, std::string> &info);31+ CommHandle OpenServer(OptType type, const std::map<std::string, std::string>& info);
29- int32_t CloseServer(const CommHandle &handle) const;32+ int32_t CloseServer(const CommHandle& handle) const;
30- CommHandle OpenClient(OptType type, const std::map<std::string, std::string> &info);33+ CommHandle OpenClient(OptType type, const std::map<std::string, std::string>& info);
31- int32_t CloseClient(CommHandle &handle) const;34+ int32_t CloseClient(CommHandle& handle) const;
32- CommHandle Accept(const CommHandle &handle) const;35+ CommHandle Accept(const CommHandle& handle) const;
33- CommHandle Connect(const CommHandle &handle, const std::map<std::string, std::string> &info);36+ CommHandle Connect(const CommHandle& handle, const std::map<std::string, std::string>& info);
34- int32_t Close(CommHandle &handle) const;37+ int32_t Close(CommHandle& handle) const;
35- int32_t Write(const CommHandle &handle, IdeSendBuffT buffer, int32_t length, int32_t flag);38+ int32_t Write(const CommHandle& handle, IdeSendBuffT buffer, int32_t length, int32_t flag);
36- int32_t Read(const CommHandle &handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag);39+ int32_t Read(const CommHandle& handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag);
37 SharedPtr<AdxDevice> GetDevice(OptType type);40 SharedPtr<AdxDevice> GetDevice(OptType type);
38 void Timer(OptType type) const;41 void Timer(OptType type) const;
42+ 
39private:43private:
40 std::map<OptType, std::shared_ptr<AdxCommOpt>> commOptMap_;44 std::map<OptType, std::shared_ptr<AdxCommOpt>> commOptMap_;
41 mutable std::mutex commOptMapMtx_;45 mutable std::mutex commOptMapMtx_;
42};46};
43-}47+} // namespace Adx
44-#endif48+#endif
@@ -14,17 +14,11 @@
14#include "device/adx_hdc_device.h"14#include "device/adx_hdc_device.h"
15#include "mmpa_api.h"15#include "mmpa_api.h"
16namespace Adx {16namespace Adx {
17-std::string HdcCommOpt::CommOptName()17+std::string HdcCommOpt::CommOptName() { return "HDC"; }
18-{
19- return "HDC";
20-}
21 18 
22-OptType HdcCommOpt::GetOptType()19+OptType HdcCommOpt::GetOptType() { return OptType::COMM_HDC; }
23-{
24- return OptType::COMM_HDC;
25-}
26 20 
27-OptHandle HdcCommOpt::OpenServer(const std::map<std::string, std::string> &info)21+OptHandle HdcCommOpt::OpenServer(const std::map<std::string, std::string>& info)
28{22{
29 if (info.empty() || info.size() < 1) {23 if (info.empty() || info.size() < 1) {
30 IDE_LOGE("open server input invalid");24 IDE_LOGE("open server input invalid");
@@ -45,8 +39,8 @@ OptHandle HdcCommOpt::OpenServer(const std::map<std::string, std::string> &info)
45 IDE_LOGE("open server input parameter invalid, ServiceType not found");39 IDE_LOGE("open server input parameter invalid, ServiceType not found");
46 return ADX_OPT_INVALID_HANDLE;40 return ADX_OPT_INVALID_HANDLE;
47 }41 }
48- devId = std::stoi(device->second); // device id42+ devId = std::stoi(device->second); // device id
49- type = (drvHdcServiceType)std::stoi(service->second); // service type43+ type = (drvHdcServiceType)std::stoi(service->second); // service type
50 } catch (...) {44 } catch (...) {
51 IDE_LOGE("Value of device id or service type is not a number");45 IDE_LOGE("Value of device id or service type is not a number");
52 return ADX_OPT_INVALID_HANDLE;46 return ADX_OPT_INVALID_HANDLE;
@@ -65,18 +59,18 @@ OptHandle HdcCommOpt::OpenServer(const std::map<std::string, std::string> &info)
65 return (OptHandle)server;59 return (OptHandle)server;
66}60}
67 61 
68-int32_t HdcCommOpt::CloseServer(const OptHandle &handle) const62+int32_t HdcCommOpt::CloseServer(const OptHandle& handle) const
69{63{
70 if (handle == ADX_OPT_INVALID_HANDLE) {64 if (handle == ADX_OPT_INVALID_HANDLE) {
71 IDE_LOGE("close server input invalid");65 IDE_LOGE("close server input invalid");
72 return IDE_DAEMON_ERROR;66 return IDE_DAEMON_ERROR;
73 }67 }
74 68 
75- IDE_RUN_LOGI("close device server[%u]", static_cast<uint32_t>(handle));69+ IDE_RUN_LOGI("close device server[%u]", static_cast<uint32_t>(handle));
76 return HdcServerDestroy(reinterpret_cast<HDC_SERVER>(handle));70 return HdcServerDestroy(reinterpret_cast<HDC_SERVER>(handle));
77}71}
78 72 
79-OptHandle HdcCommOpt::OpenClient(const std::map<std::string, std::string> &info)73+OptHandle HdcCommOpt::OpenClient(const std::map<std::string, std::string>& info)
80{74{
81 if (info.empty() || info.size() == 0) {75 if (info.empty() || info.size() == 0) {
82 IDE_LOGE("open client input invalid");76 IDE_LOGE("open client input invalid");
@@ -90,7 +84,7 @@ OptHandle HdcCommOpt::OpenClient(const std::map<std::string, std::string> &info)
90 IDE_LOGE("open client input parameter invalid, ServiceType not found");84 IDE_LOGE("open client input parameter invalid, ServiceType not found");
91 return ADX_OPT_INVALID_HANDLE;85 return ADX_OPT_INVALID_HANDLE;
92 }86 }
93- type = (drvHdcServiceType)std::stoi(service->second); // service type87+ type = (drvHdcServiceType)std::stoi(service->second); // service type
94 } catch (...) {88 } catch (...) {
95 IDE_LOGE("Value of service type is not a number");89 IDE_LOGE("Value of service type is not a number");
96 return ADX_OPT_INVALID_HANDLE;90 return ADX_OPT_INVALID_HANDLE;
@@ -110,17 +104,15 @@ OptHandle HdcCommOpt::OpenClient(const std::map<std::string, std::string> &info)
110 return (OptHandle)session;104 return (OptHandle)session;
111}105}
112 106 
113-int32_t HdcCommOpt::CloseClient(OptHandle &handle) const107+int32_t HdcCommOpt::CloseClient(OptHandle& handle) const
114{108{
115- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,109+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "hdc close client input invalid");
116- "hdc close client input invalid");
117 return HdcClientDestroy((HDC_CLIENT)handle);110 return HdcClientDestroy((HDC_CLIENT)handle);
118}111}
119 112 
120OptHandle HdcCommOpt::Accept(const OptHandle handle) const113OptHandle HdcCommOpt::Accept(const OptHandle handle) const
121{114{
122- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return ADX_OPT_INVALID_HANDLE,115+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return ADX_OPT_INVALID_HANDLE, "hdc accept input invalid");
123- "hdc accept input invalid");
124 HDC_SESSION session = HdcServerAccept((HDC_SERVER)handle);116 HDC_SESSION session = HdcServerAccept((HDC_SERVER)handle);
125 if (session == nullptr) {117 if (session == nullptr) {
126 return ADX_OPT_INVALID_HANDLE;118 return ADX_OPT_INVALID_HANDLE;
@@ -129,12 +121,10 @@ OptHandle HdcCommOpt::Accept(const OptHandle handle) const
129 return (OptHandle)session;121 return (OptHandle)session;
130}122}
131 123 
132-OptHandle HdcCommOpt::Connect(const OptHandle handle, const std::map<std::string, std::string> &info)124+OptHandle HdcCommOpt::Connect(const OptHandle handle, const std::map<std::string, std::string>& info)
133{125{
134- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return ADX_OPT_INVALID_HANDLE,126+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return ADX_OPT_INVALID_HANDLE, "hdc connect input invalid");
135- "hdc connect input invalid");127+ IDE_CTRL_VALUE_FAILED(!info.empty(), return ADX_OPT_INVALID_HANDLE, "hdc connect input invalid");
136- IDE_CTRL_VALUE_FAILED(!info.empty(), return ADX_OPT_INVALID_HANDLE,
137- "hdc connect input invalid");
138 128 
139 int32_t devId;129 int32_t devId;
140 auto device = info.find(OPT_DEVICE_KEY);130 auto device = info.find(OPT_DEVICE_KEY);
@@ -148,8 +138,7 @@ OptHandle HdcCommOpt::Connect(const OptHandle handle, const std::map<std::string
148 IDE_LOGE("Value of device id is not a number");138 IDE_LOGE("Value of device id is not a number");
149 return ADX_OPT_INVALID_HANDLE;139 return ADX_OPT_INVALID_HANDLE;
150 }140 }
151- IDE_CTRL_VALUE_FAILED(devId >= 0 && devId < DEVICE_NUM_MAX,141+ IDE_CTRL_VALUE_FAILED(devId >= 0 && devId < DEVICE_NUM_MAX, return ADX_OPT_INVALID_HANDLE, "devId invalid");
152- return ADX_OPT_INVALID_HANDLE, "devId invalid");
153 HDC_SESSION session = nullptr;142 HDC_SESSION session = nullptr;
154 int32_t err;143 int32_t err;
155 try {144 try {
@@ -176,9 +165,10 @@ OptHandle HdcCommOpt::Connect(const OptHandle handle, const std::map<std::string
176 return (OptHandle)session;165 return (OptHandle)session;
177}166}
178 167 
179-int32_t HdcCommOpt::Close(OptHandle &handle) const168+int32_t HdcCommOpt::Close(OptHandle& handle) const
180{169{
181- IDE_CTRL_VALUE_WARN(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_OK,170+ IDE_CTRL_VALUE_WARN(
171+ handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_OK,
182 "hdc handle is invalid. maybe has been closed or not connected");172 "hdc handle is invalid. maybe has been closed or not connected");
183 173 
184 HDC_SESSION session = (HDC_SESSION)handle;174 HDC_SESSION session = (HDC_SESSION)handle;
@@ -190,8 +180,7 @@ int32_t HdcCommOpt::Close(OptHandle &handle) const
190 180 
191int32_t HdcCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag)181int32_t HdcCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag)
192{182{
193- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,183+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "hdc write input invalid");
194- "hdc write input invalid");
195 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "hdc write input invalid");184 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "hdc write input invalid");
196 IDE_CTRL_VALUE_FAILED(length > 0, return IDE_DAEMON_ERROR, "hdc write input invalid");185 IDE_CTRL_VALUE_FAILED(length > 0, return IDE_DAEMON_ERROR, "hdc write input invalid");
197 186 
@@ -202,10 +191,9 @@ int32_t HdcCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t l
202 return HdcWriteNb((HDC_SESSION)handle, buffer, length);191 return HdcWriteNb((HDC_SESSION)handle, buffer, length);
203}192}
204 193 
205-int32_t HdcCommOpt::Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag)194+int32_t HdcCommOpt::Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag)
206{195{
207- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,196+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "hdc read input invalid");
208- "hdc read input invalid");
209 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "hdc read input invalid");197 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "hdc read input invalid");
210 198 
211 if (flag == COMM_OPT_BLOCK) {199 if (flag == COMM_OPT_BLOCK) {
@@ -252,7 +240,5 @@ SharedPtr<AdxDevice> HdcCommOpt::GetDevice()
252 return device_;240 return device_;
253}241}
254 242 
255-void HdcCommOpt::Timer(void) const243+void HdcCommOpt::Timer(void) const {}
256-{244+} // namespace Adx
257-}
258-}
@@ -18,17 +18,17 @@ public:
18 ~HdcCommOpt() override {}18 ~HdcCommOpt() override {}
19 std::string CommOptName() override;19 std::string CommOptName() override;
20 OptType GetOptType() override;20 OptType GetOptType() override;
21- OptHandle OpenServer(const std::map<std::string, std::string> &info) override;21+ OptHandle OpenServer(const std::map<std::string, std::string>& info) override;
22- int32_t CloseServer(const OptHandle &handle) const override;22+ int32_t CloseServer(const OptHandle& handle) const override;
23 OptHandle Accept(const OptHandle handle) const override;23 OptHandle Accept(const OptHandle handle) const override;
24- OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string> &info) override;24+ OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string>& info) override;
25 int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) override;25 int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) override;
26- int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag) override;26+ int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag) override;
27- OptHandle OpenClient(const std::map<std::string, std::string> &info) override;27+ OptHandle OpenClient(const std::map<std::string, std::string>& info) override;
28- int32_t CloseClient(OptHandle &handle) const override;28+ int32_t CloseClient(OptHandle& handle) const override;
29- int32_t Close(OptHandle &handle) const override;29+ int32_t Close(OptHandle& handle) const override;
30 SharedPtr<AdxDevice> GetDevice() override;30 SharedPtr<AdxDevice> GetDevice() override;
31 void Timer(void) const override;31 void Timer(void) const override;
32};32};
33-}33+} // namespace Adx
34#endif34#endif
@@ -23,7 +23,7 @@ using namespace Adx;
23 * @return23 * @return
24 * sock fd24 * sock fd
25 */25 */
26-int32_t SockServerCreate(const std::string &adxLocalChan)26+int32_t SockServerCreate(const std::string& adxLocalChan)
27{27{
28 IDE_CTRL_VALUE_FAILED(!adxLocalChan.empty(), return -1, "local socket failed");28 IDE_CTRL_VALUE_FAILED(!adxLocalChan.empty(), return -1, "local socket failed");
29 int32_t sockFd = mmSocket(PF_LOCAL, SOCK_STREAM, 0);29 int32_t sockFd = mmSocket(PF_LOCAL, SOCK_STREAM, 0);
@@ -39,12 +39,13 @@ int32_t SockServerCreate(const std::string &adxLocalChan)
39 }39 }
40 40 
41 sockAddr.sun_family = AF_LOCAL;41 sockAddr.sun_family = AF_LOCAL;
42- ret = mmBind(sockFd, reinterpret_cast<mmSockAddr *>(&sockAddr),42+ ret = mmBind(
43+ sockFd, reinterpret_cast<mmSockAddr*>(&sockAddr),
43 offsetof(struct sockaddr_un, sun_path) + 1 + adxLocalChan.size());44 offsetof(struct sockaddr_un, sun_path) + 1 + adxLocalChan.size());
44 if (ret < 0) {45 if (ret < 0) {
45 char errBuf[MAX_ERRSTR_LEN + 1] = {0};46 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
46- IDE_LOGE("local server bind exception info : %s",47+ IDE_LOGE(
47- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));48+ "local server bind exception info : %s", mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
48 ADX_LOCAL_CLOSE_AND_SET_INVALID(sockFd);49 ADX_LOCAL_CLOSE_AND_SET_INVALID(sockFd);
49 return sockFd;50 return sockFd;
50 }51 }
@@ -52,8 +53,9 @@ int32_t SockServerCreate(const std::string &adxLocalChan)
52 ret = mmListen(sockFd, TCP_MAX_LISTEN_NUM);53 ret = mmListen(sockFd, TCP_MAX_LISTEN_NUM);
53 if (ret < 0) {54 if (ret < 0) {
54 char errBuf[MAX_ERRSTR_LEN + 1] = {0};55 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
55- IDE_LOGE("local server listen exception info : %s",56+ IDE_LOGE(
56- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));57+ "local server listen exception info : %s",
58+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
57 ADX_LOCAL_CLOSE_AND_SET_INVALID(sockFd);59 ADX_LOCAL_CLOSE_AND_SET_INVALID(sockFd);
58 return sockFd;60 return sockFd;
59 }61 }
@@ -70,7 +72,7 @@ int32_t SockServerCreate(const std::string &adxLocalChan)
70 * IDE_DAEMON_OK: destroy sock server success72 * IDE_DAEMON_OK: destroy sock server success
71 * IDE_DAEMON_ERROR: destroy sock server failed73 * IDE_DAEMON_ERROR: destroy sock server failed
72 */74 */
73-int32_t SockServerDestroy(int32_t &sockFd)75+int32_t SockServerDestroy(int32_t& sockFd)
74{76{
75 if (sockFd < 0) {77 if (sockFd < 0) {
76 return IDE_DAEMON_ERROR;78 return IDE_DAEMON_ERROR;
@@ -103,7 +105,7 @@ int32_t SockClientCreate()
103 * IDE_DAEMON_OK: destroy sock client success105 * IDE_DAEMON_OK: destroy sock client success
104 * IDE_DAEMON_ERROR: destroy sock client failed106 * IDE_DAEMON_ERROR: destroy sock client failed
105 */107 */
106-int32_t SockClientDestory(int32_t &sockFd)108+int32_t SockClientDestory(int32_t& sockFd)
107{109{
108 IDE_CTRL_VALUE_FAILED(sockFd >= 0, return IDE_DAEMON_ERROR, "sockFd invalid");110 IDE_CTRL_VALUE_FAILED(sockFd >= 0, return IDE_DAEMON_ERROR, "sockFd invalid");
109 111 
@@ -128,8 +130,8 @@ int32_t SockAccept(int32_t sockFd)
128 int32_t clientFd = mmAccept(sockFd, &clientAddr, &len);130 int32_t clientFd = mmAccept(sockFd, &clientAddr, &len);
129 if (clientFd < 0) {131 if (clientFd < 0) {
130 char errBuf[MAX_ERRSTR_LEN + 1] = {0};132 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
131- IDE_LOGE("local socket accept failed, info : %s",133+ IDE_LOGE(
132- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));134+ "local socket accept failed, info : %s", mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
133 }135 }
134 136 
135 return clientFd;137 return clientFd;
@@ -144,11 +146,10 @@ int32_t SockAccept(int32_t sockFd)
144 * sockFd: sock fd146 * sockFd: sock fd
145 * IDE_DAEMON_ERROR: sock connect failed147 * IDE_DAEMON_ERROR: sock connect failed
146 */148 */
147-int32_t SockConnect(int32_t sockFd, const std::string &adxLocalChan)149+int32_t SockConnect(int32_t sockFd, const std::string& adxLocalChan)
148{150{
149 IDE_CTRL_VALUE_FAILED(sockFd >= 0, return IDE_DAEMON_ERROR, "local socket failed");151 IDE_CTRL_VALUE_FAILED(sockFd >= 0, return IDE_DAEMON_ERROR, "local socket failed");
150- IDE_CTRL_VALUE_FAILED(!adxLocalChan.empty(), return IDE_DAEMON_ERROR,152+ IDE_CTRL_VALUE_FAILED(!adxLocalChan.empty(), return IDE_DAEMON_ERROR, "local socket failed");
151- "local socket failed");
152 struct sockaddr_un sockAddr;153 struct sockaddr_un sockAddr;
153 (void)memset_s(&sockAddr, sizeof(sockAddr), 0, sizeof(sockAddr));154 (void)memset_s(&sockAddr, sizeof(sockAddr), 0, sizeof(sockAddr));
154 int32_t ret = strcpy_s(sockAddr.sun_path + 1, sizeof(sockAddr.sun_path) - 1, adxLocalChan.c_str());155 int32_t ret = strcpy_s(sockAddr.sun_path + 1, sizeof(sockAddr.sun_path) - 1, adxLocalChan.c_str());
@@ -158,7 +159,8 @@ int32_t SockConnect(int32_t sockFd, const std::string &adxLocalChan)
158 }159 }
159 160 
160 sockAddr.sun_family = AF_LOCAL;161 sockAddr.sun_family = AF_LOCAL;
161- ret = mmConnect(sockFd, reinterpret_cast<mmSockAddr *>(&sockAddr),162+ ret = mmConnect(
163+ sockFd, reinterpret_cast<mmSockAddr*>(&sockAddr),
162 offsetof(struct sockaddr_un, sun_path) + 1 + adxLocalChan.size());164 offsetof(struct sockaddr_un, sun_path) + 1 + adxLocalChan.size());
163 if (ret < 0) {165 if (ret < 0) {
164 IDE_LOGE("local socket connect failed");166 IDE_LOGE("local socket connect failed");
@@ -212,7 +214,7 @@ static uint32_t SockHalRead(int32_t fd, IdeBuffT readBuf, int32_t recvLen, int32
212 * true: msg is valid214 * true: msg is valid
213 * false: msg is invalid215 * false: msg is invalid
214 */216 */
215-static bool CheckMsgValid(const MsgProto &proto)217+static bool CheckMsgValid(const MsgProto& proto)
216{218{
217 if (proto.headInfo != ADX_PROTO_MAGIC_VALUE) {219 if (proto.headInfo != ADX_PROTO_MAGIC_VALUE) {
218 return false;220 return false;
@@ -350,7 +352,7 @@ int32_t SockWrite(int32_t fd, IdeSendBuffT writeBuf, int32_t len, int32_t flag)
350 * ret: return val of mmClose352 * ret: return val of mmClose
351 * IDE_DAEMON_ERROR: sockFd invalid353 * IDE_DAEMON_ERROR: sockFd invalid
352 */354 */
353-int32_t SockClose(int32_t &sockFd)355+int32_t SockClose(int32_t& sockFd)
354{356{
355 if (sockFd < 0) {357 if (sockFd < 0) {
356 return IDE_DAEMON_ERROR;358 return IDE_DAEMON_ERROR;
@@ -359,4 +361,4 @@ int32_t SockClose(int32_t &sockFd)
359 int32_t ret = mmClose(sockFd);361 int32_t ret = mmClose(sockFd);
360 sockFd = -1;362 sockFd = -1;
361 return ret;363 return ret;
362-}364+}
@@ -12,20 +12,21 @@
12#include <cstdint>12#include <cstdint>
13#include <string>13#include <string>
14#include "extra_config.h"14#include "extra_config.h"
15-#define ADX_LOCAL_CLOSE_AND_SET_INVALID(fd) do { \15+#define ADX_LOCAL_CLOSE_AND_SET_INVALID(fd) \
16- if ((fd) >= 0) { \16+ do { \
17- (void)close(fd); \17+ if ((fd) >= 0) { \
18- fd = -1; \18+ (void)close(fd); \
19- } \19+ fd = -1; \
20-} while (0)20+ } \
21+ } while (0)
21 22 
22-int32_t SockServerCreate(const std::string &adxLocalChan);23+int32_t SockServerCreate(const std::string& adxLocalChan);
23-int32_t SockServerDestroy(int32_t &sockFd);24+int32_t SockServerDestroy(int32_t& sockFd);
24int32_t SockClientCreate();25int32_t SockClientCreate();
25-int32_t SockClientDestory(int32_t &sockFd);26+int32_t SockClientDestory(int32_t& sockFd);
26int32_t SockAccept(int32_t sockFd);27int32_t SockAccept(int32_t sockFd);
27-int32_t SockConnect(int32_t sockFd, const std::string &adxLocalChan);28+int32_t SockConnect(int32_t sockFd, const std::string& adxLocalChan);
28int32_t SockRead(int32_t fd, IdeRecvBuffT readBuf, IdeI32Pt recvLen, int32_t flag);29int32_t SockRead(int32_t fd, IdeRecvBuffT readBuf, IdeI32Pt recvLen, int32_t flag);
29int32_t SockWrite(int32_t fd, IdeSendBuffT writeBuf, int32_t len, int32_t flag);30int32_t SockWrite(int32_t fd, IdeSendBuffT writeBuf, int32_t len, int32_t flag);
30-int32_t SockClose(int32_t &sockFd);31+int32_t SockClose(int32_t& sockFd);
31-#endif32+#endif
@@ -18,10 +18,7 @@ namespace Adx {
18 * @return18 * @return
19 * "LOCAL_SOCK"19 * "LOCAL_SOCK"
20 */20 */
21-std::string SockCommOpt::CommOptName()21+std::string SockCommOpt::CommOptName() { return "LOCAL_SOCK"; }
22-{
23- return "LOCAL_SOCK";
24-}
25 22 
26/**23/**
27 * @brief get opt type24 * @brief get opt type
@@ -29,10 +26,7 @@ std::string SockCommOpt::CommOptName()
29 * @return26 * @return
30 * COMM_LOCAL27 * COMM_LOCAL
31 */28 */
32-OptType SockCommOpt::GetOptType()29+OptType SockCommOpt::GetOptType() { return OptType::COMM_LOCAL; }
33-{
34- return OptType::COMM_LOCAL;
35-}
36 30 
37/**31/**
38 * @brief open server32 * @brief open server
@@ -42,7 +36,7 @@ OptType SockCommOpt::GetOptType()
42 * handle: opt handle36 * handle: opt handle
43 * ADX_OPT_INVALID_HANDLE37 * ADX_OPT_INVALID_HANDLE
44 */38 */
45-OptHandle SockCommOpt::OpenServer(const std::map<std::string, std::string> &info)39+OptHandle SockCommOpt::OpenServer(const std::map<std::string, std::string>& info)
46{40{
47 OptHandle handle = ADX_OPT_INVALID_HANDLE;41 OptHandle handle = ADX_OPT_INVALID_HANDLE;
48 if (info.empty()) {42 if (info.empty()) {
@@ -53,7 +47,7 @@ OptHandle SockCommOpt::OpenServer(const std::map<std::string, std::string> &info
53 if (it == info.end()) {47 if (it == info.end()) {
54 return ADX_OPT_INVALID_HANDLE;48 return ADX_OPT_INVALID_HANDLE;
55 }49 }
56- int32_t fd = SockServerCreate(it->second);50+ int32_t fd = SockServerCreate(it->second);
57 if (fd < 0) {51 if (fd < 0) {
58 return handle;52 return handle;
59 }53 }
@@ -70,7 +64,7 @@ OptHandle SockCommOpt::OpenServer(const std::map<std::string, std::string> &info
70 * IDE_DAEMON_OK: close and destroy server success64 * IDE_DAEMON_OK: close and destroy server success
71 * IDE_DAEMON_ERROR: close and destroy server failed65 * IDE_DAEMON_ERROR: close and destroy server failed
72 */66 */
73-int32_t SockCommOpt::CloseServer(const OptHandle &handle) const67+int32_t SockCommOpt::CloseServer(const OptHandle& handle) const
74{68{
75 if (handle == ADX_OPT_INVALID_HANDLE) {69 if (handle == ADX_OPT_INVALID_HANDLE) {
76 return IDE_DAEMON_ERROR;70 return IDE_DAEMON_ERROR;
@@ -87,7 +81,7 @@ int32_t SockCommOpt::CloseServer(const OptHandle &handle) const
87 * @return81 * @return
88 * fd: opt handle82 * fd: opt handle
89 */83 */
90-OptHandle SockCommOpt::OpenClient(const std::map<std::string, std::string> &info)84+OptHandle SockCommOpt::OpenClient(const std::map<std::string, std::string>& info)
91{85{
92 UNUSED(info);86 UNUSED(info);
93 int32_t fd = SockClientCreate();87 int32_t fd = SockClientCreate();
@@ -102,7 +96,7 @@ OptHandle SockCommOpt::OpenClient(const std::map<std::string, std::string> &info
102 * IDE_DAEMON_OK: close and destroy client success96 * IDE_DAEMON_OK: close and destroy client success
103 * IDE_DAEMON_ERROR: close and destroy client failed97 * IDE_DAEMON_ERROR: close and destroy client failed
104 */98 */
105-int32_t SockCommOpt::CloseClient(OptHandle &handle) const99+int32_t SockCommOpt::CloseClient(OptHandle& handle) const
106{100{
107 if (handle == ADX_OPT_INVALID_HANDLE) {101 if (handle == ADX_OPT_INVALID_HANDLE) {
108 return IDE_DAEMON_ERROR;102 return IDE_DAEMON_ERROR;
@@ -145,7 +139,7 @@ OptHandle SockCommOpt::Accept(const OptHandle handle) const
145 * fd: opt handle139 * fd: opt handle
146 * ADX_OPT_INVALID_HANDLE140 * ADX_OPT_INVALID_HANDLE
147 */141 */
148-OptHandle SockCommOpt::Connect(const OptHandle handle, const std::map<std::string, std::string> &info)142+OptHandle SockCommOpt::Connect(const OptHandle handle, const std::map<std::string, std::string>& info)
149{143{
150 if (handle == ADX_OPT_INVALID_HANDLE) {144 if (handle == ADX_OPT_INVALID_HANDLE) {
151 return ADX_OPT_INVALID_HANDLE;145 return ADX_OPT_INVALID_HANDLE;
@@ -171,7 +165,7 @@ OptHandle SockCommOpt::Connect(const OptHandle handle, const std::map<std::strin
171 * IDE_DAEMON_OK: close success165 * IDE_DAEMON_OK: close success
172 * IDE_DAEMON_ERROR: close failed166 * IDE_DAEMON_ERROR: close failed
173 */167 */
174-int32_t SockCommOpt::Close(OptHandle &handle) const168+int32_t SockCommOpt::Close(OptHandle& handle) const
175{169{
176 if (handle == ADX_OPT_INVALID_HANDLE) {170 if (handle == ADX_OPT_INVALID_HANDLE) {
177 return IDE_DAEMON_ERROR;171 return IDE_DAEMON_ERROR;
@@ -195,8 +189,7 @@ int32_t SockCommOpt::Close(OptHandle &handle) const
195 */189 */
196int32_t SockCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag)190int32_t SockCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag)
197{191{
198- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,192+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "sock write input invalid");
199- "sock write input invalid");
200 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "sock write input invalid");193 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "sock write input invalid");
201 IDE_CTRL_VALUE_FAILED(length > 0, return IDE_DAEMON_ERROR, "sock write input invalid");194 IDE_CTRL_VALUE_FAILED(length > 0, return IDE_DAEMON_ERROR, "sock write input invalid");
202 195 
@@ -214,10 +207,9 @@ int32_t SockCommOpt::Write(const OptHandle handle, IdeSendBuffT buffer, int32_t
214 * IDE_DAEMON_OK: sock read success207 * IDE_DAEMON_OK: sock read success
215 * IDE_DAEMON_ERROR: sock read failed208 * IDE_DAEMON_ERROR: sock read failed
216 */209 */
217-int32_t SockCommOpt::Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t &length, int32_t /* flag */)210+int32_t SockCommOpt::Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t& length, int32_t /* flag */)
218{211{
219- IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR,212+ IDE_CTRL_VALUE_FAILED(handle != ADX_OPT_INVALID_HANDLE, return IDE_DAEMON_ERROR, "sock write input invalid");
220- "sock write input invalid");
221 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "sock write input invalid");213 IDE_CTRL_VALUE_FAILED(buffer != nullptr, return IDE_DAEMON_ERROR, "sock write input invalid");
222 214 
223 int32_t nonBlockFlag = 0;215 int32_t nonBlockFlag = 0;
@@ -237,7 +229,5 @@ SharedPtr<AdxDevice> SockCommOpt::GetDevice()
237 return device_;229 return device_;
238}230}
239 231 
240-void SockCommOpt::Timer(void) const232+void SockCommOpt::Timer(void) const {}
241-{233+} // namespace Adx
242-}
243-}
@@ -18,17 +18,17 @@ public:
18 ~SockCommOpt() override {}18 ~SockCommOpt() override {}
19 std::string CommOptName() override;19 std::string CommOptName() override;
20 OptType GetOptType() override;20 OptType GetOptType() override;
21- OptHandle OpenServer(const std::map<std::string, std::string> &info) override;21+ OptHandle OpenServer(const std::map<std::string, std::string>& info) override;
22- int32_t CloseServer(const OptHandle &handle) const override;22+ int32_t CloseServer(const OptHandle& handle) const override;
23- OptHandle OpenClient(const std::map<std::string, std::string> &info) override;23+ OptHandle OpenClient(const std::map<std::string, std::string>& info) override;
24- int32_t CloseClient(OptHandle &handle) const override;24+ int32_t CloseClient(OptHandle& handle) const override;
25 OptHandle Accept(const OptHandle handle) const override;25 OptHandle Accept(const OptHandle handle) const override;
26- OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string> &info) override;26+ OptHandle Connect(const OptHandle handle, const std::map<std::string, std::string>& info) override;
27- int32_t Close(OptHandle &handle) const override;27+ int32_t Close(OptHandle& handle) const override;
28- int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) override;28+ int32_t Write(const OptHandle handle, IdeSendBuffT buffer, int32_t length, int32_t flag) override;
29- int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t &length, int32_t flag) override;29+ int32_t Read(const OptHandle handle, IdeRecvBuffT buffer, int32_t& length, int32_t flag) override;
30 SharedPtr<AdxDevice> GetDevice() override;30 SharedPtr<AdxDevice> GetDevice() override;
31 void Timer(void) const override;31 void Timer(void) const override;
32};32};
33-}33+} // namespace Adx
34#endif34#endif
@@ -13,39 +13,33 @@
13namespace Adx {13namespace Adx {
14int32_t AdxCommonComponent::Init()14int32_t AdxCommonComponent::Init()
15{15{
16- IDE_CTRL_VALUE_WARN(init_ != nullptr, return IDE_DAEMON_ERROR, "common component %d null init",16+ IDE_CTRL_VALUE_WARN(
17+ init_ != nullptr, return IDE_DAEMON_ERROR, "common component %d null init",
17 static_cast<int32_t>(componentType_));18 static_cast<int32_t>(componentType_));
18 return init_();19 return init_();
19}20}
20 21 
21-const std::string AdxCommonComponent::GetInfo()22+const std::string AdxCommonComponent::GetInfo() { return "Common hdc server process"; }
22-{
23- return "Common hdc server process";
24-}
25 23 
26-ComponentType AdxCommonComponent::GetType()24+ComponentType AdxCommonComponent::GetType() { return componentType_; }
27-{
28- return componentType_;
29-}
30 25 
31-int32_t AdxCommonComponent::Process(const CommHandle &handle, const SharedPtr<MsgProto> &proto)26+int32_t AdxCommonComponent::Process(const CommHandle& handle, const SharedPtr<MsgProto>& proto)
32{27{
33- IDE_CTRL_VALUE_FAILED(process_ != nullptr, return IDE_DAEMON_ERROR, "common component %d process error",28+ IDE_CTRL_VALUE_FAILED(
29+ process_ != nullptr, return IDE_DAEMON_ERROR, "common component %d process error",
34 static_cast<int32_t>(componentType_));30 static_cast<int32_t>(componentType_));
35 return process_(&handle, proto.get(), sizeof(MsgProto) + proto->sliceLen);31 return process_(&handle, proto.get(), sizeof(MsgProto) + proto->sliceLen);
36}32}
37 33 
38int32_t AdxCommonComponent::UnInit()34int32_t AdxCommonComponent::UnInit()
39{35{
40- IDE_CTRL_VALUE_WARN(uninit_ != nullptr, return IDE_DAEMON_ERROR, "common component %d null uninit",36+ IDE_CTRL_VALUE_WARN(
37+ uninit_ != nullptr, return IDE_DAEMON_ERROR, "common component %d null uninit",
41 static_cast<int32_t>(componentType_));38 static_cast<int32_t>(componentType_));
42 return uninit_();39 return uninit_();
43}40}
44 41 
45-void AdxCommonComponent::SetType(ComponentType componentType)42+void AdxCommonComponent::SetType(ComponentType componentType) { componentType_ = componentType; }
46-{
47- componentType_ = componentType;
48-}
49 43 
50AdxCommonComponent::~AdxCommonComponent()44AdxCommonComponent::~AdxCommonComponent()
51{45{
@@ -53,4 +47,4 @@ AdxCommonComponent::~AdxCommonComponent()
53 process_ = nullptr;47 process_ = nullptr;
54 uninit_ = nullptr;48 uninit_ = nullptr;
55}49}
56-}50+} // namespace Adx
@@ -13,21 +13,23 @@
13namespace Adx {13namespace Adx {
14class AdxCommonComponent : public AdxComponent {14class AdxCommonComponent : public AdxComponent {
15public:15public:
16- AdxCommonComponent(AdxComponentInit init, AdxComponentProcess process, AdxComponentUnInit uninit,16+ AdxCommonComponent(
17- ComponentType componentType) : init_(init), process_(process), uninit_(uninit),17+ AdxComponentInit init, AdxComponentProcess process, AdxComponentUnInit uninit, ComponentType componentType)
18- componentType_(componentType) {}18+ : init_(init), process_(process), uninit_(uninit), componentType_(componentType)
19+ {}
19 ~AdxCommonComponent() override;20 ~AdxCommonComponent() override;
20 int32_t Init() override;21 int32_t Init() override;
21 const std::string GetInfo() override;22 const std::string GetInfo() override;
22 ComponentType GetType() override;23 ComponentType GetType() override;
23- int32_t Process(const CommHandle &handle, const SharedPtr<MsgProto> &proto) override;24+ int32_t Process(const CommHandle& handle, const SharedPtr<MsgProto>& proto) override;
24 int32_t UnInit() override;25 int32_t UnInit() override;
25 void SetType(ComponentType componentType);26 void SetType(ComponentType componentType);
27+ 
26private:28private:
27 AdxComponentInit init_;29 AdxComponentInit init_;
28 AdxComponentProcess process_;30 AdxComponentProcess process_;
29 AdxComponentUnInit uninit_;31 AdxComponentUnInit uninit_;
30 ComponentType componentType_;32 ComponentType componentType_;
31};33};
32-}34+} // namespace Adx
33-#endif // ADX_COMMON_COMMON_COMPONENT_H35+#endif // ADX_COMMON_COMMON_COMPONENT_H
@@ -17,26 +17,25 @@
17#include "adx_msg.h"17#include "adx_msg.h"
18namespace Adx {18namespace Adx {
19struct AdxComponentMap {19struct AdxComponentMap {
20- ComponentType cmptType; // component type20+ ComponentType cmptType; // component type
21- CmdClassT cmdType; // request type21+ CmdClassT cmdType; // request type
22- std::string cmptName; // name of request22+ std::string cmptName; // name of request
23- std::string oprtName; // name of record opreate log23+ std::string oprtName; // name of record opreate log
24};24};
25 25 
26const AdxComponentMap g_componentsInfo[] = {26const AdxComponentMap g_componentsInfo[] = {
27- {ComponentType::COMPONENT_GETD_FILE, IDE_FILE_GETD_REQ, "file_getd", "TransferFile" },27+ {ComponentType::COMPONENT_GETD_FILE, IDE_FILE_GETD_REQ, "file_getd", "TransferFile"},
28- {ComponentType::COMPONENT_LOG_BACKHAUL, IDE_LOG_BACKHAUL_REQ, "log_backhaul", "BackhaulLog" },28+ {ComponentType::COMPONENT_LOG_BACKHAUL, IDE_LOG_BACKHAUL_REQ, "log_backhaul", "BackhaulLog"},
29- {ComponentType::COMPONENT_LOG_LEVEL, IDE_LOG_LEVEL_REQ, "log_level", "OperateLevel" },29+ {ComponentType::COMPONENT_LOG_LEVEL, IDE_LOG_LEVEL_REQ, "log_level", "OperateLevel"},
30- {ComponentType::COMPONENT_DUMP, IDE_DUMP_REQ, "dump", "DataDump" },30+ {ComponentType::COMPONENT_DUMP, IDE_DUMP_REQ, "dump", "DataDump"},
31- {ComponentType::COMPONENT_TRACE, IDE_TRACE_REQ, "trace", "Trace" },31+ {ComponentType::COMPONENT_TRACE, IDE_TRACE_REQ, "trace", "Trace"},
32- {ComponentType::COMPONENT_MSNPUREPORT, IDE_MSN_REQ, "msnpureport", "Msnpureport" },32+ {ComponentType::COMPONENT_MSNPUREPORT, IDE_MSN_REQ, "msnpureport", "Msnpureport"},
33- {ComponentType::COMPONENT_HBM_DETECT, IDE_HBM_REQ, "hbm_detect", "HbmDetect" },33+ {ComponentType::COMPONENT_HBM_DETECT, IDE_HBM_REQ, "hbm_detect", "HbmDetect"},
34- {ComponentType::COMPONENT_SYS_GET, IDE_SYS_GET_REQ, "sys_get", "SysGet" },34+ {ComponentType::COMPONENT_SYS_GET, IDE_SYS_GET_REQ, "sys_get", "SysGet"},
35- {ComponentType::COMPONENT_SYS_REPORT, IDE_SYS_REPORT_REQ, "sys_report", "SysReport" },35+ {ComponentType::COMPONENT_SYS_REPORT, IDE_SYS_REPORT_REQ, "sys_report", "SysReport"},
36- {ComponentType::COMPONENT_FILE_REPORT, IDE_FILE_REPORT_REQ, "file_report", "FileReport" },36+ {ComponentType::COMPONENT_FILE_REPORT, IDE_FILE_REPORT_REQ, "file_report", "FileReport"},
37- {ComponentType::COMPONENT_CPU_DETECT, IDE_CPU_DETECT_REQ, "cpu_detect", "CpuDetect" },37+ {ComponentType::COMPONENT_CPU_DETECT, IDE_CPU_DETECT_REQ, "cpu_detect", "CpuDetect"},
38- {ComponentType::COMPONENT_DETECT_LIB_LOAD , IDE_DETECT_LIB_LOAD_REQ, "lib_load", "LibLoad" }38+ {ComponentType::COMPONENT_DETECT_LIB_LOAD, IDE_DETECT_LIB_LOAD_REQ, "lib_load", "LibLoad"}};
39-};
40 39 
41class AdxComponent {40class AdxComponent {
42public:41public:
@@ -45,9 +44,9 @@ public:
45 virtual int32_t Init() = 0;44 virtual int32_t Init() = 0;
46 virtual const std::string GetInfo() { return "None"; }45 virtual const std::string GetInfo() { return "None"; }
47 virtual ComponentType GetType() = 0;46 virtual ComponentType GetType() = 0;
48- virtual int32_t Process(const CommHandle &handle, const SharedPtr<MsgProto> &req) = 0;47+ virtual int32_t Process(const CommHandle& handle, const SharedPtr<MsgProto>& req) = 0;
49 virtual int32_t UnInit() = 0;48 virtual int32_t UnInit() = 0;
50 virtual int32_t Terminate() { return 0; }49 virtual int32_t Terminate() { return 0; }
51};50};
52-}51+} // namespace Adx
53-#endif // ADX_COMMON_COMPONENT_H52+#endif // ADX_COMMON_COMPONENT_H
@@ -14,11 +14,12 @@
14#include "extra_config.h"14#include "extra_config.h"
15#include "ascend_hal.h"15#include "ascend_hal.h"
16using namespace Adx;16using namespace Adx;
17-int32_t AdxRegisterService(int32_t serverType, ComponentType componentType, AdxComponentInit init,17+int32_t AdxRegisterService(
18- AdxComponentProcess process, AdxComponentUnInit uninit)18+ int32_t serverType, ComponentType componentType, AdxComponentInit init, AdxComponentProcess process,
19+ AdxComponentUnInit uninit)
19{20{
20 std::unique_ptr<AdxComponent> commonComponent(new (std::nothrow)21 std::unique_ptr<AdxComponent> commonComponent(new (std::nothrow)
21- AdxCommonComponent(init, process, uninit, componentType));22+ AdxCommonComponent(init, process, uninit, componentType));
22 IDE_CTRL_VALUE_FAILED(commonComponent != nullptr, return IDE_DAEMON_ERROR, "create common component error");23 IDE_CTRL_VALUE_FAILED(commonComponent != nullptr, return IDE_DAEMON_ERROR, "create common component error");
23 return AdxRegisterComponentFunc(static_cast<drvHdcServiceType>(serverType), commonComponent);24 return AdxRegisterComponentFunc(static_cast<drvHdcServiceType>(serverType), commonComponent);
24}25}
@@ -28,12 +29,9 @@ int32_t AdxUnRegisterService(int32_t serverType, ComponentType componentType)
28 return AdxComponentServerCleanup(static_cast<drvHdcServiceType>(serverType), componentType);29 return AdxComponentServerCleanup(static_cast<drvHdcServiceType>(serverType), componentType);
29}30}
30 31 
31-int32_t AdxServiceStartup(ServerInitInfo info)32+int32_t AdxServiceStartup(ServerInitInfo info) { return AdxComponentServerStartup(info); }
32-{
33- return AdxComponentServerStartup(info);
34-}
35 33 
36int32_t AdxServiceCleanup(int32_t serverType)34int32_t AdxServiceCleanup(int32_t serverType)
37{35{
38 return AdxComponentServerCleanup(static_cast<drvHdcServiceType>(serverType));36 return AdxComponentServerCleanup(static_cast<drvHdcServiceType>(serverType));
39-}37+}
@@ -17,7 +17,7 @@ namespace Adx {
17namespace {17namespace {
18constexpr uint32_t RECONNECT_TIMES = 3U;18constexpr uint32_t RECONNECT_TIMES = 3U;
19constexpr uint32_t MAX_PROCESS_DRAIN_TIMEOUT = 5000U; // max 5s to wait the process threads over19constexpr uint32_t MAX_PROCESS_DRAIN_TIMEOUT = 5000U; // max 5s to wait the process threads over
20-}20+} // namespace
21 21 
22AdxServerManager::AdxServerManager() noexcept22AdxServerManager::AdxServerManager() noexcept
23 : pid_(0),23 : pid_(0),
@@ -47,12 +47,9 @@ AdxServerManager::AdxServerManager(int32_t loadMode, int32_t deviceId) noexcept
47 servers_.clear();47 servers_.clear();
48}48}
49 49 
50-AdxServerManager::~AdxServerManager()50+AdxServerManager::~AdxServerManager() { (void)Exit(); }
51-{
52- (void)Exit();
53-}
54 51 
55-bool AdxServerManager::RegisterEpoll(std::unique_ptr<AdxEpoll> &epoll)52+bool AdxServerManager::RegisterEpoll(std::unique_ptr<AdxEpoll>& epoll)
56{53{
57 if (epoll == nullptr) {54 if (epoll == nullptr) {
58 IDE_LOGE("register epoll input error");55 IDE_LOGE("register epoll input error");
@@ -67,8 +64,7 @@ bool AdxServerManager::RegisterEpoll(std::unique_ptr<AdxEpoll> &epoll)
67 return false;64 return false;
68}65}
69 66 
70-bool AdxServerManager::RegisterCommOpt(std::unique_ptr<AdxCommOpt> &opt,67+bool AdxServerManager::RegisterCommOpt(std::unique_ptr<AdxCommOpt>& opt, const std::string& info)
71- const std::string &info)
72{68{
73 if (opt == nullptr) {69 if (opt == nullptr) {
74 IDE_LOGE("register commopt input error");70 IDE_LOGE("register commopt input error");
@@ -80,7 +76,7 @@ bool AdxServerManager::RegisterCommOpt(std::unique_ptr<AdxCommOpt> &opt,
80 return AdxCommOptManager::Instance().CommOptsRegister(opt);76 return AdxCommOptManager::Instance().CommOptsRegister(opt);
81}77}
82 78 
83-bool AdxServerManager::ServerInit(const std::map<std::string, std::string> &info)79+bool AdxServerManager::ServerInit(const std::map<std::string, std::string>& info)
84{80{
85 EpollEvent event;81 EpollEvent event;
86 if (epoll_ == nullptr || type_ == OptType::NR_COMM || info.empty()) {82 if (epoll_ == nullptr || type_ == OptType::NR_COMM || info.empty()) {
@@ -138,7 +134,7 @@ bool AdxServerManager::ServerUnInit(OptHandle epHandle)
138 return true;134 return true;
139}135}
140 136 
141-bool AdxServerManager::ComponentAdd(std::unique_ptr<AdxComponent> &comp)137+bool AdxServerManager::ComponentAdd(std::unique_ptr<AdxComponent>& comp)
142{138{
143 if (comp == nullptr) {139 if (comp == nullptr) {
144 IDE_LOGE("add component input error");140 IDE_LOGE("add component input error");
@@ -217,12 +213,13 @@ void AdxServerManager::HandleConnectEvent(CommHandle handle)
217 EpollHandle epHandle = ADX_INVALID_HANDLE;213 EpollHandle epHandle = ADX_INVALID_HANDLE;
218 if (handleQue_.Pop(epHandle) == true) {214 if (handleQue_.Pop(epHandle) == true) {
219 IDE_LOGD("handle queue pop: %lx", epHandle);215 IDE_LOGD("handle queue pop: %lx", epHandle);
220- CommHandle curHandle {type_, epHandle, NR_COMPONENTS, -1, nullptr};216+ CommHandle curHandle{type_, epHandle, NR_COMPONENTS, -1, nullptr};
221 (void)AdxCommOptManager::Instance().Close(curHandle);217 (void)AdxCommOptManager::Instance().Close(curHandle);
222 }218 }
223 char errBuf[MAX_ERRSTR_LEN + 1] = {0};219 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
224- IDE_LOGE("create component process thread failed, strerror is %s",220+ IDE_LOGE(
225- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));221+ "create component process thread failed, strerror is %s",
222+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
226 }223 }
227}224}
228bool AdxServerManager::ComponentWaitEvent()225bool AdxServerManager::ComponentWaitEvent()
@@ -276,7 +273,7 @@ IdeThreadArg AdxServerManager::ThreadProcess(IdeThreadArg arg)
276 if (arg == nullptr) {273 if (arg == nullptr) {
277 return nullptr;274 return nullptr;
278 }275 }
279- auto runnable = reinterpret_cast<AdxServerManager *>(arg);276+ auto runnable = reinterpret_cast<AdxServerManager*>(arg);
280 (void)mmSetCurrentThreadName("adx_component_process");277 (void)mmSetCurrentThreadName("adx_component_process");
281 runnable->ComponentProcess();278 runnable->ComponentProcess();
282 return nullptr;279 return nullptr;
@@ -284,7 +281,7 @@ IdeThreadArg AdxServerManager::ThreadProcess(IdeThreadArg arg)
284 281 
285void AdxServerManager::ComponentProcess()282void AdxServerManager::ComponentProcess()
286{283{
287- const std::shared_ptr<void> processGuard(nullptr, [this](void *) {284+ const std::shared_ptr<void> processGuard(nullptr, [this](void*) {
288 std::lock_guard<std::mutex> lck(this->processMtx_);285 std::lock_guard<std::mutex> lck(this->processMtx_);
289 --this->processingNum_;286 --this->processingNum_;
290 this->processCv_.notify_all();287 this->processCv_.notify_all();
@@ -312,21 +309,22 @@ void AdxServerManager::ComponentProcess()
312 ComponentType comp = ComponentType::NR_COMPONENTS;309 ComponentType comp = ComponentType::NR_COMPONENTS;
313 bool ret = SubComponentProcess(*handle, comp);310 bool ret = SubComponentProcess(*handle, comp);
314 if (((comp != ComponentType::COMPONENT_LOG_BACKHAUL) && (comp != ComponentType::COMPONENT_TRACE) &&311 if (((comp != ComponentType::COMPONENT_LOG_BACKHAUL) && (comp != ComponentType::COMPONENT_TRACE) &&
315- (comp != ComponentType::COMPONENT_SYS_REPORT) && (comp != ComponentType::COMPONENT_FILE_REPORT) &&312+ (comp != ComponentType::COMPONENT_SYS_REPORT) && (comp != ComponentType::COMPONENT_FILE_REPORT) &&
316- (comp != ComponentType::COMPONENT_CPU_DETECT)) || !ret) {313+ (comp != ComponentType::COMPONENT_CPU_DETECT)) ||
314+ !ret) {
317 (void)AdxCommOptManager::Instance().Close(*handle);315 (void)AdxCommOptManager::Instance().Close(*handle);
318 handle->session = ADX_OPT_INVALID_HANDLE;316 handle->session = ADX_OPT_INVALID_HANDLE;
319 IDE_XFREE_AND_SET_NULL(handle);317 IDE_XFREE_AND_SET_NULL(handle);
320 }318 }
321}319}
322 320 
323-bool AdxServerManager::SubComponentProcess(CommHandle &handle, ComponentType &comp)321+bool AdxServerManager::SubComponentProcess(CommHandle& handle, ComponentType& comp)
324{322{
325- MsgProto *req = nullptr;323+ MsgProto* req = nullptr;
326 int32_t length = 0;324 int32_t length = 0;
327 325 
328- int32_t ret = AdxCommOptManager::Instance().Read(handle, reinterpret_cast<IdeRecvBuffT>(&req), length,326+ int32_t ret =
329- COMM_OPT_NOBLOCK);327+ AdxCommOptManager::Instance().Read(handle, reinterpret_cast<IdeRecvBuffT>(&req), length, COMM_OPT_NOBLOCK);
330 if (ret == IDE_DAEMON_ERROR || req == nullptr || length <= 0) {328 if (ret == IDE_DAEMON_ERROR || req == nullptr || length <= 0) {
331 IDE_LOGE("receive request failed ret %d, length(%d bytes)", ret, length);329 IDE_LOGE("receive request failed ret %d, length(%d bytes)", ret, length);
332 return false;330 return false;
@@ -352,8 +350,8 @@ bool AdxServerManager::SubComponentProcess(CommHandle &handle, ComponentType &co
352 return DispatchComponent(handle, msgPtr, session, comp);350 return DispatchComponent(handle, msgPtr, session, comp);
353}351}
354 352 
355-bool AdxServerManager::DispatchComponent(CommHandle &handle, SharedPtr<MsgProto> &msgPtr, HDC_SESSION session,353+bool AdxServerManager::DispatchComponent(
356- ComponentType &comp)354+ CommHandle& handle, SharedPtr<MsgProto>& msgPtr, HDC_SESSION session, ComponentType& comp)
357{355{
358 comp = GetComponentTypeByReqType(static_cast<CmdClassT>(msgPtr->reqType));356 comp = GetComponentTypeByReqType(static_cast<CmdClassT>(msgPtr->reqType));
359 // hold a reference of the component, it keeps alive until this process is over357 // hold a reference of the component, it keeps alive until this process is over
@@ -414,8 +412,7 @@ void AdxServerManager::TimerProcess()
414 std::lock_guard<std::mutex> lck(serverMtx_);412 std::lock_guard<std::mutex> lck(serverMtx_);
415 for (const auto& deviceId : devLogIds) {413 for (const auto& deviceId : devLogIds) {
416 // filter the device that created HDC server(or not the specified device)414 // filter the device that created HDC server(or not the specified device)
417- if (servers_.find(deviceId) != servers_.end() ||415+ if (servers_.find(deviceId) != servers_.end() || !(deviceId_ == -1 || std::to_string(deviceId_) == deviceId)) {
418- !(deviceId_ == -1 || std::to_string(deviceId_) == deviceId)) {
419 continue;416 continue;
420 }417 }
421 418 
@@ -517,22 +514,18 @@ int32_t AdxServerManager::Exit()
517void AdxServerManager::WaitProcessDrained()514void AdxServerManager::WaitProcessDrained()
518{515{
519 std::unique_lock<std::mutex> lck(processMtx_);516 std::unique_lock<std::mutex> lck(processMtx_);
520- if (!processCv_.wait_for(lck, std::chrono::milliseconds(MAX_PROCESS_DRAIN_TIMEOUT),517+ if (!processCv_.wait_for(lck, std::chrono::milliseconds(MAX_PROCESS_DRAIN_TIMEOUT), [this]() {
521- [this]() { return this->processingNum_ == 0U; })) {518+ return this->processingNum_ == 0U;
522- IDE_LOGW("still have %u component process threads running after waiting %ums",519+ })) {
523- processingNum_, MAX_PROCESS_DRAIN_TIMEOUT);520+ IDE_LOGW(
521+ "still have %u component process threads running after waiting %ums", processingNum_,
522+ MAX_PROCESS_DRAIN_TIMEOUT);
524 }523 }
525}524}
526 525 
527-void AdxServerManager::SetMode(int32_t loadMode)526+void AdxServerManager::SetMode(int32_t loadMode) { loadMode_ = loadMode; }
528-{
529- loadMode_ = loadMode;
530-}
531 527 
532-void AdxServerManager::SetDeviceId(int32_t deviceId)528+void AdxServerManager::SetDeviceId(int32_t deviceId) { deviceId_ = deviceId; }
533-{
534- deviceId_ = deviceId;
535-}
536 529 
537bool AdxServerManager::IsLinkOverload(HDC_SESSION session) const530bool AdxServerManager::IsLinkOverload(HDC_SESSION session) const
538{531{
@@ -566,4 +559,4 @@ bool AdxServerManager::WaitServerInitted() const
566 559 
567 return false;560 return false;
568}561}
569-}562+} // namespace Adx
@@ -31,31 +31,32 @@ public:
31 AdxServerManager() noexcept;31 AdxServerManager() noexcept;
32 explicit AdxServerManager(int32_t loadMode, int32_t deviceId) noexcept;32 explicit AdxServerManager(int32_t loadMode, int32_t deviceId) noexcept;
33 ~AdxServerManager();33 ~AdxServerManager();
34- bool RegisterEpoll(std::unique_ptr<AdxEpoll> &epoll);34+ bool RegisterEpoll(std::unique_ptr<AdxEpoll>& epoll);
35- bool RegisterCommOpt(std::unique_ptr<AdxCommOpt> &opt,35+ bool RegisterCommOpt(std::unique_ptr<AdxCommOpt>& opt, const std::string& info);
36- const std::string &info);36+ bool ComponentAdd(std::unique_ptr<AdxComponent>& comp);
37- bool ComponentAdd(std::unique_ptr<AdxComponent> &comp);
38 bool ComponentErase(ComponentType type);37 bool ComponentErase(ComponentType type);
39 bool ComponentInit() const;38 bool ComponentInit() const;
40 bool ComponentWaitEvent();39 bool ComponentWaitEvent();
41 void Run();40 void Run();
42 void ComponentProcess();41 void ComponentProcess();
43- bool SubComponentProcess(CommHandle &handle, ComponentType &comp);42+ bool SubComponentProcess(CommHandle& handle, ComponentType& comp);
44 static IdeThreadArg ThreadProcess(IdeThreadArg arg);43 static IdeThreadArg ThreadProcess(IdeThreadArg arg);
45 int32_t Exit();44 int32_t Exit();
46 void SetMode(int32_t loadMode);45 void SetMode(int32_t loadMode);
47 void SetDeviceId(int32_t deviceId);46 void SetDeviceId(int32_t deviceId);
48 bool WaitServerInitted() const;47 bool WaitServerInitted() const;
48+ 
49private:49private:
50 void TimerProcess(void);50 void TimerProcess(void);
51- bool ServerInit(const std::map<std::string, std::string> &info);51+ bool ServerInit(const std::map<std::string, std::string>& info);
52 bool ServerUnInit(OptHandle epHandle);52 bool ServerUnInit(OptHandle epHandle);
53 ComponentType GetComponentTypeByReqType(CmdClassT cmdType) const;53 ComponentType GetComponentTypeByReqType(CmdClassT cmdType) const;
54 void HandleConnectEvent(CommHandle handle);54 void HandleConnectEvent(CommHandle handle);
55 bool IsLinkOverload(HDC_SESSION session) const;55 bool IsLinkOverload(HDC_SESSION session) const;
56- bool DispatchComponent(CommHandle &handle, SharedPtr<MsgProto> &msgPtr, HDC_SESSION session, ComponentType &comp);56+ bool DispatchComponent(CommHandle& handle, SharedPtr<MsgProto>& msgPtr, HDC_SESSION session, ComponentType& comp);
57 std::shared_ptr<AdxComponent> GetComponent(ComponentType type) const;57 std::shared_ptr<AdxComponent> GetComponent(ComponentType type) const;
58 void WaitProcessDrained();58 void WaitProcessDrained();
59+ 
59private:60private:
60 std::atomic<bool> waitOver_{true};61 std::atomic<bool> waitOver_{true};
61 int32_t pid_;62 int32_t pid_;
@@ -77,5 +78,5 @@ private:
77 mutable std::mutex processMtx_;78 mutable std::mutex processMtx_;
78 std::condition_variable processCv_;79 std::condition_variable processCv_;
79};80};
80-}81+} // namespace Adx
81#endif82#endif
@@ -13,7 +13,7 @@
13#include "log/adx_log.h"13#include "log/adx_log.h"
14using namespace Adx;14using namespace Adx;
15namespace Adx {15namespace Adx {
16-int32_t ServerRegister::RegisterComponent(int32_t serverType, std::unique_ptr<AdxComponent> &adxComponent)16+int32_t ServerRegister::RegisterComponent(int32_t serverType, std::unique_ptr<AdxComponent>& adxComponent)
17{17{
18 std::lock_guard<std::mutex> lk(mtx_);18 std::lock_guard<std::mutex> lk(mtx_);
19 return services_[serverType].ComponentAdd(adxComponent) ? IDE_DAEMON_OK : IDE_DAEMON_ERROR;19 return services_[serverType].ComponentAdd(adxComponent) ? IDE_DAEMON_OK : IDE_DAEMON_ERROR;
@@ -68,16 +68,17 @@ static IdeThreadArg AdxServerProcess(const IdeThreadArg arg)
68 if (arg == nullptr) {68 if (arg == nullptr) {
69 return nullptr;69 return nullptr;
70 }70 }
71- ServerInitInfo info = *static_cast<ServerInitInfo *>(arg);71+ ServerInitInfo info = *static_cast<ServerInitInfo*>(arg);
72 int32_t ret = ServerRegister::Instance().ComponentServerStartup(info);72 int32_t ret = ServerRegister::Instance().ComponentServerStartup(info);
73 IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK, return nullptr, "server process failed");73 IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK, return nullptr, "server process failed");
74 return nullptr;74 return nullptr;
75}75}
76-}76+} // namespace Adx
77 77 
78-int32_t AdxRegisterComponentFunc(drvHdcServiceType serverType, std::unique_ptr<AdxComponent> &adxComponent)78+int32_t AdxRegisterComponentFunc(drvHdcServiceType serverType, std::unique_ptr<AdxComponent>& adxComponent)
79{79{
80- IDE_LOGI("Start to register, serverType:%d, componentType:%d", static_cast<int32_t>(serverType),80+ IDE_LOGI(
81+ "Start to register, serverType:%d, componentType:%d", static_cast<int32_t>(serverType),
81 static_cast<int32_t>(adxComponent->GetType()));82 static_cast<int32_t>(adxComponent->GetType()));
82 return ServerRegister::Instance().RegisterComponent(serverType, adxComponent);83 return ServerRegister::Instance().RegisterComponent(serverType, adxComponent);
83}84}
@@ -104,10 +105,11 @@ int32_t AdxComponentServerStartup(ServerInitInfo info)
104 105 
105int32_t AdxComponentServerCleanup(drvHdcServiceType serverType, ComponentType cmpt)106int32_t AdxComponentServerCleanup(drvHdcServiceType serverType, ComponentType cmpt)
106{107{
107- IDE_LOGI("Start to cleanup, serverType:%d, componentType:%d", static_cast<int32_t>(serverType),108+ IDE_LOGI(
109+ "Start to cleanup, serverType:%d, componentType:%d", static_cast<int32_t>(serverType),
108 static_cast<int32_t>(cmpt));110 static_cast<int32_t>(cmpt));
109 if (cmpt == ComponentType::NR_COMPONENTS) {111 if (cmpt == ComponentType::NR_COMPONENTS) {
110 return ServerRegister::Instance().ComponentServerCleanup(serverType);112 return ServerRegister::Instance().ComponentServerCleanup(serverType);
111 }113 }
112 return ServerRegister::Instance().UnRegisterComponent(serverType, cmpt);114 return ServerRegister::Instance().UnRegisterComponent(serverType, cmpt);
113-}115+}
@@ -20,24 +20,27 @@
20namespace Adx {20namespace Adx {
21class ServerRegister : public Adx::Common::Singleton::Singleton<ServerRegister> {21class ServerRegister : public Adx::Common::Singleton::Singleton<ServerRegister> {
22public:22public:
23- int32_t RegisterComponent(int32_t serverType, std::unique_ptr<AdxComponent> &adxComponent);23+ int32_t RegisterComponent(int32_t serverType, std::unique_ptr<AdxComponent>& adxComponent);
24 int32_t UnRegisterComponent(int32_t serverType, ComponentType cmpt);24 int32_t UnRegisterComponent(int32_t serverType, ComponentType cmpt);
25 int32_t ComponentServerStartup(ServerInitInfo info) const;25 int32_t ComponentServerStartup(ServerInitInfo info) const;
26 int32_t ComponentServerCleanup(int32_t serverType);26 int32_t ComponentServerCleanup(int32_t serverType);
27+ 
27private:28private:
28 bool ServerManagerInit(const ServerInitInfo info);29 bool ServerManagerInit(const ServerInitInfo info);
29 std::map<int32_t, AdxServerManager> services_;30 std::map<int32_t, AdxServerManager> services_;
30 mutable std::mutex mtx_;31 mutable std::mutex mtx_;
31};32};
32-}33+} // namespace Adx
33#define ADX_API __attribute__((visibility("default")))34#define ADX_API __attribute__((visibility("default")))
34#ifdef __cplusplus35#ifdef __cplusplus
35extern "C" {36extern "C" {
36#endif37#endif
37-ADX_API int32_t AdxRegisterComponentFunc(drvHdcServiceType serverType, std::unique_ptr<Adx::AdxComponent> &adxComponent);38+ADX_API int32_t
39+AdxRegisterComponentFunc(drvHdcServiceType serverType, std::unique_ptr<Adx::AdxComponent>& adxComponent);
38ADX_API int32_t AdxComponentServerStartup(ServerInitInfo info);40ADX_API int32_t AdxComponentServerStartup(ServerInitInfo info);
39-ADX_API int32_t AdxComponentServerCleanup(drvHdcServiceType serverType, ComponentType cmpt = ComponentType::NR_COMPONENTS);41+ADX_API int32_t
42+AdxComponentServerCleanup(drvHdcServiceType serverType, ComponentType cmpt = ComponentType::NR_COMPONENTS);
40#ifdef __cplusplus43#ifdef __cplusplus
41}44}
42#endif45#endif
43-#endif46+#endif
@@ -11,7 +11,7 @@
11#include "adx_device.h"11#include "adx_device.h"
12#include "log/adx_log.h"12#include "log/adx_log.h"
13namespace Adx {13namespace Adx {
14-void AdxDevice::EnableNotify(const std::string &devId)14+void AdxDevice::EnableNotify(const std::string& devId)
15{15{
16 auto it = devices_.find(devId);16 auto it = devices_.find(devId);
17 if (it != devices_.end() && it->second != DeviceState::ENABLE_STATE) {17 if (it != devices_.end() && it->second != DeviceState::ENABLE_STATE) {
@@ -20,7 +20,7 @@ void AdxDevice::EnableNotify(const std::string &devId)
20 }20 }
21}21}
22 22 
23-void AdxDevice::DisableNotify(const std::string &devId)23+void AdxDevice::DisableNotify(const std::string& devId)
24{24{
25 auto it = devices_.find(devId);25 auto it = devices_.find(devId);
26 if (it != devices_.end() && it->second != DeviceState::DISABLE_STATE) {26 if (it != devices_.end() && it->second != DeviceState::DISABLE_STATE) {
@@ -29,7 +29,7 @@ void AdxDevice::DisableNotify(const std::string &devId)
29 }29 }
30}30}
31 31 
32-void AdxDevice::GetEnableDevices(std::vector<std::string> &devices) const32+void AdxDevice::GetEnableDevices(std::vector<std::string>& devices) const
33{33{
34 auto it = devices_.begin();34 auto it = devices_.begin();
35 for (; it != devices_.end(); it++) {35 for (; it != devices_.end(); it++) {
@@ -39,7 +39,7 @@ void AdxDevice::GetEnableDevices(std::vector<std::string> &devices) const
39 }39 }
40}40}
41 41 
42-void AdxDevice::GetDisableDevices(std::vector<std::string> &devices) const42+void AdxDevice::GetDisableDevices(std::vector<std::string>& devices) const
43{43{
44 devices.clear();44 devices.clear();
45 auto it = devices_.begin();45 auto it = devices_.begin();
@@ -50,16 +50,13 @@ void AdxDevice::GetDisableDevices(std::vector<std::string> &devices) const
50 }50 }
51}51}
52 52 
53-bool AdxDevice::NoDevice() const53+bool AdxDevice::NoDevice() const { return devices_.empty(); }
54-{
55- return devices_.empty();
56-}
57 54 
58-void AdxDevice::InitDevice(const std::string &devId)55+void AdxDevice::InitDevice(const std::string& devId)
59{56{
60 auto it = devices_.find(devId);57 auto it = devices_.find(devId);
61 if (it == devices_.end()) {58 if (it == devices_.end()) {
62 devices_[devId] = DeviceState::ENABLE_STATE;59 devices_[devId] = DeviceState::ENABLE_STATE;
63 }60 }
64}61}
65-}62+} // namespace Adx
@@ -22,16 +22,16 @@ enum class DeviceState {
22class AdxDevice {22class AdxDevice {
23public:23public:
24 virtual ~AdxDevice() {}24 virtual ~AdxDevice() {}
25- virtual void GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string> &devices) = 0;25+ virtual void GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string>& devices) = 0;
26- void EnableNotify(const std::string &devId);26+ void EnableNotify(const std::string& devId);
27- void DisableNotify(const std::string &devId);27+ void DisableNotify(const std::string& devId);
28- void GetEnableDevices(std::vector<std::string> &devices) const;28+ void GetEnableDevices(std::vector<std::string>& devices) const;
29- void GetDisableDevices(std::vector<std::string> &devices) const;29+ void GetDisableDevices(std::vector<std::string>& devices) const;
30 bool NoDevice() const;30 bool NoDevice() const;
31- void InitDevice(const std::string &devId);31+ void InitDevice(const std::string& devId);
32+ 
32private:33private:
33 std::map<std::string, DeviceState> devices_;34 std::map<std::string, DeviceState> devices_;
34};35};
35-}36+} // namespace Adx
36#endif37#endif
37- 
@@ -44,7 +44,7 @@ bool CheckVfId(uint32_t devId)
44 * IDE_DAEMON_OK: get device num succ44 * IDE_DAEMON_OK: get device num succ
45 * IDE_DAEMON_ERROR: get device num failed45 * IDE_DAEMON_ERROR: get device num failed
46 */46 */
47-int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len)47+int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t>& devs, uint32_t len)
48{48{
49 IDE_CTRL_VALUE_FAILED(devNum != nullptr, return IDE_DAEMON_ERROR, "devNum is nullptr");49 IDE_CTRL_VALUE_FAILED(devNum != nullptr, return IDE_DAEMON_ERROR, "devNum is nullptr");
50 IDE_CTRL_VALUE_FAILED(len == DEVICE_NUM_MAX, return IDE_DAEMON_ERROR, "len is invalid");50 IDE_CTRL_VALUE_FAILED(len == DEVICE_NUM_MAX, return IDE_DAEMON_ERROR, "len is invalid");
@@ -56,7 +56,7 @@ int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len
56 56 
57 if (*devNum > 0 && *devNum <= DEVICE_NUM_MAX) {57 if (*devNum > 0 && *devNum <= DEVICE_NUM_MAX) {
58#if (defined ADX_LIB_HOST) || (defined ADX_LIB_HOST_DRV)58#if (defined ADX_LIB_HOST) || (defined ADX_LIB_HOST_DRV)
59- err = drvGetDevIDs(devs.data(), MAX_LOCAL_DEVICE_NUM); // host side get devId59+ err = drvGetDevIDs(devs.data(), MAX_LOCAL_DEVICE_NUM); // host side get devId
60#else60#else
61 err = drvGetDeviceLocalIDs(devs.data(), MAX_LOCAL_DEVICE_NUM); // device side get devId61 err = drvGetDeviceLocalIDs(devs.data(), MAX_LOCAL_DEVICE_NUM); // device side get devId
62#endif62#endif
@@ -78,7 +78,7 @@ int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len
78 * IDE_DAEMON_OK: get device num succ78 * IDE_DAEMON_OK: get device num succ
79 * IDE_DAEMON_ERROR: get device num failed79 * IDE_DAEMON_ERROR: get device num failed
80 */80 */
81-int32_t IdeGetPhyDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len)81+int32_t IdeGetPhyDevList(IdeU32Pt devNum, std::vector<uint32_t>& devs, uint32_t len)
82{82{
83 IDE_CTRL_VALUE_FAILED(devNum != nullptr, return IDE_DAEMON_ERROR, "devNum is nullptr");83 IDE_CTRL_VALUE_FAILED(devNum != nullptr, return IDE_DAEMON_ERROR, "devNum is nullptr");
84 IDE_CTRL_VALUE_FAILED(len == DEVICE_NUM_MAX, return IDE_DAEMON_ERROR, "len is invalid");84 IDE_CTRL_VALUE_FAILED(len == DEVICE_NUM_MAX, return IDE_DAEMON_ERROR, "len is invalid");
@@ -91,8 +91,9 @@ int32_t IdeGetPhyDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t
91 uint32_t phyId = 0;91 uint32_t phyId = 0;
92 for (i = 0; i < *devNum && i < DEVICE_NUM_MAX; i++) {92 for (i = 0; i < *devNum && i < DEVICE_NUM_MAX; i++) {
93 drvError_t err = drvDeviceGetPhyIdByIndex(devLogIds[i], &phyId);93 drvError_t err = drvDeviceGetPhyIdByIndex(devLogIds[i], &phyId);
94- IDE_CTRL_VALUE_FAILED(err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR,94+ IDE_CTRL_VALUE_FAILED(
95- "drvDeviceGetPhyIdByIndex devIds: %u failed, err: %d", devLogIds[i], err);95+ err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "drvDeviceGetPhyIdByIndex devIds: %u failed, err: %d",
96+ devLogIds[i], err);
96 devs[i] = phyId;97 devs[i] = phyId;
97 }98 }
98 return IDE_DAEMON_OK;99 return IDE_DAEMON_OK;
@@ -124,8 +125,9 @@ int32_t IdeGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId)
124 uint32_t phyId = 0;125 uint32_t phyId = 0;
125 for (i = 0; i < devNum; i++) {126 for (i = 0; i < devNum; i++) {
126 err = drvDeviceGetPhyIdByIndex(devIds[i], &phyId);127 err = drvDeviceGetPhyIdByIndex(devIds[i], &phyId);
127- IDE_CTRL_VALUE_FAILED(err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR,128+ IDE_CTRL_VALUE_FAILED(
128- "drvDeviceGetPhyIdByIndex devIds: %u failed, err: %d", devIds[i], err);129+ err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "drvDeviceGetPhyIdByIndex devIds: %u failed, err: %d",
130+ devIds[i], err);
129 if (phyId == desPhyId) {131 if (phyId == desPhyId) {
130 IDE_LOGI("the logical ID(%u) is a corresponding physical ID(%u)", devIds[i], phyId);132 IDE_LOGI("the logical ID(%u) is a corresponding physical ID(%u)", devIds[i], phyId);
131 *logId = devIds[i];133 *logId = devIds[i];
@@ -152,9 +154,10 @@ int32_t AdxGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId)
152 }154 }
153 155 
154 drvError_t err = drvDeviceGetIndexByPhyId(desPhyId, logId);156 drvError_t err = drvDeviceGetIndexByPhyId(desPhyId, logId);
155- IDE_CTRL_VALUE_FAILED(err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR,157+ IDE_CTRL_VALUE_FAILED(
156- "drvDeviceGetIndexByPhyId devIds: %u failed, err: %d", desPhyId, err);158+ err == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "drvDeviceGetIndexByPhyId devIds: %u failed, err: %d", desPhyId,
159+ err);
157 160 
158 return IDE_DAEMON_OK;161 return IDE_DAEMON_OK;
159}162}
160-}163+} // namespace Adx
@@ -17,9 +17,9 @@ namespace Adx {
17const int32_t MAX_LOCAL_DEVICE_NUM = 64; // 0~31 device phyid; 32~63 device vfid17const int32_t MAX_LOCAL_DEVICE_NUM = 64; // 0~31 device phyid; 32~63 device vfid
18 18 
19bool CheckVfId(uint32_t devId);19bool CheckVfId(uint32_t devId);
20-int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len);20+int32_t IdeGetDevList(IdeU32Pt devNum, std::vector<uint32_t>& devs, uint32_t len);
21-int32_t IdeGetPhyDevList(IdeU32Pt devNum, std::vector<uint32_t> &devs, uint32_t len);21+int32_t IdeGetPhyDevList(IdeU32Pt devNum, std::vector<uint32_t>& devs, uint32_t len);
22int32_t IdeGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId);22int32_t IdeGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId);
23int32_t AdxGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId);23int32_t AdxGetLogIdByPhyId(uint32_t desPhyId, IdeU32Pt logId);
24-}24+} // namespace Adx
25#endif25#endif
@@ -13,9 +13,9 @@
13#include "log/adx_log.h"13#include "log/adx_log.h"
14#include "ascend_hal.h"14#include "ascend_hal.h"
15#include "adx_dsmi.h"15#include "adx_dsmi.h"
16-using AdxDrvStateInfoPt = devdrv_state_info_t *;16+using AdxDrvStateInfoPt = devdrv_state_info_t*;
17namespace Adx {17namespace Adx {
18-void AdxHdcDevice::GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string> &devices)18+void AdxHdcDevice::GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string>& devices)
19{19{
20 devices.clear();20 devices.clear();
21 std::lock_guard<std::mutex> lk(this->deviceNotifyMtx_);21 std::lock_guard<std::mutex> lk(this->deviceNotifyMtx_);
@@ -38,4 +38,4 @@ void AdxHdcDevice::GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<
38 }38 }
39 AdxHdcDevice::GetEnableDevices(devices);39 AdxHdcDevice::GetEnableDevices(devices);
40}40}
41-}41+} // namespace Adx
@@ -17,9 +17,10 @@ class AdxHdcDevice : public AdxDevice {
17public:17public:
18 AdxHdcDevice() {}18 AdxHdcDevice() {}
19 ~AdxHdcDevice() override {}19 ~AdxHdcDevice() override {}
20- void GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string> &devices) override;20+ void GetAllEnableDevices(int32_t mode, int32_t devId, std::vector<std::string>& devices) override;
21+ 
21private:22private:
22 std::mutex deviceNotifyMtx_;23 std::mutex deviceNotifyMtx_;
23};24};
24-}25+} // namespace Adx
25-#endif26+#endif
@@ -11,7 +11,7 @@
11#include "adx_sock_device.h"11#include "adx_sock_device.h"
12#include "log/adx_log.h"12#include "log/adx_log.h"
13namespace Adx {13namespace Adx {
14-void AdxSockDevice::GetAllEnableDevices(int32_t /* mode */, int32_t /* devId */, std::vector<std::string> &devices)14+void AdxSockDevice::GetAllEnableDevices(int32_t /* mode */, int32_t /* devId */, std::vector<std::string>& devices)
15{15{
16 devices.clear();16 devices.clear();
17 if (AdxSockDevice::NoDevice()) {17 if (AdxSockDevice::NoDevice()) {
@@ -19,4 +19,4 @@ void AdxSockDevice::GetAllEnableDevices(int32_t /* mode */, int32_t /* devId */,
19 }19 }
20 AdxSockDevice::GetEnableDevices(devices);20 AdxSockDevice::GetEnableDevices(devices);
21}21}
22-}22+} // namespace Adx
@@ -17,8 +17,7 @@ class AdxSockDevice : public AdxDevice {
17public:17public:
18 AdxSockDevice() {}18 AdxSockDevice() {}
19 ~AdxSockDevice() override {}19 ~AdxSockDevice() override {}
20- void GetAllEnableDevices(int32_t /* mode */, int32_t /* devId */, std::vector<std::string> &devices) override;20+ void GetAllEnableDevices(int32_t /* mode */, int32_t /* devId */, std::vector<std::string>& devices) override;
21};21};
22-}22+} // namespace Adx
23#endif23#endif
24- 
@@ -28,11 +28,7 @@ struct EpollEvent {
28 EpollHandle data;28 EpollHandle data;
29};29};
30 30 
31-enum class EpollType {31+enum class EpollType { EPOLL_HDC, EPOLL_SOCK, NR_EPOLL };
32- EPOLL_HDC,
33- EPOLL_SOCK,
34- NR_EPOLL
35-};
36 32 
37class AdxEpoll {33class AdxEpoll {
38public:34public:
@@ -40,14 +36,15 @@ public:
40 virtual ~AdxEpoll() {}36 virtual ~AdxEpoll() {}
41 virtual int32_t EpollCreate(const int32_t size) = 0;37 virtual int32_t EpollCreate(const int32_t size) = 0;
42 virtual int32_t EpollDestroy() = 0;38 virtual int32_t EpollDestroy() = 0;
43- virtual int32_t EpollCtl(EpollHandle target, EpollEvent &event, int32_t op) = 0;39+ virtual int32_t EpollCtl(EpollHandle target, EpollEvent& event, int32_t op) = 0;
44- virtual int32_t EpollAdd(EpollHandle target, EpollEvent &event) = 0;40+ virtual int32_t EpollAdd(EpollHandle target, EpollEvent& event) = 0;
45- virtual int32_t EpollDel(EpollHandle target, EpollEvent &event) = 0;41+ virtual int32_t EpollDel(EpollHandle target, EpollEvent& event) = 0;
46- virtual int32_t EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout) = 0;42+ virtual int32_t EpollWait(std::vector<EpollEvent>& events, int32_t size, int32_t timeout) = 0;
47 virtual int32_t EpollErrorHandle() = 0;43 virtual int32_t EpollErrorHandle() = 0;
48 virtual int32_t EpollGetSize() = 0;44 virtual int32_t EpollGetSize() = 0;
45+ 
49protected:46protected:
50 int32_t epMaxSize_;47 int32_t epMaxSize_;
51};48};
52-}49+} // namespace Adx
53#endif50#endif
@@ -25,7 +25,7 @@ int32_t AdxHdcEpoll::EpollCreate(const int32_t size)
25 }25 }
26 26 
27 if (epEvent_ == nullptr) {27 if (epEvent_ == nullptr) {
28- epEvent_ = (struct drvHdcEvent *)ADX_SAFE_CALLOC(size, sizeof(struct drvHdcEvent));28+ epEvent_ = (struct drvHdcEvent*)ADX_SAFE_CALLOC(size, sizeof(struct drvHdcEvent));
29 if (epEvent_ == nullptr) {29 if (epEvent_ == nullptr) {
30 IDE_LOGE("hdc epoll calloc error.");30 IDE_LOGE("hdc epoll calloc error.");
31 return IDE_DAEMON_ERROR;31 return IDE_DAEMON_ERROR;
@@ -73,7 +73,7 @@ int32_t AdxHdcEpoll::EpollDestroy()
73 * @param [in] event: epoll event73 * @param [in] event: epoll event
74 * @return !=0: failure ==0: success74 * @return !=0: failure ==0: success
75 */75 */
76-int32_t AdxHdcEpoll::EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op)76+int32_t AdxHdcEpoll::EpollCtl(EpollHandle handle, EpollEvent& event, int32_t op)
77{77{
78 int32_t ret;78 int32_t ret;
79 if (ep_ == nullptr || handle == ADX_INVALID_HANDLE) {79 if (ep_ == nullptr || handle == ADX_INVALID_HANDLE) {
@@ -106,7 +106,7 @@ int32_t AdxHdcEpoll::EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op)
106 * @param [in] event: epoll event106 * @param [in] event: epoll event
107 * @return !=0: failure ==0: success107 * @return !=0: failure ==0: success
108 */108 */
109-int32_t AdxHdcEpoll::EpollAdd(EpollHandle target, EpollEvent &event)109+int32_t AdxHdcEpoll::EpollAdd(EpollHandle target, EpollEvent& event)
110{110{
111 return EpollCtl(target, event, HDC_EPOLL_CTL_ADD);111 return EpollCtl(target, event, HDC_EPOLL_CTL_ADD);
112}112}
@@ -118,7 +118,7 @@ int32_t AdxHdcEpoll::EpollAdd(EpollHandle target, EpollEvent &event)
118 * @param [in] event: epoll event118 * @param [in] event: epoll event
119 * @return !=0: failure ==0: success119 * @return !=0: failure ==0: success
120 */120 */
121-int32_t AdxHdcEpoll::EpollDel(EpollHandle target, EpollEvent &event)121+int32_t AdxHdcEpoll::EpollDel(EpollHandle target, EpollEvent& event)
122{122{
123 return EpollCtl(target, event, HDC_EPOLL_CTL_DEL);123 return EpollCtl(target, event, HDC_EPOLL_CTL_DEL);
124}124}
@@ -131,7 +131,7 @@ int32_t AdxHdcEpoll::EpollDel(EpollHandle target, EpollEvent &event)
131 * @param [in] timeout: timeout131 * @param [in] timeout: timeout
132 * @return event num132 * @return event num
133 */133 */
134-int32_t AdxHdcEpoll::EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout)134+int32_t AdxHdcEpoll::EpollWait(std::vector<EpollEvent>& events, int32_t size, int32_t timeout)
135{135{
136 int32_t ret;136 int32_t ret;
137 if (ep_ == nullptr || size < epMaxSize_) {137 if (ep_ == nullptr || size < epMaxSize_) {
@@ -160,10 +160,7 @@ int32_t AdxHdcEpoll::EpollErrorHandle()
160 return IDE_DAEMON_OK;160 return IDE_DAEMON_OK;
161}161}
162 162 
163-int32_t AdxHdcEpoll::EpollGetSize()163+int32_t AdxHdcEpoll::EpollGetSize() { return epMaxSize_; }
164-{
165- return epMaxSize_;
166-}
167 164 
168uint32_t AdxHdcEpoll::EpollEventToHdcEvent(uint32_t events) const165uint32_t AdxHdcEpoll::EpollEventToHdcEvent(uint32_t events) const
169{166{
@@ -184,4 +181,4 @@ uint32_t AdxHdcEpoll::HdcEventToEpollEvent(uint32_t events) const
184 }181 }
185 return transed;182 return transed;
186}183}
187-}184+} // namespace Adx
@@ -20,18 +20,20 @@ public:
20 ~AdxHdcEpoll() override {}20 ~AdxHdcEpoll() override {}
21 int32_t EpollCreate(const int32_t size) override;21 int32_t EpollCreate(const int32_t size) override;
22 int32_t EpollDestroy() override;22 int32_t EpollDestroy() override;
23- int32_t EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op) override;23+ int32_t EpollCtl(EpollHandle handle, EpollEvent& event, int32_t op) override;
24- int32_t EpollAdd(EpollHandle target, EpollEvent &event) override;24+ int32_t EpollAdd(EpollHandle target, EpollEvent& event) override;
25- int32_t EpollDel(EpollHandle target, EpollEvent &event) override;25+ int32_t EpollDel(EpollHandle target, EpollEvent& event) override;
26- int32_t EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout) override;26+ int32_t EpollWait(std::vector<EpollEvent>& events, int32_t size, int32_t timeout) override;
27 int32_t EpollErrorHandle() override;27 int32_t EpollErrorHandle() override;
28 int32_t EpollGetSize() override;28 int32_t EpollGetSize() override;
29+ 
29private:30private:
30 uint32_t EpollEventToHdcEvent(uint32_t events) const;31 uint32_t EpollEventToHdcEvent(uint32_t events) const;
31 uint32_t HdcEventToEpollEvent(uint32_t events) const;32 uint32_t HdcEventToEpollEvent(uint32_t events) const;
33+ 
32private:34private:
33 HDC_EPOLL ep_ = nullptr;35 HDC_EPOLL ep_ = nullptr;
34- struct drvHdcEvent *epEvent_ = nullptr;36+ struct drvHdcEvent* epEvent_ = nullptr;
35};37};
36-}38+} // namespace Adx
37-#endif39+#endif
@@ -29,11 +29,8 @@ int32_t AdxSockEpoll::EpollCreate(const int32_t size)
29 return IDE_DAEMON_OK;29 return IDE_DAEMON_OK;
30}30}
31 31 
32-int32_t AdxSockEpoll::EpollDestroy()32+int32_t AdxSockEpoll::EpollDestroy() { return IDE_DAEMON_OK; }
33-{33+int32_t AdxSockEpoll::EpollCtl(EpollHandle handle, EpollEvent& event, int32_t op)
34- return IDE_DAEMON_OK;
35-}
36-int32_t AdxSockEpoll::EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op)
37{34{
38 if (ep_ == -1 || handle == ADX_INVALID_HANDLE) {35 if (ep_ == -1 || handle == ADX_INVALID_HANDLE) {
39 IDE_LOGE("sock epoll ctl input error");36 IDE_LOGE("sock epoll ctl input error");
@@ -55,24 +52,18 @@ int32_t AdxSockEpoll::EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op
55 return IDE_DAEMON_OK;52 return IDE_DAEMON_OK;
56}53}
57 54 
58-int32_t AdxSockEpoll::EpollAdd(EpollHandle target, EpollEvent &event)55+int32_t AdxSockEpoll::EpollAdd(EpollHandle target, EpollEvent& event) { return EpollCtl(target, event, EPOLL_CTL_ADD); }
59-{
60- return EpollCtl(target, event, EPOLL_CTL_ADD);
61-}
62 56 
63-int32_t AdxSockEpoll::EpollDel(EpollHandle target, EpollEvent &event)57+int32_t AdxSockEpoll::EpollDel(EpollHandle target, EpollEvent& event) { return EpollCtl(target, event, EPOLL_CTL_DEL); }
64-{
65- return EpollCtl(target, event, EPOLL_CTL_DEL);
66-}
67 58 
68-int32_t AdxSockEpoll::EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout)59+int32_t AdxSockEpoll::EpollWait(std::vector<EpollEvent>& events, int32_t size, int32_t timeout)
69{60{
70 if (ep_ < 0) {61 if (ep_ < 0) {
71 IDE_LOGW("epoll wait init");62 IDE_LOGW("epoll wait init");
72 return IDE_DAEMON_ERROR;63 return IDE_DAEMON_ERROR;
73 }64 }
74 65 
75- struct epoll_event epEvent[DEFAULT_EPOLL_SIZE] = { {0} };66+ struct epoll_event epEvent[DEFAULT_EPOLL_SIZE] = {{0}};
76 int32_t ret = epoll_wait(ep_, epEvent, size, timeout);67 int32_t ret = epoll_wait(ep_, epEvent, size, timeout);
77 if (ret < 0) {68 if (ret < 0) {
78 IDE_LOGE("epoll wait process error");69 IDE_LOGE("epoll wait process error");
@@ -87,15 +78,9 @@ int32_t AdxSockEpoll::EpollWait(std::vector<EpollEvent> &events, int32_t size, i
87 return ret;78 return ret;
88}79}
89 80 
90-int32_t AdxSockEpoll::EpollErrorHandle()81+int32_t AdxSockEpoll::EpollErrorHandle() { return IDE_DAEMON_OK; }
91-{
92- return IDE_DAEMON_OK;
93-}
94 82 
95-int32_t AdxSockEpoll::EpollGetSize()83+int32_t AdxSockEpoll::EpollGetSize() { return epMaxSize_; }
96-{
97- return epMaxSize_;
98-}
99 84 
100uint32_t AdxSockEpoll::EpollEventToHdcEvent(uint32_t events) const85uint32_t AdxSockEpoll::EpollEventToHdcEvent(uint32_t events) const
101{86{
@@ -113,4 +98,4 @@ uint32_t AdxSockEpoll::HdcEventToEpollEvent(uint32_t events) const
113 98 
114 return transed;99 return transed;
115}100}
116-}101+} // namespace Adx
@@ -14,24 +14,23 @@ namespace Adx {
14#define SOCK_EPOLL_EVENT_MASK (HDC_EPOLL_DATA_IN | HDC_EPOLL_CONN_IN | HDC_EPOLL_SESSION_CLOSE)14#define SOCK_EPOLL_EVENT_MASK (HDC_EPOLL_DATA_IN | HDC_EPOLL_CONN_IN | HDC_EPOLL_SESSION_CLOSE)
15class AdxSockEpoll : public AdxEpoll {15class AdxSockEpoll : public AdxEpoll {
16public:16public:
17- AdxSockEpoll() : ep_(-1)17+ AdxSockEpoll() : ep_(-1) { epMaxSize_ = DEFAULT_EPOLL_SIZE; }
18- {
19- epMaxSize_ = DEFAULT_EPOLL_SIZE;
20- }
21 ~AdxSockEpoll() override {}18 ~AdxSockEpoll() override {}
22 int32_t EpollCreate(const int32_t size) override;19 int32_t EpollCreate(const int32_t size) override;
23- int32_t EpollAdd(EpollHandle target, EpollEvent &event) override;20+ int32_t EpollAdd(EpollHandle target, EpollEvent& event) override;
24- int32_t EpollDel(EpollHandle target, EpollEvent &event) override;21+ int32_t EpollDel(EpollHandle target, EpollEvent& event) override;
25- int32_t EpollCtl(EpollHandle handle, EpollEvent &event, int32_t op) override;22+ int32_t EpollCtl(EpollHandle handle, EpollEvent& event, int32_t op) override;
26- int32_t EpollWait(std::vector<EpollEvent> &events, int32_t size, int32_t timeout) override;23+ int32_t EpollWait(std::vector<EpollEvent>& events, int32_t size, int32_t timeout) override;
27 int32_t EpollGetSize() override;24 int32_t EpollGetSize() override;
28 int32_t EpollErrorHandle() override;25 int32_t EpollErrorHandle() override;
29 int32_t EpollDestroy() override;26 int32_t EpollDestroy() override;
27+ 
30private:28private:
31 uint32_t HdcEventToEpollEvent(uint32_t events) const;29 uint32_t HdcEventToEpollEvent(uint32_t events) const;
32 uint32_t EpollEventToHdcEvent(uint32_t events) const;30 uint32_t EpollEventToHdcEvent(uint32_t events) const;
31+ 
33private:32private:
34 int32_t ep_;33 int32_t ep_;
35};34};
36-}35+} // namespace Adx
37-#endif36+#endif
@@ -16,12 +16,13 @@
16#include "ide_os_type.h"16#include "ide_os_type.h"
17#include "hdc_api.h"17#include "hdc_api.h"
18 18 
19-#define IDE_FREE_HDC_MSG_AND_SET_NULL(ptr) do { \19+#define IDE_FREE_HDC_MSG_AND_SET_NULL(ptr) \
20- if ((ptr) != nullptr) { \20+ do { \
21- (void)drvHdcFreeMsg(ptr); \21+ if ((ptr) != nullptr) { \
22- ptr = nullptr; \22+ (void)drvHdcFreeMsg(ptr); \
23- } \23+ ptr = nullptr; \
24-} while (0)24+ } \
25+ } while (0)
25 26 
26using namespace IdeDaemon::Common::Config;27using namespace IdeDaemon::Common::Config;
27 28 
@@ -40,14 +41,14 @@ struct DataSendMsg {
40 * IDE_DAEMON_OK: init succ41 * IDE_DAEMON_OK: init succ
41 * IDE_DAEMON_ERROR: init failed42 * IDE_DAEMON_ERROR: init failed
42 */43 */
43-int32_t HdcClientInit(HDC_CLIENT *client)44+int32_t HdcClientInit(HDC_CLIENT* client)
44{45{
45 hdcError_t error;46 hdcError_t error;
46 int32_t flag = 0;47 int32_t flag = 0;
47 IDE_CTRL_VALUE_FAILED(client != nullptr, return IDE_DAEMON_ERROR, "client is nullptr");48 IDE_CTRL_VALUE_FAILED(client != nullptr, return IDE_DAEMON_ERROR, "client is nullptr");
48 49 
49 // create HDC client50 // create HDC client
50- error = drvHdcClientCreate (client, MAX_SESSION_NUM, HDC_SERVICE_TYPE_IDE1, flag);51+ error = drvHdcClientCreate(client, MAX_SESSION_NUM, HDC_SERVICE_TYPE_IDE1, flag);
51 if (error != DRV_ERROR_NONE || *client == nullptr) {52 if (error != DRV_ERROR_NONE || *client == nullptr) {
52 IDE_LOGE("Hdc Client Create Failed, error: %d", error);53 IDE_LOGE("Hdc Client Create Failed, error: %d", error);
53 return IDE_DAEMON_ERROR;54 return IDE_DAEMON_ERROR;
@@ -171,7 +172,7 @@ HDC_SESSION HdcServerAccept(HDC_SERVER server)
171 * @param [in] base : iovec slice of receive data172 * @param [in] base : iovec slice of receive data
172 * @param [out] ioList : iovec slice list173 * @param [out] ioList : iovec slice list
173 */174 */
174-static void IoVecAddToList(struct IoVec &base, std::list<struct IoVec> &ioList)175+static void IoVecAddToList(struct IoVec& base, std::list<struct IoVec>& ioList)
175{176{
176 if (base.base != nullptr && base.len > 0) {177 if (base.base != nullptr && base.len > 0) {
177 ioList.push_back(base);178 ioList.push_back(base);
@@ -186,14 +187,14 @@ static void IoVecAddToList(struct IoVec &base, std::list<struct IoVec> &ioList)
186 * @param [out] base : save receive data of all slice187 * @param [out] base : save receive data of all slice
187 * @return IDE_DAEMON_OK : success188 * @return IDE_DAEMON_OK : success
188 */189 */
189-static int32_t IoVecListToMem(std::list<struct IoVec> &ioList, struct IoVec &base)190+static int32_t IoVecListToMem(std::list<struct IoVec>& ioList, struct IoVec& base)
190{191{
191 uint32_t offset = 0;192 uint32_t offset = 0;
192- for (const auto &eit: ioList) {193+ for (const auto& eit : ioList) {
193 if (base.len >= eit.len && offset <= base.len - eit.len) {194 if (base.len >= eit.len && offset <= base.len - eit.len) {
194 const errno_t err = memcpy_s(195 const errno_t err = memcpy_s(
195- static_cast<IdeU8Pt>(base.base) + offset, static_cast<size_t>(base.len - offset), 196+ static_cast<IdeU8Pt>(base.base) + offset, static_cast<size_t>(base.len - offset), eit.base,
196- eit.base, static_cast<size_t>(eit.len));197+ static_cast<size_t>(eit.len));
197 if (err != EOK) {198 if (err != EOK) {
198 return IDE_DAEMON_ERROR;199 return IDE_DAEMON_ERROR;
199 }200 }
@@ -207,9 +208,9 @@ static int32_t IoVecListToMem(std::list<struct IoVec> &ioList, struct IoVec &bas
207 * @brief free list of iovec208 * @brief free list of iovec
208 * @param [in] ioList ide daemon hdc client209 * @param [in] ioList ide daemon hdc client
209 */210 */
210-static void IoVecListFree(std::list<struct IoVec> &ioList)211+static void IoVecListFree(std::list<struct IoVec>& ioList)
211{212{
212- for (auto &eit: ioList) {213+ for (auto& eit : ioList) {
213 IDE_XFREE_AND_SET_NULL(eit.base);214 IDE_XFREE_AND_SET_NULL(eit.base);
214 }215 }
215 ioList.clear();216 ioList.clear();
@@ -224,7 +225,7 @@ static void IoVecListFree(std::list<struct IoVec> &ioList)
224 * IDE_DAEMON_OK: store data succ225 * IDE_DAEMON_OK: store data succ
225 * IDE_DAEMON_ERROR: store data failed226 * IDE_DAEMON_ERROR: store data failed
226 */227 */
227-int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)228+int32_t HdcStorePackage(const IdeHdcPacket& packet, struct IoVec& ioVec)
228{229{
229 IdeStringBuffer buf = reinterpret_cast<IdeStringBuffer>(ioVec.base);230 IdeStringBuffer buf = reinterpret_cast<IdeStringBuffer>(ioVec.base);
230 // little package packet type231 // little package packet type
@@ -236,9 +237,8 @@ int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)
236 237 
237 const uint32_t len = ioVec.len + packet.len;238 const uint32_t len = ioVec.len + packet.len;
238 // malloc new buffer for adding new data239 // malloc new buffer for adding new data
239- IdeStringBuffer newBuf = static_cast<IdeStringBuffer>(IdeXrmalloc(buf,240+ IdeStringBuffer newBuf =
240- static_cast<size_t>(ioVec.len),241+ static_cast<IdeStringBuffer>(IdeXrmalloc(buf, static_cast<size_t>(ioVec.len), static_cast<size_t>(len)));
241- static_cast<size_t>(len)));
242 if (newBuf == nullptr) {242 if (newBuf == nullptr) {
243 IDE_LOGE("Ide Xrmalloc Failed");243 IDE_LOGE("Ide Xrmalloc Failed");
244 return IDE_DAEMON_ERROR;244 return IDE_DAEMON_ERROR;
@@ -246,8 +246,8 @@ int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)
246 IDE_XFREE_AND_SET_NULL(buf);246 IDE_XFREE_AND_SET_NULL(buf);
247 buf = newBuf;247 buf = newBuf;
248 // add new package data248 // add new package data
249- const errno_t ret = memcpy_s(buf + ioVec.len, static_cast<size_t>(packet.len),249+ const errno_t ret =
250- packet.value, static_cast<size_t>(packet.len));250+ memcpy_s(buf + ioVec.len, static_cast<size_t>(packet.len), packet.value, static_cast<size_t>(packet.len));
251 if (ret != EOK) {251 if (ret != EOK) {
252 IDE_LOGE("memory copy failed, ret: %d", ret);252 IDE_LOGE("memory copy failed, ret: %d", ret);
253 IDE_XFREE_AND_SET_NULL(buf);253 IDE_XFREE_AND_SET_NULL(buf);
@@ -262,8 +262,7 @@ int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)
262 return IDE_DAEMON_ERROR;262 return IDE_DAEMON_ERROR;
263}263}
264 264 
265-static int32_t HdcReadPackage(struct drvHdcMsg &pmsg, IdeLastPacket &isLast,265+static int32_t HdcReadPackage(struct drvHdcMsg& pmsg, IdeLastPacket& isLast, int32_t recvBufCount, struct IoVec& ioVec)
266- int32_t recvBufCount, struct IoVec &ioVec)
267{266{
268 IdeStringBuffer pBuf = nullptr;267 IdeStringBuffer pBuf = nullptr;
269 int32_t pBufLen = 0;268 int32_t pBufLen = 0;
@@ -271,16 +270,15 @@ static int32_t HdcReadPackage(struct drvHdcMsg &pmsg, IdeLastPacket &isLast,
271 int32_t i = 0;270 int32_t i = 0;
272 for (; i < recvBufCount; i++) {271 for (; i < recvBufCount; i++) {
273 const hdcError_t error = drvHdcGetMsgBuffer(&pmsg, i, &pBuf, &pBufLen);272 const hdcError_t error = drvHdcGetMsgBuffer(&pmsg, i, &pBuf, &pBufLen);
274- IDE_CTRL_VALUE_FAILED(error == DRV_ERROR_NONE,273+ IDE_CTRL_VALUE_FAILED(error == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "Hdc Get Msg Buffer, error %d", error);
275- return IDE_DAEMON_ERROR, "Hdc Get Msg Buffer, error %d", error);
276 if (pBuf != nullptr && pBufLen > 0) {274 if (pBuf != nullptr && pBufLen > 0) {
277- struct IdeHdcPacket *packet = reinterpret_cast<struct IdeHdcPacket*>(pBuf);275+ struct IdeHdcPacket* packet = reinterpret_cast<struct IdeHdcPacket*>(pBuf);
278- IDE_CTRL_VALUE_FAILED(static_cast<uint32_t>(pBufLen) >= sizeof(IdeHdcPacket) + packet->len,276+ IDE_CTRL_VALUE_FAILED(
279- return IDE_DAEMON_ERROR, "packet len is larger than pBufLen");277+ static_cast<uint32_t>(pBufLen) >= sizeof(IdeHdcPacket) + packet->len, return IDE_DAEMON_ERROR,
278+ "packet len is larger than pBufLen");
280 // store package by packet type279 // store package by packet type
281 const int32_t err = HdcStorePackage(*packet, ioVec);280 const int32_t err = HdcStorePackage(*packet, ioVec);
282- IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return IDE_DAEMON_ERROR,281+ IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return IDE_DAEMON_ERROR, "Hdc store package, error");
283- "Hdc store package, error");
284 // receive the last package is true282 // receive the last package is true
285 if (packet->isLast == IdeLastPacket::IDE_LAST_PACK) {283 if (packet->isLast == IdeLastPacket::IDE_LAST_PACK) {
286 isLast = IdeLastPacket::IDE_LAST_PACK;284 isLast = IdeLastPacket::IDE_LAST_PACK;
@@ -299,8 +297,8 @@ static int32_t HdcReadPackage(struct drvHdcMsg &pmsg, IdeLastPacket &isLast,
299 * @param [out] recvLen : length of hdc data297 * @param [out] recvLen : length of hdc data
300 * @return IDE_DAEMON_OK : success; IDE_DAEMON_ERROR:failed298 * @return IDE_DAEMON_OK : success; IDE_DAEMON_ERROR:failed
301 */299 */
302-static int32_t HdcReadIovecToMem(std::list<struct IoVec> &hdcIoList, uint32_t bufLen, IdeRecvBuffT recvBuf,300+static int32_t HdcReadIovecToMem(
303- IdeI32Pt recvLen)301+ std::list<struct IoVec>& hdcIoList, uint32_t bufLen, IdeRecvBuffT recvBuf, IdeI32Pt recvLen)
304{302{
305 struct IoVec ioBase = {nullptr, 0};303 struct IoVec ioBase = {nullptr, 0};
306 IDE_CTRL_VALUE_FAILED(recvBuf != nullptr, return IDE_DAEMON_ERROR, "recvBuf is nullptr");304 IDE_CTRL_VALUE_FAILED(recvBuf != nullptr, return IDE_DAEMON_ERROR, "recvBuf is nullptr");
@@ -324,14 +322,14 @@ static int32_t HdcReadIovecToMem(std::list<struct IoVec> &hdcIoList, uint32_t bu
324 return IDE_DAEMON_OK;322 return IDE_DAEMON_OK;
325}323}
326 324 
327-static inline void HdcReadBuffFree(struct drvHdcMsg *pmsg, std::list<struct IoVec> &ioList)325+static inline void HdcReadBuffFree(struct drvHdcMsg* pmsg, std::list<struct IoVec>& ioList)
328{326{
329 IDE_FREE_HDC_MSG_AND_SET_NULL(pmsg);327 IDE_FREE_HDC_MSG_AND_SET_NULL(pmsg);
330 IoVecListFree(ioList);328 IoVecListFree(ioList);
331}329}
332 330 
333-static int32_t HdcRecvData(HDC_SESSION session, struct drvHdcMsg *pmsg, int32_t nbFlag, int32_t *recvBufCount,331+static int32_t HdcRecvData(
334- uint32_t timeout)332+ HDC_SESSION session, struct drvHdcMsg* pmsg, int32_t nbFlag, int32_t* recvBufCount, uint32_t timeout)
335{333{
336 uint32_t len = 0;334 uint32_t len = 0;
337 const hdcError_t error = halHdcRecv(session, pmsg, len, nbFlag, recvBufCount, timeout);335 const hdcError_t error = halHdcRecv(session, pmsg, len, nbFlag, recvBufCount, timeout);
@@ -363,10 +361,10 @@ static int32_t HdcRecvData(HDC_SESSION session, struct drvHdcMsg *pmsg, int32_t
363 * IDE_DAEMON_OK: read succ361 * IDE_DAEMON_OK: read succ
364 * IDE_DAEMON_ERROR: read failed362 * IDE_DAEMON_ERROR: read failed
365 */363 */
366-static int32_t HdcSessionRead(HDC_SESSION session, const IdeRecvBuffT recvBuf, const IdeI32Pt recvLen, int32_t nbFlag,364+static int32_t HdcSessionRead(
367- uint32_t timeout)365+ HDC_SESSION session, const IdeRecvBuffT recvBuf, const IdeI32Pt recvLen, int32_t nbFlag, uint32_t timeout)
368{366{
369- struct drvHdcMsg *pmsg = nullptr;367+ struct drvHdcMsg* pmsg = nullptr;
370 constexpr int32_t count = 1;368 constexpr int32_t count = 1;
371 int32_t recvBufCount = 0;369 int32_t recvBufCount = 0;
372 IdeLastPacket isLast = IdeLastPacket::IDE_NOT_LAST_PACK;370 IdeLastPacket isLast = IdeLastPacket::IDE_NOT_LAST_PACK;
@@ -380,8 +378,8 @@ static int32_t HdcSessionRead(HDC_SESSION session, const IdeRecvBuffT recvBuf, c
380 378 
381 // 1.request alloc hdc message, count is 1379 // 1.request alloc hdc message, count is 1
382 hdcError_t error = drvHdcAllocMsg(session, &pmsg, count);380 hdcError_t error = drvHdcAllocMsg(session, &pmsg, count);
383- IDE_CTRL_VALUE_FAILED((error == DRV_ERROR_NONE) && (pmsg != nullptr),381+ IDE_CTRL_VALUE_FAILED(
384- return IDE_DAEMON_ERROR, "Hdc Alloc Msg, error %d", error);382+ (error == DRV_ERROR_NONE) && (pmsg != nullptr), return IDE_DAEMON_ERROR, "Hdc Alloc Msg, error %d", error);
385 uint32_t pkgCount = 0;383 uint32_t pkgCount = 0;
386 while (true) {384 while (true) {
387 // 2.Receive data, since the count is 1 when applying the descriptor, read up to 1 buf at a time.385 // 2.Receive data, since the count is 1 when applying the descriptor, read up to 1 buf at a time.
@@ -501,8 +499,8 @@ int32_t HdcReadTimeout(HDC_SESSION session, uint32_t timeout, IdeRecvBuffT recvB
501 * DRV_ERROR_NONE: send succ499 * DRV_ERROR_NONE: send succ
502 * others: send failed500 * others: send failed
503 */501 */
504-static hdcError_t HdcWritePackage(HDC_SESSION session, DataSendMsg dataSendMsg,502+static hdcError_t HdcWritePackage(
505- struct drvHdcMsg *pmsg, struct IdeHdcPacket *packet, int32_t flag)503+ HDC_SESSION session, DataSendMsg dataSendMsg, struct drvHdcMsg* pmsg, struct IdeHdcPacket* packet, int32_t flag)
506{504{
507 hdcError_t hdcError = DRV_ERROR_NONE;505 hdcError_t hdcError = DRV_ERROR_NONE;
508 uint32_t reservedLen = dataSendMsg.bufLen;506 uint32_t reservedLen = dataSendMsg.bufLen;
@@ -529,20 +527,21 @@ static hdcError_t HdcWritePackage(HDC_SESSION session, DataSendMsg dataSendMsg,
529 packet->type = IdeDaemonPackageType::IDE_DAEMON_LITTLE_PACKAGE;527 packet->type = IdeDaemonPackageType::IDE_DAEMON_LITTLE_PACKAGE;
530 packet->len = sendLen;528 packet->len = sendLen;
531 529 
532- const errno_t ret = memcpy_s(packet->value, dataSendMsg.maxSendLen,530+ const errno_t ret = memcpy_s(
533- static_cast<IdeU8Pt>(const_cast<IdeBuffT>(buf)) +531+ packet->value, dataSendMsg.maxSendLen,
534- (totalLen - reservedLen), sendLen);532+ static_cast<IdeU8Pt>(const_cast<IdeBuffT>(buf)) + (totalLen - reservedLen), sendLen);
535 IDE_CTRL_VALUE_FAILED(ret == EOK, return DRV_ERROR_INVALID_VALUE, "memory copy failed");533 IDE_CTRL_VALUE_FAILED(ret == EOK, return DRV_ERROR_INVALID_VALUE, "memory copy failed");
536 534 
537 // add buffer to hdc message535 // add buffer to hdc message
538- hdcError = drvHdcAddMsgBuffer(pmsg, reinterpret_cast<IdeStringBuffer>(packet),536+ hdcError = drvHdcAddMsgBuffer(
539- sizeof(struct IdeHdcPacket) + packet->len);537+ pmsg, reinterpret_cast<IdeStringBuffer>(packet), sizeof(struct IdeHdcPacket) + packet->len);
540 IDE_CTRL_VALUE_FAILED(hdcError == DRV_ERROR_NONE, return hdcError, "Hdc Add Msg Buffer, error: %d", hdcError);538 IDE_CTRL_VALUE_FAILED(hdcError == DRV_ERROR_NONE, return hdcError, "Hdc Add Msg Buffer, error: %d", hdcError);
541 539 
542 // send hdc message540 // send hdc message
543 hdcError = halHdcSend(session, pmsg, flag, timeout);541 hdcError = halHdcSend(session, pmsg, flag, timeout);
544- IDE_CTRL_VALUE_WARN(hdcError == DRV_ERROR_NONE, return hdcError, "Hdc Send, error: %d, session: %zu",542+ IDE_CTRL_VALUE_WARN(
545- hdcError, reinterpret_cast<uintptr_t>(session));543+ hdcError == DRV_ERROR_NONE, return hdcError, "Hdc Send, error: %d, session: %zu", hdcError,
544+ reinterpret_cast<uintptr_t>(session));
546 545 
547 // reuse hdc message546 // reuse hdc message
548 hdcError = drvHdcReuseMsg(pmsg);547 hdcError = drvHdcReuseMsg(pmsg);
@@ -567,21 +566,22 @@ static hdcError_t HdcWritePackage(HDC_SESSION session, DataSendMsg dataSendMsg,
567int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int32_t flag)566int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int32_t flag)
568{567{
569 hdcError_t hdcError;568 hdcError_t hdcError;
570- struct drvHdcMsg *pmsg = nullptr;569+ struct drvHdcMsg* pmsg = nullptr;
571 constexpr int32_t count = 1;570 constexpr int32_t count = 1;
572 uint32_t capacity = 0;571 uint32_t capacity = 0;
573 struct IdeHdcPacket* packet = nullptr;572 struct IdeHdcPacket* packet = nullptr;
574 573 
575- IDE_CTRL_VALUE_FAILED((session != nullptr && buf != nullptr && len > 0),574+ IDE_CTRL_VALUE_FAILED(
576- return IDE_DAEMON_ERROR, "Invalid Parameter");575+ (session != nullptr && buf != nullptr && len > 0), return IDE_DAEMON_ERROR, "Invalid Parameter");
577 576 
578 const int32_t err = HdcCapacity(&capacity);577 const int32_t err = HdcCapacity(&capacity);
579 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return IDE_DAEMON_ERROR, "Hdc Capacity Failed, err: %d", err);578 IDE_CTRL_VALUE_FAILED(err == IDE_DAEMON_OK, return IDE_DAEMON_ERROR, "Hdc Capacity Failed, err: %d", err);
580 579 
581 // 1.request alloc hdc message, count is 1580 // 1.request alloc hdc message, count is 1
582 hdcError = drvHdcAllocMsg(session, &pmsg, count);581 hdcError = drvHdcAllocMsg(session, &pmsg, count);
583- IDE_CTRL_VALUE_FAILED((hdcError == DRV_ERROR_NONE) && (pmsg != nullptr),582+ IDE_CTRL_VALUE_FAILED(
584- return IDE_DAEMON_ERROR, "Hdc Alloc Msg, error: %d", hdcError);583+ (hdcError == DRV_ERROR_NONE) && (pmsg != nullptr), return IDE_DAEMON_ERROR, "Hdc Alloc Msg, error: %d",
584+ hdcError);
585 585 
586 const uint32_t maxDatalen = capacity - sizeof(struct IdeHdcPacket);586 const uint32_t maxDatalen = capacity - sizeof(struct IdeHdcPacket);
587 const size_t packetLen = sizeof(struct IdeHdcPacket) + maxDatalen;587 const size_t packetLen = sizeof(struct IdeHdcPacket) + maxDatalen;
@@ -592,7 +592,7 @@ int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int3
592 return IDE_DAEMON_ERROR;592 return IDE_DAEMON_ERROR;
593 }593 }
594 594 
595- struct DataSendMsg dataSendMsg = { buf, len, maxDatalen };595+ struct DataSendMsg dataSendMsg = {buf, len, maxDatalen};
596 hdcError = HdcWritePackage(session, dataSendMsg, pmsg, packet, flag);596 hdcError = HdcWritePackage(session, dataSendMsg, pmsg, packet, flag);
597 597 
598 // free packet598 // free packet
@@ -603,8 +603,8 @@ int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int3
603 IDE_CTRL_VALUE_FAILED(ret == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "Hdc Free Msg, error: %d", ret);603 IDE_CTRL_VALUE_FAILED(ret == DRV_ERROR_NONE, return IDE_DAEMON_ERROR, "Hdc Free Msg, error: %d", ret);
604 pmsg = nullptr;604 pmsg = nullptr;
605 605 
606- return hdcError == DRV_ERROR_NONE ? IDE_DAEMON_OK : (hdcError == DRV_ERROR_SOCKET_CLOSE ?606+ return hdcError == DRV_ERROR_NONE ? IDE_DAEMON_OK :
607- IDE_DAEMON_SOCK_CLOSE : IDE_DAEMON_ERROR);607+ (hdcError == DRV_ERROR_SOCKET_CLOSE ? IDE_DAEMON_SOCK_CLOSE : IDE_DAEMON_ERROR);
608}608}
609 609 
610/**610/**
@@ -656,7 +656,7 @@ int32_t HdcWriteNb(HDC_SESSION session, IdeSendBuffT buf, int32_t len)
656 * IDE_DAEMON_OK: connect succ656 * IDE_DAEMON_OK: connect succ
657 * IDE_DAEMON_ERROR: connect failed657 * IDE_DAEMON_ERROR: connect failed
658 */658 */
659-int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION *session)659+int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION* session)
660{660{
661 IDE_CTRL_VALUE_FAILED(peerNode >= 0, return IDE_DAEMON_ERROR, "peer_node is invalid");661 IDE_CTRL_VALUE_FAILED(peerNode >= 0, return IDE_DAEMON_ERROR, "peer_node is invalid");
662 IDE_CTRL_VALUE_FAILED(peerDevId >= 0, return IDE_DAEMON_ERROR, "peer_devid is invalid");662 IDE_CTRL_VALUE_FAILED(peerDevId >= 0, return IDE_DAEMON_ERROR, "peer_devid is invalid");
@@ -693,8 +693,8 @@ int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client
693 * IDE_DAEMON_OK: connect succ693 * IDE_DAEMON_OK: connect succ
694 * IDE_DAEMON_ERROR: connect failed694 * IDE_DAEMON_ERROR: connect failed
695 */695 */
696-int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,696+int32_t HalHdcSessionConnect(
697- int32_t hostPid, HDC_CLIENT client, HDC_SESSION *session)697+ int32_t peerNode, int32_t peerDevId, int32_t hostPid, HDC_CLIENT client, HDC_SESSION* session)
698{698{
699 IDE_CTRL_VALUE_FAILED(peerNode >= 0, return IDE_DAEMON_ERROR, "peer_node is invalid");699 IDE_CTRL_VALUE_FAILED(peerNode >= 0, return IDE_DAEMON_ERROR, "peer_node is invalid");
700 IDE_CTRL_VALUE_FAILED(peerDevId >= 0, return IDE_DAEMON_ERROR, "peer_devid is invalid");700 IDE_CTRL_VALUE_FAILED(peerDevId >= 0, return IDE_DAEMON_ERROR, "peer_devid is invalid");
@@ -720,7 +720,6 @@ int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,
720 return IDE_DAEMON_OK;720 return IDE_DAEMON_OK;
721}721}
722 722 
723- 
724/**723/**
725 * @brief destroy hdc_connect session724 * @brief destroy hdc_connect session
726 * @param session: the session created by hdc connect725 * @param session: the session created by hdc connect
@@ -896,7 +895,7 @@ int32_t IdeGetPidBySession(HDC_SESSION session, IdeI32Pt pid)
896 return IDE_DAEMON_OK;895 return IDE_DAEMON_OK;
897}896}
898 897 
899- /**898+/**
900 * @brief : get attribute value by HDC session and attribute type899 * @brief : get attribute value by HDC session and attribute type
901 * @param [in] : handle hdc session900 * @param [in] : handle hdc session
902 * @param [in] : attr attribute type901 * @param [in] : attr attribute type
@@ -920,5 +919,4 @@ int32_t IdeGetAttrBySession(HDC_SESSION session, int32_t attr, IdeI32Pt value)
920 919 
921 return IDE_DAEMON_OK;920 return IDE_DAEMON_OK;
922}921}
923-}922+} // namespace Adx
924- 
@@ -14,24 +14,18 @@
14#include "extra_config.h"14#include "extra_config.h"
15 15 
16namespace Adx {16namespace Adx {
17-enum class IdeDaemonPackageType {17+enum class IdeDaemonPackageType { IDE_DAEMON_LITTLE_PACKAGE = 0xB0, IDE_DAEMON_BIG_PACKAGE };
18- IDE_DAEMON_LITTLE_PACKAGE = 0xB0,
19- IDE_DAEMON_BIG_PACKAGE
20-};
21 18 
22-enum class IdeLastPacket:int8_t {19+enum class IdeLastPacket : int8_t { IDE_NOT_LAST_PACK = 0, IDE_LAST_PACK = 1 };
23- IDE_NOT_LAST_PACK = 0,
24- IDE_LAST_PACK = 1
25-};
26 20 
27struct IdeHdcPacket {21struct IdeHdcPacket {
28 uint32_t len;22 uint32_t len;
29- IdeDaemonPackageType type; // package type : big package,little package23+ IdeDaemonPackageType type; // package type : big package,little package
30- IdeLastPacket isLast; // only 0:is not last package; 1:last package24+ IdeLastPacket isLast; // only 0:is not last package; 1:last package
31 char value[0];25 char value[0];
32};26};
33 27 
34-int32_t HdcClientInit(HDC_CLIENT *client);28+int32_t HdcClientInit(HDC_CLIENT* client);
35 29 
36struct IoVec {30struct IoVec {
37 IdeBuffT base;31 IdeBuffT base;
@@ -111,8 +105,7 @@ int32_t HdcWriteNb(HDC_SESSION session, IdeSendBuffT buf, int32_t len);
111 * IDE_DAEMON_OK: connect succ105 * IDE_DAEMON_OK: connect succ
112 * IDE_DAEMON_ERROR: connect failed106 * IDE_DAEMON_ERROR: connect failed
113 */107 */
114-int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId,108+int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION* session);
115- HDC_CLIENT client, HDC_SESSION *session);
116 109 
117/**110/**
118 * @brief connect remote hal hdc server111 * @brief connect remote hal hdc server
@@ -125,8 +118,8 @@ int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId,
125 * IDE_DAEMON_OK: connect success118 * IDE_DAEMON_OK: connect success
126 * IDE_DAEMON_ERROR: connect failed119 * IDE_DAEMON_ERROR: connect failed
127 */120 */
128-int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,121+int32_t HalHdcSessionConnect(
129- int32_t hostPid, HDC_CLIENT client, HDC_SESSION *session);122+ int32_t peerNode, int32_t peerDevId, int32_t hostPid, HDC_CLIENT client, HDC_SESSION* session);
130 123 
131/**124/**
132 * @brief Destroy an HDC session (Client).125 * @brief Destroy an HDC session (Client).
@@ -160,7 +153,7 @@ int32_t IdeGetVfIdBySession(HDC_SESSION session, IdeI32Pt vfId);
160int32_t IdeGetPidBySession(HDC_SESSION session, IdeI32Pt pid);153int32_t IdeGetPidBySession(HDC_SESSION session, IdeI32Pt pid);
161int32_t IdeGetAttrBySession(HDC_SESSION session, int32_t attr, IdeI32Pt value);154int32_t IdeGetAttrBySession(HDC_SESSION session, int32_t attr, IdeI32Pt value);
162int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int32_t flag);155int32_t HdcSessionWrite(HDC_SESSION session, IdeSendBuffT buf, int32_t len, int32_t flag);
163-int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec);156+int32_t HdcStorePackage(const IdeHdcPacket& packet, struct IoVec& ioVec);
164-}157+} // namespace Adx
165 158 
166#endif159#endif
@@ -16,12 +16,13 @@
16#include "ide_os_type.h"16#include "ide_os_type.h"
17#include "hdc_api.h"17#include "hdc_api.h"
18 18 
19-#define IDE_FREE_HDC_MSG_AND_SET_NULL(ptr) do { \19+#define IDE_FREE_HDC_MSG_AND_SET_NULL(ptr) \
20- if ((ptr) != nullptr) { \20+ do { \
21- (void)drvHdcFreeMsg(ptr); \21+ if ((ptr) != nullptr) { \
22- ptr = nullptr; \22+ (void)drvHdcFreeMsg(ptr); \
23- } \23+ ptr = nullptr; \
24-} while (0)24+ } \
25+ } while (0)
25 26 
26using namespace IdeDaemon::Common::Config;27using namespace IdeDaemon::Common::Config;
27 28 
@@ -40,7 +41,7 @@ struct DataSendMsg {
40 * IDE_DAEMON_OK: init succ41 * IDE_DAEMON_OK: init succ
41 * IDE_DAEMON_ERROR: init failed42 * IDE_DAEMON_ERROR: init failed
42 */43 */
43-int32_t HdcClientInit(HDC_CLIENT *client)44+int32_t HdcClientInit(HDC_CLIENT* client)
44{45{
45 UNUSED(client);46 UNUSED(client);
46 return IDE_DAEMON_ERROR;47 return IDE_DAEMON_ERROR;
@@ -110,7 +111,7 @@ HDC_SESSION HdcServerAccept(HDC_SERVER server)
110 * IDE_DAEMON_OK: store data succ111 * IDE_DAEMON_OK: store data succ
111 * IDE_DAEMON_ERROR: store data failed112 * IDE_DAEMON_ERROR: store data failed
112 */113 */
113-int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)114+int32_t HdcStorePackage(const IdeHdcPacket& packet, struct IoVec& ioVec)
114{115{
115 UNUSED(packet);116 UNUSED(packet);
116 UNUSED(ioVec);117 UNUSED(ioVec);
@@ -128,8 +129,8 @@ int32_t HdcStorePackage(const IdeHdcPacket &packet, struct IoVec &ioVec)
128 * IDE_DAEMON_OK: read succ129 * IDE_DAEMON_OK: read succ
129 * IDE_DAEMON_ERROR: read failed130 * IDE_DAEMON_ERROR: read failed
130 */131 */
131-static int32_t HdcSessionRead(HDC_SESSION session, const IdeRecvBuffT recvBuf, const IdeI32Pt recvLen, int32_t nbFlag,132+static int32_t HdcSessionRead(
132- uint32_t timeout)133+ HDC_SESSION session, const IdeRecvBuffT recvBuf, const IdeI32Pt recvLen, int32_t nbFlag, uint32_t timeout)
133{134{
134 UNUSED(session);135 UNUSED(session);
135 UNUSED(timeout);136 UNUSED(timeout);
@@ -245,7 +246,7 @@ int32_t HdcWriteNb(HDC_SESSION session, IdeSendBuffT buf, int32_t len)
245 * IDE_DAEMON_OK: connect succ246 * IDE_DAEMON_OK: connect succ
246 * IDE_DAEMON_ERROR: connect failed247 * IDE_DAEMON_ERROR: connect failed
247 */248 */
248-int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION *session)249+int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client, HDC_SESSION* session)
249{250{
250 UNUSED(peerNode);251 UNUSED(peerNode);
251 UNUSED(peerDevId);252 UNUSED(peerDevId);
@@ -266,8 +267,8 @@ int32_t HdcSessionConnect(int32_t peerNode, int32_t peerDevId, HDC_CLIENT client
266 * IDE_DAEMON_OK: connect succ267 * IDE_DAEMON_OK: connect succ
267 * IDE_DAEMON_ERROR: connect failed268 * IDE_DAEMON_ERROR: connect failed
268 */269 */
269-int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,270+int32_t HalHdcSessionConnect(
270- int32_t hostPid, HDC_CLIENT client, HDC_SESSION *session)271+ int32_t peerNode, int32_t peerDevId, int32_t hostPid, HDC_CLIENT client, HDC_SESSION* session)
271{272{
272 UNUSED(peerNode);273 UNUSED(peerNode);
273 UNUSED(peerDevId);274 UNUSED(peerDevId);
@@ -277,7 +278,6 @@ int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,
277 return IDE_DAEMON_ERROR;278 return IDE_DAEMON_ERROR;
278}279}
279 280 
280- 
281/**281/**
282 * @brief destroy hdc_connect session282 * @brief destroy hdc_connect session
283 * @param session: the session created by hdc connect283 * @param session: the session created by hdc connect
@@ -286,10 +286,7 @@ int32_t HalHdcSessionConnect(int32_t peerNode, int32_t peerDevId,
286 * IDE_DAEMON_OK: destroy succ286 * IDE_DAEMON_OK: destroy succ
287 * IDE_DAEMON_ERROR: destroy failed287 * IDE_DAEMON_ERROR: destroy failed
288 */288 */
289-int32_t HdcSessionDestroy(HDC_SESSION session)289+int32_t HdcSessionDestroy(HDC_SESSION session) { return HdcSessionClose(session); }
290-{
291- return HdcSessionClose(session);
292-}
293 290 
294/**291/**
295 * @brief destroy hdc_accpet session292 * @brief destroy hdc_accpet session
@@ -381,7 +378,7 @@ int32_t IdeGetPidBySession(HDC_SESSION session, IdeI32Pt pid)
381 return IDE_DAEMON_ERROR;378 return IDE_DAEMON_ERROR;
382}379}
383 380 
384- /**381+/**
385 * @brief : get attribute value by HDC session and attribute type382 * @brief : get attribute value by HDC session and attribute type
386 * @param [in] : handle hdc session383 * @param [in] : handle hdc session
387 * @param [in] : attr attribute type384 * @param [in] : attr attribute type
@@ -395,4 +392,4 @@ int32_t IdeGetAttrBySession(HDC_SESSION session, int32_t attr, IdeI32Pt value)
395 UNUSED(value);392 UNUSED(value);
396 return IDE_DAEMON_ERROR;393 return IDE_DAEMON_ERROR;
397}394}
398-}395+} // namespace Adx
@@ -11,48 +11,48 @@
11#define ADX_MSG_H11#define ADX_MSG_H
12#include <cstdint>12#include <cstdint>
13namespace Adx {13namespace Adx {
14-const uint16_t ADX_PROTO_MAGIC_VALUE = 0xC396;14+const uint16_t ADX_PROTO_MAGIC_VALUE = 0xC396;
15-const uint8_t ADX_PROTO_VERSION = 0x10; // version v1.015+const uint8_t ADX_PROTO_VERSION = 0x10; // version v1.0
16-enum class MsgType:uint16_t {16+enum class MsgType : uint16_t {
17 MSG_DATA,17 MSG_DATA,
18 MSG_CTRL,18 MSG_CTRL,
19 NR_MSG_TYPE,19 NR_MSG_TYPE,
20};20};
21 21 
22-enum class MsgStatus:uint16_t {22+enum class MsgStatus : uint16_t {
23 // contrl status23 // contrl status
24 MSG_STATUS_HAND_SHAKE,24 MSG_STATUS_HAND_SHAKE,
25- MSG_STATUS_DATA_IN, // in transfering data25+ MSG_STATUS_DATA_IN, // in transfering data
26- MSG_STATUS_DATA_END, // transfering end message26+ MSG_STATUS_DATA_END, // transfering end message
27 // msg status // data dump remote message27 // msg status // data dump remote message
28- MSG_STATUS_FILE_LOAD, // begin load file28+ MSG_STATUS_FILE_LOAD, // begin load file
29- MSG_STATUS_LOAD_ERROR, // load file exception29+ MSG_STATUS_LOAD_ERROR, // load file exception
30- MSG_STATUS_LOAD_DONE, // load file done30+ MSG_STATUS_LOAD_DONE, // load file done
31 // return status31 // return status
32- MSG_STATUS_NONE_ERROR, // none32+ MSG_STATUS_NONE_ERROR, // none
33- MSG_STATUS_FILE_ERROR, // file33+ MSG_STATUS_FILE_ERROR, // file
34- MSG_STATUS_MEMORY_ERROR, // opreate memory error34+ MSG_STATUS_MEMORY_ERROR, // opreate memory error
35- MSG_STATUS_NO_SPACE_ERROR, // no disk space35+ MSG_STATUS_NO_SPACE_ERROR, // no disk space
36- MSG_STATUS_PREMISSION_ERROR, // permission deny36+ MSG_STATUS_PREMISSION_ERROR, // permission deny
37- MSG_STATUS_CACHE_FULL_ERROR, // cache full37+ MSG_STATUS_CACHE_FULL_ERROR, // cache full
38 // link status38 // link status
39- MSG_STATUS_LONG_LINK, // long link39+ MSG_STATUS_LONG_LINK, // long link
40- MSG_STATUS_SHORT_LINK, // short link40+ MSG_STATUS_SHORT_LINK, // short link
41 NR_MSG_STATUS41 NR_MSG_STATUS
42};42};
43 43 
44struct MsgProto {44struct MsgProto {
45- uint16_t headInfo; // head magic data, judge to little,45+ uint16_t headInfo; // head magic data, judge to little,
46- uint8_t headVer; // head version46+ uint8_t headVer; // head version
47- uint8_t order; // packet order (reserved)47+ uint8_t order; // packet order (reserved)
48- uint16_t reqType; // request type of proto48+ uint16_t reqType; // request type of proto
49- uint16_t devId; // request device Id49+ uint16_t devId; // request device Id
50- uint32_t totalLen; // whole message length, only all data[0] length50+ uint32_t totalLen; // whole message length, only all data[0] length
51- uint32_t sliceLen; // one slice length, only data[0] length51+ uint32_t sliceLen; // one slice length, only data[0] length
52- uint32_t offset; // offset52+ uint32_t offset; // offset
53- MsgType msgType; // message type53+ MsgType msgType; // message type
54- MsgStatus status; // message status data54+ MsgStatus status; // message status data
55- uint8_t data[0]; // message data55+ uint8_t data[0]; // message data
56};56};
57-}57+} // namespace Adx
58-#endif58+#endif
@@ -15,28 +15,28 @@
15#include "log/adx_log.h"15#include "log/adx_log.h"
16#include "adx_comm_opt_manager.h"16#include "adx_comm_opt_manager.h"
17namespace Adx {17namespace Adx {
18-static const uint32_t MAX_PROTO_FILE_BUFFER_SIZE = 512000; // 500kb18+static const uint32_t MAX_PROTO_FILE_BUFFER_SIZE = 512000; // 500kb
19-static const int32_t MAX_DEV_FILE_SIZE = 4096; // 4k19+static const int32_t MAX_DEV_FILE_SIZE = 4096; // 4k
20 20 
21-MsgProto *AdxMsgProto::CreateMsgPacket(CmdClassT type, uint16_t devId, IdeSendBuffT data, uint32_t length)21+MsgProto* AdxMsgProto::CreateMsgPacket(CmdClassT type, uint16_t devId, IdeSendBuffT data, uint32_t length)
22{22{
23- MsgProto *msg = AdxMsgProto::CreateDataMsg(data, length);23+ MsgProto* msg = AdxMsgProto::CreateDataMsg(data, length);
24 IDE_CTRL_VALUE_FAILED(msg != nullptr, return nullptr, "create message failed");24 IDE_CTRL_VALUE_FAILED(msg != nullptr, return nullptr, "create message failed");
25 msg->devId = devId;25 msg->devId = devId;
26 msg->reqType = type;26 msg->reqType = type;
27 return msg;27 return msg;
28}28}
29 29 
30-MsgProto *AdxMsgProto::CreateMsgByType(MsgType type, IdeSendBuffT data, uint32_t length)30+MsgProto* AdxMsgProto::CreateMsgByType(MsgType type, IdeSendBuffT data, uint32_t length)
31{31{
32- MsgProto *msg = nullptr;32+ MsgProto* msg = nullptr;
33 if (length > UINT32_MAX - sizeof(MsgProto)) {33 if (length > UINT32_MAX - sizeof(MsgProto)) {
34 return nullptr;34 return nullptr;
35 }35 }
36 36 
37 if (type == MsgType::MSG_CTRL || type == MsgType::MSG_DATA) {37 if (type == MsgType::MSG_CTRL || type == MsgType::MSG_DATA) {
38 uint32_t mallocLen = length + sizeof(MsgProto);38 uint32_t mallocLen = length + sizeof(MsgProto);
39- msg = reinterpret_cast<MsgProto *>(IdeXmalloc(mallocLen));39+ msg = reinterpret_cast<MsgProto*>(IdeXmalloc(mallocLen));
40 IDE_CTRL_VALUE_FAILED(msg != nullptr, return nullptr, "malloc memory failed");40 IDE_CTRL_VALUE_FAILED(msg != nullptr, return nullptr, "malloc memory failed");
41 if (data != nullptr) { // send buffer(data) not nullptr copy data to message41 if (data != nullptr) { // send buffer(data) not nullptr copy data to message
42 int32_t ret = memcpy_s(msg->data, length, data, length);42 int32_t ret = memcpy_s(msg->data, length, data, length);
@@ -60,12 +60,12 @@ MsgProto *AdxMsgProto::CreateMsgByType(MsgType type, IdeSendBuffT data, uint32_t
60 return nullptr;60 return nullptr;
61}61}
62 62 
63-MsgProto *AdxMsgProto::CreateDataMsg(IdeSendBuffT data, uint32_t length)63+MsgProto* AdxMsgProto::CreateDataMsg(IdeSendBuffT data, uint32_t length)
64{64{
65 return CreateMsgByType(MsgType::MSG_DATA, data, length);65 return CreateMsgByType(MsgType::MSG_DATA, data, length);
66}66}
67 67 
68-int32_t AdxMsgProto::CreateCtrlMsg(MsgProto &proto, MsgStatus status)68+int32_t AdxMsgProto::CreateCtrlMsg(MsgProto& proto, MsgStatus status)
69{69{
70 proto.headInfo = ADX_PROTO_MAGIC_VALUE;70 proto.headInfo = ADX_PROTO_MAGIC_VALUE;
71 proto.headVer = ADX_PROTO_VERSION;71 proto.headVer = ADX_PROTO_VERSION;
@@ -77,28 +77,29 @@ int32_t AdxMsgProto::CreateCtrlMsg(MsgProto &proto, MsgStatus status)
77 return IDE_DAEMON_OK;77 return IDE_DAEMON_OK;
78}78}
79 79 
80-MsgCode AdxMsgProto::SendMsgData(const CommHandle &handle, CmdClassT type, MsgStatus status,80+MsgCode AdxMsgProto::SendMsgData(
81- IdeSendBuffT data, uint32_t length)81+ const CommHandle& handle, CmdClassT type, MsgStatus status, IdeSendBuffT data, uint32_t length)
82{82{
83- MsgProto *msg = AdxMsgProto::CreateMsgPacket(type, 0, data, length);83+ MsgProto* msg = AdxMsgProto::CreateMsgPacket(type, 0, data, length);
84 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");84 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");
85 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);85 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);
86 sendDataMsgPtr->status = status;86 sendDataMsgPtr->status = status;
87 msg = nullptr;87 msg = nullptr;
88- int32_t ret = AdxCommOptManager::Instance().Write(handle, sendDataMsgPtr.get(),88+ int32_t ret = AdxCommOptManager::Instance().Write(
89- sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);89+ handle, sendDataMsgPtr.get(), sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);
90 if (ret != IDE_DAEMON_OK) {90 if (ret != IDE_DAEMON_OK) {
91- IDE_LOGE("send message failed, ret: %d, session: %zu, length: %u bytes, please check peer end is alive",91+ IDE_LOGE(
92- ret, handle.session, length);92+ "send message failed, ret: %d, session: %zu, length: %u bytes, please check peer end is alive", ret,
93+ handle.session, length);
93 return IDE_DAEMON_CHANNEL_ERROR;94 return IDE_DAEMON_CHANNEL_ERROR;
94 }95 }
95 96 
96 return IDE_DAEMON_NONE_ERROR;97 return IDE_DAEMON_NONE_ERROR;
97}98}
98 99 
99-MsgCode AdxMsgProto::GetStringMsgData(const CommHandle &handle, std::string &value)100+MsgCode AdxMsgProto::GetStringMsgData(const CommHandle& handle, std::string& value)
100{101{
101- MsgProto *req = nullptr;102+ MsgProto* req = nullptr;
102 int32_t length = 0;103 int32_t length = 0;
103 int32_t blockType = COMM_OPT_NOBLOCK;104 int32_t blockType = COMM_OPT_NOBLOCK;
104 if (handle.timeout == 0) {105 if (handle.timeout == 0) {
@@ -136,10 +137,10 @@ MsgCode AdxMsgProto::GetStringMsgData(const CommHandle &handle, std::string &val
136 return IDE_DAEMON_NONE_ERROR;137 return IDE_DAEMON_NONE_ERROR;
137}138}
138 139 
139-MsgCode AdxMsgProto::SendEventFile(const CommHandle &handle, CmdClassT type, uint16_t devId, int32_t fd)140+MsgCode AdxMsgProto::SendEventFile(const CommHandle& handle, CmdClassT type, uint16_t devId, int32_t fd)
140{141{
141 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");142 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");
142- MsgProto *msg = AdxMsgProto::CreateMsgPacket(type, devId, nullptr, MAX_PROTO_FILE_BUFFER_SIZE);143+ MsgProto* msg = AdxMsgProto::CreateMsgPacket(type, devId, nullptr, MAX_PROTO_FILE_BUFFER_SIZE);
143 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");144 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");
144 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);145 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);
145 msg = nullptr;146 msg = nullptr;
@@ -155,8 +156,8 @@ MsgCode AdxMsgProto::SendEventFile(const CommHandle &handle, CmdClassT type, uin
155 IDE_LOGW("An EIO exception occurred when reading files from the event_sched directory");156 IDE_LOGW("An EIO exception occurred when reading files from the event_sched directory");
156 len = 0;157 len = 0;
157 } else {158 } else {
158- IDE_CTRL_VALUE_FAILED(len >= 0, return IDE_DAEMON_UNKNOW_ERROR,159+ IDE_CTRL_VALUE_FAILED(
159- "Failed to read file in the event_sched directory: info [%s]",160+ len >= 0, return IDE_DAEMON_UNKNOW_ERROR, "Failed to read file in the event_sched directory: info [%s]",
160 mmGetErrorFormatMessage(err, errBuf, MAX_ERRSTR_LEN));161 mmGetErrorFormatMessage(err, errBuf, MAX_ERRSTR_LEN));
161 }162 }
162 163 
@@ -167,18 +168,19 @@ MsgCode AdxMsgProto::SendEventFile(const CommHandle &handle, CmdClassT type, uin
167 sendDataMsgPtr->totalLen = len;168 sendDataMsgPtr->totalLen = len;
168 sendDataMsgPtr->offset = 0;169 sendDataMsgPtr->offset = 0;
169 sendDataMsgPtr->sliceLen = (uint32_t)len;170 sendDataMsgPtr->sliceLen = (uint32_t)len;
170- int32_t ret = AdxCommOptManager::Instance().Write(handle, sendDataMsgPtr.get(),171+ int32_t ret = AdxCommOptManager::Instance().Write(
171- sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);172+ handle, sendDataMsgPtr.get(), sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);
172- IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR,173+ IDE_CTRL_VALUE_FAILED(
173- "hand shake failed ret %d, please check server is alive", ret);174+ ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR, "hand shake failed ret %d, please check server is alive",
175+ ret);
174 RecvResponse(handle);176 RecvResponse(handle);
175 return IDE_DAEMON_NONE_ERROR;177 return IDE_DAEMON_NONE_ERROR;
176}178}
177 179 
178-MsgCode AdxMsgProto::SendFile(const CommHandle &handle, CmdClassT type, uint16_t devId, int32_t fd)180+MsgCode AdxMsgProto::SendFile(const CommHandle& handle, CmdClassT type, uint16_t devId, int32_t fd)
179{181{
180 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");182 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");
181- MsgProto *msg = AdxMsgProto::CreateMsgPacket(type, devId, nullptr, MAX_PROTO_FILE_BUFFER_SIZE);183+ MsgProto* msg = AdxMsgProto::CreateMsgPacket(type, devId, nullptr, MAX_PROTO_FILE_BUFFER_SIZE);
182 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");184 IDE_CTRL_VALUE_FAILED(msg != nullptr, return IDE_DAEMON_MALLOC_ERROR, "create message failed");
183 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);185 std::unique_ptr<MsgProto, decltype(&IdeXfree)> sendDataMsgPtr(msg, IdeXfree);
184 msg = nullptr;186 msg = nullptr;
@@ -194,24 +196,27 @@ MsgCode AdxMsgProto::SendFile(const CommHandle &handle, CmdClassT type, uint16_t
194 196 
195 if (resLen == 0) {197 if (resLen == 0) {
196 sendDataMsgPtr->sliceLen = (uint32_t)fileLength;198 sendDataMsgPtr->sliceLen = (uint32_t)fileLength;
197- int32_t ret = AdxCommOptManager::Instance().Write(handle, sendDataMsgPtr.get(),199+ int32_t ret = AdxCommOptManager::Instance().Write(
198- sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);200+ handle, sendDataMsgPtr.get(), sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);
199- IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR,201+ IDE_CTRL_VALUE_FAILED(
202+ ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR,
200 "send empty file failed ret %d, please check server is alive", ret);203 "send empty file failed ret %d, please check server is alive", ret);
201 }204 }
202 205 
203 while (resLen > 0) {206 while (resLen > 0) {
204- mmSsize_t readLen = static_cast<uint32_t>(resLen) > MAX_PROTO_FILE_BUFFER_SIZE ?207+ mmSsize_t readLen =
205- MAX_PROTO_FILE_BUFFER_SIZE : resLen;208+ static_cast<uint32_t>(resLen) > MAX_PROTO_FILE_BUFFER_SIZE ? MAX_PROTO_FILE_BUFFER_SIZE : resLen;
206 mmSsize_t len = mmRead(fd, sendDataMsgPtr->data, readLen);209 mmSsize_t len = mmRead(fd, sendDataMsgPtr->data, readLen);
207 char errBuf[MAX_ERRSTR_LEN + 1] = {0};210 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
208- IDE_CTRL_VALUE_FAILED(len >= 0, return IDE_DAEMON_UNKNOW_ERROR,211+ IDE_CTRL_VALUE_FAILED(
209- "read file failed : info [%s]", mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));212+ len >= 0, return IDE_DAEMON_UNKNOW_ERROR, "read file failed : info [%s]",
213+ mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
210 if (len > 0 && len <= readLen) {214 if (len > 0 && len <= readLen) {
211 sendDataMsgPtr->sliceLen = (uint32_t)len;215 sendDataMsgPtr->sliceLen = (uint32_t)len;
212- int32_t ret = AdxCommOptManager::Instance().Write(handle, sendDataMsgPtr.get(),216+ int32_t ret = AdxCommOptManager::Instance().Write(
213- sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);217+ handle, sendDataMsgPtr.get(), sendDataMsgPtr->sliceLen + sizeof(MsgProto), COMM_OPT_BLOCK);
214- IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR,218+ IDE_CTRL_VALUE_FAILED(
219+ ret == IDE_DAEMON_OK, return IDE_DAEMON_CHANNEL_ERROR,
215 "hand shake failed ret %d, please check server is alive", ret);220 "hand shake failed ret %d, please check server is alive", ret);
216 }221 }
217 sendDataMsgPtr->offset += (uint32_t)len;222 sendDataMsgPtr->offset += (uint32_t)len;
@@ -221,16 +226,16 @@ MsgCode AdxMsgProto::SendFile(const CommHandle &handle, CmdClassT type, uint16_t
221 return IDE_DAEMON_NONE_ERROR;226 return IDE_DAEMON_NONE_ERROR;
222}227}
223 228 
224-MsgCode AdxMsgProto::RecvFile(const CommHandle &handle, int32_t fd)229+MsgCode AdxMsgProto::RecvFile(const CommHandle& handle, int32_t fd)
225{230{
226 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");231 IDE_CTRL_VALUE_FAILED(fd >= 0, return IDE_DAEMON_INVALID_PARAM_ERROR, "create message failed");
227- MsgProto *msg = nullptr;232+ MsgProto* msg = nullptr;
228 int32_t length = 0;233 int32_t length = 0;
229 while (true) {234 while (true) {
230- int32_t ret = AdxCommOptManager::Instance().Read(handle, (IdeRecvBuffT)&msg,235+ int32_t ret = AdxCommOptManager::Instance().Read(handle, (IdeRecvBuffT)&msg, length, handle.timeout);
231- length, handle.timeout);236+ IDE_CTRL_VALUE_FAILED(
232- IDE_CTRL_VALUE_FAILED(ret == IDE_DAEMON_OK && msg != nullptr, return IDE_DAEMON_CHANNEL_ERROR,237+ ret == IDE_DAEMON_OK && msg != nullptr, return IDE_DAEMON_CHANNEL_ERROR,
233- "hand shake failed ret %d, read failed or timeout", ret);238+ "hand shake failed ret %d, read failed or timeout", ret);
234 if (msg->msgType == MsgType::MSG_CTRL) { // check the message is ctrl or not239 if (msg->msgType == MsgType::MSG_CTRL) { // check the message is ctrl or not
235 IDE_LOGW("receive ctrl msg from device, stop receiving this file");240 IDE_LOGW("receive ctrl msg from device, stop receiving this file");
236 IDE_XFREE_AND_SET_NULL(msg);241 IDE_XFREE_AND_SET_NULL(msg);
@@ -240,8 +245,8 @@ MsgCode AdxMsgProto::RecvFile(const CommHandle &handle, int32_t fd)
240 mmSsize_t len = mmWrite(fd, msg->data, msg->sliceLen);245 mmSsize_t len = mmWrite(fd, msg->data, msg->sliceLen);
241 if (len < 0) {246 if (len < 0) {
242 char errBuf[MAX_ERRSTR_LEN + 1] = {0};247 char errBuf[MAX_ERRSTR_LEN + 1] = {0};
243- IDE_LOGE("write file failed : info [%s]",248+ IDE_LOGE(
244- mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));249+ "write file failed : info [%s]", mmGetErrorFormatMessage(mmGetErrorCode(), errBuf, MAX_ERRSTR_LEN));
245 IDE_XFREE_AND_SET_NULL(msg);250 IDE_XFREE_AND_SET_NULL(msg);
246 return IDE_DAEMON_UNKNOW_ERROR;251 return IDE_DAEMON_UNKNOW_ERROR;
247 }252 }
@@ -254,8 +259,7 @@ MsgCode AdxMsgProto::RecvFile(const CommHandle &handle, int32_t fd)
254 IDE_XFREE_AND_SET_NULL(msg);259 IDE_XFREE_AND_SET_NULL(msg);
255 }260 }
256 261 
257- if (SendResponse(handle, msg->reqType, msg->devId, MsgStatus::MSG_STATUS_NONE_ERROR) !=262+ if (SendResponse(handle, msg->reqType, msg->devId, MsgStatus::MSG_STATUS_NONE_ERROR) != IDE_DAEMON_NONE_ERROR) {
258- IDE_DAEMON_NONE_ERROR) {
259 IDE_LOGW("send response exception");263 IDE_LOGW("send response exception");
260 IDE_XFREE_AND_SET_NULL(msg);264 IDE_XFREE_AND_SET_NULL(msg);
261 return IDE_DAEMON_CHANNEL_ERROR;265 return IDE_DAEMON_CHANNEL_ERROR;
@@ -265,8 +269,7 @@ MsgCode AdxMsgProto::RecvFile(const CommHandle &handle, int32_t fd)
265 return IDE_DAEMON_NONE_ERROR;269 return IDE_DAEMON_NONE_ERROR;
266}270}
267 271 
268-MsgCode AdxMsgProto::SendResponse(const CommHandle &handle, uint16_t type,272+MsgCode AdxMsgProto::SendResponse(const CommHandle& handle, uint16_t type, uint16_t devId, MsgStatus status)
269- uint16_t devId, MsgStatus status)
270{273{
271 MsgProto msg;274 MsgProto msg;
272 (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));275 (void)memset_s(&msg, sizeof(msg), 0, sizeof(msg));
@@ -283,9 +286,9 @@ MsgCode AdxMsgProto::SendResponse(const CommHandle &handle, uint16_t type,
283 return IDE_DAEMON_NONE_ERROR;286 return IDE_DAEMON_NONE_ERROR;
284}287}
285 288 
286-MsgCode AdxMsgProto::RecvResponse(const CommHandle &handle)289+MsgCode AdxMsgProto::RecvResponse(const CommHandle& handle)
287{290{
288- MsgProto *recvBuf = nullptr;291+ MsgProto* recvBuf = nullptr;
289 int32_t length = 0;292 int32_t length = 0;
290 int32_t ret = AdxCommOptManager::Instance().Read(handle, (IdeRecvBuffT)&recvBuf, length, COMM_OPT_BLOCK);293 int32_t ret = AdxCommOptManager::Instance().Read(handle, (IdeRecvBuffT)&recvBuf, length, COMM_OPT_BLOCK);
291 if (ret != IDE_DAEMON_OK || recvBuf == nullptr) {294 if (ret != IDE_DAEMON_OK || recvBuf == nullptr) {
@@ -305,4 +308,4 @@ MsgCode AdxMsgProto::RecvResponse(const CommHandle &handle)
305 IDE_XFREE_AND_SET_NULL(recvBuf);308 IDE_XFREE_AND_SET_NULL(recvBuf);
306 return IDE_DAEMON_UNKNOW_ERROR;309 return IDE_DAEMON_UNKNOW_ERROR;
307}310}
308-}311+} // namespace Adx
@@ -20,20 +20,21 @@ namespace Adx {
20using MsgCode = IdeErrorT;20using MsgCode = IdeErrorT;
21class AdxMsgProto {21class AdxMsgProto {
22public:22public:
23- static MsgProto *CreateMsgPacket(CmdClassT type, uint16_t devId, IdeSendBuffT data, uint32_t length);23+ static MsgProto* CreateMsgPacket(CmdClassT type, uint16_t devId, IdeSendBuffT data, uint32_t length);
24- static MsgProto *CreateDataMsg(IdeSendBuffT data, uint32_t length);24+ static MsgProto* CreateDataMsg(IdeSendBuffT data, uint32_t length);
25- static int32_t CreateCtrlMsg(MsgProto &proto, MsgStatus status);25+ static int32_t CreateCtrlMsg(MsgProto& proto, MsgStatus status);
26- static MsgCode SendMsgData(const CommHandle &handle, CmdClassT type, MsgStatus status,26+ static MsgCode SendMsgData(
27- IdeSendBuffT data, uint32_t length);27+ const CommHandle& handle, CmdClassT type, MsgStatus status, IdeSendBuffT data, uint32_t length);
28- static MsgCode GetStringMsgData(const CommHandle &handle, std::string &value);28+ static MsgCode GetStringMsgData(const CommHandle& handle, std::string& value);
29- static MsgCode SendEventFile(const CommHandle &handle, CmdClassT type, uint16_t devId, int32_t fd);29+ static MsgCode SendEventFile(const CommHandle& handle, CmdClassT type, uint16_t devId, int32_t fd);
30- static MsgCode SendFile(const CommHandle &handle, CmdClassT type, uint16_t devId, int32_t fd);30+ static MsgCode SendFile(const CommHandle& handle, CmdClassT type, uint16_t devId, int32_t fd);
31- static MsgCode RecvFile(const CommHandle &handle, int32_t fd);31+ static MsgCode RecvFile(const CommHandle& handle, int32_t fd);
32- static MsgCode HandShake(const CommHandle &handle, CmdClassT type, uint16_t devId);32+ static MsgCode HandShake(const CommHandle& handle, CmdClassT type, uint16_t devId);
33- static MsgCode SendResponse(const CommHandle &handle, uint16_t type, uint16_t devId, MsgStatus status);33+ static MsgCode SendResponse(const CommHandle& handle, uint16_t type, uint16_t devId, MsgStatus status);
34- static MsgCode RecvResponse(const CommHandle &handle);34+ static MsgCode RecvResponse(const CommHandle& handle);
35+ 
35private:36private:
36- static MsgProto *CreateMsgByType(MsgType type, IdeSendBuffT data, uint32_t length);37+ static MsgProto* CreateMsgByType(MsgType type, IdeSendBuffT data, uint32_t length);
37};38};
38-}39+} // namespace Adx
39#endif // ADX_PROTOCOL_H40#endif // ADX_PROTOCOL_H