[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step1 r299246 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Dec 20 21:34:00 UTC 2010


Author: dvossel
Date: Mon Dec 20 15:33:56 2010
New Revision: 299246

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=299246
Log:
This commit addresses reviewboard comments

Modified:
    team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h
    team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h
    team/dvossel/fixtheworld_phase1_step1/main/asterisk.c
    team/dvossel/fixtheworld_phase1_step1/main/format.c
    team/dvossel/fixtheworld_phase1_step1/main/format_cap.c

Modified: team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h?view=diff&rev=299246&r1=299245&r2=299246
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h Mon Dec 20 15:33:56 2010
@@ -233,7 +233,8 @@
  */
 struct ast_format *ast_format_from_iax2(uint64_t src, struct ast_format *dst);
 
-/*! \brief register ast_format_attr_interface with core.
+/*!
+ * \brief register ast_format_attr_interface with core.
  *
  * \retval 0 success
  * \retval -1 failure
@@ -248,4 +249,9 @@
  */
 int ast_format_attr_unreg_interface(struct ast_format_attr_interface *interface);
 
+/*!
+ * \brief Init the ast_format attribute interface register container.
+ */
+int ast_format_attr_init(void);
+
 #endif /* _AST_FORMATNEW_H */

Modified: team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h?view=diff&rev=299246&r1=299245&r2=299246
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h Mon Dec 20 15:33:56 2010
@@ -29,20 +29,23 @@
 /*! Capabilities are represented by an opaque structure statically defined in format_capability.c */
 struct ast_cap;
 
-/*! \brief Allocate a new ast_cap structure.
+/*!
+ * \brief Allocate a new ast_cap structure.
  *
  * \retval ast_cap object on success.
  * \retval NULL on failure.
  */
 struct ast_cap *ast_cap_alloc(void);
 
-/*! \brief Destroy an ast_cap structure.
+/*!
+ * \brief Destroy an ast_cap structure.
  *
  * \return NULL
  */
 void *ast_cap_destroy(struct ast_cap *cap);
 
-/*! \brief Add format capability to capabilities structure.
+/*!
+ * \brief Add format capability to capabilities structure.
  *
  * \note A copy of the input format is made and that copy is
  * what is placed in the ast_cap structure.  The actual
@@ -50,7 +53,8 @@
  */
 void ast_cap_add(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Remove format capability from capability structure.
+/*!
+ * \brief Remove format capability from capability structure.
  *
  * \Note format must match Exactly to format in ast_cap object in order
  * to be removed.
@@ -60,7 +64,8 @@
  */
 int ast_cap_remove(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Remove all format capabilities from capability
+/*!
+ * \brief Remove all format capabilities from capability
  * structure for a specific format id.
  *
  * \Note This will remove _ALL_ formats matching the format id from the
@@ -71,21 +76,24 @@
  */
 int ast_cap_remove_byid(struct ast_cap *cap, enum ast_format_id id);
 
-/*! \brief Find if ast_format is within the capabilities of the ast_cap object.
+/*!
+ * \brief Find if ast_format is within the capabilities of the ast_cap object.
  *
  * retval 1 format is compatible with formats held in ast_cap object.
  * retval 0 format is not compatible with any formats in ast_cap object.
  */
 int ast_cap_iscompatible(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Get joint capability structure.
+/*!
+ * \brief Get joint capability structure.
  *
  * \retval !NULL success
  * \retval NULL failure
  */
 struct ast_cap *ast_cap_joint(struct ast_cap *cap1, struct ast_cap *cap2);
 
-/*! \brief Get all capabilities for a specific media type
+/*!
+ * \brief Get all capabilities for a specific media type
  *
  * \retval !NULL success
  * \retval NULL failure
@@ -96,7 +104,8 @@
 /*! \brief Start iterating formats */
 void ast_cap_iter_start(struct ast_cap *cap);
 
-/*! \brief Next format in interation
+/*!
+ * \brief Next format in interation
  *
  * \details
  * Here is how to use the ast_cap iterator.
@@ -118,7 +127,8 @@
  */
 int ast_cap_iter_next(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Ends ast_cap iteration.
+/*!
+ * \brief Ends ast_cap iteration.
  * \note this must be call after every ast_cap_iter_start
  */
 void ast_cap_iter_end(struct ast_cap *cap);

Modified: team/dvossel/fixtheworld_phase1_step1/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/asterisk.c?view=diff&rev=299246&r1=299245&r2=299246
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/asterisk.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/asterisk.c Mon Dec 20 15:33:56 2010
@@ -142,6 +142,7 @@
 #include "asterisk/poll-compat.h"
 #include "asterisk/ccss.h"
 #include "asterisk/test.h"
+#include "asterisk/format.h"
 #include "asterisk/aoc.h"
 
 #include "../defaults.h"
@@ -3700,6 +3701,8 @@
 
 	astobj2_init();
 
+	ast_format_attr_init();
+
 	ast_autoservice_init();
 
 	if (ast_timing_init()) {

Modified: team/dvossel/fixtheworld_phase1_step1/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format.c?view=diff&rev=299246&r1=299245&r2=299246
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format.c Mon Dec 20 15:33:56 2010
@@ -76,7 +76,7 @@
 	memcpy(dst, src, sizeof(struct ast_format));
 }
 
-/* \internal
+/*! \internal
  * \brief set format attributes using an interface
  */
 static int format_set_helper(struct ast_format *format, va_list ap)
@@ -85,10 +85,6 @@
 	struct interface_ao2_wrapper tmp_wrapper = {
 		.id = format->id,
 	};
-
-	if (!interfaces) {
-		return -1;
-	}
 
 	ast_rwlock_rdlock(&ilock);
 	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
@@ -130,7 +126,7 @@
 	return format;
 }
 
-/* \internal
+/*! \internal
  * \brief determine if a list of attribute key value pairs are set on a format
  */
 static int format_isset_helper(struct ast_format *format, va_list ap)
@@ -145,10 +141,6 @@
 		.fattr = { { 0, }, },
 	};
 
-	if (!interfaces) {
-		return -1;
-	}
-
 	ast_rwlock_rdlock(&ilock);
 	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
 		ast_rwlock_unlock(&ilock);
@@ -189,7 +181,7 @@
 }
 
 
-/* \internal
+/*! \internal
  * \brief cmp format attributes using an interface
  */
 static enum ast_format_cmp_res format_cmp_helper(struct ast_format *format1, struct ast_format *format2)
@@ -199,10 +191,6 @@
 	struct interface_ao2_wrapper tmp_wrapper = {
 		.id = format1->id,
 	};
-
-	if (!interfaces) {
-		return res;
-	}
 
 	ast_rwlock_rdlock(&ilock);
 	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
@@ -235,7 +223,7 @@
 	return format_cmp_helper(format1, format2);
 }
 
-/* \internal
+/*! \internal
  * \brief get joint format attributes using an interface
  */
 static int format_joint_helper(struct ast_format *format1, struct ast_format *format2, struct ast_format *result)
@@ -245,10 +233,6 @@
 	struct interface_ao2_wrapper tmp_wrapper = {
 		.id = format1->id,
 	};
-
-	if (!interfaces) {
-		return res;
-	}
 
 	ast_rwlock_rdlock(&ilock);
 	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
@@ -471,9 +455,7 @@
 	return NULL;
 }
 
