提交 a3ccefa7 authored 作者: Anthony Minessale's avatar Anthony Minessale

snake charming

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8998 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 0f873e69
......@@ -331,7 +331,7 @@ libs/openzap/Makefile:
cd libs/openzap && autoconf
cd libs/openzap && ./configure
update-clean: clean modwipe uninstall libs/openzap/Makefile
update-clean: clean modwipe uninstall libs/openzap/Makefile python-reconf
cd libs/sofia-sip && $(MAKE) clean
cd libs/openzap && $(MAKE) clean
cd libs/portaudio && $(MAKE) clean
......@@ -347,6 +347,10 @@ speedy-sure: update-clean
cd libs/sofia-sip && $(MAKE) -j
$(MAKE) -j modules
python-reconf:
rm -f src/mod/languages/mod_python/Makefile
./config.status
pa-reconf:
cd libs/portaudio && $(MAKE) clean
cd libs/portaudio && sh ./configure.gnu
......
......@@ -9,7 +9,8 @@ make mod_perl_wrap.cpp
cd ../../../..
cd src/mod/languages/mod_python
make reswig
make swigclean
make mod_python_wrap.cpp
cd ../../../..
cd src/mod/languages/mod_java
......
......@@ -101,6 +101,14 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg);
S_RDLOCK = (1 << 2)
} session_flag_t;
class DTMF {
public:
char digit;
uint32_t duration;
SWITCH_DECLARE_CONSTRUCTOR DTMF(char idigit, uint32_t iduration = SWITCH_DEFAULT_DTMF_DURATION);
virtual SWITCH_DECLARE_CONSTRUCTOR ~DTMF();
};
class Stream {
protected:
switch_stream_handle_t mystream;
......@@ -172,7 +180,7 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg);
SWITCH_DECLARE_CONSTRUCTOR CoreSession();
SWITCH_DECLARE_CONSTRUCTOR CoreSession(char *uuid);
SWITCH_DECLARE_CONSTRUCTOR CoreSession(switch_core_session_t *new_session);
SWITCH_DECLARE_CONSTRUCTOR ~ CoreSession();
virtual SWITCH_DECLARE_CONSTRUCTOR ~ CoreSession();
switch_core_session_t *session;
switch_channel_t *channel;
unsigned int flags;
......
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.35
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.freeswitch.swig;
public class DTMF {
private long swigCPtr;
protected boolean swigCMemOwn;
protected DTMF(long cPtr, boolean cMemoryOwn) {
swigCMemOwn = cMemoryOwn;
swigCPtr = cPtr;
}
protected static long getCPtr(DTMF obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
protected void finalize() {
delete();
}
public synchronized void delete() {
if(swigCPtr != 0 && swigCMemOwn) {
swigCMemOwn = false;
freeswitchJNI.delete_DTMF(swigCPtr);
}
swigCPtr = 0;
}
public void setDigit(char value) {
freeswitchJNI.DTMF_digit_set(swigCPtr, this, value);
}
public char getDigit() {
return freeswitchJNI.DTMF_digit_get(swigCPtr, this);
}
public void setDuration(SWIGTYPE_p_uint32_t value) {
freeswitchJNI.DTMF_duration_set(swigCPtr, this, SWIGTYPE_p_uint32_t.getCPtr(value));
}
public SWIGTYPE_p_uint32_t getDuration() {
return new SWIGTYPE_p_uint32_t(freeswitchJNI.DTMF_duration_get(swigCPtr, this), true);
}
public DTMF(char idigit, SWIGTYPE_p_uint32_t iduration) {
this(freeswitchJNI.new_DTMF__SWIG_0(idigit, SWIGTYPE_p_uint32_t.getCPtr(iduration)), true);
}
public DTMF(char idigit) {
this(freeswitchJNI.new_DTMF__SWIG_1(idigit), true);
}
}
/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 1.3.35
*
* Do not make changes to this file unless you know what you are doing--modify
* the SWIG interface file instead.
* ----------------------------------------------------------------------------- */
package org.freeswitch.swig;
public class SWIGTYPE_p_uint32_t {
private long swigCPtr;
protected SWIGTYPE_p_uint32_t(long cPtr, boolean futureUse) {
swigCPtr = cPtr;
}
protected SWIGTYPE_p_uint32_t() {
swigCPtr = 0;
}
protected static long getCPtr(SWIGTYPE_p_uint32_t obj) {
return (obj == null) ? 0 : obj.swigCPtr;
}
}
......@@ -32,6 +32,13 @@ class freeswitchJNI {
public final static native int S_HUP_get();
public final static native int S_FREE_get();
public final static native int S_RDLOCK_get();
public final static native void DTMF_digit_set(long jarg1, DTMF jarg1_, char jarg2);
public final static native char DTMF_digit_get(long jarg1, DTMF jarg1_);
public final static native void DTMF_duration_set(long jarg1, DTMF jarg1_, long jarg2);
public final static native long DTMF_duration_get(long jarg1, DTMF jarg1_);
public final static native long new_DTMF__SWIG_0(char jarg1, long jarg2);
public final static native long new_DTMF__SWIG_1(char jarg1);
public final static native void delete_DTMF(long jarg1);
public final static native long new_Stream__SWIG_0();
public final static native long new_Stream__SWIG_1(long jarg1);
public final static native void delete_Stream(long jarg1);
......
......@@ -643,6 +643,117 @@ SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_S_1RDLOCK_1get(JN
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_DTMF_1digit_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jchar jarg2) {
DTMF *arg1 = (DTMF *) 0 ;
char arg2 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(DTMF **)&jarg1;
arg2 = (char)jarg2;
if (arg1) (arg1)->digit = arg2;
}
SWIGEXPORT jchar JNICALL Java_org_freeswitch_swig_freeswitchJNI_DTMF_1digit_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jchar jresult = 0 ;
DTMF *arg1 = (DTMF *) 0 ;
char result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(DTMF **)&jarg1;
result = (char) ((arg1)->digit);
jresult = (jchar)result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_DTMF_1duration_1set(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jlong jarg2) {
DTMF *arg1 = (DTMF *) 0 ;
uint32_t arg2 ;
uint32_t *argp2 ;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(DTMF **)&jarg1;
argp2 = *(uint32_t **)&jarg2;
if (!argp2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null uint32_t");
return ;
}
arg2 = *argp2;
if (arg1) (arg1)->duration = arg2;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_DTMF_1duration_1get(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jlong jresult = 0 ;
DTMF *arg1 = (DTMF *) 0 ;
uint32_t result;
(void)jenv;
(void)jcls;
(void)jarg1_;
arg1 = *(DTMF **)&jarg1;
result = ((arg1)->duration);
*(uint32_t **)&jresult = new uint32_t((uint32_t &)result);
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1DTMF_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jchar jarg1, jlong jarg2) {
jlong jresult = 0 ;
char arg1 ;
uint32_t arg2 ;
DTMF *result = 0 ;
uint32_t *argp2 ;
(void)jenv;
(void)jcls;
arg1 = (char)jarg1;
argp2 = *(uint32_t **)&jarg2;
if (!argp2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null uint32_t");
return 0;
}
arg2 = *argp2;
result = (DTMF *)new DTMF(arg1,arg2);
*(DTMF **)&jresult = result;
return jresult;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1DTMF_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jchar jarg1) {
jlong jresult = 0 ;
char arg1 ;
DTMF *result = 0 ;
(void)jenv;
(void)jcls;
arg1 = (char)jarg1;
result = (DTMF *)new DTMF(arg1);
*(DTMF **)&jresult = result;
return jresult;
}
SWIGEXPORT void JNICALL Java_org_freeswitch_swig_freeswitchJNI_delete_1DTMF(JNIEnv *jenv, jclass jcls, jlong jarg1) {
DTMF *arg1 = (DTMF *) 0 ;
(void)jenv;
(void)jcls;
arg1 = *(DTMF **)&jarg1;
delete arg1;
}
SWIGEXPORT jlong JNICALL Java_org_freeswitch_swig_freeswitchJNI_new_1Stream_1_1SWIG_10(JNIEnv *jenv, jclass jcls) {
jlong jresult = 0 ;
Stream *result = 0 ;
......
......@@ -179,6 +179,47 @@ sub ACQUIRE {
}
############# Class : freeswitch::DTMF ##############
package freeswitch::DTMF;
use vars qw(@ISA %OWNER %ITERATORS %BLESSEDMEMBERS);
@ISA = qw( freeswitch );
%OWNER = ();
%ITERATORS = ();
*swig_digit_get = *freeswitchc::DTMF_digit_get;
*swig_digit_set = *freeswitchc::DTMF_digit_set;
*swig_duration_get = *freeswitchc::DTMF_duration_get;
*swig_duration_set = *freeswitchc::DTMF_duration_set;
sub new {
my $pkg = shift;
my $self = freeswitchc::new_DTMF(@_);
bless $self, $pkg if defined($self);
}
sub DESTROY {
return unless $_[0]->isa('HASH');
my $self = tied(%{$_[0]});
return unless defined $self;
delete $ITERATORS{$self};
if (exists $OWNER{$self}) {
freeswitchc::delete_DTMF($self);
delete $OWNER{$self};
}
}
sub DISOWN {
my $self = shift;
my $ptr = tied(%$self);
delete $OWNER{$ptr};
}
sub ACQUIRE {
my $self = shift;
my $ptr = tied(%$self);
$OWNER{$ptr} = 1;
}
############# Class : freeswitch::Stream ##############
package freeswitch::Stream;
......
......@@ -11,19 +11,20 @@ include ../../../../build/modmake.rules
LINK=$(CXXLINK)
PYMOD=freeswitch
PYTHON_SITE_DIR=@PYTHON_SITE_DIR@
PYTHON_SITE_DIR=/usr/lib/python2.4/site-packages
SWIGCFILE=../../../switch_swig.c
SWIGIFILE=../../../switch_swig.i
reswig:
swig -python -shadow -c++ -I../../../../src/include -o mod_python_wrap.cpp mod_python.i
reswig: swigclean mod_python_wrap.cpp
switch_swig_wrap.o: switch_swig_wrap.c Makefile
$(CC) -w $(CFLAGS) -c $< -o $@
swigclean: clean
rm -f mod_python_wrap.* freeswitch.py
switch_swig.o: $(SWIGCFILE) Makefile
$(CC) -w $(CFLAGS) -c $< -o $@
mod_python_wrap.cpp: mod_python_extra.c
swig -python -c++ -I../../../../src/include -oh mod_python_wrap.h -o mod_python_wrap.cpp mod_python.i
echo "#include \"mod_python_extra.c\"" >> mod_python_wrap.cpp
patch -s -p0 -i hack.diff
local_install:
mkdir -m755 -p $(DESTDIR)$(PYTHON_SITE_DIR)
......
......@@ -114,6 +114,27 @@ input_callback_state_t_swigregister(input_callback_state_t)
S_HUP = _freeswitch.S_HUP
S_FREE = _freeswitch.S_FREE
S_RDLOCK = _freeswitch.S_RDLOCK
class DTMF(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, DTMF, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, DTMF, name)
__repr__ = _swig_repr
__swig_setmethods__["digit"] = _freeswitch.DTMF_digit_set
__swig_getmethods__["digit"] = _freeswitch.DTMF_digit_get
if _newclass:digit = _swig_property(_freeswitch.DTMF_digit_get, _freeswitch.DTMF_digit_set)
__swig_setmethods__["duration"] = _freeswitch.DTMF_duration_set
__swig_getmethods__["duration"] = _freeswitch.DTMF_duration_get
if _newclass:duration = _swig_property(_freeswitch.DTMF_duration_get, _freeswitch.DTMF_duration_set)
def __init__(self, *args):
this = _freeswitch.new_DTMF(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _freeswitch.delete_DTMF
__del__ = lambda self : None;
DTMF_swigregister = _freeswitch.DTMF_swigregister
DTMF_swigregister(DTMF)
class Stream(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, Stream, name, value)
......@@ -274,31 +295,43 @@ console_clean_log = _freeswitch.console_clean_log
bridge = _freeswitch.bridge
hanguphook = _freeswitch.hanguphook
dtmf_callback = _freeswitch.dtmf_callback
S_SWAPPED_IN = _freeswitch.S_SWAPPED_IN
S_SWAPPED_OUT = _freeswitch.S_SWAPPED_OUT
class PySession(CoreSession):
class Session(CoreSession):
__swig_setmethods__ = {}
for _s in [CoreSession]: __swig_setmethods__.update(getattr(_s,'__swig_setmethods__',{}))
__setattr__ = lambda self, name, value: _swig_setattr(self, PySession, name, value)
__setattr__ = lambda self, name, value: _swig_setattr(self, Session, name, value)
__swig_getmethods__ = {}
for _s in [CoreSession]: __swig_getmethods__.update(getattr(_s,'__swig_getmethods__',{}))
__getattr__ = lambda self, name: _swig_getattr(self, PySession, name)
__getattr__ = lambda self, name: _swig_getattr(self, Session, name)
__repr__ = _swig_repr
def __init__(self, *args):
this = _freeswitch.new_PySession(*args)
this = _freeswitch.new_Session(*args)
try: self.this.append(this)
except: self.this = this
__swig_destroy__ = _freeswitch.delete_PySession
__swig_destroy__ = _freeswitch.delete_Session
__del__ = lambda self : None;
def setDTMFCallback(*args): return _freeswitch.PySession_setDTMFCallback(*args)
def setHangupHook(*args): return _freeswitch.PySession_setHangupHook(*args)
def check_hangup_hook(*args): return _freeswitch.PySession_check_hangup_hook(*args)
def hangup(*args): return _freeswitch.PySession_hangup(*args)
def begin_allow_threads(*args): return _freeswitch.PySession_begin_allow_threads(*args)
def end_allow_threads(*args): return _freeswitch.PySession_end_allow_threads(*args)
def run_dtmf_callback(*args): return _freeswitch.PySession_run_dtmf_callback(*args)
PySession_swigregister = _freeswitch.PySession_swigregister
PySession_swigregister(PySession)
def begin_allow_threads(*args): return _freeswitch.Session_begin_allow_threads(*args)
def end_allow_threads(*args): return _freeswitch.Session_end_allow_threads(*args)
def check_hangup_hook(*args): return _freeswitch.Session_check_hangup_hook(*args)
def run_dtmf_callback(*args): return _freeswitch.Session_run_dtmf_callback(*args)
def setInputCallback(*args): return _freeswitch.Session_setInputCallback(*args)
def setHangupHook(*args): return _freeswitch.Session_setHangupHook(*args)
def ready(*args): return _freeswitch.Session_ready(*args)
__swig_setmethods__["cb_function"] = _freeswitch.Session_cb_function_set
__swig_getmethods__["cb_function"] = _freeswitch.Session_cb_function_get
if _newclass:cb_function = _swig_property(_freeswitch.Session_cb_function_get, _freeswitch.Session_cb_function_set)
__swig_setmethods__["cb_arg"] = _freeswitch.Session_cb_arg_set
__swig_getmethods__["cb_arg"] = _freeswitch.Session_cb_arg_get
if _newclass:cb_arg = _swig_property(_freeswitch.Session_cb_arg_get, _freeswitch.Session_cb_arg_set)
__swig_setmethods__["hangup_func"] = _freeswitch.Session_hangup_func_set
__swig_getmethods__["hangup_func"] = _freeswitch.Session_hangup_func_get
if _newclass:hangup_func = _swig_property(_freeswitch.Session_hangup_func_get, _freeswitch.Session_hangup_func_set)
__swig_setmethods__["hangup_func_arg"] = _freeswitch.Session_hangup_func_arg_set
__swig_getmethods__["hangup_func_arg"] = _freeswitch.Session_hangup_func_arg_get
if _newclass:hangup_func_arg = _swig_property(_freeswitch.Session_hangup_func_arg_get, _freeswitch.Session_hangup_func_arg_set)
def setPython(*args): return _freeswitch.Session_setPython(*args)
def setSelf(*args): return _freeswitch.Session_setSelf(*args)
Session_swigregister = _freeswitch.Session_swigregister
Session_swigregister(Session)
#ifndef FREESWITCH_PYTHON_H
#define FREESWITCH_PYTHON_H
#include <Python.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef DOH
#include <Python.h>
#include "mod_python_extra.h"
}
#endif
#include <switch_cpp.h>
typedef enum {
S_SWAPPED_IN = (1 << 0),
S_SWAPPED_OUT = (1 << 1)
} swap_state_t;
void console_log(char *level_str, char *msg);
void console_clean_log(char *msg);
class PySession : public CoreSession {
namespace PYTHON {
class Session : public CoreSession {
private:
void *threadState;
int swapstate;
virtual void do_hangup_hook();
PyObject *getPython();
PyObject *Py;
PyObject *Self;
int hh;
int mark;
PyThreadState *TS;
public:
PySession();
PySession(char *uuid);
PySession(switch_core_session_t *session);
~PySession();
void setDTMFCallback(PyObject *pyfunc, char *funcargs);
void setHangupHook(PyObject *pyfunc);
void check_hangup_hook();
void hangup(char *cause);
bool begin_allow_threads();
bool end_allow_threads();
/**
* Run DTMF callback
*
* A static method in CoreSession is the first thing called
* upon receving a dtmf/event callback from fs engine, and then
* it gets the PySession instance and calls this method with
* dtmf/event object.
*
* @param input - a dtmf char buffer, or an event 'object' (not sure..)
* @param itype - a SWITCH_INPUT_TYPE_DTMF or a SWITCH_INPUT_TYPE_EVENT
*/
switch_status_t run_dtmf_callback(void *input,
switch_input_type_t itype);
Session();
Session(char *uuid);
Session(switch_core_session_t *session);
virtual ~Session();
virtual bool begin_allow_threads();
virtual bool end_allow_threads();
virtual void check_hangup_hook();
virtual switch_status_t run_dtmf_callback(void *input, switch_input_type_t itype);
void setInputCallback(PyObject *cbfunc, PyObject *funcargs = NULL);
void setHangupHook(PyObject *pyfunc, PyObject *arg = NULL);
bool ready();
PyObject *cb_function;
PyObject *cb_arg;
PyObject *hangup_func;
PyObject *hangup_func_arg;
void setPython(PyObject *state);
void setSelf(PyObject *state);
};
#ifdef __cplusplus
}
#endif
#endif
--- mod_python_wrap.cpp 2008-07-10 13:14:21.000000000 -0500
+++ old.cpp 2008-07-10 13:13:57.000000000 -0500
@@ -8150,20 +8150,20 @@
}
-SWIGINTERN PyObject *_wrap_new_Session__SWIG_0(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_new_Session__SWIG_0(PyObject *self, PyObject *args) {
PyObject *resultobj = 0;
PYTHON::Session *result = 0 ;
if (!PyArg_ParseTuple(args,(char *)":new_Session")) SWIG_fail;
result = (PYTHON::Session *)new PYTHON::Session();
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 );
+ resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 ); result->setPython(self);
return resultobj;
fail:
return NULL;
}
-SWIGINTERN PyObject *_wrap_new_Session__SWIG_1(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_new_Session__SWIG_1(PyObject *self, PyObject *args) {
PyObject *resultobj = 0;
char *arg1 = (char *) 0 ;
PYTHON::Session *result = 0 ;
@@ -8179,7 +8179,7 @@
}
arg1 = reinterpret_cast< char * >(buf1);
result = (PYTHON::Session *)new PYTHON::Session(arg1);
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 );
+ resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 ); result->setPython(self);
if (alloc1 == SWIG_NEWOBJ) delete[] buf1;
return resultobj;
fail:
@@ -8188,7 +8188,7 @@
}
-SWIGINTERN PyObject *_wrap_new_Session__SWIG_2(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+SWIGINTERN PyObject *_wrap_new_Session__SWIG_2(PyObject *self, PyObject *args) {
PyObject *resultobj = 0;
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
PYTHON::Session *result = 0 ;
@@ -8203,7 +8203,7 @@
}
arg1 = reinterpret_cast< switch_core_session_t * >(argp1);
result = (PYTHON::Session *)new PYTHON::Session(arg1);
- resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 );
+ resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_NEW | 0 ); result->setPython(self);
return resultobj;
fail:
return NULL;
......@@ -42,7 +42,7 @@
#endif
#include <switch.h>
#include "mod_python_extra.h"
PyThreadState *mainThreadState = NULL;
......@@ -62,7 +62,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
int argc;
int lead = 0;
char *script = NULL;
PyObject *module = NULL;
PyObject *module = NULL, *sp = NULL;
PyObject *function = NULL;
PyObject *arg = NULL;
PyObject *result = NULL;
......@@ -139,6 +139,10 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyTuple_SetItem(arg, 0, nada);
}
if (session) {
sp = mod_python_conjure_session(module, session, "session");
}
// invoke the handler
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
......@@ -150,21 +154,26 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyErr_Print();
PyErr_Clear();
}
goto done_swap_out;
done:
switch_safe_free(dupargs);
if (sp) {
Py_XDECREF(sp);
}
done_swap_out:
// decrement ref counts
Py_XDECREF(module);
Py_XDECREF(function);
Py_XDECREF(arg);
Py_XDECREF(result);
// swap out thread state
if (session) {
//switch_core_session_rwunlock(session);
// record the fact that thread state is swapped in
switch_channel_t *channel = switch_core_session_get_channel(session);
PyThreadState *swapin_tstate = (PyThreadState *) switch_channel_get_private(channel, "SwapInThreadState");
......@@ -189,7 +198,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No session: Threadstate mod_python.c swap-out! \n");
PyEval_ReleaseThread(tstate);
}
switch_safe_free(dupargs);
......
......@@ -26,5 +26,3 @@
%include switch_swigable_cpp.h
%include freeswitch_python.h
SWITCH_BEGIN_EXTERN_C
PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, const char *name)
{
PyObject *obj;
Event *result = new Event(event, 0);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Event, SWIG_POINTER_OWN );
if (module && name) {
PyDict_SetItem(PyModule_GetDict(module), Py_BuildValue("s", name), obj);
Py_DECREF(obj);
}
return obj;
}
PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *stream, const char *name)
{
PyObject *obj;
Stream *result = new Stream(stream);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Stream, SWIG_POINTER_OWN );
if (module && name) {
PyDict_SetItem(PyModule_GetDict(module), Py_BuildValue("s", name), obj);
Py_DECREF(obj);
}
return obj;
}
PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session, const char *name)
{
PyObject *obj;
PYTHON::Session *result = new PYTHON::Session(session);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_PYTHON__Session, SWIG_POINTER_OWN);
result->setPython(module);
result->setSelf(obj);
if (module && name) {
PyDict_SetItem(PyModule_GetDict(module), Py_BuildValue("s", name), obj);
Py_DECREF(obj);
}
return obj;
}
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration)
{
PyObject *obj;
DTMF *result = new DTMF(digit, duration);
obj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_DTMF, SWIG_POINTER_OWN);
return obj;
}
SWITCH_END_EXTERN_C
#ifndef MOD_PYTHON_EXTRA
#define MOD_PYTHON_EXTRA
SWITCH_BEGIN_EXTERN_C
PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, const char *name);
PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *stream, const char *name);
PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session, const char *name);
PyObject *mod_python_conjure_DTMF(char digit, int32_t duration);
SWITCH_END_EXTERN_C
#endif
......@@ -367,6 +367,24 @@ SWITCH_DECLARE(const char *)Event::getType(void)
return (char *) "invalid";
}
SWITCH_DECLARE_CONSTRUCTOR DTMF::DTMF(char idigit, uint32_t iduration)
{
digit = idigit;
if (iduration == 0) {
iduration == SWITCH_DEFAULT_DTMF_DURATION;
}
duration = iduration;
}
SWITCH_DECLARE_CONSTRUCTOR DTMF::~DTMF()
{
}
SWITCH_DECLARE_CONSTRUCTOR Stream::Stream()
{
SWITCH_STANDARD_STREAM(mystream);
......@@ -457,8 +475,6 @@ SWITCH_DECLARE_CONSTRUCTOR CoreSession::~CoreSession()
}
switch_core_session_rwunlock(session);
}
}
SWITCH_DECLARE(char *) CoreSession::getXMLCDR()
......@@ -602,11 +618,6 @@ SWITCH_DECLARE(int) CoreSession::speak(char *text)
this_check(-1);
sanity_check(-1);
// create and store an empty filehandle in callback args
// to workaround a bug in the presumptuous process_callback_result()
switch_file_handle_t fh = { 0 };
store_file_handle(&fh);
if (!tts_name) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No TTS engine specified\n");
return SWITCH_STATUS_FALSE;
......@@ -793,13 +804,12 @@ SWITCH_DECLARE(int) CoreSession::streamFile(char *file, int starting_sample_coun
}
}
store_file_handle(&local_fh);
begin_allow_threads();
status = switch_ivr_play_file(session, fhp, file, ap);
end_allow_threads();
fhp = NULL;
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
......@@ -895,18 +905,22 @@ SWITCH_DECLARE(int) CoreSession::originate(CoreSession *a_leg_session, char *des
SWITCH_DECLARE(int) CoreSession::recordFile(char *file_name, int max_len, int silence_threshold, int silence_secs)
{
switch_file_handle_t fh = { 0 };
switch_status_t status;
this_check(-1);
sanity_check(-1);
fh.thresh = silence_threshold;
fh.silence_hits = silence_secs;
store_file_handle(&fh);
memset(&local_fh, 0, sizeof(local_fh));
fhp = &local_fh;
local_fh.thresh = silence_threshold;
local_fh.silence_hits = silence_secs;
begin_allow_threads();
status = switch_ivr_record_file(session, &fh, file_name, &args, max_len);
status = switch_ivr_record_file(session, &local_fh, file_name, &args, max_len);
end_allow_threads();
fhp = NULL;
return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
}
......@@ -1012,22 +1026,6 @@ SWITCH_DECLARE(void) CoreSession::setHangupHook(void *hangup_func) {
switch_core_event_hook_add_state_change(session, hanguphook);
}
/** \brief Store a file handle in the callback args
*
* In a few of the methods like playFile and streamfile,
* an empty switch_file_handle_t is created and passed
* to core, and stored in callback args so that the callback
* handler can retrieve it for pausing, ff, rewinding file ptr.
*
* \param fh - a switch_file_handle_t
*/
void CoreSession::store_file_handle(switch_file_handle_t *fh) {
cb_state.extra = fh; // set a file handle so callback handler can pause
args.buf = &cb_state;
ap = &args;
}
/* ---- methods not bound to CoreSession instance ---- */
SWITCH_DECLARE(void) consoleLog(char *level_str, char *msg)
......@@ -1137,13 +1135,6 @@ SWITCH_DECLARE(switch_status_t) CoreSession::process_callback_result(char *resul
if (fhp) {
fh = fhp;
} else {
if (!cb_state.extra) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Process callback result aborted because cb_state.extra is null\n");
return SWITCH_STATUS_FALSE;
}
fh = (switch_file_handle_t *) cb_state.extra;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论