]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
change CS_DONE to CS_DESTROY and add state handler for destroy and tear down critical...
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 10 Apr 2009 17:43:18 +0000 (17:43 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 10 Apr 2009 17:43:18 +0000 (17:43 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12986 d0543943-73ff-0310-b7d9-9358b9ac24b2

19 files changed:
src/include/switch_core.h
src/include/switch_module_interfaces.h
src/include/switch_types.h
src/mod/endpoints/mod_alsa/mod_alsa.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_loopback/mod_loopback.c
src/mod/endpoints/mod_opal/mod_opal.cpp
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/mod/endpoints/mod_reference/mod_reference.c
src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_unicall/mod_unicall.c
src/switch_channel.c
src/switch_core_io.c
src/switch_core_rwlock.c
src/switch_core_session.c
src/switch_core_sqldb.c
src/switch_core_state_machine.c

index 15c5c48c3853bc97664b4fa8c7a54d1d892d111b..78f566b7395eb26696b49ba700e5832dd6483f9a 100644 (file)
@@ -578,6 +578,8 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(_Inout_ switch_core_ses
 */
 #define switch_core_session_destroy(session) switch_core_session_perform_destroy(session, __FILE__, __SWITCH_FUNC__, __LINE__)
 
+SWITCH_DECLARE(void) switch_core_session_destroy_state(switch_core_session_t *session);
+
 /*! 
   \brief Provide the total number of sessions
   \return the total number of allocated sessions
index fa85ce42e23e73cee492239862ef640c1b950aa4..13a5b7a1e7bc158138c39feccdac29d39f76669c 100644 (file)
@@ -56,7 +56,8 @@ typedef enum {
        SWITCH_SHN_ON_HIBERNATE,
        SWITCH_SHN_ON_RESET,
        SWITCH_SHN_ON_PARK,
-       SWITCH_SHN_ON_REPORTING
+       SWITCH_SHN_ON_REPORTING,
+       SWITCH_SHN_ON_DESTROY
 } switch_state_handler_name_t;
 
 struct switch_state_handler_table {
@@ -82,6 +83,8 @@ struct switch_state_handler_table {
        switch_state_handler_t on_park;
        /*! executed when the state changes to reporting */
        switch_state_handler_t on_reporting;
+       /*! executed when the state changes to destroy */
+       switch_state_handler_t on_destroy;
        void *padding[10];
 };
 
index a9617174b63d1fd256f7eed279b81cd4859176c6..67ff017887f78b95db06feedbeeeb10644408295 100644 (file)
@@ -787,7 +787,7 @@ CS_HIBERNATE - Channel is in a sleep state.
 CS_RESET        - Channel is in a reset state.
 CS_HANGUP    - Channel is flagged for hangup and ready to end.
 CS_REPORTING - Channel is ready to collect call detail.
-CS_DONE      - Channel is ready to be destroyed and out of the state machine
+CS_DESTROY      - Channel is ready to be destroyed and out of the state machine
 </pre>
  */
 typedef enum {
@@ -803,7 +803,7 @@ typedef enum {
        CS_RESET,
        CS_HANGUP,
        CS_REPORTING,
-       CS_DONE,
+       CS_DESTROY,
        CS_NONE
 } switch_channel_state_t;
 
index a0260c0886d8a40a83ee178d432741821810d035..7e215f3426dc6f8e2288b85eca44bf6d30c53435 100644 (file)
@@ -143,6 +143,7 @@ static void add_pvt(private_t *tech_pvt, int master);
 static void remove_pvt(private_t *tech_pvt);
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -425,6 +426,22 @@ static void remove_pvt(private_t *tech_pvt)
        switch_mutex_unlock(globals.pvt_lock);
 }
 
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
+{
+       switch_channel_t *channel = NULL;
+       private_t *tech_pvt = NULL;
+
+       channel = switch_core_session_get_channel(session);
+       assert(channel != NULL);
+
+       tech_pvt = switch_core_session_get_private(session);
+       assert(tech_pvt != NULL);
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
+
 static switch_status_t channel_on_hangup(switch_core_session_t *session)
 {
        switch_channel_t *channel = NULL;
@@ -719,7 +736,13 @@ static switch_state_handler_table_t channel_event_handlers = {
        /*.on_execute */ channel_on_execute,
        /*.on_hangup */ channel_on_hangup,
        /*.on_exchange_media */ channel_on_exchange_media,
-       /*.on_soft_execute */ channel_on_soft_execute
+       /*.on_soft_execute */ channel_on_soft_execute,
+       /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
 };
 
 static switch_io_routines_t channel_io_routines = {
index dc033325ac8f5c8d6855ffdcf13a93b0db4280bd..998a829a9d2ca33446778f12854f537c50cb0b8a 100644 (file)
@@ -206,6 +206,7 @@ SWITCH_STANDARD_API(dl_pres);
 SWITCH_STANDARD_API(dl_debug);
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -1207,6 +1208,33 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
        return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
+{
+       //switch_channel_t *channel = switch_core_session_get_channel(session);
+       struct private_object *tech_pvt = NULL;
+
+       tech_pvt = switch_core_session_get_private(session);
+       switch_assert(tech_pvt != NULL);
+
+       if (tech_pvt->rtp_session) {
+               switch_rtp_destroy(&tech_pvt->rtp_session);
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NUKE RTP\n");
+               tech_pvt->rtp_session = NULL;
+       }
+
+       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+               switch_core_codec_destroy(&tech_pvt->read_codec);
+       }
+
+       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+               switch_core_codec_destroy(&tech_pvt->write_codec);
+       }
+
+
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
 static switch_status_t channel_on_hangup(switch_core_session_t *session)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -1238,20 +1266,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
                ldl_session_destroy(&tech_pvt->dlsession);
        }
 
-       if (tech_pvt->rtp_session) {
-               switch_rtp_destroy(&tech_pvt->rtp_session);
-               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NUKE RTP\n");
-               tech_pvt->rtp_session = NULL;
-       }
-
-       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-               switch_core_codec_destroy(&tech_pvt->read_codec);
-       }
-
-       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-               switch_core_codec_destroy(&tech_pvt->write_codec);
-       }
-
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
 
        return SWITCH_STATUS_SUCCESS;
@@ -1554,7 +1568,13 @@ switch_state_handler_table_t dingaling_event_handlers = {
        /*.on_execute */ channel_on_execute,
        /*.on_hangup */ channel_on_hangup,
        /*.on_exchange_media */ channel_on_exchange_media,
-       /*.on_soft_execute */ channel_on_soft_execute
+       /*.on_soft_execute */ channel_on_soft_execute,
+       /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
 };
 
 switch_io_routines_t dingaling_io_routines = {
index 7749a95aa66d0c5fe620396b36557791d0b79bf9..78368e12a4c25658e126e1e79d20a7cfb53846d1 100644 (file)
@@ -416,6 +416,7 @@ static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *ia
 
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -488,16 +489,12 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
        return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_hangup(switch_core_session_t *session)
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
 {
        private_t *tech_pvt = switch_core_session_get_private(session);
 
        switch_assert(tech_pvt != NULL);
 
-       switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-       switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-       switch_clear_flag_locked(tech_pvt, TFLAG_CODEC);
-
        if (switch_core_codec_ready(&tech_pvt->read_codec)) {
                switch_core_codec_destroy(&tech_pvt->read_codec);
        }
@@ -506,6 +503,19 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
                switch_core_codec_destroy(&tech_pvt->write_codec);
        }
 
+       return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_hangup(switch_core_session_t *session)
+{
+       private_t *tech_pvt = switch_core_session_get_private(session);
+
+       switch_assert(tech_pvt != NULL);
+
+       switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+       switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+       switch_clear_flag_locked(tech_pvt, TFLAG_CODEC);
+
        switch_mutex_lock(globals.mutex);
        if (tech_pvt->iax_session) {
                if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
@@ -787,7 +797,13 @@ switch_state_handler_table_t iax_state_handlers = {
        /*.on_execute */ channel_on_execute,
        /*.on_hangup */ channel_on_hangup,
        /*.on_exchange_media */ channel_on_exchange_media,
-       /*.on_soft_execute */ channel_on_soft_execute
+       /*.on_soft_execute */ channel_on_soft_execute,
+       /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
 };
 
 switch_io_routines_t iax_io_routines = {
index 82d8aaebdd65a5b72ab7bd2d57d7cfd2d2e871fa..ebb890aabd5bdd66b76b2f8e6f1933eb856b6978 100644 (file)
@@ -88,6 +88,7 @@ static struct {
 
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -339,10 +340,36 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
        assert(tech_pvt != NULL);
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
+       
+       return SWITCH_STATUS_SUCCESS;
+}
+
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
+{
+       switch_channel_t *channel = NULL;
+       private_t *tech_pvt = NULL;
+
+       channel = switch_core_session_get_channel(session);
+       switch_assert(channel != NULL);
+
+       tech_pvt = switch_core_session_get_private(session);
+       switch_assert(tech_pvt != NULL);
+
+       switch_core_timer_destroy(&tech_pvt->timer);
+
+       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+               switch_core_codec_destroy(&tech_pvt->read_codec);
+       }
+
+       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+               switch_core_codec_destroy(&tech_pvt->write_codec);
+       }
+
 
        return SWITCH_STATUS_SUCCESS;
 }
 
+
 static switch_status_t channel_on_hangup(switch_core_session_t *session)
 {
        switch_channel_t *channel = NULL;
@@ -370,17 +397,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
                tech_pvt->other_session = NULL;
        }
        switch_mutex_unlock(tech_pvt->mutex);
-
-       switch_core_timer_destroy(&tech_pvt->timer);
-
-       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-               switch_core_codec_destroy(&tech_pvt->read_codec);
-       }
-
-       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-               switch_core_codec_destroy(&tech_pvt->write_codec);
-       }
-
+       
        return SWITCH_STATUS_SUCCESS;
 }
 
