[Freeswitch-svn] [commit] r9051 - freeswitch/trunk/src/mod/languages/mod_python

Freeswitch SVN anthm at freeswitch.org
Wed Jul 16 10:58:01 EDT 2008


Author: anthm
Date: Wed Jul 16 10:58:00 2008
New Revision: 9051

Added:
   freeswitch/trunk/src/mod/languages/mod_python/python_example.py
Modified:
   freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py
   freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
   freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
   freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c
   freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h
   freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp

Log:
fix the evil snake (again)

Modified: freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py	Wed Jul 16 10:58:00 2008
@@ -246,6 +246,15 @@
     __swig_setmethods__["hook_state"] = _freeswitch.CoreSession_hook_state_set
     __swig_getmethods__["hook_state"] = _freeswitch.CoreSession_hook_state_get
     if _newclass:hook_state = _swig_property(_freeswitch.CoreSession_hook_state_get, _freeswitch.CoreSession_hook_state_set)
+    __swig_setmethods__["uuid"] = _freeswitch.CoreSession_uuid_set
+    __swig_getmethods__["uuid"] = _freeswitch.CoreSession_uuid_get
+    if _newclass:uuid = _swig_property(_freeswitch.CoreSession_uuid_get, _freeswitch.CoreSession_uuid_set)
+    __swig_setmethods__["tts_name"] = _freeswitch.CoreSession_tts_name_set
+    __swig_getmethods__["tts_name"] = _freeswitch.CoreSession_tts_name_get
+    if _newclass:tts_name = _swig_property(_freeswitch.CoreSession_tts_name_get, _freeswitch.CoreSession_tts_name_set)
+    __swig_setmethods__["voice_name"] = _freeswitch.CoreSession_voice_name_set
+    __swig_getmethods__["voice_name"] = _freeswitch.CoreSession_voice_name_get
+    if _newclass:voice_name = _swig_property(_freeswitch.CoreSession_voice_name_get, _freeswitch.CoreSession_voice_name_set)
     def answer(*args): return _freeswitch.CoreSession_answer(*args)
     def preAnswer(*args): return _freeswitch.CoreSession_preAnswer(*args)
     def hangup(*args): return _freeswitch.CoreSession_hangup(*args)

Modified: freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.cpp	Wed Jul 16 10:58:00 2008
@@ -28,27 +28,27 @@
 		if (session) {
 			switch_core_event_hook_remove_state_change(session, python_hanguphook);
 		}
-		Py_XDECREF(hangup_func);
+		Py_DECREF(hangup_func);
 		hangup_func = NULL;
 	}
 	
 	if (hangup_func_arg) {
-		Py_XDECREF(hangup_func_arg);
+		Py_DECREF(hangup_func_arg);
 		hangup_func_arg = NULL;
 	}
 
 	if (cb_function) {
-		Py_XDECREF(cb_function);
+		Py_DECREF(cb_function);
 		cb_function = NULL;
 	}
 
 	if (cb_arg) {
-		Py_XDECREF(cb_arg);
+		Py_DECREF(cb_arg);
 		cb_arg = NULL;
 	}
 
 	if (Self) {
-		Py_XDECREF(Self);
+		Py_DECREF(Self);
 	}
 }
 
@@ -136,7 +136,7 @@
 			}
 
 			if (!Self) {
-				mod_python_conjure_session(NULL, session, NULL);
+				mod_python_conjure_session(NULL, session);
 			}
 			
 			if (hangup_func_arg) {
@@ -266,14 +266,14 @@
 		what = "dtmf";
 	} else if (itype == SWITCH_INPUT_TYPE_EVENT){
 		what = "event";
-		io = mod_python_conjure_event(NULL, (switch_event_t *) input, NULL);
+		io = mod_python_conjure_event((switch_event_t *) input);
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "unsupported type!\n");
 		return SWITCH_STATUS_FALSE;
 	}
 
 	if (!Self) {
-		mod_python_conjure_session(NULL, session, NULL);
+		mod_python_conjure_session(NULL, session);
 	}
 	
 	if (cb_arg) {

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python.c	Wed Jul 16 10:58:00 2008
@@ -62,11 +62,11 @@
 } globals;
 
 
