[asterisk-commits] dvossel: branch dvossel/generic_aoc r255114 - /team/dvossel/generic_aoc/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 26 17:53:57 CDT 2010


Author: dvossel
Date: Fri Mar 26 17:53:53 2010
New Revision: 255114

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=255114
Log:
AOC request manager events, aoc debug now uses same code as the manager events

Modified:
    team/dvossel/generic_aoc/main/aoc.c

Modified: team/dvossel/generic_aoc/main/aoc.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/generic_aoc/main/aoc.c?view=diff&rev=255114&r1=255113&r2=255114
==============================================================================
--- team/dvossel/generic_aoc/main/aoc.c (original)
+++ team/dvossel/generic_aoc/main/aoc.c Fri Mar 26 17:53:53 2010
@@ -974,109 +974,50 @@
 	return "NotAvailable";
 }
 
-static const char *aoc_msg_type_str(const struct ast_aoc_decoded *decoded)
-{
-	switch (decoded->msg_type) {
-	case AST_AOC_S:
-		return "AOC-S";
-	case AST_AOC_D:
-		return "AOC-D";
-	case AST_AOC_E:
-		return "AOC-E";
-	case AST_AOC_REQUEST:
-		return "AOC-REQUEST";
-	}
-
-	return "Unknown";
-}
-static void aoc_display_decoded_aocd(const struct ast_aoc_decoded *decoded)
-{
-	ast_verb(1, "MsgType:    %s\n", aoc_msg_type_str(decoded));
-	ast_verb(1, "ChargeType: %s\n", aoc_charge_type_str(decoded->charge_type));
-	if (decoded->billing_id) {
-		ast_verb(1, "BillingId:  %s\n", aoc_billingid_str(decoded->billing_id));
-	}
-	ast_verb(1, "TotalType:  %s\n", decoded->total_type ? "Total" : "Subtotal");
-	if (decoded->charge_type == AST_AOC_CHARGE_CURRENCY) {
-		ast_verb(1, "Multiplier:     %s\n", aoc_multiplier_str(decoded->multiplier));
-		ast_verb(1, "CurrencyAmount: %u\n", decoded->currency_amount);
-		ast_verb(1, "CurrencyName:   %s\n", ast_strlen_zero(decoded->currency_name) ? "Not Available" : decoded->currency_name);
-	} else if (decoded->charge_type == AST_AOC_CHARGE_UNIT) {
-		int i;
-		ast_verb(1, "UnitCount:     %u\n", decoded->unit_count);
-		for (i = 0; i < decoded->unit_count; i++) {
-			ast_verb(1, "UnitAmount(%d): %u\n", i, decoded->unit_list[i].amount);
-			ast_verb(1, "UnitType(%d):   %u\n", i, decoded->unit_list[i].type);
-		}
-	}
-}
-
-static void aoc_display_decoded_aoce(const struct ast_aoc_decoded *decoded)
-{
-	ast_verb(1, "MsgType:    %s\n", aoc_msg_type_str(decoded));
-	ast_verb(1, "ChargeType: %s\n", aoc_charge_type_str(decoded->charge_type));
-	if (decoded->billing_id) {
-		ast_verb(1, "BillingId:  %s\n", aoc_billingid_str(decoded->billing_id));
-	}
-	if (decoded->charge_type == AST_AOC_CHARGE_CURRENCY) {
-		ast_verb(1, "Multiplier:     %s\n", aoc_multiplier_str(decoded->multiplier));
-		ast_verb(1, "CurrencyAmount: %u\n", decoded->currency_amount);
-		ast_verb(1, "CurrencyName:   %s\n", ast_strlen_zero(decoded->currency_name) ? "Not Available" : decoded->currency_name);
-	} else if (decoded->charge_type == AST_AOC_CHARGE_UNIT) {
-		int i;
-		ast_verb(1, "UnitCount:     %u\n", decoded->unit_count);
-		for (i = 0; i < decoded->unit_count; i++) {
-			ast_verb(1, "UnitAmount(%d): %u\n", i, decoded->unit_list[i].amount);
-			ast_verb(1, "UnitType(%d):   %u\n", i, decoded->unit_list[i].type);
-		}
-	}
-
-	if (!ast_strlen_zero(decoded->charging_association_number)) {
-		ast_verb(1,"ChargingAssociationNumber: %s\n", decoded->charging_association_number);
-		ast_verb(1,"ChargingAssociationPlan:   %d\n", decoded->charging_association_plan);
-	} else if (decoded->charging_association_id) {
-		ast_verb(1,"ChargingAssociationId: %d\n", decoded->charging_association_id);
-	}
-}
-static void aoc_display_decoded_aoc_request(const struct ast_aoc_decoded *decoded)
-{
-	ast_verb(1, "MsgType:    %s\n", aoc_msg_type_str(decoded));
-	if (decoded->request_flag & AST_AOC_REQUEST_S) {
-		ast_verb(1, "Requesting AOC-S\n");
-	}
-	if (decoded->request_flag & AST_AOC_REQUEST_D) {
-		ast_verb(1, "Requesting AOC-D\n");
-	}
-	if (decoded->request_flag & AST_AOC_REQUEST_E) {
-		ast_verb(1, "Requesting AOC-E\n");
-	}
-}
-static void aoc_display_decoded(const struct ast_aoc_decoded *decoded, int decoding)
-{
-	if (decoding) {
-		ast_verb(1, "---- DECODED AOC MSG ----\n");
+static void aoc_request_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan, int manager, int debug)
+{
+	struct ast_str *msg;
+
+	if (!decoded) {
+		return;
+	}
+
+	msg = ast_str_create(1024);
+	if (!msg) {
+		return;
+	}
+
+	if (chan) {
+		ast_str_append(&msg, 0, "Channel: %s\r\n", chan->name);
+		ast_str_append(&msg, 0, "UniqueID: %s\r\n", chan->uniqueid);
+	}
+
+	if (decoded->request_flag) {
+		ast_str_append(&msg, 0, "AOCRequest:");
+		if (decoded->request_flag & AST_AOC_REQUEST_S) {
+			ast_str_append(&msg, 0, "S");
+		}
+		if (decoded->request_flag & AST_AOC_REQUEST_D) {
+			ast_str_append(&msg, 0, "D");
+		}
+		if (decoded->request_flag & AST_AOC_REQUEST_E) {
+			ast_str_append(&msg, 0, "E");
+		}
+		ast_str_append(&msg, 0, "AOCRequest: \r\n");
+
 	} else {
-		ast_verb(1, "---- ENCODED AOC MSG ----\n");
-	}
-
-	switch (decoded->msg_type) {
-	case AST_AOC_S:
-		/* TODO implement this */
-		break;
-	case AST_AOC_D:
-		aoc_display_decoded_aocd(decoded);
-		break;
-	case AST_AOC_E:
-		aoc_display_decoded_aoce(decoded);
-		break;
-	case AST_AOC_REQUEST:
-		aoc_display_decoded_aoc_request(decoded);
-		break;
-	}
-
-	ast_verb(1, "\n");
-
-}
+		ast_str_append(&msg, 0, "AOCRequest: NONE");
+	}
+
+	if (debug) {
+		ast_verb(1,"%s", ast_str_buffer(msg));
+	}
+	if (manager && chan) {
+		ast_manager_event(chan, EVENT_FLAG_AOC, "AOC-Request", "%s", ast_str_buffer(msg));
+	}
+	ast_free(msg);
+}
+
 int ast_aoc_test_encode_decode_match(struct ast_aoc_decoded *decoded)
 {
 	struct ast_aoc_decoded *new = NULL;
@@ -1170,25 +1111,22 @@
 		aoc_multiplier_str(mult));
 }
 
