[asterisk-commits] russell: branch russell/sla_updates r57029 -
/team/russell/sla_updates/apps/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Feb 27 17:06:34 MST 2007
Author: russell
Date: Tue Feb 27 18:06:33 2007
New Revision: 57029
URL: http://svn.digium.com/view/asterisk?view=rev&rev=57029
Log:
Fix things ... add comments .. :)
Modified:
team/russell/sla_updates/apps/app_meetme.c
Modified: team/russell/sla_updates/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_updates/apps/app_meetme.c?view=diff&rev=57029&r1=57028&r2=57029
==============================================================================
--- team/russell/sla_updates/apps/app_meetme.c (original)
+++ team/russell/sla_updates/apps/app_meetme.c Tue Feb 27 18:06:33 2007
@@ -3240,13 +3240,16 @@
/*! \brief Choose the highest priority ringing trunk for a station
* \param station the station
* \param remove remove the ringing trunk once selected
+ * \param trunk_ref a place to store the pointer to this stations reference to
+ * the selected trunk
* \return a pointer to the selected ringing trunk, or NULL if none found
* \note Assumes that sla.lock is locked
*/
-static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *station, int remove)
+static struct sla_ringing_trunk *sla_choose_ringing_trunk(struct sla_station *station,
+ struct sla_trunk_ref **trunk_ref, int remove)
{
struct sla_trunk_ref *s_trunk_ref;
- struct sla_ringing_trunk *ringing_trunk;
+ struct sla_ringing_trunk *ringing_trunk = NULL;
AST_LIST_TRAVERSE(&station->trunks, s_trunk_ref, entry) {
AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
@@ -3261,6 +3264,9 @@
if (remove)
AST_LIST_REMOVE_CURRENT(&sla.ringing_trunks, entry);
+
+ if (trunk_ref)
+ *trunk_ref = s_trunk_ref;
break;
}
@@ -3300,7 +3306,7 @@
AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
/* Find the appropriate trunk to answer. */
ast_mutex_lock(&sla.lock);
- ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, 1);
+ ringing_trunk = sla_choose_ringing_trunk(ringing_station->station, &s_trunk_ref, 1);
ast_mutex_unlock(&sla.lock);
if (!ringing_trunk) {
ast_log(LOG_DEBUG, "Found no ringing trunk for station '%s' to answer!\n",
@@ -3470,9 +3476,11 @@
unsigned int delay = UINT_MAX;
if (!ringing_trunk)
- ringing_trunk = sla_choose_ringing_trunk(station, 0);
-
- if (!(trunk_ref = sla_find_trunk_ref(station, ringing_trunk->trunk)))
+ ringing_trunk = sla_choose_ringing_trunk(station, &trunk_ref, 0);
+ else
+ trunk_ref = sla_find_trunk_ref(station, ringing_trunk->trunk);
+
+ if (!ringing_trunk || !trunk_ref)
return delay;
/* If this station has a ring delay specific to the highest priority
@@ -3628,26 +3636,28 @@
AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
unsigned int ring_timeout = 0;
- int time_elapsed, time_left, final_trunk_time_left = INT_MIN;
+ int time_elapsed, time_left = INT_MAX, final_trunk_time_left = INT_MIN;
struct sla_trunk_ref *trunk_ref;
+
/* If there are any ring timeouts specified for a specific trunk
* on the station, then use the highest per-trunk ring timeout.
* Otherwise, use the ring timeout set for the entire station. */
AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
struct sla_station_ref *station_ref;
int trunk_time_elapsed, trunk_time_left;
+
AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
if (ringing_trunk->trunk == trunk_ref->trunk)
break;
}
if (!ringing_trunk)
continue;
+
/* If there is a trunk that is ringing without a timeout, then the
* only timeout that could matter is a global station ring timeout. */
- if (!trunk_ref->ring_timeout) {
- final_trunk_time_left = INT_MAX;
+ if (!trunk_ref->ring_timeout)
break;
- }
+
/* This trunk on this station is ringing and has a timeout.
* However, make sure this trunk isn't still ringing from a
* previous timeout. If so, don't consider it. */
@@ -3657,27 +3667,39 @@
}
if (station_ref)
continue;
+
trunk_time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
trunk_time_left = (trunk_ref->ring_timeout * 1000) - trunk_time_elapsed;
if (trunk_time_left > final_trunk_time_left)
final_trunk_time_left = trunk_time_left;
}
- if (final_trunk_time_left == INT_MAX && !ringing_station->station->ring_timeout)
+
+ /* No timeout was found for ringing trunks, and no timeout for the entire station */
+ if (final_trunk_time_left == INT_MIN && !ringing_station->station->ring_timeout)
continue;
- ring_timeout = ringing_station->station->ring_timeout;
- time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_station->ring_begin);
- time_left = (ring_timeout * 1000) - time_elapsed;
+ /* Compute how much time is left for a global station timeout */
+ if (ringing_station->station->ring_timeout) {
+ ring_timeout = ringing_station->station->ring_timeout;
+ time_elapsed = ast_tvdiff_ms(ast_tvnow(), ringing_station->ring_begin);
+ time_left = (ring_timeout * 1000) - time_elapsed;
+ }
+
/* If the time left based on the per-trunk timeouts is smaller than the
* global station ring timeout, use that. */
if (final_trunk_time_left > INT_MIN && final_trunk_time_left < time_left)
time_left = final_trunk_time_left;
+
+ /* If there is no time left, the station needs to stop ringing */
if (time_left <= 0) {
AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
sla_stop_ringing_station(ringing_station, SLA_STATION_HANGUP_TIMEOUT);
res = 1;
continue;
}
+
+ /* There is still some time left for this station to ring, so save that
+ * timeout if it is the first event scheduled to occur */
if (time_left < *timeout)
*timeout = time_left;
}
@@ -3708,7 +3730,7 @@
continue;
/* Ignore stations that don't have one of their trunks ringing */
- if (!(ringing_trunk = sla_choose_ringing_trunk(station, 0)))
+ if (!(ringing_trunk = sla_choose_ringing_trunk(station, NULL, 0)))
continue;
if ((delay = sla_check_station_delay(station, ringing_trunk)) == UINT_MAX)
@@ -3896,7 +3918,6 @@
ast_mutex_unlock(args->cond_lock);
ast_dial_join(dial);
ast_dial_destroy(dial);
- ast_log(LOG_DEBUG, "broke out with no chan\n");
return NULL;
}
More information about the asterisk-commits
mailing list