mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-20 08:40:16 +00:00
sorcery: Add support for object staleness
This patch enhances the sorcery API to allow for sorcery wizards to determine if an object is stale. This includes the following: * Sorcery objects now have a timestamp that is set on creation. Since sorcery objects are immutable, this can be used by sorcery wizards to determine if an object is stale. * A new API call has been added, ast_sorcery_is_stale. This API call queries the wizards associated with the object, calling a new callback function 'is_stale'. Note that if a wizard does not support the new callback, objects are always assumed to not be stale. * Unit tests have been added that cover the new API call. Change-Id: Ica93c6a4e8a06c0376ea43e00cf702920b806064
This commit is contained in:
@@ -312,6 +312,9 @@ struct ast_sorcery_wizard {
|
||||
|
||||
/*! \brief Callback for closing a wizard */
|
||||
void (*close)(void *data);
|
||||
|
||||
/* \brief Callback for whether or not the wizard believes the object is stale */
|
||||
int (*is_stale)(const struct ast_sorcery *sorcery, void *data, void *object);
|
||||
};
|
||||
|
||||
/*! \brief Interface for a sorcery object type observer */
|
||||
@@ -1201,6 +1204,20 @@ int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object);
|
||||
*/
|
||||
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object);
|
||||
|
||||
/*!
|
||||
* \brief Determine if a sorcery object is stale with respect to its backing datastore
|
||||
* \since 14.0.0
|
||||
*
|
||||
* This function will query the wizard(s) backing the particular sorcery object to
|
||||
* determine if the in-memory object is now stale. No action is taken to update
|
||||
* the object. Callers of this function may use one of the ast_sorcery_retrieve
|
||||
* functions to obtain a new instance of the object if desired.
|
||||
*
|
||||
* \retval 0 the object is not stale
|
||||
* \retval 1 the object is stale
|
||||
*/
|
||||
int ast_sorcery_is_stale(const struct ast_sorcery *sorcery, void *object);
|
||||
|
||||
/*!
|
||||
* \brief Decrease the reference count of a sorcery structure
|
||||
*
|
||||
@@ -1217,6 +1234,16 @@ void ast_sorcery_unref(struct ast_sorcery *sorcery);
|
||||
*/
|
||||
const char *ast_sorcery_object_get_id(const void *object);
|
||||
|
||||
/*!
|
||||
* \since 14.0.0
|
||||
* \brief Get when the socery object was created
|
||||
*
|
||||
* \param object Pointer to a sorcery object
|
||||
*
|
||||
* \retval The time when the object was created
|
||||
*/
|
||||
const struct timeval ast_sorcery_object_get_created(const void *object);
|
||||
|
||||
/*!
|
||||
* \brief Get the type of a sorcery object
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user