[Freeswitch-svn] [commit] r2301 - in freeswitch/trunk/src: . mod/applications/mod_bridgecall

Freeswitch SVN anthm at freeswitch.org
Tue Aug 15 17:38:24 EDT 2006


Author: anthm
Date: Tue Aug 15 17:38:24 2006
New Revision: 2301

Modified:
   freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c
   freeswitch/trunk/src/switch.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_ivr.c

Log:
redecorating

Modified: freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_bridgecall/mod_bridgecall.c	Tue Aug 15 17:38:24 2006
@@ -40,42 +40,17 @@
 {
 	switch_channel_t *caller_channel;
 	switch_core_session_t *peer_session;
-	switch_caller_profile_t *caller_profile, *caller_caller_profile;
-	char chan_type[128] = { '\0' }, *chan_data;
-	unsigned int timelimit = 60;			/* probably a useful option to pass in when there's time */
+	unsigned int timelimit = 60; /* probably a useful option to pass in when there's time */
+
 	caller_channel = switch_core_session_get_channel(session);
 	assert(caller_channel != NULL);
 
-
-	strncpy(chan_type, data, sizeof(chan_type));
-
-	if ((chan_data = strchr(chan_type, '/')) != 0) {
-		*chan_data = '\0';
-		chan_data++;
-	}
-
-	caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
-	caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
-											   caller_caller_profile->username,
-											   caller_caller_profile->dialplan,
-											   caller_caller_profile->caller_id_name,
-											   caller_caller_profile->caller_id_number,
-											   caller_caller_profile->network_addr, 
-											   NULL, 
-											   NULL, 
-											   caller_caller_profile->rdnis,
-											   caller_caller_profile->source,
-											   caller_caller_profile->context,
-											   chan_data);
-
-
-
-	if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session, NULL) !=
-		SWITCH_STATUS_SUCCESS) {
+	if (switch_ivr_outcall(session, &peer_session, data) != SWITCH_STATUS_SUCCESS) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot Create Outgoing Channel!\n");
 		switch_channel_hangup(caller_channel, SWITCH_CAUSE_REQUESTED_CHAN_UNAVAIL);
 		return;
 	} else {
+		/* peer channel is read locked now the bridge func will unlock it for us */
 		switch_ivr_multi_threaded_bridge(session, peer_session, timelimit, NULL, NULL, NULL);
 	}
 }

Modified: freeswitch/trunk/src/switch.c
==============================================================================
--- freeswitch/trunk/src/switch.c	(original)
+++ freeswitch/trunk/src/switch.c	Tue Aug 15 17:38:24 2006
@@ -220,7 +220,6 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "End existing sessions\n");
 	switch_core_session_hupall();
