MODAPP-325 part 1

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14981 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Brian West 2009-09-25 19:07:20 +00:00
parent a9936c09e8
commit 3bc20b3c43
9 changed files with 78 additions and 29 deletions

View File

@ -286,7 +286,8 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg);
* For timeout milliseconds, call the dtmf function set previously * For timeout milliseconds, call the dtmf function set previously
* by setDTMFCallback whenever a dtmf or event is received * by setDTMFCallback whenever a dtmf or event is received
*/ */
SWITCH_DECLARE(int) collectDigits(int timeout); SWITCH_DECLARE(int) collectDigits(int abs_timeout);
SWITCH_DECLARE(int) collectDigits(int digit_timeout, int abs_timeout);
/** /**
* Collect up to maxdigits digits worth of digits * Collect up to maxdigits digits worth of digits

View File

@ -122,7 +122,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
\param timeout a timeout in milliseconds \param timeout a timeout in milliseconds
\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_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t timeout); SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout);
/*! /*!
\brief Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up. \brief Wait for specified number of DTMF digits, untile terminator is received or until the channel hangs up.

View File

@ -1011,7 +1011,7 @@ SWITCH_STANDARD_APP(fifo_function)
goto abort; goto abort;
} }
} else { } else {
switch_ivr_collect_digits_callback(session, &args, 0); switch_ivr_collect_digits_callback(session, &args, 0, 0);
} }
if (caller_exit_key && *buf == *caller_exit_key) { if (caller_exit_key && *buf == *caller_exit_key) {

View File

@ -22136,17 +22136,19 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_park(void * jarg1, void * jarg2) {
} }
SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_collect_digits_callback(void * jarg1, void * jarg2, unsigned long jarg3) { SWIGEXPORT int SWIGSTDCALL CSharp_switch_ivr_collect_digits_callback(void * jarg1, void * jarg2, unsigned long jarg3, unsigned long jarg4) {
int jresult ; int jresult ;
switch_core_session_t *arg1 = (switch_core_session_t *) 0 ; switch_core_session_t *arg1 = (switch_core_session_t *) 0 ;
switch_input_args_t *arg2 = (switch_input_args_t *) 0 ; switch_input_args_t *arg2 = (switch_input_args_t *) 0 ;
uint32_t arg3 ; uint32_t arg3 ;
uint32_t arg4 ;
switch_status_t result; switch_status_t result;
arg1 = (switch_core_session_t *)jarg1; arg1 = (switch_core_session_t *)jarg1;
arg2 = (switch_input_args_t *)jarg2; arg2 = (switch_input_args_t *)jarg2;
arg3 = (uint32_t)jarg3; arg3 = (uint32_t)jarg3;
result = (switch_status_t)switch_ivr_collect_digits_callback(arg1,arg2,arg3); arg4 = (uint32_t)jarg4;
result = (switch_status_t)switch_ivr_collect_digits_callback(arg1,arg2,arg3,arg4);
jresult = result; jresult = result;
return jresult; return jresult;
} }
@ -28912,7 +28914,7 @@ SWIGEXPORT void SWIGSTDCALL CSharp_CoreSession_SetTtsParameters(void * jarg1, ch
} }
SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_CollectDigits(void * jarg1, int jarg2) { SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_CollectDigits__SWIG_0(void * jarg1, int jarg2) {
int jresult ; int jresult ;
CoreSession *arg1 = (CoreSession *) 0 ; CoreSession *arg1 = (CoreSession *) 0 ;
int arg2 ; int arg2 ;
@ -28926,6 +28928,22 @@ SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_CollectDigits(void * jarg1, int ja
} }
SWIGEXPORT int SWIGSTDCALL CSharp_CoreSession_CollectDigits__SWIG_1(void * jarg1, int jarg2, int jarg3) {
int jresult ;
CoreSession *arg1 = (CoreSession *) 0 ;
int arg2 ;
int arg3 ;
int result;
arg1 = (CoreSession *)jarg1;
arg2 = (int)jarg2;
arg3 = (int)jarg3;
result = (int)(arg1)->collectDigits(arg2,arg3);
jresult = result;
return jresult;
}
SWIGEXPORT char * SWIGSTDCALL CSharp_CoreSession_GetDigits__SWIG_0(void * jarg1, int jarg2, char * jarg3, int jarg4) { SWIGEXPORT char * SWIGSTDCALL CSharp_CoreSession_GetDigits__SWIG_0(void * jarg1, int jarg2, char * jarg3, int jarg4) {
char * jresult ; char * jresult ;
CoreSession *arg1 = (CoreSession *) 0 ; CoreSession *arg1 = (CoreSession *) 0 ;

View File

@ -282,8 +282,13 @@ public class CoreSession : IDisposable {
freeswitchPINVOKE.CoreSession_SetTtsParameters(swigCPtr, tts_name, voice_name); freeswitchPINVOKE.CoreSession_SetTtsParameters(swigCPtr, tts_name, voice_name);
} }
public int CollectDigits(int timeout) { public int CollectDigits(int abs_timeout) {
int ret = freeswitchPINVOKE.CoreSession_CollectDigits(swigCPtr, timeout); int ret = freeswitchPINVOKE.CoreSession_CollectDigits__SWIG_0(swigCPtr, abs_timeout);
return ret;
}
public int CollectDigits(int digit_timeout, int abs_timeout) {
int ret = freeswitchPINVOKE.CoreSession_CollectDigits__SWIG_1(swigCPtr, digit_timeout, abs_timeout);
return ret; return ret;
} }
@ -3178,8 +3183,8 @@ public class freeswitch {
return ret; return ret;
} }
public static switch_status_t switch_ivr_collect_digits_callback(SWIGTYPE_p_switch_core_session session, switch_input_args_t args, uint timeout) { public static switch_status_t switch_ivr_collect_digits_callback(SWIGTYPE_p_switch_core_session session, switch_input_args_t args, uint digit_timeout, uint abs_timeout) {
switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_collect_digits_callback(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_input_args_t.getCPtr(args), timeout); switch_status_t ret = (switch_status_t)freeswitchPINVOKE.switch_ivr_collect_digits_callback(SWIGTYPE_p_switch_core_session.getCPtr(session), switch_input_args_t.getCPtr(args), digit_timeout, abs_timeout);
return ret; return ret;
} }
@ -9901,7 +9906,7 @@ class freeswitchPINVOKE {
public static extern int switch_ivr_park(HandleRef jarg1, HandleRef jarg2); public static extern int switch_ivr_park(HandleRef jarg1, HandleRef jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_collect_digits_callback")] [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_collect_digits_callback")]
public static extern int switch_ivr_collect_digits_callback(HandleRef jarg1, HandleRef jarg2, uint jarg3); public static extern int switch_ivr_collect_digits_callback(HandleRef jarg1, HandleRef jarg2, uint jarg3, uint jarg4);
[DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_collect_digits_count")] [DllImport("mod_managed", EntryPoint="CSharp_switch_ivr_collect_digits_count")]
public static extern int switch_ivr_collect_digits_count(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, string jarg5, string jarg6, uint jarg7, uint jarg8, uint jarg9); public static extern int switch_ivr_collect_digits_count(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, string jarg5, string jarg6, uint jarg7, uint jarg8, uint jarg9);
@ -11430,8 +11435,11 @@ class freeswitchPINVOKE {
[DllImport("mod_managed", EntryPoint="CSharp_CoreSession_SetTtsParameters")] [DllImport("mod_managed", EntryPoint="CSharp_CoreSession_SetTtsParameters")]
public static extern void CoreSession_SetTtsParameters(HandleRef jarg1, string jarg2, string jarg3); public static extern void CoreSession_SetTtsParameters(HandleRef jarg1, string jarg2, string jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_CoreSession_CollectDigits")] [DllImport("mod_managed", EntryPoint="CSharp_CoreSession_CollectDigits__SWIG_0")]
public static extern int CoreSession_CollectDigits(HandleRef jarg1, int jarg2); public static extern int CoreSession_CollectDigits__SWIG_0(HandleRef jarg1, int jarg2);
[DllImport("mod_managed", EntryPoint="CSharp_CoreSession_CollectDigits__SWIG_1")]
public static extern int CoreSession_CollectDigits__SWIG_1(HandleRef jarg1, int jarg2, int jarg3);
[DllImport("mod_managed", EntryPoint="CSharp_CoreSession_GetDigits__SWIG_0")] [DllImport("mod_managed", EntryPoint="CSharp_CoreSession_GetDigits__SWIG_0")]
public static extern string CoreSession_GetDigits__SWIG_0(HandleRef jarg1, int jarg2, string jarg3, int jarg4); public static extern string CoreSession_GetDigits__SWIG_0(HandleRef jarg1, int jarg2, string jarg3, int jarg4);

View File

@ -1463,7 +1463,9 @@ static JSBool session_collect_input(JSContext * cx, JSObject * obj, uintN argc,
switch_channel_t *channel; switch_channel_t *channel;
void *bp = NULL; void *bp = NULL;
int len = 0; int len = 0;
int32 to = 0; int32 abs_timeout = 0;
int32 digit_timeout = 0;
switch_input_callback_function_t dtmf_func = NULL; switch_input_callback_function_t dtmf_func = NULL;
struct input_callback_state cb_state = { 0 }; struct input_callback_state cb_state = { 0 };
JSFunction *function; JSFunction *function;
@ -1494,8 +1496,11 @@ static JSBool session_collect_input(JSContext * cx, JSObject * obj, uintN argc,
} }
} }
if (argc > 2) { if (argc == 3) {
JS_ValueToInt32(jss->cx, argv[2], &to); JS_ValueToInt32(jss->cx, argv[2], &abs_timeout);
} else if (argc > 3) {
JS_ValueToInt32(jss->cx, argv[2], &digit_timeout);
JS_ValueToInt32(jss->cx, argv[3], &abs_timeout);
} }
cb_state.saveDepth = JS_SuspendRequest(cx); cb_state.saveDepth = JS_SuspendRequest(cx);
@ -1503,7 +1508,7 @@ static JSBool session_collect_input(JSContext * cx, JSObject * obj, uintN argc,
args.buf = bp; args.buf = bp;
args.buflen = len; args.buflen = len;
switch_ivr_collect_digits_callback(jss->session, &args, to); switch_ivr_collect_digits_callback(jss->session, &args, digit_timeout, abs_timeout);
JS_ResumeRequest(cx, cb_state.saveDepth); JS_ResumeRequest(cx, cb_state.saveDepth);
check_hangup_hook(jss, &ret); check_hangup_hook(jss, &ret);
*rval = cb_state.ret; *rval = cb_state.ret;

View File

@ -684,11 +684,15 @@ SWITCH_DECLARE(void) CoreSession::set_tts_parms(char *tts_name_p, char *voice_na
SWITCH_DECLARE(int) CoreSession::collectDigits(int timeout) { SWITCH_DECLARE(int) CoreSession::collectDigits(int abs_timeout) {
return collectDigits(0, abs_timeout);
}
SWITCH_DECLARE(int) CoreSession::collectDigits(int digit_timeout, int abs_timeout) {
this_check(-1); this_check(-1);
sanity_check(-1); sanity_check(-1);
begin_allow_threads(); begin_allow_threads();
switch_ivr_collect_digits_callback(session, ap, timeout); switch_ivr_collect_digits_callback(session, ap, digit_timeout, abs_timeout);
end_allow_threads(); end_allow_threads();
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -815,21 +815,23 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session,
return status; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t timeout) SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_session_t *session, switch_input_args_t *args, uint32_t digit_timeout, uint32_t abs_timeout)
{ {
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_time_t started = 0; switch_time_t abs_started = 0, digit_started = 0;
uint32_t elapsed; uint32_t abs_elapsed = 0, digit_elapsed = 0;
if (!args || !args->input_callback) { if (!args || !args->input_callback) {
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
if (timeout) { if (abs_timeout) {
started = switch_micro_time_now(); abs_started = switch_micro_time_now();
}
if (digit_timeout) {
digit_started = switch_micro_time_now();
} }
while (switch_channel_ready(channel)) { while (switch_channel_ready(channel)) {
switch_frame_t *read_frame = NULL; switch_frame_t *read_frame = NULL;
switch_event_t *event; switch_event_t *event;
@ -841,9 +843,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
break; break;
} }
if (timeout) { if (abs_timeout) {
elapsed = (uint32_t) ((switch_micro_time_now() - started) / 1000); abs_elapsed = (uint32_t) ((switch_micro_time_now() - abs_started) / 1000);
if (elapsed >= timeout) { if (abs_elapsed >= abs_timeout) {
status = SWITCH_STATUS_TIMEOUT;
break;
}
}
if (digit_timeout) {
digit_elapsed = (uint32_t) ((switch_micro_time_now() - digit_started) / 1000);
if (digit_elapsed >= digit_timeout) {
status = SWITCH_STATUS_TIMEOUT;
break; break;
} }
} }
@ -855,6 +865,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
if (switch_channel_has_dtmf(channel)) { if (switch_channel_has_dtmf(channel)) {
switch_channel_dequeue_dtmf(channel, &dtmf); switch_channel_dequeue_dtmf(channel, &dtmf);
status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen);
if (digit_timeout) {
digit_started = switch_micro_time_now();
}
} }
if (switch_core_session_dequeue_event(session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) { if (switch_core_session_dequeue_event(session, &event, SWITCH_FALSE) == SWITCH_STATUS_SUCCESS) {

View File

@ -2223,7 +2223,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_soft_hold(switch_core_session_t *sess
if (!switch_strlen_zero(moh) && strcasecmp(moh, "silence")) { if (!switch_strlen_zero(moh) && strcasecmp(moh, "silence")) {
switch_ivr_play_file(session, NULL, moh, &args); switch_ivr_play_file(session, NULL, moh, &args);
} else { } else {
switch_ivr_collect_digits_callback(session, &args, 0); switch_ivr_collect_digits_callback(session, &args, 0, 0);
} }
if (moh_br) { if (moh_br) {