[Freeswitch-svn] [commit] r3571 - in freeswitch/branches/jkr888/trunk: scripts src/mod/languages/mod_python

Freeswitch SVN jkr888 at freeswitch.org
Thu Dec 7 18:01:01 EST 2006


Author: jkr888
Date: Thu Dec  7 18:01:00 2006
New Revision: 3571

Modified:
   freeswitch/branches/jkr888/trunk/scripts/mytest.py
   freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/Makefile
   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

Log:


Modified: freeswitch/branches/jkr888/trunk/scripts/mytest.py
==============================================================================
--- freeswitch/branches/jkr888/trunk/scripts/mytest.py	(original)
+++ freeswitch/branches/jkr888/trunk/scripts/mytest.py	Thu Dec  7 18:01:00 2006
@@ -1,5 +1,5 @@
 import sys, time 
-from _freeswitch import *
+from freeswitch import *
 
 print "Hello World"
 print sys.path
@@ -7,28 +7,30 @@
 print sys.argv
 
 uuid = sys.argv[0]
-fs_console_log("1","test from my python program\n")
-fs_console_clean("This is fs_consol_clean\n")
-fs_console_clean("My uuid is " + uuid + "\n")
 
-session = fs_core_session_locate(uuid)
+newSession = SessionContainer(uuid)
 
-fs_channel_answer(session)
+newSession.console_log("1","test from my python program\n")
 
+newSession.console_clean_log("This is fs_consol_clean\n")
+newSession.console_clean_log("My uuid is " + uuid + "\n")
+
+newSession.answer()
+
 #fs_switch_ivr_session_transfer(session, "1234", "XML", "default")
-fs_ivr_play_file2(session, "/root/test.gsm")
+newSession.play_file("/root/test.gsm", "")
 
 #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.")
 
-fs_switch_ivr_speak_text(session, 
-                "cepstral",
-                "david",
-                None,
-                0, 
-                None,
-                "Welcome to my first python application",
-                None,
-                0)
+#fs_switch_ivr_speak_text(session, 
+#                "cepstral",
+#                "david",
+#                None,
+#                0, 
+#                None,
+#                "Welcome to my first python application",
+#                None,
+#                0)
 
-fs_channel_hangup(session, "")
+newSession.hangup("1")
 

Modified: freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/Makefile
==============================================================================
--- freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/Makefile	(original)
+++ freeswitch/branches/jkr888/trunk/src/mod/languages/mod_python/Makefile	Thu Dec  7 18:01:00 2006
@@ -1,11 +1,11 @@
 LCFLAGS=-fPIC
 CFLAGS += -fPIC -I$(PREFIX)/include/python2.4/
 PYMOD=freeswitch
-LDFLAGS=-lpython2.4 -Xlinker -export-dynamic -L$(PREFIX)/lib/python2.4/config/  -lutil
+LDFLAGS=-lpython2.4 -Xlinker -export-dynamic -L$(PREFIX)/lib/python2.4/config/  -lutil -lstdc++
 SWIGCFILE=../../../switch_swig.c
 SWIGIFILE=../../../switch_swig.i
 CPPCC = g++
-OBJS=freeswitch_python.o
+OBJS=freeswitch_python.o mod_python_wrap.o
 
 #all:	depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(PYMOD).$(DYNAMIC_LIB_EXTEN)
 all:	depends $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(OBJS) 
@@ -19,13 +19,13 @@
 %.o:  %.c
 	$(CC) $(LCFLAGS) $(CFLAGS) -c $< -o $@
 
-mod_python.c:
+od_python.c:
 	$(CC) $(LCFLAGS) $(CFLAGS) -c  mod_python.c -o mod_python.o
 
 reswig: 
 	# rm -f switch_swig_wrap.c config.m4 CREDITS *${PYMOD}*
 	# swig -o switch_swig_wrap.c -l$(SWIGIFILE) -ignoremissing -DMULTIPLICITY -python -module $(PYMOD) $(SWIGCFILE)
-	swig -python -shadow -c++ mod_python.i
+	swig -python -shadow -c++ -o mod_python_wrap.cpp mod_python.i
 	# patch -p0 -i fix.diff
 
 switch_swig_wrap.o: switch_swig_wrap.c Makefile
