[svn-commits] dvossel: branch dvossel/fixtheworld_phase1_step3 r303283 - in /team/dvossel/f...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jan 21 13:21:04 CST 2011


Author: dvossel
Date: Fri Jan 21 13:21:00 2011
New Revision: 303283

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=303283
Log:
make function parameters const where they need to be

Modified:
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
    team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
    team/dvossel/fixtheworld_phase1_step3/main/format.c
    team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
    team/dvossel/fixtheworld_phase1_step3/main/translate.c
    team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format.h Fri Jan 21 13:21:00 2011
@@ -149,7 +149,7 @@
 	 * \retval 0 if joint attributes exist
 	 * \retval -1 if no joint attributes are present
 	 */
-	int (* const format_attr_get_joint)(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2, struct ast_format_attr *result);
+	int (* const format_attr_get_joint)(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result);
 
 	/*! \brief Set format capabilities from a list of key value pairs ending with AST_FORMAT_ATTR_END.
 	 * \note This function does not need to call va_end of the va_list. */
@@ -212,7 +212,7 @@
  * retval 0, joint attribute capabilities exist.
  * retval -1, no joint attribute capabilities exist.
  */
-int ast_format_joint(struct ast_format *format1, struct ast_format *format2, struct ast_format *result);
+int ast_format_joint(const struct ast_format *format1, const struct ast_format *format2, struct ast_format *result);
 
 /*!
  * \brief copy format src into format dst.
@@ -241,7 +241,7 @@
  * \retval iax2 representation of ast_format
  * \retval 0, if no representation existis for iax2
  */
-uint64_t ast_format_to_old_bitfield(struct ast_format *format);
+uint64_t ast_format_to_old_bitfield(const struct ast_format *format);
 
 /*!
  * \brief ast_format_id to old bitfield format represenatation
@@ -269,7 +269,7 @@
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface);
+int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interface);
 
 /*!
  * \brief unregister format_attr interface with core.
@@ -277,7 +277,7 @@
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_format_attr_unreg_interface(struct ast_format_attr_interface *interface);
+int ast_format_attr_unreg_interface(const struct ast_format_attr_interface *interface);
 
 /*!
  * \brief Init the ast_format attribute interface register container.

Modified: team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step3/include/asterisk/format_cap.h Fri Jan 21 13:21:00 2011
@@ -106,7 +106,7 @@
  * \retval cap on success, New capabilities structure is allocated with _NO_ locking enabled.
  * \retval NULL on failure
  */
-struct ast_format_cap *ast_format_cap_copy(struct ast_format_cap *src);
+struct ast_format_cap *ast_format_cap_copy(const struct ast_format_cap *src);
 
 /*!
  * \brief determine if a capabilities structure is empty or not
@@ -184,7 +184,7 @@
  * \retval 1, joint capabilities exist
  * \retval 0, joint capabilities do not exist
  */
-int ast_format_cap_joint_copy(struct ast_format_cap *cap1, struct ast_format_cap *cap2, struct ast_format_cap *result);
+int ast_format_cap_joint_copy(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result);
 
 /*!
  * \brief Find out if capability structures have any joint capabilities without
@@ -201,7 +201,7 @@
  * \retval !NULL success, new capabilities structure with _NO_ locking enabled on the new structure.
  * \retval NULL failure
  */
-struct ast_format_cap *ast_format_cap_get_type(struct ast_format_cap *cap, enum ast_format_type ftype);
+struct ast_format_cap *ast_format_cap_get_type(const struct ast_format_cap *cap, enum ast_format_type ftype);
 
 /*!
  * \brief Find out if the capabilities structure has any formats
@@ -210,7 +210,7 @@
  * \retval 1 true
  * \retval 0 false, no formats of specific type.
  */
-int ast_format_cap_has_type(struct ast_format_cap *cap, enum ast_format_type type);
+int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_format_type type);
 
 /*! \brief Start iterating formats */
 void ast_format_cap_iter_start(struct ast_format_cap *cap);
@@ -252,7 +252,7 @@
  * \retval old bitfield representation of ast_format_cap
  * \retval 0, if no old bitfield capabilities are present in ast_format_cap
  */
