Provide access to modules
With the provided functions it is possible to iterate over all loaded modules or over all modules of a specific type.
This commit is contained in:
@ -121,4 +121,44 @@ void module_feedback_send(void*);
|
|||||||
*/
|
*/
|
||||||
void moduleShowFeedbackReport(DCB *dcb);
|
void moduleShowFeedbackReport(DCB *dcb);
|
||||||
|
|
||||||
|
typedef struct mxs_module_iterator
|
||||||
|
{
|
||||||
|
const char* type;
|
||||||
|
void* position;
|
||||||
|
} MXS_MODULE_ITERATOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns an iterator to modules.
|
||||||
|
*
|
||||||
|
* @attention It is unspecified whether a module loaded after the iterator
|
||||||
|
* was created, will be returned by the iterator. The behaviour
|
||||||
|
* is undefined if a module is unloaded while an iteration is
|
||||||
|
* being performed.
|
||||||
|
*
|
||||||
|
* @param type The type of modules that should be returned. If NULL,
|
||||||
|
* then all modules are returned.
|
||||||
|
*
|
||||||
|
* @return An iterator.
|
||||||
|
*/
|
||||||
|
MXS_MODULE_ITERATOR mxs_module_iterator_get(const char* type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Indicates whether the iterator has a module to return.
|
||||||
|
*
|
||||||
|
* @param iterator An iterator
|
||||||
|
*
|
||||||
|
* @return True if a subsequent call to @c mxs_module_iterator_get
|
||||||
|
* will return a module.
|
||||||
|
*/
|
||||||
|
bool mxs_module_iterator_has_next(const MXS_MODULE_ITERATOR* iterator);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the next module and advances the iterator.
|
||||||
|
*
|
||||||
|
* @param iterator An iterator.
|
||||||
|
*
|
||||||
|
* @return A module if there was a module to return, NULL otherwise.
|
||||||
|
*/
|
||||||
|
MXS_MODULE* mxs_module_iterator_get_next(MXS_MODULE_ITERATOR* iterator);
|
||||||
|
|
||||||
MXS_END_DECLS
|
MXS_END_DECLS
|
||||||
|
@ -849,3 +849,45 @@ const MXS_MODULE *get_module(const char *name, const char *type)
|
|||||||
|
|
||||||
return mod ? mod->info : NULL;
|
return mod ? mod->info : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MXS_MODULE_ITERATOR mxs_module_iterator_get(const char* type)
|
||||||
|
{
|
||||||
|
LOADED_MODULE* module = registered;
|
||||||
|
|
||||||
|
while (module && type && (strcmp(module->type, type) != 0))
|
||||||
|
{
|
||||||
|
module = module->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
MXS_MODULE_ITERATOR iterator;
|
||||||
|
iterator.type = type;
|
||||||
|
iterator.position = module;
|
||||||
|
|
||||||
|
return iterator;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool mxs_module_iterator_has_next(const MXS_MODULE_ITERATOR* iterator)
|
||||||
|
{
|
||||||
|
return iterator->position != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
MXS_MODULE* mxs_module_iterator_get_next(MXS_MODULE_ITERATOR* iterator)
|
||||||
|
{
|
||||||
|
MXS_MODULE* module = NULL;
|
||||||
|
LOADED_MODULE* loaded_module = (LOADED_MODULE*)iterator->position;
|
||||||
|
|
||||||
|
if (loaded_module)
|
||||||
|
{
|
||||||
|
module = loaded_module->info;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
loaded_module = loaded_module->next;
|
||||||
|
}
|
||||||
|
while (loaded_module && iterator->type && (strcmp(loaded_module->type, iterator->type) != 0));
|
||||||
|
|
||||||
|
iterator->position = loaded_module;
|
||||||
|
}
|
||||||
|
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user