]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
use channel flag to tell when to read from channel during some stuff
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 9 Jun 2006 22:59:13 +0000 (22:59 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 9 Jun 2006 22:59:13 +0000 (22:59 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1590 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/include/switch_types.h
src/mod/applications/mod_ivrtest/mod_ivrtest.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_core.c
src/switch_ivr.c

index f0f75623eec365c9d2daed26af8b0467bd97caa6..15f13bb07b0db7086251e954cb19fa105e67f734 100644 (file)
@@ -72,17 +72,15 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
   \param terminators digits to end the collection
   \param terminator actual digit that caused the collection to end (if any)
   \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.
 */
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
-                                                                                                                         char *buf,
-                                                                                                                         unsigned int buflen,
-                                                                                                                         unsigned int maxdigits,
-                                                                                                                         const char *terminators,
-                                                                                                                         char *terminator,
-                                                                                                                         unsigned int timeout,
-                                                              unsigned int poll_channel);
+                                                                                                                               char *buf,
+                                                                                                                               unsigned int buflen,
+                                                                                                                               unsigned int maxdigits,
+                                                                                                                               const char *terminators,
+                                                                                                                               char *terminator,
+                                                                                                                               unsigned int timeout);
        
 /*!
   \brief play a file from the disk to the session
index 51b8bbd0ef0334e2463de9527c2c884572a5a1c8..072812a13a9c4b2143d505b105ec4d49d8564c2b 100644 (file)
@@ -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_BRIDGED             = (1 <<  7) - Channel in a bridge
 CF_HOLD                        = (1 <<  8) - Channel is on hold
+CF_SERVICE             = (1 <<  9) - Channel has a service thread
 </pre>
  */
 
@@ -356,7 +357,8 @@ typedef enum {
        CF_ACCEPT_CNG   = (1 <<  5),
        CF_LOCK_THREAD  = (1 <<  6),
        CF_BRIDGED              = (1 <<  7),
-       CF_HOLD                 = (1 <<  8)
+       CF_HOLD                 = (1 <<  8),
+       CF_SERVICE              = (1 <<  9)
 } switch_channel_flag_t;
 
 
index 9ad8971d3ef6fefc7df80b78199f209cdfabe976..aad96294acea9b949f5040fef97cd62855b0981e 100644 (file)
@@ -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);
                        break;
                }
index c0904cd7d875a02c91266c3bd095d5485e9c3ac2..be31afda529ca0e80bd63e3851fa0538ceab5454 100644 (file)
@@ -559,8 +559,6 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval
        char *buf;
        int digits;
        int32 timeout = 5000;
-       int32 poll_chan = 1;
-       
        
        if (argc > 0) {
                char term;
@@ -571,11 +569,9 @@ static JSBool session_get_digits(JSContext *cx, JSObject *obj, uintN argc, jsval
                if (argc > 2) {
                        JS_ValueToInt32(cx, argv[2], &timeout);
                }
-               if (argc > 3) {
-                       JS_ValueToInt32(cx, argv[3], &poll_chan);
-               }
+
                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) );
                return JS_TRUE;
        }
index 511245a748f7bed02e7cd69898bda3afe758c112..d78c322eda21041f5ea85f356c97ff7fa801f4ae 100644 (file)
@@ -743,6 +743,7 @@ static void *switch_core_service_thread(switch_thread_t *thread, void *obj)
        channel = switch_core_session_get_channel(session);
        assert(channel != NULL);
 
+       switch_channel_set_flag(channel, CF_SERVICE);
        while (data->running > 0) {
                switch (switch_core_session_read_frame(session, &read_frame, -1, stream_id)) {
                case SWITCH_STATUS_SUCCESS:
@@ -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;
        return NULL;
 }
index 902a4411157c9536d81dbdba0c7f721691a64af5..fa029fa88abb86706480f9a5dfd90887474343d4 100644 (file)
@@ -63,7 +63,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
                        break;
                }
 
-               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)) {
                        break;
@@ -75,14 +79,12 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_callback(switch_core_s
 
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_session_t *session,
-                                                                                                                         char *buf,
-                                                                                                                         unsigned int buflen,
-                                                                                                                         unsigned int maxdigits,
-                                                                                                                         const char *terminators,
-                                                                                                                         char *terminator,
-                                                                                                                         unsigned int timeout,
-                                                                                                                         unsigned int poll_channel
-                                                                                                                         )
+                                                                                                                               char *buf,
+                                                                                                                               unsigned int buflen,
+                                                                                                                               unsigned int maxdigits,
+                                                                                                                               const char *terminators,
+                                                                                                                               char *terminator,
+                                                                                                                               unsigned int timeout)
 {
        unsigned int i = 0, x =  (unsigned int) strlen(buf);
        switch_channel_t *channel;
@@ -135,14 +137,14 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_collect_digits_count(switch_core_sess
                                }
                        }
                }
-               if (poll_channel) {
+
+               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)) {
                                break;
                        }
-               } else {
-                       switch_yield(1000);
                }
        }