Revision
15865
Author
anthm
Date
2009-12-09 19:29:02 -0600 (Wed, 09 Dec 2009)

Log Message

add priority queue for events so important broadcasts like hold music can take precedenced over event-lock

Modified Paths

Diff

Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h (15864 => 15865)


--- freeswitch/trunk/src/include/private/switch_core_pvt.h	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h	2009-12-10 01:29:02 UTC (rev 15865)
@@ -134,6 +134,7 @@
 	switch_queue_t *event_queue;
 	switch_queue_t *message_queue;
 	switch_queue_t *private_event_queue;
+	switch_queue_t *private_event_queue_pri;
 	switch_thread_rwlock_t *bug_rwlock;
 	switch_media_bug_t *bugs;
 	switch_app_log_t *app_log;

Modified: freeswitch/trunk/src/include/switch_core.h (15864 => 15865)


--- freeswitch/trunk/src/include/switch_core.h	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/include/switch_core.h	2009-12-10 01:29:02 UTC (rev 15865)
@@ -986,9 +986,10 @@
   \brief Queue a private event on a given session
   \param session the session to queue the message on
   \param event the event to queue
+  \param priority event has high priority
   \return the status returned by the message handler
 */
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event);
+SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(_In_ switch_core_session_t *session, _Inout_ switch_event_t **event, switch_bool_t priority);
 
 
 /*! 

Modified: freeswitch/trunk/src/include/switch_types.h (15864 => 15865)


--- freeswitch/trunk/src/include/switch_types.h	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/include/switch_types.h	2009-12-10 01:29:02 UTC (rev 15865)
@@ -326,7 +326,8 @@
 	SMF_LOOP = (1 << 4),
 	SMF_HOLD_BLEG = (1 << 5),
 	SMF_IMMEDIATE = (1 << 6),
-	SMF_EXEC_INLINE = (1 << 7)
+	SMF_EXEC_INLINE = (1 << 7),
+	SMF_PRIORITY = (1 << 8)
 } switch_media_flag_enum_t;
 typedef uint32_t switch_media_flag_t;
 
@@ -919,6 +920,7 @@
 	CF_UNICAST,
 	CF_VIDEO,
 	CF_EVENT_LOCK,
+	CF_EVENT_LOCK_PRI,
 	CF_RESET,
 	CF_ORIGINATING,
 	CF_STOP_BROADCAST,

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15864 => 15865)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -2938,7 +2938,8 @@
 					switch_channel_set_flag(tech_pvt->channel, CF_HOLD);
 					switch_ivr_hold_uuid(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), NULL, 0);
 				} else {
-					switch_ivr_broadcast(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), stream, SMF_ECHO_ALEG | SMF_LOOP);
+					switch_ivr_broadcast(switch_channel_get_variable(tech_pvt->channel, SWITCH_SIGNAL_BOND_VARIABLE), stream, 
+										 SMF_ECHO_ALEG | SMF_LOOP | SMF_PRIORITY);
 					switch_yield(250000);
 				}
 			}

Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (15864 => 15865)


--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -1655,7 +1655,7 @@
 
 		if (zstr(uuid) && listener->session) {
 			if (async) {
-				if ((status = switch_core_session_queue_private_event(listener->session, event)) == SWITCH_STATUS_SUCCESS) {
+				if ((status = switch_core_session_queue_private_event(listener->session, event, SWITCH_FALSE)) == SWITCH_STATUS_SUCCESS) {
 					switch_snprintf(reply, reply_len, "+OK");
 				} else {
 					switch_snprintf(reply, reply_len, "-ERR memory error");
@@ -1666,7 +1666,7 @@
 			}
 		} else {
 			if (!zstr(uuid) && (session = switch_core_session_locate(uuid))) {
-				if ((status = switch_core_session_queue_private_event(session, event)) == SWITCH_STATUS_SUCCESS) {
+				if ((status = switch_core_session_queue_private_event(session, event, SWITCH_FALSE)) == SWITCH_STATUS_SUCCESS) {
 					switch_snprintf(reply, reply_len, "+OK");
 				} else {
 					switch_snprintf(reply, reply_len, "-ERR memory error");

Modified: freeswitch/trunk/src/switch_core_session.c (15864 => 15865)


--- freeswitch/trunk/src/switch_core_session.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/switch_core_session.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -847,15 +847,18 @@
 	return status;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(switch_core_session_t *session, switch_event_t **event)
+SWITCH_DECLARE(switch_status_t) switch_core_session_queue_private_event(switch_core_session_t *session, switch_event_t **event, switch_bool_t priority)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
+	switch_queue_t *queue;
 
 	switch_assert(session != NULL);
 
 	if (session->private_event_queue) {
+		queue = priority ? session->private_event_queue_pri : session->private_event_queue;
+		
 		(*event)->event_id = SWITCH_EVENT_PRIVATE_COMMAND;
-		if (switch_queue_trypush(session->private_event_queue, *event) == SWITCH_STATUS_SUCCESS) {
+		if (switch_queue_trypush(queue, *event) == SWITCH_STATUS_SUCCESS) {
 			*event = NULL;
 			switch_core_session_kill_channel(session, SWITCH_SIG_BREAK);
 			status = SWITCH_STATUS_SUCCESS;
@@ -878,8 +881,16 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	uint32_t count = 0;
 	
-	if (!switch_channel_test_flag(channel, CF_EVENT_LOCK) && session->private_event_queue) {
-		count = switch_queue_size(session->private_event_queue);
+	if (session->private_event_queue) {
+
+		if (!switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
+			count = switch_queue_size(session->private_event_queue);
+		}
+
+		if (!switch_channel_test_flag(channel, CF_EVENT_LOCK_PRI)) {
+			count += switch_queue_size(session->private_event_queue_pri);
+		}
+
 		if (count == 0) {
 			check_media(session);
 		}
@@ -893,13 +904,24 @@
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	void *pop;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
+	switch_queue_t *queue;
+	
+	if (session->private_event_queue) {
+		if (switch_queue_size(session->private_event_queue_pri)) {
+			queue = session->private_event_queue_pri;
 
-	if (switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
-		return status;
-	}
+			if (switch_channel_test_flag(channel, CF_EVENT_LOCK_PRI)) {
+				return SWITCH_STATUS_FALSE;
+			}
+		} else {
+			queue = session->private_event_queue;
+			
+			if (switch_channel_test_flag(channel, CF_EVENT_LOCK)) {
+				return SWITCH_STATUS_FALSE;
+			}
+		}
 
-	if (session->private_event_queue) {
-		if ((status = (switch_status_t) switch_queue_trypop(session->private_event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
+		if ((status = (switch_status_t) switch_queue_trypop(queue, &pop)) == SWITCH_STATUS_SUCCESS) {
 			*event = (switch_event_t *) pop;
 		} else {
 			check_media(session);
@@ -916,6 +938,9 @@
 	void *pop;
 
 	if (session->private_event_queue) {
+		while ((status = (switch_status_t) switch_queue_trypop(session->private_event_queue_pri, &pop)) == SWITCH_STATUS_SUCCESS) {
+			x++;
+		}
 		while ((status = (switch_status_t) switch_queue_trypop(session->private_event_queue, &pop)) == SWITCH_STATUS_SUCCESS) {
 			x++;
 		}
@@ -1327,6 +1352,7 @@
 	switch_queue_create(&session->message_queue, SWITCH_MESSAGE_QUEUE_LEN, session->pool);
 	switch_queue_create(&session->event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
 	switch_queue_create(&session->private_event_queue, SWITCH_EVENT_QUEUE_LEN, session->pool);
+	switch_queue_create(&session->private_event_queue_pri, SWITCH_EVENT_QUEUE_LEN, session->pool);
 
 	switch_mutex_lock(runtime.session_hash_mutex);
 	switch_core_hash_insert(session_manager.session_table, session->uuid_str, session);

Modified: freeswitch/trunk/src/switch_ivr.c (15864 => 15865)


--- freeswitch/trunk/src/switch_ivr.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/switch_ivr.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -461,6 +461,7 @@
 	unsigned long CMD_UNICAST = switch_hashfunc_default("unicast", &hlen);
 	char *lead_frames = switch_event_get_header(event, "lead-frames");
 	char *event_lock = switch_event_get_header(event, "event-lock");
+	char *event_lock_pri = switch_event_get_header(event, "event-lock-pri");
 	switch_status_t status = SWITCH_STATUS_FALSE;
 
 	if (zstr(cmd)) {
@@ -476,6 +477,10 @@
 		switch_channel_set_flag_recursive(channel, CF_EVENT_LOCK);
 	}
 
+	if (switch_true(event_lock_pri)) {
+		switch_channel_set_flag_recursive(channel, CF_EVENT_LOCK_PRI);
+	}
+
 	if (lead_frames) {
 		switch_frame_t *read_frame;
 		int frame_count = atoi(lead_frames);
@@ -606,6 +611,7 @@
   done:
 	switch_channel_clear_flag_recursive(channel, CF_EVENT_PARSE);
 	switch_channel_clear_flag_recursive(channel, CF_EVENT_LOCK);
+	switch_channel_clear_flag_recursive(channel, CF_EVENT_LOCK_PRI);
 
 	return status;
 }

Modified: freeswitch/trunk/src/switch_ivr_async.c (15864 => 15865)


--- freeswitch/trunk/src/switch_ivr_async.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/switch_ivr_async.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -1740,7 +1740,7 @@
 								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", cont->list[i].app);
 								switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", cont->list[i].data);
 								switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-								switch_core_session_queue_private_event(cont->session, &event);
+								switch_core_session_queue_private_event(cont->session, &event, SWITCH_FALSE);
 							}
 						}
 
@@ -2713,8 +2713,10 @@
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", path);
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, (flags & SMF_PRIORITY) ? "event-lock-pri" : "event-lock", "true");
+
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-lock", "true");
+				
 				if ((flags & SMF_LOOP)) {
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
 				}
@@ -2723,7 +2725,7 @@
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hold-bleg", "true");
 				}
 				
-				switch_core_session_queue_private_event(other_session, &event);
+				switch_core_session_queue_private_event(other_session, &event, (flags & SMF_PRIORITY));
 			}
 		}
 		
@@ -2745,15 +2747,18 @@
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", app);
 				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", path);
+				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, (flags & SMF_PRIORITY) ? "event-lock-pri" : "event-lock", "true");
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
-				switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-lock", "true");
+				
 				if ((flags & SMF_LOOP)) {
 					switch_event_add_header(event, SWITCH_STACK_BOTTOM, "loops", "%d", -1);
 				}
 				if ((flags & SMF_HOLD_BLEG)) {
 					switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "hold-bleg", "true");
 				}
-				switch_core_session_queue_private_event(session, &event);
+
+				switch_core_session_queue_private_event(session, &event, (flags & SMF_PRIORITY));
+
 				if (nomedia) switch_channel_set_flag(channel, CF_BROADCAST_DROP_MEDIA);
 			}
 		}
@@ -2765,8 +2770,8 @@
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "call-command", "execute");
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-name", "hangup");
 			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "execute-app-arg", cause);
-			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-			switch_core_session_queue_private_event(session, &event);
+			switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, (flags & SMF_PRIORITY) ? "event-lock-pri" : "event-lock", "true");
+			switch_core_session_queue_private_event(session, &event, (flags & SMF_PRIORITY));
 		}
 	}
 

Modified: freeswitch/trunk/src/switch_ivr_bridge.c (15864 => 15865)


--- freeswitch/trunk/src/switch_ivr_bridge.c	2009-12-10 01:17:41 UTC (rev 15864)
+++ freeswitch/trunk/src/switch_ivr_bridge.c	2009-12-10 01:29:02 UTC (rev 15865)
@@ -1059,7 +1059,7 @@
 					switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", data);
 					switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
 					switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-					switch_core_session_queue_private_event(session, &execute_event);
+					switch_core_session_queue_private_event(session, &execute_event, SWITCH_FALSE);
 					a_leg->skip_frames = DEFAULT_LEAD_FRAMES;
 				}
 
@@ -1074,7 +1074,7 @@
 					switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "execute-app-arg", data);
 					switch_event_add_header(execute_event, SWITCH_STACK_BOTTOM, "lead-frames", "%d", 5);
 					switch_event_add_header_string(execute_event, SWITCH_STACK_BOTTOM, "event-lock", "true");
-					switch_core_session_queue_private_event(peer_session, &execute_event);
+					switch_core_session_queue_private_event(peer_session, &execute_event, SWITCH_FALSE);
 					b_leg->skip_frames = DEFAULT_LEAD_FRAMES;
 				}
 			}