-
Notifications
You must be signed in to change notification settings - Fork 0
/
retcodes.h
278 lines (217 loc) · 10.4 KB
/
retcodes.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is COID/comm module.
*
* The Initial Developer of the Original Code is
* PosAm.
* Portions created by the Initial Developer are Copyright (C) 2003
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brano Kemen
* Robert Strycek
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __COID_COMM_RETCODES__HEADER_FILE__
#define __COID_COMM_RETCODES__HEADER_FILE__
#include "namespace.h"
#include "comm.h"
COID_NAMESPACE_BEGIN
///Handle exceptions in expression, convert to return the opcd code. ThreadException rethrown.
#define OPCD_CATCH_RETURN(exp) \
try { exp; } \
catch( opcd __e ) { return __e; } \
catch( thread::Exception& ) { throw; } \
catch( ... ) { return ersEXCEPTION "non-opcd type thrown"; }
#define OPCD_CATCH_ERR(exp,e) \
e = 0; \
try { exp; } \
catch( opcd __e ) { e = __e; } \
catch( thread::Exception& ) { throw; } \
catch( ... ) { e = ersEXCEPTION "non-opcd type thrown"; } \
#define OPCD_CATCH(exp) \
try { exp; } \
catch( opcd ) { } \
catch( thread::Exception& ) { throw; } \
catch( ... ) { }
#define ERETURN(exp) { coid::opcd e = exp; if(e) return e; }
////////////////////////////////////////////////////////////////////////////////
#define MKERR1(id, code) (coid::opcd)(const coid::opcd::errcode*) id "\x000" code
#define MKERR2(id1, id2, code) (coid::opcd)(const coid::opcd::errcode*) id1 id2 code
#define ersxFRAMEWORK_ERROR(id, code) MKERR1(id, "FE" code)
#define ersxSPECIFIC(id, code) MKERR1(id, "SP" code)
#define NOERR 0
#define ersNOERR coid::opcd(0)
#define ersUNKNOWN MKERR1("\x001", "?????")
#define ersFRAMEWORK_ERROR MKERR1("\x002", "FrErr") //2
#define ersSPECIFIC MKERR1("\x003", "Spcfc")
#define ersABORT MKERR1("\x004", "Abort")
#define ersALREADY_DELETED MKERR1("\x005", "ADel ")
#define ersALREADY_EXISTS MKERR1("\x006", "Exist")
#define ersBUSY MKERR1("\x007", "Busy ")
#define ersDENIED MKERR1("\x008", "Deny ")
#define ersEXCEPTION MKERR1("\x009", "Exc ")
#define ersEXIT MKERR1("\x00A", "Exit ")
#define ersFAILED MKERR1("\x00B", "Fail ")
#define ersFAILED_ASSERTION MKERR1("\x00C", "Assrt")
#define ersIGNORE MKERR1("\x00D", "Ignor")
#define ersIMPROPER_STATE MKERR1("\x00E", "State")
#define ersINTERNAL_ERROR MKERR1("\x00F", "IntEr")
#define ersINVALID_CREDENTIALS MKERR1("\x010", "ICred")
#define ersINVALID_NAME MKERR1("\x011", "IName")
#define ersINVALID_PARAMS MKERR1("\x012", "IParm")
#define ersINVALID_TYPE MKERR1("\x013", "IType")
#define ersINVALID_VERSION MKERR1("\x014", "IVer ")
#define ersINVALID_LOGIN MKERR1("\x015", "ILgn ") //21
#define ersINVALID_LOGIN_NAME MKERR1("\x016", "LGnam")
#define ersINVALID_LOGIN_PASSWORD MKERR1("\x017", "LGpwd")
#define ersIO_ERROR MKERR1("\x018", "IOerr")
#define ersMISMATCHED MKERR1("\x019", "Misma")
#define ersNO_CHANGE MKERR1("\x01A", "NChng")
#define ersNO_MATCH MKERR1("\x01B", "NMtch")
#define ersNO_MORE MKERR1("\x01C", "NMore")
#define ersNOT_ENOUGH_MEM MKERR1("\x01D", "!Mem ")
#define ersNOT_ENOUGH_VIRTUAL_MEM MKERR1("\x01E", "!VMem")
#define ersNOT_FOUND MKERR1("\x01F", "!Fnd ")
#define ersNOT_IMPLEMENTED MKERR1("\x020", "!Impl")
#define ersNOT_READY MKERR1("\x021", "!Rdy ")
#define ersOBSOLETE MKERR1("\x022", "Obslt")
#define ersOUT_OF_RANGE MKERR1("\x023", "OoRng")
#define ersREJECTED MKERR1("\x024", "Rjctd")
#define ersRETRY MKERR1("\x025", "Retry")
#define ersSYNTAX_ERROR MKERR1("\x026", "SynEr")
#define ersTIMEOUT MKERR1("\x027", "TimeO")
#define ersUNAVAILABLE MKERR1("\x028", "!Avlb")
#define ersUNKNOWN_CMD MKERR1("\x029", "?Cmd ") //41
/// FRAMEWORK_ERROR subcodes:
#define ersFE_ALREADY_CONNECTED ersxFRAMEWORK_ERROR("\x02A", "con")
#define ersFE_CHANNEL ersxFRAMEWORK_ERROR("\x02B", "chn")
#define ersFE_DENIED ersxFRAMEWORK_ERROR("\x02C", "den")
#define ersFE_DISCONNECTED ersxFRAMEWORK_ERROR("\x02D", "dis")
#define ersFE_EXCEPTION ersxFRAMEWORK_ERROR("\x02E", "exc")
#define ersFE_INVALID_SERVER_VER ersxFRAMEWORK_ERROR("\x02F", "vSr")
#define ersFE_INVALID_SVC_VER ersxFRAMEWORK_ERROR("\x030", "vSc")
#define ersFE_NO_ACCESS_MODE_FITS ersxFRAMEWORK_ERROR("\x031", "acc")
#define ersFE_NO_SUCH_SERVICE ersxFRAMEWORK_ERROR("\x032", "nss")
#define ersFE_NONLOCAL_AUTO ersxFRAMEWORK_ERROR("\x033", "nla")
#define ersFE_NOT_ATTACHED_SVC ersxFRAMEWORK_ERROR("\x034", "!at")
#define ersFE_NOT_AUTHENTIFIED ersxFRAMEWORK_ERROR("\x035", "!au")
#define ersFE_NOT_PRIMARY_SVC ersxFRAMEWORK_ERROR("\x036", "!pr")
#define ersFE_NOT_YET_READY ersxFRAMEWORK_ERROR("\x037", "!rd")
#define ersFE_SVC_ALREADY_DELETED ersxFRAMEWORK_ERROR("\x038", "dlt")
#define ersFE_UNKNOWN_METHOD ersxFRAMEWORK_ERROR("\x039", "?m ")
#define ersFE_UNREACHABLE ersxFRAMEWORK_ERROR("\x03A", "rch")
#define ersFE_UNRECG_REQUEST ersxFRAMEWORK_ERROR("\x03B", "rcg")
#define ersFE_UNKNOWN_ERROR ersxFRAMEWORK_ERROR("\x03C", "???") //60
#define ersINTEGER_OVERFLOW MKERR1("\x03D", "intOv")
#define ersNOT_KNOWN MKERR1("\x03E", "!know")
#define ersDISCONNECTED MKERR1("\x03f", "discn")
#define ersINVALID_SESSION MKERR1("\x040", "Isess")
//ADJUST THIS WHEN ADDING ERROR CODES
#define opcdERROR_COUNT 0x41
////////////////////////////////////////////////////////////////////////////////
///Error code structure
struct opcd
{
///Internal error code struct
struct errcode
{
short _code;
unsigned char _desc[6];
int code() const { return _code; }
};
typedef const errcode* perrcode_t;
const errcode* _ptr;
////////////////////////////////////////////////////////////////////////////////
opcd() : _ptr(0) {}
opcd(const opcd& e) : _ptr(e._ptr) {}
opcd(const errcode* pe) : _ptr(pe) {}
opcd& operator = (const opcd e)
{
_ptr = e._ptr;
return *this;
}
opcd& operator = (const errcode* pe)
{
_ptr = pe;
return *this;
}
///Set error by number
void set(uint e);
bool operator == (opcd c) const
{
return code() == c.code();
}
bool operator != (opcd c) const { return ! (*this == c); }
// returns true if right side is either parent or if both are equal
bool operator >= (opcd c) const
{
uint c1 = code();
uint c2 = c.code();
if (c1 == c2) return true;
return parent1_equal(c1, c2);
}
friend inline bool operator == (opcd c, int err) { return (int)c.code() == err; }
friend inline bool operator == (int err, opcd c) { return (int)c.code() == err; }
friend inline bool operator != (opcd c, int err) { return (int)c.code() != err; }
friend inline bool operator != (int err, opcd c) { return (int)c.code() != err; }
///Get specific error text
const char* text() const
{
if (!_ptr || !_ptr->_code) return "";
return _ptr->_desc[5] ? (const char*)_ptr + 7 : "";
}
///Get common error text
const char* error_desc() const;
///Return error code, max 5 characters valid or until 0
const char* error_code() const
{
if (!_ptr || !_ptr->_code) return "OK";
return (const char*)_ptr->_desc;
}
static uints find_code(const char* c, uints len);
uint code() const
{
if (!_ptr) return 0;
if (_ptr->code() >= opcdERROR_COUNT) return (ersUNKNOWN)._ptr->code();
///TODO: remove this check later:
//assert( _ptr->code() == opcd::opcdTABLE[_ptr->code()].code->code() );
return _ptr->code();
}
private:
static bool parent1_equal(uint c1, uint c2);
};
////////////////////////////////////////////////////////////////////////////////
class charstr;
struct opcd_formatter
{
opcd_formatter(opcd e) : e(e) { }
charstr& text(charstr& dst) const;
uints write(char* buf, uints size);
opcd e;
};
COID_NAMESPACE_END
#endif /// ! __COID_COMM_RETCODES__HEADER_FILE__