[svn-commits] russell: branch russell/sla_rewrite r52330 - in /team/russell/sla_rewrite: ap...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Jan 25 16:20:22 MST 2007


Author: russell
Date: Thu Jan 25 17:20:22 2007
New Revision: 52330

URL: http://svn.digium.com/view/asterisk?view=rev&rev=52330
Log:
Commit some more progress on the rewrite of SLA support.  This now has some
basic functionality.  This case now works:
  - Call comes in on a trunk
  - Stations start ringing and with the appropriate line flashing
  - Station answers
  - All stations show that line as in use
  - trunk hangs up, or all stations hung up, all phones show line as free

Modified:
    team/russell/sla_rewrite/apps/app_meetme.c
    team/russell/sla_rewrite/main/dial.c

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=52330&r1=52329&r2=52330
==============================================================================
--- team/russell/sla_rewrite/apps/app_meetme.c (original)
+++ team/russell/sla_rewrite/apps/app_meetme.c Thu Jan 25 17:20:22 2007
@@ -350,6 +350,7 @@
 		AST_STRING_FIELD(autocontext);	
 	);
 	AST_LIST_HEAD_NOLOCK(, sla_trunk_ref) trunks;
+	struct ast_channel *chan;
 };
 
 struct sla_station_ref {
@@ -365,7 +366,11 @@
 		AST_STRING_FIELD(autocontext);	
 	);
 	AST_LIST_HEAD_NOLOCK(, sla_station_ref) stations;
+	/*! Number of stations that use this trunk */
 	unsigned int num_stations;
+	/*! Number of stations currently on a call with this trunk */
+	unsigned int active_stations;
+	struct ast_channel *chan;
 	enum sla_trunk_state state;
 	pthread_t station_thread;
 };
@@ -905,6 +910,18 @@
 	return RESULT_SUCCESS;
 }
 
+static const char *trunkstate2str(enum sla_trunk_state state)
+{
+#define S(e) case e: return # e;
+	switch (state) {
+	S(SLA_TRUNK_STATE_IDLE)
+	S(SLA_TRUNK_STATE_RINGING)
+	S(SLA_TRUNK_STATE_UP)
+	}
+	return "Uknown State";
+#undef S
+}
+
 static const char sla_show_trunks_usage[] =
 "Usage: sla show trunks\n"
 "       This will list all trunks defined in sla.conf\n";
@@ -926,7 +943,8 @@
 					S_OR(station->autocontext, "(none)"));
 		AST_RWLIST_RDLOCK(&sla_trunks);
 		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry)
-			ast_cli(fd, "--- =====> Trunk Name: %s\n", trunk_ref->trunk->name);
+			ast_cli(fd, "--- =====> Trunk Name: %s State: %s\n", 
+				trunk_ref->trunk->name, trunkstate2str(trunk_ref->state));
 		AST_RWLIST_UNLOCK(&sla_trunks);
 		ast_cli(fd, "\n");
 	}
@@ -1534,8 +1552,10 @@
 			/* If I have been kicked, exit the conference */
 			if (user->adminflags & ADMINFLAG_KICKME) {
 				//You have been kicked.
-				if (!ast_streamfile(chan, "conf-kicked", chan->language))
+				if (!(confflags & CONFFLAG_QUIET) && 
+					!ast_streamfile(chan, "conf-kicked", chan->language)) {
 					ast_waitstream(chan, "");
+				}
 				ret = 0;
 				break;
 			}
@@ -2752,18 +2772,6 @@
 	ast_config_destroy(cfg);
 }
 
-static const char *trunkstate2str(enum sla_trunk_state state)
-{
-#define S(e) case e: return # e;
-	switch (state) {
-	S(SLA_TRUNK_STATE_IDLE)
-	S(SLA_TRUNK_STATE_RINGING)
-	S(SLA_TRUNK_STATE_UP)
-	}
-	return "Uknown State";
-#undef S
-}
-
 /*! \brief Find an SLA trunk by name
  * \note This must be called with the sla_trunks container locked
  */
@@ -2790,18 +2798,19 @@
 	struct sla_station_ref *station_ref;
 	struct ast_dial **dials;
 	struct sla_trunk_ref **trunk_refs;
-	struct ast_channel *chan;
-	struct ast_flags conf_flags;
+	struct sla_station **stations;
+	struct ast_flags conf_flags = { 0 };
 	struct ast_conference *conf;
 	int res = 0, len, num_dials = 0, i, winner;
 	char conf_name[MAX_CONFNUM];
 
 	len = (trunk->num_stations + 1) * sizeof(*dials);
-	ast_log(LOG_DEBUG, "len is %d\n", len);
 	dials = alloca(len);
 	memset(dials, 0, len);
 	trunk_refs = alloca(len);
 	memset(trunk_refs, 0, len);
