From 36792607d8758ec0c8f1b360f9592d47c09223c8 Mon Sep 17 00:00:00 2001 From: Esa Korhonen Date: Fri, 30 Nov 2018 18:28:29 +0200 Subject: [PATCH] MXS-2205 Combine internal/modules.h with internal/modules.hh --- server/core/authenticator.cc | 2 +- server/core/config.cc | 2 +- server/core/config_runtime.cc | 2 +- server/core/dcb.cc | 2 +- server/core/filter.cc | 2 +- server/core/gateway.cc | 2 +- server/core/internal/modules.h | 158 ------------------ server/core/internal/modules.hh | 139 ++++++++++++++- server/core/modulecmd.cc | 2 +- server/core/monitor.cc | 2 +- server/core/query_classifier.cc | 2 +- server/core/resource.cc | 2 +- server/core/routingworker.cc | 2 +- server/core/server.cc | 2 +- server/core/service.cc | 2 +- server/modules/filter/test/filtermodule.cc | 2 +- server/modules/filter/test/module.cc | 2 +- .../filter/test/queryclassifiermodule.cc | 2 +- .../routing/binlogrouter/test/testbinlog.cc | 2 +- server/modules/routing/debugcli/debugcmd.cc | 2 +- server/modules/routing/maxinfo/maxinfo.cc | 2 +- 21 files changed, 156 insertions(+), 179 deletions(-) delete mode 100644 server/core/internal/modules.h diff --git a/server/core/authenticator.cc b/server/core/authenticator.cc index 6ab1d88e0..eba7bee90 100644 --- a/server/core/authenticator.cc +++ b/server/core/authenticator.cc @@ -15,7 +15,7 @@ #include #include -#include "internal/modules.h" +#include "internal/modules.hh" /** * @file authenticator.c - Authenticator module functions */ diff --git a/server/core/config.cc b/server/core/config.cc index ce416d7ca..4cdebf967 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -61,7 +61,7 @@ #include "internal/config.hh" #include "internal/event.hh" #include "internal/filter.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/monitor.hh" #include "internal/service.hh" diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index e3f297564..acf48c671 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -36,7 +36,7 @@ #include "internal/config.hh" #include "internal/filter.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/monitor.hh" #include "internal/query_classifier.hh" diff --git a/server/core/dcb.cc b/server/core/dcb.cc index d231ca861..85ce34763 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -52,7 +52,7 @@ #include #include -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/session.h" using maxscale::RoutingWorker; diff --git a/server/core/filter.cc b/server/core/filter.cc index d8ad0c6e1..e6f53b274 100644 --- a/server/core/filter.cc +++ b/server/core/filter.cc @@ -39,7 +39,7 @@ #include #include "internal/config.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/service.hh" using std::string; diff --git a/server/core/gateway.cc b/server/core/gateway.cc index 22b58ec79..2df4f4a86 100644 --- a/server/core/gateway.cc +++ b/server/core/gateway.cc @@ -67,7 +67,7 @@ #include "internal/admin.hh" #include "internal/config.hh" #include "internal/maxscale.h" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/monitor.hh" #include "internal/poll.hh" #include "internal/service.hh" diff --git a/server/core/internal/modules.h b/server/core/internal/modules.h deleted file mode 100644 index e65942381..000000000 --- a/server/core/internal/modules.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright (c) 2018 MariaDB Corporation Ab - * - * Use of this software is governed by the Business Source License included - * in the LICENSE.TXT file and at www.mariadb.com/bsl11. - * - * Change Date: 2022-01-01 - * - * On the date above, in accordance with the Business Source License, use - * of this software will be governed by version 2 or later of the General - * Public License. - */ -#pragma once - -/** - * @file modules.h Utilities for loading modules - */ - -#include -#include -#include - -MXS_BEGIN_DECLS - -/** - * Module types - */ -#define MODULE_PROTOCOL "Protocol" /**< A protocol module type */ -#define MODULE_AUTHENTICATOR "Authenticator" /**< An authenticator module type */ -#define MODULE_ROUTER "Router" /**< A router module type */ -#define MODULE_MONITOR "Monitor" /**< A database monitor module type */ -#define MODULE_FILTER "Filter" /**< A filter module type */ -#define MODULE_QUERY_CLASSIFIER "QueryClassifier" /**< A query classifier module type */ - - -/** - *@brief Load a module - * - * @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); - -/** - * @brief Get a module - * - * @param name Name of the module - * @param type The module type or NULL for any type - * @return The loaded module or NULL if the module is not loaded - */ -const MXS_MODULE* get_module(const char* name, const char* type); - -/** - * @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*); - -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); - -/** - * @brief Convert module to JSON - * - * @param module Module to convert - * @param host Hostname of this server - * - * @return The module in JSON format - */ -json_t* module_to_json(const MXS_MODULE* module, const char* host); - -/** - * @brief Convert all modules to JSON - * - * @param host The hostname of this server - * - * @return Array of modules in JSON format - */ -json_t* module_list_to_json(const char* host); - -/** - * @brief Return effective module name. - * - * The effective module name is the actual name of a module. In case - * a module has been renamed (and the old name deprecated), the effective - * name of a module may be different from the used one. - * - * @param name The name of a module. - * - * @return The effective name (may be the same). - */ -const char* mxs_module_get_effective_name(const char* name); - -MXS_END_DECLS diff --git a/server/core/internal/modules.hh b/server/core/internal/modules.hh index afa2f51dc..48aed7ee1 100644 --- a/server/core/internal/modules.hh +++ b/server/core/internal/modules.hh @@ -12,13 +12,148 @@ */ #pragma once -#include "modules.h" - +#include +#include +#include #include +/* Module types */ +#define MODULE_PROTOCOL "Protocol" /**< A protocol module type */ +#define MODULE_AUTHENTICATOR "Authenticator" /**< An authenticator module type */ +#define MODULE_ROUTER "Router" /**< A router module type */ +#define MODULE_MONITOR "Monitor" /**< A database monitor module type */ +#define MODULE_FILTER "Filter" /**< A filter module type */ +#define MODULE_QUERY_CLASSIFIER "QueryClassifier" /**< A query classifier module type */ + /** * @brief Return a resultset that has the current set of modules in it * * @return A Result set */ std::unique_ptr moduleGetList(); + +MXS_BEGIN_DECLS + +/** + *@brief Load a module + * + * @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); + +/** + * @brief Get a module + * + * @param name Name of the module + * @param type The module type or NULL for any type + * @return The loaded module or NULL if the module is not loaded + */ +const MXS_MODULE* get_module(const char* name, const char* type); + +/** + * @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*); + +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); + +/** + * @brief Convert module to JSON + * + * @param module Module to convert + * @param host Hostname of this server + * + * @return The module in JSON format + */ +json_t* module_to_json(const MXS_MODULE* module, const char* host); + +/** + * @brief Convert all modules to JSON + * + * @param host The hostname of this server + * + * @return Array of modules in JSON format + */ +json_t* module_list_to_json(const char* host); + +/** + * @brief Return effective module name. + * + * The effective module name is the actual name of a module. In case + * a module has been renamed (and the old name deprecated), the effective + * name of a module may be different from the used one. + * + * @param name The name of a module. + * + * @return The effective name (may be the same). + */ +const char* mxs_module_get_effective_name(const char* name); + +MXS_END_DECLS diff --git a/server/core/modulecmd.cc b/server/core/modulecmd.cc index 0aeef1331..5b13dac46 100644 --- a/server/core/modulecmd.cc +++ b/server/core/modulecmd.cc @@ -20,7 +20,7 @@ #include #include "internal/filter.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/monitor.hh" /** Size of the error buffer */ diff --git a/server/core/monitor.cc b/server/core/monitor.cc index cee9c28bf..d271a0a33 100644 --- a/server/core/monitor.cc +++ b/server/core/monitor.cc @@ -47,7 +47,7 @@ #include "internal/config.hh" #include "internal/externcmd.hh" #include "internal/monitor.hh" -#include "internal/modules.h" +#include "internal/modules.hh" /** Schema version, journals must have a matching version */ #define MMB_SCHEMA_VERSION 2 diff --git a/server/core/query_classifier.cc b/server/core/query_classifier.cc index 93f111cbe..79bbde5ab 100644 --- a/server/core/query_classifier.cc +++ b/server/core/query_classifier.cc @@ -30,7 +30,7 @@ #include #include "internal/config_runtime.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/trxboundaryparser.hh" // #define QC_TRACE_ENABLED diff --git a/server/core/resource.cc b/server/core/resource.cc index 2b623c8cd..7fd1711fb 100644 --- a/server/core/resource.cc +++ b/server/core/resource.cc @@ -30,7 +30,7 @@ #include "internal/filter.hh" #include "internal/httprequest.hh" #include "internal/httpresponse.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/monitor.hh" #include "internal/query_classifier.hh" #include "internal/service.hh" diff --git a/server/core/routingworker.cc b/server/core/routingworker.cc index 4047edee4..7876d531c 100644 --- a/server/core/routingworker.cc +++ b/server/core/routingworker.cc @@ -35,7 +35,7 @@ #include #include "internal/dcb.h" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/poll.hh" #include "internal/service.hh" diff --git a/server/core/server.cc b/server/core/server.cc index 98f4a7d38..b6fae968f 100644 --- a/server/core/server.cc +++ b/server/core/server.cc @@ -55,7 +55,7 @@ #include "internal/poll.hh" #include "internal/config.hh" #include "internal/service.hh" -#include "internal/modules.h" +#include "internal/modules.hh" using maxbase::Worker; diff --git a/server/core/service.cc b/server/core/service.cc index 0f7178b6c..94a328213 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -59,7 +59,7 @@ #include "internal/config.hh" #include "internal/filter.hh" -#include "internal/modules.h" +#include "internal/modules.hh" #include "internal/service.hh" #include "internal/maxscale.h" diff --git a/server/modules/filter/test/filtermodule.cc b/server/modules/filter/test/filtermodule.cc index d70c0dbc4..231fbcadd 100644 --- a/server/modules/filter/test/filtermodule.cc +++ b/server/modules/filter/test/filtermodule.cc @@ -13,7 +13,7 @@ #include #include "maxscale/filtermodule.hh" -#include "../../../core/internal/modules.h" +#include "../../../core/internal/modules.hh" using std::auto_ptr; diff --git a/server/modules/filter/test/module.cc b/server/modules/filter/test/module.cc index c5773d1c9..39afa671d 100644 --- a/server/modules/filter/test/module.cc +++ b/server/modules/filter/test/module.cc @@ -13,7 +13,7 @@ #include "maxscale/module.hh" #include -#include "../../../core/internal/modules.h" +#include "../../../core/internal/modules.hh" using std::auto_ptr; diff --git a/server/modules/filter/test/queryclassifiermodule.cc b/server/modules/filter/test/queryclassifiermodule.cc index 6271d203c..a0dc191ae 100644 --- a/server/modules/filter/test/queryclassifiermodule.cc +++ b/server/modules/filter/test/queryclassifiermodule.cc @@ -12,7 +12,7 @@ */ #include "maxscale/queryclassifiermodule.hh" -#include "../../../core/internal/modules.h" +#include "../../../core/internal/modules.hh" namespace maxscale { diff --git a/server/modules/routing/binlogrouter/test/testbinlog.cc b/server/modules/routing/binlogrouter/test/testbinlog.cc index af4fbf232..24e215861 100644 --- a/server/modules/routing/binlogrouter/test/testbinlog.cc +++ b/server/modules/routing/binlogrouter/test/testbinlog.cc @@ -39,7 +39,7 @@ #include #include #include -#include "../../../../core/internal/modules.h" +#include "../../../../core/internal/modules.hh" #include "../../../../core/internal/config.hh" #include diff --git a/server/modules/routing/debugcli/debugcmd.cc b/server/modules/routing/debugcli/debugcmd.cc index a7ed96b81..228a56dc8 100644 --- a/server/modules/routing/debugcli/debugcmd.cc +++ b/server/modules/routing/debugcli/debugcmd.cc @@ -59,7 +59,7 @@ #include "../../../core/internal/config.hh" #include "../../../core/internal/config_runtime.hh" #include "../../../core/internal/maxscale.h" -#include "../../../core/internal/modules.h" +#include "../../../core/internal/modules.hh" #include "../../../core/internal/monitor.hh" #include "../../../core/internal/poll.hh" #include "../../../core/internal/session.h" diff --git a/server/modules/routing/maxinfo/maxinfo.cc b/server/modules/routing/maxinfo/maxinfo.cc index bf76583c0..e784b0e4d 100644 --- a/server/modules/routing/maxinfo/maxinfo.cc +++ b/server/modules/routing/maxinfo/maxinfo.cc @@ -51,7 +51,7 @@ #include #include -#include "../../../core/internal/modules.h" +#include "../../../core/internal/modules.hh" #include "../../../core/internal/monitor.hh" #include "../../../core/internal/session.h" #include "../../../core/internal/session.hh"