@@ -754,7 +771,11 @@ static switch_state_handler_table_t channel_event_handlers = {
        /*.on_soft_execute */ channel_on_soft_execute,
        /*.on_consume_media */ channel_on_consume_media,
        /*.on_hibernate */ channel_on_hibernate,
-       /*.on_reset */ channel_on_reset
+       /*.on_reset */ channel_on_reset,
+       /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
+
 };
 
 static switch_io_routines_t channel_io_routines = {
index c1213bc792b2d23cc49a6a838b14de846de41fdc..38c93ab929990f1189e2affc330332130b6e9a4a 100644 (file)
@@ -70,7 +70,14 @@ static switch_state_handler_table_t opalfs_event_handlers = {
     /*.on_execute */ FSConnection::on_execute,\r
     /*.on_hangup */ on_hangup,\r
     /*.on_loopback */ FSConnection::on_loopback,\r
-    /*.on_transmit */ FSConnection::on_transmit\r
+    /*.on_transmit */ FSConnection::on_transmit,\r
+       /*.on_soft_execute */ NULL,\r
+       /*.on_consume_media*/ NULL,\r
+       /*.on_hibernate*/ NULL,\r
+       /*.on_reset*/ NULL,\r
+       /*.on_park*/ NULL,\r
+       /*.on_reporting*/ NULL,\r
+       /*.on_destroy*/ on_destroy\r
 };\r
 \r
 \r
@@ -826,23 +833,11 @@ switch_status_t FSConnection::on_execute()
     return SWITCH_STATUS_SUCCESS;\r
 }\r
 \r
