[asterisk-commits] file: trunk r383405 - in /trunk: include/asterisk/ main/ res/ tests/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 20 09:52:26 CDT 2013


Author: file
Date: Wed Mar 20 09:52:23 2013
New Revision: 383405

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383405
Log:
Pass the sorcery instance to wizards for CUD operations as well as retrieve.

Modified:
    trunk/include/asterisk/sorcery.h
    trunk/main/sorcery.c
    trunk/res/res_sorcery_memory.c
    trunk/tests/test_sorcery.c

Modified: trunk/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/sorcery.h?view=diff&rev=383405&r1=383404&r2=383405
==============================================================================
--- trunk/include/asterisk/sorcery.h (original)
+++ trunk/include/asterisk/sorcery.h Wed Mar 20 09:52:23 2013
@@ -203,7 +203,7 @@
 	void (*reload)(void *data, const struct ast_sorcery *sorcery, const char *type);
 
 	/*! \brief Callback for creating an object */
-	int (*create)(void *data, void *object);
+	int (*create)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for retrieving an object using an id */
 	void *(*retrieve_id)(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id);
@@ -218,10 +218,10 @@
 	void (*retrieve_multiple)(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const struct ast_variable *fields);
 
 	/*! \brief Callback for updating an object */
-	int (*update)(void *data, void *object);
+	int (*update)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for deleting an object */
-	int (*delete)(void *data, void *object);
+	int (*delete)(const struct ast_sorcery *sorcery, void *data, void *object);
 
 	/*! \brief Callback for closing a wizard */
 	void (*close)(void *data);

Modified: trunk/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/sorcery.c?view=diff&rev=383405&r1=383404&r2=383405
==============================================================================
--- trunk/main/sorcery.c (original)
+++ trunk/main/sorcery.c Wed Mar 20 09:52:23 2013
@@ -888,16 +888,25 @@
 	}
 }
 
+/*! \brief Structure used when calling create, update, or delete */
+struct sorcery_details {
+	/*! \brief Pointer to the sorcery instance */
+	const struct ast_sorcery *sorcery;
+	/*! \brief Pointer to the object itself */
+	void *obj;
+};
+
 /*! \brief Internal function used to create an object in caching wizards */
 static int sorcery_cache_create(void *obj, void *arg, int flags)
 {
-	struct ast_sorcery_object_wizard *object_wizard = obj;
+	const struct ast_sorcery_object_wizard *object_wizard = obj;
+	const struct sorcery_details *details = arg;
 
 	if (!object_wizard->caching || !object_wizard->wizard->create) {
 		return 0;
 	}
 
-	object_wizard->wizard->create(object_wizard->data, arg);
+	object_wizard->wizard->create(details->sorcery, object_wizard->data, details->obj);
 
 	return 0;
 }
@@ -1014,8 +1023,9 @@
 static int sorcery_wizard_create(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (!object_wizard->caching && !object_wizard->wizard->create(object_wizard->data, arg)) ? CMP_MATCH | CMP_STOP : 0;
+	const struct sorcery_details *details = arg;
+
+	return (!object_wizard->caching && !object_wizard->wizard->create(details->sorcery, object_wizard->data, details->obj)) ? CMP_MATCH | CMP_STOP : 0;
 }
 
 int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
@@ -1023,12 +1033,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_create, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }
@@ -1037,8 +1051,9 @@
 static int sorcery_wizard_update(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (object_wizard->wizard->update && !object_wizard->wizard->update(object_wizard->data, arg) &&
+	const struct sorcery_details *details = arg;
+
+	return (object_wizard->wizard->update && !object_wizard->wizard->update(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -1047,12 +1062,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_update, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_update, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }
@@ -1061,8 +1080,9 @@
 static int sorcery_wizard_delete(void *obj, void *arg, int flags)
 {
 	const struct ast_sorcery_object_wizard *object_wizard = obj;
-
-	return (object_wizard->wizard->delete && !object_wizard->wizard->delete(object_wizard->data, arg) &&
+	const struct sorcery_details *details = arg;
+
+	return (object_wizard->wizard->delete && !object_wizard->wizard->delete(details->sorcery, object_wizard->data, details->obj) &&
 		!object_wizard->caching) ? CMP_MATCH | CMP_STOP : 0;
 }
 
@@ -1071,12 +1091,16 @@
 	const struct ast_sorcery_object_details *details = object;
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, details->type, OBJ_KEY), ao2_cleanup);
 	RAII_VAR(struct ast_sorcery_object_wizard *, object_wizard, NULL, ao2_cleanup);
+	struct sorcery_details sdetails = {
+		.sorcery = sorcery,
+		.obj = object,
+	};
 
 	if (!object_type) {
 		return -1;
 	}
 
-	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_delete, object);
+	object_wizard = ao2_callback(object_type->wizards, 0, sorcery_wizard_delete, &sdetails);
 
 	return object_wizard ? 0 : -1;
 }

