Provide read-only access to loaded modules

The MXS_MODULE structure of each module is now globally exposed by the
`get_module` function. This allows the module information of any module to
be queried.

This information can then be used to validate various things but the main
goal is to provide a way for modules to declare accepted parameters in the
MXS_MODULE structure. This will be done in a later commit.

Also the function documentation is now in the header file. This should
make it easier to read.
This commit is contained in:
Markus Mäkelä
2017-01-04 07:36:47 +02:00
parent 0215ad32a1
commit 33d98830dd
2 changed files with 81 additions and 77 deletions

View File

@ -50,13 +50,74 @@ MXS_BEGIN_DECLS
#define MODULE_QUERY_CLASSIFIER "QueryClassifier" /**< A query classifier module type */ #define MODULE_QUERY_CLASSIFIER "QueryClassifier" /**< A query classifier module type */
extern void *load_module(const char *module, const char *type); /**
extern void unload_module(const char *module); *@brief Load a module
extern void unload_all_modules(); *
extern void printModules(); * @param module Name of the module to load
extern void dprintAllModules(DCB *); * @param type Type of module, used purely for registration
extern RESULTSET *moduleGetList(); * @return The module specific entry point structure or NULL
extern void module_feedback_send(void*); */
extern void moduleShowFeedbackReport(DCB *dcb); void *load_module(const char *module, const char *type);
/**
* @brief Get a module
*
* @param name Name of the module
* @return The loaded module or NULL if the module is not loaded
*/
const MXS_MODULE *get_module(const char *name);
/**
* @brief Unload a module.
*
* No errors are returned since it is not clear that much can be done
* to fix issues relating to unloading modules.
*
* @param module The name of the module
*/
void unload_module(const char *module);
/**
* @brief Unload all modules
*
* Remove all the modules from the system, called during shutdown
* to allow termination hooks to be called.
*/
void unload_all_modules();
/**
* @brief Print Modules
*
* Diagnostic routine to display all the loaded modules
*/
void printModules();
/**
* @brief Print Modules to a DCB
*
* Diagnostic routine to display all the loaded modules
*/
void dprintAllModules(DCB *);
/**
* @brief Return a resultset that has the current set of modules in it
*
* @return A Result set
*/
RESULTSET *moduleGetList();
/**
* @brief Send loaded modules info to notification service
*
* @param data The configuration details of notification service
*/
void module_feedback_send(void*);
/**
* @brief Show feedback report
*
* Prints the feedback report to a DCB
*/
void moduleShowFeedbackReport(DCB *dcb);
MXS_END_DECLS MXS_END_DECLS

View File

@ -159,22 +159,6 @@ static bool check_module(const MXS_MODULE *mod_info, const char *type, const cha
return success; return success;
} }
/**
* Load the dynamic library related to a gateway module. The routine
* will look for library files in the current directory,
* the configured folder and /usr/lib64/maxscale.
*
* Note that a number of entry points are standard for any module, as is
* the data structure named "info". They are only accessed by explicit
* reference to the module, and so the fact that they are duplicated in
* every module is not a problem. The declarations are protected from
* lint by suppressing error 14, since the duplication is a feature and
* not an error.
*
* @param module Name of the module to load
* @param type Type of module, used purely for registration
* @return The module specific entry point structure or NULL
*/
void *load_module(const char *module, const char *type) void *load_module(const char *module, const char *type)
{ {
ss_dassert(module && type); ss_dassert(module && type);
@ -232,16 +216,7 @@ void *load_module(const char *module, const char *type)
return mod->modobj; return mod->modobj;
} }
/** void unload_module(const char *module)
* Unload a module.
*
* No errors are returned since it is not clear that much can be done
* to fix issues relating to unloading modules.
*
* @param module The name of the module
*/
void
unload_module(const char *module)
{ {
LOADED_MODULE *mod = find_module(module); LOADED_MODULE *mod = find_module(module);
@ -372,14 +347,7 @@ unregister_module(const char *module)
MXS_FREE(mod); MXS_FREE(mod);
} }
/** void unload_all_modules()
* Unload all modules
*
* Remove all the modules from the system, called during shutdown
* to allow termination hooks to be called.
*/
void
unload_all_modules()
{ {
while (registered) while (registered)
{ {
@ -387,13 +355,7 @@ unload_all_modules()
} }
} }
/** void printModules()
* Print Modules
*
* Diagnostic routine to display all the loaded modules
*/
void
printModules()
{ {
LOADED_MODULE *ptr = registered; LOADED_MODULE *ptr = registered;
@ -406,13 +368,7 @@ printModules()
} }
} }
/** void dprintAllModules(DCB *dcb)
* Print Modules to a DCB
*
* Diagnostic routine to display all the loaded modules
*/
void
dprintAllModules(DCB *dcb)
{ {
LOADED_MODULE *ptr = registered; LOADED_MODULE *ptr = registered;
@ -444,13 +400,7 @@ dprintAllModules(DCB *dcb)
dcb_printf(dcb, "----------------+-----------------+---------+-------+-------------------------\n\n"); dcb_printf(dcb, "----------------+-----------------+---------+-------+-------------------------\n\n");
} }
/** void moduleShowFeedbackReport(DCB *dcb)
* Print Modules to a DCB
*
* Diagnostic routine to display all the loaded modules
*/
void
moduleShowFeedbackReport(DCB *dcb)
{ {
GWBUF *buffer; GWBUF *buffer;
LOADED_MODULE *modules_list = registered; LOADED_MODULE *modules_list = registered;
@ -516,13 +466,7 @@ moduleRowCallback(RESULTSET *set, void *data)
return row; return row;
} }
/** RESULTSET *moduleGetList()
* Return a resultset that has the current set of modules in it
*
* @return A Result set
*/
RESULTSET *
moduleGetList()
{ {
RESULTSET *set; RESULTSET *set;
int *data; int *data;
@ -546,13 +490,7 @@ moduleGetList()
return set; return set;
} }
/** void module_feedback_send(void* data)
* Send loaded modules info to notification service
*
* @param data The configuration details of notification service
*/
void
module_feedback_send(void* data)
{ {
LOADED_MODULE *modules_list = registered; LOADED_MODULE *modules_list = registered;
CURL *curl = NULL; CURL *curl = NULL;
@ -900,3 +838,8 @@ cleanup:
return ret_code; return ret_code;
} }
const MXS_MODULE *get_module(const char *name)
{
LOADED_MODULE *mod = find_module(name);
return mod ? mod->info : NULL;
}