]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
openzap: handle loop requests
authorMoises Silva <moy@sangoma.com>
Thu, 20 May 2010 23:30:01 +0000 (19:30 -0400)
committerMoises Silva <moy@sangoma.com>
Thu, 20 May 2010 23:30:18 +0000 (19:30 -0400)
libs/openzap/src/include/zap_types.h
libs/openzap/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c
libs/openzap/src/ozmod/ozmod_wanpipe/ozmod_wanpipe.c
libs/openzap/src/zap_io.c

index 1e9a00502ded6eaa20630a8adffe436ef50c5021..810a365e19be76c7775de272a81d36492c11d4af 100644 (file)
@@ -360,7 +360,8 @@ typedef enum {
 } zap_channel_state_t;
 #define CHANNEL_STATE_STRINGS "DOWN", "HOLD", "SUSPENDED", "DIALTONE", "COLLECT", \
                "RING", "BUSY", "ATTN", "GENRING", "DIALING", "GET_CALLERID", "CALLWAITING", \
-               "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", "HANGUP", "HANGUP_COMPLETE", "INVALID"
+               "RESTART", "PROGRESS", "PROGRESS_MEDIA", "UP", "IDLE", "TERMINATING", "CANCEL", \
+               "HANGUP", "HANGUP_COMPLETE", "IN_LOOP", "INVALID"
 ZAP_STR2ENUM_P(zap_str2zap_channel_state, zap_channel_state2str, zap_channel_state_t)
 
 typedef enum {
index 12a5e872d7907545eef185e4a1aff86cb4e903f3..ddf74cc032960c92dff0613d25bc3f00b1ba8cce 100644 (file)
@@ -903,11 +903,12 @@ static void handle_call_loop_start(zap_span_t *span, sangomabc_connection_t *mco
        }
 
        zap_set_state_r(zchan, ZAP_CHANNEL_STATE_IN_LOOP, 0, res);
-       if (res != ZAP_SUCCESS) {
+       if (res != ZAP_STATE_CHANGE_SUCCESS) {
                zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel to IN_LOOP, loop will fail\n");
                zap_channel_done(zchan);
                return;
        }
+       zap_log(ZAP_LOG_DEBUG, "%d:%d starting loop\n", zchan->span_id, zchan->chan_id);
        zap_channel_command(zchan, ZAP_COMMAND_ENABLE_LOOP, NULL);
 }
 
@@ -927,6 +928,9 @@ static void handle_call_loop_stop(zap_span_t *span, sangomabc_connection_t *mcon
        /* even when we did not sent a msg we set this flag to avoid sending call stop in the DOWN state handler */
        zap_set_flag(zchan, SFLAG_SENT_FINAL_MSG);
        zap_set_state_r(zchan, ZAP_CHANNEL_STATE_DOWN, 0, res);
+       if (res != ZAP_STATE_CHANGE_SUCCESS) {
+               zap_log(ZAP_LOG_CRIT, "yay, could not set the state of the channel from IN_LOOP to DOWN\n");
+       }
 }
 
 /**
@@ -1163,33 +1167,35 @@ static __inline__ void state_advance(zap_channel_t *zchan)
        switch (zchan->state) {
        case ZAP_CHANNEL_STATE_DOWN:
                {
-                       /* Always try to clear the GRID */
-                       release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1);
-
-                       if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) {
-                               zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
-
-                               if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) {
-                                       sangomabc_exec_command(mcon,
-                                                                                  zchan->physical_span_id-1,
-                                                                                  zchan->physical_chan_id-1,
-                                                                                  0,
-                                                                                  SIGBOOST_EVENT_CALL_START_NACK_ACK,
-                                                                                  0, 0);
-                                       
-                               } else {
-                                       sangomabc_exec_command(mcon,
-                                                                                  zchan->physical_span_id-1,
-                                                                                  zchan->physical_chan_id-1,
-                                                                                  0,
-                                                                                  SIGBOOST_EVENT_CALL_STOPPED_ACK,
-                                                                                  0, 0);
+                       if (zchan->last_state == ZAP_CHANNEL_STATE_IN_LOOP) {
+                               /* nothing to do after a loop */
+                               zap_log(ZAP_LOG_DEBUG, "%d:%d terminating loop\n", zchan->span_id, zchan->chan_id);
+                       } else {
+                               /* Always try to clear the GRID */
+                               release_request_id_span_chan(zchan->physical_span_id-1, zchan->physical_chan_id-1);
+
+                               if (!zap_test_sflag(zchan, SFLAG_SENT_FINAL_MSG)) {
+                                       zap_set_sflag_locked(zchan, SFLAG_SENT_FINAL_MSG);
+
+                                       if (zchan->call_data && ((uint32_t)(intptr_t)zchan->call_data == SIGBOOST_EVENT_CALL_START_NACK)) {
+                                               sangomabc_exec_command(mcon,
+                                                                                          zchan->physical_span_id-1,
+                                                                                          zchan->physical_chan_id-1,
+                                                                                          0,
+                                                                                          SIGBOOST_EVENT_CALL_START_NACK_ACK,
+                                                                                          0, 0);
+                                               
+                                       } else {
+                                               sangomabc_exec_command(mcon,
+                                                                                          zchan->physical_span_id-1,
+                                                                                          zchan->physical_chan_id-1,
+                                                                                          0,
+                                                                                          SIGBOOST_EVENT_CALL_STOPPED_ACK,
+                                                                                          0, 0);
+                                       }
                                }
-                       }
-
-                       if (zchan->extra_id) {
-                               zchan->extra_id = 0;
-                       }
+                       } 
+                       zchan->extra_id = 0;
                        zchan->sflags = 0;
                        zchan->call_data = NULL;
                        zap_channel_done(zchan);
index a896f1a169e5707e300c87dc8278c7532bd9a2fc..2c8068e523c9400630148b279eaaaec9ca32b666 100644 (file)
@@ -609,6 +609,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command)
                        }
 #endif         
                }
+               break;
        case ZAP_COMMAND_DISABLE_LOOP:
                {
 #ifdef WP_API_FEATURE_LOOP
@@ -619,6 +620,7 @@ static ZIO_COMMAND_FUNCTION(wanpipe_command)
                        }
 #endif  
                }
+               break;
        case ZAP_COMMAND_SET_INTERVAL: 
                {
                        err=sangoma_tdm_set_usr_period(zchan->sockfd, &tdm_api, ZAP_COMMAND_OBJ_INT);
index 38166d26d47f44bc24689dea979eca227328845e..058cbc921c74bd401663f28d84e8ca2a7e2caf4f 100644 (file)
@@ -948,11 +948,15 @@ OZ_DECLARE(zap_status_t) zap_channel_set_state(zap_channel_t *zchan, zap_channel
        int ok = 1;
        
        if (!zap_test_flag(zchan, ZAP_CHANNEL_READY)) {
+               zap_log(ZAP_LOG_ERROR, "%d:%d Cannot set state in channel that is not ready\n",
+                               zchan->span_id, zchan->chan_id);
                return ZAP_FAIL;
        }
 
        if (zap_test_flag(zchan->span, ZAP_SPAN_SUSPENDED)) {
                if (state != ZAP_CHANNEL_STATE_RESTART && state != ZAP_CHANNEL_STATE_DOWN) {
+                       zap_log(ZAP_LOG_ERROR, "%d:%d Cannot set state in channel that is suspended\n",
+                               zchan->span_id, zchan->chan_id);
                        return ZAP_FAIL;
                }
        }