Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
21534d46
提交
21534d46
authored
7月 11, 2008
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add api
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@8999
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
a3ccefa7
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
40 行删除
+62
-40
mod_python.c
src/mod/languages/mod_python/mod_python.c
+62
-38
mod_python_extra.c
src/mod/languages/mod_python/mod_python_extra.c
+0
-2
没有找到文件。
src/mod/languages/mod_python/mod_python.c
浏览文件 @
21534d46
...
...
@@ -54,7 +54,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_python_shutdown
);
SWITCH_MODULE_DEFINITION
(
mod_python
,
mod_python_load
,
mod_python_shutdown
,
NULL
);
static
void
eval_some_python
(
char
*
uuid
,
char
*
args
,
switch_core_session_t
*
session
)
static
void
eval_some_python
(
char
*
args
,
switch_core_session_t
*
session
,
switch_stream_handle_t
*
stream
)
{
PyThreadState
*
tstate
=
NULL
;
char
*
dupargs
=
NULL
;
...
...
@@ -62,10 +62,11 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
int
argc
;
int
lead
=
0
;
char
*
script
=
NULL
;
PyObject
*
module
=
NULL
,
*
sp
=
NULL
;
PyObject
*
module
=
NULL
,
*
sp
=
NULL
,
*
stp
=
NULL
,
*
eve
=
NULL
;
PyObject
*
function
=
NULL
;
PyObject
*
arg
=
NULL
;
PyObject
*
result
=
NULL
;
char
*
uuid
=
NULL
;
if
(
args
)
{
dupargs
=
strdup
(
args
);
...
...
@@ -93,6 +94,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
// 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
);
...
...
@@ -115,6 +117,17 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyErr_Clear
();
goto
done_swap_out
;
}
if
(
stream
)
{
printf
(
"doh
\n\n\n
"
);
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"
);
if
(
!
function
)
{
...
...
@@ -161,43 +174,45 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
if
(
sp
)
{
Py_XDECREF
(
sp
);
}
if
(
stp
)
{
Py_XDECREF
(
stp
);
}
if
(
eve
)
{
Py_XDECREF
(
eve
);
}
done_swap_out:
// 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
);
}
// decrement ref counts
Py_XDECREF
(
module
);
Py_XDECREF
(
function
);
Py_XDECREF
(
arg
);
Py_XDECREF
(
result
);
// 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
);
}
switch_safe_free
(
dupargs
);
...
...
@@ -206,7 +221,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
SWITCH_STANDARD_APP
(
python_function
)
{
eval_some_python
(
switch_core_session_get_uuid
(
session
),
(
char
*
)
data
,
session
);
eval_some_python
(
(
char
*
)
data
,
session
,
NULL
);
}
...
...
@@ -220,7 +235,7 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
switch_memory_pool_t
*
pool
;
struct
switch_py_thread
*
pt
=
(
struct
switch_py_thread
*
)
obj
;
eval_some_python
(
NULL
,
strdup
(
pt
->
args
)
,
NULL
);
eval_some_python
(
pt
->
args
,
NULL
,
NULL
);
pool
=
pt
->
pool
;
switch_core_destroy_memory_pool
(
&
pool
);
...
...
@@ -228,6 +243,14 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
return
NULL
;
}
SWITCH_STANDARD_API
(
api_python
)
{
eval_some_python
((
char
*
)
cmd
,
session
,
stream
);
return
SWITCH_STATUS_SUCCESS
;
}
SWITCH_STANDARD_API
(
launch_python
)
{
switch_thread_t
*
thread
;
...
...
@@ -288,7 +311,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
/* connect my internal structure to the blank pointer passed to me */
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
SWITCH_ADD_API
(
api_interface
,
"python"
,
"run a python script"
,
launch_python
,
"python </path/to/script>"
);
SWITCH_ADD_API
(
api_interface
,
"pyrun"
,
"run a python script"
,
launch_python
,
"python </path/to/script>"
);
SWITCH_ADD_API
(
api_interface
,
"python"
,
"run a python script"
,
api_python
,
"python </path/to/script>"
);
SWITCH_ADD_APP
(
app_interface
,
"python"
,
"Launch python ivr"
,
"Run a python ivr on a channel"
,
python_function
,
"<script> [additional_vars [...]]"
,
SAF_SUPPORT_NOMEDIA
);
...
...
src/mod/languages/mod_python/mod_python_extra.c
浏览文件 @
21534d46
...
...
@@ -8,7 +8,6 @@ PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, cons
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
);
Py_DECREF
(
obj
);
}
return
obj
;
...
...
@@ -24,7 +23,6 @@ PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *st
if
(
module
&&
name
)
{
PyDict_SetItem
(
PyModule_GetDict
(
module
),
Py_BuildValue
(
"s"
,
name
),
obj
);
Py_DECREF
(
obj
);
}
return
obj
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论