/** poslib.c ** Perl interface hooks for displayLocalize.c and posServer CGI * * Copyright (C) 2001 Brian Rudy (brudyNO@SPAMpraecogito.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * * 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 (using modified * displayLocalize.c) * ** Revision History ** * 0.20 8/16/2001 * Cleaned up includes, added call_newgoal() and call_getgoal(). * Now works with basic client-side voting. * * 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.*/ } /* * Get the new goal (test version only) */ goalPosition call_getgoal(void) { goalPosition retGoals; int x, y; 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("getgoal", G_ARRAY|G_NOARGS); /* 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); } /* * 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); } /* * Init perl interpreter */ void initperl(void) { char *my_argv[] = { "", "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); }