mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-29 18:19:30 +00:00
sorcery: Add API to insert/remove a wizard to/from an object type's list
Currently you can 'apply' a wizard to an object type but the wizard always goes at the end of the object type's wizard list. This patch adds a new ast_sorcery_insert_wizard_mapping function that allows you to insert a wizard anyplace in the list. I.E. You could add a caching wizard to an object type and place it before all wizards. ast_sorcery_get_wizard_mapping_count and ast_sorcery_get_wizard_mapping were added to allow examination of the mapping list. ast_sorcery_remove_mapping was added to remove a mapping by name. As part of this patch, the object type's wizard list was converted from an ao2_container to an AST_VECTOR_RW. A new test was added to test_sorcery for this capability. ASTERISK-25044 #close Change-Id: I9d2469a9296b2698082c0989e25e6848dc403b57
This commit is contained in:
@@ -497,6 +497,125 @@ enum ast_sorcery_apply_result __ast_sorcery_apply_wizard_mapping(struct ast_sorc
|
||||
#define ast_sorcery_apply_wizard_mapping(sorcery, type, name, data, caching) \
|
||||
__ast_sorcery_apply_wizard_mapping((sorcery), (type), AST_MODULE, (name), (data), (caching));
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Pre-defined locations to insert at
|
||||
*/
|
||||
enum ast_sorcery_wizard_position {
|
||||
AST_SORCERY_WIZARD_POSITION_LAST = -1,
|
||||
AST_SORCERY_WIZARD_POSITION_FIRST = 0,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Insert an additional object wizard mapping at a specific position
|
||||
* in the wizard list
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object to apply to
|
||||
* \param module The name of the module, typically AST_MODULE
|
||||
* \param name Name of the wizard to use
|
||||
* \param data Data to be passed to wizard
|
||||
* \param caching Wizard should cache
|
||||
* \param position An index to insert to or one of ast_sorcery_wizard_position
|
||||
*
|
||||
* \return What occurred when applying the mapping
|
||||
*
|
||||
* \note This should be called *after* applying default mappings
|
||||
* \note Wizards can be retrieved by using ast_sorcery_get_wizard_mapping_count
|
||||
* and iterating over them using ast_sorcery_get_wizard_mapping.
|
||||
*
|
||||
* \since 13.4.0
|
||||
*/
|
||||
enum ast_sorcery_apply_result __ast_sorcery_insert_wizard_mapping(struct ast_sorcery *sorcery,
|
||||
const char *type, const char *module, const char *name, const char *data,
|
||||
unsigned int caching, int position);
|
||||
|
||||
/*!
|
||||
* \brief Insert an additional object wizard mapping at a specific position
|
||||
* in the wizard list
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object to apply to
|
||||
* \param module The name of the module, typically AST_MODULE
|
||||
* \param name Name of the wizard to use
|
||||
* \param data Data to be passed to wizard
|
||||
* \param position One of ast_sorcery_wizard_position
|
||||
*
|
||||
* \return What occurred when applying the mapping
|
||||
*
|
||||
* \note This should be called *after* applying default mappings
|
||||
* \since 13.4.0
|
||||
*/
|
||||
#define ast_sorcery_insert_wizard_mapping(sorcery, type, name, data, caching, position) \
|
||||
__ast_sorcery_insert_wizard_mapping((sorcery), (type), AST_MODULE, (name), (data), \
|
||||
(caching), (position))
|
||||
|
||||
/*!
|
||||
* \brief Remove an object wizard mapping
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object to remove from
|
||||
* \param module The name of the module, typically AST_MODULE
|
||||
* \param name The name of the wizard to remove
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*
|
||||
* \since 13.4.0
|
||||
*/
|
||||
int __ast_sorcery_remove_wizard_mapping(struct ast_sorcery *sorcery,
|
||||
const char *type, const char *module, const char *name);
|
||||
|
||||
/*!
|
||||
* \brief Remove an object wizard mapping
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object to remove from
|
||||
* \param name The name of the wizard to remove
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*
|
||||
* \since 13.4.0
|
||||
*/
|
||||
#define ast_sorcery_remove_wizard_mapping(sorcery, type, name) \
|
||||
__ast_sorcery_remove_wizard_mapping((sorcery), (type), AST_MODULE, (name))
|
||||
|
||||
/*!
|
||||
* \brief Return the number of wizards mapped to an object type
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object
|
||||
*
|
||||
* \return Number of wizards or -1 for error
|
||||
* \since 13.4.0
|
||||
*/
|
||||
int ast_sorcery_get_wizard_mapping_count(struct ast_sorcery *sorcery,
|
||||
const char *type);
|
||||
|
||||
/*!
|
||||
* \brief By index, return a wizard mapped to an object type
|
||||
*
|
||||
* \param sorcery Pointer to a sorcery structure
|
||||
* \param type Type of object
|
||||
* \param index Index of the wizard
|
||||
* \param wizard A pointer to receive the wizard pointer
|
||||
* \param data A pointer to receive the data pointer
|
||||
*
|
||||
* \retval 0 success
|
||||
* \retval -1 failure
|
||||
*
|
||||
* \warning The wizard will have its reference count bumped so you must
|
||||
* call ao2_cleanup when you're done with it.
|
||||
*
|
||||
* \note The wizard and data returned are valid only for this object type
|
||||
* and only while the wizard is applied to the object type.
|
||||
*
|
||||
* \since 13.4.0
|
||||
*/
|
||||
int ast_sorcery_get_wizard_mapping(struct ast_sorcery *sorcery,
|
||||
const char *type, int index, struct ast_sorcery_wizard **wizard, void **data);
|
||||
|
||||
/*!
|
||||
* \brief Register an object type
|
||||
*
|
||||
|
Reference in New Issue
Block a user