MXS-2304 Remove additional module parameter classes
Equivalent functionality is now in the basic config parameter class.
This commit is contained in:
@ -319,13 +319,13 @@ int test(FilterModule& filter_module, const TEST_CASE& tc)
|
||||
{
|
||||
int rv = 1;
|
||||
|
||||
auto_ptr<FilterModule::ConfigParameters> sParameters = filter_module.create_default_parameters();
|
||||
sParameters->set_value("cache_in_transactions", to_string(tc.cit));
|
||||
sParameters->set_value("debug", "31");
|
||||
sParameters->set_value("cached_data", "shared");
|
||||
sParameters->set_value("selects", "verify_cacheable");
|
||||
auto params = filter_module.create_default_parameters();
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "cache_in_transactions", to_string(tc.cit));
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "debug", "31");
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "cached_data", "shared");
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "selects", "verify_cacheable");
|
||||
|
||||
auto_ptr<FilterModule::Instance> sInstance = filter_module.createInstance("test", sParameters);
|
||||
auto_ptr<FilterModule::Instance> sInstance = filter_module.createInstance("test", params);
|
||||
|
||||
if (sInstance.get())
|
||||
{
|
||||
|
@ -816,11 +816,11 @@ int test(FilterModule& filter_module, const FW_TEST& t)
|
||||
TempFile file;
|
||||
file.write(t.zRules);
|
||||
|
||||
auto_ptr<FilterModule::ConfigParameters> sParameters = filter_module.create_default_parameters();
|
||||
sParameters->set_value("action", zAction);
|
||||
sParameters->set_value("rules", file.name());
|
||||
auto params = filter_module.create_default_parameters();
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "action", zAction);
|
||||
MXS_CONFIG_PARAMETER::set(¶ms, "rules", file.name());
|
||||
|
||||
auto_ptr<FilterModule::Instance> sInstance = filter_module.createInstance("test", sParameters);
|
||||
auto_ptr<FilterModule::Instance> sInstance = filter_module.createInstance("test", params);
|
||||
|
||||
if (sInstance.get())
|
||||
{
|
||||
|
@ -41,12 +41,6 @@ auto_ptr<FilterModule::Instance> FilterModule::createInstance(const char* zName,
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
auto_ptr<FilterModule::Instance> FilterModule::createInstance(const char* zName,
|
||||
std::auto_ptr<ConfigParameters> sParameters)
|
||||
{
|
||||
return createInstance(zName, sParameters.get());
|
||||
}
|
||||
|
||||
//
|
||||
// FilterModule::Instance
|
||||
//
|
||||
|
@ -136,11 +136,7 @@ public:
|
||||
*
|
||||
* @return A new instance or NULL if creation failed.
|
||||
*/
|
||||
std::auto_ptr<Instance> createInstance(const char* zName,
|
||||
MXS_CONFIG_PARAMETER* pParameters);
|
||||
|
||||
std::auto_ptr<Instance> createInstance(const char* zName,
|
||||
std::auto_ptr<ConfigParameters> sParameters);
|
||||
std::auto_ptr<Instance> createInstance(const char* zName, MXS_CONFIG_PARAMETER* pParameters);
|
||||
|
||||
private:
|
||||
friend class Instance;
|
||||
|
@ -28,45 +28,6 @@ namespace maxscale
|
||||
class Module
|
||||
{
|
||||
public:
|
||||
class ConfigParameters : public MXS_CONFIG_PARAMETER
|
||||
{
|
||||
ConfigParameters(const ConfigParameters&);
|
||||
ConfigParameters& operator=(const ConfigParameters&);
|
||||
|
||||
public:
|
||||
~ConfigParameters();
|
||||
|
||||
/**
|
||||
* Get the value of a parameter
|
||||
*
|
||||
* @param zName The name of a parameter.
|
||||
*
|
||||
* @return The value of the parameter or NULL if the parameter does not exist.
|
||||
*/
|
||||
const char* get(const char* zName) const;
|
||||
|
||||
/**
|
||||
* Set the value of a parameter
|
||||
*
|
||||
* @param zName The name of a parameter.
|
||||
* @param zValue The value of the parameter.
|
||||
*/
|
||||
void set_value(const char* zName, const char* zValue);
|
||||
|
||||
void set_value(const char* zName, const std::string& value);
|
||||
|
||||
private:
|
||||
friend class Module;
|
||||
|
||||
ConfigParameters(const MXS_MODULE_PARAM* pParams);
|
||||
|
||||
const MXS_CONFIG_PARAMETER* get_param(const char* zName) const;
|
||||
MXS_CONFIG_PARAMETER* get_param(const char* zName);
|
||||
|
||||
MXS_CONFIG_PARAMETER* get_tail();
|
||||
|
||||
std::deque<std::string> m_values; /** Storage for modified parameters. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Get a ConfigParameters instance containing the default values
|
||||
@ -74,7 +35,7 @@ public:
|
||||
*
|
||||
* @return A ConfigParameters object.
|
||||
*/
|
||||
std::auto_ptr<ConfigParameters> create_default_parameters() const;
|
||||
MXS_CONFIG_PARAMETER* create_default_parameters() const;
|
||||
|
||||
/**
|
||||
* Load a module with a specific name, assumed to be of a specific type.
|
||||
|
@ -21,131 +21,19 @@ using std::auto_ptr;
|
||||
namespace maxscale
|
||||
{
|
||||
|
||||
//
|
||||
// Module::ConfigParameters
|
||||
//
|
||||
|
||||
Module::ConfigParameters::ConfigParameters(const MXS_MODULE_PARAM* pParams)
|
||||
MXS_CONFIG_PARAMETER* Module::create_default_parameters() const
|
||||
{
|
||||
this->name = NULL;
|
||||
this->value = NULL;
|
||||
this->next = NULL;
|
||||
|
||||
MXS_CONFIG_PARAMETER* pCurrent = this;
|
||||
|
||||
while (pParams->name)
|
||||
MXS_CONFIG_PARAMETER* rval = nullptr;
|
||||
const MXS_MODULE_PARAM* param_definition = m_module.parameters;
|
||||
while (param_definition->name)
|
||||
{
|
||||
if (pParams->name && pParams->default_value)
|
||||
if (param_definition->default_value)
|
||||
{
|
||||
if (this->name == NULL)
|
||||
{
|
||||
this->name = MXS_STRDUP(pParams->name);
|
||||
this->value = MXS_STRDUP(pParams->default_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pNext = new MXS_CONFIG_PARAMETER;
|
||||
pNext->name = MXS_STRDUP(pParams->name);
|
||||
pNext->value = MXS_STRDUP(pParams->default_value);
|
||||
pNext->next = NULL;
|
||||
|
||||
pCurrent->next = pNext;
|
||||
pCurrent = pNext;
|
||||
}
|
||||
MXS_CONFIG_PARAMETER::set(&rval, param_definition->name, param_definition->default_value);
|
||||
}
|
||||
|
||||
++pParams;
|
||||
++param_definition;
|
||||
}
|
||||
}
|
||||
|
||||
Module::ConfigParameters::~ConfigParameters()
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pNext = this->next;
|
||||
|
||||
while (pNext)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pCurrent = pNext;
|
||||
pNext = pNext->next;
|
||||
|
||||
delete pCurrent;
|
||||
}
|
||||
}
|
||||
|
||||
const char* Module::ConfigParameters::get(const char* zName) const
|
||||
{
|
||||
const MXS_CONFIG_PARAMETER* pParam = get_param(zName);
|
||||
|
||||
return pParam ? pParam->value : NULL;
|
||||
}
|
||||
|
||||
void Module::ConfigParameters::set_value(const char* zName, const char* zValue)
|
||||
{
|
||||
set_value(zName, std::string(zValue));
|
||||
}
|
||||
|
||||
void Module::ConfigParameters::set_value(const char* zName, const std::string& value)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pParam = get_param(zName);
|
||||
|
||||
if (!pParam)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pTail = get_tail();
|
||||
|
||||
pParam = new MXS_CONFIG_PARAMETER;
|
||||
m_values.push_back(zName);
|
||||
pParam->name = MXS_STRDUP(m_values.back().c_str());
|
||||
pParam->value = NULL;
|
||||
pParam->next = NULL;
|
||||
|
||||
pTail->next = pParam;
|
||||
}
|
||||
|
||||
m_values.push_back(value);
|
||||
|
||||
pParam->value = MXS_STRDUP(m_values.back().c_str());
|
||||
}
|
||||
|
||||
const MXS_CONFIG_PARAMETER* Module::ConfigParameters::get_param(const char* zName) const
|
||||
{
|
||||
return const_cast<Module::ConfigParameters*>(this)->get_param(zName);
|
||||
}
|
||||
|
||||
MXS_CONFIG_PARAMETER* Module::ConfigParameters::get_param(const char* zName)
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pParam = NULL;
|
||||
|
||||
if (this->name && (strcmp(this->name, zName) == 0))
|
||||
{
|
||||
pParam = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
pParam = this->next;
|
||||
|
||||
while (pParam && (strcmp(pParam->name, zName) != 0))
|
||||
{
|
||||
pParam = pParam->next;
|
||||
}
|
||||
}
|
||||
|
||||
return pParam;
|
||||
}
|
||||
|
||||
MXS_CONFIG_PARAMETER* Module::ConfigParameters::get_tail()
|
||||
{
|
||||
MXS_CONFIG_PARAMETER* pTail = this;
|
||||
|
||||
while (pTail->next)
|
||||
{
|
||||
pTail = pTail->next;
|
||||
}
|
||||
|
||||
return pTail;
|
||||
}
|
||||
|
||||
auto_ptr<Module::ConfigParameters> Module::create_default_parameters() const
|
||||
{
|
||||
return auto_ptr<ConfigParameters>(new ConfigParameters(m_module.parameters));
|
||||
return rval;
|
||||
}
|
||||
|
||||
//
|
||||
|
Reference in New Issue
Block a user