提交 fe32a839 authored 作者: Anthony Minessale's avatar Anthony Minessale

use channel flag to tell when to read from channel during some stuff

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1590 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 1212c95e
...@@ -72,7 +72,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s ...@@ -72,7 +72,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
\param terminators digits to end the collection \param terminators digits to end the collection
\param terminator actual digit that caused the collection to end (if any) \param terminator actual digit that caused the collection to end (if any)
\param timeout timeout in ms \param timeout timeout in ms
\param poll_channel flag to specify if you want the function to poll the channel while running
\return SWITCH_STATUS_SUCCESS to keep the collection moving. \return SWITCH_STATUS_SUCCESS to keep the collection moving.
*/ */
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session, SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
...@@ -81,8 +80,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess ...@@ -81,8 +80,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
unsigned int maxdigits, unsigned int maxdigits,
const char *terminators, const char *terminators,
char *terminator, char *terminator,
unsigned int timeout, unsigned int timeout);
unsigned int poll_channel);
/*! /*!
\brief play a file from the disk to the session \brief play a file from the disk to the session
......
...@@ -344,6 +344,7 @@ CF_ACCEPT_CNG = (1 << 5) - Channel will accept CNG frames ...@@ -344,6 +344,7 @@ CF_ACCEPT_CNG = (1 << 5) - Channel will accept CNG frames
CF_LOCK_THREAD = (1 << 6) - Prevent the channel thread from exiting while this flag is set CF_LOCK_THREAD = (1 << 6) - Prevent the channel thread from exiting while this flag is set
CF_BRIDGED = (1 << 7) - Channel in a bridge CF_BRIDGED = (1 << 7) - Channel in a bridge
CF_HOLD = (1 << 8) - Channel is on hold CF_HOLD = (1 << 8) - Channel is on hold
CF_SERVICE = (1 << 9) - Channel has a service thread
</pre> </pre>
*/ */
...@@ -356,7 +357,8 @@ typedef enum { ...@@ -356,7 +357,8 @@ typedef enum {
CF_ACCEPT_CNG = (1 << 5), CF_ACCEPT_CNG = (1 << 5),
CF_LOCK_THREAD = (1 << 6), CF_LOCK_THREAD = (1 << 6),
CF_BRIDGED = (1 << 7), CF_BRIDGED = (1 << 7),
CF_HOLD = (1 << 8) CF_HOLD = (1 << 8),
CF_SERVICE = (1 << 9)
} switch_channel_flag_t; } switch_channel_flag_t;
......
...@@ -183,7 +183,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data) ...@@ -183,7 +183,7 @@ static void ivrtest_function(switch_core_session_t *session, char *data)
} }
} }
if (switch_ivr_collect_digits_count(session, buf, sizeof(buf), 10, "#*", &term, 10000, 1) != SWITCH_STATUS_SUCCESS) { if (switch_ivr_collect_digits_count(session, buf, sizeof(buf), 10, "#*", &term, 10000) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break; break;
} }
......
...@@ -559,8 +559,6 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval ...@@ -559,8 +559,6 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval
char *buf; char *buf;
int digits; int digits;
int32 timeout = 5000; int32 timeout = 5000;
int32 poll_chan = 1;
if (argc > 0) { if (argc > 0) {
char term; char term;
...@@ -571,11 +569,9 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval ...@@ -571,11 +569,9 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval
if (argc > 2) { if (argc > 2) {
JS_ValueToInt32(cx, argv[2], &timeout); JS_ValueToInt32(cx, argv[2], &timeout);
} }
if (argc > 3) {
JS_ValueToInt32(cx, argv[3], &poll_chan);
}
buf = switch_core_session_alloc(jss->session, digits); buf = switch_core_session_alloc(jss->session, digits);
switch_ivr_collect_digits_count(jss->session, buf, digits, digits, terminators, &term, timeout, poll_chan ? SWITCH_TRUE : SWITCH_FALSE); switch_ivr_collect_digits_count(jss->session, buf, digits, digits, terminators, &term, timeout);
*rval = STRING_TO_JSVAL ( JS_NewStringCopyZ(cx, buf) ); *rval = STRING_TO_JSVAL ( JS_NewStringCopyZ(cx, buf) );
return JS_TRUE; return JS_TRUE;
} }
......
...@@ -743,6 +743,7 @@ static void *switch_core_service_thread(switch_thread_t *thread, void *obj) ...@@ -743,6 +743,7 @@ static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
assert(channel != NULL); assert(channel != NULL);
switch_channel_set_flag(channel, CF_SERVICE);
while (data->running > 0) { while (data->running > 0) {
switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) { switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
case SWITCH_STATUS_SUCCESS: case SWITCH_STATUS_SUCCESS:
...@@ -755,6 +756,7 @@ static void *switch_core_service_thread(switch_thread_t *thread, void *obj) ...@@ -755,6 +756,7 @@ static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
} }
} }
switch_channel_clear_flag(channel, CF_SERVICE);
data->running = 0; data->running = 0;
return NULL; return NULL;
} }
......
...@@ -63,7 +63,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s ...@@ -63,7 +63,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
break; break;
} }
if (switch_channel_test_flag(channel, CF_SERVICE)) {
switch_yield(1000);
} else {
status = switch_core_session_read_frame(session, &read_frame, -1, 0); status = switch_core_session_read_frame(session, &read_frame, -1, 0);
}
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
...@@ -80,9 +84,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess ...@@ -80,9 +84,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
unsigned int maxdigits, unsigned int maxdigits,
const char *terminators, const char *terminators,
char *terminator, char *terminator,
unsigned int timeout, unsigned int timeout)
unsigned int poll_channel
)
{ {
unsigned int i = 0, x = (unsigned int) strlen(buf); unsigned int i = 0, x = (unsigned int) strlen(buf);
switch_channel_t *channel; switch_channel_t *channel;
...@@ -135,14 +137,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess ...@@ -135,14 +137,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
} }
} }
} }
if (poll_channel) {
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (switch_channel_test_flag(channel, CF_SERVICE)) {
switch_yield(1000);
} else {
status = switch_core_session_read_frame(session, &read_frame, -1, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) { if (!SWITCH_READ_ACCEPTABLE(status)) {
break; break;
} }
} else {
switch_yield(1000);
} }
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论