[asterisk-commits] rmudgett: branch 12 r403324 - in /branches/12: include/asterisk/ main/ res/ r...

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


Author: rmudgett
Date: Tue Dec  3 11:23:50 2013
New Revision: 403324

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=403324
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.

Modified:
    branches/12/include/asterisk/bucket.h
    branches/12/include/asterisk/sorcery.h
    branches/12/main/bucket.c
    branches/12/main/sorcery.c
    branches/12/res/res_pjsip/pjsip_configuration.c
    branches/12/res/res_pjsip/pjsip_options.c
    branches/12/res/res_pjsip_registrar_expire.c
    branches/12/tests/test_sorcery.c

Modified: branches/12/include/asterisk/bucket.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/bucket.h?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/include/asterisk/bucket.h (original)
+++ branches/12/include/asterisk/bucket.h Tue Dec  3 11:23:50 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: branches/12/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/branches/12/include/asterisk/sorcery.h?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/include/asterisk/sorcery.h (original)
+++ branches/12/include/asterisk/sorcery.h Tue Dec  3 11:23:50 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: branches/12/main/bucket.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/bucket.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/main/bucket.c (original)
+++ branches/12/main/bucket.c Tue Dec  3 11:23:50 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: branches/12/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/main/sorcery.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/main/sorcery.c (original)
+++ branches/12/main/sorcery.c Tue Dec  3 11:23:50 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: branches/12/res/res_pjsip/pjsip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_configuration.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/res/res_pjsip/pjsip_configuration.c (original)
+++ branches/12/res/res_pjsip/pjsip_configuration.c Tue Dec  3 11:23:50 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: branches/12/res/res_pjsip/pjsip_options.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/pjsip_options.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/res/res_pjsip/pjsip_options.c (original)
+++ branches/12/res/res_pjsip/pjsip_options.c Tue Dec  3 11:23:50 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: branches/12/res/res_pjsip_registrar_expire.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_registrar_expire.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/res/res_pjsip_registrar_expire.c (original)
+++ branches/12/res/res_pjsip_registrar_expire.c Tue Dec  3 11:23:50 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: branches/12/tests/test_sorcery.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/tests/test_sorcery.c?view=diff&rev=403324&r1=403323&r2=403324
==============================================================================
--- branches/12/tests/test_sorcery.c (original)
+++ branches/12/tests/test_sorcery.c Tue Dec  3 11:23:50 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