[asterisk-commits] file: branch file/sorcery r378707 - in /team/file/sorcery: include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 9 09:11:23 CST 2013


Author: file
Date: Wed Jan  9 09:11:19 2013
New Revision: 378707

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378707
Log:
Remove an implementation detail from being exposed to users of sorcery.

Modified:
    team/file/sorcery/include/asterisk/sorcery.h
    team/file/sorcery/main/sorcery.c
    team/file/sorcery/tests/test_sorcery.c

Modified: team/file/sorcery/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/include/asterisk/sorcery.h?view=diff&rev=378707&r1=378706&r2=378707
==============================================================================
--- team/file/sorcery/include/asterisk/sorcery.h (original)
+++ team/file/sorcery/include/asterisk/sorcery.h Wed Jan  9 09:11:19 2013
@@ -289,14 +289,14 @@
  *
  * \param sorcery Pointer to a sorcery structure
  * \param type Type of object
- * \param aco_type Configuration framework details for type
+ * \param alloc Required object allocation callback
  * \param transform Optional transformation callback
  * \param apply Optional object set apply callback
  *
  * \retval 0 success
  * \retval -1 failure
  */
-int ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, struct aco_type *aco_type, sorcery_transform_handler transform, sorcery_apply_handler apply);
+int ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply);
 
 /*!
  * \brief Register a field within an object

Modified: team/file/sorcery/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/main/sorcery.c?view=diff&rev=378707&r1=378706&r2=378707
==============================================================================
--- team/file/sorcery/main/sorcery.c (original)
+++ team/file/sorcery/main/sorcery.c Wed Jan  9 09:11:19 2013
@@ -71,8 +71,8 @@
 	/*! \brief Configuration framework file information */
 	struct aco_file *file;
 
-	/*! \brief Pointer to the configuration framework details for the object */
-	struct aco_type *type;
+	/*! \brief Type details */
+	struct aco_type type;
 };
 
 /*! \brief Structure for registered object field */
@@ -466,7 +466,7 @@
 	return sorcery_apply_wizard_mapping(sorcery, type, name, data, 0);
 }
 
-int ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, struct aco_type *aco_type, sorcery_transform_handler transform, sorcery_apply_handler apply)
+int ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply)
 {
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 
@@ -474,15 +474,17 @@
 		return -1;
 	}
 
+	object_type->type.type = ACO_ITEM;
+	object_type->type.category = "";
+	object_type->type.item_alloc = alloc;
+
 	object_type->transform = transform;
-	object_type->file->types[0] = aco_type;
+	object_type->file->types[0] = &object_type->type;
 	object_type->file->types[1] = NULL;
 
 	if (aco_info_init(object_type->info)) {
 		return -1;
 	}
-
-	object_type->type = aco_type;
 
 	return 0;
 }
@@ -493,7 +495,7 @@
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 	va_list args;
 
-	if (!object_type || !object_type->type) {
+	if (!object_type || !object_type->type.item_alloc) {
 		return -1;
 	}
 
@@ -656,7 +658,7 @@
 	}
 
 	for (; field; field = field->next) {
-		if ((res = aco_process_var(object_type->type, details->id, field, object))) {
+		if ((res = aco_process_var(&object_type->type, details->id, field, object))) {
 			break;
 		}
 	}
@@ -718,9 +720,8 @@
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 	struct ast_sorcery_object_details *details;
 
-	if (!object_type || !object_type->type ||
-	    !object_type->type->item_alloc ||
-	    !(details = object_type->type->item_alloc(""))) {
+	if (!object_type || !object_type->type.item_alloc ||
+	    !(details = object_type->type.item_alloc(""))) {
 		return NULL;
 	}
 
@@ -740,7 +741,7 @@
 
 	ast_copy_string(details->type, type, sizeof(details->type));
 
-	if (aco_set_defaults(object_type->type, id, details)) {
+	if (aco_set_defaults(&object_type->type, id, details)) {
 		ao2_ref(details, -1);
 		return NULL;
 	}

Modified: team/file/sorcery/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/team/file/sorcery/tests/test_sorcery.c?view=diff&rev=378707&r1=378706&r2=378707
==============================================================================
--- team/file/sorcery/tests/test_sorcery.c (original)
+++ team/file/sorcery/tests/test_sorcery.c Wed Jan  9 09:11:19 2013
@@ -77,14 +77,6 @@
 	return transformed;
 }
 
-/*! \brief Configuration framework definition for test object */
-static struct aco_type test_object = {
-	.type = ACO_ITEM,
-	.category_match = ACO_BLACKLIST,
-	.category = "^general$",
-	.item_alloc = test_sorcery_object_alloc,
-};
-
 /*! \brief Test structure for caching */
 struct sorcery_test_caching {
 	/*! \brief Whether the object has been created in the cache or not */
@@ -301,7 +293,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -330,7 +322,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (!ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (!ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Registered object type when no object mapping exists\n");
 		return AST_TEST_FAIL;
 	}
@@ -374,7 +366,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -415,7 +407,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -474,7 +466,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -523,7 +515,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -587,7 +579,7 @@
 	       return AST_TEST_FAIL;
        }
 
-       if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+       if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 	       ast_test_status_update(test, "Failed to register object type\n");
 	       return AST_TEST_FAIL;
        }
@@ -661,7 +653,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -728,7 +720,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -783,7 +775,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -838,7 +830,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, test_sorcery_transform, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, test_sorcery_transform, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1010,7 +1002,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1058,7 +1050,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1125,7 +1117,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1190,7 +1182,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1256,7 +1248,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1325,7 +1317,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1393,7 +1385,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1438,7 +1430,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1495,7 +1487,7 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1556,7 +1548,7 @@
 		goto end;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		goto end;
 	}
@@ -1656,7 +1648,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1719,7 +1711,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1773,7 +1765,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1831,7 +1823,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1888,7 +1880,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}
@@ -1955,7 +1947,7 @@
 		return AST_TEST_NOT_RUN;
 	}
 
-	if (ast_sorcery_object_register(sorcery, "test", &test_object, NULL, NULL)) {
+	if (ast_sorcery_object_register(sorcery, "test", test_sorcery_object_alloc, NULL, NULL)) {
 		ast_test_status_update(test, "Failed to register object type\n");
 		return AST_TEST_FAIL;
 	}




More information about the asterisk-commits mailing list