MXS-2304 Convert configuration management structs to classes

The fields of MXS_CONFIG_PARAMETER remain unchanged so that parameter
processing can be changed gradually.
This commit is contained in:
Esa Korhonen 2019-01-30 17:18:22 +02:00
parent 03411e825d
commit 63b5eab89e
2 changed files with 54 additions and 9 deletions

View File

@ -215,31 +215,56 @@ extern const char CN_LOG_AUGMENTATION[];
extern const char CN_LOG_TO_SHM[];
/**
* The config parameter
* Config parameter container. Typically includes all parameters of a single configuration file section
* such as a server or filter.
*/
typedef struct config_parameter
class MXS_CONFIG_PARAMETER
{
public:
/**
* Get value of key as string.
*
* @param key Parameter name
* @return Parameter value. Empty string if key not found.
*/
std::string get_string(const std::string& key) const;
/**
* Get value of key as c-string. The pointer is valid as long as the underlying configuration
* is not changed.
*
* @param key Parameter name
* @return Parameter value. Empty string if key not found.
*/
const char* get_c_str(const std::string& key) const;
int64_t get_integer(const std::string& key) const;
int64_t get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const;
char* name; /**< The name of the parameter */
char* value; /**< The value of the parameter */
struct config_parameter* next; /**< Next pointer in the linked list */
} MXS_CONFIG_PARAMETER;
MXS_CONFIG_PARAMETER* next; /**< Next pointer in the linked list */
};
/**
* The config context structure, used to build the configuration
* data during the parse process
*/
typedef struct config_context
class CONFIG_CONTEXT
{
public:
char* object; /**< The name of the object being configured */
MXS_CONFIG_PARAMETER* parameters; /**< The list of parameter values */
bool was_persisted; /**< True if this object was persisted */
struct config_context* next; /**< Next pointer in the linked list */
} CONFIG_CONTEXT;
CONFIG_CONTEXT* next; /**< Next pointer in the linked list */
};
/**
* The gateway global configuration data
*/
typedef struct
struct MXS_CONFIG
{
bool config_check; /**< Only check config */
int n_threads; /**< Number of polling threads */
@ -287,7 +312,7 @@ typedef struct
char peer_user[MAX_ADMIN_HOST_LEN]; /**< Username for maxscale-to-maxscale traffic */
char peer_password[MAX_ADMIN_HOST_LEN]; /**< Password for maxscale-to-maxscale traffic */
mxb_log_target_t log_target; /**< Log type */
} MXS_CONFIG;
};
/**
* @brief Get global MaxScale configuration

View File

@ -1900,6 +1900,26 @@ bool config_get_compiled_regexes(const MXS_CONFIG_PARAMETER* params,
return rval;
}
string MXS_CONFIG_PARAMETER::get_string(const std::string& key) const
{
return get_c_str(key);
}
const char* MXS_CONFIG_PARAMETER::get_c_str(const std::string& key) const
{
return config_get_string(this, key.c_str());
}
int64_t MXS_CONFIG_PARAMETER::get_integer(const std::string& key) const
{
return config_get_integer(this, key.c_str());
}
int64_t MXS_CONFIG_PARAMETER::get_enum(const std::string& key, const MXS_ENUM_VALUE* enum_mapping) const
{
return config_get_enum(this, key.c_str(), enum_mapping);
}
MXS_CONFIG_PARAMETER* config_clone_param(const MXS_CONFIG_PARAMETER* param)
{
MXS_CONFIG_PARAMETER* p2 = (MXS_CONFIG_PARAMETER*)MXS_MALLOC(sizeof(MXS_CONFIG_PARAMETER));