theLink 10.0
Loading...
Searching...
No Matches
MqCall_rb.c File Reference

tag: nhi1-release-250425 More...

#include "LibMqMsgque_private_rb.h"
#include "misc_check_rb.h"
#include "tmpl/mq_misc_check_lng.h"
+ Include dependency graph for MqCall_rb.c:

Go to the source code of this file.

Functions

static VALUE rbmqmsgque_sRescue (MK_RT mkrt, MK_MNG const mng, VALUE(*proc)(ANYARGS), VALUE data)
 
static VALUE rbmqmsgque_sCallMethodWithoutSelf (VALUE method)
 
static VALUE rbmqmsgque_sCallMethodWithSelf (VALUE array)
 
static VALUE rbmqmsgque_sCallProcWithSelf (VALUE array)
 
enum MkErrorE rbmqmsgque_ServiceCall (MQ_SERVICE_CALL_ARGS)
 
void rbmqmsgque_ServiceFree (MQ_SERVICE_FREE_ARGS)
 
VALUE rbmqmsgque_sCopyWithSelf (MQ_CTX const mqctx, VALUE meth)
 
VALUE rbmqmsgque_sCopyWithoutSelf (MQ_CTX const mqctx, VALUE proc)
 
void rbmqmsgque_ServiceCopy (MQ_SERVICE_COPY_ARGS)
 
void rbmqmsgque_ProcMark (MK_RT mkrt, MK_PTR data)
 
enum MkErrorE rbmqmsgque_CheckConstructor (OT_Check_ARGS, MK_CCP *retP)
 

Detailed Description

tag: nhi1-release-250425

Definition in file MqCall_rb.c.

Function Documentation

◆ rbmqmsgque_CheckConstructor()

enum MkErrorE rbmqmsgque_CheckConstructor ( OT_Check_ARGS ,
MK_CCP * retP )

Definition at line 182 of file MqCall_rb.c.

186{
187 if ((*skipP) >= objc) {
188 WrongNumArgs(hdl, (*skipP), objc, -999, +999, arg);
189 goto error;
190 }
191 OT_OBJ_T objV = OT_LNG_OBJV((*skipP)++);
192 if (rb_class_inherited_p(objV,MQ(MqContextC)) != Qnil) {
193 *retP = (MK_CCP) objV;
194 } else if (rb_class_inherited_p(objV,MK(MkObjectC)) != Qnil) {
196 } else {
197 WrongTypeOfArgError(OT_LNG_NAME_FROM_CLASS(NS(MqContextC)), OT_OBJ_TYPE_STRING(objV));
198 }
199 return MK_OK;
200error:
201 return OT_ERROR_STACK;
202}
#define MK(n)
#define OT_LNG_NAME_FROM_CLASS(cls)
#define OT_OBJ_T
#define OT_LNG_OBJV(idx)
#define MQ(n)
#define NS(n)
MK_OK
MK_PTRB * MK_CCP
goto error
Definition high_lng.h:251
#define OT_ERROR_STACK
#define WrongNumArgs(...)
#define WrongTypeOfArgError(exp, got)

◆ rbmqmsgque_ProcMark()

void rbmqmsgque_ProcMark ( MK_RT mkrt,
MK_PTR data )

Definition at line 171 of file MqCall_rb.c.

171 {
172 struct MkCallS *call = (struct MkCallS*) data;
173//printV("call=%p, data=%p\n", call, call->procCallback)
174 rb_gc_mark(call->procCallback);
175}
enum MqCallE call

◆ rbmqmsgque_sCallMethodWithoutSelf()

static VALUE rbmqmsgque_sCallMethodWithoutSelf ( VALUE method)
static

Definition at line 33 of file MqCall_rb.c.

33 {
34 return rb_method_call(0, NULL, method);
35}

◆ rbmqmsgque_sCallMethodWithSelf()

static VALUE rbmqmsgque_sCallMethodWithSelf ( VALUE array)
static

Definition at line 38 of file MqCall_rb.c.

38 {
39 const VALUE *valP = rb_array_const_ptr(array);
40 return rb_method_call(1, &valP[0], valP[1]);
41}

◆ rbmqmsgque_sCallProcWithSelf()

static VALUE rbmqmsgque_sCallProcWithSelf ( VALUE array)
static

Definition at line 44 of file MqCall_rb.c.

44 {
45 const VALUE *valP = rb_array_const_ptr(array);
46 return rb_proc_call_with_block(valP[1], 1, &valP[0], Qnil);
47}

◆ rbmqmsgque_sCopyWithoutSelf()

VALUE rbmqmsgque_sCopyWithoutSelf ( MQ_CTX const mqctx,
VALUE proc )

Definition at line 156 of file MqCall_rb.c.

156 {
157 return rb_funcallv(proc,MK(id_clone),0,NULL);
158}

◆ rbmqmsgque_sCopyWithSelf()

VALUE rbmqmsgque_sCopyWithSelf ( MQ_CTX const mqctx,
VALUE meth )

Definition at line 147 of file MqCall_rb.c.

147 {
150 meth = rb_funcallv(meth,MK(id_clone),0,NULL);
151 meth = rb_funcallv(meth,MK(id_unbind),0,NULL);
152 meth = rb_funcall(meth,MK(id_bind),1,self);
153 return meth;
154}
#define OT_SETUP_self
#define mqctx
#define MkRtSetup_X(x)

◆ rbmqmsgque_ServiceCall()

enum MkErrorE rbmqmsgque_ServiceCall ( MQ_SERVICE_CALL_ARGS )

