From ed7e4a96a541ce139b5130fe558303a9f9dcf961 Mon Sep 17 00:00:00 2001 From: zhanglianghy Date: Thu, 22 Aug 2019 15:55:36 +0800 Subject: [PATCH] =?UTF-8?q?MOD=20aaa-12=20=E5=B0=86=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=A0=81=E6=8F=90=E5=8F=96=E5=87=BA=E6=9D=A5=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E5=BD=A2=E6=88=90=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E4=BE=BF=E4=BA=8E=E5=90=8E=E7=BB=AD=E5=90=84=E4=B8=AA=E4=B8=9A?= =?UTF-8?q?=E5=8A=A1=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E8=87=AA=E8=BA=AB?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=A0=81=20SOL=20=20=E5=B0=86=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E7=A0=81=E6=8F=90=E5=8F=96=E5=87=BA=E6=9D=A5=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=BD=A2=E6=88=90=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= =?UTF-8?q?=EF=BC=8C=E4=BE=BF=E4=BA=8E=E5=90=8E=E7=BB=AD=E5=90=84=E4=B8=AA?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E6=A8=A1=E5=9D=97=E6=B7=BB=E5=8A=A0=E8=87=AA?= =?UTF-8?q?=E8=BA=AB=E9=94=99=E8=AF=AF=E7=A0=81=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E4=BA=BA=EF=BC=9Azhangliang=20=E6=A3=80=E8=A7=86=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhangliang?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/ret_errno.h | 29 +++++++++++++++++-- .../configm/config-server/include/configm.h | 5 +--- .../netconfig/ipconfig/ipconfig.c | 2 +- .../user/configm/config-test/configtest.c | 7 +++-- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Common/ret_errno.h b/Common/ret_errno.h index f7eaf757a..7ef6ed927 100644 --- a/Common/ret_errno.h +++ b/Common/ret_errno.h @@ -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 diff --git a/Platform/user/configm/config-server/include/configm.h b/Platform/user/configm/config-server/include/configm.h index 81bd290eb..e2dd3d5d4 100755 --- a/Platform/user/configm/config-server/include/configm.h +++ b/Platform/user/configm/config-server/include/configm.h @@ -173,7 +173,7 @@ nat_config_proc, \ NULL, \ nat_config_get_all \ - }\ + }\ } typedef ret_code (*cm_config_init)(); @@ -214,8 +214,5 @@ struct _config_service { typedef struct _config_service config_service_t; - - - #endif /* RPC_COMMON_H_ */ diff --git a/Platform/user/configm/config-server/netconfig/ipconfig/ipconfig.c b/Platform/user/configm/config-server/netconfig/ipconfig/ipconfig.c index 7e3e04e5a..8132b8a85 100644 --- a/Platform/user/configm/config-server/netconfig/ipconfig/ipconfig.c +++ b/Platform/user/configm/config-server/netconfig/ipconfig/ipconfig.c @@ -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); diff --git a/Platform/user/configm/config-test/configtest.c b/Platform/user/configm/config-test/configtest.c index 095f1484a..f4a40142a 100644 --- a/Platform/user/configm/config-test/configtest.c +++ b/Platform/user/configm/config-test/configtest.c @@ -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);