Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "json_parser.h"
12 :
13 : #include <fstream>
14 : #include <sstream>
15 : #include <regex>
16 : #include <sys/stat.h>
17 : #include "mmpa/mmpa_api.h"
18 :
19 : namespace {
20 : const std::string ACL_JSON_DEFAULT_DEVICE = "defaultDevice";
21 : const std::string ACL_JSON_DEFAULT_DEVICE_ID = "default_device";
22 : constexpr int32_t DECIMAL = 10;
23 :
24 23640 : void CountDepth(const char_t ch, size_t& objDepth, size_t& maxObjDepth, size_t& arrayDepth, size_t& maxArrayDepth)
25 : {
26 23640 : switch (ch) {
27 481 : case '{': {
28 481 : ++objDepth;
29 481 : if (objDepth > maxObjDepth) {
30 455 : maxObjDepth = objDepth;
31 : }
32 481 : break;
33 : }
34 479 : case '}': {
35 479 : if (objDepth > 0) {
36 479 : --objDepth;
37 : }
38 479 : break;
39 : }
40 75 : case '[': {
41 75 : ++arrayDepth;
42 75 : if (arrayDepth > maxArrayDepth) {
43 63 : maxArrayDepth = arrayDepth;
44 : }
45 75 : break;
46 : }
47 75 : case ']': {
48 75 : if (arrayDepth > 0) {
49 75 : --arrayDepth;
50 : }
51 75 : break;
52 : }
53 22530 : default: {
54 22530 : return;
55 : }
56 : }
57 : }
58 : } // namespace
59 : namespace acl {
60 : // 配置文件最大字节数目10MBytes
61 : constexpr int64_t MAX_CONFIG_FILE_BYTE = 10 * 1024 * 1024;
62 : // 配置文件最大递归深度
63 : constexpr size_t MAX_CONFIG_OBJ_DEPTH = 10U;
64 : // 配置文件最大数组个数
65 : constexpr size_t MAX_CONFIG_ARRAY_DEPTH = 10U;
66 :
67 258 : bool JsonParser::IsValidFileName(const char_t* const fileName)
68 : {
69 258 : char_t trustedPath[MMPA_MAX_PATH] = {};
70 258 : int32_t ret = mmRealPath(fileName, trustedPath, MMPA_MAX_PATH);
71 258 : if (ret != EN_OK) {
72 4 : const auto formatErrMsg = acl::AclGetErrorFormatMessage(mmGetErrorCode());
73 4 : acl::AclErrorLogManager::ReportInputError(
74 8 : acl::INVALID_PATH_MSG, std::vector<const char*>({"path", "reason"}),
75 8 : std::vector<const char*>({fileName, formatErrMsg.c_str()}));
76 4 : ACL_LOG_ERROR(
77 : "[Trans][RealPath]the file path %s is not like a real path, mmRealPath return %d, "
78 : "errMessage is %s",
79 : fileName, ret, formatErrMsg.c_str());
80 4 : return false;
81 4 : }
82 :
83 : mmStat_t pathStat;
84 254 : ret = mmStatGet(trustedPath, &pathStat);
85 254 : if (ret != EN_OK) {
86 0 : const auto formatErrMsg = acl::AclGetErrorFormatMessage(mmGetErrorCode());
87 0 : acl::AclErrorLogManager::ReportInputError(
88 0 : acl::INVALID_PATH_MSG, std::vector<const char*>({"path", "reason"}),
89 0 : std::vector<const char*>({trustedPath, formatErrMsg.c_str()}));
90 0 : ACL_LOG_ERROR(
91 : "[Get][FileStatus]cannot get config file status, which path is %s, "
92 : "maybe does not exist, return %d, errcode %d",
93 : trustedPath, ret, mmGetErrorCode());
94 0 : return false;
95 0 : }
96 254 : if ((pathStat.st_mode & S_IFMT) != S_IFREG) {
97 0 : acl::AclErrorLogManager::ReportInputError(
98 0 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
99 0 : std::vector<const char*>({trustedPath, "config file is not a regular file"}));
100 0 : ACL_LOG_ERROR(
101 : "[Config][ConfigFile]config file is not a regular file, which path is %s, "
102 : "mode is %u",
103 : trustedPath, pathStat.st_mode);
104 0 : return false;
105 : }
106 254 : if (pathStat.st_size > MAX_CONFIG_FILE_BYTE) {
107 : std::string reason = acl::AclErrorLogManager::FormatStr(
108 0 : "file size %ld exceeds maximum allowed size %ld", pathStat.st_size, MAX_CONFIG_FILE_BYTE);
109 0 : acl::AclErrorLogManager::ReportInputError(
110 0 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
111 0 : std::vector<const char*>({trustedPath, reason.c_str()}));
112 0 : ACL_LOG_ERROR(
113 : "[Check][FileSize]config file %s size[%ld] is larger than "
114 : "max config file Bytes[%ld]",
115 : trustedPath, pathStat.st_size, MAX_CONFIG_FILE_BYTE);
116 0 : return false;
117 0 : }
118 254 : return true;
119 : }
120 :
121 246 : void JsonParser::GetMaxNestedLayers(
122 : const char_t* const fileName, const size_t length, size_t& maxObjDepth, size_t& maxArrayDepth)
123 : {
124 246 : if (length <= 0) {
125 1 : ACL_LOG_ERROR("[Check][Length]the length of file %s must be larger than 0.", fileName);
126 3 : return;
127 : }
128 :
129 245 : char_t* pBuffer = new (std::nothrow) char_t[length];
130 245 : if (pBuffer == nullptr) {
131 0 : ACL_LOG_ERROR("[Check][Malloc]Allocate memory failed, bufferSize=%zu.", length);
132 0 : const std::string lengthVal = std::to_string(length);
133 0 : acl::AclErrorLogManager::ReportInputError(
134 0 : acl::ALLOC_MEMORY_FAILED_MSG, std::vector<const char*>({"buf_size", "alloc_interface"}),
135 0 : std::vector<const char*>({lengthVal.c_str(), "new"}));
136 0 : return;
137 0 : }
138 490 : const std::shared_ptr<char_t> buffer(pBuffer, [](char_t* const deletePtr) { delete[] deletePtr; });
139 :
140 245 : std::ifstream fin(fileName);
141 245 : if (!fin.is_open()) {
142 1 : ACL_LOG_INNER_ERROR("[Open][File]Read file %s failed.", fileName);
143 1 : return;
144 : }
145 244 : (void)fin.seekg(0, fin.beg);
146 244 : (void)fin.read(buffer.get(), static_cast<int64_t>(length));
147 :
148 244 : size_t arrayDepth = 0U;
149 244 : size_t objDepth = 0U;
150 23884 : for (size_t i = 0U; i < length; ++i) {
151 23641 : const char_t v = buffer.get()[i];
152 23641 : if (v == '\0') {
153 1 : fin.close();
154 1 : return;
155 : }
156 23640 : CountDepth(v, objDepth, maxObjDepth, arrayDepth, maxArrayDepth);
157 : }
158 243 : fin.close();
159 247 : }
160 :
161 216 : aclError JsonParser::ParseJson(const char_t* const fileName, const char_t* const configStr, nlohmann::json& js)
162 : {
163 216 : if (strlen(configStr) == 0UL) {
164 11 : ACL_LOG_DEBUG("buffer is empty, no need parse json.");
165 11 : return ACL_SUCCESS;
166 : }
167 : try {
168 620 : js = nlohmann::json::parse(std::string(configStr));
169 5 : } catch (const nlohmann::json::exception& e) {
170 5 : ACL_LOG_ERROR("[Check][JsonFile]invalid json buffer, exception:%s.", e.what());
171 5 : std::string reason = acl::AclErrorLogManager::FormatStr("Parse exception: %s", e.what());
172 5 : acl::AclErrorLogManager::ReportInputError(
173 10 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
174 10 : std::vector<const char*>({fileName, reason.c_str()}));
175 5 : return ACL_ERROR_PARSE_FILE;
176 5 : }
177 200 : ACL_LOG_DEBUG("parse json from buffer successfully.");
178 200 : return ACL_SUCCESS;
179 : }
180 :
181 259 : aclError JsonParser::GetConfigStrFromFile(const char_t* const fileName, std::string& configStr)
182 : {
183 259 : if (fileName == nullptr) {
184 1 : ACL_LOG_DEBUG("filename is nullptr, no need to parse json");
185 1 : return ACL_SUCCESS;
186 : }
187 258 : ACL_LOG_DEBUG("before GetConfigStrFromFile in ParseJsonFromFile");
188 258 : if (!IsValidFileName(fileName)) {
189 4 : ACL_LOG_ERROR("[Check][File]invalid config file[%s]", fileName);
190 4 : return ACL_ERROR_INVALID_FILE;
191 : }
192 254 : std::ifstream fin(fileName, std::ios::binary);
193 254 : ACL_CHECK_INVALID_FILE_MSG_RET(
194 : !fin.is_open(), fileName, "File cannot be opened for reading", ACL_ERROR_INVALID_FILE);
195 254 : (void)fin.seekg(0, std::ios::end);
196 254 : const std::streampos fp = fin.tellg();
197 254 : if (static_cast<int32_t>(fp) == 0) {
198 12 : ACL_LOG_DEBUG("parse file is null");
199 12 : fin.close();
200 12 : return ACL_SUCCESS;
201 : }
202 : // checking the depth of file
203 242 : size_t maxObjDepth = 0U;
204 242 : size_t maxArrayDepth = 0U;
205 242 : GetMaxNestedLayers(fileName, static_cast<size_t>(fp), maxObjDepth, maxArrayDepth);
206 242 : if ((maxObjDepth > MAX_CONFIG_OBJ_DEPTH) || (maxArrayDepth > MAX_CONFIG_ARRAY_DEPTH)) {
207 : std::string reason = acl::AclErrorLogManager::FormatStr(
208 : "object depth %zu exceeds max %zu or array depth %zu exceeds max %zu", maxObjDepth, MAX_CONFIG_OBJ_DEPTH,
209 0 : maxArrayDepth, MAX_CONFIG_ARRAY_DEPTH);
210 0 : acl::AclErrorLogManager::ReportInputError(
211 0 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
212 0 : std::vector<const char*>({fileName, reason.c_str()}));
213 0 : ACL_LOG_ERROR(
214 : "[Check][MaxArrayDepth]invalid json file, the object's depth[%zu] is larger than %zu, "
215 : "or the array's depth[%zu] is larger than %zu.",
216 : maxObjDepth, MAX_CONFIG_OBJ_DEPTH, maxArrayDepth, MAX_CONFIG_ARRAY_DEPTH);
217 0 : fin.close();
218 0 : return ACL_ERROR_PARSE_FILE;
219 0 : }
220 242 : ACL_LOG_DEBUG("json file's obj's depth is %zu, array's depth is %zu", maxObjDepth, maxArrayDepth);
221 242 : std::stringstream buffer;
222 242 : fin.seekg(0, std::ios::beg);
223 242 : buffer << fin.rdbuf();
224 242 : configStr = buffer.str();
225 242 : fin.close();
226 242 : return ACL_SUCCESS;
227 254 : }
228 :
229 219 : aclError JsonParser::ParseJsonFromFile(const char_t* const fileName, nlohmann::json& js)
230 : {
231 219 : std::string configStr;
232 219 : auto ret = GetConfigStrFromFile(fileName, configStr);
233 219 : if (ret != ACL_SUCCESS) {
234 3 : ACL_LOG_ERROR("[Parse][File]Get Buffer from file[%s] failed.", fileName);
235 3 : return ret;
236 : }
237 :
238 216 : ret = ParseJson(fileName, configStr.c_str(), js);
239 216 : if (ret != ACL_SUCCESS) {
240 5 : ACL_LOG_ERROR("[Parse][File]parse config file[%s] to json failed.", fileName);
241 5 : return ACL_ERROR_PARSE_FILE;
242 : }
243 :
244 211 : ACL_LOG_DEBUG("parse json from file[%s] successfully.", fileName);
245 211 : return ACL_SUCCESS;
246 219 : }
247 :
248 73 : aclError JsonParser::GetJsonCtxByKey(
249 : const char_t* const fileName, std::string& strJsonCtx, const std::string& subStrKey, bool& found)
250 : {
251 73 : found = false;
252 73 : nlohmann::json js;
253 73 : aclError ret = acl::JsonParser::ParseJsonFromFile(fileName, js);
254 73 : if (ret != ACL_SUCCESS) {
255 2 : ACL_LOG_ERROR("parse json from file failed, errorCode = %d", ret);
256 2 : return ret;
257 : }
258 71 : const auto configIter = js.find(subStrKey);
259 71 : if (configIter != js.end()) {
260 10 : strJsonCtx = configIter->dump();
261 10 : found = true;
262 : }
263 71 : return ACL_SUCCESS;
264 73 : }
265 :
266 7 : aclError JsonParser::GetAttrConfigFromFile(const char_t* const fileName, std::map<aclCannAttr, CannInfo>& cannInfoMap)
267 : {
268 7 : nlohmann::json js;
269 7 : aclError ret = JsonParser::ParseJsonFromFile(fileName, js);
270 7 : if (ret != ACL_SUCCESS) {
271 1 : ACL_LOG_ERROR("parse swFeatureList.json from file[%s] failed, ret = %d", fileName, ret);
272 1 : return ret;
273 : }
274 : try {
275 24 : for (auto& item : cannInfoMap) {
276 18 : auto& cannInfo = item.second;
277 18 : const auto config = js.find(cannInfo.readableAttrName);
278 18 : if (config != js.end()) {
279 14 : const auto runtimeIter = config->find(SW_CONFIG_RUNTIME);
280 14 : if (runtimeIter != config->end()) {
281 14 : ACL_REQUIRES_OK(CannInfoUtils::ParseVersionValue(
282 : runtimeIter->get<std::string>(), &cannInfo.minimumRuntimeVersion));
283 : }
284 : }
285 : }
286 0 : } catch (const nlohmann::json::exception& e) {
287 0 : std::string reason = acl::AclErrorLogManager::FormatStr("JSON parse exception: %s", e.what());
288 0 : acl::AclErrorLogManager::ReportInputError(
289 0 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
290 0 : std::vector<const char*>({fileName, reason.c_str()}));
291 0 : ACL_LOG_ERROR("invalid config file [%s], exception: %s", fileName, e.what());
292 0 : return ACL_ERROR_INTERNAL_ERROR;
293 0 : }
294 6 : ACL_LOG_INFO("Finish parsing swFeatureList.json");
295 6 : return ACL_SUCCESS;
296 7 : }
297 :
298 30 : aclError JsonParser::GetDefaultDeviceIdFromFile(const char_t* const fileName, int32_t& devId)
299 : {
300 30 : ACL_LOG_DEBUG("start to execute GetDefaultDeviceIdFromFile.");
301 30 : nlohmann::json js;
302 30 : std::string enableFlagStr, defaultDeviceIdStr;
303 30 : aclError ret = acl::JsonParser::ParseJsonFromFile(fileName, js);
304 30 : if (ret != ACL_SUCCESS) {
305 0 : ACL_LOG_ERROR("[Parse][JsonFromFile]parse default config from file[%s] failed, errorCode = %d", fileName, ret);
306 0 : return ret;
307 : }
308 :
309 : try {
310 30 : if (!JsonParser::ContainKey(js, ACL_JSON_DEFAULT_DEVICE)) {
311 21 : ACL_LOG_WARN("no defaultDevice item!");
312 21 : return ACL_SUCCESS;
313 : }
314 9 : const nlohmann::json& jsDefaultDeviceConfig = JsonParser::GetCfgJsonByKey(js, ACL_JSON_DEFAULT_DEVICE);
315 9 : if (!JsonParser::ContainKey(jsDefaultDeviceConfig, ACL_JSON_DEFAULT_DEVICE_ID)) {
316 1 : ACL_LOG_WARN("no default_device in acl.json!");
317 1 : return ACL_SUCCESS;
318 : }
319 :
320 8 : defaultDeviceIdStr = JsonParser::GetCfgStrByKey(jsDefaultDeviceConfig, ACL_JSON_DEFAULT_DEVICE_ID);
321 1 : } catch (const nlohmann::json::exception& e) {
322 1 : std::string reason = acl::AclErrorLogManager::FormatStr("JSON parse exception: %s", e.what());
323 1 : acl::AclErrorLogManager::ReportInputError(
324 2 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
325 2 : std::vector<const char*>({fileName, reason.c_str()}));
326 1 : ACL_LOG_ERROR("parse config file [%s], exception: %s", fileName, e.what());
327 1 : return ACL_ERROR_INTERNAL_ERROR;
328 1 : }
329 :
330 7 : std::regex reg("0|[1-9]\\d*");
331 7 : if (!std::regex_match(defaultDeviceIdStr, reg)) {
332 3 : acl::AclErrorLogManager::ReportInputError(
333 6 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
334 3 : std::vector<const char*>(
335 3 : {"Parsing the default device ID from the configuration file", defaultDeviceIdStr.c_str(),
336 6 : "default_device", "value must be zero or a positive integer"}));
337 3 : ACL_LOG_ERROR(
338 : "default_device %s in acl.json is neither zero nor positive integer.", defaultDeviceIdStr.c_str());
339 3 : return ACL_ERROR_INVALID_PARAM;
340 : }
341 4 : devId = static_cast<int32_t>(std::strtol(defaultDeviceIdStr.c_str(), nullptr, DECIMAL));
342 4 : ACL_LOG_DEBUG("successfully parse defaultDevice, devId:%d", devId);
343 4 : return ACL_SUCCESS;
344 30 : }
345 :
346 15 : aclError JsonParser::GetEventModeFromFile(const char_t* const fileName, uint8_t& event_mode, bool& found)
347 : {
348 15 : nlohmann::json js;
349 15 : std::string eventModeStr;
350 15 : aclError ret = acl::JsonParser::ParseJsonFromFile(fileName, js);
351 15 : if (ret != ACL_SUCCESS) {
352 1 : ACL_LOG_ERROR("[Parse][JsonFromFile]parse json from file[%s] failed, errorCode = %d", fileName, ret);
353 1 : return ret;
354 : }
355 28 : const std::string ACL_GRAPH_CONFIG_NAME = "acl_graph";
356 14 : const std::string ACL_EVENT_MODE_CONFIG_NAME = "event_mode";
357 :
358 14 : if (!JsonParser::ContainKey(js, ACL_GRAPH_CONFIG_NAME)) {
359 10 : ACL_LOG_INFO("No acl_graph in json file!");
360 10 : return ACL_SUCCESS;
361 : }
362 4 : const nlohmann::json& jsAclGraphConfig = JsonParser::GetCfgJsonByKey(js, ACL_GRAPH_CONFIG_NAME);
363 4 : if (!JsonParser::ContainKey(jsAclGraphConfig, ACL_EVENT_MODE_CONFIG_NAME)) {
364 1 : ACL_LOG_INFO("No event_mode under acl_graph in json file!");
365 1 : return ACL_SUCCESS;
366 : }
367 3 : eventModeStr = JsonParser::GetCfgStrByKey(jsAclGraphConfig, ACL_EVENT_MODE_CONFIG_NAME);
368 :
369 : // 校验 event_mode 是否为合法整数,只允许 0 或 1
370 3 : std::regex reg("0|1");
371 3 : if (!std::regex_match(eventModeStr, reg)) {
372 1 : ACL_LOG_ERROR("event_mode value [%s] in json is not a valid integer.", eventModeStr.c_str());
373 1 : acl::AclErrorLogManager::ReportInputError(
374 2 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
375 2 : std::vector<const char*>({__func__, eventModeStr.c_str(), "event_mode", "value must be 0 or 1"}));
376 1 : return ACL_ERROR_INVALID_PARAM;
377 : }
378 :
379 2 : event_mode = static_cast<uint8_t>(std::strtol(eventModeStr.c_str(), nullptr, DECIMAL));
380 2 : found = true;
381 2 : ACL_LOG_INFO("Successfully parse event_mode: %d, event_mode_str: %s", event_mode, eventModeStr.c_str());
382 2 : return ACL_SUCCESS;
383 15 : }
384 :
385 90 : aclError JsonParser::GetStackSizeByType(
386 : const char_t* const fileName, const std::string& typeName, size_t& outSize, bool& outExist)
387 : {
388 90 : ACL_LOG_DEBUG("start to execute GetStackSizeByType, typeName = %s.", typeName.c_str());
389 90 : outExist = false;
390 90 : outSize = 0U;
391 90 : nlohmann::json js;
392 90 : aclError ret = acl::JsonParser::ParseJsonFromFile(fileName, js);
393 90 : if (ret != ACL_SUCCESS) {
394 2 : ACL_LOG_ERROR("[Parse][JsonFromFile]parse default config from file[%s] failed, errorCode = %d", fileName, ret);
395 2 : acl::AclErrorLogManager::ReportInputError(
396 4 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
397 4 : std::vector<const char*>({fileName, "Parse config file failed"}));
398 2 : return ret;
399 : }
400 :
401 : try {
402 : // 检查 "StackSize" 键是否存在
403 88 : if (js.find("StackSize") == js.end()) {
404 66 : ACL_LOG_DEBUG("StackSize key not found in config file [%s]", fileName);
405 66 : outExist = false; // 明确设置 outExist 为 false
406 66 : return ACL_SUCCESS;
407 : }
408 :
409 22 : const nlohmann::json& stackSizeJs = js["StackSize"];
410 22 : if (stackSizeJs.find(typeName.c_str()) != stackSizeJs.end()) {
411 19 : size_t rawSize = stackSizeJs.at(typeName.c_str()).get<size_t>();
412 18 : outSize = rawSize;
413 18 : outExist = true;
414 18 : ACL_LOG_INFO("successfully parse %s, size is %zu", typeName.c_str(), outSize);
415 : }
416 1 : } catch (const nlohmann::json::exception& e) {
417 1 : ACL_LOG_ERROR("parse config file [%s], exception: %s", fileName, e.what());
418 1 : std::string reason = acl::AclErrorLogManager::FormatStr("Parse exception: %s", e.what());
419 1 : acl::AclErrorLogManager::ReportInputError(
420 2 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
421 2 : std::vector<const char*>({fileName, reason.c_str()}));
422 1 : return ACL_ERROR_INTERNAL_ERROR;
423 1 : }
424 :
425 21 : ACL_LOG_DEBUG("successfully parse StackSize by type");
426 21 : return ACL_SUCCESS;
427 90 : }
428 :
429 31 : aclError JsonParser::GetPrintFifoSizeByType(
430 : const char_t* const fileName, const std::string& typeName, size_t& fifoSize, bool& found)
431 : {
432 31 : ACL_LOG_DEBUG("start to execute GetPrintFifoSizeByType, typeName = %s.", typeName.c_str());
433 31 : std::string fifoSizeStr;
434 31 : found = false;
435 :
436 31 : auto ret = acl::JsonParser::GetJsonCtxByKey(fileName, fifoSizeStr, typeName, found);
437 31 : if (ret != ACL_SUCCESS) {
438 0 : acl::AclErrorLogManager::ReportInputError(
439 0 : acl::INVALID_FILE_MSG, std::vector<const char*>({"path", "reason"}),
440 0 : std::vector<const char*>({fileName, ("cannot parse config for " + typeName).c_str()}));
441 0 : ACL_LOG_ERROR(
442 : "can not parse config from file[%s], config[%s], errorCode = %d", fileName, typeName.c_str(), ret);
443 0 : return ret;
444 : }
445 31 : if (!found) {
446 26 : return ACL_SUCCESS;
447 : }
448 :
449 5 : std::regex reg("[1-9]\\d*");
450 5 : if (!std::regex_match(fifoSizeStr, reg)) {
451 2 : acl::AclErrorLogManager::ReportInputError(
452 4 : acl::INVALID_PARAM_REASON_MSG, std::vector<const char*>({"func", "value", "param", "reason"}),
453 2 : std::vector<const char*>(
454 4 : {__func__, fifoSizeStr.c_str(), "fifoSize", "value must be a positive integer in acl.json"}));
455 2 : ACL_LOG_ERROR("fifoSize %s in acl.json is not a positive integer.", fifoSizeStr.c_str());
456 2 : return ACL_ERROR_INVALID_PARAM;
457 : }
458 :
459 3 : fifoSize = static_cast<size_t>(std::strtol(fifoSizeStr.c_str(), nullptr, DECIMAL));
460 3 : ACL_LOG_DEBUG("successfully parse print fifo size by type");
461 3 : return ACL_SUCCESS;
462 31 : }
463 : } // namespace acl
|