[asterisk-commits] rmudgett: branch rmudgett/parking r330824 - /team/rmudgett/parking/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Aug 3 19:15:12 CDT 2011


Author: rmudgett
Date: Wed Aug  3 19:15:08 2011
New Revision: 330824

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=330824
Log:
Add warning msgs about parking lot ramp and spaces overlap.  Update unit test to exercise this.

Modified:
    team/rmudgett/parking/main/features.c

Modified: team/rmudgett/parking/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/parking/main/features.c?view=diff&rev=330824&r1=330823&r2=330824
==============================================================================
--- team/rmudgett/parking/main/features.c (original)
+++ team/rmudgett/parking/main/features.c Wed Aug  3 19:15:08 2011
@@ -5415,12 +5415,11 @@
  * \brief Create a new parking lot ramp dialplan usage node.
  *
  * \param exten Parking lot access ramp extension.
- * \param lot Parking lot supplying reference data.
  *
  * \retval New usage ramp node on success.
  * \retval NULL on error.
  */
-static struct parking_dp_ramp *build_dialplan_useage_ramp(const char *exten, struct ast_parkinglot *lot)
+static struct parking_dp_ramp *build_dialplan_useage_ramp(const char *exten)
 {
 	struct parking_dp_ramp *ramp_node;
 
@@ -5439,11 +5438,12 @@
  * \param ramp_map Current parking lot context ramp usage map.
  * \param exten Parking lot access ramp extension to add.
  * \param lot Parking lot supplying reference data.
+ * \param complain TRUE if to complain of parking lot ramp conflicts.
  *
  * \retval 0 on success.  The ramp_map is updated.
  * \retval -1 on failure.
  */
-static int usage_context_add_ramp(struct parking_dp_ramp_map *ramp_map, const char *exten, struct ast_parkinglot *lot)
+static int usage_context_add_ramp(struct parking_dp_ramp_map *ramp_map, const char *exten, struct ast_parkinglot *lot, int complain)
 {
 	struct parking_dp_ramp *cur_ramp;
 	struct parking_dp_ramp *new_ramp;
@@ -5457,10 +5457,15 @@
 		}
 		if (cmp == 0) {
 			/* The ramp is already in the map. */
+			if (complain) {
+				ast_log(LOG_WARNING,
+					"Parking lot '%s' parkext %s@%s used by another parking lot.\n",
+					lot->name, exten, lot->cfg.parking_con);
+			}
 			return 0;
 		}
 		/* The new parking lot ramp goes before this node. */
-		new_ramp = build_dialplan_useage_ramp(exten, lot);
+		new_ramp = build_dialplan_useage_ramp(exten);
 		if (!new_ramp) {
 			return -1;
 		}
@@ -5470,7 +5475,7 @@
 	AST_LIST_TRAVERSE_SAFE_END;
 
 	/* New parking lot access ramp goes on the end. */
-	new_ramp = build_dialplan_useage_ramp(exten, lot);
+	new_ramp = build_dialplan_useage_ramp(exten);
 	if (!new_ramp) {
 		return -1;
 	}
@@ -5484,12 +5489,11 @@
  *
  * \param start First parking lot space to add.
  * \param stop Last parking lot space to add.
- * \param lot Parking lot supplying reference data.
  *
  * \retval New usage ramp node on success.
  * \retval NULL on error.
  */
-static struct parking_dp_spaces *build_dialplan_useage_spaces(int start, int stop, struct ast_parkinglot *lot)
+static struct parking_dp_spaces *build_dialplan_useage_spaces(int start, int stop)
 {
 	struct parking_dp_spaces *spaces_node;
 
@@ -5510,11 +5514,12 @@
  * \param start First parking lot space to add.
  * \param stop Last parking lot space to add.
  * \param lot Parking lot supplying reference data.
+ * \param complain TRUE if to complain of parking lot spaces conflicts.
  *
  * \retval 0 on success.  The space_map is updated.
  * \retval -1 on failure.
  */
-static int usage_context_add_spaces(struct parking_dp_space_map *space_map, int start, int stop, struct ast_parkinglot *lot)
+static int usage_context_add_spaces(struct parking_dp_space_map *space_map, int start, int stop, struct ast_parkinglot *lot, int complain)
 {
 	struct parking_dp_spaces *cur_node;
 	struct parking_dp_spaces *expand_node;
@@ -5530,6 +5535,17 @@
 				return 0;
 			}
 
+			if (complain
+				&& ((cur_node->start <= start && start <= cur_node->stop)
+					|| (cur_node->start <= stop && stop <= cur_node->stop)
+					|| (start < cur_node->start && cur_node->stop < stop))) {
+				/* Only complain once per range add. */
+				complain = 0;
+				ast_log(LOG_WARNING,
+					"Parking lot '%s' parkpos %d-%d@%s overlaps another parking lot.\n",
+					lot->name, start, stop, lot->cfg.parking_con);
+			}
+
 			/* Current node is eaten by the expanding node. */
 			if (expand_node->stop < cur_node->stop) {
 				expand_node->stop = cur_node->stop;
@@ -5545,12 +5561,23 @@
 		}
 		if (stop + 1 < cur_node->start) {
 			/* New range is completely before current node. */
-			new_node = build_dialplan_useage_spaces(start, stop, lot);
+			new_node = build_dialplan_useage_spaces(start, stop);
 			if (!new_node) {
 				return -1;
 			}
 			AST_LIST_INSERT_BEFORE_CURRENT(new_node, node);
 			return 0;
+		}
+
+		if (complain
+			&& ((cur_node->start <= start && start <= cur_node->stop)
+				|| (cur_node->start <= stop && stop <= cur_node->stop)
+				|| (start < cur_node->start && cur_node->stop < stop))) {
+			/* Only complain once per range add. */
+			complain = 0;
+			ast_log(LOG_WARNING,
+				"Parking lot '%s' parkpos %d-%d@%s overlaps another parking lot.\n",
+				lot->name, start, stop, lot->cfg.parking_con);
 		}
 
 		/* Current node range overlaps or is immediately adjacent to new range. */
@@ -5576,7 +5603,7 @@
 	}
 
 	/* New range goes on the end. */
-	new_node = build_dialplan_useage_spaces(start, stop, lot);
+	new_node = build_dialplan_useage_spaces(start, stop);
 	if (!new_node) {
 		return -1;
 	}
@@ -5590,22 +5617,24 @@
  *
  * \param ctx_node Usage node to add parking lot spaces.
  * \param lot Parking lot to add data to ctx_node.
+ * \param complain TRUE if to complain of parking lot ramp and spaces conflicts.
  *
  * \retval 0 on success.
  * \retval -1 on error.
  */
-static int dialplan_usage_add_parkinglot_data(struct parking_dp_context *ctx_node, struct ast_parkinglot *lot)
-{
-	if (usage_context_add_ramp(&ctx_node->access_extens, lot->cfg.parkext, lot)) {
+static int dialplan_usage_add_parkinglot_data(struct parking_dp_context *ctx_node, struct ast_parkinglot *lot, int complain)
+{
+	if (usage_context_add_ramp(&ctx_node->access_extens, lot->cfg.parkext, lot,
+		complain)) {
 		return -1;
 	}
 	if (usage_context_add_spaces(&ctx_node->spaces, lot->cfg.parking_start,
-		lot->cfg.parking_stop, lot)) {
+		lot->cfg.parking_stop, lot, complain)) {
 		return -1;
 	}
 	if (lot->cfg.parkaddhints
 		&& usage_context_add_spaces(&ctx_node->hints, lot->cfg.parking_start,
-			lot->cfg.parking_stop, lot)) {
+			lot->cfg.parking_stop, lot, 0)) {
 		return -1;
 	}
 	return 0;
@@ -5628,7 +5657,7 @@
 	if (!ctx_node) {
 		return NULL;
 	}
-	if (dialplan_usage_add_parkinglot_data(ctx_node, lot)) {
+	if (dialplan_usage_add_parkinglot_data(ctx_node, lot, 0)) {
 		destroy_dialplan_usage_context(ctx_node);
 		return NULL;
 	}
@@ -5642,11 +5671,12 @@
  *
  * \param usage_map Parking lot usage map to add the given parking lot.
  * \param lot Parking lot to add dialplan usage.
+ * \param complain TRUE if to complain of parking lot ramp and spaces conflicts.
  *
  * \retval 0 on success.
  * \retval -1 on error.
  */
-static int dialplan_usage_add_parkinglot(struct parking_dp_map *usage_map, struct ast_parkinglot *lot)
+static int dialplan_usage_add_parkinglot(struct parking_dp_map *usage_map, struct ast_parkinglot *lot, int complain)
 {
 	struct parking_dp_context *cur_ctx;
 	struct parking_dp_context *new_ctx;
@@ -5660,7 +5690,7 @@
 		}
 		if (cmp == 0) {
 			/* This is the node we will add parking lot spaces to the map. */
-			return dialplan_usage_add_parkinglot_data(cur_ctx, lot);
+			return dialplan_usage_add_parkinglot_data(cur_ctx, lot, complain);
 		}
 		/* The new parking lot context goes before this node. */
 		new_ctx = build_dialplan_useage_context(lot);
@@ -5686,11 +5716,12 @@
  * \brief Build the dialplan usage map of the current parking lot container.
  *
  * \param usage_map Parking lot usage map.  Must already be initialized.
+ * \param complain TRUE if to complain of parking lot ramp and spaces conflicts.
  *
  * \retval 0 on success.  The usage_map is filled in.
  * \retval -1 on failure.  Built usage_map is incomplete.
  */
-static int build_dialplan_useage_map(struct parking_dp_map *usage_map)
+static int build_dialplan_useage_map(struct parking_dp_map *usage_map, int complain)
 {
 	int status = 0;
 	struct ao2_iterator iter;
@@ -5700,7 +5731,7 @@
 	iter = ao2_iterator_init(parkinglots, 0);
 	for (; (curlot = ao2_iterator_next(&iter)); ao2_ref(curlot, -1)) {
 		/* Add the parking lot to the map. */
-		if (dialplan_usage_add_parkinglot(usage_map, curlot)) {
+		if (dialplan_usage_add_parkinglot(usage_map, curlot, complain)) {
 			ao2_ref(curlot, -1);
 			status = -1;
 			break;
@@ -6019,7 +6050,7 @@
 	}
 
 	/* Save current parking lot dialplan needs. */
-	if (build_dialplan_useage_map(&old_usage_map)) {
+	if (build_dialplan_useage_map(&old_usage_map, 0)) {
 		destroy_dialplan_usage_map(&old_usage_map);
 
 		/* Allow reloading later to see if conditions have improved. */
@@ -6035,7 +6066,7 @@
 		"callback to remove marked parking lots");
 
 	/* Save updated parking lot dialplan needs. */
-	if (build_dialplan_useage_map(&new_usage_map)) {
+	if (build_dialplan_useage_map(&new_usage_map, 1)) {
 		/*
 		 * Yuck, if this failure caused any parking lot dialplan items
 		 * to be lost, they will likely remain lost until Asterisk is
@@ -7094,7 +7125,7 @@
 {
 	struct parking_dp_space_map *dead_spaces = (struct parking_dp_space_map *) context;
 
-	usage_context_add_spaces(dead_spaces, space, space, NULL);
+	usage_context_add_spaces(dead_spaces, space, space, NULL, 0);
 }
 #endif	/* defined(TEST_FRAMEWORK) */
 
@@ -7148,7 +7179,7 @@
 		ast_copy_string(lot->cfg.parkext, table->ramp, sizeof(lot->cfg.parkext));
 		lot->cfg.parking_start = table->start;
 		lot->cfg.parking_stop = table->stop;
-		if (dialplan_usage_add_parkinglot_data(ctx_node, lot)) {
+		if (dialplan_usage_add_parkinglot_data(ctx_node, lot, 1)) {
 			ast_test_status_update(test, "Failed to add parking lot data for %s\n", what);
 			destroy_dialplan_usage_context(ctx_node);
 			return NULL;
@@ -7168,22 +7199,26 @@
 	{ "701", 18, 19, "10-11,14-15,18-19" },
 	{ "703", 12, 13, "10-15,18-19" },
 	{ "704", 16, 17, "10-19" },
-	{ "704", 10, 19, "10-19" },
+
+	/* Parking ramp and space conflicts are intended with these lines. */
+	{ "704", 9, 19, "9-19" },
+	{ "704", 9, 20, "9-20" },
+	{ "704", 8, 21, "8-21" },
 
 	/* Add more spaces to ctx to test removing dead parking spaces. */
-	{ "705", 21, 23, "10-19,21-23" },
-	{ "706", 26, 29, "10-19,21-23,26-29" },
-	{ "707", 31, 32, "10-19,21-23,26-29,31-32" },
-	{ "708", 36, 38, "10-19,21-23,26-29,31-32,36-38" },
-	{ "708", 40, 41, "10-19,21-23,26-29,31-32,36-38,40-41" },
+	{ "705", 23, 25, "8-21,23-25" },
+	{ "706", 28, 31, "8-21,23-25,28-31" },
+	{ "707", 33, 34, "8-21,23-25,28-31,33-34" },
+	{ "708", 38, 40, "8-21,23-25,28-31,33-34,38-40" },
+	{ "709", 42, 43, "8-21,23-25,28-31,33-34,38-40,42-43" },
 };
 
 static const struct test_map test_new_ctx[] = {
 	{ "702", 4, 5, "4-5" },
-	{ "704", 22, 24, "4-5,22-24" },
-	{ "709", 27, 28, "4-5,22-24,27-28" },
-	{ "710", 30, 33, "4-5,22-24,27-28,30-33" },
-	{ "711", 35, 37, "4-5,22-24,27-28,30-33,35-37" },
+	{ "704", 24, 26, "4-5,24-26" },
+	{ "709", 29, 30, "4-5,24-26,29-30" },
+	{ "710", 32, 35, "4-5,24-26,29-30,32-35" },
+	{ "711", 37, 39, "4-5,24-26,29-30,32-35,37-39" },
 };
 #endif	/* defined(TEST_FRAMEWORK) */
 
@@ -7214,7 +7249,9 @@
 	}
 	ast_copy_string(lot->cfg.parking_con, "test-ctx", sizeof(lot->cfg.parking_con));
 
-	ast_test_status_update(test, "Build old_ctx map\n");
+	ast_test_status_update(test,
+		"Build old_ctx map\n");
+	ast_log(LOG_NOTICE, "6 Ramp and space conflict warnings are expected.\n");
 	old_ctx = test_build_maps(test, lot, "test_old_ctx", test_old_ctx,
 		ARRAY_LEN(test_old_ctx));
 	if (!old_ctx) {
@@ -7233,7 +7270,7 @@
 	ast_test_status_update(test, "Test removing dead parking spaces\n");
 	remove_dead_spaces_usage((void *) &dead_spaces, &old_ctx->spaces,
 		&new_ctx->spaces, test_add_dead_space);
-	if (check_spaces(test, &dead_spaces, "10-19,21,26,29,38,40-41", "dead_spaces")) {
+	if (check_spaces(test, &dead_spaces, "8-21,23,28,31,40,42-43", "dead_spaces")) {
 		res = -1;
 		goto fail_dead_spaces;
 	}




More information about the asterisk-commits mailing list