[Freeswitch-svn] [commit] r8930 - in freeswitch/trunk/src: . include mod/applications/mod_dptools mod/applications/mod_fifo mod/applications/mod_voicemail mod/languages/mod_java mod/languages/mod_java/src/org/freeswitch/swig mod/languages/mod_lua mod/languages/mod_perl mod/languages/mod_python mod/languages/mod_spidermonkey

Freeswitch SVN anthm at freeswitch.org
Tue Jul 8 13:27:03 EDT 2008


Author: anthm
Date: Tue Jul  8 13:27:02 2008
New Revision: 8930

Modified:
   freeswitch/trunk/src/include/switch_cpp.h
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java
   freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java
   freeswitch/trunk/src/mod/languages/mod_java/switch_swig_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm
   freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py
   freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
   freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
   freeswitch/trunk/src/switch_cpp.cpp
   freeswitch/trunk/src/switch_ivr.c
   freeswitch/trunk/src/switch_ivr_menu.c
   freeswitch/trunk/src/switch_ivr_originate.c

Log:
add args to sleep

Modified: freeswitch/trunk/src/include/switch_cpp.h
==============================================================================
--- freeswitch/trunk/src/include/switch_cpp.h	(original)
+++ freeswitch/trunk/src/include/switch_cpp.h	Tue Jul  8 13:27:02 2008
@@ -276,6 +276,7 @@
 	 *
 	 */
 		 SWITCH_DECLARE(int) streamFile(char *file, int starting_sample_count = 0);
+		 SWITCH_DECLARE(int) sleep(char *file, int ms);
 
 	/** \brief flush any pending events
 	 */

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Tue Jul  8 13:27:02 2008
@@ -107,9 +107,10 @@
   \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);
 

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue Jul  8 13:27:02 2008
@@ -586,16 +586,6 @@
 	}
 }
 
-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 @@
 	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);

Modified: freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_fifo/mod_fifo.c	Tue Jul  8 13:27:02 2008
@@ -855,7 +855,7 @@
 				if (announce) {
 					switch_ivr_play_file(session, NULL, announce, NULL);
 				} else {
-					switch_ivr_sleep(session, 500);
+					switch_ivr_sleep(session, 500, NULL);
 				}
 
 

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Tue Jul  8 13:27:02 2008
@@ -1314,7 +1314,7 @@
 	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:

Modified: freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java	(original)
+++ freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/CoreSession.java	Tue Jul  8 13:27:02 2008
@@ -209,6 +209,10 @@
     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);
   }

Modified: freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java	(original)
+++ freeswitch/trunk/src/mod/languages/mod_java/src/org/freeswitch/swig/freeswitchJNI.java	Tue Jul  8 13:27:02 2008
@@ -120,6 +120,7 @@
   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);

Modified: freeswitch/trunk/src/mod/languages/mod_java/switch_swig_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_java/switch_swig_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_java/switch_swig_wrap.cpp	Tue Jul  8 13:27:02 2008
@@ -2376,6 +2376,30 @@
 }
 
 
+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 ;

Modified: freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_lua/mod_lua_wrap.cpp	Tue Jul  8 13:27:02 2008
@@ -5476,6 +5476,37 @@
 }
 
 
+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 @@
     {"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}, 

Modified: freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm	(original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/freeswitch.pm	Tue Jul  8 13:27:02 2008
@@ -372,6 +372,7 @@
 *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;

Modified: freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_perl/mod_perl_wrap.cpp	Tue Jul  8 13:27:02 2008
@@ -7312,6 +7312,55 @@
 }
 
 
+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 @@
 {"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},

Modified: freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/freeswitch.py	Tue Jul  8 13:27:02 2008
@@ -247,6 +247,7 @@
     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)

Modified: freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp	(original)
+++ freeswitch/trunk/src/mod/languages/mod_python/mod_python_wrap.cpp	Tue Jul  8 13:27:02 2008
@@ -7354,6 +7354,49 @@
 }
 
 
+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 @@
 	 { (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},

Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	(original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c	Tue Jul  8 13:27:02 2008
@@ -1689,6 +1689,64 @@
 	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 @@
 	{"sendEvent", session_send_event, 0},
 	{"hangup", session_hangup, 0},
 	{"execute", session_execute, 0},
+	{"sleep", session_sleep, 1},
 	{0}
 };
 

Modified: freeswitch/trunk/src/switch_cpp.cpp
==============================================================================
--- freeswitch/trunk/src/switch_cpp.cpp	(original)
+++ freeswitch/trunk/src/switch_cpp.cpp	Tue Jul  8 13:27:02 2008
@@ -804,6 +804,21 @@
 
 }
 
+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);

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Jul  8 13:27:02 2008
@@ -38,7 +38,7 @@
 #include <switch_ivr.h>
 #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 @@
 		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);

Modified: freeswitch/trunk/src/switch_ivr_menu.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_menu.c	(original)
+++ freeswitch/trunk/src/switch_ivr_menu.c	Tue Jul  8 13:27:02 2008
@@ -501,7 +501,7 @@
 			}
 			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)) {

Modified: freeswitch/trunk/src/switch_ivr_originate.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_originate.c	(original)
+++ freeswitch/trunk/src/switch_ivr_originate.c	Tue Jul  8 13:27:02 2008
@@ -40,7 +40,7 @@
 
 	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);
 		}
 	}
 



More information about the Freeswitch-svn mailing list