-\r
-/* this function has to be called with the original session beause the FSConnection might already be destroyed and we \r
-   will can't have it be a method of a dead object\r
- */\r
-static switch_status_t on_hangup(switch_core_session_t *session)\r
+static switch_status_t on_destroy(switch_core_session_t *session)\r
 {\r
     switch_channel_t *channel = switch_core_session_get_channel(session);\r
     opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session);\r
-    \r
-    /* if this is still here it was our idea to hangup not opal's */\r
-    if (tech_pvt->me) {\r
-        Q931::CauseValues cause = (Q931::CauseValues)switch_channel_get_cause_q850(channel);\r
-        tech_pvt->me->SetQ931Cause(cause);\r
-        tech_pvt->me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX));\r
-        tech_pvt->me = NULL;\r
-    }\r
-    \r
+\r
     if (tech_pvt->read_codec.implementation) {\r
         switch_core_codec_destroy(&tech_pvt->read_codec);\r
     }\r
@@ -869,7 +864,27 @@ static switch_status_t on_hangup(switch_core_session_t *session)
 \r
     switch_core_session_unset_read_codec(session);\r
     switch_core_session_unset_write_codec(session);\r
+    \r
+       return SWITCH_STATUS_SUCCESS;\r
+\r
+}\r
 \r