+	stations = alloca(len);
+	memset(stations, 0, len);
 
 	AST_RWLIST_RDLOCK(&sla_stations);
 	AST_LIST_TRAVERSE(&trunk->stations, station_ref, entry) {
@@ -2829,6 +2838,7 @@
 			break;
 		}
 		trunk_refs[num_dials] = trunk_ref;
+		stations[num_dials] = station_ref->station;
 		dials[num_dials++] = dial;
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);
@@ -2858,12 +2868,16 @@
 	}
 
 	for (i = 0, winner = -1; ; i = (i + 1) % num_dials) {
+		enum ast_dial_result status;
 		if (!dials[i])
 			continue;
 
-		switch (ast_dial_status(dials[i])) {
+		switch ((status = ast_dial_status(dials[i]))) {
 		case AST_DIAL_RESULT_HANGUP:
-			trunk_refs[i]->state = SLA_TRUNK_STATE_IDLE;
+			if (trunk_refs[i]->state != SLA_TRUNK_STATE_IDLE) {
+				trunk_refs[i]->state = SLA_TRUNK_STATE_IDLE;
+				ast_device_state_changed("SLA:%s_%s", stations[i]->name, trunk->name);
+			}
 		case AST_DIAL_RESULT_INVALID:
 		case AST_DIAL_RESULT_FAILED:
 		case AST_DIAL_RESULT_TIMEOUT:
@@ -2871,19 +2885,29 @@
 			ast_dial_join(dials[i]);
 			ast_dial_destroy(dials[i]);
 			dials[i] = NULL;
+			ast_log(LOG_DEBUG, "breaking #1 i: %d status: %d\n", i, status);
 			break;
 		case AST_DIAL_RESULT_TRYING:
 			break;
 		case AST_DIAL_RESULT_RINGING:
 		case AST_DIAL_RESULT_PROGRESS:
 		case AST_DIAL_RESULT_PROCEEDING:
-			trunk_refs[i]->state = SLA_TRUNK_STATE_RINGING;
+			if (trunk_refs[i]->state != SLA_TRUNK_STATE_RINGING) {
+				trunk_refs[i]->state = SLA_TRUNK_STATE_RINGING;
+				ast_device_state_changed("SLA:%s_%s", stations[i]->name, trunk->name);
+			}
 			break;
 		case AST_DIAL_RESULT_ANSWERED:
 			winner = i;
+			ast_answer(trunk->chan);
+			trunk->state = SLA_TRUNK_STATE_UP;
+			for (i = 0; trunk_refs[i]; i++) {
+				trunk_refs[i]->state = SLA_TRUNK_STATE_UP;
+				ast_device_state_changed("SLA:%s_%s", stations[i]->name, trunk->name);
+			}
 			break;
 		}
-		if (winner > -1)
+		if (winner > -1 || trunk->state == SLA_TRUNK_STATE_IDLE)
 			break;
 	}
 
@@ -2895,17 +2919,35 @@
 		dials[i] = NULL;
 	}
 
-	chan = ast_dial_answered(dials[winner]);
+	if (winner == -1)
+		return NULL;
+
+	ast_atomic_fetchadd_int((int *) &trunk->active_stations, 1);
+	stations[winner]->chan = ast_dial_answered(dials[winner]);
 	ast_set_flag(&conf_flags,
 		CONFFLAG_QUIET |
 		CONFFLAG_MARKEDEXIT);
-	snprintf(conf_name, sizeof(conf_name), "SLA-%s", trunk->name);
+	snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk->name);
 	conf = build_conf(conf_name, "", "", 0, 0, 1);
 	if (conf)
-		res = conf_run(chan, conf, conf_flags.flags, NULL);
-	trunk_refs[winner]->state = SLA_TRUNK_STATE_IDLE;
+		res = conf_run(stations[winner]->chan, conf, conf_flags.flags, NULL);
+	res = ast_atomic_fetchadd_int((int *) &trunk->active_stations, -1);
+	if (res == 1) {	
+		strncat(conf_name, "|K", sizeof(conf_name) - strlen(conf_name) - 1);
+		admin_exec(NULL, conf_name);
+	}
+	
+	for (i = 0; stations[i]; i++) {
+		if (trunk_refs[i]->state != SLA_TRUNK_STATE_IDLE &&
+			(!stations[i]->chan || i == winner)) {
+			trunk_refs[i]->state = SLA_TRUNK_STATE_IDLE;
+			ast_device_state_changed("SLA:%s_%s", stations[i]->name, trunk->name);
+		}
+	}
+	
 	ast_dial_join(dials[winner]);
 	ast_dial_destroy(dials[winner]);
+	stations[winner]->chan = NULL;
 
 	return NULL;
 }
@@ -2916,7 +2958,7 @@
 	char conf_name[MAX_CONFNUM];
 	struct ast_conference *conf;
 	int res;