-	switch_yield(10000);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clean up modules.\n");
 	switch_loadable_module_shutdown();
 	switch_core_destroy();

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Tue Aug 15 17:38:24 2006
@@ -762,9 +762,14 @@
 SWITCH_DECLARE(int) switch_channel_add_state_handler(switch_channel_t *channel,
 													 const switch_state_handler_table_t *state_handler)
 {
-	int index;
+	int x, index;
 
 	assert(channel != NULL);
+	for (x = 0; x < SWITCH_MAX_STATE_HANDLERS; x++) {
+		if (channel->state_handlers[x] == state_handler) {
+			return x;
+		}
+	}
 	index = channel->state_handler_index++;
 
 	if (channel->state_handler_index >= SWITCH_MAX_STATE_HANDLERS) {

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Tue Aug 15 17:38:24 2006
@@ -233,7 +233,15 @@
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_read_lock(switch_core_session_t *session)
 {
-	return (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock);
+	switch_status_t status = SWITCH_STATUS_SUCCESS;
+
+	if (!switch_channel_test_flag(session->channel, CF_LOCK_THREAD)) {
+		if ((status = (switch_status_t) switch_thread_rwlock_tryrdlock(session->rwlock)) == SWITCH_STATUS_SUCCESS) {
+			switch_channel_set_flag(session->channel, CF_LOCK_THREAD);
+		}
+	}
+	
+	return status;
 }
 
 SWITCH_DECLARE(void) switch_core_session_write_lock(switch_core_session_t *session)
@@ -243,6 +251,7 @@
 
 SWITCH_DECLARE(void) switch_core_session_rwunlock(switch_core_session_t *session)
 {
+	switch_channel_clear_flag(session->channel, CF_LOCK_THREAD);
 	switch_thread_rwlock_unlock(session->rwlock);
 }
 
@@ -283,7 +292,7 @@
 	switch_mutex_unlock(runtime.session_table_mutex);
 
 	while(runtime.session_count) {
-		switch_yield(1000);
+		switch_yield(10000);
 	}
 }
 
@@ -3116,15 +3125,13 @@
 SWITCH_DECLARE(switch_status_t) switch_core_destroy(void)
 {
 
-
-
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Closing Event Engine.\n");
 	switch_event_shutdown();
 	
 	switch_queue_push(runtime.sql_queue, NULL);
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waiting for unfinished SQL transactions\n");
 	while (switch_queue_size(runtime.sql_queue) > 0) {
-		switch_yield(1000);
+		switch_yield(10000);
 	}
 	switch_core_db_close(runtime.db);
 	switch_core_db_close(runtime.event_db);
@@ -3132,15 +3139,15 @@
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Finalizing Shutdown.\n");
 	switch_log_shutdown();
-
-	if (runtime.memory_pool) {
-		apr_pool_destroy(runtime.memory_pool);
-		apr_terminate();
-	}
 	
 	if(runtime.console != stdout && runtime.console != stderr) {
 		fclose(runtime.console);
 		runtime.console = NULL;
+	}
+
+	if (runtime.memory_pool) {
+		apr_pool_destroy(runtime.memory_pool);
+		apr_terminate();
 	}
 
 	return SWITCH_STATUS_SUCCESS;

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Aug 15 17:38:24 2006
@@ -1177,8 +1177,8 @@
 												   caller_caller_profile->caller_id_name,
 												   caller_caller_profile->caller_id_number,
 												   caller_caller_profile->network_addr, 
+												   NULL,
 												   NULL, 
-												   NULL, 
 												   caller_caller_profile->rdnis,
 												   caller_caller_profile->source,
 												   caller_caller_profile->context,
@@ -1207,6 +1207,8 @@
 		goto done;
 	} 
 
+	switch_core_session_read_lock(peer_session);
+
 	peer_channel = switch_core_session_get_channel(peer_session);
 	assert(peer_channel != NULL);
 		
@@ -1294,12 +1296,9 @@
 {
 	switch_core_thread_session_t *this_audio_thread, *other_audio_thread;
 	switch_channel_t *caller_channel, *peer_channel;
-	time_t start;
 	int stream_id = 0;
-	switch_frame_t *read_frame = NULL;
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 	
-
 	caller_channel = switch_core_session_get_channel(session);
 	assert(caller_channel != NULL);
 
@@ -1328,59 +1327,6 @@
 	this_audio_thread->running = 2;
 
 	switch_channel_add_state_handler(peer_channel, &audio_bridge_peer_state_handlers);
-
-	if (switch_core_session_runing(peer_session)) {
-		switch_channel_set_state(peer_channel, CS_RING);
-	} else {
-		switch_core_session_thread_launch(peer_session);
-	}
-
-	time(&start);
-
-	for (;;) {
-		int state = switch_channel_get_state(peer_channel);
-		if (state >= CS_RING) {
-			break;
-		}
-		
-		if (!switch_channel_ready(caller_channel)) {
-			break;
-		}
-		
-		if ((time(NULL) - start) > (time_t)timelimit) {
-			break;
-		}
-		switch_yield(1000);
-	}
-
-	switch_channel_pre_answer(caller_channel);
-	
-
-	while (switch_channel_ready(caller_channel) &&
-		   switch_channel_ready(peer_channel) &&
-		   !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
-		   !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
-		   ((time(NULL) - start) < (time_t)timelimit)) {
-		
-		/* read from the channel while we wait if the audio is up on it */
-		if (switch_channel_test_flag(caller_channel, CF_ANSWERED) || switch_channel_test_flag(caller_channel, CF_EARLY_MEDIA)) {
-			switch_status_t status = switch_core_session_read_frame(session, &read_frame, 1000, 0);
-			
-			if (!SWITCH_READ_ACCEPTABLE(status)) {
-				break;
-			}
-			if (read_frame) {
-				//memset(read_frame->data, 0, read_frame->datalen);
-				if (switch_core_session_write_frame(session, read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
-					break;
-				}
-			}
-
-		} else {
-			switch_yield(1000);
-		}
-
-	}
 
 	if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
 		switch_channel_answer(caller_channel);



More information about the Freeswitch-svn mailing list