[Freeswitch-svn] [commit] r5103 - freeswitch/trunk/src/mod/languages/mod_python
Freeswitch SVN
anthm at freeswitch.org
Tue May 8 12:08:48 EDT 2007
Author: anthm
Date: Tue May 8 12:08:48 2007
New Revision: 5103
Modified:
freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py
freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h
freeswitch/trunk/src/mod/languages/mod_python/mod_python.c
freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
Log:
change mod_python so freeswitch module is auto-loaded and session is auto declared
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 Tue May 8 12:08:48 2007
@@ -54,6 +54,9 @@
try:
if self.thisown: destroy(self)
except: pass
+ __swig_setmethods__["uuid"] = _freeswitch.SessionContainer_uuid_set
+ __swig_getmethods__["uuid"] = _freeswitch.SessionContainer_uuid_get
+ if _newclass:uuid = property(_freeswitch.SessionContainer_uuid_get, _freeswitch.SessionContainer_uuid_set)
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)
Modified: freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h (original)
+++ freeswitch/trunk/src/mod/languages/mod_python/freeswitch_python.h Tue May 8 12:08:48 2007
@@ -6,42 +6,46 @@
#ifdef __cplusplus
extern "C" {
#endif
+#ifdef DOH
+}
+#endif
#include <switch.h>
- extern switch_status_t PythonDTMFCallback(switch_core_session * session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
- void console_log(char *level_str, char *msg);
- void console_clean_log(char *msg);
- char *api_execute(char *cmd, char *arg);
- void api_reply_delete(char *reply);
+extern switch_status_t PythonDTMFCallback(switch_core_session * session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen);
+void console_log(char *level_str, char *msg);
+void console_clean_log(char *msg);
+char *api_execute(char *cmd, char *arg);
+void api_reply_delete(char *reply);
+
+class SessionContainer {
+ private:
+ switch_core_session_t *session;
+ switch_channel_t *channel;
+ PyObject *dtmfCallbackFunction;
+ char *tts_name;
+ char *voice_name;
+ public:
+ SessionContainer(char *uuid);
+ ~SessionContainer();
+ char *uuid;
- class SessionContainer {
- private:
- switch_core_session_t *session;
- switch_channel_t *channel;
- char *uuid;
- PyObject *dtmfCallbackFunction;
- char *tts_name;
- char *voice_name;
- public:
- SessionContainer(char *uuid);
- ~SessionContainer();
- int answer();
- int pre_answer();
- void hangup(char *cause);
- void set_variable(char *var, char *val);
- void get_variable(char *var, char *val);
- int play_file(char *file, char *timer_name);
- void set_dtmf_callback(PyObject * pyfunc);
- int speak_text(char *text);
- void set_tts_parms(char *tts_name, char *voice_name);
- int get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
- int transfer(char *extensions, char *dialplan, char *context);
- int play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
- char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
- void execute(char *app, char *data);
- protected:
- };
+ int answer();
+ int pre_answer();
+ void hangup(char *cause);
+ void set_variable(char *var, char *val);
+ void get_variable(char *var, char *val);
+ int play_file(char *file, char *timer_name);
+ void set_dtmf_callback(PyObject * pyfunc);
+ int speak_text(char *text);
+ void set_tts_parms(char *tts_name, char *voice_name);
+ int get_digits(char *dtmf_buf, int len, char *terminators, char *terminator, int timeout);
+ int transfer(char *extensions, char *dialplan, char *context);
+ int play_and_get_digits(int min_digits, int max_digits, int max_tries, int timeout, char *terminators,
+ char *audio_files, char *bad_input_audio_files, char *dtmf_buf, char *digits_regex);
+ void execute(char *app, char *data);
+ protected:
+};
#ifdef __cplusplus
}
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 Tue May 8 12:08:48 2007
@@ -73,14 +73,8 @@
}
script = argv[0];
-
- if (uuid) {
- argv[0] = uuid;
- } else {
- lead = 1;
- }
+ lead = 1;
-
if (switch_is_file_path(script)) {
script_path = script;
if ((script = strrchr(script_path, *SWITCH_PATH_SEPARATOR))) {
@@ -114,7 +108,11 @@
PyThreadState_Clear(tstate);
init_freeswitch();
PyRun_SimpleString("from freeswitch import *");
-
+ if (uuid) {
+ char code[128];
+ snprintf(code, sizeof(code), "session = SessionContainer(\"%s\");", uuid);
+ PyRun_SimpleString(code);
+ }
PySys_SetArgv(argc - lead, &argv[lead]);
PyRun_SimpleFile(pythonfile, script);
Py_EndInterpreter(tstate);
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 Tue May 8 12:08:48 2007
@@ -931,6 +931,47 @@
}
+static PyObject *_wrap_SessionContainer_uuid_set(PyObject *self, PyObject *args) {
+ PyObject *resultobj;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *arg2 ;
+ PyObject * obj0 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"Os:SessionContainer_uuid_set",&obj0,&arg2)) goto fail;
+ if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_SessionContainer,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
+ {
+ if (arg1->uuid) delete [] arg1->uuid;
+ if (arg2) {
+ arg1->uuid = (char *) (new char[strlen(arg2)+1]);
+ strcpy((char *) arg1->uuid,arg2);
+ } else {
+ arg1->uuid = 0;
+ }
+ }
+ Py_INCREF(Py_None); resultobj = Py_None;
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
+static PyObject *_wrap_SessionContainer_uuid_get(PyObject *self, PyObject *args) {
+ PyObject *resultobj;
+ SessionContainer *arg1 = (SessionContainer *) 0 ;
+ char *result;
+ PyObject * obj0 = 0 ;
+
+ if(!PyArg_ParseTuple(args,(char *)"O:SessionContainer_uuid_get",&obj0)) goto fail;
+ if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_SessionContainer,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
+ result = (char *) ((arg1)->uuid);
+
+ resultobj = result ? PyString_FromString(result) : Py_BuildValue((char*)"");
+ return resultobj;
+ fail:
+ return NULL;
+}
+
+
static PyObject *_wrap_SessionContainer_answer(PyObject *self, PyObject *args) {
PyObject *resultobj;
SessionContainer *arg1 = (SessionContainer *) 0 ;
@@ -1235,6 +1276,8 @@
{ (char *)"api_reply_delete", _wrap_api_reply_delete, METH_VARARGS },
{ (char *)"new_SessionContainer", _wrap_new_SessionContainer, METH_VARARGS },
{ (char *)"delete_SessionContainer", _wrap_delete_SessionContainer, METH_VARARGS },
+ { (char *)"SessionContainer_uuid_set", _wrap_SessionContainer_uuid_set, METH_VARARGS },
+ { (char *)"SessionContainer_uuid_get", _wrap_SessionContainer_uuid_get, METH_VARARGS },
{ (char *)"SessionContainer_answer", _wrap_SessionContainer_answer, METH_VARARGS },
{ (char *)"SessionContainer_pre_answer", _wrap_SessionContainer_pre_answer, METH_VARARGS },
{ (char *)"SessionContainer_hangup", _wrap_SessionContainer_hangup, METH_VARARGS },
More information about the Freeswitch-svn
mailing list