perlvdb_oohelpers.c

Go to the documentation of this file.
00001 /* 
00002  * $Id: perlvdb_oohelpers.c 770 2007-01-22 10:16:34Z bastian $
00003  *
00004  * Perl virtual database module interface
00005  *
00006  * Copyright (C) 2007 Collax GmbH
00007  *                    (Bastian Friedrich <bastian.friedrich@collax.com>)
00008  *
00009  * This file is part of Kamailio, a free SIP server.
00010  *
00011  * Kamailio is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * Kamailio is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License 
00022  * along with this program; if not, write to the Free Software 
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  *
00025  */
00026 
00027 #include "perlvdb_oohelpers.h"
00028 
00029 #include "../../mem/mem.h"
00030 
00031 SV *perlvdb_perlmethod(SV *class,
00032              const char* method,
00033              SV *param1,
00034              SV *param2,
00035              SV *param3,
00036              SV *param4) {
00037    
00038    I32 res;
00039    SV *retval = NULL;
00040    
00041    dSP;
00042    
00043                   ENTER;
00044                             SAVETMPS;
00045                   
00046    PUSHMARK(SP);
00047 
00048    /* passed stack:
00049     * class, and optionally parameters
00050     */
00051    XPUSHs(class);
00052 
00053    if (param1) {
00054       XPUSHs(param1);
00055    }
00056 
00057    if (param2) {
00058       XPUSHs(param2);
00059    }
00060 
00061    if (param3) {
00062       XPUSHs(param3);
00063    }
00064 
00065    if (param4) {
00066       XPUSHs(param4);
00067    }
00068 
00069    PUTBACK;
00070 
00071    res = call_method(method, G_SCALAR | G_EVAL);
00072 
00073    SPAGAIN;
00074 
00075    if (res == 0) {
00076       retval = &PL_sv_undef;
00077    } else if (res == 1) {
00078       retval = POPs;
00079    } else {
00080       /* More than one result in Scalar context??? */
00081       LM_CRIT("got more than one result from scalar method!");
00082       while (res--) { /* Try to clean stack. This
00083                should never happen anyway.*/
00084          retval = POPs;
00085       }
00086    }
00087 
00088    SPAGAIN;
00089 
00090 // if (sv_isobject(retval))
00091       SvREFCNT_inc(retval);
00092 
00093    FREETMPS;
00094    LEAVE;
00095 
00096    return retval;
00097 }
00098 

Generated on Thu May 24 02:00:29 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6