[Freeswitch-svn] [commit] r12986 - in freeswitch/trunk/src: . include mod/endpoints/mod_alsa mod/endpoints/mod_dingaling mod/endpoints/mod_iax mod/endpoints/mod_loopback mod/endpoints/mod_opal mod/endpoints/mod_portaudio mod/endpoints/mod_reference mod/endpoints/mod_skypiax mod/endpoints/mod_sofia mod/endpoints/mod_unicall

FreeSWITCH SVN anthm at freeswitch.org
Fri Apr 10 10:43:19 PDT 2009


Author: anthm
Date: Fri Apr 10 12:43:18 2009
New Revision: 12986

Log:
change CS_DONE to CS_DESTROY and add state handler for destroy and tear down critical parts of the channel from this method which is not called until it's impossible for anything to be referencing the channel (after final write lock and before destroying the pool)

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

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Fri Apr 10 12:43:18 2009
@@ -578,6 +578,8 @@
 */
 #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

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Fri Apr 10 12:43:18 2009
@@ -56,7 +56,8 @@
 	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 @@
 	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];
 };
 

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Fri Apr 10 12:43:18 2009
@@ -787,7 +787,7 @@
 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 @@
 	CS_RESET,
 	CS_HANGUP,
 	CS_REPORTING,
-	CS_DONE,
+	CS_DESTROY,
 	CS_NONE
 } switch_channel_state_t;
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c	Fri Apr 10 12:43:18 2009
@@ -143,6 +143,7 @@
 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 @@
 	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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c	Fri Apr 10 12:43:18 2009
@@ -206,6 +206,7 @@
 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 @@
 	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 @@
 		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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c	Fri Apr 10 12:43:18 2009
@@ -416,6 +416,7 @@
 
 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 @@
 	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 @@
 		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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c	Fri Apr 10 12:43:18 2009
@@ -88,6 +88,7 @@
 
 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 @@
 	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 @@
 		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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.cpp
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.cpp	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_opal/mod_opal.cpp	Fri Apr 10 12:43:18 2009
@@ -70,7 +70,14 @@
     /*.on_execute */ FSConnection::on_execute,
     /*.on_hangup */ on_hangup,
     /*.on_loopback */ FSConnection::on_loopback,
-    /*.on_transmit */ FSConnection::on_transmit
+    /*.on_transmit */ FSConnection::on_transmit,
+	/*.on_soft_execute */ NULL,
+	/*.on_consume_media*/ NULL,
+	/*.on_hibernate*/ NULL,
+	/*.on_reset*/ NULL,
+	/*.on_park*/ NULL,
+	/*.on_reporting*/ NULL,
+	/*.on_destroy*/ on_destroy
 };
 
 
@@ -826,23 +833,11 @@
     return SWITCH_STATUS_SUCCESS;
 }
 
-
-/* this function has to be called with the original session beause the FSConnection might already be destroyed and we 
-   will can't have it be a method of a dead object
- */
-static switch_status_t on_hangup(switch_core_session_t *session)
+static switch_status_t on_destroy(switch_core_session_t *session)
 {
     switch_channel_t *channel = switch_core_session_get_channel(session);
     opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session);
-    
-    /* if this is still here it was our idea to hangup not opal's */
-    if (tech_pvt->me) {
-        Q931::CauseValues cause = (Q931::CauseValues)switch_channel_get_cause_q850(channel);
-        tech_pvt->me->SetQ931Cause(cause);
-        tech_pvt->me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX));
-        tech_pvt->me = NULL;
-    }
-    
+
     if (tech_pvt->read_codec.implementation) {
         switch_core_codec_destroy(&tech_pvt->read_codec);
     }
@@ -869,7 +864,27 @@
 
     switch_core_session_unset_read_codec(session);
     switch_core_session_unset_write_codec(session);
+    
+	return SWITCH_STATUS_SUCCESS;
+
+}
 