+/* this function has to be called with the original session beause the FSConnection might already be destroyed and we \r
+   will can't have it be a method of a dead object\r
+ */\r
+static switch_status_t on_hangup(switch_core_session_t *session)\r
+{\r
+    switch_channel_t *channel = switch_core_session_get_channel(session);\r
+    opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session);\r
+    \r
+    /* if this is still here it was our idea to hangup not opal's */\r
+    if (tech_pvt->me) {\r
+        Q931::CauseValues cause = (Q931::CauseValues)switch_channel_get_cause_q850(channel);\r
+        tech_pvt->me->SetQ931Cause(cause);\r
+        tech_pvt->me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX));\r
+        tech_pvt->me = NULL;\r
+    }\r
+    \r
     return SWITCH_STATUS_SUCCESS;\r
 }\r
 \r
index af2109c09b9108e08c56d75e053d843d9d2e7f7b..b6936e6704ecc9212c82cd5fde166ed694d66d25 100644 (file)
@@ -148,6 +148,7 @@ static void add_pvt(private_t *tech_pvt, int master);
 static void remove_pvt(private_t *tech_pvt);
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -469,6 +470,13 @@ static void tech_close_file(private_t *tech_pvt)
        }
 }
 
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
+{
+       //private_t *tech_pvt = switch_core_session_get_private(session);
+       //switch_assert(tech_pvt != NULL);
+       return SWITCH_STATUS_SUCCESS;
+}
+
 static switch_status_t channel_on_hangup(switch_core_session_t *session)
 {
        private_t *tech_pvt = switch_core_session_get_private(session);
@@ -692,7 +700,14 @@ switch_state_handler_table_t portaudio_event_handlers = {
        /*.on_execute */ channel_on_execute,
        /*.on_hangup */ channel_on_hangup,
        /*.on_exchange_media */ channel_on_exchange_media,
-       /*.on_soft_execute */ channel_on_soft_execute
+       /*.on_soft_execute */ channel_on_soft_execute,
+       /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
+
 };
 
 switch_io_routines_t portaudio_io_routines = {
index 6d264ea50b88ee1f3c3517f249df47c78198badb..c6bcb1755671223d0d8c7d1b046e3d3511fa20ee 100644 (file)
@@ -100,6 +100,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip);
 
 static switch_status_t channel_on_init(switch_core_session_t *session);
 static switch_status_t channel_on_hangup(switch_core_session_t *session);
+static switch_status_t channel_on_destroy(switch_core_session_t *session);
 static switch_status_t channel_on_routing(switch_core_session_t *session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t *session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t *session);
@@ -185,7 +186,7 @@ static switch_status_t channel_on_execute(switch_core_session_t *session)
        return SWITCH_STATUS_SUCCESS;
 }
 