-static void aoc_s_event(const struct ast_aoc_decoded *decoded, struct ast_channel *owner)
+static void aoc_s_event(const struct ast_aoc_decoded *decoded, struct ast_channel *owner, int manager, int debug)
 {
 	struct ast_str *msg;
 	const char *rate_str;
 	char prefix[32];
 	int idx;
 
-
-	if (!owner || !decoded || (decoded->msg_type != AST_AOC_S)) {
-		return;
-	}
-
 	msg = ast_str_create(1024);
 	if (!msg) {
 		return;
 	}
 
-	ast_str_append(&msg, 0, "Channel: %s\r\n", owner->name);
-	ast_str_append(&msg, 0, "UniqueID: %s\r\n", owner->uniqueid);
+	if (owner) {
+		ast_str_append(&msg, 0, "Channel: %s\r\n", owner->name);
+		ast_str_append(&msg, 0, "UniqueID: %s\r\n", owner->uniqueid);
+	}
 
 	ast_str_append(&msg, 0, "NumberRates: %d\r\n", decoded->aoc_s_count);
 	for (idx = 0; idx < decoded->aoc_s_count; ++idx) {
@@ -1251,28 +1189,32 @@
 		}
 	}
 
-	ast_manager_event(owner, EVENT_FLAG_AOC, "AOC-S", "%s", ast_str_buffer(msg));
+	if (debug) {
+		ast_verb(1,"%s", ast_str_buffer(msg));
+	}
+	if (manager && owner) {
+		ast_manager_event(owner, EVENT_FLAG_AOC, "AOC-S", "%s", ast_str_buffer(msg));
+	}
 	ast_free(msg);
 }
 
