[asterisk-commits] russell: branch russell/sla_rewrite r53747 - in /team/russell/sla_rewrite: ap...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Feb 9 11:11:17 MST 2007


Author: russell
Date: Fri Feb  9 12:11:16 2007
New Revision: 53747

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53747
Log:
Keep track of active channels per trunk on each station instead of globally for
a station.  There can be more than one channel active for a since station at a
time, when calls are on hold.  Also, for changing state on blinky lights for
hold state, we have to know exactly which trunk the station is on the phone
with.

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

Modified: team/russell/sla_rewrite/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_rewrite/apps/app_meetme.c?view=diff&rev=53747&r1=53746&r2=53747
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Fri Feb  9 12:11:16 2007
@@ -360,7 +360,6 @@
 	);
 	AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
 	struct ast_dial *dial;
-	struct ast_channel *chan;
 };
 
 struct sla_station_ref {
@@ -390,6 +389,7 @@
 	AST_LIST_ENTRY(sla_trunk_ref) entry;
 	struct sla_trunk *trunk;
 	enum sla_trunk_state state;
+	struct ast_channel *chan;
 };
 
 static AST_RWLIST_HEAD_STATIC(sla_stations, sla_station);
@@ -1102,22 +1102,21 @@
 	struct sla_trunk_ref *trunk_ref = NULL;
 	char *trunk_name;
 
+	trunk_name = ast_strdupa(conf->confno);
+	strsep(&trunk_name, "_");
+	if (ast_strlen_zero(trunk_name)) {
+		ast_log(LOG_ERROR, "Invalid conference name for SLA - '%s'!\n", conf->confno);
+		return;
+	}
+
 	AST_RWLIST_RDLOCK(&sla_stations);
 	AST_RWLIST_TRAVERSE(&sla_stations, station, entry) {
-		if (station->chan != chan)
-			continue;
-		trunk_name = ast_strdupa(conf->confno);
-		strsep(&trunk_name, "_");
-		if (ast_strlen_zero(trunk_name)) {
-			AST_RWLIST_UNLOCK(&sla_stations);
-			ast_log(LOG_ERROR, "Invalid conference name for SLA - '%s'!\n", conf->confno);
-			return;
-		}
 		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
-			if (!strcmp(trunk_ref->trunk->name, trunk_name))
+			if (trunk_ref->chan == chan && !strcmp(trunk_ref->trunk->name, trunk_name))
 				break;
 		}
-		break;
+		if (trunk_ref)
+			break;
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);
 
@@ -2962,7 +2961,7 @@
 
 	AST_LIST_TRAVERSE(&sla_stations, station, entry) {
 		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
-			if (trunk_ref->trunk != trunk || (inactive_only ? station->chan : 0))
+			if (trunk_ref->trunk != trunk || (inactive_only ? trunk_ref->chan : 0))
 				continue;
 			trunk_ref->state = state;
 			ast_device_state_changed("SLA:%s_%s", station->name, trunk->name);
@@ -2973,7 +2972,7 @@
 
 struct run_station_args {
 	struct sla_station *station;
-	struct sla_trunk *trunk;
+	struct sla_trunk_ref *trunk_ref;
 	ast_mutex_t *cond_lock;
 	ast_cond_t *cond;
 };
@@ -2981,7 +2980,7 @@
 static void *run_station(void *data)
 {
 	struct sla_station *station;
-	struct sla_trunk *trunk;
+	struct sla_trunk_ref *trunk_ref;
 	char conf_name[MAX_CONFNUM];
 	struct ast_flags conf_flags = { 0 };
 	struct ast_conference *conf;
@@ -2989,27 +2988,31 @@
 	{
 		struct run_station_args *args = data;
 		station = args->station;
-		trunk = args->trunk;
+		trunk_ref = args->trunk_ref;
 		ast_mutex_lock(args->cond_lock);
 		ast_cond_signal(args->cond);
 		ast_mutex_unlock(args->cond_lock);
 		/* args is no longer valid here. */
 	}
 
-	ast_atomic_fetchadd_int((int *) &trunk->active_stations, 1);
-	snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk->name);
+	ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, 1);
+	snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
 	ast_set_flag(&conf_flags, 
 		CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
-	ast_answer(station->chan);
+	ast_answer(trunk_ref->chan);
 	conf = build_conf(conf_name, "", "", 0, 0, 1);
 	if (conf)
-		conf_run(station->chan, conf, conf_flags.flags, NULL);
-	station->chan = NULL;
-	if (ast_atomic_dec_and_test((int *) &trunk->active_stations)) {
+		conf_run(trunk_ref->chan, conf, conf_flags.flags, NULL);
+	trunk_ref->chan = NULL;
+	if (ast_atomic_dec_and_test((int *) &trunk_ref->trunk->active_stations)) {
 		strncat(conf_name, "|K", sizeof(conf_name) - strlen(conf_name) - 1);
 		admin_exec(NULL, conf_name);
-		change_trunk_state(trunk, SLA_TRUNK_STATE_IDLE, 0);
-	}
+		change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
+	}
+
+	ast_dial_join(station->dial);
+	ast_dial_destroy(station->dial);
+	station->dial = NULL;
 
 	return NULL;
 }
