[asterisk-commits] mmichelson: branch group/CCSS_Monitor_Restructure r242034 - /team/group/CCSS_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 21 13:25:09 CST 2010


Author: mmichelson
Date: Thu Jan 21 13:25:05 2010
New Revision: 242034

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=242034
Log:
A bit more private data handling. Most specifically helping the exception that is the generic monitor.


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

Modified: team/group/CCSS_Monitor_Restructure/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS_Monitor_Restructure/main/ccss.c?view=diff&rev=242034&r1=242033&r2=242034
==============================================================================
--- team/group/CCSS_Monitor_Restructure/main/ccss.c (original)
+++ team/group/CCSS_Monitor_Restructure/main/ccss.c Thu Jan 21 13:25:05 2010
@@ -117,6 +117,44 @@
 	 */
 	CC_FAILED,
 };
+
+/*!
+ * \since 1.8
+ * \internal
+ * \brief A structure for holding the configuration parameters
+ * relating to CCSS
+ */
+struct ast_cc_config_params {
+	enum ast_cc_agent_policies cc_agent_policy;
+	enum ast_cc_monitor_policies cc_monitor_policy;
+	unsigned int cc_offer_timer;
+	unsigned int ccnr_available_timer;
+	unsigned int ccbs_available_timer;
+	unsigned int cc_max_agents;
+	unsigned int cc_max_monitors;
+	char cc_callback_macro[AST_MAX_EXTENSION];
+};
+
+struct ast_control_cc_payload {
+	/*!
+	 * \note This really should be an array of characters in case this payload
+	 * is sent accross an IAX2 link.  However, this would not make too much sense
+	 * given this type may not be recognized by the other end.
+	 * Protection may be necessary to prevent it from being transmitted.
+	 *
+	 * In addition the following other problems are also possible:
+	 * 1) Endian issues with the integers/enums stored in the config_params.
+	 * 2) Alignment padding issues for the element types.
+	 */
+	const char *monitor_type;
+	enum ast_cc_service_type service;
+	struct ast_cc_config_params config_params;
+	int parent_interface_id;
+	void *private_data;
+	char device_name[AST_CHANNEL_NAME];
+	char dialable_name[AST_CHANNEL_NAME];
+};
+
 /*!
  * \internal
  * \brief Request that the core change states
@@ -148,7 +186,7 @@
  * \retval non-NULL A reference to the newly created cc_core_instance
  */
 static struct cc_core_instance *cc_core_init_instance(struct ast_channel *caller_chan,
-		struct ast_cc_interface_tree *called_tree, const int core_id);
+		struct ast_cc_interface_tree *called_tree, const int core_id, struct ast_control_cc_payload *cc_data);
 
 /*
  * \internal
@@ -367,23 +405,6 @@
 	return ast_str_hash_add(monitor->interface->monitor_type, ast_str_hash(monitor->interface->name));
 }
 
-/*!
- * \since 1.8
- * \internal
- * \brief A structure for holding the configuration parameters
- * relating to CCSS
- */
-struct ast_cc_config_params {
-	enum ast_cc_agent_policies cc_agent_policy;
-	enum ast_cc_monitor_policies cc_monitor_policy;
-	unsigned int cc_offer_timer;
-	unsigned int ccnr_available_timer;
-	unsigned int ccbs_available_timer;
-	unsigned int cc_max_agents;
-	unsigned int cc_max_monitors;
-	char cc_callback_macro[AST_MAX_EXTENSION];
-};
-
 static const unsigned int CC_OFFER_TIMER_DEFAULT = 20u;
 static const unsigned int CCNR_AVAILABLE_TIMER_DEFAULT = 7200u;
 static const unsigned int CCBS_AVAILABLE_TIMER_DEFAULT = 4800u;
@@ -1147,8 +1168,23 @@
 {
 	struct generic_monitor_instance_list *generic_list;
 	struct generic_monitor_instance *generic_instance;
+	struct generic_monitor_pvt *gen_mon_pvt;
 	enum ast_cc_service_type service = monitor->service_offered;
 	int when;
+
+	/* First things first. Native channel drivers will have their private data allocated
+	 * at the time that they tell the core that they can offer CC. Generic is quite a bit
+	 * different, and we wait until this point to allocate our private data.
+	 */
+	if (!(gen_mon_pvt = ast_calloc(1, sizeof(*gen_mon_pvt)))) {
+		return -1;
+	}
+
+	if (!(gen_mon_pvt->device_name = ast_strdup(monitor->interface->name))) {
+		return -1;
+	}
+
+	gen_mon_pvt->core_id = monitor->core_id;
 
 	if (!(generic_list = find_generic_monitor_instance_list(monitor->interface->name))) {
 		if (!(generic_list = create_new_generic_list(monitor))) {
@@ -1240,14 +1276,24 @@
 static void cc_generic_monitor_destructor2(void *private_data)
 {
 	struct generic_monitor_pvt *gen_mon_pvt = private_data;
-	struct generic_monitor_instance_list *generic_list = find_generic_monitor_instance_list(gen_mon_pvt->device_name);
+	struct generic_monitor_instance_list *generic_list;
 	struct generic_monitor_instance *generic_instance;
 
-	if (!generic_list) {
-		/* This will likely be the case if this gets called before we've had an adequate
-		 * opportunity to actually create the generic monitor. As such, there has been
-		 * no generic list created yet.
+	if (!private_data) {
+		/* If the private data is NULL, that means that the monitor hasn't even
+		 * been created yet, but that the destructor was called. While this sort
+		 * of behavior is useful for native monitors, with a generic one, there is
+		 * nothing in particular to do.
 		 */
+		return;
+	}
+
+	if (!(generic_list = find_generic_monitor_instance_list(gen_mon_pvt->device_name))) {
+		/* If there's no generic list, that means that the monitor is being destroyed
+		 * before we actually got to request CC. Not a biggie. Same in the situation
+		 * below if the list traversal should complete without finding an entry.
+		 */
+		ast_free((char *)gen_mon_pvt->device_name);
 		return;
 	}
 
@@ -1260,6 +1306,7 @@
 	}
 	AST_LIST_TRAVERSE_SAFE_END;
 	cc_unref(generic_list, "Done with generic list in generic monitor destructor");
+	ast_free((char *)gen_mon_pvt->device_name);
 }
 
 /*!
@@ -1561,26 +1608,6 @@
 	ast_channel_unlock(chan);
 	return 0;
 }
-
-struct ast_control_cc_payload {
-	/*!
-	 * \note This really should be an array of characters in case this payload
-	 * is sent accross an IAX2 link.  However, this would not make too much sense
-	 * given this type may not be recognized by the other end.
-	 * Protection may be necessary to prevent it from being transmitted.
-	 *
-	 * In addition the following other problems are also possible:
-	 * 1) Endian issues with the integers/enums stored in the config_params.
-	 * 2) Alignment padding issues for the element types.
-	 */
-	const char *monitor_type;
-	enum ast_cc_service_type service;
-	struct ast_cc_config_params config_params;
-	int parent_interface_id;
-	void *private_data;
-	char device_name[AST_CHANNEL_NAME];
-	char dialable_name[AST_CHANNEL_NAME];
-};
 
 /*!
  * \internal




More information about the asterisk-commits mailing list