change mod_python so freeswitch module is auto-loaded and session is auto declared
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5103 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
cb09b09f82
commit
50b4a37771
|
@ -54,6 +54,9 @@ class SessionContainer(_object):
|
|||
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)
|
||||
|
|
|
@ -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;
|
||||
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:
|
||||
};
|
||||
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;
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -73,14 +73,8 @@ static void eval_some_python(char *uuid, char *args)
|
|||
}
|
||||
|
||||
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 @@ static void eval_some_python(char *uuid, char *args)
|
|||
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);
|
||||
|
|
|
@ -931,6 +931,47 @@ static PyObject *_wrap_delete_SessionContainer(PyObject *self, PyObject *args) {
|
|||
}
|
||||
|
||||
|
||||
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 @@ static PyMethodDef SwigMethods[] = {
|
|||
{ (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 },
|
||||
|
|
Loading…
Reference in New Issue