[asterisk-commits] mmichelson: branch group/CCSS r214516 - /team/group/CCSS/main/ccss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 27 16:41:48 CDT 2009


Author: mmichelson
Date: Thu Aug 27 16:41:45 2009
New Revision: 214516

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214516
Log:
Add validation to state change function


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

Modified: team/group/CCSS/main/ccss.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=214516&r1=214515&r2=214516
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Aug 27 16:41:45 2009
@@ -440,12 +440,16 @@
 
 struct cc_core_instance {
 	/*!
-	 * unique identifier for this instance of the CC core. There will
+	 * Unique identifier for this instance of the CC core. There will
 	 * be a corresponding core_pending_cc_offer structure with the
 	 * same core_id, up until this instance of the core creates
 	 * a monitor structure
 	 */
 	int core_id;
+	/*!
+	 * The current state for this instance of the CC core.
+	 */
+	enum ast_cc_state current_state;
 	/*!
 	 * The CC agent in use for this call
 	 */
@@ -650,7 +654,9 @@
 
 static void cc_generic_agent_ack(struct ast_cc_agent *agent)
 {
-	/* STUB */
+	/* The generic agent doesn't have to do anything special to
+	 * acknowledge a CC request. Just return.
+	 */
 	return;
 }
 
@@ -692,7 +698,6 @@
 
 static int cc_do_state_change(void *datap)
 {
-	/* STUB */
 	struct cc_state_change_args *args = datap;
 	struct cc_core_instance *core_instance;
 	struct cc_core_instance finder = { .core_id = args->core_id };
@@ -710,9 +715,14 @@
 		ast_log(LOG_WARNING, "Someone requested to change to CC_AVAILABLE? Ignoring.\n");
 		break;
 	case CC_CALLER_OFFERED:
-		/* We offered CC to the caller. This is when the agent needs
-		 * to start its offer_timer
-		 */
+		if (core_instance->state != CC_AVAILABLE) {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+			break;
+		}
+
+		if (core_instance->agent->callbacks->start_offer_timer(core_instance->agent)) {
+			ast_cc_request_state_change(CC_FAILED, core_instance->core_id, "Failed to start the offer timer\n");
+		}
 		break;
 	case CC_CALLER_REQUESTED:
 		/* Caller requested CC to the caller, so we need to initialize
@@ -725,22 +735,41 @@
 		 * 2. Caller became available, call agent's stop_monitoring callback and
 		 *    call monitor's unsuspend callback.
 		 */
+		if (core_instance->state == CC_CALLER_REQUESTED) {
+			/* Do 1 */
+		} else if (core_instance->state == CC_CALLER_BUSY) {
+			/* Do 2 */
+		} else {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+		}
 		break;
 	case CC_CALLEE_READY:
 		/* Callee has become available, call agent's status request callback
 		 */
+		if (core_instance->state != CC_ACTIVE) {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+		}
 	case CC_CALLER_BUSY:
 		/* Callee was available, but caller was busy, call agent's begin_monitoring callback
 		 * and call monitor's suspend callback.
 		 */
+		if (core_instance->state != CC_CALLEE_READY) {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+		}
 		break;
 	case CC_RECALLING:
 		/* Both caller and callee are available, call agent's recall callback
 		 */
+		if (core_instance->state != CC_CALLEE_READY) {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+		}
 		break;
 	case CC_COMPLETE:
 		/* Recall has made progress, call agent and monitor destructor functions
 		 */
+		if (core_instance->state != CC_RECALLING) {
+			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->state, args->state);
+		}
 		break;
 	case CC_FAILED:
 		/* Something along the way failed, call agent and monitor destructor functions
@@ -752,6 +781,7 @@
 	}
 
 	ast_free(args);
+	ao2_ref(core_instance, -1); /* From ao2_find */
 	return 0;
 }
 




More information about the asterisk-commits mailing list