]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add channel logical direction
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 31 Oct 2013 20:28:24 +0000 (15:28 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 31 Oct 2013 20:28:33 +0000 (15:28 -0500)
src/include/switch_caller.h
src/include/switch_channel.h
src/switch_channel.c
src/switch_ivr_bridge.c

index f0dc1c76fef398a29cffab2424ec1d1612b9e58f..1fd5ecbd29e82b61571f032aacada6dbdf675241 100644 (file)
@@ -127,6 +127,7 @@ typedef struct profile_node_s {
        switch_memory_pool_t *pool;
        struct switch_caller_profile *next;
        switch_call_direction_t direction;
+       switch_call_direction_t logical_direction;
        profile_node_t *soft;
        char *uuid_str;
        char *clone_of;
index 234b692114f2158187cd8c9dbe6567512ac5fdb1..9e7c91f9358b038e3542c74758b4dda08b6fd167 100644 (file)
@@ -633,6 +633,7 @@ SWITCH_DECLARE(int) switch_channel_test_app_flag_key(const char *app, switch_cha
 SWITCH_DECLARE(void) switch_channel_set_bridge_time(switch_channel_t *channel);
 SWITCH_DECLARE(void) switch_channel_set_hangup_time(switch_channel_t *channel);
 SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_t *channel);
+SWITCH_DECLARE(switch_call_direction_t) switch_channel_logical_direction(switch_channel_t *channel);
 SWITCH_DECLARE(void) switch_channel_set_direction(switch_channel_t *channel, switch_call_direction_t direction);
 
 SWITCH_DECLARE(switch_core_session_t *) switch_channel_get_session(switch_channel_t *channel);
index aa73b4d2fc5c70643de0e782fa668e7321424889..21b9dedc6f9d100693d01c77a16a3d027fd14b2d 100644 (file)
@@ -139,6 +139,7 @@ typedef enum {
 struct switch_channel {
        char *name;
        switch_call_direction_t direction;
+       switch_call_direction_t logical_direction;
        switch_queue_t *dtmf_queue;
        switch_queue_t *dtmf_log_queue;
        switch_mutex_t*dtmf_mutex;
@@ -393,7 +394,7 @@ SWITCH_DECLARE(switch_channel_timetable_t *) switch_channel_get_timetable(switch
 SWITCH_DECLARE(void) switch_channel_set_direction(switch_channel_t *channel, switch_call_direction_t direction)
 {
        if (!switch_core_session_in_thread(channel->session)) {
-               channel->direction = direction;
+               channel->direction = channel->logical_direction = direction;
        }
 }
 
@@ -402,6 +403,11 @@ SWITCH_DECLARE(switch_call_direction_t) switch_channel_direction(switch_channel_
        return channel->direction;
 }
 
+SWITCH_DECLARE(switch_call_direction_t) switch_channel_logical_direction(switch_channel_t *channel)
+{
+       return channel->logical_direction;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel, switch_call_direction_t direction, switch_memory_pool_t *pool)
 {
        switch_assert(pool != NULL);
@@ -423,7 +429,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_alloc(switch_channel_t **channel,
        switch_mutex_init(&(*channel)->profile_mutex, SWITCH_MUTEX_NESTED, pool);
        (*channel)->hangup_cause = SWITCH_CAUSE_NONE;
        (*channel)->name = "";
-       (*channel)->direction = direction;
+       (*channel)->direction = (*channel)->logical_direction = direction;
        switch_channel_set_variable(*channel, "direction", switch_channel_direction(*channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? "outbound" : "inbound");
 
        return SWITCH_STATUS_SUCCESS;
@@ -1762,6 +1768,20 @@ SWITCH_DECLARE(void) switch_channel_set_flag_value(switch_channel_t *channel, sw
                switch_channel_set_callstate(channel, CCS_RING_WAIT);
        }
 
+       if (flag == CF_DIALPLAN) {
+               if (channel->direction == SWITCH_CALL_DIRECTION_INBOUND) {
+                       channel->logical_direction = SWITCH_CALL_DIRECTION_OUTBOUND;
+                       if (channel->device_node) {
+                               channel->device_node->direction = SWITCH_CALL_DIRECTION_INBOUND;
+                       }
+               } else {
+                       channel->logical_direction = SWITCH_CALL_DIRECTION_INBOUND;
+                       if (channel->device_node) {
+                               channel->device_node->direction = SWITCH_CALL_DIRECTION_OUTBOUND;
+                       }
+               }
+       }
+
        if (HELD) {
                switch_hold_record_t *hr;
                const char *brto = switch_channel_get_partner_uuid(channel);
@@ -1930,6 +1950,15 @@ SWITCH_DECLARE(void) switch_channel_clear_flag(switch_channel_t *channel, switch
        channel->flags[flag] = 0;
        switch_mutex_unlock(channel->flag_mutex);
 
+       if (flag == CF_DIALPLAN) {
+               if (channel->direction == SWITCH_CALL_DIRECTION_OUTBOUND) {
+                       channel->logical_direction = SWITCH_CALL_DIRECTION_OUTBOUND;
+                       if (channel->device_node) {
+                               channel->device_node->direction = SWITCH_CALL_DIRECTION_INBOUND;
+                       }
+               }
+       }
+
        if (ACTIVE) {
                switch_channel_set_callstate(channel, CCS_UNHOLD);
                switch_mutex_lock(channel->profile_mutex);
@@ -2615,6 +2644,7 @@ SWITCH_DECLARE(void) switch_channel_set_caller_profile(switch_channel_t *channel
        switch_assert(caller_profile != NULL);
 
        caller_profile->direction = channel->direction;
+       caller_profile->logical_direction = channel->logical_direction;
        uuid = switch_core_session_get_uuid(channel->session);
 
        if (!caller_profile->uuid || strcasecmp(caller_profile->uuid, uuid)) {
@@ -2697,6 +2727,7 @@ SWITCH_DECLARE(void) switch_channel_set_hunt_caller_profile(switch_channel_t *ch
        channel->caller_profile->hunt_caller_profile = NULL;
        if (channel->caller_profile && caller_profile) {
                caller_profile->direction = channel->direction;
+               caller_profile->logical_direction = channel->logical_direction;
                channel->caller_profile->hunt_caller_profile = caller_profile;
        }
        switch_mutex_unlock(channel->profile_mutex);
@@ -5038,7 +5069,7 @@ static void add_uuid(switch_device_record_t *drec, switch_channel_t *channel)
        node->uuid = switch_core_strdup(drec->pool, switch_core_session_get_uuid(channel->session));
        node->parent = drec;
        node->callstate = channel->callstate;
-       node->direction = channel->direction == SWITCH_CALL_DIRECTION_INBOUND ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND;
+       node->direction = channel->logical_direction == SWITCH_CALL_DIRECTION_INBOUND ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND;
 
        channel->device_node = node;
 
index 356e03f43de930f57502e8935104ef473f822991..089301da0e1fd2c605ad2b1b861317a9269e75c1 100644 (file)
@@ -1695,6 +1695,10 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_uuid_bridge(const char *originator_uu
                                }
                        }
 
+                       if (switch_channel_direction(originatee_channel) == SWITCH_CALL_DIRECTION_OUTBOUND && switch_channel_test_flag(originatee_channel, CF_DIALPLAN)) {
+                               switch_channel_clear_flag(originatee_channel, CF_DIALPLAN);
+                       }
+
                        cleanup_proxy_mode_a(originator_session);
                        cleanup_proxy_mode_a(originatee_session);