[asterisk-commits] russell: branch russell/sla_updates r56953 - /team/russell/sla_updates/apps/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Feb 26 17:17:04 MST 2007


Author: russell
Date: Mon Feb 26 18:17:04 2007
New Revision: 56953

URL: http://svn.digium.com/view/asterisk?view=rev&rev=56953
Log:
Break out a bunch of code into functions and add more comments to help
clarify all of the logic going on

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=56953&r1=56952&r2=56953
==============================================================================
--- team/russell/sla_updates/apps/app_meetme.c (original)
+++ team/russell/sla_updates/apps/app_meetme.c Mon Feb 26 18:17:04 2007
@@ -3311,83 +3311,150 @@
 	AST_LIST_TRAVERSE_SAFE_END
 }
 
-static void sla_handle_ringing_trunk_event(void)
-{
-	struct sla_trunk_ref *trunk_ref;
+/*! \brief Check to see if this station is already ringing 
+ * \note Assumes sla.lock is locked 
+ */
+static int sla_check_ringing_station(const struct sla_station *station)
+{
+	struct sla_ringing_station *ringing_station;
+
+	AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
+		if (station == ringing_station->station)
+			return 1;
+	}
+
+	return 0;
+}
+
+/*! \brief Check to see if this station has failed to be dialed in the past minute
+ * \note assumes sla.lock is locked
+ */
+static int sla_check_failed_station(const struct sla_station *station)
+{
+	struct sla_failed_station *failed_station;
+	int res = 0;
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.failed_stations, failed_station, entry) {
+		if (station != failed_station->station)
+			continue;
+		if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
+			AST_LIST_REMOVE_CURRENT(&sla.failed_stations, entry);
+			free(failed_station);
+			break;
+		}
+		res = 1;
+	}
+	AST_LIST_TRAVERSE_SAFE_END
+
+	return res;
+}
+
+/*! \brief Check to see if dialing this station already timed out for this ringing trunk
+ * \note Assumes sla.lock is locked
+ */
+static int sla_check_timed_out_station(const struct sla_ringing_trunk *ringing_trunk,
+	const struct sla_station *station)
+{
+	struct sla_station_ref *timed_out_station;
+
+	AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, timed_out_station, entry) {
+		if (station == timed_out_station->station)
+			return 1;
+	}
+
+	return 0;
+}
+
+/*! \brief Ring a station
+ * \note Assumes sla.lock is locked
+ */
+static int sla_ring_station(struct sla_ringing_trunk *ringing_trunk, struct sla_station *station)
+{
+	char *tech, *tech_data;
+	struct ast_dial *dial;
+	struct sla_ringing_station *ringing_station;
+
+	if (!(dial = ast_dial_create()))
+		return -1;
+
+	ast_dial_set_state_callback(dial, sla_dial_state_callback);
+	tech_data = ast_strdupa(station->device);
+	tech = strsep(&tech_data, "/");
+
+	if (ast_dial_append(dial, tech, tech_data) == -1) {
+		ast_dial_destroy(dial);
+		return -1;
+	}
+
+	if (ast_dial_run(dial, ringing_trunk->trunk->chan, 1) != AST_DIAL_RESULT_TRYING) {
+		struct sla_failed_station *failed_station;
+		ast_dial_destroy(dial);
+		if (!(failed_station = ast_calloc(1, sizeof(*failed_station))))
+			return -1;
+		failed_station->station = station;
+		failed_station->last_try = ast_tvnow();
+		AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
+		return -1;
+	}
+	if (!(ringing_station = sla_create_ringing_station(station))) {
+		ast_dial_join(dial);
+		ast_dial_destroy(dial);
+		return -1;
+	}
+
+	station->dial = dial;
+
+	AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
+
+	return 0;
+}
+
+/*! \brief Ring stations based on current set of ringing trunks
+ * \note Assumes that sla.lock is locked
+ */
+static void sla_ring_stations(void)
+{
 	struct sla_station_ref *station_ref;
 	struct sla_ringing_trunk *ringing_trunk;
-	struct sla_ringing_station *ringing_station;
-
-	ast_mutex_lock(&sla.lock);
 
 	/* Make sure that every station that uses at least one of the ringing
 	 * trunks, is ringing. */
 	AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
 		AST_LIST_TRAVERSE(&ringing_trunk->trunk->stations, station_ref, entry) {
-			char *tech, *tech_data;
-			struct ast_dial *dial;
-			struct sla_failed_station *failed_station;
-			struct sla_station_ref *timed_out_station;
+			/* Is this station already ringing? */
+			if (sla_check_ringing_station(station_ref->station))
+				continue;
+
 			/* Did we fail to dial this station earlier?  If so, has it been
  			 * a minute since we tried? */
-			AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.failed_stations, failed_station, entry) {
-				if (station_ref->station != failed_station->station)
-					continue;
-				if (ast_tvdiff_ms(ast_tvnow(), failed_station->last_try) > 1000) {
-					AST_LIST_REMOVE_CURRENT(&sla.failed_stations, entry);
-					free(failed_station);
-					failed_station = NULL;
-				}
-				break;
-			}
-			if (failed_station)
+			if (sla_check_failed_station(station_ref->station))
 				continue;
-			AST_LIST_TRAVERSE_SAFE_END
-			AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
-				if (station_ref->station == ringing_station->station)
-					break;
-			}
-			if (ringing_station)
-				continue;
+
 			/* If this station already timed out while this trunk was ringing,
 			 * do not dial it again for this ringing trunk. */
