Change parameters in dump_param

Putting the file descriptor first keeps it in line with dprintf.

Making the parameter set an initializer list allows matching against
multiple sets of parameters in one function call. This will compact the
parameter serialization by using the same code for the common service
parameters and the module parameters.
This commit is contained in:
Markus Mäkelä 2018-08-15 22:44:33 +03:00
parent 355768c564
commit 3c20b47a8d
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 24 additions and 18 deletions

View File

@ -19,6 +19,7 @@
#include <maxscale/config.h>
#include <sstream>
#include <initializer_list>
#include <maxbase/jansson.h>
#include <maxscale/ssl.h>
@ -239,13 +240,13 @@ void dump_if_changed(const MXS_MODULE_PARAM* params, int file,
* Note: Does not work with enum type parameters, they'll get converted into
* integers. Convert them to string format at the call site.
*
* @param params Module parameter to use
* @param file File descriptor where the line is written
* @param key Name of the parameter
* @param value The parameter value
* @param params List of module parameters to use
*/
template <class T>
inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::string& key, const T value)
inline void dump_param(int file, const std::string& key, const T value, std::initializer_list<const MXS_MODULE_PARAM*> params)
{
std::stringstream ss;
ss << value;
@ -254,7 +255,10 @@ inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::stri
if (!strval.empty())
{
// Don't dump empty values
dump_if_changed(params, file, key, strval);
for (auto a : params)
{
dump_if_changed(a, file, key, strval);
}
}
}
@ -262,9 +266,12 @@ inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::stri
// the defaults. This requires that all defaults use either "true" or "false"
// for the values.
template <>
inline void dump_param(const MXS_MODULE_PARAM* params, int file, const std::string& key, bool value)
inline void dump_param(int file, const std::string& key, bool value, std::initializer_list<const MXS_MODULE_PARAM*> params)
{
dump_if_changed(params, file, key, value ? "true" : "false");
for (auto a : params)
{
dump_if_changed(a, file, key, value ? "true" : "false");
}
}
}

View File

@ -1785,17 +1785,17 @@ bool Service::dump_config(const char *filename) const
const MXS_MODULE_PARAM* mp = config_service_params;
dump_param(mp, file, CN_ENABLE_ROOT_USER, enable_root);
dump_param(mp, file, CN_MAX_RETRY_INTERVAL, max_retry_interval);
dump_param(mp, file, CN_MAX_CONNECTIONS, max_connections);
dump_param(mp, file, CN_CONNECTION_TIMEOUT, conn_idle_timeout);
dump_param(mp, file, CN_AUTH_ALL_SERVERS, users_from_all);
dump_param(mp, file, CN_STRIP_DB_ESC, strip_db_esc);
dump_param(mp, file, CN_LOCALHOST_MATCH_WILDCARD_HOST, localhost_match_wildcard_host);
dump_param(mp, file, CN_LOG_AUTH_WARNINGS, log_auth_warnings);
dump_param(mp, file, CN_RETRY_ON_FAILURE, retry_start);
dump_param(mp, file, CN_VERSION_STRING, m_version_string);
dump_param(mp, file, CN_WEIGHTBY, m_weightby);
dump_param(file, CN_ENABLE_ROOT_USER, enable_root, {mp});
dump_param(file, CN_MAX_RETRY_INTERVAL, max_retry_interval, {mp});
dump_param(file, CN_MAX_CONNECTIONS, max_connections, {mp});
dump_param(file, CN_CONNECTION_TIMEOUT, conn_idle_timeout, {mp});
dump_param(file, CN_AUTH_ALL_SERVERS, users_from_all, {mp});
dump_param(file, CN_STRIP_DB_ESC, strip_db_esc, {mp});
dump_param(file, CN_LOCALHOST_MATCH_WILDCARD_HOST, localhost_match_wildcard_host, {mp});
dump_param(file, CN_LOG_AUTH_WARNINGS, log_auth_warnings, {mp});
dump_param(file, CN_RETRY_ON_FAILURE, retry_start, {mp});
dump_param(file, CN_VERSION_STRING, m_version_string, {mp});
dump_param(file, CN_WEIGHTBY, m_weightby, {mp});
if (!m_filters.empty())
{
@ -1848,14 +1848,13 @@ bool Service::dump_config(const char *filename) const
const MXS_MODULE* mod = get_module(m_router_name.c_str(), NULL);
ss_dassert(mod);
mp = mod->parameters;
// Dump router specific parameters
for (auto p = svc_config_param; p; p = p->next)
{
if (common_params.count(p->name) == 0)
{
dump_param(mp, file, p->name, p->value);
dump_param(file, p->name, p->value, {mod->parameters});
}
}