[asterisk-commits] russell: branch russell/sla_updates r54522 - in /team/russell/sla_updates: ap...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Feb 14 16:10:59 MST 2007


Author: russell
Date: Wed Feb 14 17:10:58 2007
New Revision: 54522

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54522
Log:
Start to add ring timeout per-station, and per-trunk on a station.

Modified:
    team/russell/sla_updates/apps/app_meetme.c
    team/russell/sla_updates/configs/sla.conf.sample

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=54522&r1=54521&r2=54522
==============================================================================
--- team/russell/sla_updates/apps/app_meetme.c (original)
+++ team/russell/sla_updates/apps/app_meetme.c Wed Feb 14 17:10:58 2007
@@ -1,9 +1,12 @@
 /*
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 1999 - 2006, Digium, Inc.
+ * Copyright (C) 1999 - 2007, Digium, Inc.
  *
  * Mark Spencer <markster at digium.com>
+ *
+ * SLA Implementation by:
+ * Russell Bryant <russell at digium.com>
  *
  * See http://www.asterisk.org for more information about
  * the Asterisk project. Please do not directly contact
@@ -18,9 +21,10 @@
 
 /*! \file
  *
- * \brief Meet me conference bridge
+ * \brief Meet me conference bridge and Shared Line Appearances
  *
  * \author Mark Spencer <markster at digium.com>
+ * \author (SLA) Russell Bryant <russell at digium.com>
  * 
  * \ingroup applications
  */
@@ -371,6 +375,10 @@
 	);
 	AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
 	struct ast_dial *dial;
+	/*! Ring timeout for this station, for any trunk.  If a ring timeout
+	 *  is set for a specific trunk on this station, that will take
+	 *  priority over this value. */
+	unsigned int ring_timeout;
 };
 
 struct sla_station_ref {
@@ -393,7 +401,10 @@
 	/*! Number of stations that have this trunk on hold. */
 	unsigned int hold_stations;
 	struct ast_channel *chan;
-	unsigned int ringtimeout;
+	/*! Ring timeout to use when this trunk is ringing on this specific
+	 *  station.  This takes higher priority than a ring timeout set at
+	 *  the station level. */
+	unsigned int ring_timeout;
 };
 
 struct sla_trunk_ref {
@@ -401,6 +412,7 @@
 	struct sla_trunk *trunk;
 	enum sla_trunk_state state;
 	struct ast_channel *chan;
+	unsigned int ring_timeout;
 };
 
 static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
@@ -968,9 +980,9 @@
 	AST_RWLIST_RDLOCK(&sla_trunks);
 	AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
 		struct sla_station_ref *station_ref;
-		char ringtimeout[16] = "(none)";
-		if (trunk->ringtimeout)
-			snprintf(ringtimeout, sizeof(ringtimeout), "%u Seconds", trunk->ringtimeout);
+		char ring_timeout[16] = "(none)";
+		if (trunk->ring_timeout)
+			snprintf(ring_timeout, sizeof(ring_timeout), "%u Seconds", trunk->ring_timeout);
 		ast_cli(fd, "--- Trunk Name:      %s\n"
 		            "--- ==> Device:      %s\n"
 					"--- ==> AutoContext: %s\n"
@@ -978,7 +990,7 @@
 					"--- ==> Stations ...\n",
 					trunk->name, trunk->device, 
 					S_OR(trunk->autocontext, "(none)"), 
-					ringtimeout);
+					ring_timeout);
 		AST_RWLIST_RDLOCK(&sla_stations);
 		AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry)
 			ast_cli(fd, "--- =====> Station name: %s\n", station_ref->station->name);
@@ -3293,7 +3305,7 @@
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
 		int time_left;
