Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
ed9e9c62
提交
ed9e9c62
authored
10月 02, 2015
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-8287 refactor local_stream api to be more consistent and add auto complete
上级
76b11fd8
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
149 行增加
和
243 行删除
+149
-243
mod_local_stream.c
src/mod/formats/mod_local_stream/mod_local_stream.c
+149
-243
没有找到文件。
src/mod/formats/mod_local_stream/mod_local_stream.c
浏览文件 @
ed9e9c62
...
...
@@ -118,6 +118,41 @@ struct local_stream_source {
typedef
struct
local_stream_source
local_stream_source_t
;
switch_status_t
list_streams_full
(
const
char
*
line
,
const
char
*
cursor
,
switch_console_callback_match_t
**
matches
,
switch_bool_t
show_aliases
)
{
local_stream_source_t
*
source
;
switch_hash_index_t
*
hi
;
void
*
val
;
const
void
*
vvar
;
switch_console_callback_match_t
*
my_matches
=
NULL
;
switch_status_t
status
=
SWITCH_STATUS_FALSE
;
switch_mutex_lock
(
globals
.
mutex
);
for
(
hi
=
switch_core_hash_first
(
globals
.
source_hash
);
hi
;
hi
=
switch_core_hash_next
(
&
hi
))
{
switch_core_hash_this
(
hi
,
&
vvar
,
NULL
,
&
val
);
source
=
(
local_stream_source_t
*
)
val
;
if
(
!
show_aliases
&&
strcmp
((
char
*
)
vvar
,
source
->
name
))
{
continue
;
}
switch_console_push_match
(
&
my_matches
,
(
const
char
*
)
vvar
);
}
switch_mutex_unlock
(
globals
.
mutex
);
if
(
my_matches
)
{
*
matches
=
my_matches
;
status
=
SWITCH_STATUS_SUCCESS
;
}
return
status
;
}
switch_status_t
list_streams
(
const
char
*
line
,
const
char
*
cursor
,
switch_console_callback_match_t
**
matches
)
{
return
list_streams_full
(
line
,
cursor
,
matches
,
SWITCH_TRUE
);
}
static
int
do_rand
(
uint32_t
count
)
{
double
r
;
...
...
@@ -1050,14 +1085,14 @@ static void event_handler(switch_event_t *event)
RUNNING
=
0
;
}
#define
RELOAD_LOCAL_STREAM_SYNTAX "
<local_stream_name>"
SWITCH_STANDARD_API
(
reload_
local_stream_function
)
#define
LOCAL_STREAM_SYNTAX "<show|start|reload|stop|hup>
<local_stream_name>"
SWITCH_STANDARD_API
(
local_stream_function
)
{
local_stream_source_t
*
source
=
NULL
;
char
*
mycmd
=
NULL
,
*
argv
[
1
]
=
{
0
};
char
*
mycmd
=
NULL
,
*
argv
[
5
]
=
{
0
};
char
*
local_stream_name
=
NULL
;
int
argc
=
0
;
int
ok
=
0
;
if
(
zstr
(
cmd
))
{
goto
usage
;
...
...
@@ -1071,61 +1106,31 @@ SWITCH_STANDARD_API(reload_local_stream_function)
goto
usage
;
}
local_stream_name
=
argv
[
0
];
if
(
zstr
(
local_stream_name
))
{
goto
usage
;
}
local_stream_name
=
argv
[
1
];
if
(
!
strcasecmp
(
argv
[
0
],
"hup"
))
{
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
if
(
!
source
)
{
stream
->
write_function
(
stream
,
"-ERR Cannot locate local_stream %s!
\n
"
,
local_stream_name
);
if
(
source
)
{
source
->
hup
=
1
;
stream
->
write_function
(
stream
,
"+OK hup stream: %s"
,
source
->
name
);
goto
done
;
}
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"stop"
))
{
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
source
->
full_reload
=
1
;
source
->
part_reload
=
1
;
stream
->
write_function
(
stream
,
"+OK"
);
if
(
!
source
)
{
stream
->
write_function
(
stream
,
"-ERR Cannot locate local_stream %s!
\n
"
,
local_stream_name
);
goto
done
;
usage
:
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
RELOAD_LOCAL_STREAM_SYNTAX
);
switch_safe_free
(
mycmd
);
done
:
switch_safe_free
(
mycmd
);
return
SWITCH_STATUS_SUCCESS
;
}
#define STOP_LOCAL_STREAM_SYNTAX "<local_stream_name>"
SWITCH_STANDARD_API
(
stop_local_stream_function
)
{
local_stream_source_t
*
source
=
NULL
;
char
*
mycmd
=
NULL
,
*
argv
[
1
]
=
{
0
};
char
*
local_stream_name
=
NULL
;
int
argc
=
0
;
if
(
zstr
(
cmd
))
{
goto
usage
;
}
if
(
!
(
mycmd
=
strdup
(
cmd
)))
{
goto
usage
;
}
if
((
argc
=
switch_separate_string
(
mycmd
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
]))))
<
1
)
{
goto
usage
;
}
local_stream_name
=
argv
[
0
];
if
(
zstr
(
local_stream_name
))
{
goto
usage
;
}
source
->
stopped
=
1
;
stream
->
write_function
(
stream
,
"+OK"
);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"reload"
))
{
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
...
...
@@ -1135,35 +1140,33 @@ SWITCH_STANDARD_API(stop_local_stream_function)
goto
done
;
}
source
->
stopped
=
1
;
source
->
full_reload
=
1
;
source
->
part_reload
=
1
;
stream
->
write_function
(
stream
,
"+OK"
);
goto
done
;
usage
:
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
STOP_LOCAL_STREAM_SYNTAX
);
switch_safe_free
(
mycmd
);
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"start"
))
{
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
done
:
if
(
source
)
{
source
->
stopped
=
0
;
stream
->
write_function
(
stream
,
"+OK stream: %s"
,
source
->
name
);
goto
done
;
}
switch_safe_free
(
mycmd
);
return
SWITCH_STATUS_SUCCESS
;
}
if
((
ok
=
launch_streams
(
local_stream_name
)))
{
stream
->
write_function
(
stream
,
"+OK stream: %s"
,
local_stream_name
);
goto
done
;
}
#define SHOW_LOCAL_STREAM_SYNTAX "[local_stream_name [xml]]"
SWITCH_STANDARD_API
(
show_local_stream_function
)
{
local_stream_source_t
*
source
=
NULL
;
char
*
mycmd
=
NULL
,
*
argv
[
2
]
=
{
0
};
char
*
local_stream_name
=
NULL
;
int
argc
=
0
;
}
else
if
(
!
strcasecmp
(
argv
[
0
],
"show"
))
{
switch_hash_index_t
*
hi
;
const
void
*
var
;
void
*
val
;
switch_bool_t
xml
=
SWITCH_FALSE
;
switch_mutex_lock
(
globals
.
mutex
);
if
(
zstr
(
cmd
))
{
if
(
argc
==
1
)
{
for
(
hi
=
switch_core_hash_first
(
globals
.
source_hash
);
hi
;
hi
=
switch_core_hash_next
(
&
hi
))
{
switch_core_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
if
((
source
=
(
local_stream_source_t
*
)
val
))
{
...
...
@@ -1171,22 +1174,12 @@ SWITCH_STANDARD_API(show_local_stream_function)
}
}
}
else
{
if
(
!
(
mycmd
=
strdup
(
cmd
)))
{
goto
usage
;
}
if
((
argc
=
switch_separate_string
(
mycmd
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
])))))
{
local_stream_name
=
argv
[
0
];
if
(
argc
>
1
&&
!
strcasecmp
(
"xml"
,
argv
[
1
]))
{
if
(
argc
==
4
&&
!
strcasecmp
(
"xml"
,
argv
[
3
]))
{
xml
=
SWITCH_TRUE
;
}
}
if
(
!
local_stream_name
)
{
goto
usage
;
}
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
if
(
source
)
{
if
(
xml
)
{
stream
->
write_function
(
stream
,
"<?xml version=
\"
1.0
\"
?>
\n
<local_stream name=
\"
%s
\"
>
\n
"
,
source
->
name
);
...
...
@@ -1219,105 +1212,17 @@ SWITCH_STANDARD_API(show_local_stream_function)
}
}
else
{
stream
->
write_function
(
stream
,
"-ERR Cannot locate local_stream %s!
\n
"
,
local_stream_name
);
goto
done
;
}
}
stream
->
write_function
(
stream
,
"+OK"
);
goto
done
;
usage
:
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
SHOW_LOCAL_STREAM_SYNTAX
);
done
:
switch_mutex_unlock
(
globals
.
mutex
);
switch_safe_free
(
mycmd
);
return
SWITCH_STATUS_SUCCESS
;
}
#define START_LOCAL_STREAM_SYNTAX "<local_stream_name>"
SWITCH_STANDARD_API
(
start_local_stream_function
)
{
local_stream_source_t
*
source
=
NULL
;
char
*
mycmd
=
NULL
,
*
argv
[
8
]
=
{
0
};
char
*
local_stream_name
=
NULL
;
int
argc
=
0
;
int
ok
=
0
;
if
(
zstr
(
cmd
))
{
goto
usage
;
}
if
(
!
(
mycmd
=
strdup
(
cmd
)))
{
goto
usage
;
}
if
((
argc
=
switch_separate_string
(
mycmd
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
]))))
<
1
)
{
goto
usage
;
}
local_stream_name
=
argv
[
0
];
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
if
(
source
)
{
source
->
stopped
=
0
;
stream
->
write_function
(
stream
,
"+OK stream: %s"
,
source
->
name
);
goto
done
;
}
if
((
ok
=
launch_streams
(
local_stream_name
)))
{
stream
->
write_function
(
stream
,
"+OK stream: %s"
,
local_stream_name
);
goto
done
;
}
usage
:
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
START_LOCAL_STREAM_SYNTAX
);
done
:
switch_safe_free
(
mycmd
);
return
SWITCH_STATUS_SUCCESS
;
}
#define HUP_LOCAL_STREAM_SYNTAX "<local_stream_name>"
SWITCH_STANDARD_API
(
hup_local_stream_function
)
{
local_stream_source_t
*
source
=
NULL
;
char
*
mycmd
=
NULL
,
*
argv
[
8
]
=
{
0
};
char
*
local_stream_name
=
NULL
;
int
argc
=
0
;
if
(
zstr
(
cmd
))
{
goto
usage
;
}
if
(
!
(
mycmd
=
strdup
(
cmd
)))
{
goto
usage
;
}
if
((
argc
=
switch_separate_string
(
mycmd
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
]))))
<
1
)
{
goto
usage
;
}
local_stream_name
=
argv
[
0
];
switch_mutex_lock
(
globals
.
mutex
);
source
=
switch_core_hash_find
(
globals
.
source_hash
,
local_stream_name
);
switch_mutex_unlock
(
globals
.
mutex
);
if
(
source
)
{
source
->
hup
=
1
;
stream
->
write_function
(
stream
,
"+OK hup stream: %s"
,
source
->
name
);
goto
done
;
}
goto
done
;
usage
:
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
START_LOCAL_STREAM_SYNTAX
);
stream
->
write_function
(
stream
,
"-USAGE: %s
\n
"
,
LOCAL_STREAM_SYNTAX
);
done
:
...
...
@@ -1356,15 +1261,16 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_local_stream_load)
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Couldn't bind event handler!
\n
"
);
}
SWITCH_ADD_API
(
commands_api_interface
,
"hup_local_stream"
,
"Skip to next file in local_stream"
,
hup_local_stream_function
,
RELOAD_LOCAL_STREAM_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"reload_local_stream"
,
"Reloads a local_stream"
,
reload_local_stream_function
,
RELOAD_LOCAL_STREAM_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"stop_local_stream"
,
"Stops and unloads a local_stream"
,
stop_local_stream_function
,
STOP_LOCAL_STREAM_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"start_local_stream"
,
"Starts a new local_stream"
,
start_local_stream_function
,
START_LOCAL_STREAM_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"show_local_stream"
,
"Shows a local stream"
,
show_local_stream_function
,
SHOW_LOCAL_STREAM_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"local_stream"
,
"manage local streams"
,
local_stream_function
,
LOCAL_STREAM_SYNTAX
);
// switch_console_set_complete("add sofia profile ::sofia::list_profiles start");
switch_console_set_complete
(
"add local_stream show ::console::list_streams as xml"
);
switch_console_set_complete
(
"add local_stream start"
);
switch_console_set_complete
(
"add local_stream reload ::console::list_streams"
);
switch_console_set_complete
(
"add local_stream stop ::console::list_streams"
);
switch_console_set_complete
(
"add local_stream hup ::console::list_streams"
);
switch_console_add_complete_func
(
"::console::list_streams"
,
list_streams
);
/* indicate that the module should continue to be loaded */
return
SWITCH_STATUS_SUCCESS
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论