-static void eval_some_python(char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params, char **str)
+static void eval_some_python(const char *funcname, char *args, switch_core_session_t *session, switch_stream_handle_t *stream, switch_event_t *params, char **str)
 {
 	PyThreadState *tstate = NULL;
 	char *dupargs = NULL;
-	char *argv[128] = { 0 };
+	char *argv[2] = { 0 };
 	int argc;
 	int lead = 0;
 	char *script = NULL;
@@ -74,7 +74,8 @@
 	PyObject *function = NULL;
 	PyObject *arg = NULL;
 	PyObject *result = NULL;
-	char *uuid = NULL;
+	switch_channel_t *channel = NULL;
+	char *p;
 
 	if (str) {
 		*str = NULL;
@@ -93,11 +94,20 @@
 		goto done;
 	}
 
-	script = argv[0];
+	script = strdup(switch_str_nil(argv[0]));
+	
 	lead = 1;
 
-	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invoking py module: %s\n", script);
+	if ((p = strstr(script, "::"))) {
+		*p = '\0';
+		p += 2;
+		if (p) {
+			funcname = p;
+		}
+	}
 
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Invoking py module: %s\n", script);
+	
 	tstate = PyThreadState_New(mainThreadState->interp);
 	if (!tstate) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "error acquiring tstate\n");
@@ -105,12 +115,6 @@
 	}
 	// swap in thread state
 	PyEval_AcquireThread(tstate);
-	if (session) {
-		uuid = switch_core_session_get_uuid(session);
-		// record the fact that thread state is swapped in
-		switch_channel_t *channel = switch_core_session_get_channel(session);
-		switch_channel_set_private(channel, "SwapInThreadState", NULL);
-	}
 	init_freeswitch();
 
 	// import the module
@@ -130,50 +134,48 @@
 		goto done_swap_out;
 	}
 
-	if (params) {
-		eve = mod_python_conjure_event(module, params, "params");
-	}
-
-	if (stream) {
-		stp = mod_python_conjure_stream(module, stream, "stream");
-		if (stream->param_event) {
-			eve = mod_python_conjure_event(module, stream->param_event, "env");
-		}
-	}
-
 	// get the handler function to be called
-	function = PyObject_GetAttrString(module, "handler");
+	function = PyObject_GetAttrString(module, (char *)funcname);
 	if (!function) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define handler(uuid)\n");
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Module does not define %s\n", funcname);
 		PyErr_Print();
 		PyErr_Clear();
 		goto done_swap_out;
 	}
 
