[Freeswitch-svn] [commit] r5203 - freeswitch/branches/greenlizard/src/mod/languages/mod_python

Freeswitch SVN greenlizard at freeswitch.org
Thu May 17 19:01:23 EDT 2007


Author: greenlizard
Date: Thu May 17 19:01:23 2007
New Revision: 5203

Modified:
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
   freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp

Log:
remove set_dtmf_handler which no longer works and is not present in javascript either, fix bug which segfaults when the python dtmf handler returns None.  now compares returned value with Py_None

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch.py	Thu May 17 19:01:23 2007
@@ -127,7 +127,6 @@
     __swig_destroy__ = _freeswitch.delete_PySession
     __del__ = lambda self : None;
     def streamfile(*args): return _freeswitch.PySession_streamfile(*args)
-    def set_dtmf_callback(*args): return _freeswitch.PySession_set_dtmf_callback(*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)
 PySession_swigregister = _freeswitch.PySession_swigregister

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.cpp	Thu May 17 19:01:23 2007
@@ -2,17 +2,6 @@
 
 #define sanity_check(x) do { if (!session) { switch_log_printf(SWITCH_CHANNEL_LOG,SWITCH_LOG_ERROR, "session is not initalized\n"); return x;}} while(0)
 
-void PySession::set_dtmf_callback(PyObject *pyfunc)
-{
-	sanity_check();
-    if (!PyCallable_Check(pyfunc)) {
-        dtmfCallbackFunction = NULL;
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF function is not a python function.");
-    }       
-    else {
-        dtmfCallbackFunction = pyfunc;
-    }
-}
 
 int PySession::streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count)
 {
@@ -27,14 +16,13 @@
 
     if (!PyCallable_Check(pyfunc)) {
         dtmfCallbackFunction = NULL;
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF function is not a python function.");
+        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "DTMF function is not a python function.");
     }       
     else {
         dtmfCallbackFunction = pyfunc;
     }
 
     if (dtmfCallbackFunction) {
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Setting DTMF callback\n");
 	cb_state.function = dtmfCallbackFunction;
 	cb_state.extra = &fh;
 	args.buf = &cb_state; 
@@ -42,9 +30,6 @@
         args.input_callback = PythonDTMFCallback;  // defined in mod_python.i, will use ptrs in cb_state
 	ap = &args;
     }
-    else {
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NOT Setting DTMF callback\n");
-    }
 
 
     this->begin_allow_threads();