-static switch_status_t channel_on_hangup(switch_core_session_t *session)
+static switch_status_t channel_on_destroy(switch_core_session_t *session)
 {
        switch_channel_t *channel = NULL;
        private_t *tech_pvt = NULL;
@@ -196,9 +197,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
        tech_pvt = switch_core_session_get_private(session);
        assert(tech_pvt != NULL);
 
-       switch_clear_flag_locked(tech_pvt, TFLAG_IO);
-       switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
-       //switch_thread_cond_signal(tech_pvt->cond);
 
        if (switch_core_codec_ready(&tech_pvt->read_codec)) {
                switch_core_codec_destroy(&tech_pvt->read_codec);
@@ -208,6 +206,25 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
                switch_core_codec_destroy(&tech_pvt->write_codec);
        }
 
+       return SWITCH_STATUS_SUCCESS;
+}
+
+
+static switch_status_t channel_on_hangup(switch_core_session_t *session)
+{
+       switch_channel_t *channel = NULL;
+       private_t *tech_pvt = NULL;
+
+       channel = switch_core_session_get_channel(session);
+       assert(channel != NULL);
+
+       tech_pvt = switch_core_session_get_private(session);
+       assert(tech_pvt != NULL);
+
+       switch_clear_flag_locked(tech_pvt, TFLAG_IO);
+       switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
+       //switch_thread_cond_signal(tech_pvt->cond);
+
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s CHANNEL HANGUP\n", switch_channel_get_name(channel));
        switch_mutex_lock(globals.mutex);
@@ -462,7 +479,14 @@ switch_state_handler_table_t reference_state_handlers = {
        /*.on_execute */ channel_on_execute,
        /*.on_hangup */ channel_on_hangup,
        /*.on_exchange_media */ channel_on_exchange_media,
-       /*.on_soft_execute */ channel_on_soft_execute
+       /*.on_soft_execute */ channel_on_soft_execute,
+       /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ channel_on_destroy
+
 };
 
 switch_io_routines_t reference_io_routines = {
index d90b24f19d31d974bfeb17456f12b66f7c7aae3b..33f10e88b20b4e539b3a045c63841f087342b122 100644 (file)
@@ -79,6 +79,7 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string,
 
 static switch_status_t channel_on_init(switch_core_session_t * session);
 static switch_status_t channel_on_hangup(switch_core_session_t * session);
+static switch_status_t channel_on_destroy(switch_core_session_t * session);
 static switch_status_t channel_on_routing(switch_core_session_t * session);
 static switch_status_t channel_on_exchange_media(switch_core_session_t * session);
 static switch_status_t channel_on_soft_execute(switch_core_session_t * session);
@@ -182,6 +183,29 @@ static switch_status_t channel_on_init(switch_core_session_t * session)
   return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t channel_on_hangup(switch_core_session_t * session)
+{
+  switch_channel_t *channel = NULL;
+  private_t *tech_pvt = NULL;
+
+  channel = switch_core_session_get_channel(session);
+  switch_assert(channel != NULL);
+
+  tech_pvt = switch_core_session_get_private(session);
+  switch_assert(tech_pvt != NULL);
+
+  if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+         switch_core_codec_destroy(&tech_pvt->read_codec);
+  }
+
+  if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+         switch_core_codec_destroy(&tech_pvt->write_codec);
+  }
+
+  return SWITCH_STATUS_SUCCESS;
+}
+
+
 static switch_status_t channel_on_hangup(switch_core_session_t * session)
 {
   switch_channel_t *channel = NULL;
@@ -205,13 +229,6 @@ static switch_status_t channel_on_hangup(switch_core_session_t * session)
     skypiax_signaling_write(tech_pvt, msg_to_skype);
   }
 
-  if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-         switch_core_codec_destroy(&tech_pvt->read_codec);
-  }
-
-  if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-         switch_core_codec_destroy(&tech_pvt->write_codec);
-  }
 
   memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
   DEBUGA_SKYPE("%s CHANNEL HANGUP\n", SKYPIAX_P_LOG, switch_channel_get_name(channel));
@@ -490,7 +507,13 @@ switch_state_handler_table_t skypiax_state_handlers = {
   /*.on_execute */ channel_on_execute,
   /*.on_hangup */ channel_on_hangup,
   /*.on_exchange_media */ channel_on_exchange_media,
-  /*.on_soft_execute */ channel_on_soft_execute
+  /*.on_soft_execute */ channel_on_soft_execute,
+  /*.on_consume_media*/ NULL,
+  /*.on_hibernate*/ NULL,
+  /*.on_reset*/ NULL,
+  /*.on_park*/ NULL,
+  /*.on_reporting*/ NULL,
+  /*.on_destroy*/ channel_on_destroy
 };
 
 switch_io_routines_t skypiax_io_routines = {
index f256622de9814c6ec53ff10ef810e6bdfe5437a4..2053e1f6ad69fcf6d85f15fb20b25b2660d96ee5 100644 (file)
@@ -232,6 +232,34 @@ static int hangup_cause_to_sip(switch_call_cause_t cause)
        }
 }
 
+switch_status_t sofia_on_destroy(switch_core_session_t *session)
+{
+       private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s SOFIA DESTROY\n", switch_channel_get_name(channel));
+
+       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+               switch_core_codec_destroy(&tech_pvt->read_codec);
+       }
+
+       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+               switch_core_codec_destroy(&tech_pvt->write_codec);
+       }
+
+       switch_core_session_unset_read_codec(session);
+       switch_core_session_unset_write_codec(session);
+
+       switch_mutex_lock(tech_pvt->profile->flag_mutex);
+       tech_pvt->profile->inuse--;
+       switch_mutex_unlock(tech_pvt->profile->flag_mutex);
+
+       sofia_glue_deactivate_rtp(tech_pvt);
+
+       return SWITCH_STATUS_SUCCESS;
+
+}
+
 switch_status_t sofia_on_hangup(switch_core_session_t *session)
 {
        switch_core_session_t *a_session;
@@ -282,8 +310,6 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
                sofia_clear_flag_locked(tech_pvt, TFLAG_SIP_HOLD);
        }
 
