[asterisk-commits] rmudgett: branch rmudgett/aoc_event r255702 - /team/rmudgett/aoc_event/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 31 18:14:11 CDT 2010


Author: rmudgett
Date: Wed Mar 31 18:14:07 2010
New Revision: 255702

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=255702
Log:
Adjust AOC AMI events after discussions with DVossel.

Modified:
    team/rmudgett/aoc_event/channels/sig_pri.c

Modified: team/rmudgett/aoc_event/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/aoc_event/channels/sig_pri.c?view=diff&rev=255702&r1=255701&r2=255702
==============================================================================
--- team/rmudgett/aoc_event/channels/sig_pri.c (original)
+++ team/rmudgett/aoc_event/channels/sig_pri.c Wed Mar 31 18:14:07 2010
@@ -2392,6 +2392,7 @@
 	struct ast_str *msg;
 	const char *charge_str;
 	int idx;
+	int num_items;
 	char prefix[32];
 
 	msg = ast_str_create(4096);
@@ -2422,17 +2423,35 @@
 		sig_pri_aoc_amount(&msg, charge_str, &aoc_d->recorded.money.amount);
 		break;
 	case PRI_AOC_DE_CHARGE_UNITS:
-		ast_str_append(&msg, 0, "%s/NumberItems: %d\r\n", charge_str,
-			aoc_d->recorded.unit.num_items);
+		num_items = 0;
 		for (idx = 0; idx < aoc_d->recorded.unit.num_items; ++idx) {
-			snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
-
-			/* -1 if not available. */
-			ast_str_append(&msg, 0, "%s/NumberOf: %ld\r\n", prefix,
-				aoc_d->recorded.unit.item[idx].number);
-			/* -1 if not available. */
-			ast_str_append(&msg, 0, "%s/TypeOf: %d\r\n", prefix,
-				aoc_d->recorded.unit.item[idx].type);
+			if (0 <= aoc_d->recorded.unit.item[idx].number
+				|| 0 <= aoc_d->recorded.unit.item[idx].type) {
+				/* Something is available at this index location so keep it. */
+				++num_items;
+			}
+		}
+		ast_str_append(&msg, 0, "%s/NumberItems: %d\r\n", charge_str, num_items);
+		num_items = 0;
+		for (idx = 0; idx < aoc_d->recorded.unit.num_items; ++idx) {
+			if (aoc_d->recorded.unit.item[idx].number < 0
+				&& aoc_d->recorded.unit.item[idx].type < 0) {
+				/* Nothing is available at this index location so skip it. */
+				continue;
+			}
+			snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, num_items);
+			++num_items;
+
+			if (0 <= aoc_d->recorded.unit.item[idx].number) {
+				/* Number of units recorded is available */
+				ast_str_append(&msg, 0, "%s/NumberOf: %ld\r\n", prefix,
+					aoc_d->recorded.unit.item[idx].number);
+			}
+			if (0 <= aoc_d->recorded.unit.item[idx].type) {
+				/* Type of units recorded is available */
+				ast_str_append(&msg, 0, "%s/TypeOf: %d\r\n", prefix,
+					aoc_d->recorded.unit.item[idx].type);
+			}
 		}
 		break;
 	default:
@@ -2465,6 +2484,7 @@
 	struct ast_str *msg;
 	const char *charge_str;
 	int idx;
+	int num_items;
 	char prefix[32];
 
 	msg = ast_str_create(4096);
@@ -2515,17 +2535,35 @@
 		sig_pri_aoc_amount(&msg, charge_str, &aoc_e->recorded.money.amount);
 		break;
 	case PRI_AOC_DE_CHARGE_UNITS:
-		ast_str_append(&msg, 0, "%s/NumberItems: %d\r\n", charge_str,
-			aoc_e->recorded.unit.num_items);
+		num_items = 0;
 		for (idx = 0; idx < aoc_e->recorded.unit.num_items; ++idx) {
-			snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, idx);
-
-			/* -1 if not available. */
-			ast_str_append(&msg, 0, "%s/NumberOf: %ld\r\n", prefix,
-				aoc_e->recorded.unit.item[idx].number);
-			/* -1 if not available. */
-			ast_str_append(&msg, 0, "%s/TypeOf: %d\r\n", prefix,
-				aoc_e->recorded.unit.item[idx].type);
+			if (0 <= aoc_e->recorded.unit.item[idx].number
+				|| 0 <= aoc_e->recorded.unit.item[idx].type) {
+				/* Something is available at this index location so keep it. */
+				++num_items;
+			}
+		}
+		ast_str_append(&msg, 0, "%s/NumberItems: %d\r\n", charge_str, num_items);
+		num_items = 0;
+		for (idx = 0; idx < aoc_e->recorded.unit.num_items; ++idx) {
+			if (aoc_e->recorded.unit.item[idx].number < 0
+				&& aoc_e->recorded.unit.item[idx].type < 0) {
+				/* Nothing is available at this index location so skip it. */
+				continue;
+			}
+			snprintf(prefix, sizeof(prefix), "%s/Item(%d)", charge_str, num_items);
+			++num_items;
+
+			if (0 <= aoc_e->recorded.unit.item[idx].number) {
+				/* Number of units recorded is available */
+				ast_str_append(&msg, 0, "%s/NumberOf: %ld\r\n", prefix,
+					aoc_e->recorded.unit.item[idx].number);
+			}
+			if (0 <= aoc_e->recorded.unit.item[idx].type) {
+				/* Type of units recorded is available */
+				ast_str_append(&msg, 0, "%s/TypeOf: %d\r\n", prefix,
+					aoc_e->recorded.unit.item[idx].type);
+			}
 		}
 		break;
 	default:




More information about the asterisk-commits mailing list