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

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Feb 15 09:47:08 MST 2007


Author: russell
Date: Thu Feb 15 10:47:07 2007
New Revision: 54625

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54625
Log:
Keep track of when dialing a station began

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=54625&r1=54624&r2=54625
==============================================================================
--- team/russell/sla_updates/apps/app_meetme.c (original)
+++ team/russell/sla_updates/apps/app_meetme.c Thu Feb 15 10:47:07 2007
@@ -455,6 +455,14 @@
 	AST_LIST_ENTRY(sla_ringing_trunk) entry;
 };
 
+/*! \brief A station that is ringing */
+struct sla_ringing_station {
+	struct sla_station *station;
+	/*! The time that this station started ringing */
+	struct timeval ring_begin;
+	AST_LIST_ENTRY(sla_ringing_station) entry;
+};
+
 /*!
  * \brief A structure for data used by the sla thread
  */
@@ -464,7 +472,7 @@
 	ast_cond_t cond;
 	ast_mutex_t lock;
 	AST_LIST_HEAD_NOLOCK(, sla_ringing_trunk) ringing_trunks;
-	AST_LIST_HEAD_NOLOCK(, sla_station_ref) ringing_stations;
+	AST_LIST_HEAD_NOLOCK(, sla_ringing_station) ringing_stations;
 	AST_LIST_HEAD_NOLOCK(, sla_failed_station) failed_stations;
 	AST_LIST_HEAD_NOLOCK(, sla_event) event_q;
 	unsigned int stop:1;
@@ -2982,7 +2990,7 @@
 /*! \brief Find an SLA trunk by name
  * \note This must be called with the sla_trunks container locked
  */
