[svn-commits] mmichelson: branch group/CCSS r221758 - in /team/group/CCSS: include/asterisk...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Oct 1 16:42:25 CDT 2009


Author: mmichelson
Date: Thu Oct  1 16:42:22 2009
New Revision: 221758

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=221758
Log:
Change when core_id is allocated and write API call to retrieve it.

So, let's say that you operate a channel driver, and you decide
that you can queue an AST_CONTROL_CC frame because the outbound
channel can handle CC requests. Well, when the time comes to
start monitoring that device, all you'll be given to identify
the call is a core_id. So, now at the time that you queue
the CC frame, the channel driver may use the API call to store
the core_id which will be used when monitoring time comes.


Modified:
    team/group/CCSS/include/asterisk/ccss.h
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=221758&r1=221757&r2=221758
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Thu Oct  1 16:42:22 2009
@@ -982,6 +982,26 @@
 
 /*!
  * \since 1.6.4
+ * \brief Get the core id for the current call
+ *
+ * The main use of this function is for channel drivers
+ * who queue an AST_CONTROL_CC frame. A channel driver may
+ * call this function in order to get the core_id for what
+ * may become a CC request. This way, when monitor functions
+ * are called which use a core_id as a means of identification,
+ * the channel driver will have saved this information.
+ *
+ * The channel given to this function may be an inbound or outbound
+ * channel. Both will have the necessary info on it.
+ *
+ * \param chan The channel from which to get the core_id.
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_cc_get_current_core_id(struct ast_channel *chan);
+
+/*!
+ * \since 1.6.4
  * \brief Set the CC_INTERFACES channel variable for a channel
  *
  * Implementors of protocol-specific CC agents should call this function after

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=221758&r1=221757&r2=221758
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Oct  1 16:42:22 2009
@@ -509,6 +509,15 @@
 	 */
 	unsigned int dial_parent_id;
 	/*!
+	 * Identifier for the potential CC request that may be made
+	 * based on this call. Even though an instance of the core may
+	 * not be made (since the caller may not request CC), we allocate
+	 * a new core_id at the beginning of the call so that recipient
+	 * channel drivers can have the information handy just in case
+	 * the caller does end up requesting CC.
+	 */
+	int core_id;
+	/*!
 	 * When a new Dial application is started, and the datastore
 	 * already exists on the channel, we can determine if we
 	 * should be adding any new interface information to tree.
@@ -672,6 +681,8 @@
 	return tree_item;
 }
 
+static int core_id_counter;
+
 /*!
  * \brief allocate dialed_cc_interfaces datastore and initialize fields
  *
@@ -721,6 +732,7 @@
 	dial_cc_datastore->data = interfaces;
 	dial_cc_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
 	interfaces->dial_parent_id = tree_item->id;
+	interfaces->core_id = ast_atomic_fetchadd_int(&core_id_counter, +1);
 	ast_channel_lock(chan);
 	ast_channel_datastore_add(chan, dial_cc_datastore);
 	ast_channel_unlock(chan);
@@ -959,7 +971,6 @@
 	interfaces->dial_parent_id = tree_item->id;
 	return 0;
 }
-static int core_id_counter;
 
 struct ao2_container *cc_core_instances;
 struct ao2_container *cc_monitors;
@@ -1161,6 +1172,7 @@
 	char *caller = ast_strdupa(caller_chan->name);
 	char *dash = strrchr(caller, '-');
 	struct cc_core_instance *core_instance;
+	int core_id;
 
 	if (dash) {
 		*dash = '\0';
@@ -1180,12 +1192,16 @@
 		}
 	}
 
+	if ((core_id = ast_cc_get_current_core_id(caller_chan)) == -1) {
+		return -1;
+	}
+	
 	/* Next, we need to create the core instance for this call */
 	if (!(core_instance = ao2_t_alloc(sizeof(*core_instance), cc_core_instance_destructor, "Creating core instance for CC"))) {
 		return -1;
 	}
 
-	core_instance->core_id = ast_atomic_fetchadd_int(&core_id_counter, +1);
+	core_instance->core_id = core_id;
 	if (!(core_instance->agent = cc_agent_init(caller_chan, caller, core_instance->core_id, called_tree))) {
 		cc_unref(core_instance, "Couldn't allocate agent, unref core_instance");
 		return -1;
@@ -2393,6 +2409,25 @@
 	return core_id_return;
 }
 
+int ast_cc_get_current_core_id(struct ast_channel *chan)
+{
+	struct ast_datastore *datastore;
+	struct dialed_cc_interfaces *cc_interfaces;
+	int core_id_return;
+
+	ast_channel_lock(chan);
+	if (!(datastore = ast_channel_datastore_find(chan, &dialed_cc_interfaces_info, NULL))) {
+		ast_channel_unlock(chan);
+		return -1;
+	}
+
+	cc_interfaces = datastore->data;
+	core_id_return = cc_interfaces->core_id;
+	ast_channel_unlock(chan);
+	return core_id_return;
+
+}
+
 int ast_set_cc_interfaces_chanvar(struct ast_channel *chan, const char * const extension)
 {
 	struct ast_datastore *recall_datastore;




More information about the svn-commits mailing list