@@ -3146,7 +3149,6 @@
 				break;
 			case AST_DIAL_RESULT_ANSWERED:
 				AST_LIST_REMOVE_CURRENT(&ringing_stations, entry);
-				station_ref->station->chan = ast_dial_answered(station_ref->station->dial);
 				/* Find the appropriate trunk to answer. */
 				AST_LIST_TRAVERSE(&station_ref->station->trunks, s_trunk_ref, entry) {
 					ast_mutex_lock(&sla.lock);
@@ -3166,9 +3168,10 @@
 						station_ref->station->name);
 					break;
 				}
+				s_trunk_ref->chan = ast_dial_answered(station_ref->station->dial);
 				ast_answer(trunk_ref->trunk->chan);
 				change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, 0);
-				args.trunk = trunk_ref->trunk;
+				args.trunk_ref = s_trunk_ref;
 				args.station = station_ref->station;
 				args.cond = &cond;
 				args.cond_lock = &cond_lock;
@@ -3417,12 +3420,12 @@
 	snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_ref->trunk->name);
 	ast_set_flag(&conf_flags, 
 		CONFFLAG_QUIET | CONFFLAG_MARKEDEXIT | CONFFLAG_PASS_DTMF | CONFFLAG_SLA_STATION);
-	station->chan = chan;
+	trunk_ref->chan = chan;
 	ast_answer(chan);
 	conf = build_conf(conf_name, "", "", 0, 0, 1);
 	if (conf)
 		conf_run(chan, conf, conf_flags.flags, NULL);
-	station->chan = NULL;
+	trunk_ref->chan = NULL;
 	res = ast_atomic_fetchadd_int((int *) &trunk_ref->trunk->active_stations, -1);
 	if (res == 1) {	
 		strncat(conf_name, "|K", sizeof(conf_name) - strlen(conf_name) - 1);

Modified: team/russell/sla_rewrite/configs/sla.conf.sample
URL: http://svn.digium.com/view/asterisk/team/russell/sla_rewrite/configs/sla.conf.sample?view=diff&rev=53747&r1=53746&r2=53747
==============================================================================
--- team/russell/sla_rewrite/configs/sla.conf.sample (original)
+++ team/russell/sla_rewrite/configs/sla.conf.sample Fri Feb  9 12:11:16 2007
@@ -1,9 +1,5 @@
 ;
 ; Configuration for Shared Line Appearances (SLA).
-;
-; Asterisk is a PBX, not a key system.  However, people still insist on being
-; able to make Asterisk act like a key system.  So, here it is.  This has got
-; to be the most complicated implementation of a simple key system, ever.
 ;
 
 ; ---- General Options ----------------



More information about the asterisk-commits mailing list