[asterisk-commits] mmichelson: branch group/CCSS r219791 - in /team/group/CCSS: apps/ include/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Sep 21 15:05:12 CDT 2009


Author: mmichelson
Date: Mon Sep 21 15:05:09 2009
New Revision: 219791

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219791
Log:
Move down the road of having a shared struct that is used
for both interface trees and monitors. This takes care of
the interface tree side of the equation. Next commit will
address the monitors.


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

Modified: team/group/CCSS/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/apps/app_dial.c?view=diff&rev=219791&r1=219790&r2=219791
==============================================================================
--- team/group/CCSS/apps/app_dial.c (original)
+++ team/group/CCSS/apps/app_dial.c Mon Sep 21 15:05:09 2009
@@ -1670,12 +1670,12 @@
 	 * This value serves a dual-purpose. When dial starts, if the
 	 * dial_cc_interfaces datastore currently exists on the calling
 	 * channel, then the dial_parent_id will serve as a means of
-	 * letting the new extension ast_cc_interface we create know
+	 * letting the new extension ast_cc_tree_item we create know
 	 * who his parent is. This value will be the extension
-	 * ast_cc_interface that dialed the local channel that resulted
+	 * ast_cc_tree_item that dialed the local channel that resulted
 	 * in the new Dial app being called.
 	 *
-	 * In addition, once an extension ast_cc_interface is created,
+	 * In addition, once an extension ast_cc_tree_item is created,
 	 * the dial_parent_id will be changed to the id of that newly
 	 * created interface. This way, device interfaces created from
 	 * receiving AST_CONTROL_CC frames can use this field to determine
@@ -1788,18 +1788,19 @@
  *
  * When app_dial starts, this function is called in order to set up the
  * information about the extension in which this Dial is occurring. Any
- * devices dialed will have this particular ast_cc_interface as a parent.
+ * devices dialed will have this particular ast_cc_tree_item as a parent.
  *
  * \param exten Extension from which Dial is occurring
  * \param context Context to which exten belongs
  * \param parent_id What should we set the parent_id of this interface to?
  * \retval NULL Memory allocation failure
- * \retval non-NULL The newly-created ast_cc_interface for the extension
+ * \retval non-NULL The newly-created ast_cc_tree_item for the extension
  */
-static struct ast_cc_interface *cc_extension_interface_init(const char * const exten, const char * const context, const unsigned int parent_id)
+static struct ast_cc_tree_item *cc_extension_tree_item_init(const char * const exten, const char * const context, const unsigned int parent_id)
 {
 	struct ast_str *str = ast_str_alloca(2 * AST_MAX_EXTENSION);
 	struct ast_cc_interface *cc_interface;
+	struct ast_cc_tree_item *tree_item;
 
 	ast_str_set(&str, 0, "%s@%s", exten, context);
 
@@ -1807,19 +1808,25 @@
 		return NULL;
 	}
 
-	cc_interface->id = ast_atomic_fetchadd_int(&dial_cc_interface_counter, +1);
-	cc_interface->parent_id = parent_id;
+	if (!(tree_item = ast_calloc(1, sizeof(*tree_item)))) {
+		ast_free(cc_interface);
+		return NULL;
+	}
+
+	tree_item->id = ast_atomic_fetchadd_int(&dial_cc_interface_counter, +1);
+	tree_item->parent_id = parent_id;
 	cc_interface->monitor_type = "extension";
 	cc_interface->monitor_class = AST_CC_EXTENSION_MONITOR;
 	strcpy(cc_interface->name, ast_str_buffer(str));