-uint64_t ast_format_cap_to_old_bitfield(struct ast_format_cap *cap);
+uint64_t ast_format_cap_to_old_bitfield(const struct ast_format_cap *cap);
 
 /*!
  * \brief convert old bitfield format to ast_format_cap represenatation

Modified: team/dvossel/fixtheworld_phase1_step3/main/format.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format.c?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format.c Fri Jan 21 13:21:00 2011
@@ -45,7 +45,7 @@
 /*! a wrapper is used put interfaces into the ao2 container. */
 struct interface_ao2_wrapper {
 	enum ast_format_id id;
-	struct ast_format_attr_interface *interface;
+	const struct ast_format_attr_interface *interface;
 	/*! a read write lock must be used to protect the wrapper instead
 	 * of the ao2 lock. */
 	ast_rwlock_t wraplock;
@@ -86,23 +86,34 @@
 	return format->fattr.rtp_marker_bit;
 }
 
+static struct interface_ao2_wrapper *find_interface(const struct ast_format *format)
+{
+	struct interface_ao2_wrapper *wrapper;
+	struct interface_ao2_wrapper tmp_wrapper = {
+		.id = format->id,
+	};
+
+	ast_rwlock_rdlock(&ilock);
+	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+		ast_rwlock_unlock(&ilock);
+		return NULL;
+	}
+	ast_rwlock_unlock(&ilock);
+
+	return wrapper;
+}
+
 /*! \internal
  * \brief set format attributes using an interface
  */
 static int format_set_helper(struct ast_format *format, va_list ap)
 {
 	struct interface_ao2_wrapper *wrapper;
-	struct interface_ao2_wrapper tmp_wrapper = {
-		.id = format->id,
-	};
-
-	ast_rwlock_rdlock(&ilock);
-	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
-		ast_log(LOG_WARNING, "Could not find format interface to set\n");
-		ast_rwlock_unlock(&ilock);
-		return -1;
-	}
-	ast_rwlock_unlock(&ilock);
+
+	if (!(wrapper = find_interface(format))) {
+		ast_log(LOG_WARNING, "Could not find format interface to set.\n");
+		return -1;
+	}
 
 	ast_rwlock_rdlock(&wrapper->wraplock);
 	if (!wrapper->interface || !wrapper->interface->format_attr_set) {
@@ -150,20 +161,14 @@
 {
 	int res;
 	struct interface_ao2_wrapper *wrapper;
-	struct interface_ao2_wrapper tmp_wrapper = {
-		.id = format->id,
-	};
 	struct ast_format tmp = {
 		.id = format->id,
 		.fattr = { { 0, }, },
 	};
 
-	ast_rwlock_rdlock(&ilock);
-	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
-		ast_rwlock_unlock(&ilock);
-		return -1;
-	}
-	ast_rwlock_unlock(&ilock);
+	if (!(wrapper = find_interface(format))) {
+		return -1;
+	}
 
 	ast_rwlock_rdlock(&wrapper->wraplock);
 	if (!wrapper->interface ||
@@ -205,16 +210,10 @@
 {
 	enum ast_format_cmp_res res = AST_FORMAT_CMP_EQUAL;
 	struct interface_ao2_wrapper *wrapper;
-	struct interface_ao2_wrapper tmp_wrapper = {
-		.id = format1->id,
-	};
-
-	ast_rwlock_rdlock(&ilock);
-	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
-		ast_rwlock_unlock(&ilock);
+
+	if (!(wrapper = find_interface(format1))) {
 		return res;
 	}
-	ast_rwlock_unlock(&ilock);
 
 	ast_rwlock_rdlock(&wrapper->wraplock);
 	if (!wrapper->interface || !wrapper->interface->format_attr_cmp) {
@@ -243,21 +242,15 @@
 /*! \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)
+static int format_joint_helper(const struct ast_format *format1, const struct ast_format *format2, struct ast_format *result)
 {
 	int res = 0;
 	struct interface_ao2_wrapper *wrapper;
-	struct interface_ao2_wrapper tmp_wrapper = {
-		.id = format1->id,
-	};
-
-	ast_rwlock_rdlock(&ilock);
-	if (!(wrapper = ao2_find(interfaces, &tmp_wrapper, (OBJ_POINTER | OBJ_NOLOCK)))) {
+
+	if (!(wrapper = find_interface(format1))) {
 		/* if no interface is present, we assume formats are joint by id alone */
-		ast_rwlock_unlock(&ilock);
 		return res;
 	}
-	ast_rwlock_unlock(&ilock);
 
 	ast_rwlock_rdlock(&wrapper->wraplock);
 	if (!wrapper->interface || !wrapper->interface->format_attr_get_joint) {
@@ -274,7 +267,7 @@
 	return res;
 }
 
-int ast_format_joint(struct ast_format *format1, struct ast_format *format2, struct ast_format *result)
+int ast_format_joint(const struct ast_format *format1, const struct ast_format *format2, struct ast_format *result)
 {
 	if (format1->id != format2->id) {
 		return -1;
@@ -379,7 +372,7 @@
 	return 0;
 
 }
-uint64_t ast_format_to_old_bitfield(struct ast_format *format)
+uint64_t ast_format_to_old_bitfield(const struct ast_format *format)
 {
 	return ast_format_id_to_old_bitfield(format->id);
 }
@@ -497,7 +490,7 @@
 	return 0;
 }
 
-int ast_format_attr_reg_interface(struct ast_format_attr_interface *interface)
+int ast_format_attr_reg_interface(const struct ast_format_attr_interface *interface)
 {
 	struct interface_ao2_wrapper *wrapper;
 	struct interface_ao2_wrapper tmp_wrapper = {
@@ -532,7 +525,7 @@
 	return 0;
 }
 
-int ast_format_attr_unreg_interface(struct ast_format_attr_interface *interface)
+int ast_format_attr_unreg_interface(const struct ast_format_attr_interface *interface)
 {
 	struct interface_ao2_wrapper *wrapper;
 	struct interface_ao2_wrapper tmp_wrapper = {

Modified: team/dvossel/fixtheworld_phase1_step3/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/format_cap.c?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/format_cap.c Fri Jan 21 13:21:00 2011
@@ -176,7 +176,7 @@
 	ao2_callback(src->formats, OBJ_NODATA | src->nolock, copy_cb, dst);
 }
 
-struct ast_format_cap *ast_format_cap_copy(struct ast_format_cap *cap)
+struct ast_format_cap *ast_format_cap_copy(const struct ast_format_cap *cap)
 {
 	struct ast_format_cap *dst = ast_format_cap_alloc_nolock();
 	if (!dst) {
@@ -399,7 +399,7 @@
 	return NULL;
 }
 
-int ast_format_cap_joint_copy(struct ast_format_cap *cap1, struct ast_format_cap *cap2, struct ast_format_cap *result)
+int ast_format_cap_joint_copy(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
 {
 	struct ao2_iterator it;
 	struct ast_format *tmp;
@@ -423,7 +423,7 @@
 	return ao2_container_count(result->formats) ? 1 : 0;
 }
 
-struct ast_format_cap *ast_format_cap_get_type(struct ast_format_cap *cap, enum ast_format_type ftype)
+struct ast_format_cap *ast_format_cap_get_type(const struct ast_format_cap *cap, enum ast_format_type ftype)
 {
 	struct ao2_iterator it;
 	struct ast_format_cap *result = ast_format_cap_alloc_nolock();
@@ -456,7 +456,7 @@
 }
 
 
-int ast_format_cap_has_type(struct ast_format_cap *cap, enum ast_format_type type)
+int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_format_type type)
 {
 	struct ao2_iterator it;
 	struct ast_format *tmp;
@@ -498,7 +498,7 @@
 	return 0;
 }
 
-uint64_t ast_format_cap_to_old_bitfield(struct ast_format_cap *cap)
+uint64_t ast_format_cap_to_old_bitfield(const struct ast_format_cap *cap)
 {
 	uint64_t res = 0;
 	struct ao2_iterator it;

Modified: team/dvossel/fixtheworld_phase1_step3/main/translate.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/main/translate.c?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/main/translate.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/main/translate.c Fri Jan 21 13:21:00 2011
@@ -132,7 +132,7 @@
 	ast_rwlock_wrlock(&tablelock);
 	if (cur_max_index == (index_size)) {
 		ast_rwlock_unlock(&tablelock);
-		return -1; /* hit max length. todohere, make it grow. */
+		return -1; /* hit max length */
 	}
 	__indextable[cur_max_index] = id;
 	cur_max_index++;

Modified: team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c?view=diff&rev=303283&r1=303282&r2=303283
==============================================================================
--- team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c (original)
+++ team/dvossel/fixtheworld_phase1_step3/tests/test_format_api.c Fri Jan 21 13:21:00 2011
@@ -77,7 +77,7 @@
 	return AST_FORMAT_CMP_SUBSET;
 }
 
-static int test_getjoint(struct ast_format_attr *fattr1, struct ast_format_attr *fattr2, struct ast_format_attr *result)
+static int test_getjoint(const struct ast_format_attr *fattr1, const struct ast_format_attr *fattr2, struct ast_format_attr *result)
 {
 	struct test_attr *attr1 = (struct test_attr *) fattr1;
 	struct test_attr *attr2 = (struct test_attr *) fattr2;




More information about the svn-commits mailing list