-		if (!ringing_trunk->trunk->ringtimeout)
+		if (!ringing_trunk->trunk->ring_timeout)
 			continue;
 		time_left = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
 		if (time_left <= 0) {
@@ -3328,7 +3340,7 @@
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
 		int time_left;
-		if (!ringing_trunk->trunk->ringtimeout)
+		if (!ringing_trunk->trunk->ring_timeout)
 			continue;
 		time_left = ast_tvdiff_ms(ast_tvnow(), ringing_trunk->ring_begin);
 		if (time_left <= 0) {
@@ -3792,7 +3804,7 @@
 	free(station);
 }
 
-static void destroy_sla(void)
+static void sla_destroy(void)
 {
 	struct sla_trunk *trunk;
 	struct sla_station *station;
@@ -3819,7 +3831,7 @@
 	ast_cond_destroy(&sla.cond);
 }
 
-static int check_device(const char *device)
+static int sla_check_device(const char *device)
 {
 	char *tech, *tech_data;
 
@@ -3832,7 +3844,7 @@
 	return 0;
 }
 
-static int build_trunk(struct ast_config *cfg, const char *cat)
+static int sla_build_trunk(struct ast_config *cfg, const char *cat)
 {
 	struct sla_trunk *trunk;
 	struct ast_variable *var;
@@ -3843,7 +3855,7 @@
 		return -1;
 	}
 
-	if (check_device(dev)) {
+	if (sla_check_device(dev)) {
 		ast_log(LOG_ERROR, "SLA Trunk '%s' define with invalid device '%s'!\n",
 			cat, dev);
 		return -1;
@@ -3863,10 +3875,10 @@
 		if (!strcasecmp(var->name, "autocontext"))
 			ast_string_field_set(trunk, autocontext, var->value);
 		else if (!strcasecmp(var->name, "ringtimeout")) {
-			if (sscanf(var->value, "%u", &trunk->ringtimeout) != 1) {
+			if (sscanf(var->value, "%u", &trunk->ring_timeout) != 1) {
 				ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for trunk '%s'\n",
 					var->value, trunk->name);
-				trunk->ringtimeout = 0;
+				trunk->ring_timeout = 0;
 			}
 		} else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
 			ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
@@ -3899,7 +3911,42 @@
 	return 0;
 }
 
-static int build_station(struct ast_config *cfg, const char *cat)
+static void sla_add_trunk_to_station(struct sla_station *station, struct ast_variable *var)
+{
+	struct sla_trunk *trunk;
+	struct sla_trunk_ref *trunk_ref;
+	struct sla_station_ref *station_ref;
+	char *trunk_name, *options;
+
+	options = ast_strdupa(var->value);
+	trunk_name = strsep(&options, ",");
+	
+	AST_RWLIST_RDLOCK(&sla_trunks);
+	AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
+		if (!strcasecmp(trunk->name, trunk_name))
+			break;
+	}
+	AST_RWLIST_UNLOCK(&sla_trunks);
+	if (!trunk) {
+		ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
+		return;
+	}
+	if (!(trunk_ref = create_trunk_ref(trunk)))
+		return;
+	trunk_ref->state = SLA_TRUNK_STATE_IDLE;
+	if (!(station_ref = ast_calloc(1, sizeof(*station_ref)))) {
+		free(trunk_ref);
+		return;
+	}
+	station_ref->station = station;
+	ast_atomic_fetchadd_int((int *) &trunk->num_stations, 1);
+	AST_RWLIST_WRLOCK(&sla_trunks);
+	AST_LIST_INSERT_TAIL(&trunk->stations, station_ref, entry);
+	AST_RWLIST_UNLOCK(&sla_trunks);
+	AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
+}
+
+static int sla_build_station(struct ast_config *cfg, const char *cat)
 {
 	struct sla_station *station;
 	struct ast_variable *var;
@@ -3921,35 +3968,16 @@
 	ast_string_field_set(station, device, dev);
 
 	for (var = ast_variable_browse(cfg, cat); var; var = var->next) {
-		if (!strcasecmp(var->name, "trunk")) {
-			struct sla_trunk *trunk;
-			struct sla_trunk_ref *trunk_ref;
-			struct sla_station_ref *station_ref;
-			AST_RWLIST_RDLOCK(&sla_trunks);
-			AST_RWLIST_TRAVERSE(&sla_trunks, trunk, entry) {
-				if (!strcasecmp(trunk->name, var->value))
-					break;
-			}
-			AST_RWLIST_UNLOCK(&sla_trunks);
-			if (!trunk) {
-				ast_log(LOG_ERROR, "Trunk '%s' not found!\n", var->value);
-				continue;
-			}
-			if (!(trunk_ref = create_trunk_ref(trunk)))
-				continue;
-			trunk_ref->state = SLA_TRUNK_STATE_IDLE;
-			if (!(station_ref = ast_calloc(1, sizeof(*station_ref)))) {
-				free(trunk_ref);
-				continue;
-			}
-			station_ref->station = station;
-			ast_atomic_fetchadd_int((int *) &trunk->num_stations, 1);
-			AST_RWLIST_WRLOCK(&sla_trunks);
-			AST_LIST_INSERT_TAIL(&trunk->stations, station_ref, entry);
-			AST_RWLIST_UNLOCK(&sla_trunks);
-			AST_LIST_INSERT_TAIL(&station->trunks, trunk_ref, entry);
-		} else if (!strcasecmp(var->name, "autocontext")) {
+		if (!strcasecmp(var->name, "trunk"))
+			sla_add_trunk_to_station(station, var);
+		else if (!strcasecmp(var->name, "autocontext"))
 			ast_string_field_set(station, autocontext, var->value);
+		else if (!strcasecmp(var->name, "ringtimeout")) {
+			if (sscanf(var->value, "%u", &station->ring_timeout) != 1) {
+				ast_log(LOG_WARNING, "Invalid ringtimeout '%s' specified for station '%s'\n",
+					var->value, station->name);
+				station->ring_timeout = 0;
+			}
 		} else if (strcasecmp(var->name, "type") && strcasecmp(var->name, "device")) {
 			ast_log(LOG_ERROR, "Invalid option '%s' specified at line %d of %s!\n",
 				var->name, var->lineno, SLA_CONFIG_FILE);
@@ -4010,7 +4038,7 @@
 	return 0;
 }
 
-static int load_config_sla(void)
+static int sla_load_config(void)
 {
 	struct ast_config *cfg;
 	const char *cat = NULL;
@@ -4030,9 +4058,9 @@
 			continue;
 		}
 		if (!strcasecmp(type, "trunk"))
-			res = build_trunk(cfg, cat);
+			res = sla_build_trunk(cfg, cat);
 		else if (!strcasecmp(type, "station"))
-			res = build_station(cfg, cat);
+			res = sla_build_station(cfg, cat);
 		else {
 			ast_log(LOG_WARNING, "Entry in %s defined with invalid type '%s'!\n",
 				SLA_CONFIG_FILE, type);
@@ -4052,7 +4080,7 @@
 
 	load_config_meetme();
 	if (!reload)
-		res = load_config_sla();
+		res = sla_load_config();
 
 	return res;
 }
@@ -4075,7 +4103,7 @@
 
 	ast_module_user_hangup_all();
 	
-	destroy_sla();
+	sla_destroy();
 
 	return res;
 }

Modified: team/russell/sla_updates/configs/sla.conf.sample
URL: http://svn.digium.com/view/asterisk/team/russell/sla_updates/configs/sla.conf.sample?view=diff&rev=54522&r1=54521&r2=54522
==============================================================================
--- team/russell/sla_updates/configs/sla.conf.sample (original)
+++ team/russell/sla_updates/configs/sla.conf.sample Wed Feb 14 17:10:58 2007
@@ -56,6 +56,9 @@
 ; device for this station should have its context configured to the same one
 ; listed here.
 autocontext=sla_stations
+; Set a timeout for how long to allow the station to ring for an incoming call.
+; This is specified in seconds.
+ringtimeout=10
 ; Individually list all of the trunks that will appear on this station.  This
 ; order is significant.  It should be the same order as they appear on the
 ; phone.  The order here defines the order of preference that the trunks will
@@ -63,7 +66,11 @@
 trunk=line1
 trunk=line2
 trunk=line3
-trunk=line4
+; A ring timeout for the station can also be specified for a specific trunk.
+; If a ring timeout is specified both for the whole station and for a specific
+; trunk on a station, the setting for the specific trunk will take priority.
+; This value is in seconds.
+trunk=line4,ringtimeout=5
 
 ; Define a station that uses the configuration from the template "station".
 [station1](station)



More information about the asterisk-commits mailing list