-	ast_log(LOG_NOTICE, "Created an extension cc interface for '%s' with id %d and parent %d\n", cc_interface->name, cc_interface->id, cc_interface->parent_id);
-	return cc_interface;
+	tree_item->interface = cc_interface;
+	ast_log(LOG_NOTICE, "Created an extension cc interface for '%s' with id %d and parent %d\n", cc_interface->name, tree_item->id, tree_item->parent_id);
+	return tree_item;
 }
 
 /*!
  * \brief allocate dial_cc_interfaces datastore and initialize fields
  *
- * This function is called when Situation 1 occurs in create_root_cc_interface.
+ * This function is called when Situation 1 occurs in create_root_tree_item.
  * See that function for more information on what Situation 1 is.
  *
  * In this particular case, we have to do a lot of memory allocation in order
@@ -1833,20 +1840,20 @@
  */
 static int cc_interfaces_datastore_init(struct ast_channel *chan) {
 	struct dial_cc_interfaces *interfaces;
-	struct ast_cc_interface *cc_interface;
+	struct ast_cc_tree_item *tree_item;
 	struct ast_datastore *dial_cc_datastore;
 
 	if (!(interfaces = ast_calloc(1, sizeof(*interfaces)))) {
 		return -1;
 	}
 
-	if (!(cc_interface = cc_extension_interface_init(S_OR(chan->macroexten, chan->exten), S_OR(chan->macrocontext, chan->context), 0))) {
+	if (!(tree_item = cc_extension_tree_item_init(S_OR(chan->macroexten, chan->exten), S_OR(chan->macrocontext, chan->context), 0))) {
 		ast_free(interfaces);
 		return -1;
 	}
 
 	if (!(dial_cc_datastore = ast_datastore_alloc(&dial_cc_interfaces_info, NULL))) {
-		ast_free(cc_interface);
+		ast_cc_tree_item_destroy(tree_item);
 		ast_free(interfaces);
 		return -1;
 	}
@@ -1854,17 +1861,17 @@
 	if (!(interfaces->interface_tree = ao2_t_alloc(sizeof(*interfaces->interface_tree), ast_cc_interface_tree_destroy,
 					"Allocate interface tree"))) {
 		ast_datastore_free(dial_cc_datastore);
-		ast_free(cc_interface);
+		ast_cc_tree_item_destroy(tree_item);
 		ast_free(interfaces);
 		return -1;
 	}
 
 	/* Finally, all that allocation is done... */
 	AST_LIST_HEAD_INIT(interfaces->interface_tree);
-	AST_LIST_INSERT_TAIL(interfaces->interface_tree, cc_interface, next);
+	AST_LIST_INSERT_TAIL(interfaces->interface_tree, tree_item, next);
 	dial_cc_datastore->data = interfaces;
 	dial_cc_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
-	interfaces->dial_parent_id = cc_interface->id;
+	interfaces->dial_parent_id = tree_item->id;
 	ast_channel_lock(chan);
 	ast_channel_datastore_add(chan, dial_cc_datastore);
 	ast_channel_unlock(chan);
@@ -1872,10 +1879,10 @@
 }
 
 /*!
- * \brief Allocate and intitialize a device ast_cc_interface
+ * \brief Allocate and intitialize a device ast_cc_tree_item
  *
  * For all intents and purposes, this is the same as
- * cc_extension_interface_init, except that there is only
+ * cc_extension_tree_item_init, except that there is only
  * a single parameter used for naming the interface.
  *
  * This function is called when handling AST_CONTROL_CC frames.
@@ -1895,10 +1902,11 @@
  * \retval NULL Memory allocation failure
  * \retval non-NULL The new ast_cc_interface created.
  */
-static struct ast_cc_interface *cc_device_interface_init(const char * const name, const size_t name_len,
+static struct ast_cc_tree_item *cc_device_tree_item_init(const char * const name, const size_t name_len,
 		const int parent_id, const struct ast_control_cc_payload *cc_data)
 {
 	struct ast_cc_interface *cc_interface = ast_calloc(1, sizeof(*cc_interface) + name_len);
+	struct ast_cc_tree_item *tree_item;
 
 	if (!cc_interface) {
 		return NULL;
@@ -1909,19 +1917,25 @@
 		return NULL;
 	}
 
+	if (!(tree_item = ast_calloc(1, sizeof(*tree_item)))) {
+		ast_free(cc_interface->config_params);
+		ast_free(cc_interface);
+		return NULL;
+	}
+
 	strcpy(cc_interface->name, name);
-	cc_interface->id = ast_atomic_fetchadd_int(&dial_cc_interface_counter, +1);
-	cc_interface->parent_id = parent_id;
+	tree_item->id = ast_atomic_fetchadd_int(&dial_cc_interface_counter, +1);
+	tree_item->parent_id = parent_id;
+	tree_item->service_offered = cc_data->service;
 	/* XXX This data will need to be retrieved from the frame
 	 * data. However, to keep things simple for now, always use
 	 * "generic" monitor
 	 */
 	cc_interface->monitor_type = cc_data->monitor_type;
-	cc_interface->service_offered = cc_data->service;
 	cc_interface->monitor_class = AST_CC_DEVICE_MONITOR;
 	ast_cc_copy_config_params(cc_interface->config_params, cc_data->config_params);
-	ast_log(LOG_NOTICE, "Created a device cc interface for '%s' with id %d and parent %d\n", cc_interface->name, cc_interface->id, cc_interface->parent_id);
-	return cc_interface;
+	ast_log(LOG_NOTICE, "Created a device cc interface for '%s' with id %d and parent %d\n", cc_interface->name, tree_item->id, tree_item->parent_id);
+	return tree_item;
 }
 
 /*!
@@ -1931,8 +1945,8 @@
  * call this function when we read an AST_CONTROL_CC frame
  * from an outbound channel.
  *
- * This function will call cc_device_interface_init to
- * create the new ast_cc_interface for the device from which
+ * This function will call cc_device_tree_item_init to
+ * create the new ast_cc_tree_item for the device from which
  * we read the frame. In addition, the new device will be added
  * to the interface tree on the dial_cc_interfaces datastore
  * on the inbound channel.
@@ -1951,7 +1965,7 @@
 	char device_name[AST_CHANNEL_NAME];
 	char core_id_str[20];
 	char *dash;
-	struct ast_cc_interface *cc_interface;
+	struct ast_cc_tree_item *tree_item;
 	struct ast_datastore *cc_datastore;
 	struct dial_cc_interfaces *cc_interfaces;
 	struct ast_control_cc_payload *cc_data = frame_data;
@@ -1969,13 +1983,13 @@
 
 	cc_interfaces = cc_datastore->data;
 
-	if (!(cc_interface = cc_device_interface_init(device_name, strlen(device_name), cc_interfaces->dial_parent_id, cc_data))) {
+	if (!(tree_item = cc_device_tree_item_init(device_name, strlen(device_name), cc_interfaces->dial_parent_id, cc_data))) {
 		ast_log(LOG_WARNING, "Unable to create CC device interface for '%s'. CC services will be unavailable on this interface.\n", device_name);
 		return;
 	}
 
 	AST_LIST_LOCK(cc_interfaces->interface_tree);
-	AST_LIST_INSERT_TAIL(cc_interfaces->interface_tree, cc_interface, next);
+	AST_LIST_INSERT_TAIL(cc_interfaces->interface_tree, tree_item, next);
 	AST_LIST_UNLOCK(cc_interfaces->interface_tree);
 
 	/* If this is the first CC frame we're processing, we need to
@@ -2008,7 +2022,7 @@
  * \retval 0 Success
  * \retval -1 Failure
  */
-static int create_root_cc_interface(struct ast_channel *chan, int *ignore_cc)
+static int create_root_tree_item(struct ast_channel *chan, int *ignore_cc)
 {
 	/* There are three situations to deal with here:
 	 *
@@ -2032,7 +2046,7 @@
 
 	struct ast_datastore *cc_interfaces_datastore;
 	struct dial_cc_interfaces *interfaces;
-	struct ast_cc_interface *cc_interface;
+	struct ast_cc_tree_item *tree_item;
 	ast_channel_lock(chan);
 	if (!(cc_interfaces_datastore = ast_channel_datastore_find(chan, &dial_cc_interfaces_info, NULL))) {
 		/* Situation 1 has occurred */
@@ -2050,14 +2064,14 @@
 	}
 
 	/* Situation 2 has occurred */
-	if (!(cc_interface = cc_extension_interface_init(S_OR(chan->macroexten, chan->exten), 
+	if (!(tree_item = cc_extension_tree_item_init(S_OR(chan->macroexten, chan->exten), 
 			S_OR(chan->macrocontext, chan->context), interfaces->dial_parent_id))) {
 		return -1;
 	}
 	AST_LIST_LOCK(interfaces->interface_tree);
-	AST_LIST_INSERT_TAIL(interfaces->interface_tree, cc_interface, next);
+	AST_LIST_INSERT_TAIL(interfaces->interface_tree, tree_item, next);
 	AST_LIST_UNLOCK(interfaces->interface_tree);
-	interfaces->dial_parent_id = cc_interface->id;
+	interfaces->dial_parent_id = tree_item->id;
 	return 0;
 }
 
@@ -2156,7 +2170,7 @@
 		goto done;
 	}
 
-	if (create_root_cc_interface(chan, &ignore_cc)) {
+	if (create_root_tree_item(chan, &ignore_cc)) {
 		goto done;
 	}
 

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=219791&r1=219790&r2=219791
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Mon Sep 21 15:05:09 2009
@@ -397,8 +397,34 @@
  * order.
  */
 
+struct ast_cc_interface {
+	/* What class of monitor is being offered here
+	 */
+	enum ast_cc_monitor_class monitor_class;
+	/*!
+	 * The type of monitor that should be used for this interface
+	 *
+	 * This will be something like "extension" "generic" or "SIP"
+	 * This should point to a static const char *, so there is
+	 * no reason to make a new copy.
+	 */
+	const char *monitor_type;
+	/*!
+	 * The configuration parameters used for this interface
+	 */
+	struct ast_cc_config_params *config_params;
+	/* The name of the interface/extension. local channels will
+	 * have 'exten at context' for a name. Other channel types will
+	 * have 'tech/device' for a name.
+	 */
+	char name[1];
+};
+
 /* This may be a candidate for opacity. Who the heck knows. */
-struct ast_cc_interface {
+struct ast_cc_tree_item {
+	/* Information regarding the interface.
+	 */
+	struct ast_cc_interface *interface;
 	/* Every interface has an id associated with it. Think of
 	 * it like a "primary key"
 	 */
@@ -409,31 +435,11 @@
 	 */
 	unsigned int parent_id;
 	/* What service was offered by the endpoint. Note that
-	 * this field is completely irrelevant for ast_cc_interfaces
-	 * representing dialplan extensions.
+	 * this field is completely irrelevant for ast_cc_tree_items
+	 * representing dialplan extensions. 
 	 */
 	enum ast_cc_service_type service_offered;
-	/* What class of monitor is being offered here
-	 */
-	enum ast_cc_monitor_class monitor_class;
-	/*!
-	 * The type of monitor that should be used for this interface
-	 *
-	 * This will be something like "extension" "generic" or "SIP"
-	 * This should point to a static const char *, so there is
-	 * no reason to make a new copy.
-	 */
-	const char *monitor_type;
-	/*!
-	 * The configuration parameters used for this interface
-	 */
-	struct ast_cc_config_params *config_params;
-	AST_LIST_ENTRY(ast_cc_interface) next;
-	/* The name of the interface/extension. local channels will
-	 * have 'exten at context' for a name. Other channel types will
-	 * have 'tech/device' for a name.
-	 */
-	char name[1];
+	AST_LIST_ENTRY(ast_cc_tree_item) next;
 };
 
 /*!
@@ -443,7 +449,7 @@
  * to use it, and it may last beyond the lifetime of a single
  * thread.
  */
-AST_LIST_HEAD(ast_cc_interface_tree, ast_cc_interface);
+AST_LIST_HEAD(ast_cc_interface_tree, ast_cc_tree_item);
 
 /*!
  * \brief Destructor function for an ast_cc_interface tree
@@ -451,6 +457,13 @@
  * \param data The ast_cc_interface_tree whose refcount has reached 0
  */
 void ast_cc_interface_tree_destroy(void *cc_interface_tree);
+
+/*!
+ * \brief free the components of an ast_cc_tree_item
+ *
+ * \param tree_item The ast_cc_tree_item to destroy
+ */
+void ast_cc_tree_item_destroy(struct ast_cc_tree_item *tree_item);
 
 /* END TREE STRUCTURES AND API FOR APP_DIAL'S USE */
 

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=219791&r1=219790&r2=219791
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Mon Sep 21 15:05:09 2009
@@ -446,13 +446,20 @@
 	}
 }
 
+void ast_cc_tree_item_destroy(struct ast_cc_tree_item *tree_item)
+{
+		ast_free(tree_item->interface->config_params);
+		ast_free(tree_item->interface);
+		ast_free(tree_item);
+}
+
 void ast_cc_interface_tree_destroy(void *data)
 {
 	struct ast_cc_interface_tree *cc_interface_tree = data;
-	struct ast_cc_interface *cc_interface;
-	while ((cc_interface = AST_LIST_REMOVE_HEAD(cc_interface_tree, next))) {
-		ast_log(LOG_NOTICE, "Gonna free interface named '%s' with id %d\n", cc_interface->name, cc_interface->id);
-		ast_free(cc_interface);
+	struct ast_cc_tree_item *tree_item;
+	while ((tree_item = AST_LIST_REMOVE_HEAD(cc_interface_tree, next))) {
+		ast_log(LOG_NOTICE, "Gonna free interface named '%s' with id %d\n", tree_item->interface->name, tree_item->id);
+		ast_cc_tree_item_destroy(tree_item);
 	}
 }
 
@@ -777,8 +784,8 @@
 	char *target;
 	int reason;
 	struct ast_channel *chan;
-	struct ast_cc_interface *cc_interface = AST_LIST_FIRST(agent->interface_tree);
-	char *full_extension = ast_strdupa(cc_interface->name);
+	struct ast_cc_tree_item *tree_item = AST_LIST_FIRST(agent->interface_tree);
+	char *full_extension = ast_strdupa(tree_item->interface->name);
 	char *context;
 	char *exten;
 	const char *callback_macro = ast_get_cc_callback_macro(agent->cc_params);
@@ -893,10 +900,11 @@
 	return monitor;
 }
 
-static struct ast_cc_monitor *find_or_create_monitor(struct ast_cc_monitor *parent, struct ast_cc_interface *interface, const int core_id)
+static struct ast_cc_monitor *find_or_create_monitor(struct ast_cc_monitor *parent, struct ast_cc_tree_item *tree_item, const int core_id)
 {
 	struct ast_cc_monitor *new_monitor;
 	struct ast_cc_monitor_link *new_link;
+	struct ast_cc_interface *interface = tree_item->interface;
 	struct ast_cc_monitor *finder = alloca(sizeof(*finder) + strlen(interface->name));
 
 	strcpy(finder->name, interface->name);
@@ -922,16 +930,16 @@
 	ao2_t_ref(new_link->child, +1, "Link's child reference");
 	ao2_t_ref(new_link->parent, +1, "Link's parent reference");
 	new_link->core_id = core_id;
-	new_link->service = interface->service_offered;
+	new_link->service = tree_item->service_offered;
 	AST_LIST_INSERT_TAIL(&parent->child_links, new_link, next_child);
 	AST_LIST_INSERT_TAIL(&new_monitor->parent_links, new_link, next_parent);
 	ast_log(LOG_NOTICE, "Created link with core_id %d, parent %s and child %s\n", new_link->core_id, new_link->parent->name, new_link->child->name);
 	return new_monitor;
 }
 
-static void interface_tree_to_monitor(struct ast_cc_interface *current_place, struct ast_cc_monitor *parent, const int core_id)
-{
-	struct ast_cc_interface *cc_interface = current_place;
+static void interface_tree_to_monitor(struct ast_cc_tree_item *current_place, struct ast_cc_monitor *parent, const int core_id)
+{
+	struct ast_cc_tree_item *tree_item = current_place;
 	struct ast_cc_monitor *monitor = find_or_create_monitor(parent, current_place, core_id);
 
 	if (!monitor) {
@@ -941,14 +949,14 @@
 
 	/* Device monitors won't have children, so don't bother looking.
 	 */
-	if (current_place->monitor_class == AST_CC_DEVICE_MONITOR) {
+	if (current_place->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 		ao2_t_ref(monitor, -1, "Device monitor unref from finding or creating");
 		return;
 	}
 
-	while ((cc_interface = AST_LIST_NEXT(cc_interface, next))) {
-		if (cc_interface->parent_id == current_place->id) {
-			interface_tree_to_monitor(cc_interface, monitor, core_id);
+	while ((tree_item = AST_LIST_NEXT(tree_item, next))) {
+		if (tree_item->parent_id == tree_item->id) {
+			interface_tree_to_monitor(tree_item, monitor, core_id);
 		}
 	}
 	ao2_t_ref(monitor, -1, "Unref extension monitor from finding or creating");
@@ -1677,7 +1685,7 @@
 {
 	struct ast_datastore *recall_datastore;
 	struct ast_cc_interface_tree *interface_tree;
-	struct ast_cc_interface *interface_iter;
+	struct ast_cc_tree_item *tree_item_iter;
 	unsigned int exten_id = 0;
 	struct ast_str *var_value = ast_str_create(64);
 	int multi = 0;
@@ -1690,9 +1698,9 @@
 
 	interface_tree = recall_datastore->data;
 
-	AST_LIST_TRAVERSE(interface_tree, interface_iter, next) {
-		if (!strcmp(interface_iter->name, extension)) {
-			exten_id = interface_iter->id;
+	AST_LIST_TRAVERSE(interface_tree, tree_item_iter, next) {
+		if (!strcmp(tree_item_iter->interface->name, extension)) {
+			exten_id = tree_item_iter->id;
 			break;
 		}
 	}
@@ -1705,11 +1713,11 @@
 		return -1;
 	}
 
-	/* I kind of feel wrong re-using interface_iter here, but eh, it works
-	 */
-	while ((interface_iter = AST_LIST_NEXT(interface_iter, next))) {
-		if (interface_iter->parent_id == exten_id) {
-			ast_str_append(&var_value, 0, "%s%s", multi ? "&" : "", interface_iter->name);
+	/* I kind of feel wrong re-using tree_item_iter here, but eh, it works
+	 */
+	while ((tree_item_iter = AST_LIST_NEXT(tree_item_iter, next))) {
+		if (tree_item_iter->parent_id == exten_id) {
+			ast_str_append(&var_value, 0, "%s%s", multi ? "&" : "", tree_item_iter->interface->name);
 			multi = 1;
 		}
 	}




More information about the asterisk-commits mailing list