[asterisk-commits] rmudgett: trunk r403327 - in /trunk: ./ include/asterisk/ main/ res/ res/res_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Dec 3 11:35:58 CST 2013


Author: rmudgett
Date: Tue Dec  3 11:35:54 2013
New Revision: 403327

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403327
Log:
sorcery, bucket: Change observer remove calls to take const callbacks struct.

* Make ast_sorcery_observer_remove() accept a const callbacks struct.

* Make ast_sorcery_observer_remove() tolerant of the sorcery parameter
being NULL.  Now it can be called within a module unload routine if the
sorcery initialization fails.

* Fix ast_sorcery_observer_add() to fail if the container link fails.
........

Merged revisions 403324 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/bucket.h
    trunk/include/asterisk/sorcery.h
    trunk/main/bucket.c
    trunk/main/sorcery.c
    trunk/res/res_pjsip/pjsip_configuration.c
    trunk/res/res_pjsip/pjsip_options.c
    trunk/res/res_pjsip_registrar_expire.c
    trunk/tests/test_sorcery.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Tue Dec  3 11:35:54 2013
@@ -1,1 +1,1 @@
-/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-403175,403179,403207,403209,403221,403223,403240,403256,403258,403271,403290,403311-403312
+/branches/12:1-398558,398560-398577,398579-399305,399307-401390,401392-403175,403179,403207,403209,403221,403223,403240,403256,403258,403271,403290,403311-403312,403324

Modified: trunk/include/asterisk/bucket.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/bucket.h?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/include/asterisk/bucket.h (original)
+++ trunk/include/asterisk/bucket.h Tue Dec  3 11:35:54 2013
@@ -256,7 +256,7 @@
  *
  * \param callbacks Implementation of the sorcery observer interface
  */
-void ast_bucket_observer_remove(struct ast_sorcery_observer *callbacks);
+void ast_bucket_observer_remove(const struct ast_sorcery_observer *callbacks);
 
 /*!
  * \brief Get a JSON representation of a bucket
@@ -359,7 +359,7 @@
  *
  * \param callbacks Implementation of the sorcery observer interface
  */
-void ast_bucket_file_observer_remove(struct ast_sorcery_observer *callbacks);
+void ast_bucket_file_observer_remove(const struct ast_sorcery_observer *callbacks);
 
 /*!
  * \brief Get a JSON representation of a bucket file

Modified: trunk/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/sorcery.h?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/include/asterisk/sorcery.h (original)
+++ trunk/include/asterisk/sorcery.h Tue Dec  3 11:35:54 2013
@@ -349,6 +349,7 @@
  * \param sorcery Pointer to a sorcery structure
  * \param type Type of object
  * \param hidden All objects of this type are internal and should not be manipulated by users
+ * \param reloadable All objects of this type are reloadable
  * \param alloc Required object allocation callback
  * \param transform Optional transformation callback
  * \param apply Optional object set apply callback
@@ -689,7 +690,7 @@
  * \retval 0 success
  * \retval -1 failure
  */
-void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, struct ast_sorcery_observer *callbacks);
+void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks);
 
 /*!
  * \brief Create and potentially persist an object using an available wizard
@@ -720,7 +721,7 @@
  * \param sorcery Pointer to a sorcery structure
  * \param type Type of object to retrieve
  * \param flags Flags to control behavior
- * \param fields Optional jbject fields and values to match against
+ * \param fields Optional object fields and values to match against
  *
  * \retval non-NULL if found
  * \retval NULL if not found

Modified: trunk/main/bucket.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/bucket.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/main/bucket.c (original)
+++ trunk/main/bucket.c Tue Dec  3 11:35:54 2013
@@ -473,7 +473,7 @@
 	return ast_sorcery_observer_add(bucket_sorcery, "bucket", callbacks);
 }
 
-void ast_bucket_observer_remove(struct ast_sorcery_observer *callbacks)
+void ast_bucket_observer_remove(const struct ast_sorcery_observer *callbacks)
 {
 	ast_sorcery_observer_remove(bucket_sorcery, "bucket", callbacks);
 }
@@ -763,7 +763,7 @@
 	return ast_sorcery_observer_add(bucket_sorcery, "file", callbacks);
 }
 
-void ast_bucket_file_observer_remove(struct ast_sorcery_observer *callbacks)
+void ast_bucket_file_observer_remove(const struct ast_sorcery_observer *callbacks)
 {
 	ast_sorcery_observer_remove(bucket_sorcery, "file", callbacks);
 }

Modified: trunk/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/sorcery.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/main/sorcery.c (original)
+++ trunk/main/sorcery.c Tue Dec  3 11:35:54 2013
@@ -1526,6 +1526,7 @@
 {
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 	struct ast_sorcery_object_type_observer *observer;
+	int res;
 
 	if (!object_type || !callbacks) {
 		return -1;
@@ -1536,10 +1537,13 @@
 	}
 
 	observer->callbacks = callbacks;
-	ao2_link(object_type->observers, observer);
+	res = 0;
+	if (!ao2_link(object_type->observers, observer)) {
+		res = -1;
+	}
 	ao2_ref(observer, -1);
 
-	return 0;
+	return res;
 }
 
 /*! \brief Internal callback function for removing an observer */
