/* * Perl interface hooks for displayLocalize and posServer CGI * * Brian Rudy (brudyNO@SPAMpraecogito.com) * * Compile with: * cc -c poslib.c `perl -MExtUtils::Embed -e ccopts` * gcc -shared -o libposlib.a poslib.o `perl -MExtUtils::Embed -e ccopts -e ldopts` * Then run make in localize src directory. * * 0.21 5/25/2002 * Added call_get_nearest_camerapos * * 0.20 8/16/2001 * Cleaned up includes, added call_newgoal and call_getgoal. * * 0.10 8/10/2001 * Basic test version * */ #include #include #include "poslib.h" #if defined(__cplusplus) && !defined(PERL_OBJECT) #define is_cplusplus #endif #ifdef is_cplusplus extern "C" { #endif #include #include #ifdef PERL_OBJECT #define NO_XSLOCKS #include #include "win32iop.h" #include #include #endif #ifdef is_cplusplus } # ifndef EXTERN_C # define EXTERN_C extern "C" # endif #else # ifndef EXTERN_C # define EXTERN_C extern # endif #endif EXTERN_C void xs_init (pTHXo); /* EXTERN_C void boot_IPC (pTHXo_ CV* cv); EXTERN_C void boot_IPC__ShareLite (pTHXo_ CV* cv); */ EXTERN_C void boot_DynaLoader (pTHXo_ CV* cv); EXTERN_C void xs_init(pTHXo) { char *file = __FILE__; dXSUB_SYS; /* newXS("IPC::bootstrap", boot_IPC, file); newXS("IPC::ShareLite::bootstrap", boot_IPC__ShareLite, file); */ /* DynaLoader is a special case */ newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); } static PerlInterpreter *my_perl; /* * Have poslib.pl clean things up for us. */ void call_poslibinit(void) { dSP ; PUSHMARK(SP) ; perl_call_pv("poslibinit", G_DISCARD|G_NOARGS) ; } /* * Reset the new goal semaphore. */ void call_flushsemaphores(void) { dSP ; PUSHMARK(SP) ; perl_call_pv("flushsemaphores", G_DISCARD|G_NOARGS) ; } /* * Push the current position into shared memory */ void call_pushpos(int x, int y, int theta) { dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ XPUSHs(sv_2mortal(newSViv(x))); /* push x onto the stack */ XPUSHs(sv_2mortal(newSViv(y))); /* push y onto stack */ XPUSHs(sv_2mortal(newSViv(theta))); /* push theta onto stack */ PUTBACK; /* make local stack pointer global */ call_pv("pushpos", G_SCALAR); /* call the function */ SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ /* printf ("Sucess= %d.\n", POPi); */ PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ } /* * How many active goals are there? */ int call_howmanygoals(void) { int howmany; dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ PUTBACK; /* make local stack pointer global */ call_pv("howmanygoals", G_SCALAR|G_NOARGS); /* call the function */ SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ /* These come off the stack in reverse order*/ howmany = POPi; PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ return(howmany); } /* * Get the selected goal (test version only) */ goalPosition call_getgoal(int whichone) { goalPosition retGoals; dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ XPUSHs(sv_2mortal(newSViv(whichone))); /* push whichone onto the stack */ PUTBACK; /* make local stack pointer global */ call_pv("getgoal", G_ARRAY); /* call the function */ SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ /* These come off the stack in reverse order*/ retGoals.y = POPi; retGoals.x = POPi; PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ return(retGoals); } /* * Get the nearest goal's camera target position */ cameraPosition call_get_nearest_camerapos(void) { cameraPosition retPos; dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ PUTBACK; /* make local stack pointer global */ call_pv("get_nearest_camerapos", G_ARRAY); /* call the function */ SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ /* These come off the stack in reverse order*/ retPos.z = POPi; retPos.y = POPi; retPos.x = POPi; PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ return(retPos); } /* * Check if there is a new goal waiting. */ int call_newgoal(void) { int result; dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ PUTBACK; /* make local stack pointer global */ call_pv("newgoal", G_SCALAR|G_NOARGS); /* call the function */ SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ result = POPi; PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ return(result); } /* * Speak the infotext for the nearest goal. */ void call_speakinfotext(void) { dSP ; PUSHMARK(SP) ; perl_call_pv("speakinfotext", G_DISCARD|G_NOARGS) ; } /* * Delete the nearest goal to the current position (after arrival). */ void call_mark_nearest_goal(void) { dSP ; PUSHMARK(SP) ; perl_call_pv("mark_nearest_goal", G_DISCARD|G_NOARGS) ; } /* * Init perl interpreter */ void initperl(void) { char *my_argv[] = { "", "/home/brudy/posServer/poslib.pl" }; my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, xs_init, 2, my_argv, (char **)NULL); perl_run(my_perl); } /* * Shut down local perl interpreter */ void perlclose(void) { perl_destruct(my_perl); perl_free(my_perl); }