MOD aaa-12 将错误码提取出来单独形成一个文件,便于后续各个业务模块添加自身错误码

SOL  将错误码提取出来单独形成一个文件,便于后续各个业务模块添加自身错误码
修改人:zhangliang
检视人:zhangliang
This commit is contained in:
zhanglianghy 2019-08-22 15:55:36 +08:00
parent d34129e224
commit ed7e4a96a5
4 changed files with 32 additions and 11 deletions

View File

@ -7,9 +7,10 @@
typedef uint ret_code;
/*0x00000000 ~ 0x0000ffff 为系统预留错误码,用于一般性系统错误,例如内存不够,输入错误等*/
/*0x00000000 ~ 0x0000ffff 为系统预留错误码,用于一般性系统错误,
*/
/* RPC ret code 0x00000000 ~ 0x0000ffff*/
/*ret code 0x00000000 ~ 0x0000ffff*/
#define RET_OK 0
#define RET_ERR 1
#define RET_UNKNOWN 2
@ -30,6 +31,7 @@ typedef uint ret_code;
#define RET_IPINVALID (uint)((uint)NETCONFIG_MODULE<<16|1)
#define RET_BRNAMEERR (uint)((uint)NETCONFIG_MODULE<<16|1)
#define ERR_STR_LEN 64
/* 错误码描述 */
#define RET_ERROR_DISC \
@ -41,16 +43,37 @@ typedef uint ret_code;
{ RET_NOTFOUND, "NotFound" }, \
{ RET_TIMEOUT, "Timeout" }, \
{ RET_NULLP, "NullPointer" } ,\
{ RET_NOMEM, "NotEnoughMemery"},\
{ RET_NOMEM, "NotEnoughMemory"},\
{ RET_CHKERR, "CheckError"},\
{ RET_NOTSUPPORT, "NotSupport"},\
{ RET_INPUTERR, "InputError"},\
{ RET_EXIST, "AlreadyExist"},\
{ RET_FULL, "Full"},\
{ RET_SENDERR, "SendErr"},\
\
{ RET_IPINVALID, "IpInvalid"},\
{ RET_BRNAMEERR, "BrNameInvalid"}\
}
struct err_disc {
int code;
const char *name;
} ;
static inline char* ret_code_format(ret_code code, char* str) {
struct err_disc ret_err[] = RET_ERROR_DISC;
int len = sizeof(ret_err) / sizeof(struct err_disc);
int i;
for(i = 0; i < len; i++){
if(code == ret_err[i].code){
strcpy(str, ret_err[i].name);
return str;
}
}
return str;
}
#endif

View File

@ -214,8 +214,5 @@ struct _config_service {
typedef struct _config_service config_service_t;
#endif /* RPC_COMMON_H_ */

View File

@ -563,7 +563,7 @@ ret_code ip_config_get_all(uint source, pointer output, int *output_len)
*output_len = 0;
ret = if_get_prefix_all(output, output_len, &code);
rpc_log_info("ip_config_get_all: %s\n", output);
rpc_log_info("ip_config_get_all: %s\n", (char *)output);
RET_ERR_FORMART(ret, code, output, *output_len);
ASSERT_RET(ret);

View File

@ -3,6 +3,7 @@
#include "rpc.h"
#include "configm.h"
#include "ipconfig.h"
#include "ret_errno.h"
int main(int argc, char **argv)
{
@ -35,13 +36,13 @@ int main(int argc, char **argv)
memset(config_linebuf, 0, sizeof(config_linebuf));
while(fgets(config_linebuf, 512, f) != NULL)
{
char code_str[ERR_STR_LEN] = {0};
printf("configure: %s\n", config_linebuf);
code = web_config_exec_sync(CM_CONFIG_SET, config_id,
config_linebuf, strlen(config_linebuf) + 1, &output, &output_len);
printf("call config type return:%s,result:%s\n", rpc_code_format(code), output);
ret_code_format(code, code_str);
printf("call config type return:%s,result:%s\n", code_str, output);
memset(config_linebuf, 0, sizeof(config_linebuf));
memset(output, 0, output_len);