@@ -38,8 +38,11 @@
 # $(PYMOD).$(DYNAMIC_LIB_EXTEN): $(MODNAME).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o Makefile
 #	$(CC) $(SOLINK) -o py_$(PYMOD).$(DYNAMIC_LIB_EXTEN) switch_swig_wrap.o switch_swig.o $(LDFLAGS)
 
-$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) switch_swig_wrap.o switch_swig.o Makefile
-	$(CC) $(LCFLAGS) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN)  $(MODNAME).o switch_swig_wrap.o switch_swig.o $(OBJS) $(LDFLAGS)
+# $(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) switch_swig_wrap.o switch_swig.o Makefile
+#	$(CC) $(LCFLAGS) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN)  $(MODNAME).o switch_swig_wrap.o switch_swig.o $(OBJS) $(LDFLAGS)
+
+$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).c $(MODNAME).o $(OBJS) Makefile
+	$(CC) $(LCFLAGS) $(SOLINK) -o $(MODNAME).$(DYNAMIC_LIB_EXTEN)  $(MODNAME).o $(OBJS) $(LDFLAGS)
 
 clean:
 	rm -fr *.$(DYNAMIC_LIB_EXTEN) *.o *~

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	Thu Dec  7 18:01:00 2006
@@ -37,68 +37,40 @@
 
 
 
-fs_core_set_globals = _freeswitch.fs_core_set_globals
+PythonDTMFCallback = _freeswitch.PythonDTMFCallback
+class SessionContainer(_object):
+    __swig_setmethods__ = {}
+    __setattr__ = lambda self, name, value: _swig_setattr(self, SessionContainer, name, value)
+    __swig_getmethods__ = {}
+    __getattr__ = lambda self, name: _swig_getattr(self, SessionContainer, name)
+    def __repr__(self):
+        return "<%s.%s; proxy of C++ SessionContainer instance at %s>" % (self.__class__.__module__, self.__class__.__name__, self.this,)
+    def __init__(self, *args):
+        _swig_setattr(self, SessionContainer, 'this', _freeswitch.new_SessionContainer(*args))
+        _swig_setattr(self, SessionContainer, 'thisown', 1)
+    def __del__(self, destroy=_freeswitch.delete_SessionContainer):
+        try:
+            if self.thisown: destroy(self)
+        except: pass
 
-fs_core_init = _freeswitch.fs_core_init
+    def console_log(*args): return _freeswitch.SessionContainer_console_log(*args)
+    def console_clean_log(*args): return _freeswitch.SessionContainer_console_clean_log(*args)
+    def answer(*args): return _freeswitch.SessionContainer_answer(*args)
+    def pre_answer(*args): return _freeswitch.SessionContainer_pre_answer(*args)
+    def hangup(*args): return _freeswitch.SessionContainer_hangup(*args)
+    def set_variable(*args): return _freeswitch.SessionContainer_set_variable(*args)
+    def get_variable(*args): return _freeswitch.SessionContainer_get_variable(*args)
+    def set_state(*args): return _freeswitch.SessionContainer_set_state(*args)
+    def play_file(*args): return _freeswitch.SessionContainer_play_file(*args)
+    def set_dtmf_callback(*args): return _freeswitch.SessionContainer_set_dtmf_callback(*args)
 
-fs_core_destroy = _freeswitch.fs_core_destroy
+class SessionContainerPtr(SessionContainer):
+    def __init__(self, this):
+        _swig_setattr(self, SessionContainer, 'this', this)
+        if not hasattr(self,"thisown"): _swig_setattr(self, SessionContainer, 'thisown', 0)
+        self.__class__ = SessionContainer
+_freeswitch.SessionContainer_swigregister(SessionContainerPtr)
+cvar = _freeswitch.cvar
 
