|
@@ -1,6 +1,11 @@
|
|
|
-//
|
|
|
-// Created by zx on 2019/12/30.
|
|
|
-//
|
|
|
+
|
|
|
+//Error_code是错误码的底层通用模块,
|
|
|
+//功能:用作故障分析和处理。
|
|
|
+
|
|
|
+//用法:所有的功能接口函数return错误管理类,
|
|
|
+//然后上层判断分析错误码,并进行故障处理。
|
|
|
+
|
|
|
+
|
|
|
|
|
|
#include "error_code.h"
|
|
|
|
|
@@ -51,7 +56,12 @@ Error_manager::~Error_manager()
|
|
|
free_description();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+//初始化
|
|
|
+void Error_manager::error_manager_init()
|
|
|
+{
|
|
|
+ error_manager_clear_all();
|
|
|
+ return;
|
|
|
+}
|
|
|
//初始化
|
|
|
void Error_manager::error_manager_init(Error_code error_code, Error_level error_level, char* p_error_description, int description_length)
|
|
|
{
|
|
@@ -342,6 +352,9 @@ void Error_manager::compare_and_cover_error( Error_manager & error_manager)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//将所有的错误信息,格式化为字符串,用作日志打印。
|
|
|
+//output:p_error_description 错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
|
|
|
+//output:description_length 错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
|
|
|
void Error_manager::translate_error_to_string(char* p_error_aggregate, int aggregate_length )
|
|
|
{
|
|
|
char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
|
|
@@ -373,6 +386,7 @@ void Error_manager::translate_error_to_string(char* p_error_aggregate, int aggre
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+//output:error_description_string 错误汇总的string
|
|
|
void Error_manager::translate_error_to_string(std::string & error_aggregate_string)
|
|
|
{
|
|
|
char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
|
|
@@ -388,7 +402,8 @@ void Error_manager::translate_error_to_string(std::string & error_aggregate_stri
|
|
|
//error_aggregate_string += "NULL";
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+//错误码转字符串的简易版,可支持cout<<
|
|
|
+//return 错误汇总的string
|
|
|
std::string Error_manager::to_string()
|
|
|
{
|
|
|
std::string t_string;
|
|
@@ -399,7 +414,7 @@ std::string Error_manager::to_string()
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
+//释放错误描述的内存,
|
|
|
void Error_manager::free_description()
|
|
|
{
|
|
|
if(pm_error_description != NULL)
|
|
@@ -410,6 +425,9 @@ void Error_manager::free_description()
|
|
|
m_description_length = 0;
|
|
|
}
|
|
|
|
|
|
+//重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
|
|
|
+//input:p_error_description 错误描述的字符串指针,可以为NULL,
|
|
|
+//input:description_length 错误描述的字符串长度,如果为0,则从p_error_description里面获取有效的长度
|
|
|
void Error_manager::reallocate_memory_and_copy_string(char* p_error_description, int description_length)
|
|
|
{
|
|
|
free_description();
|
|
@@ -450,6 +468,8 @@ void Error_manager::reallocate_memory_and_copy_string(char* p_error_description,
|
|
|
}
|
|
|
|
|
|
|
|
|
+//重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
|
|
|
+//input:error_aggregate_string 错误描述的string
|
|
|
void Error_manager::reallocate_memory_and_copy_string(std::string & error_aggregate_string)
|
|
|
{
|
|
|
free_description();
|