[svn-commits] file: branch file/bridging-phase2 r180530 - in /team/file/bridging-phase2: in...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Mar 6 10:41:42 CST 2009


Author: file
Date: Fri Mar  6 10:41:38 2009
New Revision: 180530

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=180530
Log:
Add the ability to allow the user of interval hooks to specify how the interval hook itself will be rescheduled. If strict is specified then the interval will be rescheduled with the execution time of the callback itself taken into account.

Modified:
    team/file/bridging-phase2/include/asterisk/bridging_features.h
    team/file/bridging-phase2/main/bridging.c

Modified: team/file/bridging-phase2/include/asterisk/bridging_features.h
URL: http://svn.digium.com/svn-view/asterisk/team/file/bridging-phase2/include/asterisk/bridging_features.h?view=diff&rev=180530&r1=180529&r2=180530
==============================================================================
--- team/file/bridging-phase2/include/asterisk/bridging_features.h (original)
+++ team/file/bridging-phase2/include/asterisk/bridging_features.h Fri Mar  6 10:41:38 2009
@@ -80,6 +80,8 @@
 	};
 	/*! Time at which the interval should actually trip */
 	struct timeval interval_trip_time;
+	/*! Bit to indicate that we should take into account the time spent executing the callback when rescheduling the interval hook */
+	unsigned int interval_strict:1;
 	/*! Callback that is called when DTMF string is matched */
 	ast_bridge_features_hook_callback callback;
 	/*! Unique data that was passed into us */
@@ -194,6 +196,7 @@
  *
  * \param features Bridge features structure
  * \param interval The interval that the hook should execute at
+ * \param strict If set this takes into account the time spent executing the callback when rescheduling the interval hook
  * \param callback Function to execute upon activation
  * \param hook_pvt Unique data
  *
@@ -205,7 +208,7 @@
  * \code
  * struct ast_bridge_features features;
  * ast_bridge_features_init(&features);
- * ast_bridge_features_interval_hook(&features, 1000, playback_callback, NULL);
+ * ast_bridge_features_interval_hook(&features, 1000, 0, playback_callback, NULL);
  * \endcode
  *
  * This makes the bridging core call playback_callback every second. A pointer to useful
@@ -214,7 +217,7 @@
  * \note It is important that the callback set the bridge channel state back to
  *       AST_BRIDGE_CHANNEL_STATE_WAIT or the bridge thread will not service the channel.
  */
-int ast_bridge_features_interval_hook(struct ast_bridge_features *features, unsigned int interval, ast_bridge_features_hook_callback callback, void *hook_pvt);	
+int ast_bridge_features_interval_hook(struct ast_bridge_features *features, unsigned int interval, unsigned int strict, ast_bridge_features_hook_callback callback, void *hook_pvt);
 
 /*! \brief Update the interval on an interval hook that is currently executing a callback
  *

Modified: team/file/bridging-phase2/main/bridging.c
URL: http://svn.digium.com/svn-view/asterisk/team/file/bridging-phase2/main/bridging.c?view=diff&rev=180530&r1=180529&r2=180530
==============================================================================
--- team/file/bridging-phase2/main/bridging.c (original)
+++ team/file/bridging-phase2/main/bridging.c Fri Mar  6 10:41:38 2009
@@ -960,8 +960,9 @@
 
 	while ((hook = AST_LIST_FIRST(&bridge_channel->features->interval_hooks))) {
 		int res;
-
-		if (ast_tvdiff_ms(hook->interval_trip_time, ast_tvnow()) > 0) {
+		struct timeval start = ast_tvnow();
+
+		if (ast_tvdiff_ms(hook->interval_trip_time, start) > 0) {
 			ast_debug(1, "Hook '%p' on '%p' wants to happen in the future, stopping our traversal\n", hook, bridge_channel);
 			break;
 		}
@@ -976,9 +977,15 @@
 			ast_free(hook);
 		} else {
 			struct ast_bridge_features_hook *existing_hook = NULL;
+			int execution_time = 0;
 
 			ast_debug(1, "Updating hook '%p' and adding it back to '%p'\n", hook, bridge_channel);
-			hook->interval_trip_time = ast_tvadd(ast_tvnow(), ast_samp2tv(hook->interval, 1000));
+
+			if (hook->interval_strict) {
+				execution_time = ast_tvdiff_ms(ast_tvnow(), start);
+			}
+
+			hook->interval_trip_time = ast_tvadd(ast_tvnow(), ast_samp2tv(hook->interval - execution_time, 1000));
 
 			AST_LIST_TRAVERSE_SAFE_BEGIN(&bridge_channel->features->interval_hooks, existing_hook, entry) {
 				if (ast_tvdiff_ms(hook->interval_trip_time, ast_tvnow()) < ast_tvdiff_ms(existing_hook->interval_trip_time, ast_tvnow())) {
@@ -1453,7 +1460,7 @@
 	return 0;
 }
 
-int ast_bridge_features_interval_hook(struct ast_bridge_features *features, unsigned int interval, ast_bridge_features_hook_callback callback, void *hook_pvt)
+int ast_bridge_features_interval_hook(struct ast_bridge_features *features, unsigned int interval, unsigned int strict, ast_bridge_features_hook_callback callback, void *hook_pvt)
 {
 	struct ast_bridge_features_hook *hook = NULL, *existing_hook = NULL;
 
@@ -1464,6 +1471,7 @@
 	hook->interval = interval;
 	hook->callback = callback;
 	hook->hook_pvt = hook_pvt;
+	hook->interval_strict = strict ? 1 : 0;
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&features->interval_hooks, existing_hook, entry) {
 		if (hook->interval < existing_hook->interval) {




More information about the svn-commits mailing list