-       sofia_glue_deactivate_rtp(tech_pvt);
-
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n",
                                          switch_channel_get_name(channel), switch_channel_cause2str(cause));
 
@@ -379,21 +405,6 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
 
        sofia_clear_flag(tech_pvt, TFLAG_IO);
 
-       if (switch_core_codec_ready(&tech_pvt->read_codec)) {
-               switch_core_codec_destroy(&tech_pvt->read_codec);
-       }
-
-       if (switch_core_codec_ready(&tech_pvt->write_codec)) {
-               switch_core_codec_destroy(&tech_pvt->write_codec);
-       }
-
-       switch_core_session_unset_read_codec(session);
-       switch_core_session_unset_write_codec(session);
-
-       switch_mutex_lock(tech_pvt->profile->flag_mutex);
-       tech_pvt->profile->inuse--;
-       switch_mutex_unlock(tech_pvt->profile->flag_mutex);
-
        if (tech_pvt->sofia_private) {
                *tech_pvt->sofia_private->uuid = '\0';
        }
@@ -2378,7 +2389,10 @@ switch_state_handler_table_t sofia_event_handlers = {
        /*.on_soft_execute */ sofia_on_soft_execute,
        /*.on_consume_media */ NULL,
        /*.on_hibernate */ sofia_on_hibernate,
-       /*.on_reset */ sofia_on_reset
+       /*.on_reset */ sofia_on_reset,
+       /*.on_park*/ NULL,
+       /*.on_reporting*/ NULL,
+       /*.on_destroy*/ sofia_on_destroy
 };
 
 static switch_status_t sofia_manage(char *relative_oid, switch_management_action_t action, char *data, switch_size_t datalen)
index 55ff75a9dc938be0c86bfddd4ecaeb3dfac92a72..da9907dc5a139b6942f06ca5a88477805d9c72c4 100644 (file)
@@ -932,6 +932,25 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_execute(%p)\n
     return SWITCH_STATUS_SUCCESS;
 }
 
+static switch_status_t unicall_on_destroy(switch_core_session_t *session)
+{
+    switch_channel_t *channel;
+    private_t *tech_pvt;
+
+    channel = switch_core_session_get_channel(session);
+    assert(channel != NULL);
+    tech_pvt = switch_core_session_get_private(session);
+    assert(tech_pvt != NULL);
+
+    if (switch_core_codec_ready(&tech_pvt->read_codec))
+        switch_core_codec_destroy(&tech_pvt->read_codec);
+    if (switch_core_codec_ready(&tech_pvt->write_codec))
+        switch_core_codec_destroy(&tech_pvt->write_codec);
+       
+       return SWITCH_STATUS_SUCCESS;
+               
+}
+
 static switch_status_t unicall_on_hangup(switch_core_session_t *session)
 {
     switch_channel_t *channel;
@@ -948,10 +967,6 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n"
     switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
     //switch_thread_cond_signal(tech_pvt->cond);
 
-    if (switch_core_codec_ready(&tech_pvt->read_codec))
-        switch_core_codec_destroy(&tech_pvt->read_codec);
-    if (switch_core_codec_ready(&tech_pvt->write_codec)
-        switch_core_codec_destroy(&tech_pvt->write_codec);
                
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel));
 
@@ -1722,7 +1737,14 @@ switch_state_handler_table_t unicall_state_handlers =
     /*.on_execute */ unicall_on_execute,
     /*.on_hangup */ unicall_on_hangup,
     /*.on_exchange_media */ unicall_on_exchange_media,
-    /*.on_soft_execute */ unicall_on_soft_execute
+    /*.on_soft_execute */ unicall_on_soft_execute,
+    /*.on_consume_media*/ NULL,
+    /*.on_hibernate*/ NULL,
+    /*.on_reset*/ NULL,
+    /*.on_park*/ NULL,
+    /*.on_reporting*/ NULL,
+    /*.on_destroy*/ unicall_on_destroy
+
 };
 
 switch_io_routines_t unicall_io_routines =
index c671f33c6c0c63578c4682421736f9961016b363..67fe38f68202d4c27e030d033e18a21cf08b73ff 100644 (file)
@@ -931,7 +931,7 @@ static const char *state_names[] = {
        "CS_RESET",
        "CS_HANGUP",
        "CS_REPORTING",
-       "CS_DONE",
+       "CS_DESTROY",
        NULL
 };
 
