theLink 10.0
Loading...
Searching...
No Matches
high_lng.h
Go to the documentation of this file.
1
9// internal usage -> PERL pre-parse (./perl_MqS.tcl) need this
10// Problem: PERL include CPP preprocessed data into the ".xsh" file but preprocessing require all
11// macros set.
12// Default: original in msgque_mq.h
13#if MQ_PRE_PARSE
14 #define MkBufferListCreateTLS(name,num) \
15 static MkThreadLocal struct MkBufferListS __##name = {0}; \
16 MK_BFL name = &__##name; \
17 if (likely(__MqBflCheck(__##name))) { \
18 MkBufferListReserve(name,num); \
19 } else { \
20 MkBufferListInit(name,num); \
21 MkRefIncr(name); \
22 }
23#endif
24
25/*
26
27highSKIP_SHIFT ... calculate argument position from array index
28 example: Send( callSig, ARRAY ...)
29 SKIP 0, ...
30 Arg-1 Arg-2, ...
31 highSKIP_SHIFT = 1 + 1 = 2
32
33highLastReturnListType ... get the last ONE CHAR signature type of the read-token.
34 -> the reason is a non-symmetric behaviour of the MkBufferS.
35 Every OTHER type can be stored into a MkBufferS but NOT the MkBufferS
36 self. the 'U' ONE CHAR signature have to be remembert if the user explicit
37 require a 'U' as return and NOT the 'U' internal data-type.
38
39EXAMPLE use of highLastReturnListType in "highRETURN_type_S"
40*/
41
42#define HighErrorV(cls,fmt,args...) \
43 MkErrorSetV_3M(obj, cls, fmt, args)
44
45#define HighErrorC(cls,fmt) \
46 MkErrorSetV_3M(obj, cls, "%s", fmt)
47
48#define highRETURN_type_S \
49 if (MkBufferListSizeI(RET) == 0 && highLastReturnListType != '*') { \
50 OT_retObj_SET_None; \
51 } else if (MkBufferListSizeI(RET) == 1 && highLastReturnListType != '*' ) { \
52 switch (highLastReturnListType) { \
53 case 'U': OT_retObj_SET_BUF(RET->data[0]); break; \
54/* >>>> disable MkBufferListReserve at startup from Send <<<< */ \
55/* OLD !! BUG FIX: high2-1-2-U-O-* */ \
56/* Return 'U' without 'Temp'orary object make return UNUSEABLE */ \
57/* as input for an other "Send", because "MkBufferListCreateTLS" */ \
58/* reset the return "U" */ \
59/* SEND_ONE_TYP_O { */ \
60/* set t [$ctx ReadSTR] */ \
61/* set RET [$ctx Send "W" "ECOA:$t@$t" [$ctx Read$t]] */ \
62/* $ctx Send "R" $t $RET */ \
63/* } */ \
64/* => "RET" is broken WITHOUT "temp" */ \
65/* case 'U': OT_MK_CALL_0(RET->data[0],MkBufferC,Temp,retObj); break; */ \
66 case 'L': OT_MK_CALL_0(RET->data[0],MkBufferC,GetBFL,retObj); break; \
67 default : OT_MK_CALL_0(RET->data[0],MkBufferC,ToObject,retObj); break; \
68 } \
69 } else { \
70 OT_retObj_SET_BFL(RET); \
71 }
72
73#define high_3_O BOL
74#define high_3_Y I8
75#define high_3_S I16
76#define high_3_I I32
77#define high_3_W I64
78#define high_3_H HDL
79#define high_3_F FLT
80#define high_3_D DBL
81#define high_3_C STRN
82#define high_3_B BIN
83#define high_3_U BUF
84#define high_3_L BFL
85#define high_3_A BAC
86
87#define high_C_BOL OT_TMP_BOL_OBJ
88#define high_C_I8 OT_TMP_I8_OBJ
89#define high_C_I16 OT_TMP_I16_OBJ
90#define high_C_I32 OT_TMP_I32_OBJ
91#define high_C_I64 OT_TMP_I64_OBJ
92#define high_C_H OT_TMP_HDL_OBJ
93#define high_C_FLT OT_TMP_FLT_OBJ
94#define high_C_DBL OT_TMP_DBL_OBJ
95#define high_C_STR OT_TMP_CST_OBJ
96#define high_C_BIN OT_TMP_BIN_OBJ
97#define high_C_BUF OT_TMP_BUF_OBJ
98#define high_C_BFL OT_TMP_BFL_OBJ
99#define high_C_A OT_TMP_BAC_OBJ
100
101#define high_T_BOL MK_BOL
102#define high_T_I8 MK_I8
103#define high_T_I16 MK_I16
104#define high_T_I32 MK_I32
105#define high_T_I64 MK_I64
106#define high_T_HDL MK_HDL
107#define high_T_FLT MK_FLT
108#define high_T_DBL MK_DBL
109#define high_T_STR MK_STRN
110#if !defined(high_T_BIN)
111 #define high_T_BIN MK_BIN
112#endif
113#if !defined(high_T_BUF)
114 #define high_T_BUF MK_BUF
115#endif
116#if !defined(high_T_BFL)
117 #define high_T_BFL MK_BFL
118#endif
119#if !defined(high_T_A)
120 #define high_T_A MK_BAC
121#endif
122#if !defined(MqReadA)
123 #define MqReadA MqReadALL
124#endif
125
126// SPLIT *********************************************************************************************
127 static MK_STRN unknown = "unknown";
134 bool Tstart = false;
135 bool Lstart = false;
137 bool rpc = false;
138
139#if highSIZE_AVAILABLE==0
140#if !defined(highSIZE)
141 # define highSIZE highSKIP+1
142#endif
143#endif
144
145#if highREAD_RETURN_LIST==1
146 __attribute__((unused)) MK_STRB highLastReturnListType = '\0';
147 // disable MkBufferListReserve temporary - the FIRST argument '->data[0]' is the return value
148 // of an previous 'Send(...' -> on a MkBufferListReserve the previous return will be destroyed.
149 #define MkBufferListReserve_RT(...)
151 #undef MkBufferListReserve_RT
152#endif
153
154#if defined(compile_as_cc_method)
155try {
156#endif
157
158 //++MkErrorReset(mqctx);
159
169
170 // step 1. -> read the CALL-Identifer
171 block = "CALL";
173 callSig = cstr;
174
175 for (ptr=cstr; *ptr != '\0'; ptr++) {
176 switch (*ptr) {
177 case 'E': call = MQ_ONCE ;timeout=0 ; continue;
178 case 'W': call = MQ_WAIT ; continue;
179 case 'R': call = MQ_RET ;timeout=0 ; continue;
180 }
181#if highSIZE_AVAILABLE
182 if (highSKIP >= highSIZE) {
183 HighErrorV("ArgumentListSizeError", "require %d have %d for item '%c'",
185 goto error;
186 }
187#endif
188 switch (*ptr) {
189 case 'S': call = MQ_SUB ;highCALL(fCall) ;
190 if (fCall==NULL) {
191 HighErrorC("SubError", "expect a FUNCTION pointer, but got 'NULL'");
192 goto error;
193 }
194 break;
195 case 'C': call = MQ_CB ;timeout=0 ;highCALL(fCall) ;
196 if (fCall==NULL) {
197 HighErrorC("CallbackError", "expect a FUNCTION pointer, but got 'NULL'");
198 goto error;
199 }
200 break;
201 case 'T': call = MQ_TRAN ;highTRAN(srvSig) ;
203 if (strlen(srvSig) != 4) {
204 HighErrorC("TokenError", "expect a '4' character string as a TRANSACTION-identifier");
205 goto error;
206 }
207 break;
208 case 't': highTIME(timeout) ;
209 break;
210 case 'r': rpc = true ;
211 break;
212 default: {
213 HighErrorV("Error", "invalid character '%c' found", *ptr);
214 goto error;
215 }
216 }
217 }
218
219 // step 2. -> build the Send-Data-Package
220
221 block = "TOKEN";
222//printV("highSKIP<%d>, highSIZE<%d>\n", highSKIP, highSIZE)
223 if (call == MQ_RET && highSKIP == highSIZE) goto call;
226 ptr = cstr = tokSig;
228
230 if (call == MQ_RET) {
231 token[0] = '\0';
232 if (tokSig[0] == ':') ptr+=1; // 1char ':' optional
233 } else {
234 size_t const toklen = strlen(tokSig);
235 if (rpc) {
236 MK_STRN end = strpbrk(ptr,":@");
237 size_t tlen = end ? (size_t) (end-ptr) : toklen;
238 strncpy(token,MkSysHashSTR(ptr,(MK_NUM)tlen),8);
239 token[8] = '\0';
240 ptr+=tlen;
241 } else if (toklen >= 4 && (tokSig[4] == ':' || tokSig[4] == '@' || tokSig[4] == '\0')) {
242 strncpy(token,tokSig,4);
243 token[4] = '\0';
244 ptr+=4;
245 } else if (toklen >= 8 && (tokSig[8] == ':' || tokSig[8] == '@' || tokSig[8] == '\0')) {
246 strncpy(token,tokSig,8);
247 token[8] = '\0';
248 ptr+=8;
249 } else {
250 HighErrorV("TokenError", "expect token as string of size 4 or as hex-string of size 8 but got '%s'", tokSig);
251 goto error;
252 }
253//printLV("token<%s>, cstr<%s>, tokSig<%s>\n", token, cstr, tokSig);
254 if (*ptr != '\0' && *ptr != '@') {
255 if (*ptr != ':' && *ptr != '\0') {
256 HighErrorV("TokenError", "expect ':' character but got '%c' character", *ptr);
257 goto error;
258 }
259 ptr+=1; // 4char 'TOKEN' + 1char ':'
260 }
261 }
262
263 for (; *ptr != '\0'; ptr++) {
264 switch (*ptr) {
265 case '[':
266 Lstart = true;
268 continue;
269 case ']':
270 if (Lstart == false) {
271 HighErrorC("SendError", "missing opening '[' to closing ']'");
272 goto error;
273 } else {
275 }
276 continue;
277 case '(':
278 if (call != MQ_TRAN) {
279 HighErrorV("SendError", "'(' invalid for CALL-signature '%s'", callSig);
280 goto error;
281 } else {
282 Tstart = true;
284 }
285 continue;
286 case ')':
287 if (call != MQ_TRAN) {
288 HighErrorV("SendError", "')' invalid for CALL-signature '%s'", callSig);
289 goto error;
290 } else if (Tstart == false) {
291 HighErrorV("SendError", "missing opening '(' to closing ')' for CALL-signature '%s'", callSig);
292 goto error;
293 } else {
295 }
296 continue;
297 case '@': goto call;
298 }
299
300#if highSIZE_AVAILABLE==1
301 if (highSKIP >= highSIZE) {
302 HighErrorV("ArgumentListSizeError", "require %d have %d for item '%c'",
304 goto error;
305 }
306#endif
307
308 switch (*ptr) {
309 case 'Y': highSend_I8;break;
310 case 'O': highSend_BOL;break;
311 case 'S': highSend_I16;break;
312 case 'I': highSend_I32;break;
313 case 'F': highSend_FLT;break;
314 case 'W': highSend_I64;break;
315 case 'D': highSend_DBL;break;
316 case 'C': highSend_STR;break;
317 case 'U': highSend_BUF;break;
318 case 'L': highSend_BFL;break;
319 case 'B': highSend_BIN;break;
320#if NHI1_bits == 64
321 case 'G': highSend_I64;break;
322#elif NHI1_bits == 32
323 case 'G': highSend_I32;break;
324#else
325# error "'wordsize' cannot be recognized because 'NHI1_bits' is not set. probably missing the header 'nhi1_config.h' ?"
326#endif
327 case 'H': highSend_HDL;break;
328 default:
329 HighErrorV("SendError","invalid character '%c' found", *ptr);
330 goto error;
331 }
332 }
333
335 // check # return-args
336 if (timeout == 0 && (*ptr) == '@' && (*(ptr+1)) != '\0') {
337 ptr++;
338 MkErrorSetV_4M(obj, "CallError", 0, "got RETURN args for NON-RETURN CALL-signature '%s'", callSig );
339 goto error;
340 }
341#if highSIZE_AVAILABLE==1
342 if ((*ptr) == '\0' && highSKIP < highSIZE) {
343 HighErrorV("ArgumentError","found '%d' argument(s) more than needed", (int)(highSIZE-highSKIP));
344 goto error;
345 }
346#endif
347
348 // do the service call
349 switch (call) {
350 case MQ_ONCE:
352 break;
353 case MQ_WAIT:
355 break;
356 case MQ_SUB:
358 break;
359 case MQ_CB:
361 break;
362 case MQ_TRAN:
364 break;
365 case MQ_RET:
367 break;
368 }
369
371#if highREAD_RETURN_LIST==1
373#endif
374 if (*ptr != '\0') {
375 for (ptr++; *ptr != '\0'; ptr++) {
377 if (highSKIP >= highSIZE) {
378#if highREAD_RETURN_LIST==0
379 HighErrorV("ArgumentListSizeError","require %d have %d - missing argument for item '%c'",
380 (int)highSKIP+highSKIP_SHIFT, (int)highSIZE, *ptr);
381 goto error;
382#else
383 if (MqReadGetNumItems(mqctx) <= 0 && *ptr != '*') {
384 HighErrorV("PackageSizeError","missing package-item(s) for format-string '%s'", ptr);
385 goto error;
386 }
387 enum MkTypeE target;
388 highLastReturnListType = *ptr;
389 // target support: highREAD_RETURN_LIST
390 switch (*ptr) {
391 case 'Y': target=MK_I8T; goto native;
392 case 'O': target=MK_BOLT; goto native;
393 case 'S': target=MK_I16T; goto native;
394 case 'I': target=MK_I32T; goto native;
395 case 'F': target=MK_FLTT; goto native;
396 case 'W': target=MK_I64T; goto native;
397 case 'D': target=MK_DBLT; goto native;
398#if NHI1_bits == 64
399 case 'G': target=MK_I64T; goto native;
400#else
401 case 'G': target=MK_I32T; goto native;
402#endif
403 case 'H': target=MK_HDLT; goto native;
404native: {
405 MK_BUF buf;
406 MqReadBUF_E(mqctx,&buf);
407 if (buf->var.type == MK_STRT) {
408 buf = MkBufferTemp(buf);
409 MkBufferCastTo_E(buf,target);
410 } else if (buf->var.type != target) {
411 HighErrorV("ReturnTypeError#1","require '%c' but have '%c'", *ptr, MkBufferGetType1(buf));
412 goto error;
413 }
414 MkBufferListAppendBUF(RET,buf);
415 break;
416 }
417 case 'C':
418 case 'L':
419 case 'B': {
420 MK_BUF buf;
421 MqReadBUF_E(mqctx,&buf);
422 if (MkBufferGetType1(buf) != *ptr) {
423 HighErrorV("ReturnTypeError#2","require '%c' but have '%c'", *ptr, MkBufferGetType1(buf));
424 goto error;
425
426 }
427 MkBufferListAppendBUF(RET,buf);
428 break;
429 }
430 case '.':
431 case 'U': {
432 MK_BUF buf;
433 MqReadBUF_E(mqctx,&buf);
434 MkBufferListAppendBUF(RET,buf);
435 break;
436 }
437 case '*': {
438 MqReadALL_E(mqctx, &RET);
439 break;
440 }
441 case '[': MkErrorCheck(MqReadL_START (mqctx,NULL) ); break;
442 case ']': MkErrorCheck(MqReadL_END (mqctx) ); break;
443 case '(':
444 case ')': {
445 HighErrorV("ReadError","special character '%c' not supported for RETURN-LIST type", *ptr);
446 goto error;
447 }
448 default: {
449 HighErrorV("ReadError","invalid character '%c' found", *ptr);
450 goto error;
451 }
452 }
453#endif
454 } else {
455 switch (*ptr) {
456#if highREAD_HAS_REFERENCE==1
457 case 'Y': highReadRef_I8;break;
458 case 'O': highReadRef_BOL;break;
459 case 'S': highReadRef_I16;break;
460 case 'I': highReadRef_I32;break;
461 case 'F': highReadRef_FLT;break;
462 case 'W': highReadRef_I64;break;
463 case 'D': highReadRef_DBL;break;
464 case 'C': highReadRef_STR;break;
465 case 'U': highReadRef_BUF;break;
466 case 'L': highReadRef_BFL;break;
467 case 'B': highReadRef_BIN;break;
468 case '*': highReadRef_ARGS;break;
469#endif
470 case '[': MkErrorCheck(MqReadL_START (mqctx,NULL) ); break;
471 case ']': MkErrorCheck(MqReadL_END (mqctx) ); break;
472 case '(': MkErrorCheck(MqReadT_START (mqctx) ); break;
473 case ')': MkErrorCheck(MqReadT_END (mqctx) ); break;
474 default: {
475 HighErrorV("ReadError","invalid character '%c' found", *ptr);
476 goto error;
477 }
478 }
479 }
480 }
481 }
482
483#if highSIZE_AVAILABLE==1
484 if (highSKIP < highSIZE) {
485 MkErrorSetV_4M(obj,"ArgumentListSizeError",-1,
486 "found more arguments '%d' as required '%d' at %s-signature '%s'",
487 (int)highSIZE, (int)highSKIP+highSKIP_SHIFT, block,cstr);
488 goto error;
489 }
490#endif
491
495#if defined(compile_as_cc_method)
496 // C++ -> FIRST raise
497 MkExceptionC::Raise(MkOBJ(mqctx));
498} catch (const std::exception& e) {
499 // C++ -> CATCH the FIRST raise AND everything wich was NOT raised by MQ
500//printV("fmtobj<%p>, fmtobj->objRt<%p>, MkRT<%p>", MkOBJ(mqctx), MkOBJ(mqctx)->objRt, MkRT);
501 //MkErrorC::DEFAULT()->Catch(e);
502 MkErrorC::FORMAT(MkOBJ(mqctx))->Catch(e);
503#endif
506 MkErrorStack_4M(obj, mqctx->ctxbuf.super.buf.storage.first.C, __FILE__, __LINE__);
507 if ((int)(ptr-cstr) > (int)strlen(cstr)) block = unknown;
508 //if (block != unknown) {
509 if (strcmp(block,"unknown")!=0) {
510 if ((int)(ptr-cstr) == (int)strlen(cstr))
511 MkErrorAppendV_2M(obj," -> found on %s-SIGNATUR '%s'", block, cstr);
512 else if (*ptr != '@')
513 MkErrorAppendV_2M(obj," -> found on CHARACTER '%c' at POSITION '" MK_FORMAT_Z "' of %s-SIGNATURE '%s'",
514 *ptr, (ptr-cstr)+1, block, cstr);
515 }
516#if defined(compile_as_cc_method)
517}
518#endif
519 // C++ -> SECOND raise
521// ********************************************************************************************
522
523// vim: nowrap
#define highSend_STR
#define highSend_I8
#define highSend_DBL
#define highREADinit
#define highREADprepare
#define highSend_BFL
#define highERRORnative
#define highFARGS(f)
#define highTOKEN(str)
#define highSend_HDL
#define highSend_BOL
#define highSKIP
#define highCALL(f)
#define highSend_I64
#define highSend_BUF
#define highSend_I32
#define highRETURN
#define highSELF
#define highTRAN(str)
#define highTIME(t)
#define highCMD
#define highSend_BIN
#define highSend_I16
#define highSend_FLT
#define highSKIP_SHIFT
#define MkBufferGetType1(...)
#define MkBufferTemp(...)
#define MkBufferCastTo_E(...)
#define MkBufferSetV(...)
#define MkBufferListAppendBUF(...)
#define MkBufferListReserve(...)
#define MkBufferListCreateTLS_T(name, num)
#define MkErrorStack_4M(m,...)
#define MkErrorAppendV_2M(m,...)
#define MkErrorSetV_4M(m,...)
MkTypeE
MK_TIMEOUT_USER
MK_I8T
MK_I64T
MK_FLTT
MK_I16T
MK_BOLT
MK_DBLT
MK_I32T
MK_STRT
int32_t MK_NUM
#define MK_HDLT
const MK_STRB * MK_STRN
char MK_STRB
time_t MK_TIME_T
#define MkOBJ(x)
MK_STRN MkSysHashSTR(MK_STRN key, MK_NUM length)
#define MQ_SEND_TOKEN_SIGNATURE_SIZE
#define MQ_SEND_TRANSACTION_TOKEN_SIZE
#define MqReadBUF_E(...)
#define MqReadALL_E(...)
#define MqReadT_START(...)
#define MqReadL_START(...)
#define MqReadT_END(...)
#define MqReadL_END(...)
MK_NUM MqReadGetNumItems(MQ_CTX const ctx)
get the number of items left in the read-data-package …
#define MqSendSTART(...)
#define MqSendEND_AND_TRANSACTION(...)
#define MqSendEND_AND_CALLBACK(...)
#define MqSendEND_AND_SUB(...)
#define MqSendEND_AND_WAIT(...)
#define MqSendEND(...)
#define MqSendL_START(...)
#define MqSendT_END(...)
#define MqSendL_END(...)
#define MqSendT_START(...)
#define MqSendRETURN(...)
#define HighErrorV(cls, fmt, args...)
Definition high_lng.h:42
MK_STRN block
Definition high_lng.h:128
MK_OBJ const obj
Definition high_lng.h:136
#define HighErrorC(cls, fmt)
Definition high_lng.h:45
static MK_STRN unknown
Definition high_lng.h:127
MK_STRB srvSig[MQ_SEND_TRANSACTION_TOKEN_SIZE+1]
Definition high_lng.h:131
highRETok
Definition high_lng.h:493
MkErrorCheck(MqSendSTART(mqctx))
bool Tstart
Definition high_lng.h:134
bool Lstart
Definition high_lng.h:135
MqCallE
select the MqSendEND... style
Definition high_lng.h:161
@ MQ_RET
MqSendRETURN
Definition high_lng.h:167
@ MQ_CB
MqSendEND_AND_CALLBACK
Definition high_lng.h:165
@ MQ_SUB
MqSendEND_AND_SUB
Definition high_lng.h:164
@ MQ_TRAN
MqSendEND_AND_TRANSACTION
Definition high_lng.h:166
@ MQ_WAIT
MqSendEND_AND_WAIT
Definition high_lng.h:163
@ MQ_ONCE
MqSendEND
Definition high_lng.h:162
bool rpc
Definition high_lng.h:137
#define highSIZE
Definition high_lng.h:141
highRETerror
Definition high_lng.h:520
MK_STRB tokSig[MQ_SEND_TOKEN_SIGNATURE_SIZE+1]
Definition high_lng.h:132
MK_STRB token[9]
Definition high_lng.h:229
goto error
Definition high_lng.h:251
MK_TIME_T timeout
Definition high_lng.h:133
enum MqCallE call
MK_STRN ptr
Definition high_lng.h:130
MK_STRN callSig
Definition high_lng.h:129
MkBufferSetV & mqctx
Definition high_lng.h:505
highINITcstr
Definition high_lng.h:172
struct MkBufferS::@4 var
enum MkTypeE type