Modified: trunk/res/res_sorcery_memory.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_sorcery_memory.c?view=diff&rev=383405&r1=383404&r2=383405
==============================================================================
--- trunk/res/res_sorcery_memory.c (original)
+++ trunk/res/res_sorcery_memory.c Wed Mar 20 09:52:23 2013
@@ -42,14 +42,14 @@
 #define OBJECT_BUCKETS 53
 
 static void *sorcery_memory_open(const char *data);
-static int sorcery_memory_create(void *data, void *object);
+static int sorcery_memory_create(const struct ast_sorcery *sorcery, void *data, void *object);
 static void *sorcery_memory_retrieve_id(const struct ast_sorcery *sorcery, void *data, const char *type, const char *id);
 static void *sorcery_memory_retrieve_fields(const struct ast_sorcery *sorcery, void *data, const char *type, const struct ast_variable *fields);
 static void sorcery_memory_retrieve_multiple(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects,
 					     const struct ast_variable *fields);
 static void sorcery_memory_retrieve_regex(const struct ast_sorcery *sorcery, void *data, const char *type, struct ao2_container *objects, const char *regex);
-static int sorcery_memory_update(void *data, void *object);
-static int sorcery_memory_delete(void *data, void *object);
+static int sorcery_memory_update(const struct ast_sorcery *sorcery, void *data, void *object);
+static int sorcery_memory_delete(const struct ast_sorcery *sorcery, void *data, void *object);
 static void sorcery_memory_close(void *data);
 
 static struct ast_sorcery_wizard memory_object_wizard = {
@@ -96,7 +96,7 @@
 	return !strcmp(ast_sorcery_object_get_id(obj), flags & OBJ_KEY ? id : ast_sorcery_object_get_id(arg)) ? CMP_MATCH | CMP_STOP : 0;
 }
 
-static int sorcery_memory_create(void *data, void *object)
+static int sorcery_memory_create(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	ao2_link(data, object);
 	return 0;
@@ -184,7 +184,7 @@
 	regfree(&expression);
 }
 
-static int sorcery_memory_update(void *data, void *object)
+static int sorcery_memory_update(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	RAII_VAR(void *, existing, NULL, ao2_cleanup);
 
@@ -202,7 +202,7 @@
 	return 0;
 }
 
-static int sorcery_memory_delete(void *data, void *object)
+static int sorcery_memory_delete(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	RAII_VAR(void *, existing, ao2_find(data, ast_sorcery_object_get_id(object), OBJ_KEY | OBJ_UNLINK), ao2_cleanup);
 

Modified: trunk/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_sorcery.c?view=diff&rev=383405&r1=383404&r2=383405
==============================================================================
--- trunk/tests/test_sorcery.c (original)
+++ trunk/tests/test_sorcery.c Wed Mar 20 09:52:23 2013
@@ -138,7 +138,7 @@
 /*! \brief Global scope caching structure for testing */
 static struct sorcery_test_caching cache = { 0, };
 
-static int sorcery_test_create(void *data, void *object)
+static int sorcery_test_create(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	cache.created = 1;
 	cache.updated = 0;
@@ -151,13 +151,13 @@
 	return (cache.created && !cache.deleted) ? ast_sorcery_alloc(sorcery, type, id) : NULL;
 }
 
-static int sorcery_test_update(void *data, void *object)
+static int sorcery_test_update(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	cache.updated = 1;
 	return 0;
 }
 
-static int sorcery_test_delete(void *data, void *object)
+static int sorcery_test_delete(const struct ast_sorcery *sorcery, void *data, void *object)
 {
 	cache.deleted = 1;
 	return 0;




More information about the asterisk-commits mailing list