rust_rsm/common/
errcode.rs1#![allow(non_camel_case_types)]
2#![allow(non_snake_case)]
3#![allow(non_upper_case_globals)]
4use std::collections::HashMap;
5pub type RESULT = i32;
6pub const RESULT_SUCCESS: RESULT = 0;
8pub const ERROR_COMMON: RESULT = 1;
9pub const ERROR_NULL_POINTER: RESULT = 2;
10pub const ERROR_INVALID_INDEX: RESULT = 3; pub const ERROR_INVALID_PARAM: RESULT = 4;
12pub const ERROR_OUTOF_SCOPE: RESULT = 5;
13pub const ERROR_NOT_FOUND: RESULT = 6;
14pub const ERROR_ALREADY_EXIST: RESULT = 7;
15pub const ERROR_OUTOF_MEM: RESULT = 8; pub const ERROR_NO_PERMISSION: RESULT = 9; pub const ERROR_MSG_TOO_LONG: RESULT = 10; pub const ERROR_ENCODE_MSG: RESULT = 11; pub const ERROR_DECODE_MSG: RESULT = 12; pub const ERROR_COLLISION: RESULT = 13; pub const ERROR_AUTH_FAILED: RESULT = 14; pub const ERROR_THRESHOLD_EXCEED: RESULT = 15; pub const ERROR_TIME_OUT: RESULT = 16; pub const ERROR_NOT_INITIALIZED: RESULT = 17; pub const ERROR_INVALID_MSG: RESULT = 18;
26pub const ERROR_INVALID_STATE: RESULT = 19; pub const ERROR_LOCK_FAILED: RESULT = 20;
28pub const ERROR_MSG_TOO_SHORT: RESULT = 21;
29pub const ERROR_NOT_SUPPORT: RESULT = 22; pub const ERROR_OS_CALL_FAILED: RESULT = 23; pub const ERROR_NO_OP: RESULT = 24; pub const ERROR_LINK_BROKEN: RESULT = 25; pub const ERROR_BUFFER_TOO_SMALL: RESULT = 26; pub const ERROR_INIT_FAILED: RESULT = 27; pub const ERROR_NO_DATA: RESULT = 28; pub const ERROR_INVALID_IPADDR: RESULT = 50; pub const ERROR_INVALID_MAC_ADDR: RESULT = 51;
41pub const ERROR_DEVICE_NOT_EXIST:RESULT=52;
42pub const ERROR_OPEN_FILE: RESULT = 100;
44pub const ERROR_FILE_NOT_FOUND: RESULT = 101;
45pub const ERROR_DISK_FULL: RESULT = 102;
46pub const ERROR_SEND_MSG: RESULT = 103;
47pub const ERROR_RECV_MSG: RESULT = 104;
48pub const ERROR_BIND_SOCKET: RESULT = 105;
49pub const ERROR_CONNECTION: RESULT = 106;
50pub const ERROR_RPC_FAILED: RESULT = 107;
51pub const ERROR_FILE_EXISTS: RESULT = 108;
52pub const ERROR_WRITE_FILE_FAILED: RESULT = 109;
53pub const HTTP_SUCCESS: i16 = 200;
57pub const HTTP_MOVED: i16 = 300;
58
59pub const HTTP_BAD_REQUEST: i16 = 400;
60pub const HTTP_UNAUTHORIZED: i16 = 401;
61pub const HTTP_PAYMENT_REQUIRED: i16 = 402;
62pub const HTTP_FORBIDDEN: i16 = 403;
63pub const HTTP_NOT_FOUND: i16 = 404;
64pub const HTTP_METHOD_NOT_ALLOWED: i16 = 405;
65pub const HTTP_REQUEST_TIMEOUT: i16 = 408;
66
67pub const HTTP_INTERNAL_ERROR: i16 = 500;
68pub const HTTP_SERVER_NOT_IMPLEMENT: i16 = 501;
69pub const HTTP_SERVER_NOT_AVAILABLE: i16 = 503;
70
71static mut ErrorNameMap:Option<HashMap<i32,&str>>=None;
72
73fn init_error_map() {
74 match unsafe {&ErrorNameMap} {
75 Some(_)=>return,
76 None=>(),
77 }
78
79 let erm = HashMap::from([
80 (RESULT_SUCCESS,"Success"),
81 (ERROR_COMMON,"General failure"),
82 (ERROR_NULL_POINTER,"Null Pointer"),
83 (ERROR_INVALID_INDEX,"Invalid Index",),
84 (ERROR_INVALID_PARAM,"Invalid parameter"),
85 (ERROR_OUTOF_SCOPE,"Out of Scope"),
86 (ERROR_NOT_FOUND,"Not Found"),
87 (ERROR_ALREADY_EXIST,"Already Exist"),
88 (ERROR_OUTOF_MEM,"Out of memory"),
89 (ERROR_NO_PERMISSION,"No Permission"),
90 (ERROR_MSG_TOO_LONG,"Msg too long"),
91 (ERROR_ENCODE_MSG,"Encode Message failed"),
92 (ERROR_DECODE_MSG,"Decode Message failed"),
93 (ERROR_COLLISION,"Collision Occured"),
94 (ERROR_AUTH_FAILED,"Authentication Failed"),
95 (ERROR_THRESHOLD_EXCEED,"Threshhold Exceed"),
96 (ERROR_TIME_OUT,"Time Out"),
97 (ERROR_NOT_INITIALIZED,"Not Initialized"),
98 (ERROR_INVALID_MSG,"Invalid Message"),
99 (ERROR_INVALID_STATE,"Invalid State"),
100 (ERROR_LOCK_FAILED,"lock Failed"),
101 (ERROR_MSG_TOO_SHORT,"Message Too Short"),
102 (ERROR_NOT_SUPPORT,"Not Support"),
103 (ERROR_OS_CALL_FAILED,"Os Call Failed"),
104 (ERROR_NO_OP,"No Operation"),
105
106 (ERROR_LINK_BROKEN,"Link Broken"),
107 (ERROR_OPEN_FILE,"Failed to Open File"),
108 (ERROR_FILE_NOT_FOUND,"File Not Found"),
109 (ERROR_DISK_FULL,"Disk is Full"),
110 (ERROR_SEND_MSG,"Send Message Failed"),
111 (ERROR_RECV_MSG,"Recv message Failed"),
112 (ERROR_BIND_SOCKET,"Bind Socket Failed"),
113 (ERROR_CONNECTION,"Connection Error"),
114
115 ]);
116 unsafe {
117 ErrorNameMap = Some(erm);
118 }
119
120}
121
122pub fn errcode_to_string(code:RESULT)->&'static str {
123 unsafe {
124 if ErrorNameMap.is_none() {
125 init_error_map();
126 }
127 }
128 if let Some(errm)=unsafe {&ErrorNameMap} {
129 match errm.get(&code) {
130 None=>return "Unknown Error",
131 Some(e)=>return e,
132 }
133 } else {
134 return "Unknown Error"
135 }
136
137
138}