MXS-1461 Template Module -> class Module + template SpecificModule

This commit is contained in:
Johan Wikman
2017-11-20 11:33:36 +02:00
parent 25e288b571
commit 604502e1cb
5 changed files with 24 additions and 27 deletions

View File

@ -23,7 +23,7 @@ namespace maxscale
/** /**
* An instance of FilterModule represents a filter module. * An instance of FilterModule represents a filter module.
*/ */
class FilterModule : public Module<FilterModule> class FilterModule : public SpecificModule<FilterModule>
{ {
FilterModule(const FilterModule&); FilterModule(const FilterModule&);
FilterModule& operator = (const FilterModule&); FilterModule& operator = (const FilterModule&);
@ -184,7 +184,7 @@ private:
} }
private: private:
friend class Module<FilterModule>; friend class SpecificModule<FilterModule>;
FilterModule(MXS_FILTER_OBJECT* pApi) FilterModule(MXS_FILTER_OBJECT* pApi)
: m_pApi(pApi) : m_pApi(pApi)

View File

@ -19,18 +19,10 @@ namespace maxscale
{ {
/** /**
* The template Module is an abstraction for a MaxScale module, to * The class Module is an abstraction for a MaxScale module, to
* be used as the base class of a concrete module. * be used as the base class of a specific module.
*/ */
template<class T> class Module
class Module;
/**
* The template specialization Module<void> provides functionality common
* to all modules.
*/
template <>
class Module<void>
{ {
public: public:
/** /**
@ -74,7 +66,7 @@ public:
* The template Module is intended to be derived from using the derived * The template Module is intended to be derived from using the derived
* class as template argument. * class as template argument.
* *
* class XyzModule : public Module<XyzModule> { ... } * class XyzModule : public SpecificModule<XyzModule> { ... }
* *
* @param zFile_name The name of the module. * @param zFile_name The name of the module.
* *
@ -82,14 +74,14 @@ public:
* the expected type. * the expected type.
*/ */
template<class T> template<class T>
class Module class SpecificModule : public Module
{ {
public: public:
static std::auto_ptr<T> load(const char* zFile_name) static std::auto_ptr<T> load(const char* zFile_name)
{ {
std::auto_ptr<T> sT; std::auto_ptr<T> sT;
void* pApi = Module<void>::load(zFile_name, T::zName); void* pApi = Module::load(zFile_name, T::zName);
if (pApi) if (pApi)
{ {
@ -98,6 +90,11 @@ public:
return sT; return sT;
} }
protected:
SpecificModule()
{
}
}; };
} }

View File

@ -24,7 +24,7 @@ namespace maxscale
* A QueryClassfierModule instance is an abstraction for a query * A QueryClassfierModule instance is an abstraction for a query
* classifier module. * classifier module.
*/ */
class QueryClassifierModule : public Module<QueryClassifierModule> class QueryClassifierModule : public SpecificModule<QueryClassifierModule>
{ {
QueryClassifierModule(const QueryClassifierModule&); QueryClassifierModule(const QueryClassifierModule&);
QueryClassifierModule& operator = (const QueryClassifierModule&); QueryClassifierModule& operator = (const QueryClassifierModule&);
@ -34,7 +34,7 @@ public:
typedef QUERY_CLASSIFIER type_t; /*< The type of the module object. */ typedef QUERY_CLASSIFIER type_t; /*< The type of the module object. */
private: private:
friend class Module<QueryClassifierModule>; friend class SpecificModule<QueryClassifierModule>;
QueryClassifierModule(QUERY_CLASSIFIER* pApi) QueryClassifierModule(QUERY_CLASSIFIER* pApi)
: m_pApi(pApi) : m_pApi(pApi)

View File

@ -18,13 +18,13 @@ namespace maxscale
{ {
//static //static
void* Module<void>::load(const char* zName, const char* zType) void* Module::load(const char* zName, const char* zType)
{ {
return load_module(zName, zType); return load_module(zName, zType);
} }
//static //static
bool Module<void>::process_init() bool Module::process_init()
{ {
bool initialized = false; bool initialized = false;
@ -69,7 +69,7 @@ bool Module<void>::process_init()
} }
//static //static
void Module<void>::process_finish() void Module::process_finish()
{ {
MXS_MODULE_ITERATOR i = mxs_module_iterator_get(NULL); MXS_MODULE_ITERATOR i = mxs_module_iterator_get(NULL);
MXS_MODULE* module = NULL; MXS_MODULE* module = NULL;
@ -84,7 +84,7 @@ void Module<void>::process_finish()
} }
//static //static
bool Module<void>::thread_init() bool Module::thread_init()
{ {
bool initialized = false; bool initialized = false;
@ -129,7 +129,7 @@ bool Module<void>::thread_init()
} }
//static //static
void Module<void>::thread_finish() void Module::thread_finish()
{ {
MXS_MODULE_ITERATOR i = mxs_module_iterator_get(NULL); MXS_MODULE_ITERATOR i = mxs_module_iterator_get(NULL);
MXS_MODULE* module = NULL; MXS_MODULE* module = NULL;

View File

@ -927,9 +927,9 @@ int run()
if (sModule.get()) if (sModule.get())
{ {
if (maxscale::Module<void>::process_init()) if (maxscale::Module::process_init())
{ {
if (maxscale::Module<void>::thread_init()) if (maxscale::Module::thread_init())
{ {
rv = 0; rv = 0;
rv += test(*sModule.get()); rv += test(*sModule.get());
@ -939,14 +939,14 @@ int run()
rv += test_on_queries(*sModule.get()); rv += test_on_queries(*sModule.get());
} }
maxscale::Module<void>::thread_finish(); maxscale::Module::thread_finish();
} }
else else
{ {
cerr << "error: Could not perform thread initialization." << endl; cerr << "error: Could not perform thread initialization." << endl;
} }
maxscale::Module<void>::process_finish(); maxscale::Module::process_finish();
} }
else else
{ {