+/* this function has to be called with the original session beause the FSConnection might already be destroyed and we 
+   will can't have it be a method of a dead object
+ */
+static switch_status_t on_hangup(switch_core_session_t *session)
+{
+    switch_channel_t *channel = switch_core_session_get_channel(session);
+    opal_private_t *tech_pvt = (opal_private_t *) switch_core_session_get_private(session);
+    
+    /* if this is still here it was our idea to hangup not opal's */
+    if (tech_pvt->me) {
+        Q931::CauseValues cause = (Q931::CauseValues)switch_channel_get_cause_q850(channel);
+        tech_pvt->me->SetQ931Cause(cause);
+        tech_pvt->me->ClearCallSynchronous(NULL, H323TranslateToCallEndReason(cause, UINT_MAX));
+        tech_pvt->me = NULL;
+    }
+    
     return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c	Fri Apr 10 12:43:18 2009
@@ -148,6 +148,7 @@
 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 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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c	Fri Apr 10 12:43:18 2009
@@ -100,6 +100,7 @@
 
 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 @@
 	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 @@
 	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 @@
 		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 @@
 	/*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Fri Apr 10 12:43:18 2009
@@ -79,6 +79,7 @@
 
 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);
@@ -186,6 +187,29 @@
 {
   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;
+  private_t *tech_pvt = NULL;
   char msg_to_skype[256];
 
   channel = switch_core_session_get_channel(session);
@@ -205,13 +229,6 @@
     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 @@
   /*.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 = {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Fri Apr 10 12:43:18 2009
@@ -232,6 +232,34 @@
 	}
 }
 
+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 @@
 		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 @@
 
 	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 @@
 	/*.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)

Modified: freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c	Fri Apr 10 12:43:18 2009
@@ -932,6 +932,25 @@
     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_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 @@
     /*.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 =

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Fri Apr 10 12:43:18 2009
@@ -931,7 +931,7 @@
 	"CS_RESET",
 	"CS_HANGUP",
 	"CS_REPORTING",
-	"CS_DONE",
+	"CS_DESTROY",
 	NULL
 };
 
@@ -950,7 +950,7 @@
 		}
 	}
 
-	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 @@
 	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 @@
 	   case CS_ROUTING:
 	   case CS_EXECUTE:
 	   case CS_HANGUP:
-	   case CS_DONE:
+	   case CS_DESTROY:
 
 	   default:
 	   break;
@@ -1182,7 +1182,7 @@
 	case CS_HANGUP:
 		switch (state) {
 		case CS_REPORTING:
-		case CS_DONE:
+		case CS_DESTROY:
 			ok++;
 		default:
 			break;
@@ -1191,7 +1191,7 @@
 
 	case CS_REPORTING:
 		switch (state) {
-		case CS_DONE:
+		case CS_DESTROY:
 			ok++;
 		default:
 			break;
@@ -1213,7 +1213,7 @@
 			channel->hangup_cause = SWITCH_CAUSE_NORMAL_CLEARING;
 		}
 
-		if (state < CS_DONE) {
+		if (state < CS_DESTROY) {
 			switch_core_session_signal_state_change(channel->session);
 		}
 	} else {

Modified: freeswitch/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/trunk/src/switch_core_io.c	(original)
+++ freeswitch/trunk/src/switch_core_io.c	Fri Apr 10 12:43:18 2009
@@ -202,16 +202,12 @@
 
 	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;

Modified: freeswitch/trunk/src/switch_core_rwlock.c
==============================================================================
--- freeswitch/trunk/src/switch_core_rwlock.c	(original)
+++ freeswitch/trunk/src/switch_core_rwlock.c	Fri Apr 10 12:43:18 2009
@@ -73,7 +73,7 @@
 	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",

Modified: freeswitch/trunk/src/switch_core_session.c
==============================================================================
--- freeswitch/trunk/src/switch_core_session.c	(original)
+++ freeswitch/trunk/src/switch_core_session.c	Fri Apr 10 12:43:18 2009
@@ -874,7 +874,6 @@
 	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_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 @@
 	UNPROTECT_INTERFACE(endpoint_interface);
 }
 
+
+
 SWITCH_STANDARD_SCHED_FUNC(sch_heartbeat_callback)
 {
 	switch_event_t *event;

Modified: freeswitch/trunk/src/switch_core_sqldb.c
==============================================================================
--- freeswitch/trunk/src/switch_core_sqldb.c	(original)
+++ freeswitch/trunk/src/switch_core_sqldb.c	Fri Apr 10 12:43:18 2009
@@ -309,7 +309,7 @@
 	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 @@
 
 			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' "

Modified: freeswitch/trunk/src/switch_core_state_machine.c
==============================================================================
--- freeswitch/trunk/src/switch_core_state_machine.c	(original)
+++ freeswitch/trunk/src/switch_core_state_machine.c	Fri Apr 10 12:43:18 2009
@@ -54,6 +54,13 @@
 					  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 @@
 
 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_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 @@
 			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 @@
 
 					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 @@
 				break;
 			}
 
-			if (midstate == CS_DONE) {
+			if (midstate == CS_DESTROY) {
 				break;
 			}
 
@@ -543,6 +550,32 @@
 	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



More information about the Freeswitch-svn mailing list