@@ -950,7 +950,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_name_state(const char *nam
                }
        }
 
-       return CS_DONE;
+       return CS_DESTROY;
 }
 
 SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(switch_channel_t *channel, switch_channel_state_t state,
@@ -1015,11 +1015,11 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
        int ok = 0;
 
        switch_assert(channel != NULL);
-       switch_assert(state <= CS_DONE);
+       switch_assert(state <= CS_DESTROY);
        switch_mutex_lock(channel->state_mutex);
 
        last_state = channel->state;
-       switch_assert(last_state <= CS_DONE);
+       switch_assert(last_state <= CS_DESTROY);
 
        if (last_state == state) {
                goto done;
@@ -1040,7 +1040,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
           case CS_ROUTING:
           case CS_EXECUTE:
           case CS_HANGUP:
-          case CS_DONE:
+          case CS_DESTROY:
 
           default:
           break;
@@ -1182,7 +1182,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
        case CS_HANGUP:
                switch (state) {
                case CS_REPORTING:
-               case CS_DONE:
+               case CS_DESTROY:
                        ok++;
                default:
                        break;
@@ -1191,7 +1191,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
 
        case CS_REPORTING:
                switch (state) {
-               case CS_DONE:
+               case CS_DESTROY:
                        ok++;
                default:
                        break;
@@ -1213,7 +1213,7 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_state(switch_c
                        channel->hangup_cause = SWITCH_CAUSE_NORMAL_CLEARING;
                }
 
-               if (state < CS_DONE) {
+               if (state < CS_DESTROY) {
                        switch_core_session_signal_state_change(channel->session);
                }
        } else {
index 221d1d71f88e4afde754fe83a0937c772770a324..d15512e8b00b4e0074241784806225989c3e453e 100644 (file)
@@ -202,16 +202,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 
        switch_assert((*frame)->codec != NULL);
 
-
-       switch_mutex_lock((*frame)->codec->mutex);              
        if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation) && switch_core_codec_ready((*frame)->codec)) {
                status = SWITCH_STATUS_FALSE;
-               switch_mutex_unlock((*frame)->codec->mutex);
                goto done;
        }
 
        codec_impl = *(*frame)->codec->implementation;
-       switch_mutex_unlock((*frame)->codec->mutex);
 
        if (session->read_codec->implementation->impl_id != codec_impl.impl_id) {
                need_codec = TRUE;
index aba781614b475f356e3b9a567f71ee8ba571ad09..1c91389e5ee66172bd64a95840ecaf38ad365b6b 100644 (file)
@@ -73,7 +73,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock_hangup(switch_core
        switch_status_t status = SWITCH_STATUS_FALSE;
 
        if (session->rwlock) {
-               if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_DONE) {
+               if (switch_test_flag(session, SSF_DESTROYED) || switch_channel_get_state(session->channel) >= CS_DESTROY) {
                        status = SWITCH_STATUS_FALSE;
 #ifdef SWITCH_DEBUG_RWLOCKS
                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "%s Read lock FAIL\n",
index 965cffe4720f04ab75fac76a6c6e5e8aa3a05e40..aeaa099fda9d6ea06737d194b1589bd8cf1bd7b2 100644 (file)
@@ -874,7 +874,6 @@ SWITCH_DECLARE(unsigned int) switch_core_session_running(switch_core_session_t *
        return session->thread_running;
 }
 
-
 SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t **session, const char *file, const char *func, int line)
 {
        switch_memory_pool_t *pool;
@@ -905,6 +904,7 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
                switch_event_fire(&event);
        }
 
+       switch_core_session_destroy_state(*session);
 
        switch_buffer_destroy(&(*session)->raw_read_buffer);
        switch_buffer_destroy(&(*session)->raw_write_buffer);
@@ -921,6 +921,8 @@ SWITCH_DECLARE(void) switch_core_session_perform_destroy(switch_core_session_t *
        UNPROTECT_INTERFACE(endpoint_interface);
 }
 
+
+
 SWITCH_STANDARD_SCHED_FUNC(sch_heartbeat_callback)
 {
        switch_event_t *event;
index 6335eaba1152d52c5afa4a7a0190be163b8ffc93..2b31e27b134876da0b6340d89ad1a53b76b86aeb 100644 (file)
@@ -309,7 +309,7 @@ static void core_event_handler(switch_event_t *event)
        case SWITCH_EVENT_CHANNEL_STATE:
                {
                        char *state = switch_event_get_header_nil(event, "channel-state-number");
-                       switch_channel_state_t state_i = CS_DONE;
+                       switch_channel_state_t state_i = CS_DESTROY;
 
                        if (!switch_strlen_zero(state)) {
                                state_i = atoi(state);
@@ -317,7 +317,7 @@ static void core_event_handler(switch_event_t *event)
 
                        switch (state_i) {
                        case CS_HANGUP:
-                       case CS_DONE:
+                       case CS_DESTROY:
                                break;
                        case CS_ROUTING:
                                sql = switch_mprintf("update channels set state='%s',cid_name='%q',cid_num='%q',ip_addr='%s',dest='%q',dialplan='%q',context='%q' "
index ceae777675d7313f1cec0bb6b1451c8b6aba28a8..a97fedb9f07e7d0a531f1c9438495c18ba3d4c13 100644 (file)
@@ -54,6 +54,13 @@ static void switch_core_standard_on_reporting(switch_core_session_t *session)
                                          switch_channel_get_name(session->channel), switch_channel_cause2str(switch_channel_get_cause(session->channel)));
 }
 
+static void switch_core_standard_on_destroy(switch_core_session_t *session)
+{
+
+       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Standard DESTROY\n",
+                                         switch_channel_get_name(session->channel));
+}
+
 static void switch_core_standard_on_reset(switch_core_session_t *session)
 {
 
@@ -318,7 +325,7 @@ void switch_core_state_machine_init(switch_memory_pool_t *pool)
 
 SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
 {
-       switch_channel_state_t state = CS_NEW, midstate = CS_DONE, endstate;
+       switch_channel_state_t state = CS_NEW, midstate = CS_DESTROY, endstate;
        const switch_endpoint_interface_t *endpoint_interface;
        const switch_state_handler_table_t *driver_state_handler = NULL;
        const switch_state_handler_table_t *application_state_handler = NULL;
@@ -376,7 +383,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
 
        switch_mutex_lock(session->mutex);
 
-       while ((state = switch_channel_get_state(session->channel)) != CS_DONE) {
+       while ((state = switch_channel_get_state(session->channel)) != CS_DESTROY) {
 
                switch_channel_wait_for_flag(session->channel, CF_BLOCK_STATE, SWITCH_FALSE, 0, NULL);
                
@@ -395,7 +402,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                        case CS_NEW: /* Just created, Waiting for first instructions */
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "(%s) State NEW\n", switch_channel_get_name(session->channel));
                                break;
-                       case CS_DONE:
+                       case CS_DESTROY:
                                goto done;
                        case CS_REPORTING: /* Call Detail */
                                {
@@ -417,7 +424,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
 
                                        STATE_MACRO(reporting, "REPORTING");
                                        
-                                       switch_channel_set_state(session->channel, CS_DONE);
+                                       switch_channel_set_state(session->channel, CS_DESTROY);
                                }
                                goto done;
                        case CS_HANGUP: /* Deactivate and end the thread */
@@ -517,7 +524,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
                                break;
                        }
 
-                       if (midstate == CS_DONE) {
+                       if (midstate == CS_DESTROY) {
                                break;
                        }
 
@@ -543,6 +550,32 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
        session->thread_running = 0;
 }
 
+SWITCH_DECLARE(void) switch_core_session_destroy_state(switch_core_session_t *session)
+{
+       switch_channel_state_t state = CS_DESTROY, midstate = CS_DESTROY;
+       const switch_endpoint_interface_t *endpoint_interface;
+       const switch_state_handler_table_t *driver_state_handler = NULL;
+       const switch_state_handler_table_t *application_state_handler = NULL;
+       int proceed = 1;
+       int global_proceed = 1;
+       int do_extra_handlers = 1;
+       int silly = 0;
+       int index = 0;
+
+       switch_assert(session != NULL);
+
+       session->thread_running = 1;
+       endpoint_interface = session->endpoint_interface;
+       switch_assert(endpoint_interface != NULL);
+
+       driver_state_handler = endpoint_interface->state_handler;
+       switch_assert(driver_state_handler != NULL);
+       
+       STATE_MACRO(destroy, "DESTROY");
+
+       return;
+}
+
 /* For Emacs:
  * Local Variables:
  * mode:c