-fs_loadable_module_init = _freeswitch.fs_loadable_module_init
-
-fs_loadable_module_shutdown = _freeswitch.fs_loadable_module_shutdown
-
-fs_console_loop = _freeswitch.fs_console_loop
-
-fs_console_log = _freeswitch.fs_console_log
-
-fs_console_clean = _freeswitch.fs_console_clean
-
-fs_core_session_locate = _freeswitch.fs_core_session_locate
-
-fs_channel_answer = _freeswitch.fs_channel_answer
-
-fs_channel_pre_answer = _freeswitch.fs_channel_pre_answer
-
-fs_channel_hangup = _freeswitch.fs_channel_hangup
-
-fs_channel_set_variable = _freeswitch.fs_channel_set_variable
-
-fs_channel_get_variable = _freeswitch.fs_channel_get_variable
-
-fs_channel_set_state = _freeswitch.fs_channel_set_state
-
-fs_ivr_play_file = _freeswitch.fs_ivr_play_file
-
-fs_switch_ivr_record_file = _freeswitch.fs_switch_ivr_record_file
-
-fs_switch_ivr_sleep = _freeswitch.fs_switch_ivr_sleep
-
-fs_ivr_play_file2 = _freeswitch.fs_ivr_play_file2
-
-fs_switch_ivr_collect_digits_callback = _freeswitch.fs_switch_ivr_collect_digits_callback
-
-fs_switch_ivr_collect_digits_count = _freeswitch.fs_switch_ivr_collect_digits_count
-
-fs_switch_ivr_originate = _freeswitch.fs_switch_ivr_originate
-
-fs_switch_ivr_session_transfer = _freeswitch.fs_switch_ivr_session_transfer
-
-fs_switch_ivr_speak_text = _freeswitch.fs_switch_ivr_speak_text
-
-fs_switch_ivr_speak_text2 = _freeswitch.fs_switch_ivr_speak_text2
-
-fs_switch_channel_get_variable = _freeswitch.fs_switch_channel_get_variable
-
-fs_switch_channel_set_variable = _freeswitch.fs_switch_channel_set_variable
-CS_NEW = _freeswitch.CS_NEW
-CS_INIT = _freeswitch.CS_INIT
-CS_RING = _freeswitch.CS_RING
-CS_TRANSMIT = _freeswitch.CS_TRANSMIT
-CS_EXECUTE = _freeswitch.CS_EXECUTE
-CS_LOOPBACK = _freeswitch.CS_LOOPBACK
-CS_HOLD = _freeswitch.CS_HOLD
-CS_HIBERNATE = _freeswitch.CS_HIBERNATE
-CS_HANGUP = _freeswitch.CS_HANGUP
-CS_DONE = _freeswitch.CS_DONE
 
 

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	Thu Dec  7 18:01:00 2006
@@ -3,6 +3,7 @@
 SessionContainer::SessionContainer(char *nuuid)
 {
     uuid = nuuid;
+    dtmfCallbackFunction = NULL;
     if ((session = switch_core_session_locate(uuid))) {
         switch_core_session_rwunlock(session);
         channel = switch_core_session_get_channel(session);
@@ -59,6 +60,36 @@
 
     if ((current_state = switch_channel_name_state(state)) < CS_HANGUP) {
         switch_channel_set_state(channel, current_state);
+    }
+}
+
+int SessionContainer::play_file(char *file, char *timer_name)
+{
+    switch_status_t status;
+    if (switch_strlen_zero(timer_name)) {
+        timer_name = NULL;
+    }
+
+    if (!dtmfCallbackFunction) {
+        status = switch_ivr_play_file(session, NULL, file, timer_name, NULL, NULL, 0);
+    } 
+    else {
+        globalDTMFCallBackFunction = dtmfCallbackFunction;
+        status = switch_ivr_play_file(session, NULL, file, timer_name, PythonDTMFCallback, NULL, 0);
+    }
+
+    return status == SWITCH_STATUS_SUCCESS ? 1 : 0;
+
+}
+
+void SessionContainer::set_dtmf_callback(PyObject *pyfunc)
+{
+    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;
     }
 }
 

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	Thu Dec  7 18:01:00 2006
@@ -1,14 +1,24 @@
+#include <Python.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #include <switch.h>
 
+void *globalDTMFCallBackFunction = NULL;
+extern switch_status_t PythonDTMFCallback(switch_core_session *session, 
+                                    void *input, 
+                                    switch_input_type_t itype,
+                                    void *buf,
+                                    unsigned int buflen);
+
 class SessionContainer {
     private:
         switch_core_session_t *session;
         switch_channel_t *channel;
         char *uuid;
+        PyObject *dtmfCallbackFunction;
     public:
         SessionContainer(char *uuid);
         ~SessionContainer();
@@ -20,6 +30,8 @@
         void set_variable(char *var, char *val);
         void get_variable(char *var, char *val);
         void set_state(char *state);
+        int  play_file(char *file, char *timer_name);
+        void set_dtmf_callback(PyObject *pyfunc);
     protected:
 };
 



More information about the Freeswitch-svn mailing list