@@ -1550,13 +1554,19 @@
 	return (observer->callbacks == arg) ? CMP_MATCH | CMP_STOP : 0;
 }
 
-void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, struct ast_sorcery_observer *callbacks)
-{
-	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
-
+void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks)
+{
+	RAII_VAR(struct ast_sorcery_object_type *, object_type, NULL, ao2_cleanup);
+	struct ast_sorcery_observer *cbs = (struct ast_sorcery_observer *) callbacks;/* Remove const for traversal. */
+
+	if (!sorcery) {
+		return;
+	}
+	object_type = ao2_find(sorcery->types, type, OBJ_KEY);
 	if (!object_type) {
 		return;
 	}
 
-	ao2_callback(object_type->observers, OBJ_NODATA | OBJ_UNLINK, sorcery_observer_remove, callbacks);
-}
+	ao2_callback(object_type->observers, OBJ_NODATA | OBJ_UNLINK,
+		sorcery_observer_remove, cbs);
+}

Modified: trunk/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_configuration.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/res/res_pjsip/pjsip_configuration.c (original)
+++ trunk/res/res_pjsip/pjsip_configuration.c Tue Dec  3 11:35:54 2013
@@ -92,7 +92,7 @@
 }
 
 /*! \brief Observer for contacts so state can be updated on respective endpoints */
-static struct ast_sorcery_observer state_contact_observer = {
+static const struct ast_sorcery_observer state_contact_observer = {
 	.created = persistent_endpoint_contact_observer,
 	.deleted = persistent_endpoint_contact_observer,
 };

Modified: trunk/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/pjsip_options.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/res/res_pjsip/pjsip_options.c (original)
+++ trunk/res/res_pjsip/pjsip_options.c Tue Dec  3 11:35:54 2013
@@ -441,7 +441,7 @@
 	}
 }
 
-struct ast_sorcery_observer contact_observer = {
+static const struct ast_sorcery_observer contact_observer = {
 	.created = contact_created,
 	.deleted = contact_deleted
 };

Modified: trunk/res/res_pjsip_registrar_expire.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_registrar_expire.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/res/res_pjsip_registrar_expire.c (original)
+++ trunk/res/res_pjsip_registrar_expire.c Tue Dec  3 11:35:54 2013
@@ -142,7 +142,7 @@
 }
 
 /*! \brief Observer callbacks for autoexpiring contacts */
-static struct ast_sorcery_observer contact_expiration_observer = {
+static const struct ast_sorcery_observer contact_expiration_observer = {
 	.created = contact_expiration_observer_created,
 	.updated = contact_expiration_observer_updated,
 	.deleted = contact_expiration_observer_deleted,

Modified: trunk/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/tests/test_sorcery.c?view=diff&rev=403327&r1=403326&r2=403327
==============================================================================
--- trunk/tests/test_sorcery.c (original)
+++ trunk/tests/test_sorcery.c Tue Dec  3 11:35:54 2013
@@ -227,7 +227,7 @@
 }
 
 /*! \brief Test sorcery observer implementation */
-static struct ast_sorcery_observer test_observer = {
+static const struct ast_sorcery_observer test_observer = {
 	.created = sorcery_observer_created,
 	.updated = sorcery_observer_updated,
 	.deleted = sorcery_observer_deleted,




More information about the asterisk-commits mailing list