[Freeswitch-svn] [commit] r11275 - in freeswitch/trunk/src: . include mod/applications/mod_commands mod/applications/mod_dptools

FreeSWITCH SVN anthm at freeswitch.org
Mon Jan 19 08:10:54 PST 2009


Author: anthm
Date: Mon Jan 19 10:10:54 2009
New Revision: 11275

Log:
pass one on refactor

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_ivr_async.c

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Mon Jan 19 10:10:54 2009
@@ -298,7 +298,8 @@
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
 															   const char *key, const char *tone_spec,
-															   const char *flags, time_t timeout, int hits, const char *app, const char *data);
+															   const char *flags, time_t timeout, int hits, 
+															   const char *app, const char *data, switch_tone_detect_callback_t callback);
 
 
 

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Mon Jan 19 10:10:54 2009
@@ -1343,6 +1343,7 @@
 typedef struct switch_core_port_allocator switch_core_port_allocator_t;
 typedef struct switch_media_bug switch_media_bug_t;
 typedef switch_bool_t (*switch_media_bug_callback_t) (switch_media_bug_t *, void *, switch_abc_type_t);
+typedef switch_bool_t (*switch_tone_detect_callback_t) (switch_core_session_t *, const char *, const char *);
 typedef struct switch_xml_binding switch_xml_binding_t;
 
 typedef switch_status_t (*switch_core_codec_encode_func_t) (switch_codec_t *codec,

Modified: freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_commands/mod_commands.c	Mon Jan 19 10:10:54 2009
@@ -1405,7 +1405,7 @@
 		}
 	}
 
-	switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, hits, argv[5], argv[6]);
+	switch_ivr_tone_detect_session(rsession, argv[1], argv[2], argv[3], to, hits, argv[5], argv[6], NULL);
 	stream->write_function(stream, "+OK Enabling tone detection '%s' '%s' '%s'\n", argv[1], argv[2], argv[3]);
 
   done:

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	Mon Jan 19 10:10:54 2009
@@ -1178,7 +1178,7 @@
 
 SWITCH_STANDARD_APP(fax_detect_session_function)
 {
-	switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, 1, NULL, NULL);
+	switch_ivr_tone_detect_session(session, "fax", "1100.0", "r", 0, 1, NULL, NULL, NULL);
 }
 
 SWITCH_STANDARD_APP(system_session_function)
@@ -1234,7 +1234,7 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Enabling tone detection '%s' '%s'\n", argv[0], argv[1]);
 
-	switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, hits, argv[4], argv[5]);
+	switch_ivr_tone_detect_session(session, argv[0], argv[1], argv[2], to, hits, argv[4], argv[5], NULL);
 }
 
 SWITCH_STANDARD_APP(stop_fax_detect_session_function)

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Mon Jan 19 10:10:54 2009
@@ -1197,6 +1197,8 @@
 	int hits;
 	int sleep;
 	int expires;
+	int once;
+	switch_tone_detect_callback_t callback;
 } switch_tone_detect_t;
 
 typedef struct {
@@ -1211,6 +1213,7 @@
 	switch_tone_container_t *cont = (switch_tone_container_t *) user_data;
 	switch_frame_t *frame = NULL;
 	int i = 0;
+	switch_bool_t rval = SWITCH_TRUE;
 
 	switch (type) {
 	case SWITCH_ABC_TYPE_INIT:
@@ -1264,8 +1267,13 @@
 					if (cont->list[i].hits >= cont->list[i].total_hits) {
 						switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "TONE %s DETECTED\n", cont->list[i].key);
 						cont->list[i].up = 0;
-					
-						if (cont->list[i].app) {
+						if (cont->list[i].once) {
+							rval = SWITCH_FALSE;
+						}
+
+						if (cont->list[i].callback) {
+							rval = cont->list[i].callback(cont->session, cont->list[i].app, cont->list[i].data);
+						} else if (cont->list[i].app) {
 							if (switch_event_create(&event, SWITCH_EVENT_COMMAND) == SWITCH_STATUS_SUCCESS) {
 								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
 								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", cont->list[i].app);
@@ -1278,7 +1286,7 @@
 						if (switch_event_create(&event, SWITCH_EVENT_DETECTED_TONE) == SWITCH_STATUS_SUCCESS) {
 							switch_event_t *dup;
 							switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Detected-Tone", cont->list[i].key);
-
+							
 							if (switch_event_dup(&dup, event) == SWITCH_STATUS_SUCCESS) {
 								switch_event_fire(&dup);
 							}
@@ -1298,7 +1306,7 @@
 	default:
 		break;
 	}
-	return SWITCH_TRUE;
+	return rval;
 }
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_stop_tone_detect_session(switch_core_session_t *session)
@@ -1316,7 +1324,9 @@
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_tone_detect_session(switch_core_session_t *session,
 															   const char *key, const char *tone_spec,
-															   const char *flags, time_t timeout, int hits, const char *app, const char *data)
+															   const char *flags, time_t timeout, 
+															   int hits, const char *app, const char *data, 
+															   switch_tone_detect_callback_t callback)
 {
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
@@ -1395,6 +1405,8 @@
 		cont->list[cont->index].data = switch_core_session_strdup(session, data);
 	}
 
+	cont->list[cont->index].callback = callback;
+
 	if (!hits) hits = 1;
 
 	cont->list[cont->index].hits = 0;
@@ -1410,6 +1422,10 @@
 	if (switch_strlen_zero(flags)) {
 		bflags = SMBF_READ_REPLACE;
 	} else {
+		if (strchr(flags, 'o')) {
+			cont->list[cont->index].once = 1;
+		}
+
 		if (strchr(flags, 'r')) {
 			bflags |= SMBF_READ_REPLACE;
 		} else if (strchr(flags, 'w')) {



More information about the Freeswitch-svn mailing list