]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
answer tweak
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 5 Dec 2006 23:08:14 +0000 (23:08 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 5 Dec 2006 23:08:14 +0000 (23:08 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3549 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_channel.h
src/mod/endpoints/mod_sofia/mod_sofia.c
src/switch_channel.c

index 5a473493bf86026bdb4bd0719347c9b892777f30..6b988d33f9d2addee340882fefbfefb6483f5699 100644 (file)
@@ -274,6 +274,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *
                                                                                                                                const char *file,
                                                                                                                                const char *func,
                                                                                                                                int line);
+
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel,
+                                                                   const char *file,
+                                                                   const char *func,
+                                                                   int line);
+
 /*!
   \brief Answer a channel (initiate/acknowledge a successful connection)
   \param channel channel to answer
@@ -281,6 +287,12 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *
 */
 #define switch_channel_answer(channel) switch_channel_perform_answer(channel, __FILE__, __FUNCTION__, __LINE__)
 
+/*!
+  \brief Mark a channel answered with no indication (for outbound calls)
+  \param channel channel to mark answered
+  \return SWITCH_STATUS_SUCCESS if channel was answered successfully
+*/
+#define switch_channel_mark_answered(channel) switch_channel_perform_mark_answered(channel, __FILE__, __FUNCTION__, __LINE__)
 
 SWITCH_DECLARE(switch_status_t) switch_channel_perform_ringback(switch_channel_t *channel,
                                                                                                                                const char *file,
index 8dfe5b69e63dfb9d777f9501172bd54981c8619f..9aaa97f5bb96ac09ebb5b4e096348d3316314052 100644 (file)
@@ -2721,7 +2721,7 @@ static void sip_i_state(int status,
                        if (r_sdp) {
                                if (switch_test_flag(tech_pvt, TFLAG_NOMEDIA)) {
                                        switch_set_flag_locked(tech_pvt, TFLAG_ANS);
-                                       switch_channel_set_flag(channel, CF_ANSWERED);
+                    switch_channel_mark_answered(channel);
                                        if ((uuid = switch_channel_get_variable(channel, SWITCH_BRIDGE_VARIABLE)) && (other_session = switch_core_session_locate(uuid))) {
                                                other_channel = switch_core_session_get_channel(other_session);
                                                switch_channel_answer(other_channel);
@@ -2749,7 +2749,7 @@ static void sip_i_state(int status,
                                                switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
                                                tech_choose_port(tech_pvt);
                                                activate_rtp(tech_pvt);
-                                               switch_channel_set_flag(channel, CF_ANSWERED);
+                        switch_channel_mark_answered(channel);
                                                return;
                                        }
                                        
@@ -2759,7 +2759,7 @@ static void sip_i_state(int status,
                        } else if (switch_test_flag(tech_pvt, TFLAG_EARLY_MEDIA)) {
                                switch_set_flag_locked(tech_pvt, TFLAG_ANS);
                                switch_channel_set_variable(channel, "endpoint_disposition", "ANSWER");
-                               switch_channel_set_flag(channel, CF_ANSWERED);
+                switch_channel_mark_answered(channel);
                                return;
                        } //else probably an ack
                }
index 7f523a3f6c8815d54f05428abeba8cc64794ef98..2a3fa1d0478ba8f34781681a8daa53a1b43b9ee4 100644 (file)
@@ -1049,6 +1049,41 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_ringback(switch_channel_t
        return status;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_channel_perform_mark_answered(switch_channel_t *channel,
+                                                                   const char *file,
+                                                                   const char *func,
+                                                                   int line)
+{
+    switch_event_t *event;
+
+    assert(channel != NULL);
+
+       if (channel->state >= CS_HANGUP) {
+               return SWITCH_STATUS_FALSE;
+       }
+
+       if (switch_channel_test_flag(channel, CF_ANSWERED)) {
+               return SWITCH_STATUS_SUCCESS;
+       }
+
+    if (channel->caller_profile && channel->caller_profile->times) {
+        switch_mutex_lock(channel->profile_mutex);
+        channel->caller_profile->times->answered = switch_time_now();
+        switch_mutex_unlock(channel->profile_mutex);
+    }
+    
+    switch_channel_set_flag(channel, CF_ANSWERED);
+    
+    if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
+        switch_channel_event_set_data(channel, event);
+        switch_event_fire(&event);
+    }
+
+    switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Channel [%s] has been answered\n", channel->name);
+    
+    return SWITCH_STATUS_SUCCESS;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *channel,
                                                                                                                                const char *file,
                                                                                                                                const char *func,
@@ -1065,21 +1100,7 @@ SWITCH_DECLARE(switch_status_t) switch_channel_perform_answer(switch_channel_t *
        }
 
        if (switch_core_session_answer_channel(channel->session) == SWITCH_STATUS_SUCCESS) {
-               switch_event_t *event;
-
-        if (channel->caller_profile && channel->caller_profile->times) {
-            switch_mutex_lock(channel->profile_mutex);
-            channel->caller_profile->times->answered = switch_time_now();
-            switch_mutex_unlock(channel->profile_mutex);
-        }
-
-               switch_channel_set_flag(channel, CF_ANSWERED);
-               switch_log_printf(SWITCH_CHANNEL_ID_LOG, (char *) file, func, line, SWITCH_LOG_NOTICE, "Answer %s!\n", channel->name);
-               if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_ANSWER) == SWITCH_STATUS_SUCCESS) {
-                       switch_channel_event_set_data(channel, event);
-                       switch_event_fire(&event);
-               }
-               return SWITCH_STATUS_SUCCESS;
+        return switch_channel_perform_mark_answered(channel, file, func, line);
        }
 
        return SWITCH_STATUS_FALSE;