summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2013-05-06 13:04:08 +0000
committerJoshua Colp <jcolp@digium.com>2013-05-06 13:04:08 +0000
commit40074542bf517a751061d7cf6f9ff83431e35ff8 (patch)
tree8e7d52a4c65363e0d4cbd8effd83995ac3bfa892 /include
parent6e2fe0c9ab1ec9cdd0d45e48fd03217d06cc17ae (diff)
Add support for observers and JSON objectset creation to sorcery.
This change adds the ability for modules to add themselves as observers to sorcery object types. Observers can be notified when objects are created, updated, or deleted as well as when the object type is loaded or reloaded. Observer notifications are done using a thread pool in a serialized fashion so the caller of the sorcery API calls is minimally impacted. This also adds the ability to create JSON changesets of a sorcery object. Tests are also present to confirm all of the above functionality. Review: https://reviewboard.asterisk.org/r/2477/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@387662 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include')
-rw-r--r--include/asterisk/sorcery.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/asterisk/sorcery.h b/include/asterisk/sorcery.h
index 434f5595a..ae97da5cc 100644
--- a/include/asterisk/sorcery.h
+++ b/include/asterisk/sorcery.h
@@ -232,6 +232,21 @@ struct ast_sorcery_wizard {
void (*close)(void *data);
};
+/*! \brief Interface for a sorcery object type observer */
+struct ast_sorcery_observer {
+ /*! \brief Callback for when an object is created */
+ void (*created)(const void *object);
+
+ /*! \brief Callback for when an object is updated */
+ void (*updated)(const void *object);
+
+ /*! \brief Callback for when an object is deleted */
+ void (*deleted)(const void *object);
+
+ /*! \brief Callback for when an object type is loaded/reloaded */
+ void (*loaded)(const char *object_type);
+};
+
/*! \brief Structure which contains details about a sorcery object */
struct ast_sorcery_object_details {
/*! \brief Unique identifier of this object */
@@ -472,6 +487,19 @@ void ast_sorcery_ref(struct ast_sorcery *sorcery);
struct ast_variable *ast_sorcery_objectset_create(const struct ast_sorcery *sorcery, const void *object);
/*!
+ * \brief Create an object set in JSON format for an object
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param object Pointer to a sorcery object
+ *
+ * \retval non-NULL success
+ * \retval NULL if error occurred
+ *
+ * \note The returned ast_json object must be unreferenced using ast_json_unref
+ */
+struct ast_json *ast_sorcery_objectset_json_create(const struct ast_sorcery *sorcery, const void *object);
+
+/*!
* \brief Apply an object set (KVP list) to an object
*
* \param sorcery Pointer to a sorcery structure
@@ -541,6 +569,30 @@ void *ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object);
int ast_sorcery_diff(const struct ast_sorcery *sorcery, const void *original, const void *modified, struct ast_variable **changes);
/*!
+ * \brief Add an observer to a specific object type
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param type Type of object that should be observed
+ * \param callbacks Implementation of the observer interface
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+int ast_sorcery_observer_add(const struct ast_sorcery *sorcery, const char *type, const struct ast_sorcery_observer *callbacks);
+
+/*!
+ * \brief Remove an observer from a specific object type
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param type Type of object that should no longer be observed
+ * \param callbacks Implementation of the observer interface
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
+void ast_sorcery_observer_remove(const struct ast_sorcery *sorcery, const char *type, struct ast_sorcery_observer *callbacks);
+
+/*!
* \brief Create and potentially persist an object using an available wizard
*
* \param sorcery Pointer to a sorcery structure