-/*! \internal
- * \brief Initiate interface container and rw lock. */
-static int format_init(void)
+int ast_format_attr_init()
 {
 	if (!(interfaces = ao2_container_alloc(256, interface_hash_cb, interface_cmp_cb))) {
 		return -1;
@@ -485,14 +467,19 @@
 int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface)
 {
 	struct interface_ao2_wrapper *wrapper;
-
-	/* check for duplicates first, remove if they exist */
-	ast_format_attr_unreg_interface(interface);
-
-	if (!interfaces && (format_init())) {
-		ast_log(LOG_WARNING, "Failed to create format attribute interface container\n");
-		return -1;
-	}
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = interface->id,
+	};
+
+	/* check for duplicates first*/
+	ast_rwlock_wrlock(&ilock);
+	if ((wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		ast_log(LOG_WARNING, "Can not register attribute interface for format id %d, interface already exists.\n", interface->id);
+		ao2_ref(wrapper, -1);
+		return -1;
+	}
+	ast_rwlock_unlock(&ilock);
 
 	if (!(wrapper = ao2_alloc(sizeof(*wrapper), interface_destroy_cb))) {
 		return -1;
@@ -518,10 +505,6 @@
 	struct interface_ao2_wrapper tmp_wrapper = {
 		.id = interface->id,
 	};
-
-	if (!interfaces) {
-		return -1;
-	}
 
 	/* use the write lock whenever the interface container is modified */
 	ast_rwlock_wrlock(&ilock);

Modified: team/dvossel/fixtheworld_phase1_step1/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step1/main/format_cap.c?view=diff&rev=299246&r1=299245&r2=299246
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format_cap.c Mon Dec 20 15:33:56 2010
@@ -47,7 +47,7 @@
 {
 	struct ast_format *format1 = arg;
 	struct ast_format *format2 = obj;
-	int res = ast_format_cmp(format1, format2);
+	enum ast_format_cmp_res res = ast_format_cmp(format1, format2);
 
 	return ((res == AST_FORMAT_CMP_EQUAL) ||
 			(res == AST_FORMAT_CMP_SUBSET)) ?
@@ -123,30 +123,45 @@
 	return -1;
 }
 
+struct multiple_by_id_data {
+	struct ast_format *format;
+	int match_found;
+};
+
 static int multiple_by_id_cb(void *obj, void *arg, int flag)
 {
-	struct ast_format *format1 = arg;
-	struct ast_format *format2 = obj;
-
-	return (format1->id == format2->id) ? CMP_MATCH : 0;
+	struct multiple_by_id_data *data = arg;
+	struct ast_format *format = obj;
+	int res;
+
+	res = (format->id == data->format->id) ? CMP_MATCH : 0;
+	if (res) {
+		data->match_found = 1;
+	}
+
+	return res;
 }
 
 int ast_cap_remove_byid(struct ast_cap *cap, enum ast_format_id id)
 {
-	struct ao2_iterator *mult_it;
 	struct ast_format format = {
 		.id = id,
 	};
-
-	mult_it = ao2_callback(cap->formats,
-		OBJ_MULTIPLE | OBJ_POINTER | OBJ_UNLINK,
+	struct multiple_by_id_data data = {
+		.format = &format,
+		.match_found = 0,
+	};
+
+	ao2_callback(cap->formats,
+		OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
 		multiple_by_id_cb,
-		&format);
-
-	if (mult_it) {
-		ao2_iterator_destroy(mult_it);
+		&data);
+
+	/* match_found will be set if at least one item was removed */
+	if (data.match_found) {
 		return 0;
 	}
+
 	return -1;
 }
 




More information about the svn-commits mailing list