-static void aoc_d_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan)
+static void aoc_d_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan, int manager, int debug)
 {
 	struct ast_str *msg;
 	const char *charge_str;
 	int idx;
 	char prefix[32];
 
-	if (!chan) {
-		return;
-	}
-
 	msg = ast_str_create(1024);
+
 	if (!msg) {
 		return;
 	}
 
-	ast_str_append(&msg, 0, "Channel: %s\r\n", chan->name);
-	ast_str_append(&msg, 0, "UniqueID: %s\r\n", chan->uniqueid);
+	if (chan) {
+		ast_str_append(&msg, 0, "Channel: %s\r\n", chan->name);
+		ast_str_append(&msg, 0, "UniqueID: %s\r\n", chan->uniqueid);
+	}
 
 	charge_str = aoc_charge_type_str(decoded->charge_type);
 	ast_str_append(&msg, 0, "Type: %s\r\n", charge_str);
@@ -1308,11 +1250,17 @@
 		break;
 	}
 
-	ast_manager_event(chan, EVENT_FLAG_AOC, "AOC-D", "%s", ast_str_buffer(msg));
+	if (debug) {
+		ast_verb(1,"%s", ast_str_buffer(msg));
+	}
+
+	if (manager && chan) {
+		ast_manager_event(chan, EVENT_FLAG_AOC, "AOC-D", "%s", ast_str_buffer(msg));
+	}
 	ast_free(msg);
 }
 
-static void aoc_e_event(const struct ast_aoc_decoded *decoded, struct ast_channel *owner)
+static void aoc_e_event(const struct ast_aoc_decoded *decoded, struct ast_channel *chan, int manager, int debug)
 {
 	struct ast_channel *chans[1];
 	struct ast_str *msg;
@@ -1329,9 +1277,9 @@
 		return;
 	}
 
-	if (owner) {
-		ast_str_append(&msg, 0, "Channel: %s\r\n", owner->name);
-		ast_str_append(&msg, 0, "UniqueID: %s\r\n", owner->uniqueid);
+	if (chan) {
+		ast_str_append(&msg, 0, "Channel: %s\r\n", chan->name);
+		ast_str_append(&msg, 0, "UniqueID: %s\r\n", chan->uniqueid);
 	}
 
 	charge_str = "ChargingAssociation";
@@ -1379,9 +1327,15 @@
 		break;
 	}
 
-	chans[0] = owner;
-	ast_manager_event_multichan(EVENT_FLAG_AOC, "AOC-E", owner ? 1 : 0, chans, "%s",
-		ast_str_buffer(msg));
+	if (debug) {
+		ast_verb(1,"%s", ast_str_buffer(msg));
+	}
+
+	if (manager) {
+		chans[0] = chan;
+		ast_manager_event_multichan(EVENT_FLAG_AOC, "AOC-E", chan ? 1 : 0, chans, "%s",
+			ast_str_buffer(msg));
+	}
 	ast_free(msg);
 }
 
@@ -1393,20 +1347,49 @@
 
 	switch (decoded->msg_type) {
 	case AST_AOC_S:
-		aoc_s_event(decoded, chan);
+		aoc_s_event(decoded, chan, 1, 0);
 		break;
 	case AST_AOC_D:
-		aoc_d_event(decoded, chan);
+		aoc_d_event(decoded, chan, 1, 0);
 		break;
 	case AST_AOC_E:
-		aoc_e_event(decoded, chan);
+		aoc_e_event(decoded, chan, 1, 0);
 		break;
 	case AST_AOC_REQUEST:
-		/* TODO add logic here */
+		aoc_request_event(decoded, chan, 1, 0);
 		break;
 	}
 
 	return 0;
+}
+
+static void aoc_display_decoded(const struct ast_aoc_decoded *decoded, int decoding)
+{
+	if (decoding) {
+		ast_verb(1, "---- DECODED AOC MSG ----\r\n");
+	} else {
+		ast_verb(1, "---- ENCODED AOC MSG ----\r\n");
+	}
+
+	switch (decoded->msg_type) {
+	case AST_AOC_S:
+		ast_verb(1, "AOC-S\r\n");
+		aoc_s_event(decoded, NULL, 0, 1);
+		break;
+	case AST_AOC_D:
+		ast_verb(1, "AOC-D\r\n");
+		aoc_d_event(decoded, NULL, 0, 1);
+		break;
+	case AST_AOC_E:
+		ast_verb(1, "AOC-E\r\n");
+		aoc_e_event(decoded, NULL, 0, 1);
+		break;
+	case AST_AOC_REQUEST:
+		ast_verb(1, "AOC-Request\r\n");
+		aoc_request_event(decoded, NULL, 1, 0);
+		break;
+	}
+	ast_verb(1, "\r\n");
 }
 
 static struct ast_cli_entry aoc_cli[] = {




More information about the asterisk-commits mailing list