MXS-929: Add mapping function for module commands
The modulecmd_foreach function allows commands to be iterated without having to manage the locking of the system. This allows the commands to be easily iterated and gathered into filtered lists without having to build it into the module command system itself.
This commit is contained in:
@ -173,7 +173,7 @@ bool modulecmd_call_command(const MODULECMD *cmd, const MODULECMD_ARG *args);
|
||||
* @brief Set the current error message
|
||||
*
|
||||
* Modules that register commands should use this function to report errors.
|
||||
* This will overwrite the existing error message.
|
||||
* This will overwrite any existing error message.
|
||||
*
|
||||
* @param format Format string
|
||||
* @param ... Format string arguments
|
||||
@ -187,4 +187,31 @@ void modulecmd_set_error(const char *format, ...);
|
||||
*/
|
||||
const char* modulecmd_get_error();
|
||||
|
||||
|
||||
/**
|
||||
* @brief Call a function for each command
|
||||
*
|
||||
* Calls a function for each matching command in the matched domains. The filters
|
||||
* for the domain and identifier are PCRE2 expressions that are matched against
|
||||
* the domain and identifier. These are optional and both @c domain and @c ident
|
||||
* can be NULL.
|
||||
*
|
||||
* @param domain_re Command domain filter, NULL for all domains
|
||||
*
|
||||
* @param ident_re Command identifier filter, NULL for all commands
|
||||
*
|
||||
* @param fn Function that is called for every command. The first parameter is
|
||||
* the current command. The second parameter is the value of @c data.
|
||||
* The function should return true to continue iteration or false to
|
||||
* stop iteration early. The function must not call any of the functions
|
||||
* declared in modulecmd.h.
|
||||
*
|
||||
* @param data User defined data passed as the second parameter to @c fn
|
||||
*
|
||||
* @return True on success, false on PCRE2 error. Use modulecmd_get_error()
|
||||
* to retrieve the error.
|
||||
*/
|
||||
bool modulecmd_foreach(const char *domain_re, const char *ident_re,
|
||||
bool(*fn)(const MODULECMD *cmd, void *data), void *data);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
Reference in New Issue
Block a user