-	struct ast_flags conf_flags;
+	struct ast_flags conf_flags = { 0 };
 	struct sla_trunk *trunk;
 
 	AST_RWLIST_RDLOCK(&sla_trunks);
@@ -2927,6 +2969,7 @@
 		pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
 		return 0;
 	}
+	trunk->chan = chan;
 	if (trunk->state != SLA_TRUNK_STATE_IDLE) {
 		ast_log(LOG_ERROR, "Call came in on %s, but the trunk is in state %s?!\n",
 			trunk_name, trunkstate2str(trunk->state));
@@ -2936,7 +2979,7 @@
 	}
 	AST_RWLIST_UNLOCK(&sla_trunks);
 
-	snprintf(conf_name, sizeof(conf_name), "SLA-%s", trunk_name);
+	snprintf(conf_name, sizeof(conf_name), "SLA_%s", trunk_name);
 	conf = build_conf(conf_name, "", "", 1, 1, 1);
 	if (!conf) {
 		pbx_builtin_setvar_helper(chan, "SLATRUNK_STATUS", "FAILURE");
@@ -2958,6 +3001,7 @@
 	trunk->state = SLA_TRUNK_STATE_RINGING;
 	res = conf_run(chan, conf, conf_flags.flags, NULL);
 	trunk->state = SLA_TRUNK_STATE_IDLE;
+	trunk->chan = NULL;
 
 	return 0;
 }
@@ -2981,8 +3025,21 @@
 			if (!strcasecmp(trunk_name, trunk_ref->trunk->name))
 				break;
 		}
-		if (trunk_ref)
-			res = trunk_ref->state;
+		if (!trunk_ref) {
+			AST_RWLIST_UNLOCK(&sla_trunks);
+			break;
+		}
+		switch (trunk_ref->state) {
+		case SLA_TRUNK_STATE_IDLE:
+			res = AST_DEVICE_NOT_INUSE;
+			break;
+		case SLA_TRUNK_STATE_RINGING:
+			res = AST_DEVICE_RINGING;
+			break;
+		case SLA_TRUNK_STATE_UP:
+			res = AST_DEVICE_INUSE;
+			break;
+		}
 		AST_RWLIST_UNLOCK(&sla_trunks);
 	}
 	AST_RWLIST_UNLOCK(&sla_stations);
@@ -3164,7 +3221,7 @@
 			if (!(trunk_ref = ast_calloc(1, sizeof(*trunk_ref))))
 				continue;
 			trunk_ref->trunk = trunk;
-			trunk_ref->state = AST_DEVICE_NOT_INUSE;
+			trunk_ref->state = SLA_TRUNK_STATE_IDLE;
 			if (!(station_ref = ast_calloc(1, sizeof(*station_ref)))) {
 				free(trunk_ref);
 				continue;

Modified: team/russell/sla_rewrite/main/dial.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_rewrite/main/dial.c?view=diff&rev=52330&r1=52329&r2=52330
==============================================================================
--- team/russell/sla_rewrite/main/dial.c (original)
+++ team/russell/sla_rewrite/main/dial.c Thu Jan 25 17:20:22 2007
@@ -229,7 +229,7 @@
 
 		/* Request that the channel be created */
 		if (!(channel->owner = ast_request(channel->tech, 
-			chan ? chan->nativeformats : 0xFFFFFFFF, numsubst, &channel->cause))) {
+			chan ? chan->nativeformats : AST_FORMAT_AUDIO_MASK, numsubst, &channel->cause))) {
 			continue;
 		}
 
@@ -534,12 +534,16 @@
 	enum ast_dial_result res = AST_DIAL_RESULT_TRYING;
 
 	/* Ensure required arguments are passed */
-	if (!dial || (!chan && !async))
+	if (!dial || (!chan && !async)) {
+		ast_log(LOG_DEBUG, "invalid #1\n");
 		return AST_DIAL_RESULT_INVALID;
+	}
 
 	/* If there are no channels to dial we can't very well try to dial them */
-	if (AST_LIST_EMPTY(&dial->channels))
+	if (AST_LIST_EMPTY(&dial->channels)) {
+		ast_log(LOG_DEBUG, "invalid #2\n");
 		return AST_DIAL_RESULT_INVALID;
+	}
 
 	/* Dial each requested channel */
 	if (!begin_dial(dial, chan))
@@ -547,6 +551,7 @@
 
 	/* If we are running async spawn a thread and send it away... otherwise block here */
 	if (async) {
+		dial->status = AST_DIAL_RESULT_TRYING;
 		/* Try to create a thread */
 		if (ast_pthread_create(&dial->thread, NULL, async_dial, dial)) {
 			/* Failed to create the thread - hangup all dialed channels and return failed */



More information about the svn-commits mailing list