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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Dec 15 19:21:24 UTC 2010


Author: dvossel
Date: Wed Dec 15 13:21:20 2010
New Revision: 298343

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=298343
Log:
Begining of Ast Capabilities API implementation

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/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=298343&r1=298342&r2=298343
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format.h Wed Dec 15 13:21:20 2010
@@ -209,6 +209,12 @@
  */
 int ast_format_joint(struct ast_format *format1, struct ast_format *format2, struct ast_format *result);
 
+/*!
+ *
+ * \brief copy format src into format dst.
+ */
+void ast_format_copy(struct ast_format *src, struct ast_format *dst);
+
 /*! \brief register ast_format_attr_interface with core.
  *
  * \retval 0 success

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=298343&r1=298342&r2=298343
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase1_step1/include/asterisk/format_cap.h Wed Dec 15 13:21:20 2010
@@ -45,15 +45,33 @@
 /*! \brief Add format capability to capabilities structure. */
 void ast_cap_add(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Remove format capability from capability structure */
-void ast_cap_remove(struct ast_cap *cap, struct ast_format *format);
+/*! \brief Remove format capability from capability structure.
+ *
+ * \Note format must match Exactly to format in ast_cap object in order
+ * to be removed.
+ *
+ * \retval 0, remove was successful
+ * \retval -1, remove failed. Could not find format to remove
+ */
+int ast_cap_remove(struct ast_cap *cap, struct ast_format *format);
 
-/*! \brief Find if ast_format is part of the capabilities structure.
+/*! \brief Remove all format capabilities from capability
+ * structure for a specific format id.
  *
- * retval 1 format is found.
- * retval 0 format is not found
+ * \Note This will remove _ALL_ formats matching the format id from the
+ * capabilities structure.
+ *
+ * \retval 0, remove was successful
+ * \retval -1, remove failed. Could not find formats to remove
  */
-int ast_cap_find(struct ast_cap *cap, struct ast_format *format);
+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.
+ *
+ * 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.
  *
@@ -67,6 +85,6 @@
  * \retval !NULL success
  * \retval NULL failure
  */
-struct ast_cap *ast_cap_get_type(struct ast_cap *cap, enum ast_format_type);
+struct ast_cap *ast_cap_get_type(struct ast_cap *cap, enum ast_format_type ftype);
 
 #endif /* _AST_FORMATCAP_H */

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=298343&r1=298342&r2=298343
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format.c Wed Dec 15 13:21:20 2010
@@ -56,6 +56,13 @@
 	return wrapper->id;
 }
 
+
+void ast_format_copy(struct ast_format *src, struct ast_format *dst)
+{
+	/* copying is simple, for now */
+	*dst = *src;
+}
+
 /* \internal
  * \brief set format attributes using an interface
  */

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=298343&r1=298342&r2=298343
==============================================================================
--- team/dvossel/fixtheworld_phase1_step1/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase1_step1/main/format_cap.c Wed Dec 15 13:21:20 2010
@@ -32,34 +32,127 @@
 #include "asterisk/format.h"
 #include "asterisk/format_cap.h"
 #include "asterisk/astobj2.h"
+#include "asterisk/utils.h"
 
 
 struct ast_cap {
+	/* The capabilities structure is just an ao2 container of ast_formats */
 	struct ao2_container *formats;
 };
 
+/*! format exists within capabilities structure if it is identical to
+ * another format, or if the format is a proper subset of another format. */
+static int cmp_cb(void *obj, void *arg, int flags)
+{
+	struct ast_format *format1 = (struct ast_format *) arg;
+	struct ast_format *format2 = (struct ast_format *) obj;
+	int res = ast_format_cmp(format1, format2);
+
+	return ((res == AST_FORMAT_CMP_SAME) ||
+			(res = AST_FORMAT_CMP_SUBSET)) ?
+				CMP_MATCH | CMP_STOP :
+				0;
+}
+
+static int hash_cb(const void *obj, const int flags)
+{
+	struct ast_format *format = (struct ast_format *) obj;
+	return format->id;
+}
+
 struct ast_cap *ast_cap_alloc(void)
 {
-	return NULL;
+	struct ast_cap *cap = ast_calloc(1, sizeof(*cap));
+
+	if (!cap) {
+		return NULL;
+	}
+
+	if (!(cap->formats = ao2_container_alloc(256, hash_cb, cmp_cb))) {
+		ast_free(cap);
+		return NULL;
+	}
+
+	return cap;
 }
 
 void *ast_cap_destroy(struct ast_cap *cap)
 {
+	ao2_ref(cap->formats, -1);
+	ast_free(cap);
 	return NULL;
 }
 
 void ast_cap_add(struct ast_cap *cap, struct ast_format *format)
 {
-	return;
+	struct ast_format *fnew;
+
+	if (!(fnew = ao2_alloc(sizeof(format), NULL))) {
+		return;
+	}
+	ast_format_copy(format, fnew);
+	ao2_link(cap->formats, fnew);
+	ao2_ref(fnew, -1);
 }
 
-void ast_cap_remove(struct ast_cap *cap, struct ast_format *format)
+static int find_exact_cb(void *obj, void *arg, int flag)
 {
-	return;
+	struct ast_format *format1 = (struct ast_format *) arg;
+	struct ast_format *format2 = (struct ast_format *) obj;
+
+	return (ast_format_cmp(format1, format2) == AST_FORMAT_CMP_SAME) ? CMP_MATCH : 0;
 }
 
-int ast_cap_find(struct ast_cap *cap, struct ast_format *format)
+int ast_cap_remove(struct ast_cap *cap, struct ast_format *format)
 {
+	struct ast_format *fremove;
+	fremove = ao2_callback(cap->formats, OBJ_POINTER | OBJ_UNLINK, find_exact_cb, format);
+
+	if (fremove) {
+		ao2_ref(fremove, -1);
+		return 0;
+	}
+
+	return -1;
+}
+
+static int multiple_by_id_cb(void *obj, void *arg, int flag)
+{
+	struct ast_format *format1 = (struct ast_format *) arg;
+	struct ast_format *format2 = (struct ast_format *) obj;
+
+	return (format1->id == format2->id) ? CMP_MATCH : 0;
+}
+
+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,
+		multiple_by_id_cb,
+		&format);
+
+	if (mult_it) {
+		ao2_iterator_destroy(mult_it);
+		return 0;
+	}
+	return -1;
+}
+
+int ast_cap_iscompatible(struct ast_cap *cap, struct ast_format *format)
+{
+	struct ast_format *f;
+	f = ao2_find(cap->formats, format, OBJ_POINTER);
+
+	if (f) {
+		ao2_ref(f, -1);
+		return 1;
+	}
+
 	return 0;
 }
 




More information about the svn-commits mailing list