… | |
… | |
292 | va_end (args); |
292 | va_end (args); |
293 | |
293 | |
294 | return sv; |
294 | return sv; |
295 | } |
295 | } |
296 | |
296 | |
297 | ///////////////////////////////////////////////////////////////////////////// |
|
|
298 | |
|
|
299 | void |
|
|
300 | inject_event (const char *func, CFPContext *context) |
|
|
301 | { |
|
|
302 | dSP; |
|
|
303 | |
|
|
304 | ENTER; |
|
|
305 | SAVETMPS; |
|
|
306 | |
|
|
307 | PUSHMARK (SP); |
|
|
308 | |
|
|
309 | EXTEND (SP, 10); |
|
|
310 | |
|
|
311 | HV *hv = newHV (); |
|
|
312 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context->expr), 0) |
|
|
313 | hv_context (CFAPI_POBJECT, ,who); |
|
|
314 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
315 | hv_context (CFAPI_POBJECT, ,third); |
|
|
316 | hv_context (CFAPI_POBJECT, ,event); |
|
|
317 | hv_context (CFAPI_PMAP, ,map); |
|
|
318 | hv_context (CFAPI_STRING , ,message); |
|
|
319 | hv_context (CFAPI_INT ,&,fix); |
|
|
320 | hv_context (CFAPI_INT ,&,event_code); |
|
|
321 | hv_context (CFAPI_STRING , ,options); |
|
|
322 | hv_context (CFAPI_STRING , ,extension); |
|
|
323 | |
|
|
324 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
325 | |
|
|
326 | PUTBACK; |
|
|
327 | int count = call_pv (func, G_SCALAR | G_EVAL); |
|
|
328 | SPAGAIN; |
|
|
329 | |
|
|
330 | if (SvTRUE (ERRSV)) |
|
|
331 | LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); |
|
|
332 | |
|
|
333 | context->returnvalue = count > 0 ? POPi : 0; |
|
|
334 | |
|
|
335 | PUTBACK; |
|
|
336 | FREETMPS; |
|
|
337 | LEAVE; |
|
|
338 | } |
|
|
339 | |
|
|
340 | ///////////////////////////////////////////////////////////////////////////// |
297 | ///////////////////////////////////////////////////////////////////////////// |
341 | |
298 | |
342 | int |
299 | int |
343 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
300 | initPlugin (const char *iversion, f_plug_api gethooksptr) |
344 | { |
301 | { |
… | |
… | |
642 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
599 | strncpy (context.extension, va_arg (args, char *), sizeof (context.extension)); |
643 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
600 | strncpy (context.options, va_arg (args, char *), sizeof (context.options)); |
644 | context.event = va_arg (args, object *); |
601 | context.event = va_arg (args, object *); |
645 | va_end (args); |
602 | va_end (args); |
646 | |
603 | |
647 | context.returnvalue = 0; |
604 | { |
|
|
605 | dSP; |
648 | |
606 | |
649 | inject_event ("cf::inject_event", &context); |
607 | ENTER; |
|
|
608 | SAVETMPS; |
|
|
609 | |
|
|
610 | PUSHMARK (SP); |
|
|
611 | |
|
|
612 | EXTEND (SP, 10); |
|
|
613 | |
|
|
614 | HV *hv = newHV (); |
|
|
615 | #define hv_context(type,addr,expr) hv_store (hv, #expr, sizeof (#expr) - 1, newSVcfapi (type, addr context.expr), 0) |
|
|
616 | hv_context (CFAPI_POBJECT, ,who); |
|
|
617 | hv_context (CFAPI_POBJECT, ,activator); |
|
|
618 | hv_context (CFAPI_POBJECT, ,third); |
|
|
619 | hv_context (CFAPI_POBJECT, ,event); |
|
|
620 | hv_context (CFAPI_PMAP, ,map); |
|
|
621 | hv_context (CFAPI_STRING , ,message); |
|
|
622 | hv_context (CFAPI_INT ,&,fix); |
|
|
623 | hv_context (CFAPI_INT ,&,event_code); |
|
|
624 | hv_context (CFAPI_STRING , ,options); |
|
|
625 | hv_context (CFAPI_STRING , ,extension); |
|
|
626 | |
|
|
627 | PUSHs (sv_2mortal (newRV_noinc ((SV *)hv))); |
|
|
628 | |
|
|
629 | PUTBACK; |
|
|
630 | int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); |
|
|
631 | SPAGAIN; |
|
|
632 | |
|
|
633 | if (SvTRUE (ERRSV)) |
|
|
634 | LOG (llevError, "event '%d' callback evaluation error: %s", context.event_code, SvPV_nolen (ERRSV)); |
|
|
635 | |
|
|
636 | context.returnvalue = count > 0 ? POPi : 0; |
|
|
637 | |
|
|
638 | PUTBACK; |
|
|
639 | FREETMPS; |
|
|
640 | LEAVE; |
|
|
641 | } |
650 | |
642 | |
651 | rv = context.returnvalue; |
643 | rv = context.returnvalue; |
652 | return &rv; |
644 | return &rv; |
653 | } |
645 | } |
654 | |
646 | |