-	if (uuid) {
-		// build a tuple to pass the args, the uuid of session
-		arg = Py_BuildValue("(s)", uuid);
-		if (!arg) {
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error building args\n");
-			PyErr_Print();
-			PyErr_Clear();
-			goto done_swap_out;
-		}
-	} else {
-		arg = PyTuple_New(1);
-		PyObject *nada = Py_BuildValue("");
-		PyTuple_SetItem(arg, 0, nada);
+	if (session) {
+		channel = switch_core_session_get_channel(session);
+		sp = mod_python_conjure_session(module, session);
 	}
 
-	if (session) {
-		sp = mod_python_conjure_session(module, session, "session");
+	if (params) {
+		eve = mod_python_conjure_event(params);
+	}
+
+	if (stream) {
+		stp = mod_python_conjure_stream(stream);
+		if (stream->param_event) {
+			eve = mod_python_conjure_event(stream->param_event);
+		}
 	}
 
+	if (sp && eve && stp) {
+		arg = Py_BuildValue("(OOOs)", sp, stp, eve, switch_str_nil(argv[1]));
+	} else if (eve && stp) {
+		arg = Py_BuildValue("(sOOs)", "na", stp, eve, switch_str_nil(argv[1]));
+	} else if (eve) {
+		arg = Py_BuildValue("(Os)", eve, switch_str_nil(argv[1]));
+	} else if (sp) {
+		arg = Py_BuildValue("(Os)", sp, switch_str_nil(argv[1]));
+	} else {
+		arg = Py_BuildValue("(s)", switch_str_nil(argv[1]));
+	}
+	
 	// invoke the handler 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Call python script \n");
 	result = PyEval_CallObjectWithKeywords(function, arg, (PyObject *) NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Finished calling python script \n");
-
+	
 	// check the result and print out any errors
 	if (result) {
 		if (str) {
@@ -183,44 +185,26 @@
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error calling python script\n");
 		PyErr_Print();
 		PyErr_Clear();
+		PyRun_SimpleString("python_makes_sense");
+		PyGC_Collect();
 	}
-	
- done:
+
  done_swap_out:
+
+	if (arg) {
+		Py_DECREF(arg);
+	}
 	
 	if (sp) {
-		Py_XDECREF(sp);
+		Py_DECREF(sp);
 	}
-
-    // 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");
-        // so lets assume nothing in the python script swapped any thread state in
-        // or out .. thread state will currently be swapped in, and the SwapInThreadState
-        // will be null
-        if (swapin_tstate == NULL) {
-            // clear out threadstate
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "clear threadstate \n");
-            // we know we are swapped in because swapin_tstate is NULL, and therefore we have the GIL, so
-            // it is safe to call PyThreadState_Get.
-            PyThreadState *cur_tstate = PyThreadState_Get();
-            PyThreadState_Clear(cur_tstate);
-            PyEval_ReleaseThread(cur_tstate);
-            PyThreadState_Delete(cur_tstate);
-        } else {
-            // thread state is already swapped out, so, nothing for us to do
-            switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "according to chan priv data, already swapped out \n");
-        }
-    } else {
-        // they ran python script from cmd line, behave a bit differently (untested)
-        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "No session: Threadstate mod_python.c swap-out! \n");
-        PyEval_ReleaseThread(tstate);
-    }
-
 	
+	if (tstate) {
+		PyEval_ReleaseThread(tstate);
+	}
+	
+ done:
+
 	switch_safe_free(dupargs);
 
 
@@ -239,7 +223,7 @@
 
 		switch_assert(mycmd);
 
-		eval_some_python(mycmd, NULL, NULL, params, &str);
+		eval_some_python("xml_fetch", mycmd, NULL, NULL, params, &str);
 
 		if (str) {
 			if (switch_strlen_zero(str)) {
@@ -290,7 +274,7 @@
 
 SWITCH_STANDARD_APP(python_function)
 {
-	eval_some_python((char *) data, session, NULL, NULL, NULL);
+	eval_some_python("handler", (char *) data, session, NULL, NULL, NULL);
 
 }
 
@@ -304,7 +288,7 @@
 	switch_memory_pool_t *pool;
 	struct switch_py_thread *pt = (struct switch_py_thread *) obj;
 
-	eval_some_python(pt->args, NULL, NULL, NULL, NULL);
+	eval_some_python("runtime", pt->args, NULL, NULL, NULL, NULL);
 
 	pool = pt->pool;
 	switch_core_destroy_memory_pool(&pool);
@@ -315,7 +299,7 @@
 SWITCH_STANDARD_API(api_python)
 {
 	
-	eval_some_python((char *) cmd, session, stream, NULL, NULL);
+	eval_some_python("fsapi", (char *) cmd, session, stream, NULL, NULL);
 
 	return SWITCH_STATUS_SUCCESS;
 }
@@ -354,6 +338,15 @@
 {
 	switch_api_interface_t *api_interface;
 	switch_application_interface_t *app_interface;
+	char *pp = getenv("PYTHONPATH");
+
+	if (pp) {
+		char *path = switch_mprintf("%s:%s", pp, SWITCH_GLOBAL_dirs.script_dir);
+		setenv("PYTHONPATH", path, 1);
+		free(path);
+	} else {
+		setenv("PYTHONPATH", SWITCH_GLOBAL_dirs.script_dir, 1);
+	}
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Python Framework Loading...\n");
 
@@ -364,7 +357,7 @@
 
 		// initialize python system
 		Py_Initialize();
-
+		
 		// create GIL and a threadstate
 		PyEval_InitThreads();
 

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.c	Wed Jul 16 10:58:00 2008
@@ -1,34 +1,27 @@
 SWITCH_BEGIN_EXTERN_C 
 
-PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, const char *name)
+PyObject *mod_python_conjure_event(switch_event_t *event)
 {
 	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);
-	}
 
 	return obj;
 }
 
 
-PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *stream, const char *name)
+PyObject *mod_python_conjure_stream(switch_stream_handle_t *stream)
 {
 	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);
-	}
-
 	return obj;
 }
 
-PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session, const char *name)
+PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session)
 {
 	PyObject *obj;
 	
@@ -38,11 +31,13 @@
 	result->setPython(module);
 	result->setSelf(obj);
 
+#if 0
 	if (module && name) {
 		PyDict_SetItem(PyModule_GetDict(module), Py_BuildValue("s", name), obj);
 		Py_DECREF(obj);
 	}
-	
+#endif
+
 	return obj;
 	
 }

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_extra.h	Wed Jul 16 10:58:00 2008
@@ -2,9 +2,9 @@
 #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_event(switch_event_t *event);
+PyObject *mod_python_conjure_stream(switch_stream_handle_t *stream);
+PyObject *mod_python_conjure_session(PyObject *module, switch_core_session_t *session);
 PyObject *mod_python_conjure_DTMF(char digit, int32_t duration);
 
 SWITCH_END_EXTERN_C

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp	Wed Jul 16 10:58:00 2008
@@ -5843,6 +5843,189 @@
 }
 
 
+SWIGINTERN PyObject *_wrap_CoreSession_uuid_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *arg2 = (char *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:CoreSession_uuid_set",&obj0,&obj1)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_uuid_set" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_uuid_set" "', argument " "2"" of type '" "char *""'");
+  }
+  arg2 = reinterpret_cast< char * >(buf2);
+  if (arg1->uuid) delete[] arg1->uuid;
+  if (arg2) {
+    size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
+    arg1->uuid = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
+  } else {
+    arg1->uuid = 0;
+  }
+  resultobj = SWIG_Py_Void();
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_uuid_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *result = 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject * obj0 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:CoreSession_uuid_get",&obj0)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_uuid_get" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  result = (char *) ((arg1)->uuid);
+  resultobj = SWIG_FromCharPtr((const char *)result);
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_tts_name_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *arg2 = (char *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:CoreSession_tts_name_set",&obj0,&obj1)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_tts_name_set" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_tts_name_set" "', argument " "2"" of type '" "char *""'");
+  }
+  arg2 = reinterpret_cast< char * >(buf2);
+  if (arg1->tts_name) delete[] arg1->tts_name;
+  if (arg2) {
+    size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
+    arg1->tts_name = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
+  } else {
+    arg1->tts_name = 0;
+  }
+  resultobj = SWIG_Py_Void();
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_tts_name_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *result = 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject * obj0 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:CoreSession_tts_name_get",&obj0)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_tts_name_get" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  result = (char *) ((arg1)->tts_name);
+  resultobj = SWIG_FromCharPtr((const char *)result);
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_voice_name_set(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *arg2 = (char *) 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  int res2 ;
+  char *buf2 = 0 ;
+  int alloc2 = 0 ;
+  PyObject * obj0 = 0 ;
+  PyObject * obj1 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"OO:CoreSession_voice_name_set",&obj0,&obj1)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_voice_name_set" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_voice_name_set" "', argument " "2"" of type '" "char *""'");
+  }
+  arg2 = reinterpret_cast< char * >(buf2);
+  if (arg1->voice_name) delete[] arg1->voice_name;
+  if (arg2) {
+    size_t size = strlen(reinterpret_cast< const char * >(arg2)) + 1;
+    arg1->voice_name = (char *)reinterpret_cast< char* >(memcpy((new char[size]), reinterpret_cast< const char * >(arg2), sizeof(char)*(size)));
+  } else {
+    arg1->voice_name = 0;
+  }
+  resultobj = SWIG_Py_Void();
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return resultobj;
+fail:
+  if (alloc2 == SWIG_NEWOBJ) delete[] buf2;
+  return NULL;
+}
+
+
+SWIGINTERN PyObject *_wrap_CoreSession_voice_name_get(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  CoreSession *arg1 = (CoreSession *) 0 ;
+  char *result = 0 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  PyObject * obj0 = 0 ;
+  
+  if (!PyArg_ParseTuple(args,(char *)"O:CoreSession_voice_name_get",&obj0)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 |  0 );
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_voice_name_get" "', argument " "1"" of type '" "CoreSession *""'"); 
+  }
+  arg1 = reinterpret_cast< CoreSession * >(argp1);
+  result = (char *) ((arg1)->voice_name);
+  resultobj = SWIG_FromCharPtr((const char *)result);
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_CoreSession_answer(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   CoreSession *arg1 = (CoreSession *) 0 ;
@@ -9216,6 +9399,12 @@
 	 { (char *)"CoreSession_cb_state_get", _wrap_CoreSession_cb_state_get, METH_VARARGS, NULL},
 	 { (char *)"CoreSession_hook_state_set", _wrap_CoreSession_hook_state_set, METH_VARARGS, NULL},
 	 { (char *)"CoreSession_hook_state_get", _wrap_CoreSession_hook_state_get, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_uuid_set", _wrap_CoreSession_uuid_set, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_uuid_get", _wrap_CoreSession_uuid_get, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_tts_name_set", _wrap_CoreSession_tts_name_set, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_tts_name_get", _wrap_CoreSession_tts_name_get, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_voice_name_set", _wrap_CoreSession_voice_name_set, METH_VARARGS, NULL},
+	 { (char *)"CoreSession_voice_name_get", _wrap_CoreSession_voice_name_get, METH_VARARGS, NULL},
 	 { (char *)"CoreSession_answer", _wrap_CoreSession_answer, METH_VARARGS, NULL},
 	 { (char *)"CoreSession_preAnswer", _wrap_CoreSession_preAnswer, METH_VARARGS, NULL},
 	 { (char *)"CoreSession_hangup", _wrap_CoreSession_hangup, METH_VARARGS, NULL},

Added: freeswitch/trunk/src/mod/languages/mod_python/python_example.py
==============================================================================
--- (empty file)
+++ freeswitch/trunk/src/mod/languages/mod_python/python_example.py	Wed Jul 16 10:58:00 2008
@@ -0,0 +1,61 @@
+import os
+from freeswitch import *
+
+# HANGUP HOOK
+#
+# session is a session object
+# what is "hangup" or "transfer"
+# if you pass an extra arg to setInputCallback then append 'arg' to get that value
+# def hangup_hook(session, what, arg):
+def hangup_hook(session, what):
+
+	consoleLog("info","hangup hook for %s!!\n\n" % what)
+	return
+
+
+# INPUT CALLBACK
+#
+# session is a session object
+# what is "dtmf" or "event"
+# obj is a dtmf object or an event object depending on the 'what' var.
+# if you pass an extra arg to setInputCallback then append 'arg' to get that value
+# def input_callback(session, what, obj, arg):
+def input_callback(session, what, obj):
+
+	if (what == "dtmf"):
+		consoleLog("info", what + " " + obj.digit + "\n")
+	else:
+		consoleLog("info", what + " " + obj.serialize() + "\n")		
+	return "pause"
+
+# APPLICATION
+#
+# default name for apps is "handler" it can be overridden with <modname>::<function>
+# session is a session object
+# args is all the args passed after the module name
+def handler(session, args):
+
+	session.answer()
+	session.setHangupHook(hangup_hook)
+	session.setInputCallback(input_callback)
+	session.execute("playback", session.getVariable("hold_music"))
+
+# FSAPI CALL FROM CLI, DP HTTP etc
+#
+# default name for python FSAPI is "fsapi" it can be overridden with <modname>::<function>
+# stream is a switch_stream, anything written with stream.write() is returned to the caller
+# env is a switch_event
+# args is all the args passed after the module name
+# session is a session object when called from the dial plan or the string "na" when not.
+def fsapi(session, stream, env, args):
+
+	stream.write("w00t!\n" + env.serialize())
+	
+
+# RUN A FUNCTION IN A THREAD
+#
+# default name for pyrun is "runtime" it can be overridden with <modname>::<function>
+# args is all the args passed after the module name
+def runtime(args):
+
+	print args + "\n"



More information about the Freeswitch-svn mailing list