Definition at line 64 of file MqCall_rb.c.

65{
67
68 struct MkCallS *call = __data__;
69 int argNum = 1;
70
71 if (!MqCtxCheck(mqctx)) {
72 mk_dbg_color_ln(MK_COLOR_RED, "%s", "mqctx invalid");
73 }
74 if (!MqCtxCheck(call->hdl)) {
75 mk_dbg_color_ln(MK_COLOR_RED, "%s", "call->hdl invalid");
76 }
77
78 // 1. check environment
79 if (OT_LNG_NULL_IS(call->procCallback)) return MK_OK;
80
81//MkDbgDeepX_3(mqctx, "AAA", "cmd=%s", VAL2STRN(rb_inspect(call->procCallback)));
82
83 // 2. if not already done initialize
84 if (call->procCall == NULL) {
85 assert(!OT_LNG_NULL_IS(call->procArgs));
86 switch (call->procType) {
87 case MkCallS_own_method: {
89 argNum = rb_equal(rb_funcallv(call->procCallback,MK(id_receiver),0,NULL),self) ? 0 : 1;
90 if (argNum > call->procArity) goto methode_arg_error;
91 if (call->procArity == 0) {
92 call->procNeedSelf = false;
93 call->procCall = NS(sCallMethodWithoutSelf);
94 } else {
95 call->procNeedSelf = true;
96 call->procCall = NS(sCallMethodWithSelf);
97 }
98 }
99 break;
100 case MkCallS_proc:
101 call->procNeedSelf = true;
102 call->procCall = NS(sCallProcWithSelf);
103 if (argNum != call->procArity) goto methode_arg_error;
104 break;
105 default:
106 MkErrorSetV_3M(mqctx, "WrongInitError", "found invalid procType for callback '%s'", VAL2STRN(call->procCallback));
107 goto error;
108 break;
109 }
110 }
111
112 // 3. call callback
113 if (call->procNeedSelf == false) {
114 // without "self"
115 if (rb_obj_is_kind_of(call->procCallback, rb_cMethod) != Qtrue) {
116 mk_dbg_color_ln(MK_COLOR_RED, "%s", "call->procCallback invalid");
117 }
118 NS(sRescue)(MK_RT_CALL mqctx,call->procCall,call->procCallback);
119 } else {
120 // with "self"
122 VALUE ary = rb_ary_resize(call->procArgs,2);
123 rb_ary_store(ary,0,self);
124 rb_ary_store(ary,1,call->procCallback);
125 NS(sRescue)(MK_RT_CALL mqctx,call->procCall,ary);
126 }
127 MkErrorCheck_0E();
128
129MkDbgDeepX_3(mqctx, "BBB", "cmd=%s", VAL2STRN(rb_inspect(call->procCallback)));
130 return MkErrorGetCode_0E();
131
132methode_arg_error:
133 MkErrorSetV_3M(mqctx, "WrongNumberOfArgError", "for callback '%s' exactly '%d' argument is required, but '%d' was received",
134 VAL2STRN(call->procCallback), argNum, call->procArity);
135 goto error;
136
137error:
138MkDbgDeepX_3(mqctx, "EEE", "cmd=%s", VAL2STRN(rb_inspect(call->procCallback)));
139//printSTACK_1(mqctx)
140 return MkErrorStack_0E();
141}
#define OT_LNG_NULL_IS(obj)
#define VAL2STRN(val)
#define MkErrorGetCode_0E()
#define MkErrorStack_0E()
#define MkErrorSetV_3M(err, callfunc, printfmt,...)
#define MkDbgDeepX_3(m, ident, fmt,...)
#define MK_RT_CALL
static bool MqCtxCheck(MK_MNGN mng)
check MqContextS -> MkObjectS::signature …
#define MQ_SERVICE_CALL_CHECK

◆ rbmqmsgque_ServiceCopy()

void rbmqmsgque_ServiceCopy ( MQ_SERVICE_COPY_ARGS )

Definition at line 160 of file MqCall_rb.c.

160 {
161 struct MkCallS *call = *dataP = MkSysMemDup(MK_ERROR_PANIC, *dataP, sizeof(struct MkCallS));
162
163 if (call->procNeedSelf) {
164 call->procCallback = NS(sRescue)(MK_RT_CALL mqctx, NS(sCopyWithSelf), call->procCallback);
165 } else {
166 call->procCallback = NS(sRescue)(MK_RT_CALL mqctx, NS(sCopyWithoutSelf), call->procCallback);
167 }
168 INCR_REF(&call->procCallback);
169}
#define INCR_REF(valP)
#define MK_ERROR_PANIC
MK_PTR MkSysMemDup(MK_OBJN fmtobj, MK_PTRN const blck, size_t const size)

◆ rbmqmsgque_ServiceFree()

void rbmqmsgque_ServiceFree ( MQ_SERVICE_FREE_ARGS )

Definition at line 143 of file MqCall_rb.c.

143 {
144 MK(CallFree)(dataP);
145}

◆ rbmqmsgque_sRescue()

static VALUE rbmqmsgque_sRescue ( MK_RT mkrt,
MK_MNG const mng,
VALUE(* proc )(ANYARGS),
VALUE data )
inlinestatic

Definition at line 16 of file MqCall_rb.c.

21 {
22 int state;
23 VALUE ret = rb_protect(proc, data, &state);
24 if (state) {
25 OT_ERROR_LNG_2_META_2(mng,"ProcessEvent");
26 }
27 return ret;
28}
#define OT_ERROR_LNG_2_META_2(m, s)