MXS-2253 Add MXS_MODULE_PARAM_DURATION
Added a new module parameter type to be used for parameters that specify a duration. With the suffixes 'h', 'm', 's' and 'ms' the duration can be specified in hours, minutes, seconds or milliseconds, respectively. Irrespective of how the duration is specified, it is always returned as milliseconds. For backward compatibility, when a duration value is read it must be specifed how a value *not* defined using a suffix should be interpreted; as seconds or milliseconds. value = param->get_duration(name, mxs::config::INTERPRET_AS_SECONDS);
This commit is contained in:
@ -215,6 +215,31 @@ extern const char CN_MAXLOG[];
|
||||
extern const char CN_LOG_AUGMENTATION[];
|
||||
extern const char CN_LOG_TO_SHM[];
|
||||
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
namespace config
|
||||
{
|
||||
|
||||
enum DurationInterpretation
|
||||
{
|
||||
INTERPRET_AS_SECONDS,
|
||||
INTERPRET_AS_MILLISECONDS
|
||||
};
|
||||
|
||||
enum DurationUnit
|
||||
{
|
||||
DURATION_IN_HOURS,
|
||||
DURATION_IN_MINUTES,
|
||||
DURATION_IN_SECONDS,
|
||||
DURATION_IN_MILLISECONDS,
|
||||
DURATION_IN_DEFAULT
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Config parameter container. Typically includes all parameters of a single configuration file section
|
||||
* such as a server or filter.
|
||||
@ -294,6 +319,19 @@ public:
|
||||
*/
|
||||
uint64_t get_size(const std::string& key) const;
|
||||
|
||||
/**
|
||||
* @brief Get a duration.
|
||||
*
|
||||
* Should be used for MXS_MODULE_PARAM_DURATION parameter types.
|
||||
*
|
||||
* @param key Parameter name.
|
||||
* @param interpretation How a value NOT having a unit suffix should be interpreted.
|
||||
*
|
||||
* @return Duration in milliseconds; 0 if the parameter is not found.
|
||||
*/
|
||||
std::chrono::milliseconds get_duration(const std::string& key,
|
||||
mxs::config::DurationInterpretation interpretation) const;
|
||||
|
||||
/**
|
||||
* @brief Get a service value
|
||||
*
|
||||
|
@ -85,7 +85,8 @@ enum mxs_module_param_type
|
||||
MXS_MODULE_PARAM_SERVICE, /**< Service name */
|
||||
MXS_MODULE_PARAM_SERVER, /**< Server name */
|
||||
MXS_MODULE_PARAM_SERVERLIST, /**< List of server names, separated by ',' */
|
||||
MXS_MODULE_PARAM_REGEX /**< A regex string enclosed in '/' */
|
||||
MXS_MODULE_PARAM_REGEX, /**< A regex string enclosed in '/' */
|
||||
MXS_MODULE_PARAM_DURATION, /**< Duration in milliseconds */
|
||||
};
|
||||
|
||||
/** Maximum and minimum values for integer types */
|
||||
|
Reference in New Issue
Block a user