[Freeswitch-branches] [commit] r3632 - in freeswitch/branches/jkr888/trunk: scripts src/mod/languages/mod_python
Freeswitch SVN
jkr888 at freeswitch.org
Tue Dec 12 18:11:13 EST 2006
Author: jkr888
Date: Tue Dec 12 18:11:11 2006
New Revision: 3632
Modified:
freeswitch/branches/jkr888/trunk/scripts/mytest.py
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i
freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
Log:
Modified: freeswitch/branches/jkr888/trunk/scripts/mytest.py
==============================================================================
--- freeswitch/branches/jkr888/trunk/scripts/mytest.py (original)
+++ freeswitch/branches/jkr888/trunk/scripts/mytest.py Tue Dec 12 18:11:11 2006
@@ -1,20 +1,16 @@
-import sys, time
from freeswitch import *
+import sys, time
-loop = 1
-
-def DTMFscanner(input, itype, buf, buflen):
+def onDTMF(input, itype, buf, buflen):
print "input=",input
print "itype=",itype
print "buf=",buf
print "buflen",buflen
- return 0
+ if input == "#":
+ return 1
+ else:
+ return 0
-print "Hello World"
-print sys.path
-print dir()
-print sys.argv
-
uuid = sys.argv[0]
newSession = SessionContainer(uuid)
@@ -25,24 +21,17 @@
newSession.console_clean_log("My uuid is " + uuid + "\n")
newSession.answer()
-newSession.set_dtmf_callback(DTMFscanner)
+newSession.set_dtmf_callback(onDTMF)
newSession.set_tts_parms("cepstral", "david")
-#fs_switch_ivr_session_transfer(session, "1234", "XML", "default")
newSession.play_file("/root/test.gsm", "")
+newSession.speak_text("Please enter telephone number with area code and press pound sign. ")
-#fs_switch_ivr_speak_text2(session, "cepstral", "david", "<break time='1s' />Welcome to my first python scripts running from <emphasis level='strong'>free switch </emphasis>application.")
-newSession.speak_text("The first of Europe's gamers got their hands on Nintendo's new video-game console on Friday after stores across the continent opened their doors at midnight to end die-hard fans long wait for a Wii.")
+input = newSession.get_digits("", 11, "*#", 10000)
-#fs_switch_ivr_speak_text(session,
-# "cepstral",
-# "david",
-# None,
-# 0,
-# None,
-# "Welcome to my first python application",
-# None,
-# 0)
+newSession.console_log("1","result from get digits is "+ input +"\n")
-newSession.hangup("1")
+newSession.transfer("1000", "XML", "default")
+
+#newSession.hangup("1")
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch.py Tue Dec 12 18:11:11 2006
@@ -65,6 +65,8 @@
def set_dtmf_callback(*args): return _freeswitch.SessionContainer_set_dtmf_callback(*args)
def speak_text(*args): return _freeswitch.SessionContainer_speak_text(*args)
def set_tts_parms(*args): return _freeswitch.SessionContainer_set_tts_parms(*args)
+ def get_digits(*args): return _freeswitch.SessionContainer_get_digits(*args)
+ def transfer(*args): return _freeswitch.SessionContainer_transfer(*args)
class SessionContainerPtr(SessionContainer):
def __init__(self, this):
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.cpp Tue Dec 12 18:11:11 2006
@@ -117,3 +117,19 @@
tts_name = tts_name_p;
voice_name = voice_name_p;
}
+
+void SessionContainer::get_digits(char *dtmf_buf, int len, char *terminators, int timeout)
+{
+ char terminator;
+
+ switch_ivr_collect_digits_count(session, dtmf_buf,(uint32_t) len,(uint32_t) len, terminators, &terminator, (uint32_t) timeout);
+
+}
+
+void SessionContainer::transfer(char *extension, char *dialplan, char *context)
+{
+ switch_ivr_session_transfer(session, extension, dialplan, context);
+}
+
+
+
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/freeswitch_python.h Tue Dec 12 18:11:11 2006
@@ -39,6 +39,8 @@
void set_dtmf_callback(PyObject *pyfunc);
int speak_text(char *text);
void set_tts_parms(char *tts_name, char *voice_name);
+ void get_digits(char *dtmf_buf, int len, char *terminators, int timeout);
+ void transfer(char *extensions, char *dialplan, char *context);
protected:
};
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python.i Tue Dec 12 18:11:11 2006
@@ -1,4 +1,8 @@
%module freeswitch
+%include "cstring.i"
+
+%cstring_bounded_mutable(char *dtmf_buf, 128);
+
%{
#include "freeswitch_python.h"
%}
Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp (original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp Tue Dec 12 18:11:11 2006
@@ -1604,7 +1604,146 @@
/*@@*/
+SWIGINTERN int
+ SWIG_CheckLongInRange(long value, long min_value, long max_value,
+ const char *errmsg)
+{
+ if (value < min_value) {
+ if (errmsg) {
+ PyErr_Format(PyExc_OverflowError,
+ "value %ld is less than '%s' minimum %ld",
+ value, errmsg, min_value);
+ }
+ return 0;
+ } else if (value > max_value) {
+ if (errmsg) {
+ PyErr_Format(PyExc_OverflowError,
+ "value %ld is greater than '%s' maximum %ld",
+ value, errmsg, max_value);
+ }
+ return 0;
+ }
+ return 1;
+}
+
+SWIGINTERN int
+ SWIG_AsVal_long(PyObject * obj, long* val)
+{
+ if (PyLong_Check(obj)) {
+ long v = PyLong_AsLong(obj);
+ if (!PyErr_Occurred()) {
+ if (val) *val = v;
+ return 1;
+ } else {
+ if (!val) PyErr_Clear();
+ return 0;
+ }
+ }
+ if (PyInt_Check(obj)) {
+ if (val) *val = PyInt_AsLong(obj);
+ return 1;
+ }
+ if (val) {
+ SWIG_type_error("long", obj);
+ }
+ return 0;
+ }
+
+
+#if INT_MAX != LONG_MAX
+SWIGINTERN int
+ SWIG_AsVal_int(PyObject *obj, int *val)
+{
+ const char* errmsg = val ? "int" : (char*)0;
+ long v;
+ if (SWIG_AsVal_long(obj, &v)) {
+ if (SWIG_CheckLongInRange(v, INT_MIN,INT_MAX, errmsg)) {
+ if (val) *val = static_cast<int >(v);
+ return 1;
+ } else {
+ return 0;
+ }
+ } else {
+ PyErr_Clear();
+ }
+ if (val) {
+ SWIG_type_error(errmsg, obj);
+ }
+ return 0;
+}
+#else
+SWIGINTERNINLINE int
+ SWIG_AsVal_int(PyObject *obj, int *val)
+{
+ return SWIG_AsVal_long(obj,(long*)val);
+}
+#endif
+
+
+SWIGINTERNINLINE int
+SWIG_As_int(PyObject* obj)
+{
+ int v;
+ if (!SWIG_AsVal_int(obj, &v)) {
+ /*
+ this is needed to make valgrind/purify happier.
+ */
+ memset((void*)&v, 0, sizeof(int));
+ }
+ return v;
+}
+
+
+SWIGINTERNINLINE int
+SWIG_Check_int(PyObject* obj)
+{
+ return SWIG_AsVal_int(obj, (int*)0);
+}
+
+
+SWIGINTERN PyObject*
+t_output_helper(PyObject* target, PyObject* o) {
+ if (!target) {
+ target = o;
+ } else if (target == Py_None) {
+ Py_DECREF(target);
+ target = o;
+ } else {
+ if (!PyList_Check(target)) {
+ PyObject *o2 = target;
+ target = PyList_New(1);
+ PyList_SetItem(target, 0, o2);
+ }
+ PyList_Append(target,o);
+ Py_DECREF(o);
+ }
+ return target;
+}
+
+
+SWIGINTERN PyObject *
+SWIG_FromCharPtr(const char* cptr)
+{
+ if (cptr) {
+ size_t size = strlen(cptr);
+ if (size > INT_MAX) {
+ return SWIG_NewPointerObj(const_cast<char* >(cptr),
+ SWIG_TypeQuery("char *"), 0);
+ } else {
+ if (size != 0) {
+ return PyString_FromStringAndSize(cptr, size);
+ } else {
+ return PyString_FromString(cptr);
+ }
+ }
+ }
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+
+
switch_status_t PythonDTMFCallback(switch_core_session_t *session,
void *input,
switch_input_type_t itype,
@@ -2025,6 +2164,85 @@
}
+static PyObject *_wrap_SessionContainer_get_digits(PyObject *, PyObject *args) {
+ PyObject *resultobj = NULL;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *arg2 = (char *) 0 ;
+ int arg3 ;
+ char *arg4 = (char *) 0 ;
+ int arg5 ;
+ char temp2[128+1] ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+ PyObject * obj3 = 0 ;
+ PyObject * obj4 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"OOOOO:SessionContainer_get_digits",&obj0,&obj1,&obj2,&obj3,&obj4)) goto fail;
+ SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_SessionContainer, SWIG_POINTER_EXCEPTION | 0);
+ if (SWIG_arg_fail(1)) SWIG_fail;
+ {
+ char *t = 0; size_t n;
+ SWIG_AsCharPtrAndSize(obj1, &t, &n);
+ if (SWIG_arg_fail(2)) SWIG_fail;
+ if ( n > (size_t)128 ) n = (size_t)128;
+ memcpy(temp2, t, sizeof(char)*n);
+ temp2[n] = 0;
+ arg2 = (char *) temp2;
+ }
+ {
+ arg3 = static_cast<int >(SWIG_As_int(obj2));
+ if (SWIG_arg_fail(3)) SWIG_fail;
+ }
+ if (!SWIG_AsCharPtr(obj3, (char**)&arg4)) {
+ SWIG_arg_fail(4);SWIG_fail;
+ }
+ {
+ arg5 = static_cast<int >(SWIG_As_int(obj4));
+ if (SWIG_arg_fail(5)) SWIG_fail;
+ }
+ (arg1)->get_digits(arg2,arg3,arg4,arg5);
+
+ Py_INCREF(Py_None); resultobj = Py_None;
+ arg2[128] = 0; resultobj = t_output_helper(resultobj, SWIG_FromCharPtr(arg2));
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
+static PyObject *_wrap_SessionContainer_transfer(PyObject *, PyObject *args) {
+ PyObject *resultobj = NULL;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *arg2 = (char *) 0 ;
+ char *arg3 = (char *) 0 ;
+ char *arg4 = (char *) 0 ;
+ PyObject * obj0 = 0 ;
+ PyObject * obj1 = 0 ;
+ PyObject * obj2 = 0 ;
+ PyObject * obj3 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"OOOO:SessionContainer_transfer",&obj0,&obj1,&obj2,&obj3)) goto fail;
+ SWIG_Python_ConvertPtr(obj0, (void **)&arg1, SWIGTYPE_p_SessionContainer, SWIG_POINTER_EXCEPTION | 0);
+ if (SWIG_arg_fail(1)) SWIG_fail;
+ if (!SWIG_AsCharPtr(obj1, (char**)&arg2)) {
+ SWIG_arg_fail(2);SWIG_fail;
+ }
+ if (!SWIG_AsCharPtr(obj2, (char**)&arg3)) {
+ SWIG_arg_fail(3);SWIG_fail;
+ }
+ if (!SWIG_AsCharPtr(obj3, (char**)&arg4)) {
+ SWIG_arg_fail(4);SWIG_fail;
+ }
+ (arg1)->transfer(arg2,arg3,arg4);
+
+ Py_INCREF(Py_None); resultobj = Py_None;
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
static PyObject * SessionContainer_swigregister(PyObject *, PyObject *args) {
PyObject *obj;
if (!PyArg_ParseTuple(args,(char*)"O", &obj)) return NULL;
@@ -2048,6 +2266,8 @@
{ (char *)"SessionContainer_set_dtmf_callback", _wrap_SessionContainer_set_dtmf_callback, METH_VARARGS, NULL},
{ (char *)"SessionContainer_speak_text", _wrap_SessionContainer_speak_text, METH_VARARGS, NULL},
{ (char *)"SessionContainer_set_tts_parms", _wrap_SessionContainer_set_tts_parms, METH_VARARGS, NULL},
+ { (char *)"SessionContainer_get_digits", _wrap_SessionContainer_get_digits, METH_VARARGS, NULL},
+ { (char *)"SessionContainer_transfer", _wrap_SessionContainer_transfer, METH_VARARGS, NULL},
{ (char *)"SessionContainer_swigregister", SessionContainer_swigregister, METH_VARARGS, NULL},
{ NULL, NULL, 0, NULL }
};
More information about the Freeswitch-branches
mailing list