7#ifndef BASE_CONFIG_BACKEND_MGR_H
8#define BASE_CONFIG_BACKEND_MGR_H
16#include <boost/shared_ptr.hpp>
60template<
typename ConfigBackendPoolType>
71 typedef std::function<
typename ConfigBackendPoolType::ConfigBackendTypePtr
106 factories_.insert(std::make_pair(db_type, factory));
128 pool_->delAllBackends(db_type);
156 db::DatabaseConnection::ParameterMap::iterator it = parameters.find(
"type");
157 if (it == parameters.end()) {
162 std::string db_type = it->second;
167 if ((db_type ==
"mysql") || (db_type ==
"postgresql")) {
168 std::string with = (db_type ==
"postgresql" ?
"pgsql" : db_type);
170 "support for configuration database type: " << db_type
171 <<
". Did you forget to use --with-"
172 << with <<
" during compilation or to load libdhcp_"
173 << with <<
" hook library?");
176 db_type <<
"' is not supported");
180 auto backend = index->second(parameters);
183 " factory returned NULL");
187 pool_->addBackend(backend);
192 pool_->delAllBackends();
208 bool delBackend(
const std::string& db_type,
const std::string& dbaccess,
210 return (
pool_->del(db_type, dbaccess, if_unusable));
224 std::stringstream txt;
227 if (!txt.str().empty()) {
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
Base class for Configuration Backend Managers (CBM).
bool delBackend(const std::string &db_type, const std::string &dbaccess, bool if_unusable)
Delete a config backend manager.
bool registerBackendFactory(const std::string &db_type, const Factory &factory)
Registers new backend factory function for a given backend type.
void addBackend(const std::string &dbaccess)
Create an instance of a configuration backend.
BaseConfigBackendMgr()
Constructor.
ConfigBackendPoolPtr getPool() const
Returns underlying config backend pool.
std::function< typename ConfigBackendPoolType::ConfigBackendTypePtr(const db::DatabaseConnection::ParameterMap &)> Factory
Type of the backend factory function.
boost::shared_ptr< ConfigBackendPoolType > ConfigBackendPoolPtr
Pointer to the configuration backend pool.
void delAllBackends()
Removes all backends from the pool.
void logRegistered()
Logs out all registered backends.
std::map< std::string, Factory > factories_
A map holding registered backend factory functions.
bool unregisterBackendFactory(const std::string &db_type)
Unregisters the backend factory function for a given backend type.
ConfigBackendPoolPtr pool_
Pointer to the configuration backends pool.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
static ParameterMap parse(const std::string &dbaccess)
Parse database access string.
We want to reuse the database backend connection and exchange code for other uses,...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
#define LOG_INFO(LOGGER, MESSAGE)
Macro to conveniently test info output and log it.
isc::log::Logger database_logger("database")
Common database library logger.
const isc::log::MessageID CONFIG_BACKENDS_REGISTERED
Defines the logger used by the top-level component of kea-lfc.