The configuration mechanism consists of the following concepts:
Specification
Specifies the available configuration parameters of a module,
their names and their types.
Param
Specifies a parameter, its name and its type.
Type
Specifies the type of a configuration parameters; Bool, Size,
Count, etc.
Configuration
Specifies the configuration values of a particular instance of
the module. Configuration walks hand in hand with Specification,
the latter specifies what the former should contain.
A Specification is capable of configuring a Configuration from a
MXS_CONFIG_PARAMETER, checking in the process that all parameters
are of the correct type and that the required parameters are present.
A Specification is capable of persisting itself so that it later
can be read back.
The mechanism is closed for modification but open for extension in
the sense that if a module requires a custom parameter, all it needs
to do is to derive one class from Param and another from Type.
The canonical way for using this mechanism is as follows. Consider
a module xyx that has three parameters; a parameter called
"enabled" that is of boolean type, a parameter called "period"
that is of duration type, and a parameter "cache" that is of
size type. That would be declared as follows:
// xyz.hh
class XYZSession;
class XYZ : public maxscale::Filter<XYZ, XYZSession>
{
public:
static XYZ* create(const char* zName, MXS_CONFIG_PARAMETER* pParams);
private:
XYZ();
static config::Specification s_specification;
static config::ParamBool s_enabled;
static config::ParamDuration<std::chrono::seconds> s_period;
static config::ParamSize s_cache;
config::Configuration m_configuration;
config::Bool m_enabled;
config::Duration<std::chrono::seconds> m_period;
config::Size m_cache;
};
// xyz.cc
config::Specification XYZ::s_specification(MXS_MODULE_NAME);
config::ParamBool XYZ::s_enabled(
&s_specification,
"enabled",
"Specifies whether ... should be enabled or not."
);
config::ParamDuration<std::chrono::seconds> XYZ::s_period(
&s_specification,
"period",
"Specifies the period. Rounded to the nearest second."
);
config::ParamSize XYZ::s_cache(
&s_specification,
"cache",
"Specifies the size of the internal cache."
);
XYZ::XYZ()
: m_configuration(&s_specification)
, m_enabled(&m_configuration, &s_enabled)
, m_period(&m_configuration, &s_period)
, m_cache(&m_configuration, &s_cache)
{
}
XYZ* XYZ::create(const char* zName, MXS_CONFIG_PARAMETER* pParams)
{
XYZ* pXyz = new XYZ;
if (!s_specification.configure(pXyz->m_configuration, pParams))
{
delete pXyz;
pXyz = nullptr;
}
return pXyz;
}
116 lines
2.3 KiB
CMake
116 lines
2.3 KiB
CMake
add_library(maxscale-common SHARED
|
|
admin.cc
|
|
adminusers.cc
|
|
authenticator.cc
|
|
backend.cc
|
|
buffer.cc
|
|
config.cc
|
|
config2.cc
|
|
config_runtime.cc
|
|
dcb.cc
|
|
encryption.cc
|
|
event.cc
|
|
externcmd.cc
|
|
filter.cc
|
|
hint.cc
|
|
httprequest.cc
|
|
httpresponse.cc
|
|
json_api.cc
|
|
listener.cc
|
|
load_utils.cc
|
|
log.cc
|
|
mainworker.cc
|
|
mariadb.cc
|
|
maxscale_pcre2.cc
|
|
misc.cc
|
|
modulecmd.cc
|
|
modutil.cc
|
|
monitor.cc
|
|
mysql_binlog.cc
|
|
mysql_utils.cc
|
|
paths.cc
|
|
poll.cc
|
|
queryclassifier.cc
|
|
query_classifier.cc
|
|
random.cc
|
|
resource.cc
|
|
response_stat.cc
|
|
resultset.cc
|
|
router.cc
|
|
routingworker.cc
|
|
secrets.cc
|
|
server.cc
|
|
service.cc
|
|
session.cc
|
|
session_command.cc
|
|
ssl.cc
|
|
users.cc
|
|
utils.cc
|
|
session_stats.cc
|
|
)
|
|
|
|
target_link_libraries(maxscale-common
|
|
maxbase
|
|
maxsql
|
|
${MARIADB_CONNECTOR_LIBRARIES}
|
|
${LZMA_LINK_FLAGS}
|
|
${PCRE2_LIBRARIES}
|
|
${JANSSON_LIBRARIES}
|
|
ssl
|
|
pthread
|
|
crypt
|
|
crypto
|
|
inih
|
|
z
|
|
rt
|
|
m
|
|
sqlite3
|
|
stdc++
|
|
gnutls
|
|
gcrypt
|
|
${MICROHTTPD_LIBRARIES}
|
|
)
|
|
|
|
if(WITH_ASAN AND ASAN_FOUND)
|
|
target_link_libraries(maxscale-common ${ASAN_LIBRARIES})
|
|
endif()
|
|
|
|
find_library(HAVE_LIBDL NAMES dl)
|
|
if (HAVE_LIBDL)
|
|
# libdl just exposes libc functionality on most systems. This means that if
|
|
# we can't find it, it's likely that libc already exposes the symbols.
|
|
target_link_libraries(maxscale-common dl)
|
|
endif()
|
|
|
|
# Using initial-exec instead of the default global-dynamic tls-model
|
|
# reduces the cost of using thread-local variables in dynamic libraries.
|
|
target_compile_options(maxscale-common PRIVATE "-ftls-model=initial-exec")
|
|
|
|
add_dependencies(maxscale-common pcre2 connector-c libmicrohttpd jansson maxbase)
|
|
set_target_properties(maxscale-common PROPERTIES VERSION "1.0.0")
|
|
install_module(maxscale-common core)
|
|
|
|
add_executable(maxscale gateway.cc)
|
|
add_dependencies(maxscale pcre2)
|
|
|
|
if(WITH_JEMALLOC)
|
|
target_link_libraries(maxscale ${JEMALLOC_LIBRARIES})
|
|
elseif(WITH_TCMALLOC)
|
|
target_link_libraries(maxscale ${TCMALLOC_LIBRARIES})
|
|
endif()
|
|
|
|
target_link_libraries(maxscale maxscale-common)
|
|
install_executable(maxscale core)
|
|
|
|
add_executable(maxkeys maxkeys.cc)
|
|
target_link_libraries(maxkeys maxscale-common)
|
|
install_executable(maxkeys core)
|
|
|
|
add_executable(maxpasswd maxpasswd.cc)
|
|
target_link_libraries(maxpasswd maxscale-common)
|
|
install_executable(maxpasswd core)
|
|
|
|
if(BUILD_TESTS)
|
|
add_subdirectory(test)
|
|
endif()
|