[asterisk-commits] rmudgett: branch group/CCSS r245190 - /team/group/CCSS/main/ccss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Feb 5 21:33:51 CST 2010


Author: rmudgett
Date: Fri Feb  5 21:33:46 2010
New Revision: 245190

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=245190
Log:
Eliminate unexpected side effect in is_state_change_valid().

The purpose of is_state_change_valid() should be to test if it is valid to
change CCSS states.  It should not change the CCSS state as a side effect.

Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=245190&r1=245189&r2=245190
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Fri Feb  5 21:33:46 2010
@@ -2302,7 +2302,7 @@
 	char debug[1];
 };
 
-static int is_state_change_valid(enum cc_state *current_state, const enum cc_state new_state, struct ast_cc_agent *agent)
+static int is_state_change_valid(enum cc_state current_state, const enum cc_state new_state, struct ast_cc_agent *agent)
 {
 	int is_valid = 0;
 	switch (new_state) {
@@ -2310,38 +2310,38 @@
 		ast_log_dynamic_level(cc_logger_level, "Asked to change to state %d? That should never happen.\n", new_state);
 		break;
 	case CC_CALLER_OFFERED:
-		if (*current_state == CC_AVAILABLE) {
+		if (current_state == CC_AVAILABLE) {
 			is_valid = 1;
 		}
 		break;
 	case CC_CALLER_REQUESTED:
-		if (*current_state == CC_CALLER_OFFERED ||
-				(*current_state == CC_AVAILABLE && ast_test_flag(agent, AST_CC_AGENT_SKIP_OFFER))) {
+		if (current_state == CC_CALLER_OFFERED ||
+				(current_state == CC_AVAILABLE && ast_test_flag(agent, AST_CC_AGENT_SKIP_OFFER))) {
 			is_valid = 1;
 		}
 		break;
 	case CC_ACTIVE:
-		if (*current_state == CC_CALLER_REQUESTED || *current_state == CC_CALLER_BUSY) {
+		if (current_state == CC_CALLER_REQUESTED || current_state == CC_CALLER_BUSY) {
 			is_valid = 1;
 		}
 		break;
 	case CC_CALLEE_READY:
-		if (*current_state == CC_ACTIVE) {
+		if (current_state == CC_ACTIVE) {
 			is_valid = 1;
 		}
 		break;
 	case CC_CALLER_BUSY:
-		if (*current_state == CC_CALLEE_READY) {
+		if (current_state == CC_CALLEE_READY) {
 			is_valid = 1;
 		}
 		break;
 	case CC_RECALLING:
-		if (*current_state == CC_CALLEE_READY) {
+		if (current_state == CC_CALLEE_READY) {
 			is_valid = 1;
 		}
 		break;
 	case CC_COMPLETE:
-		if (*current_state == CC_RECALLING) {
+		if (current_state == CC_RECALLING) {
 			is_valid = 1;
 		}
 		break;
@@ -2350,10 +2350,7 @@
 		break;
 	default:
 		ast_log_dynamic_level(cc_logger_level, "Asked to change to unknown state %d\n", new_state);
-	}
-
-	if (is_valid) {
-		*current_state = new_state;
+		break;
 	}
 
 	return is_valid;
@@ -2613,8 +2610,7 @@
 		return -1;
 	}
 
-	previous_state = core_instance->current_state;
-	if (!is_state_change_valid(&core_instance->current_state, args->state, core_instance->agent)) {
+	if (!is_state_change_valid(core_instance->current_state, args->state, core_instance->agent)) {
 		ast_log_dynamic_level(cc_logger_level, "Invalid state change requested. Cannot go from %s to %s\n",
 				cc_state_to_string(core_instance->current_state), cc_state_to_string(args->state));
 		ast_free(args);
@@ -2622,6 +2618,9 @@
 		return -1;
 	}
 
+	/* We can change to the new state now. */
+	previous_state = core_instance->current_state;
+	core_instance->current_state = args->state;
 	res = state_change_funcs[core_instance->current_state](core_instance, args, previous_state);
 
 	ast_free(args);




More information about the asterisk-commits mailing list