-static struct sla_trunk *find_trunk(const char *name)
+static struct sla_trunk *sla_find_trunk(const char *name)
 {
 	struct sla_trunk *trunk = NULL;
 
@@ -2997,7 +3005,7 @@
 /*! \brief Find an SLA station by name
  * \note This must be called with the sla_stations container locked
  */
-static struct sla_station *find_station(const char *name)
+static struct sla_station *sla_find_station(const char *name)
 {
 	struct sla_station *station = NULL;
 
@@ -3009,7 +3017,7 @@
 	return station;
 }
 
-static struct sla_trunk_ref *find_trunk_ref(const struct sla_station *station,
+static struct sla_trunk_ref *sla_sla_find_trunk_ref(const struct sla_station *station,
 	const char *name)
 {
 	struct sla_trunk_ref *trunk_ref = NULL;
@@ -3022,7 +3030,7 @@
 	return trunk_ref;
 }
 
-static struct sla_station_ref *create_station_ref(struct sla_station *station)
+static struct sla_station_ref *sla_create_station_ref(struct sla_station *station)
 {
 	struct sla_station_ref *station_ref;
 
@@ -3034,7 +3042,20 @@
 	return station_ref;
 }
 
-static void change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state, int inactive_only)
+static struct sla_ringing_station *sla_create_ringing_station(struct sla_station *station)
+{
+	struct sla_ringing_station *ringing_station;
+
+	if (!(ringing_station = ast_calloc(1, sizeof(*ringing_station))))
+		return NULL;
+
+	ringing_station->station = station;
+	ringing_station->ring_begin = ast_tvnow();
+
+	return ringing_station;
+}
+
+static void sla_change_trunk_state(const struct sla_trunk *trunk, enum sla_trunk_state state, int inactive_only)
 {
 	struct sla_station *station;
 	struct sla_trunk_ref *trunk_ref;
@@ -3089,7 +3110,7 @@
 	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_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
+		sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
 	}
 
 	ast_dial_join(station->dial);
@@ -3106,9 +3127,9 @@
 
 static void sla_handle_dial_state_event(void)
 {
-	struct sla_station_ref *station_ref;
-
-	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, station_ref, entry) {
+	struct sla_ringing_station *ringing_station;
+
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
 		struct sla_trunk_ref *s_trunk_ref;
 		struct sla_ringing_trunk *ringing_trunk;
 		struct run_station_args args;
@@ -3118,22 +3139,22 @@
 		ast_mutex_t cond_lock;
 		ast_cond_t cond;
 
-		switch ((dial_res = ast_dial_state(station_ref->station->dial))) {
+		switch ((dial_res = ast_dial_state(ringing_station->station->dial))) {
 		case AST_DIAL_RESULT_HANGUP:
 		case AST_DIAL_RESULT_INVALID:
 		case AST_DIAL_RESULT_FAILED:
 		case AST_DIAL_RESULT_TIMEOUT:
 		case AST_DIAL_RESULT_UNANSWERED:
 			AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
-			ast_dial_join(station_ref->station->dial);
-			ast_dial_destroy(station_ref->station->dial);
-			station_ref->station->dial = NULL;
-			free(station_ref);
+			ast_dial_join(ringing_station->station->dial);
+			ast_dial_destroy(ringing_station->station->dial);
+			ringing_station->station->dial = NULL;
+			free(ringing_station);
 			break;
 		case AST_DIAL_RESULT_ANSWERED:
 			AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
 			/* Find the appropriate trunk to answer. */
-			AST_LIST_TRAVERSE(&station_ref->station->trunks, s_trunk_ref, entry) {
+			AST_LIST_TRAVERSE(&ringing_station->station->trunks, s_trunk_ref, entry) {
 				ast_mutex_lock(&sla.lock);
 				AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, ringing_trunk, entry) {
 					if (s_trunk_ref->trunk == ringing_trunk->trunk) {
@@ -3148,18 +3169,18 @@
 			}
 			if (!ringing_trunk) {
 				ast_log(LOG_DEBUG, "Found no ringing trunk for station '%s' to answer!\n",
-					station_ref->station->name);
+					ringing_station->station->name);
 				break;
 			}
-			s_trunk_ref->chan = ast_dial_answered(station_ref->station->dial);
+			s_trunk_ref->chan = ast_dial_answered(ringing_station->station->dial);
 			ast_answer(ringing_trunk->trunk->chan);
-			change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, 0);
+			sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_UP, 0);
 			args.trunk_ref = s_trunk_ref;
-			args.station = station_ref->station;
+			args.station = ringing_station->station;
 			args.cond = &cond;
 			args.cond_lock = &cond_lock;
 			free(ringing_trunk);
-			free(station_ref);
+			free(ringing_station);
 			ast_mutex_init(&cond_lock);
 			ast_cond_init(&cond, NULL);
 			pthread_attr_init(&attr);
@@ -3193,6 +3214,7 @@
 	struct sla_trunk_ref *trunk_ref;
 	struct sla_station_ref *station_ref;
 	struct sla_ringing_trunk *ringing_trunk;
+	struct sla_ringing_station *ringing_station;
 
 	ast_mutex_lock(&sla.lock);
 
@@ -3202,7 +3224,6 @@
 		AST_LIST_TRAVERSE(&ringing_trunk->trunk->stations, station_ref, entry) {
 			char *tech, *tech_data;
 			struct ast_dial *dial;
-			struct sla_station_ref *ringing_ref;
 			struct sla_failed_station *failed_station;
 			/* Did we fail to dial this station earlier?  If so, has it been
  			 * a minute since we tried? */
@@ -3219,11 +3240,11 @@
 			if (failed_station)
 				continue;
 			AST_LIST_TRAVERSE_SAFE_END
-			AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_ref, entry) {
-				if (station_ref->station == ringing_ref->station)
+			AST_LIST_TRAVERSE(&sla.ringing_stations, ringing_station, entry) {
+				if (station_ref->station == ringing_station->station)
 					break;
 			}
-			if (ringing_ref)
+			if (ringing_station)
 				continue;
 			if (!(dial = ast_dial_create()))
 				continue;
@@ -3243,13 +3264,13 @@
 				AST_LIST_INSERT_HEAD(&sla.failed_stations, failed_station, entry);
 				continue;
 			}
-			if (!(ringing_ref = create_station_ref(station_ref->station))) {
+			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_ref, entry);
+			AST_LIST_INSERT_HEAD(&sla.ringing_stations, ringing_station, entry);
 			ast_log(LOG_DEBUG, "Started dialing station '%s'\n", station_ref->station->name);
 		}
 	}
@@ -3257,8 +3278,8 @@
 	/* 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, station_ref, entry) {
-		AST_LIST_TRAVERSE(&station_ref->station->trunks, trunk_ref, entry) {
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_stations, ringing_station, entry) {
+		AST_LIST_TRAVERSE(&ringing_station->station->trunks, trunk_ref, entry) {
 			struct sla_ringing_trunk *ringing_trunk;
 			ast_mutex_lock(&sla.lock);
 			AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_trunk, entry) {
@@ -3271,10 +3292,10 @@
 		}
 		if (!trunk_ref) {
 			AST_LIST_REMOVE_CURRENT(&sla.ringing_stations, entry);
-			ast_dial_join(station_ref->station->dial);
-			ast_dial_destroy(station_ref->station->dial);
-			station_ref->station->dial = NULL;
-			free(station_ref);
+			ast_dial_join(ringing_station->station->dial);
+			ast_dial_destroy(ringing_station->station->dial);
+			ringing_station->station->dial = NULL;
+			free(ringing_station);
 		}
 	}
 	AST_LIST_TRAVERSE_SAFE_END
@@ -3286,13 +3307,13 @@
 	event->trunk_ref->state = SLA_TRUNK_STATE_ONHOLD;
 	ast_device_state_changed("SLA:%s_%s", 
 		event->station->name, event->trunk_ref->trunk->name);
-	change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD, 1);	
+	sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_ONHOLD, 1);	
 }
 
 static void sla_handle_unhold_event(struct sla_event *event)
 {
 	if (ast_atomic_dec_and_test((int *) &event->trunk_ref->trunk->hold_stations) == 1)
-		change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_UP, 0);
+		sla_change_trunk_state(event->trunk_ref->trunk, SLA_TRUNK_STATE_UP, 0);
 	else {
 		event->trunk_ref->state = SLA_TRUNK_STATE_UP;
 		ast_device_state_changed("SLA:%s_%s",
@@ -3306,7 +3327,7 @@
 
 	snprintf(buf, sizeof(buf), "SLA_%s|K", ringing_trunk->trunk->name);
 	admin_exec(NULL, buf);
-	change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, 0);
+	sla_change_trunk_state(ringing_trunk->trunk, SLA_TRUNK_STATE_IDLE, 0);
 
 	free(ringing_trunk);
 }
@@ -3374,7 +3395,7 @@
 static void *sla_thread(void *data)
 {
 	struct sla_failed_station *failed_station;
-	struct sla_station_ref *station_ref;
+	struct sla_ringing_station *ringing_station;
 
 	ast_mutex_lock(&sla.lock);
 
@@ -3419,8 +3440,8 @@
 
 	ast_mutex_unlock(&sla.lock);
 
-	while ((station_ref = AST_LIST_REMOVE_HEAD(&sla.ringing_stations, entry)))
-		free(station_ref);
+	while ((ringing_station = AST_LIST_REMOVE_HEAD(&sla.ringing_stations, entry)))
+		free(ringing_station);
 
 	while ((failed_station = AST_LIST_REMOVE_HEAD(&sla.failed_stations, entry)))
 		free(failed_station);
@@ -3550,7 +3571,7 @@
 	}
 
 	AST_RWLIST_RDLOCK(&sla_stations);
-	station = find_station(station_name);
+	station = sla_find_station(station_name);
 	AST_RWLIST_UNLOCK(&sla_stations);
 
 	if (!station) {
@@ -3561,7 +3582,7 @@
 
 	AST_RWLIST_RDLOCK(&sla_trunks);
 	if (!ast_strlen_zero(trunk_name))
-		trunk_ref = find_trunk_ref(station, trunk_name);
+		trunk_ref = sla_sla_find_trunk_ref(station, trunk_name);
 	else {
 		AST_LIST_TRAVERSE(&station->trunks, trunk_ref, entry) {
 			if (trunk_ref->state == SLA_TRUNK_STATE_IDLE)
@@ -3587,7 +3608,7 @@
 			.cond_lock = &cond_lock,
 			.cond = &cond,
 		};
-		change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, 0);
+		sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_UP, 0);
 		/* Create a thread to dial the trunk and dump it into the conference.
 		 * However, we want to wait until the trunk has been dialed and the
 		 * conference is created before continuing on here. */
@@ -3607,7 +3628,7 @@
 		if (!trunk_ref->trunk->chan) {
 			ast_log(LOG_DEBUG, "Trunk didn't get created. chan: %lx\n", (long) trunk_ref->trunk->chan);
 			pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "CONGESTION");
-			change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
+			sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
 			return 0;
 		}
 	}