-			AST_LIST_TRAVERSE(&ringing_trunk->timed_out_stations, timed_out_station, entry) {
-				if (station_ref->station == timed_out_station->station)
-					break;
-			}
-			if (timed_out_station)
+			if (sla_check_timed_out_station(ringing_trunk, station_ref->station))
 				continue;
-			if (!(dial = ast_dial_create()))
-				continue;
-			ast_dial_set_state_callback(dial, sla_dial_state_callback);
-			tech_data = ast_strdupa(station_ref->station->device);
-			tech = strsep(&tech_data, "/");
-			if (ast_dial_append(dial, tech, tech_data) == -1) {
-				ast_dial_destroy(dial);
-				continue;
-			}
-			if (ast_dial_run(dial, ringing_trunk->trunk->chan, 1) != AST_DIAL_RESULT_TRYING) {
-				ast_dial_destroy(dial);
-				if (!(failed_station = ast_calloc(1, sizeof(*failed_station))))
-					continue;
-				failed_station->station = station_ref->station;
-				failed_station->last_try = ast_tvnow();
-				AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
-				continue;
-			}
-			if (!(ringing_station = sla_create_ringing_station(station_ref->station))) {
-				ast_dial_join(dial);
-				ast_dial_destroy(dial);
-				continue;
-			}
-			station_ref->station->dial = dial;
-			AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
-			ast_log(LOG_DEBUG, "Started dialing station '%s'\n", station_ref->station->name);
-		}
-	}
+
+			/* Check for a ring delay.  First, see if there is a ring delay set
+			 * globally for the station.  If not, check to see if there is a ring
+			 * delay for the highest priority ringing trunk for this station. */
+
+			/* It is time to make this station begin to ring.  Do it! */
+			sla_ring_station(ringing_trunk, station_ref->station);
+		}
+	}
+	/* Now, all of the stations that should be ringing, are ringing. */
+}
+
+static void sla_handle_ringing_trunk_event(void)
+{
+	struct sla_trunk_ref *trunk_ref;
+	struct sla_ringing_station *ringing_station;
+
+	ast_mutex_lock(&sla.lock);
+	sla_ring_stations();
 	ast_mutex_unlock(&sla.lock);
-	/* Now, all of the stations that should be ringing, are ringing. */
-	
+
 	/* Find stations that shouldn't be ringing anymore. */
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
 		AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
@@ -3518,6 +3585,11 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END
 
+	/* Check for station ring delays.  If there is a station that is currently
+	 * in the middle of a delay, then use that for the time to wake up.  If we
+	 * come across stations that have a delay that is now over, make it start
+	 * ringing by just queueing reprocessing of ringing trunks. */
+
 	/* queue reprocessing of ringing trunks */
 	if (change_made)
 		sla_queue_event_nolock(SLA_EVENT_RINGING_TRUNK);
@@ -3553,7 +3625,6 @@
 				ast_cond_wait(&sla.cond, &sla.lock);
 			if (sla.stop)
 				break;
-			ast_log(LOG_DEBUG, "Ooh, I was woken up!\n");
 		}
 
 		if (have_timeout)



More information about the asterisk-commits mailing list