From 32bbdb74a8e4ea25a9bd8abc528c45ffd46eed0e Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 8 Jul 2008 17:27:02 +0000 Subject: [PATCH] add args to sleep git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8930 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_cpp.h | 1 + src/include/switch_ivr.h | 3 +- .../applications/mod_dptools/mod_dptools.c | 30 ++++++---- src/mod/applications/mod_fifo/mod_fifo.c | 2 +- .../mod_voicemail/mod_voicemail.c | 2 +- .../src/org/freeswitch/swig/CoreSession.java | 4 ++ .../org/freeswitch/swig/freeswitchJNI.java | 1 + .../languages/mod_java/switch_swig_wrap.cpp | 24 ++++++++ src/mod/languages/mod_lua/mod_lua_wrap.cpp | 32 ++++++++++ src/mod/languages/mod_perl/freeswitch.pm | 1 + src/mod/languages/mod_perl/mod_perl_wrap.cpp | 50 ++++++++++++++++ src/mod/languages/mod_python/freeswitch.py | 1 + .../languages/mod_python/mod_python_wrap.cpp | 44 ++++++++++++++ .../mod_spidermonkey/mod_spidermonkey.c | 59 +++++++++++++++++++ src/switch_cpp.cpp | 15 +++++ src/switch_ivr.c | 37 +++++++++++- src/switch_ivr_menu.c | 2 +- src/switch_ivr_originate.c | 2 +- 18 files changed, 294 insertions(+), 16 deletions(-) diff --git a/src/include/switch_cpp.h b/src/include/switch_cpp.h index d96ee2d4ff..40ecd37607 100644 --- a/src/include/switch_cpp.h +++ b/src/include/switch_cpp.h @@ -276,6 +276,7 @@ SWITCH_DECLARE(void) consoleCleanLog(char *msg); * */ SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count = 0); + SWITCH_DECLARE(int) sleep(char *file, int ms); /** \brief flush any pending events */ diff --git a/src/include/switch_ivr.h b/src/include/switch_ivr.h index 323e84c9b1..aaa0a5eeb9 100644 --- a/src/include/switch_ivr.h +++ b/src/include/switch_ivr.h @@ -107,9 +107,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_parse_next_event(switch_core_session_ \brief Wait for time to pass for a specified number of milliseconds \param session the session to wait for. \param ms the number of milliseconds + \param args arguements to pass for callbacks etc \return SWITCH_STATUS_SUCCESS if the channel is still up */ -SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms); +SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args); SWITCH_DECLARE(switch_status_t) switch_ivr_park(switch_core_session_t *session, switch_input_args_t *args); diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index bf1846bbd1..792d626e87 100644 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -586,16 +586,6 @@ SWITCH_STANDARD_APP(sched_broadcast_function) } } -SWITCH_STANDARD_APP(sleep_function) -{ - if (switch_strlen_zero(data)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No timeout specified.\n"); - } else { - uint32_t ms = atoi(data); - switch_ivr_sleep(session, ms); - } -} - SWITCH_STANDARD_APP(delay_function) { uint32_t len = 0; @@ -1323,6 +1313,26 @@ static switch_status_t on_dtmf(switch_core_session_t *session, void *input, swit return SWITCH_STATUS_SUCCESS; } + +SWITCH_STANDARD_APP(sleep_function) +{ + if (switch_strlen_zero(data)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No timeout specified.\n"); + } else { + uint32_t ms = atoi(data); + char buf[10]; + switch_input_args_t args = { 0 }; + + args.input_callback = on_dtmf; + args.buf = buf; + args.buflen = sizeof(buf); + + switch_ivr_sleep(session, ms, &args); + } +} + + + SWITCH_STANDARD_APP(clear_speech_cache_function) { switch_ivr_clear_speech_cache(session); diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 8ac15ceeee..17e02a8278 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -855,7 +855,7 @@ SWITCH_STANDARD_APP(fifo_function) if (announce) { switch_ivr_play_file(session, NULL, announce, NULL); } else { - switch_ivr_sleep(session, 500); + switch_ivr_sleep(session, 500, NULL); } diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index e840a606a7..9f95c4a833 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -1314,7 +1314,7 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro status = switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, &args); while (switch_channel_ready(channel)) { - switch_ivr_sleep(session, 100); + switch_ivr_sleep(session, 100, NULL); switch (vm_check_state) { case VM_CHECK_START: diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java index 5dc4233866..4eb473276b 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java @@ -209,6 +209,10 @@ public class CoreSession { return freeswitchJNI.CoreSession_streamFile__SWIG_1(swigCPtr, this, file); } + public int sleep(String file, int ms) { + return freeswitchJNI.CoreSession_sleep(swigCPtr, this, file, ms); + } + public int flushEvents() { return freeswitchJNI.CoreSession_flushEvents(swigCPtr, this); } diff --git a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java index c6ffd5ec29..3ad0f37e33 100644 --- a/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java +++ b/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java @@ -120,6 +120,7 @@ class freeswitchJNI { public final static native String CoreSession_playAndGetDigits(long jarg1, CoreSession jarg1_, int jarg2, int jarg3, int jarg4, int jarg5, String jarg6, String jarg7, String jarg8, String jarg9); public final static native int CoreSession_streamFile__SWIG_0(long jarg1, CoreSession jarg1_, String jarg2, int jarg3); public final static native int CoreSession_streamFile__SWIG_1(long jarg1, CoreSession jarg1_, String jarg2); + public final static native int CoreSession_sleep(long jarg1, CoreSession jarg1_, String jarg2, int jarg3); public final static native int CoreSession_flushEvents(long jarg1, CoreSession jarg1_); public final static native int CoreSession_flushDigits(long jarg1, CoreSession jarg1_); public final static native int CoreSession_setAutoHangup(long jarg1, CoreSession jarg1_, boolean jarg2); diff --git a/src/mod/languages/mod_java/switch_swig_wrap.cpp b/src/mod/languages/mod_java/switch_swig_wrap.cpp index c4af8353b5..bbc4247a94 100644 --- a/src/mod/languages/mod_java/switch_swig_wrap.cpp +++ b/src/mod/languages/mod_java/switch_swig_wrap.cpp @@ -2376,6 +2376,30 @@ SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1stre } +SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1sleep(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jint jarg3) { + jint jresult = 0 ; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + int result; + + (void)jenv; + (void)jcls; + (void)jarg1_; + arg1 = *(CoreSession **)&jarg1; + arg2 = 0; + if (jarg2) { + arg2 = (char *)jenv->GetStringUTFChars(jarg2, 0); + if (!arg2) return 0; + } + arg3 = (int)jarg3; + result = (int)(arg1)->sleep(arg2,arg3); + jresult = (jint)result; + if (arg2) jenv->ReleaseStringUTFChars(jarg2, (const char *)arg2); + return jresult; +} + + SWIGEXPORT jint JNICALL Java_org_freeswitch_swig_freeswitchJNI_CoreSession_1flushEvents(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) { jint jresult = 0 ; CoreSession *arg1 = (CoreSession *) 0 ; diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index 212f907d21..48854f5126 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -5476,6 +5476,37 @@ static int _wrap_CoreSession_streamFile(lua_State* L) { } +static int _wrap_CoreSession_sleep(lua_State* L) { + int SWIG_arg = -1; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + int result; + + SWIG_check_num_args("sleep",3,3) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("sleep",1,"CoreSession *"); + if(!lua_isstring(L,2)) SWIG_fail_arg("sleep",2,"char *"); + if(!lua_isnumber(L,3)) SWIG_fail_arg("sleep",3,"int"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_CoreSession,0))){ + SWIG_fail_ptr("CoreSession_sleep",1,SWIGTYPE_p_CoreSession); + } + + arg2 = (char *)lua_tostring(L, 2); + arg3 = (int)lua_tonumber(L, 3); + result = (int)(arg1)->sleep(arg2,arg3); + SWIG_arg=0; + lua_pushnumber(L, (lua_Number) result); SWIG_arg++; + return SWIG_arg; + + if(0) SWIG_fail; + +fail: + lua_error(L); + return SWIG_arg; +} + + static int _wrap_CoreSession_flushEvents(lua_State* L) { int SWIG_arg = -1; CoreSession *arg1 = (CoreSession *) 0 ; @@ -6081,6 +6112,7 @@ static swig_lua_method swig_CoreSession_methods[] = { {"read", _wrap_CoreSession_read}, {"playAndGetDigits", _wrap_CoreSession_playAndGetDigits}, {"streamFile", _wrap_CoreSession_streamFile}, + {"sleep", _wrap_CoreSession_sleep}, {"flushEvents", _wrap_CoreSession_flushEvents}, {"flushDigits", _wrap_CoreSession_flushDigits}, {"setAutoHangup", _wrap_CoreSession_setAutoHangup}, diff --git a/src/mod/languages/mod_perl/freeswitch.pm b/src/mod/languages/mod_perl/freeswitch.pm index 097cfa7937..5eb1ecc82b 100644 --- a/src/mod/languages/mod_perl/freeswitch.pm +++ b/src/mod/languages/mod_perl/freeswitch.pm @@ -372,6 +372,7 @@ sub DESTROY { *read = *freeswitchc::CoreSession_read; *playAndGetDigits = *freeswitchc::CoreSession_playAndGetDigits; *streamFile = *freeswitchc::CoreSession_streamFile; +*sleep = *freeswitchc::CoreSession_sleep; *flushEvents = *freeswitchc::CoreSession_flushEvents; *flushDigits = *freeswitchc::CoreSession_flushDigits; *setAutoHangup = *freeswitchc::CoreSession_setAutoHangup; diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index 326c65e2d8..5d7497e7a7 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -7312,6 +7312,55 @@ XS(_wrap_CoreSession_streamFile) { } +XS(_wrap_CoreSession_sleep) { + { + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; + int argvi = 0; + dXSARGS; + + if ((items < 3) || (items > 3)) { + SWIG_croak("Usage: CoreSession_sleep(self,file,ms);"); + } + res1 = SWIG_ConvertPtr(ST(0), &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sleep" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(ST(1), &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sleep" "', argument " "2"" of type '" "char *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + ecode3 = SWIG_AsVal_int SWIG_PERL_CALL_ARGS_2(ST(2), &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_sleep" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); + result = (int)(arg1)->sleep(arg2,arg3); + ST(argvi) = SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(result)); argvi++ ; + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + + XSRETURN(argvi); + fail: + + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + + SWIG_croak_null(); + } +} + + XS(_wrap_CoreSession_flushEvents) { { CoreSession *arg1 = (CoreSession *) 0 ; @@ -9331,6 +9380,7 @@ static swig_command_info swig_commands[] = { {"freeswitchc::CoreSession_read", _wrap_CoreSession_read}, {"freeswitchc::CoreSession_playAndGetDigits", _wrap_CoreSession_playAndGetDigits}, {"freeswitchc::CoreSession_streamFile", _wrap_CoreSession_streamFile}, +{"freeswitchc::CoreSession_sleep", _wrap_CoreSession_sleep}, {"freeswitchc::CoreSession_flushEvents", _wrap_CoreSession_flushEvents}, {"freeswitchc::CoreSession_flushDigits", _wrap_CoreSession_flushDigits}, {"freeswitchc::CoreSession_setAutoHangup", _wrap_CoreSession_setAutoHangup}, diff --git a/src/mod/languages/mod_python/freeswitch.py b/src/mod/languages/mod_python/freeswitch.py index 495aa59237..a299a79f04 100644 --- a/src/mod/languages/mod_python/freeswitch.py +++ b/src/mod/languages/mod_python/freeswitch.py @@ -247,6 +247,7 @@ class CoreSession(_object): def read(*args): return _freeswitch.CoreSession_read(*args) def playAndGetDigits(*args): return _freeswitch.CoreSession_playAndGetDigits(*args) def streamFile(*args): return _freeswitch.CoreSession_streamFile(*args) + def sleep(*args): return _freeswitch.CoreSession_sleep(*args) def flushEvents(*args): return _freeswitch.CoreSession_flushEvents(*args) def flushDigits(*args): return _freeswitch.CoreSession_flushDigits(*args) def setAutoHangup(*args): return _freeswitch.CoreSession_setAutoHangup(*args) diff --git a/src/mod/languages/mod_python/mod_python_wrap.cpp b/src/mod/languages/mod_python/mod_python_wrap.cpp index 7dfcdb65a5..bec852d610 100644 --- a/src/mod/languages/mod_python/mod_python_wrap.cpp +++ b/src/mod/languages/mod_python/mod_python_wrap.cpp @@ -7354,6 +7354,49 @@ fail: } +SWIGINTERN PyObject *_wrap_CoreSession_sleep(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { + PyObject *resultobj = 0; + CoreSession *arg1 = (CoreSession *) 0 ; + char *arg2 = (char *) 0 ; + int arg3 ; + int result; + void *argp1 = 0 ; + int res1 = 0 ; + int res2 ; + char *buf2 = 0 ; + int alloc2 = 0 ; + int val3 ; + int ecode3 = 0 ; + PyObject * obj0 = 0 ; + PyObject * obj1 = 0 ; + PyObject * obj2 = 0 ; + + if (!PyArg_ParseTuple(args,(char *)"OOO:CoreSession_sleep",&obj0,&obj1,&obj2)) SWIG_fail; + res1 = SWIG_ConvertPtr(obj0, &argp1,SWIGTYPE_p_CoreSession, 0 | 0 ); + if (!SWIG_IsOK(res1)) { + SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CoreSession_sleep" "', argument " "1"" of type '" "CoreSession *""'"); + } + arg1 = reinterpret_cast< CoreSession * >(argp1); + res2 = SWIG_AsCharPtrAndSize(obj1, &buf2, NULL, &alloc2); + if (!SWIG_IsOK(res2)) { + SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "CoreSession_sleep" "', argument " "2"" of type '" "char *""'"); + } + arg2 = reinterpret_cast< char * >(buf2); + ecode3 = SWIG_AsVal_int(obj2, &val3); + if (!SWIG_IsOK(ecode3)) { + SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "CoreSession_sleep" "', argument " "3"" of type '" "int""'"); + } + arg3 = static_cast< int >(val3); + result = (int)(arg1)->sleep(arg2,arg3); + resultobj = SWIG_From_int(static_cast< int >(result)); + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return resultobj; +fail: + if (alloc2 == SWIG_NEWOBJ) delete[] buf2; + return NULL; +} + + SWIGINTERN PyObject *_wrap_CoreSession_flushEvents(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { PyObject *resultobj = 0; CoreSession *arg1 = (CoreSession *) 0 ; @@ -8540,6 +8583,7 @@ static PyMethodDef SwigMethods[] = { { (char *)"CoreSession_read", _wrap_CoreSession_read, METH_VARARGS, NULL}, { (char *)"CoreSession_playAndGetDigits", _wrap_CoreSession_playAndGetDigits, METH_VARARGS, NULL}, { (char *)"CoreSession_streamFile", _wrap_CoreSession_streamFile, METH_VARARGS, NULL}, + { (char *)"CoreSession_sleep", _wrap_CoreSession_sleep, METH_VARARGS, NULL}, { (char *)"CoreSession_flushEvents", _wrap_CoreSession_flushEvents, METH_VARARGS, NULL}, { (char *)"CoreSession_flushDigits", _wrap_CoreSession_flushDigits, METH_VARARGS, NULL}, { (char *)"CoreSession_setAutoHangup", _wrap_CoreSession_setAutoHangup, METH_VARARGS, NULL}, diff --git a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c index dbdad5d066..8251ad3c59 100644 --- a/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c +++ b/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c @@ -1689,6 +1689,64 @@ static JSBool session_streamfile(JSContext * cx, JSObject * obj, uintN argc, jsv return JS_TRUE; } + + +static JSBool session_sleep(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval) +{ + struct js_session *jss = JS_GetPrivate(cx, obj); + switch_channel_t *channel; + void *bp = NULL; + int len = 0; + switch_input_callback_function_t dtmf_func = NULL; + struct input_callback_state cb_state = { 0 }; + JSFunction *function; + switch_input_args_t args = { 0 }; + int32 ms; + + METHOD_SANITY_CHECK(); + channel = switch_core_session_get_channel(jss->session); + CHANNEL_SANITY_CHECK(); + CHANNEL_MEDIA_SANITY_CHECK(); + + if (argc > 0) { + JS_ValueToInt32(cx, argv[0], &ms); + if (ms <= 0) { + return JS_FALSE; + } + } + + if (argc > 1) { + if ((function = JS_ValueToFunction(cx, argv[1]))) { + memset(&cb_state, 0, sizeof(cb_state)); + cb_state.function = function; + + if (argc > 2) { + cb_state.arg = argv[2]; + } + + cb_state.session_state = jss; + cb_state.cx = cx; + cb_state.obj = obj; + dtmf_func = js_stream_input_callback; + bp = &cb_state; + len = sizeof(cb_state); + } + } + + cb_state.ret = BOOLEAN_TO_JSVAL(JS_FALSE); + cb_state.saveDepth = JS_SuspendRequest(cx); + args.input_callback = dtmf_func; + args.buf = bp; + args.buflen = len; + check_hangup_hook(jss); + switch_ivr_sleep(jss->session, ms, &args); + check_hangup_hook(jss); + JS_ResumeRequest(cx, cb_state.saveDepth); + *rval = cb_state.ret; + + return JS_TRUE; +} + static JSBool session_set_variable(JSContext * cx, JSObject * obj, uintN argc, jsval * argv, jsval * rval) { struct js_session *jss = JS_GetPrivate(cx, obj); @@ -2488,6 +2546,7 @@ static JSFunctionSpec session_methods[] = { {"sendEvent", session_send_event, 0}, {"hangup", session_hangup, 0}, {"execute", session_execute, 0}, + {"sleep", session_sleep, 1}, {0} }; diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp index 7a2bd01eb6..e7170c1bde 100644 --- a/src/switch_cpp.cpp +++ b/src/switch_cpp.cpp @@ -804,6 +804,21 @@ SWITCH_DECLARE(int) CoreSession::streamFile(char *file, int starting_sample_coun } +SWITCH_DECLARE(int) CoreSession::sleep(char *file, int ms) { + + switch_status_t status; + + this_check(-1); + sanity_check(-1); + + begin_allow_threads(); + status = switch_ivr_sleep(session, ms, ap); + end_allow_threads(); + + return status == SWITCH_STATUS_SUCCESS ? 1 : 0; + +} + SWITCH_DECLARE(bool) CoreSession::ready() { this_check(false); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 8cc6952923..6aff95885d 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -38,7 +38,7 @@ #include #include "stfu.h" -SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms) +SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, uint32_t ms, switch_input_args_t *args) { switch_channel_t *channel = switch_core_session_get_channel(session); switch_status_t status = SWITCH_STATUS_SUCCESS; @@ -59,6 +59,41 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_sleep(switch_core_session_t *session, if (now > done || left <= 0) { break; } + + if (args && (args->input_callback || args->buf || args->buflen)) { + switch_dtmf_t dtmf; + + /* + dtmf handler function you can hook up to be executed when a digit is dialed during playback + if you return anything but SWITCH_STATUS_SUCCESS the playback will stop. + */ + if (switch_channel_has_dtmf(channel)) { + if (!args->input_callback && !args->buf) { + status = SWITCH_STATUS_BREAK; + break; + } + switch_channel_dequeue_dtmf(channel, &dtmf); + if (args->input_callback) { + status = args->input_callback(session, (void *) &dtmf, SWITCH_INPUT_TYPE_DTMF, args->buf, args->buflen); + } else { + switch_copy_string((char *) args->buf, (void *) &dtmf, args->buflen); + status = SWITCH_STATUS_BREAK; + } + } + + if (args->input_callback) { + switch_event_t *event = NULL; + + if (switch_core_session_dequeue_event(session, &event) == SWITCH_STATUS_SUCCESS) { + status = args->input_callback(session, event, SWITCH_INPUT_TYPE_EVENT, args->buf, args->buflen); + switch_event_destroy(&event); + } + } + + if (status != SWITCH_STATUS_SUCCESS) { + break; + } + } if (switch_channel_test_flag(channel, CF_PROXY_MODE)) { switch_yield(1000); diff --git a/src/switch_ivr_menu.c b/src/switch_ivr_menu.c index 1c36e26078..7211687448 100644 --- a/src/switch_ivr_menu.c +++ b/src/switch_ivr_menu.c @@ -501,7 +501,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_execute(switch_core_session_t *s } errs++; if (status == SWITCH_STATUS_SUCCESS) { - status = switch_ivr_sleep(session, 1000); + status = switch_ivr_sleep(session, 1000, NULL); } /* breaks are ok too */ if (SWITCH_STATUS_IS_BREAK(status)) { diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index 13f5910547..da4ec7a368 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -40,7 +40,7 @@ static switch_status_t originate_on_consume_media_transmit(switch_core_session_t if (!switch_channel_test_flag(channel, CF_PROXY_MODE)) { while (switch_channel_get_state(channel) == CS_CONSUME_MEDIA && !switch_channel_test_flag(channel, CF_TAGGED)) { - switch_ivr_sleep(session, 10); + switch_ivr_sleep(session, 10, NULL); } }