@@ -59,12 +44,10 @@
 
 void PySession::begin_allow_threads(void) { 
     threadState = PyEval_SaveThread();
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Py_BEGIN_ALLOW_THREADS\n");
 }
 
 void PySession::end_allow_threads(void) { 
     PyEval_RestoreThread(threadState);
-    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Py_END_ALLOW_THREADS\n");
 }
 
 PySession::~PySession() {

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/freeswitch_python.h	Thu May 17 19:01:23 2007
@@ -42,7 +42,6 @@
 	PySession(switch_core_session_t *session) : CoreSession(session) {};
 	~PySession();        
 	int streamfile(char *file, PyObject *pyfunc, char *funcargs, int starting_sample_count);
-	void set_dtmf_callback(PyObject *pyfunc);
 	void begin_allow_threads();
 	void end_allow_threads();
 

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python.i	Thu May 17 19:01:23 2007
@@ -65,13 +65,17 @@
    result = PyEval_CallObject(func, arglist);    
    threadState = PyEval_SaveThread();  
 
+
    Py_DECREF(arglist);                           // Trash arglist
-   if (result) {                       
+   if (result && result != Py_None) {                       
      resultStr = (char *) PyString_AsString(result);
+     Py_XDECREF(result);
+     return process_callback_result(resultStr, cb_state, session);
+   }
+   else {
+     return SWITCH_STATUS_FALSE;	
    }
-   Py_XDECREF(result);
 
-   return process_callback_result(resultStr, cb_state, session);
 
 }
 
@@ -84,6 +88,11 @@
     switch_file_handle_t *fh = NULL;	   
     fh = (switch_file_handle_t *) cb_state->extra;    
 
+
+    if (!ret) {
+	return SWITCH_STATUS_FALSE;	
+    }
+
     if (!strncasecmp(ret, "speed", 4)) {
 	char *p;
 
@@ -111,6 +120,8 @@
 	    switch_set_flag(fh, SWITCH_FILE_PAUSE);
 	}
 	return SWITCH_STATUS_SUCCESS;
+    } else if (!strcasecmp(ret, "stop")) {
+	return SWITCH_STATUS_FALSE;
     } else if (!strcasecmp(ret, "restart")) {
 	unsigned int pos = 0;
 	fh->speed = 0;

Modified: freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp	(original)
+++ freeswitch/branches/greenlizard/src/mod/languages/mod_python/mod_python_wrap.cpp	Thu May 17 19:01:23 2007
@@ -2927,13 +2927,17 @@
    result = PyEval_CallObject(func, arglist);    
    threadState = PyEval_SaveThread();  
 
+
    Py_DECREF(arglist);                           // Trash arglist
-   if (result) {                       
+   if (result && result != Py_None) {                       
      resultStr = (char *) PyString_AsString(result);
+     Py_XDECREF(result);
+     return process_callback_result(resultStr, cb_state, session);
+   }
+   else {
+     return SWITCH_STATUS_FALSE;	
    }
-   Py_XDECREF(result);
 
-   return process_callback_result(resultStr, cb_state, session);
 
 }
 
@@ -2946,6 +2950,11 @@
     switch_file_handle_t *fh = NULL;	   
     fh = (switch_file_handle_t *) cb_state->extra;    
 
+
+    if (!ret) {
+	return SWITCH_STATUS_FALSE;	
+    }
+
     if (!strncasecmp(ret, "speed", 4)) {
 	char *p;
 
@@ -2973,6 +2982,10 @@
 	    switch_set_flag(fh, SWITCH_FILE_PAUSE);
 	}
 	return SWITCH_STATUS_SUCCESS;
+    } else if (!strcasecmp(ret, "stop")) {
+	return SWITCH_STATUS_FALSE;
+    } else if (!strcasecmp(ret, "hangup")) {
+	return SWITCH_STATUS_BREAK; 
     } else if (!strcasecmp(ret, "restart")) {
 	unsigned int pos = 0;
 	fh->speed = 0;
@@ -4672,30 +4685,6 @@
 }
 
 
-SWIGINTERN PyObject *_wrap_PySession_set_dtmf_callback(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  PySession *arg1 = (PySession *) 0 ;
-  PyObject *arg2 = (PyObject *) 0 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  PyObject * obj0 = 0 ;
-  PyObject * obj1 = 0 ;
-  
-  if (!PyArg_ParseTuple(args,(char *)"OO:PySession_set_dtmf_callback",&obj0,&obj1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_PySession, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "PySession_set_dtmf_callback" "', argument " "1"" of type '" "PySession *""'"); 
-  }
-  arg1 = reinterpret_cast< PySession * >(argp1);
-  arg2 = obj1;
-  (arg1)->set_dtmf_callback(arg2);
-  resultobj = SWIG_Py_Void();
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
 SWIGINTERN PyObject *_wrap_PySession_begin_allow_threads(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   PySession *arg1 = (PySession *) 0 ;
@@ -4789,7 +4778,6 @@
 	 { (char *)"new_PySession", _wrap_new_PySession, METH_VARARGS, NULL},
 	 { (char *)"delete_PySession", _wrap_delete_PySession, METH_VARARGS, NULL},
 	 { (char *)"PySession_streamfile", _wrap_PySession_streamfile, METH_VARARGS, NULL},
-	 { (char *)"PySession_set_dtmf_callback", _wrap_PySession_set_dtmf_callback, METH_VARARGS, NULL},
 	 { (char *)"PySession_begin_allow_threads", _wrap_PySession_begin_allow_threads, METH_VARARGS, NULL},
 	 { (char *)"PySession_end_allow_threads", _wrap_PySession_end_allow_threads, METH_VARARGS, NULL},
 	 { (char *)"PySession_swigregister", PySession_swigregister, METH_VARARGS, NULL},



More information about the Freeswitch-svn mailing list