@@ -3626,7 +3647,7 @@
 	if (res == 1) {	
 		strncat(conf_name, "|K", sizeof(conf_name) - strlen(conf_name) - 1);
 		admin_exec(NULL, conf_name);
-		change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
+		sla_change_trunk_state(trunk_ref->trunk, SLA_TRUNK_STATE_IDLE, 0);
 	}
 	
 	pbx_builtin_setvar_helper(chan, "SLASTATION_STATUS", "SUCCESS");
@@ -3656,7 +3677,7 @@
 	ringing_trunk->trunk = trunk;
 	ringing_trunk->ring_begin = ast_tvnow();
 
-	change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, 0);
+	sla_change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, 0);
 
 	ast_mutex_lock(&sla.lock);
 	AST_LIST_INSERT_HEAD(&sla.ringing_trunks, ringing_trunk, entry);
@@ -3676,7 +3697,7 @@
 	struct sla_ringing_trunk *ringing_trunk;
 
 	AST_RWLIST_RDLOCK(&sla_trunks);
-	trunk = find_trunk(trunk_name);
+	trunk = sla_find_trunk(trunk_name);
 	AST_RWLIST_UNLOCK(&sla_trunks);
 	if (!trunk) {
 		ast_log(LOG_ERROR, "SLA Trunk '%s' not found!\n", trunk_name);
@@ -3966,11 +3987,10 @@
 		}
 	}
 
-	if (!(station_ref = ast_calloc(1, sizeof(*station_ref)))) {
+	if (!(station_ref = sla_create_station_ref(station))) {
 		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);



More information about the asterisk-commits mailing list