secgateway/Common/ret_errno.h

84 lines
2.1 KiB
C
Raw Normal View History

#ifndef _RET_ERRNO_H
#define _RET_ERRNO_H
#include "config_manager.h"
/* error no, 32位前16位为模块ID后16位为模块错误码 */
typedef uint ret_code;
/*0x00000000 ~ 0x0000ffff 为系统预留错误码,用于一般性系统错误,
*/
/*ret code 0x00000000 ~ 0x0000ffff*/
#define RET_OK 0
#define RET_ERR 1
#define RET_UNKNOWN 2
#define RET_SYSERR 3
#define RET_NOTFOUND 4
#define RET_TIMEOUT 5
#define RET_NULLP 6
#define RET_NOMEM 7
#define RET_CHKERR 8
#define RET_NOTSUPPORT 9
#define RET_INPUTERR 10
#define RET_EXIST 11
#define RET_FULL 12
#define RET_SENDERR 13
#define RET_NOCMID 14
#define RET_SRCERR 15
/* NETCONFIG_MODULE 0x00010000 ~ 0x0001ffff*/
#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 \
{ \
{ RET_OK, "OK" }, \
{ RET_ERR, "Error" },\
{ RET_UNKNOWN, "Unkown" },\
{ RET_SYSERR, "SystemError" },\
{ RET_NOTFOUND, "NotFound" }, \
{ RET_TIMEOUT, "Timeout" }, \
{ RET_NULLP, "NullPointer" } ,\
{ RET_NOMEM, "NotEnoughMemory"},\
{ RET_CHKERR, "CheckError"},\
{ RET_NOTSUPPORT, "NotSupport"},\
{ RET_INPUTERR, "InputError"},\
{ RET_EXIST, "AlreadyExist"},\
{ RET_FULL, "Full"},\
{ RET_SENDERR, "SendErr"},\
{ RET_NOCMID, "CanNotFindConfig"},\
{ RET_SRCERR, "ConfigSourceErr"},\
\
{ 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