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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 27 17:58:39 CDT 2009


Author: mmichelson
Date: Thu Aug 27 17:58:35 2009
New Revision: 214590

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214590
Log:
Add start_monitoring and stop_monitoring callbacks
for generic agent.


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=214590&r1=214589&r2=214590
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Aug 27 17:58:35 2009
@@ -28,6 +28,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/utils.h"
 #include "asterisk/taskprocessor.h"
+#include "asterisk/event.h"
 
 /*!
  * \since 1.6.4
@@ -73,6 +74,20 @@
 	.stop_monitoring = cc_generic_agent_stop_monitoring,
 	.recall = cc_generic_agent_recall,
 	.destructor = cc_generic_agent_destructor,
+};
+
+struct cc_generic_agent_pvt {
+	/*!
+	 * Subscription to device state
+	 *
+	 * Used in the CC_CALLER_BUSY state. The
+	 * generic agent will subscribe to the
+	 * device state of the caller in order to
+	 * determine when we may move on
+	 */
+	struct ast_event_sub *sub;
+	/* XXX Potentially more to come...
+	 */
 };
 
 struct ast_taskprocessor *cc_core_taskprocessor;
@@ -625,11 +640,13 @@
 
 static int cc_generic_agent_init(struct ast_cc_agent *agent, struct ast_channel *chan)
 {
-	/* I'm kind of playing this by ear right now. I'm not thinking
-	 * of anything that a generic agent really needs to remember, so
-	 * for now I'm setting the private data on the agent to NULL but
-	 * returning a successful condition.
-	 */
+	struct cc_generic_agent_pvt *generic_pvt = ast_calloc(1, sizeof(*generic_pvt));
+
+	if (!generic_pvt) {
+		return -1;
+	}
+
+	agent->private_data = generic_pvt;
 	return 0;
 }
 
@@ -661,32 +678,62 @@
 
 static enum ast_device_state cc_generic_agent_status_request(struct ast_cc_agent *agent)
 {
+	return ast_device_state(agent->interface);
+}
+
+static void generic_devstate_cb(const struct ast_event *event, void *userdata)
+{
+	struct ast_cc_agent *agent = userdata;
+	struct ast_str *str = ast_str_alloca(128);
+	ast_str_set(&str, 0, "%s is no longer busy\n", agent->interface);
+	ast_cc_request_state_change(CC_ACTIVE, agent->core_id, ast_str_buffer(str));
+}
+
+static int cc_generic_agent_start_monitoring(struct ast_cc_agent *agent)
+{
+	struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
+	struct ast_str *str = ast_str_alloca(128);
+
+	ast_assert(generic_pvt->sub == NULL);
+	ast_str_set(&str, 0, "Starting to monitor %s device state since it is busy\n", agent->interface);
+
+	if (!(generic_pvt->sub = ast_event_subscribe(
+			AST_EVENT_DEVICE_STATE, generic_devstate_cb, ast_str_buffer(str), agent, 
+			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, agent->interface,
+			AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, AST_DEVICE_NOT_INUSE))) {
+		return -1;
+	}
+	return 0;
+}
+
+static int cc_generic_agent_stop_monitoring(struct ast_cc_agent *agent)
+{
+	struct cc_generic_agent_pvt *generic_pvt = agent->private_data;
+	
+	ast_assert(generic_pvt->sub != NULL);
+
+	generic_pvt->sub = ast_event_unsubscribe(generic_pvt->sub);
+	return 0;
+}
+
+static int cc_generic_agent_recall(struct ast_cc_agent *agent)
+{
 	/* STUB */
 	return 0;
 }
 
-static int cc_generic_agent_start_monitoring(struct ast_cc_agent *agent)
-{
-	/* STUB */
-	return 0;
-}
-
-static int cc_generic_agent_stop_monitoring(struct ast_cc_agent *agent)
-{
-	/* STUB */
-	return 0;
-}
-
-static int cc_generic_agent_recall(struct ast_cc_agent *agent)
-{
-	/* STUB */
-	return 0;
-}
-
 static void cc_generic_agent_destructor(struct ast_cc_agent *agent)
 {
-	/* STUB */
-	return;
+	struct cc_generic_agent_pvt *agent_pvt = agent->private_data;
+	if (!agent_pvt) {
+		return;
+	}
+	
+	if (agent_pvt->sub) {
+		agent_pvt->sub = ast_event_unsubscribe(agent_pvt->sub);
+	}
+
+	ast_free(agent_pvt);
 }
 
 struct cc_state_change_args {




More information about the asterisk-commits mailing list